Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

idb-kv-store

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

idb-kv-store

Persistent key-value store for web browsers backed by IndexDB

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.1K
increased by85.81%
Maintainers
1
Weekly downloads
 
Created
Source

idb-kv-store Build Status

Persistent key-value store for web browsers backed by IndexDB

Sauce Test Status

idb-kv-store uses asynchronous get/set operations to persist everything in IndexDB. Sometimes IndexDB is needed over something like localStorage due to storage size constraints or simply, localStorage is not available within web workers. Since IndexDB presents a complex api, storing simple key-value pairs can be complicated which this project greatly simplifies. Since everything is persisted to IndexDB, the data you store is available across multiple web sessions and within web workers.

This module can be used with browserify or the idbkvstore.min.js script can be included.

Usage

var IdbKvStore = require('idb-kv-store')
var store = new IdbKvStore()

// Store the value 'def' at key 'abc'
store.set('abc', 'def', function (err) {
  store.get('abc', function (err, value) {
    console.log('key=abc  value=' + value)
  })
})

Promises are also supported!

var IdbKvStore = require('idb-kv-store')
var store = new IdbKvStore()

// Store the value 'def' at key 'abc'
store.set('abc', 'def')
.then(() => store.get('abc'))
.then((value) => console.log('key=abc  value=' + value))

API

store = new IdbKvStore([opts])

Instantiates a new key-value store.

opts can take the following options:

  • opts.name - The name of the IndexDB database to open
  • opts.onready - A zero argument function to call when the IndexDB database is open
  • opts.onerror - This function is called when IndexDB experiences an error. It accepts one error argument. If this is undefined, the error is thrown instead.

store.set(key, value, [cb])

Stores the value at key; the value can be retreived through store.get(key). When the store operation completes, cb is called with cb(err). err is null if the store was successful. If cb is undefined then a promise is returned instead.

store.get(key, [cb])

Retreives the value at key. When the value is retreived, cb is called with cb(err, value). If the retreival was successful then err will be null. If cb is undefined then a promise is returned instead.

License

MIT. Copyright (c) Austin Middleton.

Keywords

FAQs

Package last updated on 25 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc