Skip to content

Commit

Permalink
perf: avoid lowercasing long strings
Browse files Browse the repository at this point in the history
  • Loading branch information
webstrand committed Aug 1, 2023
1 parent 61f44ce commit d67c683
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,30 @@ export function destr<T = unknown>(value: any, options: Options = {}): T {
return _value.slice(1, -1) as T;
}

const _lval = _value.toLowerCase();
if (_lval === "true") {
return true as T;
}
if (_lval === "false") {
return false as T;
}
if (_lval === "undefined") {
return undefined as T;
}
if (_lval === "null") {
// eslint-disable-next-line unicorn/no-null
return null as T;
}
if (_lval === "nan") {
return Number.NaN as T;
}
if (_lval === "infinity") {
return Number.POSITIVE_INFINITY as T;
}
if (_lval === "-infinity") {
return Number.NEGATIVE_INFINITY as T;
if (_value.length <= 9) {
const _lval = _value.toLowerCase();
if (_lval === "true") {
return true as T;
}
if (_lval === "false") {
return false as T;
}
if (_lval === "undefined") {
return undefined as T;
}
if (_lval === "null") {
// eslint-disable-next-line unicorn/no-null
return null as T;
}
if (_lval === "nan") {
return Number.NaN as T;
}
if (_lval === "infinity") {
return Number.POSITIVE_INFINITY as T;
}
if (_lval === "-infinity") {
return Number.NEGATIVE_INFINITY as T;
}
}

if (!JsonSigRx.test(value)) {
Expand Down

0 comments on commit d67c683

Please sign in to comment.