1.0.2 • Published 4 years ago

ts-bidirectional-map v1.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

TypeScript Bidirectional Map

A TypeScript Version of @educastellano's BiDirectional Map

Create "key/value" collections of one-to-one correspondence. Internally it uses two Map objects, so both keys and values can be of any type.

Install

npm install ts-bidirectional-map --save

Usage

    import BiMap from 'ts-bidirectional-map';
    
    // Create an empty map
    const map = new BiMap<String, String>();
    map.set('bob', 'alice');
    map.get('bob');          // 'alice'
    map.getKey('alice');     // 'bob'

    map2.has('bob');          // true
    map2.hasValue('alice');   // true
    map2.deleteValue('alice');

API

Properties

PropertyReturn TypeDescription
sizeanyReturns the number of key/value pairs

Methods

MethodArgumentsReturn TypeDescription
setkey: K, value: VSets a new key/value pair
getkey: KVReturns the value
getKeyvalue: VKReturns the key
clearRemoves all key/value pairs
deletekey: KDeletes a key/value pair by key
deleteValuevalue: VDeletes a key/value pair by value
entriesMapIteratorReturns a new Iterator object that contains an array of key, value for each element in the structure
haskey: KbooleanReturns a true if it exists a pair with the provided key, false otherwise
hasValuevalue: VbooleanReturns a true if it exists a pair with the provided value, false otherwise
keysMapIteratorReturns a new Iterator object that contains the keys for each element in the structure
valuesMapIteratorReturns a new Iterator object that contains the values for each element in the structure