map-upsert
v1.2.0
Published
upsert() for (Weak)Map (https://github.com/thumbsupep/proposal-upsert)
Downloads
18
Readme
map-upsert
upsert()
for (Weak)Map, as defined in the tc 39 proposal.
usage
This module follows the same logic as outlined in the proposed api, but the first argument is the Map or WeakMap object.
Example (TypeScript)
import upsert from 'map-upsert'
const map = new Map<string, number>();
const updateFn = (old: number): number => old + 1;
const insertFn = () => 0;
const upsert = require('map-upsert');
upsert(map, 'key', updateFn, insertFn);
assert.equals(map.get('key', 0);
upsert(map, 'key', updateFn, insertFn);
assert.equal(map.get('key', 1);