query-string 9.1.0 → 9.1.2
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/base.js +11 -3
- package/package.json +1 -1
- package/readme.md +6 -42
package/base.js
CHANGED
|
@@ -221,7 +221,7 @@ function parserForArrayFormat(options) {
|
|
|
221
221
|
|
|
222
222
|
const arrayValue = value === null
|
|
223
223
|
? []
|
|
224
|
-
: value.split(options.arrayFormatSeparator)
|
|
224
|
+
: decode(value, options).split(options.arrayFormatSeparator);
|
|
225
225
|
|
|
226
226
|
if (accumulator[key] === undefined) {
|
|
227
227
|
accumulator[key] = arrayValue;
|
|
@@ -309,14 +309,22 @@ function parseValue(value, options, type) {
|
|
|
309
309
|
return type(value);
|
|
310
310
|
}
|
|
311
311
|
|
|
312
|
-
if (
|
|
313
|
-
return value
|
|
312
|
+
if (type === 'string[]' && options.arrayFormat !== 'none' && typeof value === 'string') {
|
|
313
|
+
return [value];
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (type === 'number[]' && options.arrayFormat !== 'none' && !Number.isNaN(Number(value)) && (typeof value === 'string' && value.trim() !== '')) {
|
|
317
|
+
return [Number(value)];
|
|
314
318
|
}
|
|
315
319
|
|
|
316
320
|
if (type === 'number' && !Number.isNaN(Number(value)) && (typeof value === 'string' && value.trim() !== '')) {
|
|
317
321
|
return Number(value);
|
|
318
322
|
}
|
|
319
323
|
|
|
324
|
+
if (options.parseBooleans && value !== null && (value.toLowerCase() === 'true' || value.toLowerCase() === 'false')) {
|
|
325
|
+
return value.toLowerCase() === 'true';
|
|
326
|
+
}
|
|
327
|
+
|
|
320
328
|
if (options.parseNumbers && !Number.isNaN(Number(value)) && (typeof value === 'string' && value.trim() !== '')) {
|
|
321
329
|
return Number(value);
|
|
322
330
|
}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -2,42 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
> Parse and stringify URL [query strings](https://en.wikipedia.org/wiki/Query_string)
|
|
4
4
|
|
|
5
|
-
<br>
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
<div align="center">
|
|
10
|
-
<p>
|
|
11
|
-
<p>
|
|
12
|
-
<sup>
|
|
13
|
-
<a href="https://github.com/sponsors/sindresorhus">My open source work is supported by the community</a>
|
|
14
|
-
</sup>
|
|
15
|
-
</p>
|
|
16
|
-
<sup>Special thanks to:</sup>
|
|
17
|
-
<br>
|
|
18
|
-
<br>
|
|
19
|
-
<a href="https://standardresume.co/tech">
|
|
20
|
-
<img src="https://sindresorhus.com/assets/thanks/standard-resume-logo.svg" width="180"/>
|
|
21
|
-
</a>
|
|
22
|
-
<br>
|
|
23
|
-
<br>
|
|
24
|
-
<br>
|
|
25
|
-
<a href="https://strapi.io/?ref=sindresorhus">
|
|
26
|
-
<div>
|
|
27
|
-
<img src="https://sindresorhus.com/assets/thanks/strapi-logo-white-bg.png" width="200" alt="Strapi">
|
|
28
|
-
</div>
|
|
29
|
-
<b>Strapi is the leading open-source headless CMS.</b>
|
|
30
|
-
<div>
|
|
31
|
-
<sup>It’s 100% JavaScript, fully customizable, and developer-first.</sup>
|
|
32
|
-
</div>
|
|
33
|
-
</a>
|
|
34
|
-
</p>
|
|
35
|
-
</div>
|
|
36
|
-
|
|
37
|
-
---
|
|
38
|
-
|
|
39
|
-
<br>
|
|
40
|
-
|
|
41
5
|
## Install
|
|
42
6
|
|
|
43
7
|
```sh
|
|
@@ -229,7 +193,7 @@ Parse the value as a boolean type instead of string type if it's a boolean.
|
|
|
229
193
|
Type: `object`\
|
|
230
194
|
Default: `{}`
|
|
231
195
|
|
|
232
|
-
Specify a pre-defined schema to be used when parsing values. The types specified will take precedence over options such as: `
|
|
196
|
+
Specify a pre-defined schema to be used when parsing values. The types specified will take precedence over options such as: `parseNumbers`, `parseBooleans`, and `arrayFormat`.
|
|
233
197
|
|
|
234
198
|
Use this feature to override the type of a value. This can be useful when the type is ambiguous such as a phone number.
|
|
235
199
|
|
|
@@ -237,7 +201,7 @@ It is possible to provide a custom function as the parameter type. The parameter
|
|
|
237
201
|
|
|
238
202
|
Supported Types:
|
|
239
203
|
|
|
240
|
-
- `'string'`: Parse `phoneNumber` as a string (overriding the `
|
|
204
|
+
- `'string'`: Parse `phoneNumber` as a string (overriding the `parseNumbers` option):
|
|
241
205
|
|
|
242
206
|
```js
|
|
243
207
|
import queryString from 'query-string';
|
|
@@ -251,7 +215,7 @@ queryString.parse('?phoneNumber=%2B380951234567&id=1', {
|
|
|
251
215
|
//=> {phoneNumber: '+380951234567', id: 1}
|
|
252
216
|
```
|
|
253
217
|
|
|
254
|
-
- `'number'`: Parse `age` as a number (even when `
|
|
218
|
+
- `'number'`: Parse `age` as a number (even when `parseNumbers` is false):
|
|
255
219
|
|
|
256
220
|
```js
|
|
257
221
|
import queryString from 'query-string';
|
|
@@ -264,13 +228,13 @@ queryString.parse('?age=20&id=01234&zipcode=90210', {
|
|
|
264
228
|
//=> {age: 20, id: '01234', zipcode: '90210 }
|
|
265
229
|
```
|
|
266
230
|
|
|
267
|
-
- `'string[]'`: Parse `items` as an array of strings (overriding the `
|
|
231
|
+
- `'string[]'`: Parse `items` as an array of strings (overriding the `parseNumbers` option):
|
|
268
232
|
|
|
269
233
|
```js
|
|
270
234
|
import queryString from 'query-string';
|
|
271
235
|
|
|
272
236
|
queryString.parse('?age=20&items=1%2C2%2C3', {
|
|
273
|
-
|
|
237
|
+
parseNumbers: true,
|
|
274
238
|
types: {
|
|
275
239
|
items: 'string[]',
|
|
276
240
|
}
|
|
@@ -278,7 +242,7 @@ queryString.parse('?age=20&items=1%2C2%2C3', {
|
|
|
278
242
|
//=> {age: 20, items: ['1', '2', '3']}
|
|
279
243
|
```
|
|
280
244
|
|
|
281
|
-
- `'number[]'`: Parse `items` as an array of numbers (even when `
|
|
245
|
+
- `'number[]'`: Parse `items` as an array of numbers (even when `parseNumbers` is false):
|
|
282
246
|
|
|
283
247
|
```js
|
|
284
248
|
import queryString from 'query-string';
|