Package Exports
- lite-url
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (lite-url) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
lite-url
Small, JS lib that uses regex for parsing a URL into it's component parts.
Broadly provides the same interface as the native URL function, but in a cross browser way (taken from Chrome 35):
new URL('http://user:pass@example.com:8080/directory/file.ext?query=1#anchor'); //results in...
{
"hash": "#anchor",
"search": "?query=1",
"pathname": "/directory/file.ext",
"port": "8080",
"hostname": "example.com",
"host": "example.com:8080",
"password": "pass",
"username": "user",
"protocol": "http:",
"origin": "http://example.com:8080",
"href": "http://user:pass@example.com:8080/directory/file.ext?query=1#anchor"
}
install
bower install --save lite-url
or just grab the minified version from dist/
or full version from src/
usage
<script src="tiny-url.min.js"></script>
<script>
var url = 'http://user:pass@example.com:8080/directory/file.ext?query=1#anchor';
var parsed = new liteURL(url);
console.log(parsed);
</script>
notes
The URL object in Chrome etc doesn't quite fit with other interpretations of the spec (http://en.wikipedia.org/wiki/URI_scheme#Examples).
alternatives
- https://github.com/medialize/URI.js
- good if size isn't an issue
- http://stevenlevithan.com/demo/parseuri/js/
- good test examples but has a bug or two ('@' symbol in path or query breaks it)
var x = document.createElement('a'); x.href = '/relative/url'; console.log(x.hostname)
- requires a document and creating an element (just not tidy)
- isn't compatible with lt IE10
- can't get authentication info from URL
- https://developer.mozilla.org/en-US/docs/Web/API/URL
- not cross browser