https://github.com/xuexb/urlpath
url路径解析
https://github.com/xuexb/urlpath
url url-parser urlpath
Last synced: about 1 month ago
JSON representation
url路径解析
- Host: GitHub
- URL: https://github.com/xuexb/urlpath
- Owner: xuexb
- License: mit
- Created: 2017-04-07T03:35:28.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-04-07T06:17:01.000Z (about 8 years ago)
- Last Synced: 2024-04-24T03:23:42.522Z (about 1 year ago)
- Topics: url, url-parser, urlpath
- Language: JavaScript
- Size: 6.84 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# urlpath
url路径解析, 为了解决在拼接链接中多个`/`连接问题, 感谢 [@52cik](http://github.com/52cik)
[](https://github.com/ecomfe/fecs)
[](https://www.npmjs.com/package/urlpath)
[](https://www.npmjs.com/package/urlpath)
[](https://travis-ci.org/xuexb/urlpath)
[](https://coveralls.io/r/xuexb/urlpath?branch=master)---
### 例子
```js
urlpath('//xuexb.com/', '//static/a.js') // '//xuexb.com/static/a.js'urlpath('http://xuexb.com/', '//', '//static//', '/a.js') // 'http://xuexb.com/static/a.js'
urlpath('http://xuexb.com/////static///a.js') // 'http://xuexb.com/static/a.js'
```请注意和 [url.resolve](https://nodejs.org/api/url.html#url_url_resolve_from_to) 的区别:
```
url.resolve('http://example.com/', '/one') // 'http://example.com/one'
url.resolve('http://example.com/one', '/two') // 'http://example.com/two'urlpath('http://example.com/', '/one') // 'http://example.com/one'
urlpath('http://example.com/one', '/one') // 'http://example.com/one/one'
```