diff options
Diffstat (limited to 'deps/npm/node_modules/query-string/index.js')
-rw-r--r-- | deps/npm/node_modules/query-string/index.js | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/deps/npm/node_modules/query-string/index.js b/deps/npm/node_modules/query-string/index.js index 523c87fdfb..6a1b3c2a30 100644 --- a/deps/npm/node_modules/query-string/index.js +++ b/deps/npm/node_modules/query-string/index.js @@ -123,6 +123,7 @@ function extract(input) { if (queryStart === -1) { return ''; } + return input.slice(queryStart + 1); } @@ -171,21 +172,24 @@ exports.extract = extract; exports.parse = parse; exports.stringify = (obj, options) => { - const defaults = { + if (!obj) { + return ''; + } + + options = Object.assign({ encode: true, strict: true, arrayFormat: 'none' - }; + }, options); - options = Object.assign(defaults, options); + const formatter = encoderForArrayFormat(options); + const keys = Object.keys(obj); - if (options.sort === false) { - options.sort = () => {}; + if (options.sort !== false) { + keys.sort(options.sort); } - const formatter = encoderForArrayFormat(options); - - return obj ? Object.keys(obj).sort(options.sort).map(key => { + return keys.map(key => { const value = obj[key]; if (value === undefined) { @@ -211,10 +215,15 @@ exports.stringify = (obj, options) => { } return encode(key, options) + '=' + encode(value, options); - }).filter(x => x.length > 0).join('&') : ''; + }).filter(x => x.length > 0).join('&'); }; exports.parseUrl = (input, options) => { + const hashStart = input.indexOf('#'); + if (hashStart !== -1) { + input = input.slice(0, hashStart); + } + return { url: input.split('?')[0] || '', query: parse(extract(input), options) |