1.2.0 • Published 4 years ago

map-upsert v1.2.0

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

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);
1.2.0

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.0

4 years ago