Skip to content

Commit

Permalink
[Refactor] stringify: reduce branching
Browse files Browse the repository at this point in the history
  • Loading branch information
daggerjames authored and ljharb committed Jun 9, 2019
1 parent daf3e6a commit 83d1e9a
Showing 1 changed file with 21 additions and 34 deletions.
55 changes: 21 additions & 34 deletions lib/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,44 +115,31 @@ var stringify = function stringify(

for (var i = 0; i < objKeys.length; ++i) {
var key = objKeys[i];
var value = obj[key];

if (skipNulls && obj[key] === null) {
if (skipNulls && value === null) {
continue;
}

if (isArray(obj)) {
pushToArray(values, stringify(
obj[key],
typeof generateArrayPrefix === 'function' ? generateArrayPrefix(prefix, key) : prefix,
generateArrayPrefix,
strictNullHandling,
skipNulls,
encoder,
filter,
sort,
allowDots,
serializeDate,
formatter,
encodeValuesOnly,
charset
));
} else {
pushToArray(values, stringify(
obj[key],
prefix + (allowDots ? '.' + key : '[' + key + ']'),
generateArrayPrefix,
strictNullHandling,
skipNulls,
encoder,
filter,
sort,
allowDots,
serializeDate,
formatter,
encodeValuesOnly,
charset
));
}
var keyPrefix = isArray(obj)
? typeof generateArrayPrefix === 'function' ? generateArrayPrefix(prefix, key) : prefix
: prefix + (allowDots ? '.' + key : '[' + key + ']');

pushToArray(values, stringify(
value,
keyPrefix,
generateArrayPrefix,
strictNullHandling,
skipNulls,
encoder,
filter,
sort,
allowDots,
serializeDate,
formatter,
encodeValuesOnly,
charset
));
}

return values;
Expand Down

0 comments on commit 83d1e9a

Please sign in to comment.