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.

storage
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.

Package exports a default object; CommonJS require works but ESM is recommended.

import storage from 'good-storage'

set expects separate key and value arguments, not an object.

storage.set(key, val)

session is a property of the default export, not a separate named export.

import storage from 'good-storage'; storage.session.set(key, val)

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 footguns
gotchaThe `set` method does not support complex objects serialization automatically; it uses JSON.stringify internally but may fail for non-serializable values.
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.
gotchaThe `clear` method only clears localStorage; sessionStorage must be cleared separately via `storage.session.clear()`.
gotchaThe `getAll` method returns an object with all localStorage key-value pairs, but not sessionStorage; there is no separate `session.getAll` method.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
14 hits · last 30 days
gptbot
3
amazonbot
3
ahrefsbot
1
Resources