Skip to content

Commit 2edc957

Browse files
nhz-ioljharb
authored andcommittedOct 18, 2022
[Fix] opt.string works with multiple aliases
Fixes #9.
1 parent 62fde7d commit 2edc957

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed
 

‎index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ module.exports = function (args, opts) {
6161
[].concat(opts.string).filter(Boolean).forEach(function (key) {
6262
flags.strings[key] = true;
6363
if (aliases[key]) {
64-
flags.strings[aliases[key]] = true;
64+
[].concat(aliases[key]).forEach(function (k) {
65+
flags.strings[k] = true;
66+
});
6567
}
6668
});
6769

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"prepublish": "not-in-publish || npm run prepublishOnly",
2121
"lint": "eslint --ext=js,mjs .",
2222
"pretest": "npm run lint",
23-
"tests-only": "nyc tape test/*.js",
23+
"tests-only": "nyc tape 'test/**/*.js'",
2424
"test": "npm run tests-only",
2525
"posttest": "aud --production",
2626
"version": "auto-changelog && git add CHANGELOG.md",

‎test/parse.js

+11
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,17 @@ test('string and alias', function (t) {
142142
t.equal(typeof y.str, 'string');
143143
t.equal(y.s, '000123');
144144
t.equal(typeof y.s, 'string');
145+
146+
var z = parse(['-s123'], {
147+
alias: { str: ['s', 'S'] },
148+
string: ['str'],
149+
});
150+
151+
t.deepEqual(
152+
z,
153+
{ _: [], s: '123', S: '123', str: '123' },
154+
'opt.string works with multiple aliases'
155+
);
145156
t.end();
146157
});
147158

0 commit comments

Comments
 (0)
Please sign in to comment.