Skip to content

Commit

Permalink
[Refactor] misc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Aug 22, 2024
1 parent ca55d0f commit 3e750c1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
3 changes: 2 additions & 1 deletion lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 : '';
Expand Down
13 changes: 9 additions & 4 deletions lib/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 3e750c1

Please sign in to comment.