jakearchibald/idb-keyval is tracked by TopGit as an open-source project, with 3.3k stars on GitHub, written primarily in TypeScript. A super-simple-small promise-based keyval store implemented with IndexedDB
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
This is a super-simple promise-based keyval store implemented with IndexedDB, originally based on async-storage by Mozilla.
It's small and tree-shakeable. If you only use get/set, the library is 295 bytes (brotli'd), if you use all methods it's 573 bytes.
localForage offers similar functionality, but supports older browsers with broken/absent IDB implementations. Because of that, it's orders of magnitude bigger (~7k).
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 1k). The first example in its README is how to create a keyval store.
Installing
Recommended: Via npm + webpack/rollup/parcel/etc
npm install idb-keyval
Now you can require/import idb-keyval:
import { get, set } from 'idb-keyval';
If you're targeting IE10/11, use the compat version, and import a Promise polyfill.
// Import a Promise polyfill
import 'es6-promise/auto';
import { get, set } from 'idb-keyval/compat';
All bundles
A well-behaved bundler should automatically pick the ES module or the CJS module depending on what it supports, but if you need to force it either way:
idb-keyval/dist/index.js EcmaScript module.
idb-keyval/dist/index.cjs CommonJS module.
Legacy builds:
idb-keyval/compat transpiled for older browsers; a well-behaved bundler will pick the ES module or CJS module as appropriate.
idb-keyval/umd UMD module, transpiled for older browsers; a well-behaved bundler will pick the appropriate module.
idb-keyval/dist/compat.js EcmaScript module, transpiled for older browsers.
idb-keyval/dist/compat.cjs CommonJS module, transpiled for older browsers.
idb-keyval/dist/umd.js UMD module, also transpiled for older browsers.
These built versions are also available on jsDelivr, e.g.:
<script src="https://cdn.jsdelivr.net/npm/idb-keyval@6/dist/umd.js"></script>
<!-- Or in modern browsers: -->
<script type="module">
import { get, set } from 'https://cdn.jsdelivr.net/npm/idb-keyval@6/+esm';
</script>
Usage
set:
import { set } from 'idb-keyval';
set('hello', 'world');
Since this is IDB-backed, you can store anything structured-clonable (numbers, arrays, objects, dates, blobs etc), although old Edge doesn't support null. Keys can be numbers, strings, Dates, (IDB also allows arrays of those values, but IE doesn't support it).
All methods return promises:
import { set } from 'idb-keyval';
set('hello', 'world')
.then(() => console.log('It worked!'))
.catch((err) => console.log('It failed!', err));
get:
import { get } from 'idb-keyval';
// logs: "world"
get('hello').then((val) => console.log(val));
If there is no 'hello' key, then val will be undefined.
setMany:
Set many keyval pairs at once. This is faster than calling set multiple times.
Transforming a value (eg incrementing a number) using get and set is risky, as both get and set are async and non-atomic:
// Don't do this:
import { get, set } from 'idb-keyval';
get('counter').then((val) =>
set('counter', (val || 0) + 1);
);
get('counter').then((val) =>
set('counter', (val || 0) + 1);
);
With the above, both get operations will complete first, each returning undefined, then each set operation will be setting 1. You could fix the above by queuing the second get on the first set, but that isn't always feasible across multiple pieces of code. Instead:
By default, the methods above use an IndexedDB database named keyval-store and an object store named keyval. If you want to use something different, see custom stores.
TopGit's last sync did not record any GitHub topics for jakearchibald/idb-keyval. GitHub topics appear in the right sidebar of a repository page; that's the authoritative place to check.
How active is development on jakearchibald/idb-keyval?
The most recent commit recorded on jakearchibald/idb-keyval was 4 months ago, based on the GitHub push timestamp. The repository has 148 forks — one of the better signals of community interest.
How many stars does jakearchibald/idb-keyval have?
jakearchibald/idb-keyval has 3.3k GitHub stars — refresh the page for the live number, or check github.com/jakearchibald/idb-keyval. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
What is jakearchibald/idb-keyval?
jakearchibald/idb-keyval (jakearchibald/idb-keyval) is a TypeScript project on GitHub. From the project's own README: A super-simple-small promise-based keyval store implemented with IndexedDB
What language is jakearchibald/idb-keyval written in?
jakearchibald/idb-keyval is written primarily in TypeScript. GitHub's language field is based on the largest share of bytes in the default branch.
Read full README in the tab above.
Want a second opinion on idb-keyval?
Ask an AI that can read this page — one click and you get its take on idb-keyval.