query-string
Advanced tools
Comparing version 6.13.5 to 6.13.6
38
index.js
@@ -125,4 +125,6 @@ 'use strict'; | ||
return (key, value, accumulator) => { | ||
const isArray = typeof value === 'string' && value.split('').indexOf(options.arrayFormatSeparator) > -1; | ||
const newValue = isArray ? value.split(options.arrayFormatSeparator).map(item => decode(item, options)) : value === null ? value : decode(value, options); | ||
const isArray = typeof value === 'string' && value.includes(options.arrayFormatSeparator); | ||
const isEncodedArray = (typeof value === 'string' && !isArray && decode(value, options).includes(options.arrayFormatSeparator)); | ||
value = isEncodedArray ? decode(value, options) : value; | ||
const newValue = isArray || isEncodedArray ? value.split(options.arrayFormatSeparator).map(item => decode(item, options)) : value === null ? value : decode(value, options); | ||
accumulator[key] = newValue; | ||
@@ -218,3 +220,3 @@ }; | ||
function parse(input, options) { | ||
function parse(query, options) { | ||
options = Object.assign({ | ||
@@ -236,13 +238,13 @@ decode: true, | ||
if (typeof input !== 'string') { | ||
if (typeof query !== 'string') { | ||
return ret; | ||
} | ||
input = input.trim().replace(/^[?#&]/, ''); | ||
query = query.trim().replace(/^[?#&]/, ''); | ||
if (!input) { | ||
if (!query) { | ||
return ret; | ||
} | ||
for (const param of input.split('&')) { | ||
for (const param of query.split('&')) { | ||
let [key, value] = splitOnFirst(options.decode ? param.replace(/\+/g, ' ') : param, '='); | ||
@@ -343,3 +345,3 @@ | ||
exports.parseUrl = (input, options) => { | ||
exports.parseUrl = (url, options) => { | ||
options = Object.assign({ | ||
@@ -349,8 +351,8 @@ decode: true | ||
const [url, hash] = splitOnFirst(input, '#'); | ||
const [url_, hash] = splitOnFirst(url, '#'); | ||
return Object.assign( | ||
{ | ||
url: url.split('?')[0] || '', | ||
query: parse(extract(input), options) | ||
url: url_.split('?')[0] || '', | ||
query: parse(extract(url), options) | ||
}, | ||
@@ -361,3 +363,3 @@ options && options.parseFragmentIdentifier && hash ? {fragmentIdentifier: decode(hash, options)} : {} | ||
exports.stringifyUrl = (input, options) => { | ||
exports.stringifyUrl = (object, options) => { | ||
options = Object.assign({ | ||
@@ -368,7 +370,7 @@ encode: true, | ||
const url = removeHash(input.url).split('?')[0] || ''; | ||
const queryFromUrl = exports.extract(input.url); | ||
const url = removeHash(object.url).split('?')[0] || ''; | ||
const queryFromUrl = exports.extract(object.url); | ||
const parsedQueryFromUrl = exports.parse(queryFromUrl, {sort: false}); | ||
const query = Object.assign(parsedQueryFromUrl, input.query); | ||
const query = Object.assign(parsedQueryFromUrl, object.query); | ||
let queryString = exports.stringify(query, options); | ||
@@ -379,5 +381,5 @@ if (queryString) { | ||
let hash = getHash(input.url); | ||
if (input.fragmentIdentifier) { | ||
hash = `#${encode(input.fragmentIdentifier, options)}`; | ||
let hash = getHash(object.url); | ||
if (object.fragmentIdentifier) { | ||
hash = `#${encode(object.fragmentIdentifier, options)}`; | ||
} | ||
@@ -384,0 +386,0 @@ |
{ | ||
"name": "query-string", | ||
"version": "6.13.5", | ||
"version": "6.13.6", | ||
"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
32433
600