datamap-interface
![Coverage Status](https://img.shields.io/codecov/c/github/wooorm/datamap-interface.svg)
A simple interface for a map.
Installation
npm:
npm install datamap-interface
Usage
var DatamapInterface = require('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
DatamapInterface(values)
datamap-interface exports a constructor, which can be passed an object.
var DatamapInterface = require('datamap-interface');
var animals = new DatamapInterface({
'unicorn' : 'mystical creature',
'shark' : 'fish',
'tuna' : 'fish',
'colugo' : 'mammal',
'human' : 'mammal'
});
API
datamapInterface([values])
Create a new instance. Values are passed to #add()
.
Example
var DatamapInterface = require('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