minimistjs / minimist

parse argument options
MIT License
515 stars 30 forks source link

Numbers larger than 32 bits are parsed incorrectly #55

Closed gilbert closed 5 months ago

gilbert commented 7 months ago

This code parses all number-looking values as numbers. However, if the number is too large, it gets parsed as a different number. For example, 1735778230747959786 is parsed as 1735778230747959800.

ljharb commented 7 months ago

It's not "larger than 32 bits", it's "larger than Number.MAX_SAFE_INTEGER" - and that's just the nature of JavaScript.

shadowspawn commented 7 months ago

Related, I did some work on this in #18 (as I knew an issue had been reported on the original Minimist repository).

shadowspawn commented 7 months ago

Did this affect something you were using Minimist for @gilbert , or rather you found the possibility of a lossy conversion?

The work-around for a false positive with a string of digits being inappropriately converted to a number is to specify the option is a string. This can also be done for positionals: #52.