From 73c65ea9fb5ca26f9f29388eca03f28e9693b92e Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 12 Jun 2024 22:00:01 +0200 Subject: [PATCH] [New] Allow array in dotted notation --- index.js | 4 +++- test/dotted.js | 8 ++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 78cafa8..389285f 100644 --- a/index.js +++ b/index.js @@ -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 diff --git a/test/dotted.js b/test/dotted.js index c606118..ac524c1 100644 --- a/test/dotted.js +++ b/test/dotted.js @@ -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(); });