query-string 6.8.2 → 6.8.3
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 +4 -4
- package/index.js +20 -6
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -53,11 +53,11 @@ export interface ParseOptions {
|
|
|
53
53
|
queryString.parse('?a=one&b=two&c=three', {
|
|
54
54
|
sort: (itemLeft, itemRight) => order.indexOf(itemLeft) - order.indexOf(itemRight)
|
|
55
55
|
});
|
|
56
|
-
|
|
56
|
+
//=> {c: 'three', a: 'one', b: 'two'}
|
|
57
57
|
```
|
|
58
58
|
|
|
59
59
|
queryString.parse('?a=one&c=three&b=two', {sort: false});
|
|
60
|
-
|
|
60
|
+
//=> {a: 'one', c: 'three', b: 'two'}
|
|
61
61
|
```
|
|
62
62
|
*/
|
|
63
63
|
readonly sort?: ((itemLeft: string, itemRight: string) => number) | false;
|
|
@@ -185,10 +185,10 @@ export interface StringifyOptions {
|
|
|
185
185
|
queryString.stringify({a: 1, b: 2, c: 3}, {
|
|
186
186
|
sort: (itemLeft, itemRight) => order.indexOf(itemLeft) - order.indexOf(itemRight)
|
|
187
187
|
});
|
|
188
|
-
|
|
188
|
+
//=> 'c=3&a=1&b=2'
|
|
189
189
|
|
|
190
190
|
queryString.stringify({b: 1, c: 2, a: 3}, {sort: false});
|
|
191
|
-
|
|
191
|
+
//=> 'b=1&c=2&a=3'
|
|
192
192
|
```
|
|
193
193
|
*/
|
|
194
194
|
readonly sort?: ((itemLeft: string, itemRight: string) => number) | false;
|
package/index.js
CHANGED
|
@@ -171,6 +171,16 @@ function extract(input) {
|
|
|
171
171
|
return input.slice(queryStart + 1);
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
+
function parseValue(value, options) {
|
|
175
|
+
if (options.parseNumbers && !Number.isNaN(Number(value)) && (typeof value === 'string' && value.trim() !== '')) {
|
|
176
|
+
value = Number(value);
|
|
177
|
+
} else if (options.parseBooleans && value !== null && (value.toLowerCase() === 'true' || value.toLowerCase() === 'false')) {
|
|
178
|
+
value = value.toLowerCase() === 'true';
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return value;
|
|
182
|
+
}
|
|
183
|
+
|
|
174
184
|
function parse(input, options) {
|
|
175
185
|
options = Object.assign({
|
|
176
186
|
decode: true,
|
|
@@ -201,14 +211,18 @@ function parse(input, options) {
|
|
|
201
211
|
// Missing `=` should be `null`:
|
|
202
212
|
// http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters
|
|
203
213
|
value = value === undefined ? null : decode(value, options);
|
|
214
|
+
formatter(decode(key, options), value, ret);
|
|
215
|
+
}
|
|
204
216
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
217
|
+
for (const key of Object.keys(ret)) {
|
|
218
|
+
const value = ret[key];
|
|
219
|
+
if (typeof value === 'object' && value !== null) {
|
|
220
|
+
for (const k of Object.keys(value)) {
|
|
221
|
+
value[k] = parseValue(value[k], options);
|
|
222
|
+
}
|
|
223
|
+
} else {
|
|
224
|
+
ret[key] = parseValue(value, options);
|
|
209
225
|
}
|
|
210
|
-
|
|
211
|
-
formatter(decode(key, options), value, ret);
|
|
212
226
|
}
|
|
213
227
|
|
|
214
228
|
if (options.sort === false) {
|