0.0.15 • Published 6 years ago

xorderedlist v0.0.15

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

XOrderedList

Build Status npm version

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 xorderedlist

example

import OrderedList from 'xorderedlist'

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.insertOne({id: 1.5, name: 'one point five' }, 1)

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
insertOne   obj: Object      this  Insert data after the given id of the list
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 your own method. Support one extra argument

License

MIT

0.0.15

6 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago