From 39b4a6d8a6bb99279899b8040a700f42dbe2c3de Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Sat, 4 Oct 2025 14:07:21 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=B7=BB=E5=8A=A0=20Map=20=E5=BA=8F?= =?UTF-8?q?=E5=88=97=E5=8C=96=E7=9B=B8=E5=85=B3=E8=BE=85=E5=8A=A9=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/MapJson.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 client/MapJson.ts diff --git a/client/MapJson.ts b/client/MapJson.ts new file mode 100644 index 0000000..be64c19 --- /dev/null +++ b/client/MapJson.ts @@ -0,0 +1,20 @@ +// https://stackoverflow.com/questions/29085197/how-do-you-json-stringify-an-es6-map + +export default class MapJson { + static replacer(key: unknown, value: unknown) { + if (value instanceof Map) { + return { + dataType: 'Map', + value: Array.from(value.entries()), // or with spread: value: [...value] + } + } else { + return value + } + } + static reviver(key: unknown, value: any) { + if (value?.dataType === 'Map') { + return new Map(value.value) + } + return value + } +} \ No newline at end of file