JSPM

  • Created
  • Published
  • Downloads 13534742
  • Score
    100M100P100Q221172F
  • License MIT

Parse and stringify URL query strings

Package Exports

  • query-string

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (query-string) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

query-string Build Status

Parse and stringify URL query strings

Install

Download manually or with a package-manager.

npm

npm install --save query-string

Bower

bower install --save query-string

Component

component install sindresorhus/query-string

Example

console.log(location.search);
// ?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);
// ?foo=unicorn&ilike=pizza

API

queryString.parse(string)

Parse a query string into an object.

queryString.stringify(object)

Stringify an object into a query string.

Nesting

This module intentionally doesn't support nesting as it's not specced and varies between implementations, which causes a lot of edge cases.

You're much better off just converting the object to a JSON string:

queryString.stringify({
  foo: 'bar',
  nested: JSON.stringify({
    unicorn: 'cake'
  })
});
// foo=bar&nested=%7B%22unicorn%22%3A%22cake%22%7D

License

MIT © Sindre Sorhus