1.0.1 • Published 7 years ago
storage-plus v1.0.1
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
import storagePlus from 'storage-plus';
var userInfo = { age: 10, name: 'Jack' };
var cacheTime = 7 * 24 * 3600 * 1000; // expired after seven days
storagePlus.setItem('userInfo', userInfo, cacheTime);
storagePlus.getItem('userInfo');
// => { age: 10, name: 'Jack' }
storagePlus.removeItem('userInfo');
Standalone build available as dist/storage-plus.min.js
.
<script src="./node_modules/storage-plus/dist/storage-plus.min.js"></script>
<script>
storagePlus.setItem('flag', true, 1000);
</script>
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