map-upsert
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i map-upsert

Weekly Downloads

2

Version

1.2.0

License

MIT

Unpacked Size

13.2 kB

Total Files

11

Last publish

Collaborators

  • kesla