diff --git a/index.js b/index.js index a6c95ba3..315d1aab 100644 --- a/index.js +++ b/index.js @@ -497,7 +497,7 @@ function parse (args, opts) { } function maybeCoerceNumber (key, value) { - if (!checkAllAliases(key, flags.strings) && !checkAllAliases(key, flags.coercions)) { + if (!checkAllAliases(key, flags.strings)) { const shouldCoerceNumber = isNumber(value) && configuration['parse-numbers'] && ( Number.isSafeInteger(Math.floor(value)) ) @@ -604,7 +604,7 @@ function parse (args, opts) { coerce = checkAllAliases(key, flags.coercions) if (typeof coerce === 'function') { try { - var value = coerce(argv[key]) + var value = maybeCoerceNumber(key, coerce(argv[key])) ;([].concat(flags.aliases[key] || [], key)).forEach(ali => { applied[ali] = argv[ali] = value }) diff --git a/test/yargs-parser.js b/test/yargs-parser.js index a8628261..c908187b 100644 --- a/test/yargs-parser.js +++ b/test/yargs-parser.js @@ -2147,14 +2147,18 @@ describe('yargs-parser', function () { }) it('parses number if option explicitly set to number type', function () { - var parsed = parser(['--foo', '5', '--bar', '6'], { - number: 'bar', + var parsed = parser(['--foo', '5', '--bar', '6', '--baz', '7'], { + number: ['bar', 'baz'], + coerce: { + 'baz': val => val + }, configuration: { 'parse-numbers': false } }) expect(parsed['foo']).to.equal('5') expect(parsed['bar']).to.equal(6) + expect(parsed['baz']).to.equal(7) }) })