Last change
on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
500 bytes
|
Rev | Line | |
---|
[6a3a178] | 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 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.