vdf icon indicating copy to clipboard operation
vdf copied to clipboard

String-only parsing mode

Open LONGACAT opened this issue 4 years ago • 1 comments

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;

LONGACAT avatar Jul 21 '21 21:07 LONGACAT

@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

lenovouser avatar Aug 23 '21 12:08 lenovouser