webstorage-utils
v1.4.0
Published
web storage utils
Downloads
11
Maintainers
Readme
webstorage-utils
Some utils of WebStorage
Install
// npm
npm install webstorage-utils
// yarn
yarn add webstorage-utils
Use
import { localStorage, sessionStorage } from 'webstorage-utils'
localStorage.set('example', 'demo')
localStorage.get('example') // demo
sessionStorage.set('example', 'demo')
sessionStorage.get('example') // demo
API
new WebStorageUtils(options)
- options
storage
: 'localStorage' | 'local' | 'sessionStorage' | 'session'prefix
: string
storage.set(key, value[, ttl])
key
: stringvalue
: anyttl
: number, second
storage.set('key1', 1)
storage.set('key2', { example: 1 })
// invalid after 10 seconds
storage.set('key3', { example: 1 }, 10)
storage.get(key)
key
: string
const value1 = storage.set('key1')
storage.del(key)
key
: string
storage.del('key1')
storage.clear()
storage.clear('key1')