Skip to content

Commit

Permalink
fix: Replace for..of with primordial
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronccasanova committed Mar 1, 2022
1 parent 0d5a35e commit ecf1fb0
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

const {
ArrayPrototypeConcat,
ArrayPrototypeFind,
ArrayPrototypeForEach,
ArrayPrototypeSlice,
ArrayPrototypeSplice,
ArrayPrototypePush,
Expand Down Expand Up @@ -85,7 +87,7 @@ const parseArgs = ({
} = {}) => {
validateArray(args, 'args');
validateObject(options, 'options');
for (const [option, optionConfig] of ObjectEntries(options)) {
ArrayPrototypeForEach(ObjectEntries(options), ([option, optionConfig]) => {
validateObject(optionConfig, `options.${option}`);

if (ObjectHasOwn(optionConfig, 'type')) {
Expand All @@ -103,7 +105,7 @@ const parseArgs = ({
if (ObjectHasOwn(optionConfig, 'multiple')) {
validateBoolean(optionConfig.multiple, `options.${option}.multiple`);
}
}
});

const result = {
flags: {},
Expand Down Expand Up @@ -141,12 +143,14 @@ const parseArgs = ({
}

arg = StringPrototypeCharAt(arg, 1); // short
for (const [option, optionConfig] of ObjectEntries(options)) {
if (optionConfig.short === arg) {
arg = option; // now long!
break;
}
}

const [ longOption ] = ArrayPrototypeFind(
ObjectEntries(options),
([, optionConfig]) => optionConfig.short === arg
) || [];

arg = longOption ?? arg;

// ToDo: later code tests for `=` in arg and wrong for shorts
} else {
arg = StringPrototypeSlice(arg, 2); // remove leading --
Expand Down

0 comments on commit ecf1fb0

Please sign in to comment.