https://github.com/inker/bim
Bidirectional dictionaries based on the ES6 Map & WeakMap
https://github.com/inker/bim
bidirectional bimap dictionary map weakmap
Last synced: about 1 month ago
JSON representation
Bidirectional dictionaries based on the ES6 Map & WeakMap
- Host: GitHub
- URL: https://github.com/inker/bim
- Owner: inker
- Created: 2016-07-26T18:51:27.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-02-03T15:02:17.000Z (over 2 years ago)
- Last Synced: 2025-03-29T06:33:45.214Z (about 2 months ago)
- Topics: bidirectional, bimap, dictionary, map, weakmap
- Language: TypeScript
- Homepage:
- Size: 879 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# bim
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Dependency status][david-dm-image]][david-dm-url] [![Dev Dependency status][david-dm-dev-image]][david-dm-dev-url]
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.
```javascript
import { WeakBiMap } from 'bim'// create objects to use as keys
const a = {
i: 'foo',
j: 8,
}
const b = {
k: 'bar',
p: 11,
}// create the bidirectional weak map
const wbm = new WeakBiMap()wbm.set(a, 5)
wbm.set(b, 6)
wbm.deleteValue(5) // now only has { k: 'bar', p: 11 } => 6
wbm.hasValue(5) // falseconst c = {
h: 'quux',
z: 100,
}wbm.set(c, 7)
wbm.hasValue(7) // true
wbm.getKey(7) // { h: 'quux', z: 100 }
```[npm-url]: https://npmjs.org/package/bim
[downloads-image]: http://img.shields.io/npm/dm/bim.svg
[npm-image]: http://img.shields.io/npm/v/bim.svg
[david-dm-url]:https://david-dm.org/inker/bim
[david-dm-image]:https://david-dm.org/inker/bim.svg
[david-dm-dev-url]:https://david-dm.org/inker/bim#info=devDependencies
[david-dm-dev-image]:https://david-dm.org/inker/bim/dev-status.svg