https://github.com/haruncpi/lscollection
Manage browser local storage key as an object collection.
https://github.com/haruncpi/lscollection
javascript js js-library jslibrary localstorage object
Last synced: about 1 year ago
JSON representation
Manage browser local storage key as an object collection.
- Host: GitHub
- URL: https://github.com/haruncpi/lscollection
- Owner: haruncpi
- Created: 2020-07-19T16:33:27.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-07-30T05:14:13.000Z (almost 6 years ago)
- Last Synced: 2025-03-24T22:51:21.801Z (over 1 year ago)
- Topics: javascript, js, js-library, jslibrary, localstorage, object
- Language: HTML
- Homepage:
- Size: 13.7 KB
- Stars: 9
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
LS Collection
Manage browser localStorage key as an object collection.
### Usages
```markup
```
### Methods
- insert
- getAll
- find
- findWhere
- where
- update
- delete
- flash
Create an instance of lsCollection
```js
var todos = new lsCollection('todos');
```
`insert` - it returns inserted object
```js
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.
```js
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.
```js
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.
```js
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.
```js
todos.find({status:1})
//output: [{title:"Task 02", status:1, _id:1595165132214}]
```
`update` - it returns an object, returns false when data not found.
```js
todos.update(1595165132214,updateObjData)
//output: [{title:"Task 02 updated", status:1, _id:1595165132214}]
```
`delete` - it returns true/false.
```js
todos.delete(1595166010878)
//output: true
```
`flash` - it deletes all data with localstorage key and returns nothing.
```js
todos.flash()
```