Registry / storage / serviceworker-storage

serviceworker-storage

JSON →
library0.1.0jsnpmunverified

A lightweight library providing a localStorage-like API for use within Service Workers. Current stable version is 0.1.0. It offers simple asynchronous get/set operations backed by IndexedDB, with support for versioned storage instances. Unlike directly using the Cache API or IndexedDB, it provides a familiar synchronous-style interface (though methods return Promises) and automatic key management. Minimal dependencies; suitable for small projects needing persistent storage in Service Workers.

npm install serviceworker-storage
INSTALL
IMPORT
SIG · SERVICEWORKER-STOR
S
serviceworker-storage
storagejavascriptv0.1.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.

ServiceWorkerStorage
import ServiceWorkerStorage from 'serviceworker-storage'
const { ServiceWorkerStorage } = require('serviceworker-storage')
Default export; CommonJS require would need .default property.

Creates a versioned storage instance, sets and retrieves an object, checks length, gets a key by index, removes an item.

import ServiceWorkerStorage from 'serviceworker-storage'; const storage = new ServiceWorkerStorage('MyStorage', 1); storage.setItem('myKey', { foo: 'bar' }).then(() => { console.log('Item saved'); return storage.getItem('myKey'); }).then(value => { console.log(value); // { foo: 'bar' } return storage.length(); }).then(len => { console.log('Storage length:', len); return storage.key(0); }).then(key => { console.log('First key:', key); return storage.removeItem('myKey'); }).then(() => { console.log('Item removed'); });
Debug
Known issues
gotchaVersions are not automatically migrated; if you increment version, old data is inaccessible.
fix
Use a consistent version number or implement manual migration.
affects: >=0.0.0
gotchaAll methods return Promises, even though the API looks synchronous like localStorage.
fix
Always use .then() or await when calling methods.
affects: >=0.0.0
deprecatedNo built-in TypeScript types; library is plain JavaScript.
fix
Create custom type declarations or use JSDoc.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: ServiceWorkerStorage is not a constructor
Incorrect import: using named import instead of default import in ESM.
fix
Use `import ServiceWorkerStorage from 'serviceworker-storage'`.
Cannot read property 'then' of undefined
Calling a method without awaiting or not returning the promise chain.
fix
Ensure all storage methods are awaited or chained with .then().
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
16
OpenAI (training)
1
Resources
serviceworker-storage — npm install serviceworker-storage · libregistry