Socket
Socket
Sign inDemoInstall

idb-keyval

Package Overview
Dependencies
0
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    idb-keyval

A super-simple-small keyval store built on top of IndexedDB


Version published
Maintainers
1
Install size
7.44 kB
Created

Readme

Source

IDB-Keyval

This is a super-simple-small promise-based keyval store implemented with IndexedDB, largely based on async-storage by Mozilla.

localForage offers similar functionality, but supports older browsers with broken/absent IDB implementations. Because of that, it's 6k, whereas idb-keyval is less than 500 bytes. Pick whichever works best for you!

This is only a keyval store. If you need to do more complex things like iteration & indexing, check out IDB on NPM (a little heavier at 1.7k). The first example in its README is how to recreate this library.

Usage

set:

idbKeyval.set('hello', 'world');
idbKeyval.set('foo', 'bar');

Since this is IDB-backed, you can store anything structured-clonable (numbers, arrays, objects, dates, blobs etc).

All methods return promises:

idbKeyval.set('hello', 'world')
  .then(() => console.log('It worked!'))
  .catch(err => console.log('It failed!', err));

get:

// logs: "world"
idbKeyval.get('hello').then(val => console.log(val));

If there is no 'hello' key, then val will be undefined.

keys:

// logs: ["hello", "foo"]
idbKeyval.keys().then(keys => console.log(keys));

delete:

idbKeyval.delete('hello');

clear:

idbKeyval.clear();

That's it!

Keywords

FAQs

Last updated on 12 Dec 2016

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc