diff --git a/src/config/util.ts b/src/config/util.ts index e09aa51c3..b0b2e8152 100644 --- a/src/config/util.ts +++ b/src/config/util.ts @@ -107,7 +107,7 @@ export function getCommandIdPermutations(commandId: string): string[] { * @param commandIds string[] * @returns string[] */ -export function collectUsableIds(commandIds: string[]): string[] { +export function collectUsableIds(commandIds: string[]): Set { const usuableIds: string[] = [] for (const id of commandIds) { const parts = id.split(':') @@ -118,5 +118,5 @@ export function collectUsableIds(commandIds: string[]): string[] { } } - return uniq(usuableIds).sort() + return new Set(usuableIds) } diff --git a/src/help/util.ts b/src/help/util.ts index 6fcb6d3f5..ffa0b7cd7 100644 --- a/src/help/util.ts +++ b/src/help/util.ts @@ -44,7 +44,7 @@ function collateSpacedCmdIDFromArgs(argv: string[], config: IConfig): string[] { const ids = collectUsableIds(config.commandIDs) const final: string[] = [] - const idPresent = (id: string) => ids.includes(id) + const idPresent = (id: string) => ids.has(id) const isFlag = (s: string) => s.startsWith('-') const isArgWithValue = (s: string) => s.includes('=') const finalizeId = (s?: string) => s ? [...final, s].join(':') : final.join(':') diff --git a/test/config/util.test.ts b/test/config/util.test.ts index 847a4f290..22152e9c9 100644 --- a/test/config/util.test.ts +++ b/test/config/util.test.ts @@ -6,14 +6,14 @@ describe('util', () => { test .it('returns all usable command ids', async () => { const ids = collectUsableIds(['foo:bar:baz', 'one:two:three']) - expect(ids).to.deep.equal([ + expect(ids).to.deep.equal(new Set([ 'foo', 'foo:bar', 'foo:bar:baz', 'one', 'one:two', 'one:two:three', - ]) + ])) }) }) diff --git a/yarn.lock b/yarn.lock index 149731e7c..35d5b2576 100644 --- a/yarn.lock +++ b/yarn.lock @@ -642,16 +642,11 @@ resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-3.12.7.tgz#330c5d97a3500e9c903210d6e49f02964af04a0e" integrity sha512-S6+8JAYTE1qdsc9HMVsfY7+SgSuUU/Tp6TYTmITW0PZxiyIMvol3Gy//y69Wkhs0ti4py5qgR3uZH6uz/DNzJQ== -"@types/json-schema@*": +"@types/json-schema@*", "@types/json-schema@^7.0.7": version "7.0.11" resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.11.tgz#d421b6c527a3037f7c84433fd2c4229e016863d3" integrity sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ== -"@types/json-schema@^7.0.7": - version "7.0.9" - resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.9.tgz#97edc9037ea0c38585320b28964dde3b39e4660d" - integrity sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ== - "@types/lodash@*": version "4.14.182" resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.182.tgz#05301a4d5e62963227eaafe0ce04dd77c54ea5c2"