libs
libs copied to clipboard
Stringify converts decimals to integers
I had trouble with Strava accepting my GPX files that were generated using this tool. Turns out it's because the first line of the file
<?xml version="1.0" encoding="UTF-8"?>
was turning into
<?xml version="1" encoding="UTF-8"?>
after being parsed, modified, and stringified. This is happening to all decimal numbers that have a .0
ending (whether they're numbers or strings).
Hi!
I think indeed we shouldn't touch the version
attribute of the xml prolog and exclude it from the default reviver.
Also, it seems reasonable to not trim a number back during stringification if it's explicitely passed as a string. Not sure if it'd count as a breaking change and should be a new major version though 🤔
In the meantime, if you don't really need numbers-like values to be converted to numbers, you can pass {reviveNumbers:false}
as second argument of parse()
function to disable this behaviour, maybe that can unblock you
Ah, thanks for the heads up on the number reviver. That did indeed solve the problem. Thanks.
I'll leave it up to you on whether you'd like to close this.