Create 'key/value' collections of one-to-one correspondence.
npm install bidirectional-mapCreate "key/value" collections of one-to-one correspondence. Internally it uses two Map objects, so both keys and values can be of any type, and keys can preserve their type.
npm install bidirectional-map
``js
import BiMap from 'bidirectional-map'
// Create an empty map
let map = new BiMap()
map.set('bob', 'alice')
map.get('bob') // 'alice'
map.getKey('alice') // 'bob'
// Create a map with some key/values
let map2 = new BiMap({
bob: 'alice',
john: 'mary'
})
map2.has('bob') // true
map2.hasValue('mary') // true
map2.deleteValue('mary')
`
| Arguments | Description |
|:---|:---|
| | Creates an empty structure |
| object: Object | Creates a structure with the key/values of object |
| Property | Return Type | Description |
|:---|:---|:---|
| size | any | Returns the number of key/value pairs |
| Method | Arguments | Return Type | Description |
|:---|:---|:---|:---|
| set | key: any, value: any | | Sets a new key/value pair |any
| get | key: | any | Returns the value |any
| getKey | value: | any | Returns the key |any
| clear | | | Removes all key/value pairs |
| delete | key: | | Deletes a key/value pair by key |any
| deleteValue | value: | | Deletes a key/value pair by value |MapIterator
| entries | | | Returns a new Iterator object that contains an array of [key, value] for each element in the structure |any
| has | key: | boolean| Returns true if it exists a pair with the provided key, false otherwise |any
| hasValue | value: | boolean | Returns true if it exists a pair with the provided value, false otherwise |MapIterator
| keys | | | Returns a new Iterator object that contains the keys for each element in the structure |MapIterator
| values | | | Returns a new Iterator object that contains the values for each element in the structure |Object
| getObject | | | Parses the internal "one direction" map to a plain {}. Throws exception if the map has non-primitive key types |Object
| getObjectReverse | | | Parses the internal "one direction" reverse map to a plain {}. Throws exception if the reverse map has non-primitive key types |
* 1.1.0
* Add getObject() and getObjectReverse()` methods
* 1.0.0
* Initial release :tada: