{"id":47776,"library":"good-storage","title":"good-storage","description":"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.","status":"active","version":"1.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/ustbhuangyi/storage","tags":["javascript","store","html5"],"install":[{"cmd":"npm install good-storage","lang":"bash","label":"npm"},{"cmd":"yarn add good-storage","lang":"bash","label":"yarn"},{"cmd":"pnpm add good-storage","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package exports a default object; CommonJS require works but ESM is recommended.","wrong":"const storage = require('good-storage')","symbol":"default","correct":"import storage from 'good-storage'"},{"note":"set expects separate key and value arguments, not an object.","wrong":"storage.set({key: val})","symbol":"set","correct":"storage.set(key, val)"},{"note":"session is a property of the default export, not a separate named export.","wrong":"import { session } from 'good-storage'","symbol":"session","correct":"import storage from 'good-storage'; storage.session.set(key, val)"}],"quickstart":{"code":"import storage from 'good-storage';\n\n// Set a value in localStorage\nstorage.set('user', { name: 'Alice' });\n\n// Get the value\nconst user = storage.get('user', {});\nconsole.log(user.name); // 'Alice'\n\n// Use sessionStorage\nstorage.session.set('token', 'abc123');\nconst token = storage.session.get('token');\nconsole.log(token); // 'abc123'\n\n// Check if key exists\nif (storage.has('user')) {\n  console.log('user exists');\n}\n\n// Remove key\nstorage.remove('user');\n\n// Clear all localStorage\nstorage.clear();\n\n// Iterate over all items\nstorage.getAll(); // returns object of key-value pairs\nstorage.forEach((val, key) => console.log(key, val));","lang":"javascript","description":"Shows basic usage of good-storage: setting/getting localStorage and sessionStorage, checking keys, removing, clearing, and iterating."},"warnings":[{"fix":"Ensure values are JSON-serializable (e.g., no functions, undefined, or circular references).","message":"The `set` method does not support complex objects serialization automatically; it uses JSON.stringify internally but may fail for non-serializable values.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use `has(key)` to check existence before calling `get` if you need to distinguish between missing and null.","message":"The `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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Call `storage.session.clear()` to clear sessionStorage.","message":"The `clear` method only clears localStorage; sessionStorage must be cleared separately via `storage.session.clear()`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"To get all sessionStorage items, you must use the native sessionStorage API or iterate manually.","message":"The `getAll` method returns an object with all localStorage key-value pairs, but not sessionStorage; there is no separate `session.getAll` method.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.1.1':20 'api':11,42 'browser':18 'clear':35 'differenti':40 'get':33 'good':2 'good-storag':1 'html5':54 'iter':37 'javascript':6,52 'key':39 'librari':7 'lightweight':5 'like':31 'localstorag':15 'method':30 'namespac':49 'oper':28 'provid':8 'releas':24 'remov':34 'sessionstorag':13,51 'set':32 'simplifi':26 'stabl':23 'storag':3,27,45 'store':53 'support':38 'type':46 'unifi':10 'version':19","created_at":"2026-06-07T16:53:16.010474+00:00","updated_at":"2026-06-07T16:53:16.010474+00:00","problems":[{"fix":"Use `import storage from 'good-storage'` then call `storage.set(...)`.","cause":"Using named import `{ set }` instead of default import or having multiple versions of the library.","error":"TypeError: storage.set is not a function"},{"fix":"Check browser settings or use a try-catch block to fallback gracefully.","cause":"Running in a browser context where localStorage is blocked (e.g., sandboxed iframe or third-party cookie restrictions).","error":"Uncaught DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document."},{"fix":"Ensure the code runs in a browser, or check if `typeof window !== 'undefined'` before using the library.","cause":"Running in a non-browser environment like Node.js.","error":"ReferenceError: window is not defined"},{"fix":"Use default import: `import storage from 'good-storage'`.","cause":"The imported variable is not the default export (e.g., using `import * as storage`).","error":"Cannot read property 'session' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/ustbhuangyi/storage#readme","github":"https://github.com/ustbhuangyi/storage","docs":null,"changelog":null,"pypi":null,"npm":"good-storage","openapi_spec":null,"status_page":null,"smithery":null,"categories":["storage"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}