0.0.5 • Published 6 years ago

orderedlist.js v0.0.5

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

OrderedList

A useful tool to manage array of object.

Introduction

Sometimes it would be a headache to maintain and to manipulate an array of object. ListStore is just a Map wrapper Object that enhances the original Map object. It looks like a small "database" which will help you manage arrays in a rather comfortable way.

How to use it

install

npm install orderedlist

example

import OrderedList from 'orderedlist'
const list = new OrderedList([{ id: 1, name: 'one' }])
console.log(list.size) // 1

list.push([{ id: 2, name: 'two' }])
list.unshift([{ id: 0, name: 'zero' }])
list.update([{ id: 1, name: 'update one'}])
list.delete([2])
list.findOne(0)
list.findList([1, 2])
list.mutate((orderedList) => {
  return orderedList.values.map(v => {
    v.name = 'mutate ' + v.name
  })
})

APIs

Properties
NameTypedefault
dataMap[]
idAttrString'id'
valuesArray[]
keysArray[]
sizenumber[]
lengthnumber[]
firstObject/undefinedundefined
lastObject/undefinedundefined
Methods
Nameargumentreturndescription
findOneid: AnyObjectSame to Map.get. Query one result from list
findListidList: ArrayObjectQuery results
unshiftarrOfObject: ArraythisAdd data to the start of list
pusharrOfObject: ArraythisAdd data at the end of list
updatearrOfObject: ArraythisUpdate the given data
deleteidList: ArraythisDelete data by the given id list
mutatecallback: Function, argument: ObjectArraychange the data by passing in your own method

License

MIT