Map with bidirectional lookups - query by key or value
npm install @a11d/bidirectional-map@a11d/bidirectional-mapA Map implementation that maintains a bidirectional relationship between keys and values, allowing lookups in both directions.
``typescript
import '@a11d/bidirectional-map'
const map = new BidirectionalMap([
['en', 'English'],
['fr', 'French'],
])
map.get('en') // 'English'
map.getKey('English') // 'en'
`
`bash`
npm install @a11d/bidirectional-map
Implements the standard Map interface with additional methods:
getKey(value: V): K | undefined — Get key by value (reverse lookup)
`typescript`
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
`typescript`
const map = new BidirectionalMap([['en', 'English']])
map.hasValue('English') // true
map.hasValue('French') // false
deleteValue(value: V): boolean — Remove entry by value
`typescript`
const map = new BidirectionalMap([['en', 'English']])
map.deleteValue('English') // true
map.has('en') // false
The package automatically registers itself globally, so TypeScript recognizes BidirectionalMap without explicit imports:
`typescript``
// Type is available globally
const map: BidirectionalMap