Parse and stringify URL query strings
Download manually or with a package-manager.
npm install --save query-string
bower install --save query-string
component install sindresorhus/query-string
var queryString = require('query-string');
var url = 'http://sindresorhus.com?foo=bar'.split('?');
var parsed = queryString.parse(url[1]);
console.log(parsed);
// {foo: 'bar'}
parsed.foo = 'unicorn';
parsed.ilike = 'pizza';
console.log(url[0] + '?' + queryString.stringify(parsed));
// http://sindresorhus.com?foo=unicorn&ilike=pizza
<script src="bower_components/query-string/query-string.js"></script>
console.log(location.search);
// http://sindresorhus.com?foo=bar
var parsed = queryString.parse(location.search);
console.log(parsed);
// {foo: 'bar'}
parsed.foo = 'unicorn';
parsed.ilike = 'pizza';
location.search = queryString.stringify(parsed);
console.log(location.search);
// http://sindresorhus.com?foo=unicorn&ilike=pizza
Parse a query string into an object.
Stringify an object into a query string.
MIT © Sindre Sorhus