UNPKG

@contextjs/collections

Version:

Strongly-typed collection classes for TypeScript, including List, Dictionary, Queue, Stack, and HashSet.

30 lines (29 loc) 584 B
export class Dictionary { map = new Map(); set(key, value) { this.map.set(key, value); } get(key) { return this.map.has(key) ? this.map.get(key) : null; } has(key) { return this.map.has(key); } delete(key) { this.map.delete(key); } clear() { this.map.clear(); } values() { if (this.map.size === 0) return []; return Array.from(this.map.values()); } keys() { return Array.from(this.map.keys()); } count() { return this.map.size; } }