Parse and stringify URL query strings
This fork of sindresorhus/query-string introduces a couple of changes.
- UMD: there's now a bundled and UMD compatible version available along with the CommonJS one (the file is named
umd.js) - Array Notation: the original array notation was
?foo=bar&foo=bazand is now?foo[]=bar&foo[]=baz - Nesting: this implementation supports nesting but please, be aware of the edge cases.
$ npm install --save wizbii/query-string
const queryString = require('query-string');
console.log(location.search);
//=> '?foo=bar'
const parsed = queryString.parse(location.search);
console.log(parsed);
//=> {foo: 'bar'}
console.log(location.hash);
//=> '#token=bada55cafe'
const parsedHash = queryString.parse(location.hash);
console.log(parsedHash);
//=> {token: 'bada55cafe'}
parsed.foo = 'unicorn';
parsed.ilike = 'pizza';
location.search = queryString.stringify(parsed);
console.log(location.search);
//=> '?foo=unicorn&ilike=pizza'Parse a query string into an object. Leading ? or # are ignored, so you can pass location.search or location.hash directly.
Stringify an object into a query string, sorting the keys.
Extract a query string from a URL that can be passed into .parse().
MIT © Sindre Sorhus