Skip to content

Commit

Permalink
[Fix] opt.string works with multiple aliases (#10)
Browse files Browse the repository at this point in the history
Fixes #9.
  • Loading branch information
nhz-io authored and ljharb committed Oct 18, 2022
1 parent c59965e commit a37dd24
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion index.js
Expand Up @@ -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;
});
}
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions test/parse.js
Expand Up @@ -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();
});

Expand Down

0 comments on commit a37dd24

Please sign in to comment.