diff options
Diffstat (limited to 'node_modules/query-string')
| -rw-r--r-- | node_modules/query-string/index.js | 205 | ||||
| -rw-r--r-- | node_modules/query-string/license | 21 | ||||
| -rw-r--r-- | node_modules/query-string/package.json | 44 | ||||
| -rw-r--r-- | node_modules/query-string/readme.md | 184 |
4 files changed, 0 insertions, 454 deletions
diff --git a/node_modules/query-string/index.js b/node_modules/query-string/index.js deleted file mode 100644 index 2d22df2a..00000000 --- a/node_modules/query-string/index.js +++ /dev/null @@ -1,205 +0,0 @@ -'use strict'; -var strictUriEncode = require('strict-uri-encode'); -var objectAssign = require('object-assign'); - -function encoderForArrayFormat(opts) { - switch (opts.arrayFormat) { - case 'index': - return function (key, value, index) { - return value === null ? [ - encode(key, opts), - '[', - index, - ']' - ].join('') : [ - encode(key, opts), - '[', - encode(index, opts), - ']=', - encode(value, opts) - ].join(''); - }; - - case 'bracket': - return function (key, value) { - return value === null ? encode(key, opts) : [ - encode(key, opts), - '[]=', - encode(value, opts) - ].join(''); - }; - - default: - return function (key, value) { - return value === null ? encode(key, opts) : [ - encode(key, opts), - '=', - encode(value, opts) - ].join(''); - }; - } -} - -function parserForArrayFormat(opts) { - var result; - - switch (opts.arrayFormat) { - case 'index': - return function (key, value, accumulator) { - result = /\[(\d*)\]$/.exec(key); - - key = key.replace(/\[\d*\]$/, ''); - - if (!result) { - accumulator[key] = value; - return; - } - - if (accumulator[key] === undefined) { - accumulator[key] = {}; - } - - accumulator[key][result[1]] = value; - }; - - case 'bracket': - return function (key, value, accumulator) { - result = /(\[\])$/.exec(key); - key = key.replace(/\[\]$/, ''); - - if (!result) { - accumulator[key] = value; - return; - } else if (accumulator[key] === undefined) { - accumulator[key] = [value]; - return; - } - - accumulator[key] = [].concat(accumulator[key], value); - }; - - default: - return function (key, value, accumulator) { - if (accumulator[key] === undefined) { - accumulator[key] = value; - return; - } - - accumulator[key] = [].concat(accumulator[key], value); - }; - } -} - -function encode(value, opts) { - if (opts.encode) { - return opts.strict ? strictUriEncode(value) : encodeURIComponent(value); - } - - return value; -} - -function keysSorter(input) { - if (Array.isArray(input)) { - return input.sort(); - } else if (typeof input === 'object') { - return keysSorter(Object.keys(input)).sort(function (a, b) { - return Number(a) - Number(b); - }).map(function (key) { - return input[key]; - }); - } - - return input; -} - -exports.extract = function (str) { - return str.split('?')[1] || ''; -}; - -exports.parse = function (str, opts) { - opts = objectAssign({arrayFormat: 'none'}, opts); - - var formatter = parserForArrayFormat(opts); - - // Create an object with no prototype - // https://github.com/sindresorhus/query-string/issues/47 - var ret = Object.create(null); - - if (typeof str !== 'string') { - return ret; - } - - str = str.trim().replace(/^(\?|#|&)/, ''); - - if (!str) { - return ret; - } - - str.split('&').forEach(function (param) { - var parts = param.replace(/\+/g, ' ').split('='); - // Firefox (pre 40) decodes `%3D` to `=` - // https://github.com/sindresorhus/query-string/pull/37 - var key = parts.shift(); - var val = parts.length > 0 ? parts.join('=') : undefined; - - // missing `=` should be `null`: - // http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters - val = val === undefined ? null : decodeURIComponent(val); - - formatter(decodeURIComponent(key), val, ret); - }); - - return Object.keys(ret).sort().reduce(function (result, key) { - var val = ret[key]; - if (Boolean(val) && typeof val === 'object' && !Array.isArray(val)) { - // Sort object keys, not values - result[key] = keysSorter(val); - } else { - result[key] = val; - } - - return result; - }, Object.create(null)); -}; - -exports.stringify = function (obj, opts) { - var defaults = { - encode: true, - strict: true, - arrayFormat: 'none' - }; - - opts = objectAssign(defaults, opts); - - var formatter = encoderForArrayFormat(opts); - - return obj ? Object.keys(obj).sort().map(function (key) { - var val = obj[key]; - - if (val === undefined) { - return ''; - } - - if (val === null) { - return encode(key, opts); - } - - if (Array.isArray(val)) { - var result = []; - - val.slice().forEach(function (val2) { - if (val2 === undefined) { - return; - } - - result.push(formatter(key, val2, result.length)); - }); - - return result.join('&'); - } - - return encode(key, opts) + '=' + encode(val, opts); - }).filter(function (x) { - return x.length > 0; - }).join('&') : ''; -}; diff --git a/node_modules/query-string/license b/node_modules/query-string/license deleted file mode 100644 index 654d0bfe..00000000 --- a/node_modules/query-string/license +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/node_modules/query-string/package.json b/node_modules/query-string/package.json deleted file mode 100644 index f3cc9d14..00000000 --- a/node_modules/query-string/package.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "name": "query-string", - "version": "4.3.4", - "description": "Parse and stringify URL query strings", - "license": "MIT", - "repository": "sindresorhus/query-string", - "author": { - "name": "Sindre Sorhus", - "email": "sindresorhus@gmail.com", - "url": "sindresorhus.com" - }, - "engines": { - "node": ">=0.10.0" - }, - "scripts": { - "test": "xo && ava" - }, - "files": [ - "index.js" - ], - "keywords": [ - "browser", - "querystring", - "query", - "string", - "qs", - "param", - "parameter", - "url", - "uri", - "parse", - "stringify", - "encode", - "decode" - ], - "dependencies": { - "object-assign": "^4.1.0", - "strict-uri-encode": "^1.0.0" - }, - "devDependencies": { - "ava": "^0.17.0", - "xo": "^0.16.0" - } -} diff --git a/node_modules/query-string/readme.md b/node_modules/query-string/readme.md deleted file mode 100644 index f8ac0da3..00000000 --- a/node_modules/query-string/readme.md +++ /dev/null @@ -1,184 +0,0 @@ -# query-string [](https://travis-ci.org/sindresorhus/query-string) - -> Parse and stringify URL [query strings](http://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. You might also like his <a href="https://ReactForBeginners.com/friend/AWESOME">React course</a>.</p> - ---- - - -## Install - -``` -$ npm install --save query-string -``` - - -## Usage - -```js -const queryString = require('query-string'); - -console.log(location.search); -//=> '?foo=bar' - -const parsed = queryString.parse(location.search); -console.log(parsed); -//=> {foo: 'bar'} - -console.log(location.hash); -//=> '#token=bada55cafe' - -const parsedHash = queryString.parse(location.hash); -console.log(parsedHash); -//=> {token: 'bada55cafe'} - -parsed.foo = 'unicorn'; -parsed.ilike = 'pizza'; - -const stringified = queryString.stringify(parsed); -//=> 'foo=unicorn&ilike=pizza' - -location.search = stringified; -// note that `location.search` automatically prepends a question mark -console.log(location.search); -//=> '?foo=unicorn&ilike=pizza' -``` - - -## API - -### .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`. - -#### arrayFormat - -Type: `string`<br> -Default: `'none'` - -Supports both `index` for an indexed array representation or `bracket` for a *bracketed* array representation. - -- `bracket`: stands for parsing correctly arrays with bracket representation on the query string, such as: - -```js -queryString.parse('foo[]=1&foo[]=2&foo[]=3', {arrayFormat: 'bracket'}); -//=> foo: [1,2,3] -``` - -- `index`: stands for parsing taking the index into account, such as: - -```js -queryString.parse('foo[0]=1&foo[1]=2&foo[3]=3', {arrayFormat: 'index'}); -//=> foo: [1,2,3] -``` - -- `none`: is the **default** option and removes any bracket representation, such as: - -```js -queryString.parse('foo=1&foo=2&foo=3'); -//=> foo: [1,2,3] -``` - -### .stringify(*object*, *[options]*) - -Stringify an object into a query string, sorting the keys. - -#### 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. - -#### 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 - -Type: `string`<br> -Default: `'none'` - -Supports both `index` for an indexed array representation or `bracket` for a *bracketed* array 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`: stands for parsing taking the index into account, such as: - -```js -queryString.stringify({foo: [1,2,3]}, {arrayFormat: 'index'}); -// => foo[0]=1&foo[1]=2&foo[3]=3 -``` - -- `none`: is the __default__ option and removes any bracket representation, such as: - -```js -queryString.stringify({foo: [1,2,3]}); -// => foo=1&foo=2&foo=3 -``` - -### .extract(*string*) - -Extract a query string from a URL that can be passed into `.parse()`. - - -## Nesting - -This module intentionally doesn't support nesting as it's not spec'd and varies between implementations, which causes a lot of [edge cases](https://github.com/visionmedia/node-querystring/issues). - -You're much better off just converting the object to a JSON string: - -```js -queryString.stringify({ - foo: 'bar', - nested: JSON.stringify({ - unicorn: 'cake' - }) -}); -//=> 'foo=bar&nested=%7B%22unicorn%22%3A%22cake%22%7D' -``` - -However, there is support for multiple instances of the same key: - -```js -queryString.parse('likes=cake&name=bob&likes=icecream'); -//=> {likes: ['cake', 'icecream'], name: 'bob'} - -queryString.stringify({color: ['taupe', 'chartreuse'], id: '515'}); -//=> 'color=chartreuse&color=taupe&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 -queryString.stringify({foo: false}); -//=> 'foo=false' - -queryString.stringify({foo: null}); -//=> 'foo' - -queryString.stringify({foo: undefined}); -//=> '' -``` - - -## License - -MIT © [Sindre Sorhus](https://sindresorhus.com) |
