Skip to content

Commit

Permalink
feat: tiny improvements for "convertValue" (#5302)
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.

Speed up config dump process.

## Summary by CodeRabbit

- **Refactor**
- Improved efficiency in handling `ignore` keys within utility
functions.
- Consolidated conditions for returning values for primitives and
arrays, enhancing code readability.
  • Loading branch information
SEWeiTung authored Mar 31, 2024
1 parent 84b162f commit 794d7f3
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 794d7f3

Please sign in to comment.