Skip to content

Commit

Permalink
[Fix] opt.string works with multiple aliases
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 62fde7d commit 2edc957
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,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
Original file line number Diff line number Diff line change
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 2edc957

Please sign in to comment.