@paar-it-gmbh/bidirectional-map
    TypeScript icon, indicating that this package has built-in type declarations

    3.0.0 • Public • Published

    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 @paar-it-gmbh/bidirectional-map --save
    

    Usage

    import BiMap from '@paar-it-gmbh/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')

    API

    Constructors

    Arguments Description
    Creates an empty structure
    array: array Creates a structure with the elements of object

    Properties

    Property Return Type Description
    size any Returns the number of key/value pairs

    Methods

    Method Arguments Return Type Description
    set key: any, value: any Sets a new key/value pair
    get key: any any Returns the value
    getKey value: any any Returns the key
    clear Removes all key/value pairs
    delete key: any Deletes a key/value pair by key
    deleteValue value: any Deletes a key/value pair by value
    entries MapIterator Returns a new Iterator object that contains an array of [key, value] for each element in the structure
    has key: any boolean Returns a true if it exists a pair with the provided key, false otherwise
    hasValue value: any boolean Returns a true if it exists a pair with the provided value, false otherwise
    keys MapIterator Returns a new Iterator object that contains the keys for each element in the structure
    values MapIterator Returns a new Iterator object that contains the values for each element in the structure

    Changelog

    • 3.0.0
    • Improved typings, strict mode
    • 2.0.0
    • Constructor rework, typing
    • 1.0.0
    • Initial release 🎉

    License

    ISC License

    Keywords

    none

    Install

    npm i @paar-it-gmbh/bidirectional-map

    DownloadsWeekly Downloads

    9

    Version

    3.0.0

    License

    ISC

    Unpacked Size

    8 kB

    Total Files

    6

    Last publish

    Collaborators

    • jmussmann
    • mlink