From 26643e0e7d3ec2ba082ffb2651c5bcb71d54b6de Mon Sep 17 00:00:00 2001 From: juergba Date: Fri, 12 Jul 2019 18:49:18 +0200 Subject: [PATCH] merge PR187 --- index.js | 6 ++++-- test/yargs-parser.js | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 4fd05531..11eac1e5 100644 --- a/index.js +++ b/index.js @@ -470,7 +470,9 @@ function parse (args, opts) { if (typeof val === 'string') val = val === 'true' } - var value = maybeCoerceNumber(key, val) + var value = Array.isArray(val) + ? val.map(function (v) { return maybeCoerceNumber(key, v) }) + : maybeCoerceNumber(key, val) // increment a count given as arg (either no value or value parsed as boolean) if (checkAllAliases(key, flags.counts) && (isUndefined(value) || typeof value === 'boolean')) { @@ -486,7 +488,7 @@ function parse (args, opts) { } function maybeCoerceNumber (key, value) { - if (!checkAllAliases(key, flags.strings)) { + if (!checkAllAliases(key, flags.strings) && !checkAllAliases(key, flags.bools) && !Array.isArray(value)) { const shouldCoerceNumber = isNumber(value) && configuration['parse-numbers'] && ( Number.isSafeInteger(Math.floor(value)) ) diff --git a/test/yargs-parser.js b/test/yargs-parser.js index abcfaafd..ade47e7d 100644 --- a/test/yargs-parser.js +++ b/test/yargs-parser.js @@ -2453,7 +2453,7 @@ describe('yargs-parser', function () { 'flatten-duplicate-arrays': false } }) - parsed['x'].should.deep.equal([1, 2, 3]) + parsed['x'].should.deep.equal([[1], [2], [3]]) }) it('[-x 1 2 3 -x 2 3 4] => [[1, 2, 3], [ 2, 3, 4]]', function () { var parsed = parser('-x 1 2 3 -x 2 3 4', {