mmle-storage
Make My Life Easier when manipulate with
localStorage
- fallback to
cookie
iflocalStorage
is not available - include unique prefix automatically to prevent conflict
- support time expiration
- option to use lz-string as data compressor
Usage
Browser
└── dist
├── mmle-storage.js
└── mmle-storage-compressor.js // included lz-string compressor
var storage = mmlestorage; var info = location: 'Japan' timezone: '+9'; // save to storagestorage; var storedInfo = storage;console; // { location: 'Japan', timezone: '+9' }
API
storage.set(key, value)
Set value
to the key
.
// save to storagestorage;
storage.get(key)
Get value
from the key
.
var data = storageconsole; // [1, 3, 5]
storage.setWithExpire(key, value, date)
storage.getWithExpire(key, value, date)
Set/Get value
to/from the key
with a Date
to be expired.
var nextWeek = + 7 * 24 * 60 * 60 * 1000; // save to storagestorage; // one day laterstorage; // true // one week laterstorage; // undefined
storage.remove(key)
Remove key
and value
from the storage.
// remove key and value from the storagestorage;
storage.removeAll()
Remove all key
and value
from the storage. This only remove data which prefixed uniquely.
// remove all key and value from the storagestorage;
Test
npm test