UNPKG

multi-value-map

Version:
56 lines 1.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MultiValueMap = void 0; class MultiValueMap { constructor() { this.map = new Map(); } get(key) { return this.map.get(key) || []; } push(key, value) { const array = this.get(key); if (!array.length) { this.map.set(key, array); } array.push(value); return this; } toObject() { return Object.fromEntries(this.entries()); } keys() { return [...this.map.keys()]; } values() { return [...this.map.values()]; } entries() { return [...this.map.entries()]; } forEach(callbackfn, thisArg) { this.map.forEach((values, key) => { callbackfn(values, key, this); }, thisArg); } clear() { this.map.clear(); } delete(key) { return this.map.delete(key); } has(key) { return this.map.has(key); } [Symbol.iterator]() { return this.map[Symbol.iterator](); } get size() { return this.map.size; } get [Symbol.toStringTag]() { return this.map.toString(); } } exports.MultiValueMap = MultiValueMap; //# sourceMappingURL=multi-value-map.js.map