chore: 添加 Map 序列化相关辅助类
This commit is contained in:
18
server/MapJson.ts
Normal file
18
server/MapJson.ts
Normal file
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user