json-bigint
json-bigint copied to clipboard
Why not use BigInt now native to node.js since v10.4.0?
Since v8 added native BigInt support and that has been available since node.js v10.4.0, why not use that instead of bignumber.js?
Thanks for this package! Greate work!
@codyzu it has the problems that JSON.stringify a BigInt value as of v10.4.0
> theBiggestInt = 9007199254740991n;
9007199254740991n
> JSON.stringify(theBiggestInt)
Thrown:
TypeError: Do not know how to serialize a BigInt
at JSON.stringify (<anonymous>)
@huturen
BigInt's toJSON is not implemented. I think that it can be handled using by implementing the BigInt.prototype.toJSON
function.
But it would also override the default behavior of BigInt!
@huturen But we wouldn't be using JSON.stringify
, we'd be using JSONbig.stringify
and they handle it.
@rramaa No need to override to prototype either.
if(typeof x === 'bigint') {
return String(x);
}