yahoo / serialize-javascript

Serialize JavaScript to a superset of JSON that includes regular expressions and functions.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BigInt not supported but it has been since v4

dan-online opened this issue · comments

Node 16.0.0
Serialize-Javascript 6.0.0
Typescript 4.3.4

I ran into this error today, my first idea is that "BigInt" is weird because I'm using typescript?

Example data: { big: BigInt(0) }

Error:

str = JSON.stringify(obj, options.isJSON ? null : replacer, options.space);
                   ^
TypeError: Do not know how to serialize a BigInt

This repo seems quiet so I'll just post why and close:

Because big is nested in an object, it doesn't go deeper and so BigInt is never serialized

commented

Nop, it DOES go deeper with replacer; however, no other bigint but 0n passes through the replacer without being serialized due to the following condition, which returns the 0n directly.

if (!value && value !== undefined) {
return value;
}

Other bigints are serialized as expected.

Also see #154