Skip to content

Existence of ‘number’ Key in Options.arrays Changes Parsing #415

@JoeDailey

Description

@JoeDailey

The documentation says to set numbers: true to parse option-array values as numbers. However, this value can be anything other than true and yargs will still use number parsing. This is particularly confusing when trying to set numbers: false or numbers: undefined.

> const parser = require('yargs-parser')
undefined
> parser('--foo dog cat', {array: {key: 'foo'}})
{ _: [], foo: [ 'dog', 'cat' ] }
> parser('--foo dog cat', {array: {key: 'foo', number: false}})
{ _: [], foo: [ NaN, NaN ] }
> parser('--foo dog cat', {array: {key: 'foo', number: undefined}})
{ _: [], foo: [ NaN, NaN ] } 

This applies to boolean as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions