From f29538762b36d0c35336b77bb8326688bdaea317 Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Sat, 4 Oct 2025 13:02:13 +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 --- server/MapJson.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 server/MapJson.ts diff --git a/server/MapJson.ts b/server/MapJson.ts new file mode 100644 index 0000000..ecd5034 --- /dev/null +++ b/server/MapJson.ts @@ -0,0 +1,18 @@ +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