haruncpi / lsCollection

Manage browser local storage key as an object collection.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LS Collection

Manage browser localStorage key as an object collection.

Usages

<script src="ls-collection.js"></script>

Methods

  • insert
  • getAll
  • find
  • findWhere
  • where
  • update
  • delete
  • flash

Create an instance of lsCollection

var todos = new lsCollection('todos');

insert - it returns inserted object

todos.insert({title:"Task 01",status:0})
//output: {title:"Task 01", status:0, _id:1595166010878}
todos.insert({title:"Task 02",status:1})
//output: {title:"Task 02", status:1, _id:1595165132214}

getAll - it returns an array, returns an empty array when no data exist.

todos.getAll()
/** output: 
  [
    {title:"Task 01", status:0, _id:1595166010878},
    {title:"Task 02", status:1, _id:1595165132214}
  ]
**/

find - it returns an object, returns undefined when data not found.

todos.find(1595166010878) // pass unique identifier _id
//output: {title:"Task 01", status:0, _id:1595166010878}

findWhere - it returns an object, returns undefined when data not found.

todos.find({_id:1595166010878})
//output: {title:"Task 01", status:0, _id:1595166010878}

where - it returns an array, returns an empty array when data not found.

todos.find({status:1})
//output: [{title:"Task 02", status:1, _id:1595165132214}]

update - it returns an object, returns false when data not found.

todos.update(1595165132214,updateObjData)
//output: [{title:"Task 02 updated", status:1, _id:1595165132214}]

delete - it returns true/false.

todos.delete(1595166010878)
//output: true

flash - it deletes all data with localstorage key and returns nothing.

todos.flash()

About

Manage browser local storage key as an object collection.


Languages

Language:HTML 55.6%Language:JavaScript 44.4%