From 3e750c1ac6bb7ea328b9c3183d867902dce43c95 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 22 Aug 2024 10:42:54 -0700 Subject: [PATCH] [Refactor] misc cleanup --- .eslintrc | 1 + lib/parse.js | 3 ++- lib/stringify.js | 13 +++++++++---- lib/utils.js | 7 +++++-- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/.eslintrc b/.eslintrc index b6927611..a89f60e6 100644 --- a/.eslintrc +++ b/.eslintrc @@ -13,6 +13,7 @@ "func-name-matching": 0, "id-length": [2, { "min": 1, "max": 25, "properties": "never" }], "indent": [2, 4], + "max-lines": 0, "max-lines-per-function": [2, { "max": 150 }], "max-params": [2, 18], "max-statements": [2, 100], diff --git a/lib/parse.js b/lib/parse.js index 9d323fab..f7fadc07 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -86,7 +86,8 @@ var parseValues = function parseQueryStringValues(str, options) { var bracketEqualsPos = part.indexOf(']='); var pos = bracketEqualsPos === -1 ? part.indexOf('=') : bracketEqualsPos + 1; - var key, val; + var key; + var val; if (pos === -1) { key = options.decoder(part, defaults.decoder, charset, 'key'); val = options.strictNullHandling ? null : ''; diff --git a/lib/stringify.js b/lib/stringify.js index e98303a0..3bdd4e93 100644 --- a/lib/stringify.js +++ b/lib/stringify.js @@ -34,11 +34,13 @@ var defaults = { arrayFormat: 'indices', charset: 'utf-8', charsetSentinel: false, + commaRoundTrip: false, delimiter: '&', encode: true, encodeDotInKeys: false, encoder: utils.encode, encodeValuesOnly: false, + filter: void undefined, format: defaultFormat, formatter: formats.formatters[defaultFormat], // deprecated @@ -160,7 +162,9 @@ var stringify = function stringify( for (var j = 0; j < objKeys.length; ++j) { var key = objKeys[j]; - var value = typeof key === 'object' && typeof key.value !== 'undefined' ? key.value : obj[key]; + var value = typeof key === 'object' && typeof key.value !== 'undefined' + ? key.value + : obj[key]; if (skipNulls && value === null) { continue; @@ -257,7 +261,7 @@ var normalizeStringifyOptions = function normalizeStringifyOptions(opts) { arrayFormat: arrayFormat, charset: charset, charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel, - commaRoundTrip: opts.commaRoundTrip, + commaRoundTrip: !!opts.commaRoundTrip, delimiter: typeof opts.delimiter === 'undefined' ? defaults.delimiter : opts.delimiter, encode: typeof opts.encode === 'boolean' ? opts.encode : defaults.encode, encodeDotInKeys: typeof opts.encodeDotInKeys === 'boolean' ? opts.encodeDotInKeys : defaults.encodeDotInKeys, @@ -308,12 +312,13 @@ module.exports = function (object, opts) { var sideChannel = getSideChannel(); for (var i = 0; i < objKeys.length; ++i) { var key = objKeys[i]; + var value = obj[key]; - if (options.skipNulls && obj[key] === null) { + if (options.skipNulls && value === null) { continue; } pushToArray(keys, stringify( - obj[key], + value, key, generateArrayPrefix, commaRoundTrip, diff --git a/lib/utils.js b/lib/utils.js index 7c860f1b..d4e19566 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -54,7 +54,10 @@ var merge = function merge(target, source, options) { if (isArray(target)) { target.push(source); } else if (target && typeof target === 'object') { - if ((options && (options.plainObjects || options.allowPrototypes)) || !has.call(Object.prototype, source)) { + if ( + (options && (options.plainObjects || options.allowPrototypes)) + || !has.call(Object.prototype, source) + ) { target[source] = true; } } else { @@ -108,7 +111,7 @@ var assign = function assignSingleSource(target, source) { }, target); }; -var decode = function (str, decoder, charset) { +var decode = function (str, defaultDecoder, charset) { var strWithoutPlus = str.replace(/\+/g, ' '); if (charset === 'iso-8859-1') { // unescape never throws, no try...catch needed: