From 47b08b3b9860438b416efb438e975a628ec2eed5 Mon Sep 17 00:00:00 2001 From: Audrey Eschright Date: Tue, 19 Mar 2019 11:54:04 -0700 Subject: [PATCH] query-string@6.4.0 --- node_modules/query-string/index.d.ts | 143 +++++++++++++++++++++++++ node_modules/query-string/index.js | 110 ++++++++++++------- node_modules/query-string/package.json | 30 +++--- node_modules/query-string/readme.md | 108 ++++++++++--------- package-lock.json | 6 +- package.json | 2 +- 6 files changed, 292 insertions(+), 107 deletions(-) create mode 100644 node_modules/query-string/index.d.ts diff --git a/node_modules/query-string/index.d.ts b/node_modules/query-string/index.d.ts new file mode 100644 index 0000000000000..90b3658aee108 --- /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 6a1b3c2a30eb6..3cb1adf8d3045 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 8f9b91b4fba93..cd62b3cf54fba 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 5fa1cfbde4306..fda9323cdecf9 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) ---- - -

🔥 Want to strengthen your core JavaScript skills and master ES6?
I would personally recommend this awesome ES6 course by Wes Bos.
Also check out his Node.js, React, Sublime courses.

- ---- - ## 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`. @@ -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`
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`
-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`
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`
Default: `true` [URL encode](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) the keys and values. -#### arrayFormat +##### arrayFormat Type: `string`
-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. diff --git a/package-lock.json b/package-lock.json index 8dc65aaf0a66e..18d580d29a9f8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5175,9 +5175,9 @@ "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==" }, "query-string": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/query-string/-/query-string-6.2.0.tgz", - "integrity": "sha512-5wupExkIt8RYL4h/FE+WTg3JHk62e6fFPWtAZA9J5IWK1PfTfKkMS93HBUHcFpeYi9KsY5pFbh+ldvEyaz5MyA==", + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/query-string/-/query-string-6.4.0.tgz", + "integrity": "sha512-Werid2I41/tJTqOGPJ3cC3vwrIh/8ZupBQbp7BSsqXzr+pTin3aMJ/EZb8UEuk7ZO3VqQFvq2qck/ihc6wqIdw==", "requires": { "decode-uri-component": "^0.2.0", "strict-uri-encode": "^2.0.0" diff --git a/package.json b/package.json index 0c9699c9e8a14..504fbaecaa5c7 100644 --- a/package.json +++ b/package.json @@ -108,7 +108,7 @@ "path-is-inside": "~1.0.2", "promise-inflight": "~1.0.1", "qrcode-terminal": "^0.12.0", - "query-string": "^6.2.0", + "query-string": "^6.4.0", "qw": "~1.0.1", "read": "~1.0.7", "read-cmd-shim": "~1.0.1",