Open haoadoreorange opened 2 years ago
Since I'm needing this, I rewrote the lib in TS with support for this PR here: https://github.com/haoadoresorange/when-json-met-bigint
hi @haoadoresorange thanks for the PR (and sorry for long silence). Could you add a unit test to cover functionality you are adding?
hi @haoadoresorange thanks for the PR (and sorry for long silence). Could you add a unit test to cover functionality you are adding?
Hi,
Unfortunately at the moment I have no interest in continuing this PR ): as I said I forked the project and implemented this PR here https://github.com/haoadoresorange/when-json-met-bigint
Also I fixed several bugs to align with the newest spec behaviour (: you can give it a look if you like.
Hi @sidorares, me again 😄
I talked to @MatthewKhouzam today (I believe he talked to you a couple days ago). So apparently merging my forked back to the main repo will benefit greatly everyone, and I'd be gladly to do so !
However the fork as of now is very much diversed from this repo, the original core is similar though. So now I'm not sure how to move forward with the merge and I need your help to make it work (: Could I reach you so we can talk about this a little bit more in detail ?
EDIT: typo
This might solve the limitation
o !== JSONbig.parse(JSONbig.stringify(o))
The limitation is there because JS treat
BigInt
andNumber
as 2 separate types which cannot be cooerced. The parser decides the appropriate type based on the size of the number in JSON string. Which introduces 2 problems:JSONbig.parse(JSONbig.stringify(123n))
return123
because the number is small enoughBigInt
and other times beNumber
There's the option to parse all
Number
asBigInt
but imho this isn't much desirable. Libraries solve problem (2) by iterating the parsed result and enforce the type as you can see here. That PR has an interesting approach which this one is inspired from.Here's the proposed solution. The parser can take a schema-like object which allow to say whether to use
BigInt
orNumber
for specific fields and parse it accordingly. This is a first prototype to show what it might look like.If this is something viable there's a lot to improve.