Registry / storage / kv-storage-polyfill

kv-storage-polyfill

JSON →
library2.0.0jsnpmunverified

Polyfill for the proposed kv-storage built-in module (WICG spec), version 2.0.0. Provides a simple key-value storage API similar to the native `std:kv-storage` module for browsers that don't support it yet, with optional import map fallback. It offers an async API similar to IndexedDB but simpler, and uses a shim backed by localStorage or IndexedDB. Works in modern browsers and Node.js (15+), but the native standard is not yet widely implemented.

npm install kv-storage-polyfill
INSTALL
IMPORT
SIG · KV-STORAGE-POLYFIL
K
kv-storage-polyfill
storagejavascriptv2.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

storage
import { storage } from 'kv-storage-polyfill'
import storage from 'kv-storage-polyfill'
Named export, not default.
KVStorageFactory
import { KVStorageFactory } from 'kv-storage-polyfill'
const { KVStorageFactory } = require('kv-storage-polyfill')
ESM only, not available in CJS.
StorageArea
import { StorageArea } from 'kv-storage-polyfill'
const storage = require('kv-storage-polyfill'); new storage.StorageArea()
Named export; require doesn't work because package is ESM-only.

Shows basic set, get, delete operations with the storage export.

import { storage } from 'kv-storage-polyfill'; async function main() { await storage.set('key', 'value'); const val = await storage.get('key'); console.log(val); // 'value' await storage.delete('key'); console.assert(await storage.get('key') === undefined); } main();
Debug
Known issues
gotchaPackage is ESM-only and cannot be required() or used in CommonJS without dynamic import.
fix
Use import syntax or dynamic import('kv-storage-polyfill').
affects: >=2.0.0
deprecatedThe kv-storage specification is not widely implemented and its future is uncertain.
fix
Consider using localForage or IndexedDB for production projects.
affects: >=0.0.0
gotchaThe storage object is not shared across different origins or tabs by design (like localStorage per origin).
fix
Use a different key-value store if cross-tab or cross-origin sharing is required.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'kv-storage-polyfill'
Package not installed or version not specified.
fix
Run: npm install kv-storage-polyfill
SyntaxError: Cannot use import statement outside a module
Using import in a non-module script or Node.js without "type": "module".
fix
Add "type": "module" to package.json or use .mjs extension; in browsers use <script type="module">.
ReferenceError: storage is not defined
Importing incorrectly as default or using wrong path.
fix
Use named import: import { storage } from 'kv-storage-polyfill';
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
18
Resources
kv-storage-polyfill — npm install kv-storage-polyfill · libregistry