query-string
Advanced tools
Comparing version 6.8.2 to 6.8.3
@@ -56,7 +56,7 @@ export interface ParseOptions { | ||
}); | ||
// => {c: 'three', a: 'one', b: 'two'} | ||
//=> {c: 'three', a: 'one', b: 'two'} | ||
``` | ||
queryString.parse('?a=one&c=three&b=two', {sort: false}); | ||
// => {a: 'one', c: 'three', b: 'two'} | ||
//=> {a: 'one', c: 'three', b: 'two'} | ||
``` | ||
@@ -189,6 +189,6 @@ */ | ||
}); | ||
// => 'c=3&a=1&b=2' | ||
//=> 'c=3&a=1&b=2' | ||
queryString.stringify({b: 1, c: 2, a: 3}, {sort: false}); | ||
// => 'b=1&c=2&a=3' | ||
//=> 'b=1&c=2&a=3' | ||
``` | ||
@@ -195,0 +195,0 @@ */ |
26
index.js
@@ -174,2 +174,12 @@ 'use strict'; | ||
function parseValue(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'; | ||
} | ||
return value; | ||
} | ||
function parse(input, options) { | ||
@@ -205,10 +215,14 @@ options = Object.assign({ | ||
value = value === undefined ? null : decode(value, options); | ||
formatter(decode(key, options), value, ret); | ||
} | ||
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'; | ||
for (const key of Object.keys(ret)) { | ||
const value = ret[key]; | ||
if (typeof value === 'object' && value !== null) { | ||
for (const k of Object.keys(value)) { | ||
value[k] = parseValue(value[k], options); | ||
} | ||
} else { | ||
ret[key] = parseValue(value, options); | ||
} | ||
formatter(decode(key, options), value, ret); | ||
} | ||
@@ -215,0 +229,0 @@ |
{ | ||
"name": "query-string", | ||
"version": "6.8.2", | ||
"version": "6.8.3", | ||
"description": "Parse and stringify URL query strings", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
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
20872
389
1