A light-weight localStorage tool.
- No dependency
- Supports any type of data
- Supports UMD
- JSON support
- expiration support
- ~3kb before gzipped
$ npm install tz-storage --save<script src="tz-storage.min.js"></script>Check compatibility:
storage.isSupported // return true or falseSet a storage namespace, it turns key to 'namespace.key':
storage.namespace = 'mystorage'Set a default value in advance:
storage.defaultValue = 'nothing'Set options by config:
storage.config({
namespace: 'space',
defaultValue: 'empty'
})Set a storage with any types:
storage.set('key', {active: true, label: 'helloword'})
storage.set('key', [1, 2, 3, 4])
storage.set('key', 'hello')Set a expire time, it returns default value when expired:
storage.set('key', 'value', new Date().getTime() + 8640000)Replace with a custom value when the value is empty.
storage.get('key', { defaultValue: 'empty' })Get with specified type(only worked in string, number and boolean)
storage.get('key', { type: 'number' })storage.remove('key')