extra-local-storage
v1.0.0
Published
# Install ``` npm install extra-local-storage ```
Downloads
7
Readme
node-storage
Install
npm install extra-local-storage
Usage
import storage from 'extra-local-storage'
// store data in **'./test'**, default is 'storage'
const test = storage('test')
test.xxx // call api
// each storage also can be a function to create a sub-storage, it will store data in **'./test/test1'**
const test1 = test('test1') //
test1.xxx // call api
API
Instance
- storage(dir, opts) a. opts.throws # if throws errors b. opts.max # the max number of item in this storage c. opts.ttl # the default ttl of each items d. interval # the interval time to check ttl items
Original API as localStorage in browser (Sync)
- storage.length
- storage.key(index)
- storage.getItem(key)
- storage.setItem(key, value, opts) # set opts.ttl as the time to live
- storage.removeItem(key)
- storage.clear(all) # if [all] is true, remove the dir itself including all sub-dirs
Extra API (Async)
- storage.get(key).then((value) => {})
- storage.set(key, value, opts).then(() => {})
- storage.remove(key).then(() => {})
- storage.list().then(([{key: value}, ...]) => {})
- storage.valueOf().then(({key: value, ...}) => {})
- storage.cleanup(all).then(() => {}) # if[all] is true, remove the dir itself including all sub-dirs
- storage.cleanout().then(() => {}) # remove all of the outdated items