Bidi-map
A library that extends native ES6 Map to bi-directional map.
Install
npm install bidi-map
Usage
const BidiMap = require('bidi-map');
const bidiMap = new BidiMap([
[1, 'test'],
['foo', 'bar'],
]);
bidiMap instanceof BidiMap; // true
bidiMap instanceof Map; // true
bidiMap.get(1); // "test"
bidiMap.has('foo'); // true
bidiMap.exists('bar'); // true
bidiMap.getKeyOf('test'); // 1
const key = Symbol('unique');
bidiMap.set(key, 'test');
bidiMap.getKeysOf('test'); // [1, key]
API Reference
A Bidirectional Map
-
bidi-map
-
BidiMap ⇐
Map
⏏ - new BidiMap([iterable])
-
.count :
number
-
.set(key, value) ⇒
Map.<K, V>
-
.exists(value) ⇒
boolean
-
.getKeyOf(value) ⇒
K
-
.getKeysOf(value) ⇒
Array.<K>
-
.delete(key) ⇒
boolean
-
.clear() ⇒
undefined
-
BidiMap ⇐
Map
⏏
BidiMap ⇐ Kind: Exported class
Extends: Map
Template: K, V
new BidiMap([iterable])
Create a new instance of the bidirectional-map
Param | Type | Description |
---|---|---|
[iterable] | Iterable.<Array> |
An iterable object |
number
bidiMap.count : Get the number of differed values in this map
Kind: instance property of BidiMap
Read only: true
Map.<K, V>
bidiMap.set(key, value) ⇒ Inherits from Map.set
method.
Kind: instance method of BidiMap
Param | Type |
---|---|
key | K |
value | V |
boolean
bidiMap.exists(value) ⇒ Check if the map has the given value.
Kind: instance method of BidiMap
Param | Type | Description |
---|---|---|
value | V |
The given value |
K
bidiMap.getKeyOf(value) ⇒ Get the first key of the given value or undefined
if not exists.
Kind: instance method of BidiMap
Param | Type |
---|---|
value | V |
Array.<K>
bidiMap.getKeysOf(value) ⇒ Get the all the keys of the given value.
Kind: instance method of BidiMap
Param | Type |
---|---|
value | V |
boolean
bidiMap.delete(key) ⇒ Inherits from Map.delete
method.
Kind: instance method of BidiMap
Param | Type |
---|---|
key | K |
undefined
bidiMap.clear() ⇒ Inherits from Map.clear
method.
Kind: instance method of BidiMap
© 2017 Moshe Simantov
Licensed under the Apache License, Version 2.0.