Small JS URL parser.
- Simple query params
- PHP query arrays
- Nested object
- Angular JS wrapper
bower install nebo-url-parser --save
var link = new URLParser('http://sub.domain.com:8080/test/route?query=10&arr[]=10&arr[]=20&obj.a=a&obj.b=b#!/somehash');
/* link object
{
hash: "#!/somehash",
host: "sub.domain.com:8080",
hostname: "sub.domain.com",
href: "http://sub.domain.com:8080/test/route?query=10&arr[]=10&arr[]=20&obj.a=a&obj.b=b#!/somehash",
params: {
arr: ["10", "20"],
obj: {
a: "a",
b: "b"
},
query: "10"
},
pathname: "/test/route",
port: "8080",
protocol: "http:"
}
*/
link.params.obj.a = 'c';
var href = link.toString();
Angular JS
angular.module('app', [
...,
'url-parser'
]);
See example on JSBin
params - object with search params
href - full original url
protocol - url protocol
hostname - hostname
port - hostname
pathname - pathname
search - query string
hash - url hash
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin my-new-feature - Submit a pull request :D
25.04.2016
Init project
Alexey Bondarenko (http://bondalex.com) created this!
See LICENSE-MIT