From ecf1fb09a855ccef0f4a4eaba410edb9e90610ed Mon Sep 17 00:00:00 2001 From: Aaron Casanova <32409546+aaronccasanova@users.noreply.github.com> Date: Mon, 28 Feb 2022 18:14:29 -0800 Subject: [PATCH] fix: Replace for..of with primordial --- index.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 74b2dbe..e773332 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,8 @@ const { ArrayPrototypeConcat, + ArrayPrototypeFind, + ArrayPrototypeForEach, ArrayPrototypeSlice, ArrayPrototypeSplice, ArrayPrototypePush, @@ -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')) { @@ -103,7 +105,7 @@ const parseArgs = ({ if (ObjectHasOwn(optionConfig, 'multiple')) { validateBoolean(optionConfig.multiple, `options.${option}.multiple`); } - } + }); const result = { flags: {}, @@ -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 --