store5
An easier way to store data in the browser. LocalStorage, sessionStorage, cookie supported.
1. Including store5
(1) Script tag
(2) cmd/amd
;
(3) webpack
Run npm install --save store5
or yarn add store5
to install store5.
;//or `import store5 from 'store5';` // set/get json;author; //=> 'J. K. Rowling';
2 Using store5
(1) set
- set( key, value[, expire, type] )
- key:Key.
- value:Value. Number, string, array, json... supported.
- expire:Expired timestamp(millisecond).
0
(not expired) as default. - type:
0
(default),1
or2
.0
=> UselocalStorage
to store data.1
=>sessionStorage
.2
=>cookie
.
- setLocalStorage( key, value[, expire] )
- setSessionStorage( key, value[, expire] )
- setCookie( key, value[, expire] )
(2) get
- get(key[, type]) Get a piece of data.
- getLocalStorage(key)
- getSessionStorage(key)
- getCookie(key)
(3) remove
- remove( key[, type] ) Remove the data of specified key and type.
- removeLocalStorage( key )
- removeSessionStorage( key )
- removeCookie( key )
(4) clear
- clear( [type] ) Empty the specified type of data.
- clearLocalStorage()
- clearSessionStorage()
- clearCookie()