@a11d/bidirectional-map
A Map implementation that maintains a bidirectional relationship between keys and values, allowing lookups in both directions.
import '@a11d/bidirectional-map'
const map = new BidirectionalMap([
['en', 'English'],
['fr', 'French'],
])
map.get('en') // 'English'
map.getKey('English') // 'en'
Installation
npm install @a11d/bidirectional-map
API
Implements the standard Map<K, V> interface with additional methods:
getKey(value: V): K | undefined — Get key by value (reverse lookup)
const map = new BidirectionalMap([['en', 'English'], ['fr', 'French']])
map.getKey('English') // 'en'
map.getKey('Spanish') // undefined
hasValue(value: V): boolean — Check if a value exists
const map = new BidirectionalMap([['en', 'English']])
map.hasValue('English') // true
map.hasValue('French') // false
deleteValue(value: V): boolean — Remove entry by value
const map = new BidirectionalMap([['en', 'English']])
map.deleteValue('English') // true
map.has('en') // false
Global Type
The package automatically registers itself globally, so TypeScript recognizes BidirectionalMap without explicit imports:
// Type is available globally
const map: BidirectionalMap<string, number> = new BidirectionalMap()
Exports
| Name | Kind |
|---|---|
BidirectionalMap | class |