datalist-interface

A simple interface for a list.
Installation
npm:
$ npm install datalist-interface
Component.js:
$ component install wooorm/datalist-interface
Bower:
$ bower install datalist-interface
Duo:
var DatalistInterface = require('wooorm/datalist-interface');
Usage
var DatalistInterface = require('datalist-interface');
var mammals = new DatalistInterface([
'common vampire bat',
'virginia opossum',
'eastern grey kangaroo',
'tasmanian devil',
'human',
'northern elephant seal',
'fox squirrel',
'tree pangolin',
'african elephant',
'platypus',
'colugo',
'reindeer',
'humpback whale',
'star-nosed mole',
'giant panda',
'giant armadillo',
'plains zebra',
'black and rufous elephant shrew'
]);
mammals.is('human');
mammals.is('unicorn');
mammals.add('unicorn').is('unicorn');
mammals.remove('unicorn').is('unicorn');
API
DatalistInterface(values)
datalist-interface exports a constructor, which can be passed an array.
var DatalistInterface = require('datalist-interface');
var fish = new DatalistInterface(['shark', 'tuna']);
The following functions are available on the instance:
DatalistInterface#is(value)
Alias: DatalistInterface#has(value)
fish.is('shark');
fish.is('human');
Returns whether (true) or not (false) a given value is in the list.
DatalistInterface#add(value...)
fish.add('giant grouper', 'red lionfish');
Add all arguments. Returns self.
DatalistInterface#remove(value...)
fish.remove('giant grouper', 'reindeer');
Remove all arguments. Returns self.
No error is thrown when non-existent values are removed.
DatalistInterface#all()
Alias: DatalistInterface#valueOf(), DatalistInterface#toJSON()
fish.all();
Return the list as an Array.
DatalistInterface#toString()
fish.toString();
Return the list as a string.
License
MIT © Titus Wormer