From a37dd2444b66a93c0c5ecbdaff1d904e1f87d670 Mon Sep 17 00:00:00 2001 From: nanohertz Date: Tue, 18 Oct 2022 08:21:22 +0300 Subject: [PATCH] [Fix] opt.string works with multiple aliases (#10) Fixes #9. --- index.js | 4 +++- package.json | 2 +- test/parse.js | 11 +++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index ad21027..5a76efc 100644 --- a/index.js +++ b/index.js @@ -69,7 +69,9 @@ module.exports = function (args, opts) { [].concat(opts.string).filter(Boolean).forEach(function (key) { flags.strings[key] = true; if (aliases[key]) { - flags.strings[aliases[key]] = true; + [].concat(aliases[key]).forEach(function (k) { + flags.strings[k] = true; + }); } }); diff --git a/package.json b/package.json index a774107..12eb5aa 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "prepublish": "not-in-publish || npm run prepublishOnly", "lint": "eslint --ext=js,mjs .", "pretest": "npm run lint", - "tests-only": "nyc tape test/*.js", + "tests-only": "nyc tape 'test/**/*.js'", "test": "npm run tests-only", "posttest": "aud --production", "version": "auto-changelog && git add CHANGELOG.md", diff --git a/test/parse.js b/test/parse.js index f88c816..65d9d90 100644 --- a/test/parse.js +++ b/test/parse.js @@ -142,6 +142,17 @@ test('string and alias', function (t) { t.equal(typeof y.str, 'string'); t.equal(y.s, '000123'); t.equal(typeof y.s, 'string'); + + var z = parse(['-s123'], { + alias: { str: ['s', 'S'] }, + string: ['str'], + }); + + t.deepEqual( + z, + { _: [], s: '123', S: '123', str: '123' }, + 'opt.string works with multiple aliases' + ); t.end(); });