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.