3.0.0 • Published 3 years ago

@paar-it-gmbh/bidirectional-map v3.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

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

ArgumentsDescription
Creates an empty structure
array: arrayCreates a structure with the elements of object

Properties

PropertyReturn TypeDescription
sizeanyReturns the number of key/value pairs

Methods

MethodArgumentsReturn TypeDescription
setkey: any, value: anySets a new key/value pair
getkey: anyanyReturns the value
getKeyvalue: anyanyReturns the key
clearRemoves all key/value pairs
deletekey: anyDeletes a key/value pair by key
deleteValuevalue: anyDeletes 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: anybooleanReturns a true if it exists a pair with the provided key, false otherwise
hasValuevalue: anybooleanReturns 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

Changelog

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

License

ISC License