query-string 7.0.1 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -69,6 +69,15 @@ export interface ParseOptions {
69
69
  //=> {foo: ['1', '2', '3'], bar: 'fluffy', baz:['4']}
70
70
  ```
71
71
 
72
+ - `colon-list-separator`: Parse arrays with parameter names that are explicitly marked with `:list`:
73
+
74
+ ```
75
+ import queryString = require('query-string');
76
+
77
+ queryString.parse('foo:list=one&foo:list=two', {arrayFormat: 'colon-list-separator'});
78
+ //=> {foo: ['one', 'two']}
79
+ ```
80
+
72
81
  - `none`: Parse arrays with elements using duplicate keys:
73
82
 
74
83
  ```
@@ -78,7 +87,7 @@ export interface ParseOptions {
78
87
  //=> {foo: ['1', '2', '3']}
79
88
  ```
80
89
  */
81
- readonly arrayFormat?: 'bracket' | 'index' | 'comma' | 'separator' | 'bracket-separator' | 'none';
90
+ readonly arrayFormat?: 'bracket' | 'index' | 'comma' | 'separator' | 'bracket-separator' | 'colon-list-separator' | 'none';
82
91
 
83
92
  /**
84
93
  The character used to separate array elements when using `{arrayFormat: 'separator'}`.
@@ -296,6 +305,15 @@ export interface StringifyOptions {
296
305
  //=> 'foo[]=1|2|3&bar=fluffy&baz[]=4'
297
306
  ```
298
307
 
308
+ - `colon-list-separator`: Serialize arrays with parameter names that are explicitly marked with `:list`:
309
+
310
+ ```js
311
+ import queryString = require('query-string');
312
+
313
+ queryString.stringify({foo: ['one', 'two']}, {arrayFormat: 'colon-list-separator'});
314
+ //=> 'foo:list=one&foo:list=two'
315
+ ```
316
+
299
317
  - `none`: Serialize arrays by using duplicate keys:
300
318
 
301
319
  ```
@@ -305,7 +323,7 @@ export interface StringifyOptions {
305
323
  //=> 'foo=1&foo=2&foo=3'
306
324
  ```
307
325
  */
308
- readonly arrayFormat?: 'bracket' | 'index' | 'comma' | 'separator' | 'bracket-separator' | 'none';
326
+ readonly arrayFormat?: 'bracket' | 'index' | 'comma' | 'separator' | 'bracket-separator' | 'colon-list-separator' | 'none';
309
327
 
310
328
  /**
311
329
  The character used to separate array elements when using `{arrayFormat: 'separator'}`.
package/index.js CHANGED
@@ -49,6 +49,23 @@ function encoderForArrayFormat(options) {
49
49
  return [...result, [encode(key, options), '[]=', encode(value, options)].join('')];
50
50
  };
51
51
 
52
+ case 'colon-list-separator':
53
+ return key => (result, value) => {
54
+ if (
55
+ value === undefined ||
56
+ (options.skipNull && value === null) ||
57
+ (options.skipEmptyString && value === '')
58
+ ) {
59
+ return result;
60
+ }
61
+
62
+ if (value === null) {
63
+ return [...result, [encode(key, options), ':list='].join('')];
64
+ }
65
+
66
+ return [...result, [encode(key, options), ':list=', encode(value, options)].join('')];
67
+ };
68
+
52
69
  case 'comma':
53
70
  case 'separator':
54
71
  case 'bracket-separator': {
@@ -135,6 +152,24 @@ function parserForArrayFormat(options) {
135
152
  accumulator[key] = [].concat(accumulator[key], value);
136
153
  };
137
154
 
155
+ case 'colon-list-separator':
156
+ return (key, value, accumulator) => {
157
+ result = /(:list)$/.exec(key);
158
+ key = key.replace(/:list$/, '');
159
+
160
+ if (!result) {
161
+ accumulator[key] = value;
162
+ return;
163
+ }
164
+
165
+ if (accumulator[key] === undefined) {
166
+ accumulator[key] = [value];
167
+ return;
168
+ }
169
+
170
+ accumulator[key] = [].concat(accumulator[key], value);
171
+ };
172
+
138
173
  case 'comma':
139
174
  case 'separator':
140
175
  return (key, value, accumulator) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "query-string",
3
- "version": "7.0.1",
3
+ "version": "7.1.0",
4
4
  "description": "Parse and stringify URL query strings",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/query-string",
package/readme.md CHANGED
@@ -184,6 +184,15 @@ queryString.parse('foo[]=1|2|3&bar=fluffy&baz[]=4', {arrayFormat: 'bracket-separ
184
184
  //=> {foo: ['1', '2', '3'], bar: 'fluffy', baz:['4']}
185
185
  ```
186
186
 
187
+ - `'colon-list-separator'`: Parse arrays with parameter names that are explicitly marked with `:list`:
188
+
189
+ ```js
190
+ const queryString = require('query-string');
191
+
192
+ queryString.parse('foo:list=one&foo:list=two', {arrayFormat: 'colon-list-separator'});
193
+ //=> {foo: ['one', 'two']}
194
+ ```
195
+
187
196
  - `'none'`: Parse arrays with elements using duplicate keys:
188
197
 
189
198
  ```js
@@ -330,6 +339,15 @@ queryString.stringify({foo: [1, 2, 3], bar: 'fluffy', baz: [4]}, {arrayFormat: '
330
339
  //=> 'foo[]=1|2|3&bar=fluffy&baz[]=4'
331
340
  ```
332
341
 
342
+ - `'colon-list-separator'`: Serialize arrays with parameter names that are explicitly marked with `:list`:
343
+
344
+ ```js
345
+ const queryString = require('query-string');
346
+
347
+ queryString.stringify({foo: ['one', 'two']}, {arrayFormat: 'colon-list-separator'});
348
+ //=> 'foo:list=one&foo:list=two'
349
+ ```
350
+
333
351
  - `'none'`: Serialize arrays by using duplicate keys:
334
352
 
335
353
  ```js