Skip to content

Commit

Permalink
[New] Allow array in dotted notation
Browse files Browse the repository at this point in the history
  • Loading branch information
git-developer committed Jun 12, 2024
1 parent bedaa8b commit 73c65ea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ module.exports = function (args, opts) {
for (var i = 0; i < keys.length - 1; i++) {
var key = keys[i];
if (isConstructorOrProto(o, key)) { return; }
if (o[key] === undefined) { o[key] = {}; }
if (o[key] === undefined) {
o[key] = (/^\d+$/).test(keys[i + 1]) ? [] : {};
}
if (
o[key] === Object.prototype
|| o[key] === Number.prototype
Expand Down
8 changes: 2 additions & 6 deletions test/dotted.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@ test('dotted default with no alias', function (t) {

test('dotted array', function (t) {
var argv = parse(['--a.1.foo', '11']);

t.notOk(Array.isArray(argv.a));

t.notOk(0 in argv.a);

t.true(Array.isArray(argv.a));
t.false(0 in argv.a);
t.equal(argv.a[1].foo, 11);

t.end();
});

0 comments on commit 73c65ea

Please sign in to comment.