Utilities for query string manipulation.
Checks if query string contains parameter.
url
(String) : URL or query string.paramName
(String) : Parameter name.var url = 'example.com/?lorem=ipsum';
contains(url, 'lorem'); // true
contains(url, 'foo'); //false
Parses query string and creates an object of keys => vals.
Will typecast value with string/typecast
by default
and decode string parameters using decodeURIComponent()
.
var query = '?foo=bar&lorem=123';
decode(query); // {foo: "bar", lorem: 123}
decode(query, false); // {foo: "bar", lorem: "123"}
Encode object into a query string.
Will encode parameters with encodeURIComponent()
.
encode({foo: "bar", lorem: 123}); // "?foo=bar&lorem=123"
Get query parameter value.
Will typecast value with string/typecast
by default.
See: setParam()
url
(String) : Url.param
(String) : Parameter name.[shouldTypecast]
(Boolean) : If it should typecast value.var url = 'example.com/?foo=bar&lorem=123&ipsum=false';
getParam(url, 'dolor'); // "amet"
getParam(url, 'lorem'); // 123
getParam(url, 'lorem', false); // "123"
Parses URL, extracts query string and decodes it.
It will typecast all properties of the query object unless second argument is
false
.
Alias to: decode(getQuery(url))
.
var url = 'example.com/?lorem=ipsum&a=123';
parse(url); // {lorem: "ipsum", a: 123}
parse(url, false); // {lorem: "ipsum", a: "123"}
Gets full query as string with all special chars decoded.
getQuery('example.com/?lorem=ipsum'); // "?lorem=ipsum"
Add new query string parameter to URL or update existing value.
See: getParam()
setParam('?foo=bar&lorem=0', 'lorem', 'ipsum'); // '?foo=bar&lorem=ipsum'
setParam('?lorem=1', 'foo', 123); // '?lorem=1&foo=123'
For more usage examples check specs inside /tests
folder. Unit tests are the
best documentation you can get...