Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-protocol/src/util/stringify.ts
2500 views
1
/**
2
* Copyright (c) 2024 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
export namespace BigIntToJson {
8
export const BIGINT_KEY = "bigint:";
9
export function replacer(key: string, value: any) {
10
if (typeof value === "bigint") {
11
return `${BIGINT_KEY}${value.toString()}`;
12
}
13
return value;
14
}
15
export function reviver(key: string, value: any) {
16
if (typeof value === "string" && value.startsWith(BIGINT_KEY)) {
17
const v: string = value.substring(7);
18
return BigInt(v);
19
}
20
return value;
21
}
22
}
23
24