Registry / storage / web-browser-storage

web-browser-storage

JSON →
library0.1.14jsnpmunverified

A wrapper around localStorage providing JSON value handling, caching, and a consistent Storage interface. Version 0.1.14 is current. The library offers LocalStorage (real browser storage with availability checks), MemoryStorage (for testing, with optional shared instances), and CachedStorage (buffers writes and flushes on delay/tab blur). It differs from similar libraries by including onExternalChange listeners and byte size reporting. Ideal for apps needing robust browser storage with testability and performance optimizations.

npm install web-browser-storage
INSTALL
IMPORT
SIG · WEB-BROWSER-STORAG
W
web-browser-storage
storagejavascriptv0.1.14
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.

LocalStorage
✓ import { LocalStorage } from 'web-browser-storage'
✗ import LocalStorage from 'web-browser-storage'
Named export, not default. Must use destructuring.
MemoryStorage
✓ import { MemoryStorage } from 'web-browser-storage'
✗ const MemoryStorage = require('web-browser-storage').MemoryStorage
ESM named import. CJS require works but is not tree-shakable.
CachedStorage
✓ import { CachedStorage } from 'web-browser-storage'
✗ import { CachedStorage } from 'web-browser-storage/cached'
Single entry point. No subpath exports.

Shows basic usage: store and retrieve JSON, check localStorage availability, and listen for external changes.

import { LocalStorage } from 'web-browser-storage' const storage = new LocalStorage() storage.set('user', { name: 'Alice', age: 30 }) const user = storage.get('user') console.log(user.name) // 'Alice' if (!LocalStorage.isAvailable()) { console.warn('localStorage is disabled') } storage.onExternalChange(({ key, value, prevValue }) => { console.log(`Key ${key} changed from ${JSON.stringify(prevValue)} to ${JSON.stringify(value)}`) })
Debug
Known issues
deprecatedThe isAvailable() static method may be deprecated in future versions.
fix
Check availability by wrapping localStorage access in try/catch instead.
affects: <=0.1.14
gotchaMemoryStorage stringifies values by default (simulating localStorage). Date objects become strings.
fix
Use { stringifyStoredValues: false } in constructor to keep types intact.
affects: >=0.1.0
gotchaCachedStorage delays writes; data loss risk if browser crashes before flush.
fix
Use flush() manually or rely on tab blur event. Not suitable for critical data.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: localStorage is not available
Calling localStorage methods when localStorage is disabled (e.g., private browsing in some browsers).
fix
Check availability with LocalStorage.isAvailable() before operations.
QuotaExceededError: Failed to execute 'setItem' on 'Storage'
Exceeding browser storage limit (usually 5-10 MB).
fix
Handle with try/catch or use LocalStorage constructor option 'onFull'.
import { LocalStorage } from 'web-browser-storage' did not export 'LocalStorage'
Using an older version (<0.1.0) that had different export names.
fix
Upgrade to >=0.1.0 where all classes are named exports.
Upgrade
Version history
0.1.14latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
44 hits · last 30 days
node
40
Resources
web-browser-storage — npm install web-browser-storage · libregistry