@a11d/bidirectional-map
v0.1.1
Published
Map with bidirectional lookups - query by key or value
Maintainers
Readme
@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-mapAPI
Implements the standard Map<K, V> interface with additional methods:
const map = new BidirectionalMap([['en', 'English'], ['fr', 'French']])
map.getKey('English') // 'en'
map.getKey('Spanish') // undefinedconst map = new BidirectionalMap([['en', 'English']])
map.hasValue('English') // true
map.hasValue('French') // falseconst map = new BidirectionalMap([['en', 'English']])
map.deleteValue('English') // true
map.has('en') // falseGlobal 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()