@safejs/serializer
Version:
Serializer is a superset of JSON that includes recursive objects, dates, regular expressions, functions and others which you also can expand by yourself
11 lines (9 loc) • 372 B
text/typescript
import { RecursiveExtraSerializer } from "../../types";
export const mapSerializer: RecursiveExtraSerializer<Map<any, any>, [any, any][]> = {
determine: (v) => v instanceof Map,
serialize: (v) => Array.from(v),
deserialize: () => new Map(),
initialize: (obj, v) => {
if (Array.isArray(v)) v.forEach(([k, v]) => obj.set(k, v));
},
};