芝麻web文件管理V1.00
编辑当前文件:/home/conskgoa/doughi.co.uk/query-string.zip
PK Ǜ\_ index.d.tsnu [ 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'; /** 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. @default true @example ``` const order = ['c', 'a', 'b']; queryString.parse('?a=one&b=two&c=three', { sort: (itemLeft, itemRight) => order.indexOf(itemLeft) - order.indexOf(itemRight) }); // => {c: 'three', a: 'one', b: 'two'} ``` queryString.parse('?a=one&c=three&b=two', {sort: false}); // => {a: 'one', c: 'three', b: 'two'} ``` */ readonly sort?: ((itemLeft: string, itemRight: string) => number) | false; /** Parse the value as a number type instead of string type if it's a number. @default false @example ```js queryString.parse('foo=1', {parseNumbers: true}); //=> {foo: 1} ``` */ readonly parseNumbers?: boolean; /** Parse the value as a boolean type instead of string type if it's a boolean. @default false @example ``` queryString.parse('foo=true', {parseBooleans: true}); //=> {foo: true} ``` */ readonly parseBooleans?: boolean; } export interface ParsedQuery
{ [key: string]: T | T[] | 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: {parseBooleans: true, parseNumbers: true} & ParseOptions): ParsedQuery
; export function parse(query: string, options: {parseBooleans: true} & ParseOptions): ParsedQuery
; export function parse(query: string, options: {parseNumbers: true} & ParseOptions): ParsedQuery
; 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[2]=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. @default true @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 sort the keys. */ export function stringify( object: {[key: string]: any}, options?: StringifyOptions ): string; /** Extract a query string from a URL that can be passed into `.parse()`. */ export function extract(url: string): string; PK Ǜ\)k index.jsnu [ 'use strict'; const strictUriEncode = require('strict-uri-encode'); const decodeComponent = require('decode-uri-component'); const splitOnFirst = require('split-on-first'); function encoderForArrayFormat(options) { switch (options.arrayFormat) { case 'index': 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 => (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 === null || value === undefined || value.length === 0) { return result; } if (index === 0) { return [[encode(key, options), '=', encode(value, options)].join('')]; } return [[result, encode(value, options)].join(',')]; }; default: 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('')]; }; } } function parserForArrayFormat(options) { let result; switch (options.arrayFormat) { case 'index': return (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 (key, value, accumulator) => { result = /(\[\])$/.exec(key); key = key.replace(/\[\]$/, ''); if (!result) { accumulator[key] = value; return; } if (accumulator[key] === undefined) { accumulator[key] = [value]; return; } 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) { accumulator[key] = value; return; } accumulator[key] = [].concat(accumulator[key], value); }; } } function encode(value, options) { if (options.encode) { return options.strict ? strictUriEncode(value) : encodeURIComponent(value); } return value; } function decode(value, options) { if (options.decode) { return decodeComponent(value); } return value; } function keysSorter(input) { if (Array.isArray(input)) { return input.sort(); } if (typeof input === 'object') { return keysSorter(Object.keys(input)) .sort((a, b) => Number(a) - Number(b)) .map(key => input[key]); } return input; } function removeHash(input) { const hashStart = input.indexOf('#'); if (hashStart !== -1) { input = input.slice(0, hashStart); } return input; } function extract(input) { input = removeHash(input); const queryStart = input.indexOf('?'); if (queryStart === -1) { return ''; } return input.slice(queryStart + 1); } function parse(input, options) { options = Object.assign({ decode: true, sort: true, arrayFormat: 'none', parseNumbers: false, parseBooleans: false }, options); const formatter = parserForArrayFormat(options); // Create an object with no prototype const ret = Object.create(null); if (typeof input !== 'string') { return ret; } input = input.trim().replace(/^[?#&]/, ''); if (!input) { return ret; } for (const param of input.split('&')) { let [key, value] = splitOnFirst(param.replace(/\+/g, ' '), '='); // Missing `=` should be `null`: // http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters value = value === undefined ? null : decode(value, options); if (options.parseNumbers && !Number.isNaN(Number(value)) && (typeof value === 'string' && value.trim() !== '')) { value = Number(value); } else if (options.parseBooleans && value !== null && (value.toLowerCase() === 'true' || value.toLowerCase() === 'false')) { value = value.toLowerCase() === 'true'; } formatter(decode(key, options), value, ret); } if (options.sort === false) { return ret; } return (options.sort === true ? Object.keys(ret).sort() : Object.keys(ret).sort(options.sort)).reduce((result, key) => { const value = ret[key]; if (Boolean(value) && typeof value === 'object' && !Array.isArray(value)) { // Sort object keys, not values result[key] = keysSorter(value); } else { result[key] = value; } return result; }, Object.create(null)); } exports.extract = extract; exports.parse = parse; exports.stringify = (object, options) => { if (!object) { return ''; } options = Object.assign({ encode: true, strict: true, arrayFormat: 'none' }, options); const formatter = encoderForArrayFormat(options); const keys = Object.keys(object); if (options.sort !== false) { keys.sort(options.sort); } return keys.map(key => { const value = object[key]; if (value === undefined) { return ''; } if (value === null) { return encode(key, options); } if (Array.isArray(value)) { return value .reduce(formatter(key), []) .join('&'); } return encode(key, options) + '=' + encode(value, options); }).filter(x => x.length > 0).join('&'); }; exports.parseUrl = (input, options) => { return { url: removeHash(input).split('?')[0] || '', query: parse(extract(input), options) }; }; PK Ǜ\f readme.mdnu [ # query-string [](https://travis-ci.org/sindresorhus/query-string) > Parse and stringify URL [query strings](https://en.wikipedia.org/wiki/Query_string) ## Install ``` $ 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`. ## 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`. #### options Type: `object` ##### decode 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`
Default: `'none'` - `'bracket'`: Parse arrays with bracket representation: ```js queryString.parse('foo[]=1&foo[]=2&foo[]=3', {arrayFormat: 'bracket'}); //=> {foo: ['1', '2', '3']} ``` - `'index'`: Parse arrays with index representation: ```js 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: ```js queryString.parse('foo=1,2,3', {arrayFormat: 'comma'}); //=> {foo: ['1', '2', '3']} ``` - `'none'`: Parse arrays with elements using duplicate keys: ```js queryString.parse('foo=1&foo=2&foo=3'); //=> {foo: ['1', '2', '3']} ``` ##### sort Type: `Function | boolean`
Default: `true` Supports both `Function` as a custom sorting function or `false` to disable sorting. ##### parseNumbers Type: `boolean`
Default: `false` ```js queryString.parse('foo=1', {parseNumbers: true}); //=> {foo: 1} ``` Parse the value as a number type instead of string type if it's a number. ##### parseBooleans Type: `boolean`
Default: `false` ```js 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 an object into a query string and sorting the keys. #### options Type: `object` ##### 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. ##### encode 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`
Default: `'none'` - `'bracket'`: Serialize arrays using bracket representation: ```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: 'index'}); //=> 'foo[0]=1&foo[1]=2&foo[2]=3' ``` - `'comma'`: Serialize arrays by separating elements with comma: ```js queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'comma'}); //=> 'foo=1,2,3' ``` - `'none'`: Serialize arrays by using duplicate keys: ```js queryString.stringify({foo: [1, 2, 3]}); //=> 'foo=1&foo=2&foo=3' ``` ##### sort 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: (a, b) => order.indexOf(a) - order.indexOf(b) }); //=> 'c=3&a=1&b=2' ``` ```js 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. ### .extract(string) Extract a query string from a URL that can be passed into `.parse()`. ### .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. ```js queryString.parseUrl('https://foo.bar?foo=bar'); //=> {url: 'https://foo.bar', query: {foo: 'bar'}} ``` ## 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=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 queryString.stringify({foo: false}); //=> 'foo=false' queryString.stringify({foo: null}); //=> 'foo' queryString.stringify({foo: undefined}); //=> '' ``` ---
Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
PK Ǜ\n>\ package.jsonnu [ { "_from": "query-string@6.8.2", "_id": "query-string@6.8.2", "_inBundle": false, "_integrity": "sha512-J3Qi8XZJXh93t2FiKyd/7Ec6GNifsjKXUsVFkSBj/kjLsDylWhnCz4NT1bkPcKotttPW+QbKGqqPH8OoI2pdqw==", "_location": "/query-string", "_phantomChildren": {}, "_requested": { "type": "version", "registry": true, "raw": "query-string@6.8.2", "name": "query-string", "escapedName": "query-string", "rawSpec": "6.8.2", "saveSpec": null, "fetchSpec": "6.8.2" }, "_requiredBy": [ "#USER", "/" ], "_resolved": "https://registry.npmjs.org/query-string/-/query-string-6.8.2.tgz", "_shasum": "36cb7e452ae11a4b5e9efee83375e0954407b2f6", "_spec": "query-string@6.8.2", "_where": "/Users/isaacs/dev/npm/cli", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "bugs": { "url": "https://github.com/sindresorhus/query-string/issues" }, "bundleDependencies": false, "dependencies": { "decode-uri-component": "^0.2.0", "split-on-first": "^1.0.0", "strict-uri-encode": "^2.0.0" }, "deprecated": false, "description": "Parse and stringify URL query strings", "devDependencies": { "ava": "^1.4.1", "deep-equal": "^1.0.1", "fast-check": "^1.5.0", "tsd": "^0.7.3", "xo": "^0.24.0" }, "engines": { "node": ">=6" }, "files": [ "index.js", "index.d.ts" ], "homepage": "https://github.com/sindresorhus/query-string#readme", "keywords": [ "browser", "querystring", "query", "string", "qs", "param", "parameter", "url", "parse", "stringify", "encode", "decode", "searchparams" ], "license": "MIT", "name": "query-string", "repository": { "type": "git", "url": "git+https://github.com/sindresorhus/query-string.git" }, "scripts": { "test": "xo && ava && tsd" }, "version": "6.8.2" } PK Ǜ\E}U U licensenu [ MIT License Copyright (c) Sindre Sorhus
(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. PK Ǜ\_ index.d.tsnu [ PK Ǜ\)k W index.jsnu [ PK Ǜ\f . readme.mdnu [ PK Ǜ\n>\ XI package.jsonnu [ PK Ǜ\E}U U %Q licensenu [ PK n U