Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reworking how numbers are parsed #104

Merged
merged 5 commits into from
Oct 5, 2017
Merged

Conversation

bcoe
Copy link
Member

@bcoe bcoe commented Oct 4, 2017

Begins to address issues discussed in yargs/yargs#96, moving us towards

  • don't magically parse numbers larger than Number.MAX_SAFE_INTEGER.
  • pull number parsing logic into maybeCoerceNumber.
  • fix broken parse-numbers = false logic.

@bcoe bcoe changed the title WIP: rethinking how we automatically parse #s feat: reworking how numbers are parsed Oct 4, 2017
index.js Outdated
@@ -421,6 +423,14 @@ function parse (args, opts) {
return value
}

function maybeCoerceNumber (key, value) {
if (!checkAllAliases(key, flags.strings) && !checkAllAliases(key, flags.coercions)) {
const shouldCoerceNumber = isNumber(value) && configuration['parse-numbers'] && (Number(value) <= Number.MAX_SAFE_INTEGER)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to use Number.isSafeInteger() instead of manually comparing to Number.MAX_SAFE_INTEGER. If you don't, you probably need to think about large negative numbers and using Number.MIN_SAFE_INTEGER too.

@bcoe bcoe merged commit fba00eb into master Oct 5, 2017
@bcoe bcoe deleted the less-aggro-number-parsing branch October 5, 2017 06:19
elsbree pushed a commit to elsbree/yargs-parser that referenced this pull request Dec 1, 2017
BREAKING CHANGE: strings that fail `Number.isSafeInteger()` are no longer coerced into numbers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants