Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
)
Expand Down Expand Up @@ -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
})
Expand Down
8 changes: 6 additions & 2 deletions test/yargs-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})

Expand Down