uri-util
URI Util module to work with URIs in browser and server
Install
Download the production version or the development version.
$ npm install --save uri-util
$ bower install --save uri-util
Usage
var URIUtil = ;var uri = 'https://github.com/search?q=uri-util&order=asc'; var q = URIUtil;console; // 'uri-util' var query = URIUtil;console; // {'q': 'uri-util', order: 'asc'} var qs = URIUtil;console; // '?q=uri-util&order=asc'
<script type="text/javascript" src="https://raw.githubusercontent.com/pasangsherpa/uri-util/master/dist/uri-util.min.js"></script><script type="text/javascript"> // https://github.com/search?q=uri-util&order=asc console; // 'uri-util' var query = URIUtil; console; // {'q': 'uri-util', order: 'asc'} var qs = URIUtil; console; // '?q=uri-util&order=asc' </script>
Refer to test.js in test directory for more examples.
API
Methods
.parse(str)
Parse a uri or a query string into an object.
str
Type: String
the string to be parsed. it can either be a uri or a query string.
.stringify(obj)
Convert the given object into a query string.
obj
Type: Object
the object to be converted to a query string.
.getQueryValue(str, key)
Get the value of the given query key from the given (uri or query) string.
str
Type: String
either a uri or a query string.
key
Type: String
key of the query field.
.getQueryValueInLoc(key)
Get the value of the given query key from the browser uri. (works only on client-side)
key
Type: String
key of the query field.