datamap-interface
![Size](https://img.shields.io/bundlephobia/minzip/datamap-interface.svg)
A basic interface for a map.
Install
This package is ESM only: Node 12+ is needed to use it and it must be import
ed
instead of require
d.
npm:
npm install datamap-interface
Use
import {DatamapInterface} from 'datamap-interface'
var animals = new DatamapInterface({
shark: 'fish',
tuna: 'fish',
colugo: 'mammal',
human: 'mammal'
})
animals.get('human')
animals.get('unicorn')
animals.add('unicorn', 'mammal').get('unicorn')
animals.remove('unicorn').has('unicorn')
API
This package exports the following identifiers: DatamapInterface
.
There is no default export.
DatamapInterface(values)
DatamapInterface
is a constructor, which can be passed an object.
import {DatamapInterface} from 'datamap-interface'
var animals = new DatamapInterface({
unicorn: 'mystical creature',
shark: 'fish',
tuna: 'fish',
colugo: 'mammal',
human: 'mammal'
})
DatamapInterface([values])
Create a new instance.
Values are passed to #add()
.
Example
import {DatamapInterface} from 'datamap-interface'
var animals = new DatamapInterface({
unicorn: 'mystical creature',
shark: 'fish',
tuna: 'fish',
colugo: 'mammal',
human: 'mammal'
})
DatamapInterface#has(value)
DatamapInterface#is(value)
Check if value
is in the map.
Example
animals.has('unicorn')
animals.has('rainbow')
DatamapInterface#get(key)
Get the value of key
, or null
.
Example
animals.get('unicorn')
animals.get('rainbow')
DatamapInterface#add(values)
Add each value, or one pair.
Example
animals.add('giant grouper', 'fish')
animals.add({dragon: 'mystical creature'})
DatamapInterface#remove([values])
Remove each value.
Example
animals.remove(['giant grouper', 'human'])
animals.remove('dragon')
DatamapInterface#keys()
Get each key in the map.
Example
animals.keys()
DatamapInterface#all()
DatamapInterface#valueOf()
DatamapInterface#toJSON()
Return the list as an Object
.
Example
animals.all()
Yields:
{
shark: 'fish',
tuna: 'fish',
colugo: 'mammal',
unicorn: 'mystical creature'
}
Related
License
MIT © Titus Wormer