node-steam / vdf

Module to convert Valve's KeyValue format to JSON and back
https://node-steam.github.io/vdf/
MIT License
34 stars 3 forks source link

String-only parsing mode #10

Open LONGACAT opened 3 years ago

LONGACAT commented 3 years ago

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 commented 3 years ago

@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