1 | const serialized = "$$ babel internal serialized type" + Math.random();
|
2 |
|
3 | function serialize(key, value) {
|
4 | if (typeof value !== "bigint") return value;
|
5 | return {
|
6 | [serialized]: "BigInt",
|
7 | value: value.toString(),
|
8 | };
|
9 | }
|
10 |
|
11 | function 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 |
|
17 | export default function (value) {
|
18 | return JSON.parse(JSON.stringify(value, serialize), revive);
|
19 | }
|