ts-defaultmap
v1.0.0
Published
Map, now with defaults!
Readme
ts-defaultmap
Map, now with defaults!
Installation
ts-defaultmap is available from [NPM][npm].
npm i ts-defaultmapIt is available as CommonJS and ESM, with Typescript types.
Usage
Import DefaultMap and use as below:
import { DefaultMap } from 'ts-defaultmap'
const map = new DefaultMap<string, string>(() => "myDefault")
map.has('missing') // false
map.get('missing') // 'myDefault'
map.set('missing', 'myVal')
map.get('missing') // 'myVal'
// optionally initialised with entries, just likeMap
const filledMap = new DefaultMap<string, number>(() => 42, [['unity', 1], ['magic', 3]])
map.get('unity') // 1
map.get('meaning-of-life-the-universe-and-everything') // you get it...See examples for more usage.
