jakearchibald/idb-keyval là dự án mã nguồn mở trên GitHub với 3.2k sao, viết chủ yếu bằng TypeScript. A super-simple-small promise-based keyval store implemented with IndexedDB
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
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.
jakearchibald/idb-keyval có 3.2k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/jakearchibald/idb-keyval. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
jakearchibald/idb-keyval có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho jakearchibald/idb-keyval. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
jakearchibald/idb-keyval còn đang phát triển không?
Commit gần nhất trên jakearchibald/idb-keyval là 1 tháng trước (theo timestamp GitHub). Repo có 150 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
jakearchibald/idb-keyval là gì?
jakearchibald/idb-keyval (jakearchibald/idb-keyval) là dự án TypeScript trên GitHub. Theo mô tả gốc: A super-simple-small promise-based keyval store implemented with IndexedDB
jakearchibald/idb-keyval viết bằng ngôn ngữ gì?
jakearchibald/idb-keyval chủ yếu viết bằng TypeScript. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
idb-keyval có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về idb-keyval.