2.0.1 • Published 4 years ago

@232c/kv-storage v2.0.1

Weekly downloads
-
License
GPL-3.0-or-later
Repository
github
Last release
4 years ago

@232c/kv-storage

LocalForage based key-value storage for Browser, Node.js, and Cordova/Ionic.

LocalForage Drivers

Installation

npm install @232c/kv-storage

If you would like to use SQLite as a storage engine for Cordova/Ionic, install the SQLite plugin dependency:

cordova plugin add cordova-sqlite-storage --save

Usage

Example:

const { KVStorage } = require('@232c/kv-storage')

const storage = new KVStorage({
  path: './test-db',  // path to the level-datastore being used, only required when using datastore-level localForage driver
})

await storage.ready()

await storage.set('test', 123)

console.log(await storage.has('test'))  // true
console.log(await storage.get('test'))  // 123

console.log(await storage.length())  // 1
console.log(await storage.keys())  // ['test']

storage.forEach((value, key, i) => {
  console.log(value, key, i)  // 123 'test' 0
})

await storage.remove('test')

API

see dist/index.d.ts

License

MIT

2.0.1

4 years ago

2.0.0

4 years ago

1.0.0

4 years ago