datalist-interface
Simple interface for a list functioning as a database
Last updated 5 years ago by wooorm .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install datalist-interface 
SYNC missed versions from official npm registry.

datalist-interface

Build Coverage Downloads Size

A basic interface for a list.

Install

This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.

npm:

npm install datalist-interface

Use

import {DatalistInterface} from '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') // => true
mammals.is('unicorn') // => false

mammals.add('unicorn').is('unicorn') // => true

mammals.remove('unicorn').is('unicorn') // => false

API

This package exports the following identifiers: DatalistInterface. There is no default export.

DatalistInterface([value...])

Create a new instance. Values are passed to #add().

Example
import {DatalistInterface} from 'datalist-interface'

var fish = new DatalistInterface(['shark', 'tuna'])

DatalistInterface#is(value)

DatalistInterface#has(value)

Check if value is in the list.

Example
fish.is('shark') // => true
fish.is('human') // => false

DatalistInterface#add([value...])

Add each value to list.

Example
fish.add('giant grouper', 'red lionfish')

DatalistInterface#remove([value...])

Remove each value from list.

Example
fish.remove('giant grouper', 'reindeer')

DatalistInterface#all()

DatalistInterface#valueOf()

DatalistInterface#toJSON()

Return the list as an Array.

Example
fish.all() // => ['shark', 'tuna', 'red lionfish']

DatalistInterface#toString()

Return the list as a string.

Example
fish.toString() // => 'shark,tuna,red lionfish'

Related

License

MIT © Titus Wormer

Current Tags

  • 2.1.1                                ...           latest (5 years ago)

13 Versions

  • 2.1.1                                ...           5 years ago
  • 2.1.0                                ...           5 years ago
  • 2.0.0                                ...           5 years ago
  • 1.0.5                                ...           6 years ago
  • 1.0.4                                ...           7 years ago
  • 1.0.3                                ...           8 years ago
  • 1.0.2                                ...           9 years ago
  • 1.0.1                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
  • 0.2.1                                ...           11 years ago
  • 0.2.0                                ...           11 years ago
  • 0.1.0                                ...           11 years ago
  • 0.0.1                                ...           12 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (9)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |