Simple Web Storage
Lightweight utilities that can make easier to write and read application storage in client browser.
Support :
- Local Storage
- Cookie Storage
- Session Storage
HOW TO USE
1. Use Package with NPM or YARN
# with npm $ npm i simple-webstorage --save # or with yarn $ yarn add simple-webstorage
All API import
const storage = storagelocal // empty the third parameter to store data permanently (only affected in local)storagecookiestoragesession
Partial API import
// # for local storage // # for session storage// import { get, set } from 'simple-webstorage/lib/session' // # for cookie storage// import { get, set } from 'simple-webstorage/lib/cookie' console // { name: 'you', skill: ['angry', 'crying'] }
or you can import partial API like this :
// # for cookie storage // # for local storage// import LocalStorage from 'simple-webstorage/lib/local' // # for session storage// import SessionStorage from 'simple-webstorage/lib/session' const cookie = cookiecookie console // true # get values from key. returns anyconsole // ['remembered', 'forgotten'] # list all keys. returns array
2. All in minified js
API Details
Storage | Method | Parameters |
---|---|---|
local |
set | key (type: String), value (type: any, default: 0), expiryInMinutes (type: Number, default: null) |
cookie or session |
set | key (type: String), value (type: any, default: 0), expiryInMinutes (type: Number, default: 5) |
local or cookie or session |
get | key (type: String) |
local or cookie or session |
remove | key (type: String) |
local or cookie or session |
keys | none |
local or cookie or session |
clear | none |
Feel free to contribute simple-webstorage 🙂
Copyright © 2019 by Sutan Gading Fadhillah Nasution