Skip to content

Repository files navigation

bim

NPM versionDownloadsDependency statusDev Dependency status

A bidirectional map based on the ES6 Map object containing additional methods to retrive keys by values, delete key-value pairs by values and check the existence of keys by values. The module contains two classes: BiMap & WeakBiMap based on Map & WeakMap respectively.

Installation

npm install --save bim

Usage

Same as normal Map & WeakMap, plus the getKey, hasValue & deleteValue methods.

import{WeakBiMap}from'bim'// create objects to use as keysconsta={i: 'foo',j: 8,}constb={k: 'bar',p: 11,}// create the bidirectional weak mapconstwbm=newWeakBiMap()wbm.set(a,5)wbm.set(b,6)wbm.deleteValue(5)// now only has { k: 'bar', p: 11 } => 6wbm.hasValue(5)// falseconstc={h: 'quux',z: 100,}wbm.set(c,7)wbm.hasValue(7)// truewbm.getKey(7)// { h: 'quux', z: 100 }

About

Bidirectional dictionaries based on the ES6 Map & WeakMap

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages