query-string
Advanced tools
Comparing version 7.0.1 to 7.1.0
@@ -72,2 +72,11 @@ export interface ParseOptions { | ||
- `colon-list-separator`: Parse arrays with parameter names that are explicitly marked with `:list`: | ||
``` | ||
import queryString = require('query-string'); | ||
queryString.parse('foo:list=one&foo:list=two', {arrayFormat: 'colon-list-separator'}); | ||
//=> {foo: ['one', 'two']} | ||
``` | ||
- `none`: Parse arrays with elements using duplicate keys: | ||
@@ -82,3 +91,3 @@ | ||
*/ | ||
readonly arrayFormat?: 'bracket' | 'index' | 'comma' | 'separator' | 'bracket-separator' | 'none'; | ||
readonly arrayFormat?: 'bracket' | 'index' | 'comma' | 'separator' | 'bracket-separator' | 'colon-list-separator' | 'none'; | ||
@@ -301,2 +310,11 @@ /** | ||
- `colon-list-separator`: Serialize arrays with parameter names that are explicitly marked with `:list`: | ||
```js | ||
import queryString = require('query-string'); | ||
queryString.stringify({foo: ['one', 'two']}, {arrayFormat: 'colon-list-separator'}); | ||
//=> 'foo:list=one&foo:list=two' | ||
``` | ||
- `none`: Serialize arrays by using duplicate keys: | ||
@@ -311,3 +329,3 @@ | ||
*/ | ||
readonly arrayFormat?: 'bracket' | 'index' | 'comma' | 'separator' | 'bracket-separator' | 'none'; | ||
readonly arrayFormat?: 'bracket' | 'index' | 'comma' | 'separator' | 'bracket-separator' | 'colon-list-separator' | 'none'; | ||
@@ -314,0 +332,0 @@ /** |
35
index.js
@@ -52,2 +52,19 @@ 'use strict'; | ||
case 'colon-list-separator': | ||
return key => (result, value) => { | ||
if ( | ||
value === undefined || | ||
(options.skipNull && value === null) || | ||
(options.skipEmptyString && value === '') | ||
) { | ||
return result; | ||
} | ||
if (value === null) { | ||
return [...result, [encode(key, options), ':list='].join('')]; | ||
} | ||
return [...result, [encode(key, options), ':list=', encode(value, options)].join('')]; | ||
}; | ||
case 'comma': | ||
@@ -139,2 +156,20 @@ case 'separator': | ||
case 'colon-list-separator': | ||
return (key, value, accumulator) => { | ||
result = /(:list)$/.exec(key); | ||
key = key.replace(/:list$/, ''); | ||
if (!result) { | ||
accumulator[key] = value; | ||
return; | ||
} | ||
if (accumulator[key] === undefined) { | ||
accumulator[key] = [value]; | ||
return; | ||
} | ||
accumulator[key] = [].concat(accumulator[key], value); | ||
}; | ||
case 'comma': | ||
@@ -141,0 +176,0 @@ case 'separator': |
{ | ||
"name": "query-string", | ||
"version": "7.0.1", | ||
"version": "7.1.0", | ||
"description": "Parse and stringify URL query strings", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -187,2 +187,11 @@ # query-string | ||
- `'colon-list-separator'`: Parse arrays with parameter names that are explicitly marked with `:list`: | ||
```js | ||
const queryString = require('query-string'); | ||
queryString.parse('foo:list=one&foo:list=two', {arrayFormat: 'colon-list-separator'}); | ||
//=> {foo: ['one', 'two']} | ||
``` | ||
- `'none'`: Parse arrays with elements using duplicate keys: | ||
@@ -334,2 +343,11 @@ | ||
- `'colon-list-separator'`: Serialize arrays with parameter names that are explicitly marked with `:list`: | ||
```js | ||
const queryString = require('query-string'); | ||
queryString.stringify({foo: ['one', 'two']}, {arrayFormat: 'colon-list-separator'}); | ||
//=> 'foo:list=one&foo:list=two' | ||
``` | ||
- `'none'`: Serialize arrays by using duplicate keys: | ||
@@ -336,0 +354,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46750
804
652