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

String-only parsing mode #10

Open
LONGACAT opened this issue Jul 21, 2021 · 1 comment
Open

String-only parsing mode #10

LONGACAT opened this issue Jul 21, 2021 · 1 comment

Comments

@LONGACAT
Copy link

Add an optional parameter to the parse function which makes the returned object contain only strings.

Use case - parsing an appmanifest.acf, some of the values lose precision if they're numbers. The file contains:
"manifest" "5024399731943401779"
Parsing it will return:
manifest: 5024399731943401000
A part of the value is lost. After removing the code which was responsible for converting the types, it's correctly parsed as:
manifest: '5024399731943401779'

Responsible code:

if (val !== '' && !isNaN(val)) val = +val;
if (val === 'true')            val = true;
if (val === 'false')           val = false;
if (val === 'null')            val = null;
if (val === 'undefined')       val = undefined;
@lenovouser
Copy link
Contributor

@WinterNya theoretically we could also move to bigint and then no precision would be lost, but I am not sure on how to solve that cleanly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants