Skip to content

Commit b59f300

Browse files
authored
perf(index): cache typeof result in parseOptions (#746)
1 parent e9b855e commit b59f300

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,24 +604,25 @@ function parseOptions(acceptedOptions, options, version) {
604604
// @ts-ignore: Keys are from options, TS cannot infer this
605605
const option = options[key];
606606
const acceptedOption = acceptedOptions[key];
607+
const optionType = typeof option;
607608

608-
if (acceptedOption.type === typeof option) {
609+
if (acceptedOption.type === optionType) {
609610
// Skip boolean options if false
610611
if (acceptedOption.type !== "boolean" || option) {
611612
// Arg will be empty for some non-standard options
612613
if (acceptedOption.arg !== "") {
613614
args.push(acceptedOption.arg);
614615
}
615616

616-
if (typeof option !== "boolean") {
617+
if (optionType !== "boolean") {
617618
args.push(option);
618619
}
619620
}
620621
} else {
621622
invalidArgs.push(
622623
`Invalid value type provided for option '${key}', expected ${
623624
acceptedOption.type
624-
} but received ${typeof option}`
625+
} but received ${optionType}`
625626
);
626627
}
627628

0 commit comments

Comments
 (0)