Skip to content

Commit

Permalink
chore: tiny improvements for "convertValue"
Browse files Browse the repository at this point in the history
We don't need to check each value's satisfication so
when one meets, the loop can be broken.
  • Loading branch information
SEWeiTung committed Mar 31, 2024
1 parent 84b162f commit 38623d8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@ function convertObject(obj, ignore) {
function convertValue(key, value, ignore) {
if (is.nullOrUndefined(value)) return value;

let hit;
let hit = false;
for (const matchKey of ignore) {
if (is.string(matchKey) && matchKey === key) {
hit = true;
break;
} else if (is.regExp(matchKey) && matchKey.test(key)) {
hit = true;
break;
}
}
if (!hit) {
if (is.symbol(value) || is.regExp(value)) return value.toString();
if (is.primitive(value)) return value;
if (is.array(value)) return value;
if (is.primitive(value) || is.array(value)) return value;
}

// only convert recursively when it's a plain object,
Expand Down

0 comments on commit 38623d8

Please sign in to comment.