Registry / storage / good-storage

good-storage

JSON →
library1.1.1jsnpmunverified

A lightweight JavaScript library providing a unified API for sessionStorage and localStorage in the browser. Version 1.1.1 is the stable release. It simplifies storage operations with methods like set, get, remove, clear, and iteration support. Key differentiator: same API for both storage types with a namespace for sessionStorage.

npm install good-storage
INSTALL
IMPORT
SIG · GOOD-STORAGE
G
good-storage
storagejavascriptv1.1.1
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.

default
import storage from 'good-storage'
const storage = require('good-storage')
Package exports a default object; CommonJS require works but ESM is recommended.
set
storage.set(key, val)
storage.set({key: val})
set expects separate key and value arguments, not an object.
session
import storage from 'good-storage'; storage.session.set(key, val)
import { session } from 'good-storage'
session is a property of the default export, not a separate named export.

Shows basic usage of good-storage: setting/getting localStorage and sessionStorage, checking keys, removing, clearing, and iterating.

import storage from 'good-storage'; // Set a value in localStorage storage.set('user', { name: 'Alice' }); // Get the value const user = storage.get('user', {}); console.log(user.name); // 'Alice' // Use sessionStorage storage.session.set('token', 'abc123'); const token = storage.session.get('token'); console.log(token); // 'abc123' // Check if key exists if (storage.has('user')) { console.log('user exists'); } // Remove key storage.remove('user'); // Clear all localStorage storage.clear(); // Iterate over all items storage.getAll(); // returns object of key-value pairs storage.forEach((val, key) => console.log(key, val));
Debug
Known issues
gotchaThe `set` method does not support complex objects serialization automatically; it uses JSON.stringify internally but may fail for non-serializable values.
fix
Ensure values are JSON-serializable (e.g., no functions, undefined, or circular references).
affects: >=1.0.0
gotchaThe `get` method returns the provided default value `def` only if the key is not found; it does not return `def` if the stored value is explicitly null.
fix
Use `has(key)` to check existence before calling `get` if you need to distinguish between missing and null.
affects: >=1.0.0
gotchaThe `clear` method only clears localStorage; sessionStorage must be cleared separately via `storage.session.clear()`.
fix
Call `storage.session.clear()` to clear sessionStorage.
affects: >=1.0.0
gotchaThe `getAll` method returns an object with all localStorage key-value pairs, but not sessionStorage; there is no separate `session.getAll` method.
fix
To get all sessionStorage items, you must use the native sessionStorage API or iterate manually.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: storage.set is not a function
Using named import `{ set }` instead of default import or having multiple versions of the library.
fix
Use `import storage from 'good-storage'` then call `storage.set(...)`.
Uncaught DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.
Running in a browser context where localStorage is blocked (e.g., sandboxed iframe or third-party cookie restrictions).
fix
Check browser settings or use a try-catch block to fallback gracefully.
ReferenceError: window is not defined
Running in a non-browser environment like Node.js.
fix
Ensure the code runs in a browser, or check if `typeof window !== 'undefined'` before using the library.
Cannot read property 'session' of undefined
The imported variable is not the default export (e.g., using `import * as storage`).
fix
Use default import: `import storage from 'good-storage'`.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
14
OpenAI (training)
1
Resources
good-storage — npm install good-storage · libregistry