From bcecd931489c459877b57e97dc4584ca7a96952c Mon Sep 17 00:00:00 2001 From: Mael LE GUEN Date: Wed, 2 Oct 2019 16:26:20 +0200 Subject: [PATCH] chore(checkAllAliases) : replace Array.forEach by Array.find No need to parse all the array when a single match is expected. --- index.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index a5f7ae41..395f5fee 100644 --- a/index.js +++ b/index.js @@ -748,16 +748,11 @@ function parse (args, opts) { }) } - // check if a flag is set for any of a key's aliases. + // return the 1st set flag for any of a key's aliases (or false if no flag set) function checkAllAliases (key, flag) { - var isSet = false var toCheck = [].concat(flags.aliases[key] || [], key) - - toCheck.forEach(function (key) { - if (flag.hasOwnProperty(key)) isSet = flag[key] - }) - - return isSet + let setAlias = toCheck.find(key => flag.hasOwnProperty(key)) + return setAlias ? flag[setAlias] : false } function hasAnyFlag (key) {