StoragePlus
StoragePlus is a functional wrapper around native localStorage.
The main differences with localStorage:
- no need for
JSON.stringify/parse
- support setting cache time
Install
yarn add storage-plus# or npm install storage-plus --save
Usage
; var userInfo = age: 10 name: 'Jack' ;var cacheTime = 7 * 24 * 3600 * 1000; // expired after seven days storagePlus;storagePlus;// => { age: 10, name: 'Jack' }storagePlus;
Standalone build available as dist/storage-plus.min.js
.
API
storagePlus.setItem(key, value, [cacheTime])
Set key to value with cacheTime(optional).
storagePlus.getItem(key)
Get key's value. If expired, return null
.
storagePlus.removeItem(key)
Same as localStorage.removeItem(key).
License
Copyright © 2017 MaqicStudio - MIT License