Map, now with defaults!
npm install ts-defaultmap> Map, now with defaults!
ts-defaultmap is available from [NPM][npm].
``shell`
npm i ts-defaultmap
It is available as CommonJS and ESM, with Typescript types.
Import DefaultMap and use as below:
`typescript
import { DefaultMap } from 'ts-defaultmap'
const map = new DefaultMap
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
map.get('unity') // 1
map.get('meaning-of-life-the-universe-and-everything') // you get it...
``
See examples for more usage.