0.1.2 • Published 2 years ago

shadowed-map v0.1.2

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Shadowed Map

build status Coverage Status

A read-only Set for maps' keys or values, useful to expose a read-only Set that represents the mapped keys or values, without needing to expose the Map itself, and without being worried about keeping it in sync.

import {Keys, Vaues} from 'shadowed-map';

const map = new Map([
  ['a', 1],
  ['b', 2]
]);

const keys = new Keys(map);
const values = new Values(map);

[...keys];      // a, b
[...values];    // 1, 2

keys.size;      // 2
keys.has('a');  // true
keys.keys();    // iterator
keys.values();  // iterator
keys.forEach;   // same as Set#forEach

map.set('c', 3);
[...keys];      // a, b, c
[...values];    // 1, 2, 3