https://github.com/sonukr/store
A tiny localStorage Wrapper.
https://github.com/sonukr/store
javascript localdb localstorage localstorage-api storage
Last synced: over 1 year ago
JSON representation
A tiny localStorage Wrapper.
- Host: GitHub
- URL: https://github.com/sonukr/store
- Owner: Sonukr
- Created: 2018-03-12T16:57:25.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-13T17:32:13.000Z (over 8 years ago)
- Last Synced: 2024-05-22T12:05:24.904Z (about 2 years ago)
- Topics: javascript, localdb, localstorage, localstorage-api, storage
- Language: JavaScript
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Store
A tiny API wrapper for `localStorage` that lets you safely save numbers, arrays, objects and other data types.
## Usage and API
#### Include the store.min.js
```javascript
```
#### Usage
```javascript
// define some data
var Array = [
{
name: 'Objects 1',
count: 10
},
{
name: 'Objects 2',
count: 11
}
];
var String = 'This is a text and i will save in store.';
// You can pas any kind of data type in value field like, array, object, string etc.
// save data into localStorage.
// API: store.set(key, value)
// key — string
// value - array
store.set('Array', Array);
// save data into localStorage.
// API: store.set(key, value)
// key — string
// value - string
store.set('String', String);
// get value from localStorage by key.
// API: store.get(key)
// key — string
store.get('Array');
> [{name: 'Objects 1',count: 10},{name: 'Objects 2',count: 11}]
// get value from localStorage by key.
// API: store.get(key)
// key — string
store.get('String');
> 'This is a text and i will save in store.';
// remove item from localStorage
store.remove('Array');
store.remove('String');
//get entire localStorage object
store.all
> Storage {
Array: "[{"name":"Objects 1","count":10},{"name":"Objects 2","count":11}]",
String: ""This is a text and i will save in store."", length: 2
}
// get localStorage items count
store.length
> 2
// or empty localStorage
store.clear();
```