Open OwnageIsMagic opened 6 years ago
I would accept a pull request to fix this, but it requires us to manually do the stringifying of Arrays and Objects. That would let us properly handle undefined
and Date
s even when they are properties of objects/elements of arrays.
Is it really needed?
I'm confused. This was your issue. If you don't think the problem needs solving, why did you open the issue?
Just to state that issues exists I don't know how this package is used I think that people expects that this package does 1:1 conversion, but this not true for this case https://github.com/pugjs/js-stringify/network/dependents?dependent_type=REPOSITORY states that this package used by 17k projects degrading performance for 17k projs for such edge case is somewhat not a good idea
btw fix is quite easy
if (Array.isArray(obj))
return '[' + obj.map(x => stringify(x)).join(',') + ']';
but it will sometimes add +1 to arr length based on trailing comma support of runtime
That example is wrong in a more subtle way:
[,,,,]
// => [empty x 4]
eval('[' + [,,,,].join(',') + ']')
// => [empty x 3]
I don't know whether this is super important to fix or not. I suspect not as sparse arrays are a pretty rare occurrence, but it would be nice to support undefined
in arrays and Date
objects in deeply nested locations.
Yes, as mentioned before trailing comma consumes last delimetr
Here is easy fix for that one :)
"engine": { "node": "<6" }
Accesing out of bounds will return undefined, so no problem except array.length
But code like this is already broken by Node (and this change will be semver major, so its ok)