Skip to content

query-string

6,238 2 20 MIT
8.1.0 (20 Dec 2022) Nov 13 2013 50.4 million (month)

The query-string library is a Node.js library that provides a simple way to parse and stringify query strings. It is useful for working with the query string portion of a URL, which is the part of the URL that follows 'the "?" character and contains key-value pairs.

Example Use


import queryString from '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';

const stringified = queryString.stringify(parsed);
//=> 'foo=unicorn&ilike=pizza'

location.search = stringified;
// note that `location.search` automatically prepends a question mark
console.log(location.search);
//=> '?foo=unicorn&ilike=pizza'

Alternatives / Similar


ip
1,352 1.1.8 (8 months ago) Aug 15 2012 compare
457 8.1.0 (8 months ago) May 05 2015 compare
6,223 0.1.3 (7 months ago) Jun 18 2013 compare

Other Languages

1,088 0.5.0 (5 months ago) Dec 28 2012 compare
1,077 0.9.8 (a month ago) Feb 14 2011 compare
url
85 v2.0.3 (24 days ago) Apr 15 2018 compare