Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/query-string/readme.md')
-rw-r--r--node_modules/query-string/readme.md243
1 files changed, 217 insertions, 26 deletions
diff --git a/node_modules/query-string/readme.md b/node_modules/query-string/readme.md
index 297a47d5a..46e58b5b0 100644
--- a/node_modules/query-string/readme.md
+++ b/node_modules/query-string/readme.md
@@ -1,7 +1,30 @@
-# query-string [![Build Status](https://travis-ci.org/sindresorhus/query-string.svg?branch=master)](https://travis-ci.org/sindresorhus/query-string)
+# query-string [![Build Status](https://travis-ci.com/sindresorhus/query-string.svg?branch=master)](https://travis-ci.com/github/sindresorhus/query-string) [![](https://badgen.net/bundlephobia/minzip/query-string)](https://bundlephobia.com/result?p=query-string)
> Parse and stringify URL [query strings](https://en.wikipedia.org/wiki/Query_string)
+<br>
+
+---
+
+<div align="center">
+ <p>
+ <p>
+ <sup>
+ <a href="https://github.com/sponsors/sindresorhus">My open source work is supported by the community</a>
+ </sup>
+ </p>
+ <sup>Special thanks to:</sup>
+ <br>
+ <br>
+ <a href="https://standardresume.co">
+ <img src="https://sindresorhus.com/assets/thanks/standard-resume-logo.svg" width="200"/>
+ </a>
+ </p>
+</div>
+
+---
+
+<br>
## Install
@@ -9,8 +32,7 @@
$ npm install query-string
```
-This module targets Node.js 6 or later and the latest version of Chrome, Firefox, and Safari. If you want support for older browsers, or, [if your project is using create-react-app v1](https://github.com/sindresorhus/query-string/pull/148#issuecomment-399656020), use version 5: `npm install query-string@5`.
-
+This module targets Node.js 6 or later and the latest version of Chrome, Firefox, and Safari. If you want support for older browsers, or, if your project is using create-react-app v1, use version 5: `npm install query-string@5`.
## Usage
@@ -43,7 +65,6 @@ console.log(location.search);
//=> '?foo=unicorn&ilike=pizza'
```
-
## API
### .parse(string, options?)
@@ -58,19 +79,21 @@ Type: `object`
##### decode
-Type: `boolean`<br>
+Type: `boolean`\
Default: `true`
Decode the keys and values. URL components are decoded with [`decode-uri-component`](https://github.com/SamVerschueren/decode-uri-component).
##### arrayFormat
-Type: `string`<br>
+Type: `string`\
Default: `'none'`
- `'bracket'`: Parse arrays with bracket representation:
```js
+const queryString = require('query-string');
+
queryString.parse('foo[]=1&foo[]=2&foo[]=3', {arrayFormat: 'bracket'});
//=> {foo: ['1', '2', '3']}
```
@@ -78,6 +101,8 @@ queryString.parse('foo[]=1&foo[]=2&foo[]=3', {arrayFormat: 'bracket'});
- `'index'`: Parse arrays with index representation:
```js
+const queryString = require('query-string');
+
queryString.parse('foo[0]=1&foo[1]=2&foo[3]=3', {arrayFormat: 'index'});
//=> {foo: ['1', '2', '3']}
```
@@ -85,30 +110,52 @@ queryString.parse('foo[0]=1&foo[1]=2&foo[3]=3', {arrayFormat: 'index'});
- `'comma'`: Parse arrays with elements separated by comma:
```js
+const queryString = require('query-string');
+
queryString.parse('foo=1,2,3', {arrayFormat: 'comma'});
//=> {foo: ['1', '2', '3']}
```
+- `'separator'`: Parse arrays with elements separated by a custom character:
+
+```js
+const queryString = require('query-string');
+
+queryString.parse('foo=1|2|3', {arrayFormat: 'separator', arrayFormatSeparator: '|'});
+//=> {foo: ['1', '2', '3']}
+```
+
- `'none'`: Parse arrays with elements using duplicate keys:
```js
+const queryString = require('query-string');
+
queryString.parse('foo=1&foo=2&foo=3');
//=> {foo: ['1', '2', '3']}
```
+##### arrayFormatSeparator
+
+Type: `string`\
+Default: `','`
+
+The character used to separate array elements when using `{arrayFormat: 'separator'}`.
+
##### sort
-Type: `Function | boolean`<br>
+Type: `Function | boolean`\
Default: `true`
Supports both `Function` as a custom sorting function or `false` to disable sorting.
##### parseNumbers
-Type: `boolean`<br>
+Type: `boolean`\
Default: `false`
```js
+const queryString = require('query-string');
+
queryString.parse('foo=1', {parseNumbers: true});
//=> {foo: 1}
```
@@ -117,17 +164,19 @@ Parse the value as a number type instead of string type if it's a number.
##### parseBooleans
-Type: `boolean`<br>
+Type: `boolean`\
Default: `false`
```js
+const queryString = require('query-string');
+
queryString.parse('foo=true', {parseBooleans: true});
//=> {foo: true}
```
Parse the value as a boolean type instead of string type if it's a boolean.
-### .stringify(object, [options])
+### .stringify(object, options?)
Stringify an object into a query string and sorting the keys.
@@ -137,26 +186,28 @@ Type: `object`
##### strict
-Type: `boolean`<br>
+Type: `boolean`\
Default: `true`
Strictly encode URI components with [strict-uri-encode](https://github.com/kevva/strict-uri-encode). It uses [encodeURIComponent](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) if set to false. You probably [don't care](https://github.com/sindresorhus/query-string/issues/42) about this option.
##### encode
-Type: `boolean`<br>
+Type: `boolean`\
Default: `true`
[URL encode](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) the keys and values.
##### arrayFormat
-Type: `string`<br>
+Type: `string`\
Default: `'none'`
- `'bracket'`: Serialize arrays using bracket representation:
```js
+const queryString = require('query-string');
+
queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'bracket'});
//=> 'foo[]=1&foo[]=2&foo[]=3'
```
@@ -164,6 +215,8 @@ queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'bracket'});
- `'index'`: Serialize arrays using index representation:
```js
+const queryString = require('query-string');
+
queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'index'});
//=> 'foo[0]=1&foo[1]=2&foo[2]=3'
```
@@ -171,6 +224,8 @@ queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'index'});
- `'comma'`: Serialize arrays by separating elements with comma:
```js
+const queryString = require('query-string');
+
queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'comma'});
//=> 'foo=1,2,3'
```
@@ -178,10 +233,19 @@ queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'comma'});
- `'none'`: Serialize arrays by using duplicate keys:
```js
+const queryString = require('query-string');
+
queryString.stringify({foo: [1, 2, 3]});
//=> 'foo=1&foo=2&foo=3'
```
+##### arrayFormatSeparator
+
+Type: `string`\
+Default: `','`
+
+The character used to separate array elements when using `{arrayFormat: 'separator'}`.
+
##### sort
Type: `Function | boolean`
@@ -189,6 +253,8 @@ Type: `Function | boolean`
Supports both `Function` as a custom sorting function or `false` to disable sorting.
```js
+const queryString = require('query-string');
+
const order = ['c', 'a', 'b'];
queryString.stringify({a: 1, b: 2, c: 3}, {
@@ -198,29 +264,156 @@ queryString.stringify({a: 1, b: 2, c: 3}, {
```
```js
+const queryString = require('query-string');
+
queryString.stringify({b: 1, c: 2, a: 3}, {sort: false});
//=> 'b=1&c=2&a=3'
```
If omitted, keys are sorted using `Array#sort()`, which means, converting them to strings and comparing strings in Unicode code point order.
+##### skipNull
+
+Skip keys with `null` as the value.
+
+Note that keys with `undefined` as the value are always skipped.
+
+Type: `boolean`\
+Default: `false`
+
+```js
+const queryString = require('query-string');
+
+queryString.stringify({a: 1, b: undefined, c: null, d: 4}, {
+ skipNull: true
+});
+//=> 'a=1&d=4'
+```
+
+```js
+const queryString = require('query-string');
+
+queryString.stringify({a: undefined, b: null}, {
+ skipNull: true
+});
+//=> ''
+```
+
+##### skipEmptyString
+
+Skip keys with an empty string as the value.
+
+Type: `boolean`\
+Default: `false`
+
+```js
+const queryString = require('query-string');
+
+queryString.stringify({a: 1, b: '', c: '', d: 4}, {
+ skipEmptyString: true
+});
+//=> 'a=1&d=4'
+```
+
+```js
+const queryString = require('query-string');
+
+queryString.stringify({a: '', b: ''}, {
+ skipEmptyString: true
+});
+//=> ''
+```
+
### .extract(string)
Extract a query string from a URL that can be passed into `.parse()`.
+Note: This behaviour can be changed with the `skipNull` option.
+
### .parseUrl(string, options?)
Extract the URL and the query string as an object.
-The `options` are the same as for `.parse()`.
-
Returns an object with a `url` and `query` property.
+If the `parseFragmentIdentifier` option is `true`, the object will also contain a `fragmentIdentifier` property.
+
```js
+const queryString = require('query-string');
+
queryString.parseUrl('https://foo.bar?foo=bar');
//=> {url: 'https://foo.bar', query: {foo: 'bar'}}
+
+queryString.parseUrl('https://foo.bar?foo=bar#xyz', {parseFragmentIdentifier: true});
+//=> {url: 'https://foo.bar', query: {foo: 'bar'}, fragmentIdentifier: 'xyz'}
+```
+
+#### options
+
+Type: `object`
+
+The options are the same as for `.parse()`.
+
+Extra options are as below.
+
+##### parseFragmentIdentifier
+
+Parse the fragment identifier from the URL.
+
+Type: `boolean`\
+Default: `false`
+
+```js
+const queryString = require('query-string');
+
+queryString.parseUrl('https://foo.bar?foo=bar#xyz', {parseFragmentIdentifier: true});
+//=> {url: 'https://foo.bar', query: {foo: 'bar'}, fragmentIdentifier: 'xyz'}
```
+### .stringifyUrl(object, options?)
+
+Stringify an object into a URL with a query string and sorting the keys. The inverse of [`.parseUrl()`](https://github.com/sindresorhus/query-string#parseurlstring-options)
+
+The `options` are the same as for `.stringify()`.
+
+Returns a string with the URL and a query string.
+
+Query items in the `query` property overrides queries in the `url` property.
+
+The `fragmentIdentifier` property overrides the fragment identifier in the `url` property.
+
+```js
+queryString.stringifyUrl({url: 'https://foo.bar', query: {foo: 'bar'}});
+//=> 'https://foo.bar?foo=bar'
+
+queryString.stringifyUrl({url: 'https://foo.bar?foo=baz', query: {foo: 'bar'}});
+//=> 'https://foo.bar?foo=bar'
+
+queryString.stringifyUrl({
+ url: 'https://foo.bar',
+ query: {
+ top: 'foo'
+ },
+ fragmentIdentifier: 'bar'
+});
+//=> 'https://foo.bar?top=foo#bar'
+```
+
+#### object
+
+Type: `object`
+
+##### url
+
+Type: `string`
+
+The URL to stringify.
+
+##### query
+
+Type: `object`
+
+Query items to add to the URL.
## Nesting
@@ -229,6 +422,8 @@ This module intentionally doesn't support nesting as it's not spec'd and varies
You're much better off just converting the object to a JSON string:
```js
+const queryString = require('query-string');
+
queryString.stringify({
foo: 'bar',
nested: JSON.stringify({
@@ -241,6 +436,8 @@ queryString.stringify({
However, there is support for multiple instances of the same key:
```js
+const queryString = require('query-string');
+
queryString.parse('likes=cake&name=bob&likes=icecream');
//=> {likes: ['cake', 'icecream'], name: 'bob'}
@@ -248,12 +445,13 @@ queryString.stringify({color: ['taupe', 'chartreuse'], id: '515'});
//=> 'color=taupe&color=chartreuse&id=515'
```
-
## Falsy values
Sometimes you want to unset a key, or maybe just make it present without assigning a value to it. Here is how falsy values are stringified:
```js
+const queryString = require('query-string');
+
queryString.stringify({foo: false});
//=> 'foo=false'
@@ -264,15 +462,8 @@ queryString.stringify({foo: undefined});
//=> ''
```
+## query-string for enterprise
----
+Available as part of the Tidelift Subscription.
-<div align="center">
- <b>
- <a href="https://tidelift.com/subscription/pkg/npm-query-string?utm_source=npm-query-string&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
- </b>
- <br>
- <sub>
- Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
- </sub>
-</div>
+The maintainers of query-string and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-query-string?utm_source=npm-query-string&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)