UNPKG

500 BPlain TextView Raw
1const serialized = "$$ babel internal serialized type" + Math.random();
2
3function serialize(key, value) {
4 if (typeof value !== "bigint") return value;
5 return {
6 [serialized]: "BigInt",
7 value: value.toString(),
8 };
9}
10
11function revive(key, value) {
12 if (!value || typeof value !== "object") return value;
13 if (value[serialized] !== "BigInt") return value;
14 return BigInt(value.value);
15}
16
17export default function (value) {
18 return JSON.parse(JSON.stringify(value, serialize), revive);
19}