UNPKG

@naturalcycles/js-lib

Version:

Standard library for universal (browser + Node.js) javascript

22 lines (21 loc) 446 B
/** * Like Map, but serializes to JSON as an object. * * Fixes the "issue" of stock Map being json-serialized as `{}`. * * @experimental */ export class Map2 extends Map { /** * Convenience way to create Map2 from object. */ static of(obj) { return new Map2(Object.entries(obj)); } toObject() { return Object.fromEntries(this); } toJSON() { return Object.fromEntries(this); } }