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:
authorAudrey Eschright <audrey@npmjs.com>2019-03-19 21:54:04 +0300
committerAudrey Eschright <audrey@npmjs.com>2019-03-20 02:44:05 +0300
commit47b08b3b9860438b416efb438e975a628ec2eed5 (patch)
tree087814bc111c6da4f6c707581b1f85ea20ba63c2 /node_modules/query-string
parenta163a9c35f6f341de343562368056258bba5d7dc (diff)
query-string@6.4.0
Diffstat (limited to 'node_modules/query-string')
-rw-r--r--node_modules/query-string/index.d.ts143
-rw-r--r--node_modules/query-string/index.js110
-rw-r--r--node_modules/query-string/package.json30
-rw-r--r--node_modules/query-string/readme.md108
4 files changed, 288 insertions, 103 deletions
diff --git a/node_modules/query-string/index.d.ts b/node_modules/query-string/index.d.ts
new file mode 100644
index 000000000..90b3658ae
--- /dev/null
+++ b/node_modules/query-string/index.d.ts
@@ -0,0 +1,143 @@
+export interface ParseOptions {
+ /**
+ * Decode the keys and values. URI components are decoded with [`decode-uri-component`](https://github.com/SamVerschueren/decode-uri-component).
+ *
+ * @default true
+ */
+ readonly decode?: boolean;
+
+ /**
+ * @default 'none'
+ *
+ * - `bracket`: Parse arrays with bracket representation:
+ *
+ *
+ * queryString.parse('foo[]=1&foo[]=2&foo[]=3', {arrayFormat: 'bracket'});
+ * //=> foo: [1, 2, 3]
+ *
+ * - `index`: Parse arrays with index representation:
+ *
+ *
+ * queryString.parse('foo[0]=1&foo[1]=2&foo[3]=3', {arrayFormat: 'index'});
+ * //=> foo: [1, 2, 3]
+ *
+ * - `comma`: Parse arrays with elements separated by comma:
+ *
+ *
+ * queryString.parse('foo=1,2,3', {arrayFormat: 'comma'});
+ * //=> foo: [1, 2, 3]
+ *
+ * - `none`: Parse arrays with elements using duplicate keys:
+ *
+ *
+ * queryString.parse('foo=1&foo=2&foo=3');
+ * //=> foo: [1, 2, 3]
+ */
+ readonly arrayFormat?: 'bracket' | 'index' | 'comma' | 'none';
+}
+
+export interface ParsedQuery {
+ readonly [key: string]: string | string[] | null | undefined;
+}
+
+/**
+ * Parse a query string into an object. Leading `?` or `#` are ignored, so you can pass `location.search` or `location.hash` directly.
+ *
+ * The returned object is created with [`Object.create(null)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create) and thus does not have a `prototype`.
+ *
+ * @param query - The query string to parse.
+ */
+export function parse(query: string, options?: ParseOptions): ParsedQuery;
+
+export interface ParsedUrl {
+ readonly url: string;
+ readonly query: ParsedQuery;
+}
+
+/**
+ * Extract the URL and the query string as an object.
+ *
+ * @param url - The URL to parse.
+ *
+ * @example
+ *
+ * queryString.parseUrl('https://foo.bar?foo=bar');
+ * //=> {url: 'https://foo.bar', query: {foo: 'bar'}}
+ */
+export function parseUrl(url: string, options?: ParseOptions): ParsedUrl;
+
+export interface StringifyOptions {
+ /**
+ * 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.
+ *
+ * @default true
+ */
+ readonly strict?: boolean;
+
+ /**
+ * [URL encode](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) the keys and values.
+ *
+ * @default true
+ */
+ readonly encode?: boolean;
+
+ /**
+ * @default 'none'
+ *
+ * - `bracket`: Serialize arrays using bracket representation:
+ *
+ *
+ * queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'bracket'});
+ * //=> 'foo[]=1&foo[]=2&foo[]=3'
+ *
+ * - `index`: Serialize arrays using index representation:
+ *
+ *
+ * queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'index'});
+ * //=> 'foo[0]=1&foo[1]=2&foo[3]=3'
+ *
+ * - `comma`: Serialize arrays by separating elements with comma:
+ *
+ *
+ * queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'comma'});
+ * //=> 'foo=1,2,3'
+ *
+ * - `none`: Serialize arrays by using duplicate keys:
+ *
+ *
+ * queryString.stringify({foo: [1, 2, 3]});
+ * //=> 'foo=1&foo=2&foo=3'
+ */
+ readonly arrayFormat?: 'bracket' | 'index' | 'comma' | 'none';
+
+ /**
+ * Supports both `Function` as a custom sorting function or `false` to disable sorting.
+ *
+ * If omitted, keys are sorted using `Array#sort`, which means, converting them to strings and comparing strings in Unicode code point order.
+ *
+ * @example
+ *
+ * const order = ['c', 'a', 'b'];
+ * queryString.stringify({a: 1, b: 2, c: 3}, {
+ * sort: (itemLeft, itemRight) => order.indexOf(itemLeft) - order.indexOf(itemRight)
+ * });
+ * // => 'c=3&a=1&b=2'
+ *
+ * queryString.stringify({b: 1, c: 2, a: 3}, {sort: false});
+ * // => 'b=1&c=2&a=3'
+ */
+ readonly sort?: ((itemLeft: string, itemRight: string) => number) | false;
+}
+
+/**
+ * Stringify an object into a query string and sorting the keys.
+ */
+export function stringify(
+ object: {[key: string]: unknown},
+ options?: StringifyOptions
+): string;
+
+/**
+ * Extract a query string from a URL that can be passed into `.parse()`.
+ */
+export function extract(url: string): string;
diff --git a/node_modules/query-string/index.js b/node_modules/query-string/index.js
index 6a1b3c2a3..3cb1adf8d 100644
--- a/node_modules/query-string/index.js
+++ b/node_modules/query-string/index.js
@@ -5,35 +5,59 @@ const decodeComponent = require('decode-uri-component');
function encoderForArrayFormat(options) {
switch (options.arrayFormat) {
case 'index':
- return (key, value, index) => {
- return value === null ? [
- encode(key, options),
- '[',
- index,
- ']'
- ].join('') : [
- encode(key, options),
- '[',
- encode(index, options),
- ']=',
- encode(value, options)
- ].join('');
+ return key => (result, value) => {
+ const index = result.length;
+ if (value === undefined) {
+ return result;
+ }
+
+ if (value === null) {
+ return [...result, [encode(key, options), '[', index, ']'].join('')];
+ }
+
+ return [
+ ...result,
+ [encode(key, options), '[', encode(index, options), ']=', encode(value, options)].join('')
+ ];
};
+
case 'bracket':
- return (key, value) => {
- return value === null ? [encode(key, options), '[]'].join('') : [
- encode(key, options),
- '[]=',
- encode(value, options)
- ].join('');
+ return key => (result, value) => {
+ if (value === undefined) {
+ return result;
+ }
+
+ if (value === null) {
+ return [...result, [encode(key, options), '[]'].join('')];
+ }
+
+ return [...result, [encode(key, options), '[]=', encode(value, options)].join('')];
+ };
+
+ case 'comma':
+ return key => (result, value, index) => {
+ if (!value) {
+ return result;
+ }
+
+ if (index === 0) {
+ return [[encode(key, options), '=', encode(value, options)].join('')];
+ }
+
+ return [[result, encode(value, options)].join(',')];
};
+
default:
- return (key, value) => {
- return value === null ? encode(key, options) : [
- encode(key, options),
- '=',
- encode(value, options)
- ].join('');
+ return key => (result, value) => {
+ if (value === undefined) {
+ return result;
+ }
+
+ if (value === null) {
+ return [...result, encode(key, options)];
+ }
+
+ return [...result, [encode(key, options), '=', encode(value, options)].join('')];
};
}
}
@@ -59,6 +83,7 @@ function parserForArrayFormat(options) {
accumulator[key][result[1]] = value;
};
+
case 'bracket':
return (key, value, accumulator) => {
result = /(\[\])$/.exec(key);
@@ -76,6 +101,14 @@ function parserForArrayFormat(options) {
accumulator[key] = [].concat(accumulator[key], value);
};
+
+ case 'comma':
+ return (key, value, accumulator) => {
+ const isArray = typeof value === 'string' && value.split('').indexOf(',') > -1;
+ const newValue = isArray ? value.split(',') : value;
+ accumulator[key] = newValue;
+ };
+
default:
return (key, value, accumulator) => {
if (accumulator[key] === undefined) {
@@ -128,7 +161,10 @@ function extract(input) {
}
function parse(input, options) {
- options = Object.assign({decode: true, arrayFormat: 'none'}, options);
+ options = Object.assign({
+ decode: true,
+ arrayFormat: 'none'
+ }, options);
const formatter = parserForArrayFormat(options);
@@ -171,8 +207,8 @@ function parse(input, options) {
exports.extract = extract;
exports.parse = parse;
-exports.stringify = (obj, options) => {
- if (!obj) {
+exports.stringify = (object, options) => {
+ if (!object) {
return '';
}
@@ -183,14 +219,14 @@ exports.stringify = (obj, options) => {
}, options);
const formatter = encoderForArrayFormat(options);
- const keys = Object.keys(obj);
+ const keys = Object.keys(object);
if (options.sort !== false) {
keys.sort(options.sort);
}
return keys.map(key => {
- const value = obj[key];
+ const value = object[key];
if (value === undefined) {
return '';
@@ -201,17 +237,9 @@ exports.stringify = (obj, options) => {
}
if (Array.isArray(value)) {
- const result = [];
-
- for (const value2 of value.slice()) {
- if (value2 === undefined) {
- continue;
- }
-
- result.push(formatter(key, value2, result.length));
- }
-
- return result.join('&');
+ return value
+ .reduce(formatter(key), [])
+ .join('&');
}
return encode(key, options) + '=' + encode(value, options);
diff --git a/node_modules/query-string/package.json b/node_modules/query-string/package.json
index 8f9b91b4f..cd62b3cf5 100644
--- a/node_modules/query-string/package.json
+++ b/node_modules/query-string/package.json
@@ -1,27 +1,27 @@
{
- "_from": "query-string@6.2.0",
- "_id": "query-string@6.2.0",
+ "_from": "query-string@6.4.0",
+ "_id": "query-string@6.4.0",
"_inBundle": false,
- "_integrity": "sha512-5wupExkIt8RYL4h/FE+WTg3JHk62e6fFPWtAZA9J5IWK1PfTfKkMS93HBUHcFpeYi9KsY5pFbh+ldvEyaz5MyA==",
+ "_integrity": "sha512-Werid2I41/tJTqOGPJ3cC3vwrIh/8ZupBQbp7BSsqXzr+pTin3aMJ/EZb8UEuk7ZO3VqQFvq2qck/ihc6wqIdw==",
"_location": "/query-string",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
- "raw": "query-string@6.2.0",
+ "raw": "query-string@6.4.0",
"name": "query-string",
"escapedName": "query-string",
- "rawSpec": "6.2.0",
+ "rawSpec": "6.4.0",
"saveSpec": null,
- "fetchSpec": "6.2.0"
+ "fetchSpec": "6.4.0"
},
"_requiredBy": [
"#USER",
"/"
],
- "_resolved": "https://registry.npmjs.org/query-string/-/query-string-6.2.0.tgz",
- "_shasum": "468edeb542b7e0538f9f9b1aeb26f034f19c86e1",
- "_spec": "query-string@6.2.0",
+ "_resolved": "https://registry.npmjs.org/query-string/-/query-string-6.4.0.tgz",
+ "_shasum": "1566c0cec3a2da2d82c222ed3f9e2a921dba5e6a",
+ "_spec": "query-string@6.4.0",
"_where": "/Users/aeschright/code/cli",
"author": {
"name": "Sindre Sorhus",
@@ -39,16 +39,18 @@
"deprecated": false,
"description": "Parse and stringify URL query strings",
"devDependencies": {
- "ava": "^0.25.0",
+ "ava": "^1.3.1",
"deep-equal": "^1.0.1",
"fast-check": "^1.5.0",
- "xo": "^0.23.0"
+ "tsd-check": "^0.3.0",
+ "xo": "^0.24.0"
},
"engines": {
"node": ">=6"
},
"files": [
- "index.js"
+ "index.js",
+ "index.d.ts"
],
"homepage": "https://github.com/sindresorhus/query-string#readme",
"keywords": [
@@ -73,7 +75,7 @@
"url": "git+https://github.com/sindresorhus/query-string.git"
},
"scripts": {
- "test": "xo && ava"
+ "test": "xo && ava && tsd-check"
},
- "version": "6.2.0"
+ "version": "6.4.0"
}
diff --git a/node_modules/query-string/readme.md b/node_modules/query-string/readme.md
index 5fa1cfbde..fda9323cd 100644
--- a/node_modules/query-string/readme.md
+++ b/node_modules/query-string/readme.md
@@ -2,12 +2,6 @@
> Parse and stringify URL [query strings](https://en.wikipedia.org/wiki/Query_string)
----
-
-<p align="center"><b>🔥 Want to strengthen your core JavaScript skills and master ES6?</b><br>I would personally recommend this awesome <a href="https://ES6.io/friend/AWESOME">ES6 course</a> by Wes Bos.<br>Also check out his <a href="https://LearnNode.com/friend/AWESOME">Node.js</a>, <a href="https://ReactForBeginners.com/friend/AWESOME">React</a>, <a href="https://SublimeTextBook.com/friend/AWESOME">Sublime</a> courses.</p>
-
----
-
## Install
@@ -15,7 +9,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](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](https://github.com/sindresorhus/query-string/pull/148#issuecomment-399656020), use version 5: `npm install query-string@5`.
<a href="https://www.patreon.com/sindresorhus">
<img src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" width="160">
@@ -56,120 +50,138 @@ console.log(location.search);
## API
-### .parse(*string*, *[options]*)
+### .parse(string, [options])
Parse a query string into an object. Leading `?` or `#` are ignored, so you can pass `location.search` or `location.hash` directly.
The returned object is created with [`Object.create(null)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create) and thus does not have a `prototype`.
-#### decode
+#### options
+
+Type: `Object`
+
+##### decode
Type: `boolean`<br>
Default: `true`
-Decode the keys and values. URI components are decoded with [`decode-uri-component`](https://github.com/SamVerschueren/decode-uri-component).
+Decode the keys and values. URL components are decoded with [`decode-uri-component`](https://github.com/SamVerschueren/decode-uri-component).
-#### arrayFormat
+##### arrayFormat
Type: `string`<br>
-Default: `'none'`
-
-Supports both `index` for an indexed array representation or `bracket` for a *bracketed* array representation.
+Default: `none`
-- `bracket`: stands for parsing correctly arrays with bracket representation on the query string, such as:
+- `bracket`: Parse arrays with bracket representation:
```js
queryString.parse('foo[]=1&foo[]=2&foo[]=3', {arrayFormat: 'bracket'});
-//=> foo: [1,2,3]
+//=> foo: [1, 2, 3]
```
-- `index`: stands for parsing taking the index into account, such as:
+- `index`: Parse arrays with index representation:
```js
queryString.parse('foo[0]=1&foo[1]=2&foo[3]=3', {arrayFormat: 'index'});
-//=> foo: [1,2,3]
+//=> foo: [1, 2, 3]
+```
+
+- `comma`: Parse arrays with elements separated by comma:
+
+```js
+queryString.parse('foo=1,2,3', {arrayFormat: 'comma'});
+//=> foo: [1, 2, 3]
```
-- `none`: is the **default** option and removes any bracket representation, such as:
+- `none`: Parse arrays with elements using duplicate keys:
```js
queryString.parse('foo=1&foo=2&foo=3');
-//=> foo: [1,2,3]
+//=> foo: [1, 2, 3]
```
-### .stringify(*object*, *[options]*)
+### .stringify(object, [options])
+
+Stringify an object into a query string and sorting the keys.
+
+#### options
-Stringify an object into a query string, sorting the keys.
+Type: `Object`
-#### strict
+##### strict
Type: `boolean`<br>
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.
+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
+##### encode
Type: `boolean`<br>
Default: `true`
[URL encode](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) the keys and values.
-#### arrayFormat
+##### arrayFormat
Type: `string`<br>
-Default: `'none'`
+Default: `none`
-Supports both `index` for an indexed array representation or `bracket` for a *bracketed* array representation.
+- `bracket`: Serialize arrays using bracket representation:
-- `bracket`: stands for parsing correctly arrays with bracket representation on the query string, such as:
+```js
+queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'bracket'});
+//=> 'foo[]=1&foo[]=2&foo[]=3'
+```
+
+- `index`: Serialize arrays using index representation:
```js
-queryString.stringify({foo: [1,2,3]}, {arrayFormat: 'bracket'});
-// => foo[]=1&foo[]=2&foo[]=3
+queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'index'});
+//=> 'foo[0]=1&foo[1]=2&foo[3]=3'
```
-- `index`: stands for parsing taking the index into account, such as:
+- `comma`: Serialize arrays by separating elements with comma:
```js
-queryString.stringify({foo: [1,2,3]}, {arrayFormat: 'index'});
-// => foo[0]=1&foo[1]=2&foo[3]=3
+queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'comma'});
+//=> 'foo=1,2,3'
```
-- `none`: is the __default__ option and removes any bracket representation, such as:
+- `none`: Serialize arrays by using duplicate keys:
```js
-queryString.stringify({foo: [1,2,3]});
-// => foo=1&foo=2&foo=3
+queryString.stringify({foo: [1, 2, 3]});
+//=> 'foo=1&foo=2&foo=3'
```
-#### sort
+##### sort
-Type: `Function` `boolean`
+Type: `Function | boolean`
Supports both `Function` as a custom sorting function or `false` to disable sorting.
```js
const order = ['c', 'a', 'b'];
-queryString.stringify({ a: 1, b: 2, c: 3}, {
- sort: (m, n) => order.indexOf(m) >= order.indexOf(n)
+
+queryString.stringify({a: 1, b: 2, c: 3}, {
+ sort: (a, b) => order.indexOf(a) - order.indexOf(b)
});
-// => 'c=3&a=1&b=2'
+//=> 'c=3&a=1&b=2'
```
```js
-queryString.stringify({ b: 1, c: 2, a: 3}, {sort: false});
-// => 'c=3&a=1&b=2'
+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.
+If omitted, keys are sorted using `Array#sort()`, which means, converting them to strings and comparing strings in Unicode code point order.
-### .extract(*string*)
+### .extract(string)
Extract a query string from a URL that can be passed into `.parse()`.
-### .parseUrl(*string*, *[options]*)
+### .parseUrl(string, [options])
Extract the URL and the query string as an object.