jellyfin-web/dashboard-ui/bower_components/query-string/readme.md

77 lines
1.6 KiB
Markdown
Raw Normal View History

2016-03-14 13:00:18 -07:00
# query-string [![Build Status](https://travis-ci.org/sindresorhus/query-string.svg?branch=master)](https://travis-ci.org/sindresorhus/query-string)
> Parse and stringify URL [query strings](http://en.wikipedia.org/wiki/Query_string)
## Install
```
$ npm install --save query-string
```
## Usage
```js
2016-03-14 13:27:35 -07:00
var queryString = require('query-string');
2016-03-14 13:00:18 -07:00
console.log(location.search);
2016-03-14 13:27:35 -07:00
//=> ?foo=bar
2016-03-14 13:00:18 -07:00
2016-03-14 13:27:35 -07:00
var parsed = queryString.parse(location.search);
2016-03-14 13:00:18 -07:00
console.log(parsed);
//=> {foo: 'bar'}
console.log(location.hash);
2016-03-14 13:27:35 -07:00
//=> #token=bada55cafe
2016-03-14 13:00:18 -07:00
2016-03-14 13:27:35 -07:00
var parsedHash = queryString.parse(location.hash);
2016-03-14 13:00:18 -07:00
console.log(parsedHash);
//=> {token: 'bada55cafe'}
parsed.foo = 'unicorn';
parsed.ilike = 'pizza';
location.search = queryString.stringify(parsed);
console.log(location.search);
2016-03-14 13:27:35 -07:00
//=> ?foo=unicorn&ilike=pizza
2016-03-14 13:00:18 -07:00
```
## API
### .parse(*string*)
Parse a query string into an object. Leading `?` or `#` are ignored, so you can pass `location.search` or `location.hash` directly.
### .stringify(*object*)
Stringify an object into a query string, sorting the keys.
### .extract(*string*)
Extract a query string from a URL that can be passed into `.parse()`.
## Nesting
2016-03-14 13:27:35 -07:00
This module intentionally doesn't support nesting as it's not specced and varies between implementations, which causes a lot of [edge cases](https://github.com/visionmedia/node-querystring/issues).
2016-03-14 13:00:18 -07:00
You're much better off just converting the object to a JSON string:
```js
queryString.stringify({
foo: 'bar',
nested: JSON.stringify({
unicorn: 'cake'
})
});
2016-03-14 13:27:35 -07:00
//=> foo=bar&nested=%7B%22unicorn%22%3A%22cake%22%7D
2016-03-14 13:00:18 -07:00
```
## License
MIT © [Sindre Sorhus](http://sindresorhus.com)