Registry / storage / get-storage

get-storage

JSON →
library0.3.2jsnpmunverified

A lightweight utility for easy set and get operations on Web Storage (localStorage and sessionStorage) with TypeScript type definitions. Current version 0.3.2, released as part of the react-atomic-organism monorepo. It provides a simple API to handle serialization/deserialization, supports default values, and works in browser environments. Compared to similar libraries like store2 or localForage, get-storage focuses on minimal footprint and ESM compatibility.

npm install get-storage
INSTALL
IMPORT
SIG · GET-STORAGE
G
get-storage
storagejavascriptv0.3.2
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.

getStorage
import { getStorage } from 'get-storage'
const getStorage = require('get-storage')
Package is ESM-only; CommonJS require will fail. Use named import.
setStorage
import { setStorage } from 'get-storage'
import setStorage from 'get-storage'
setStorage is a named export, not default.
removeStorage
import { removeStorage } from 'get-storage'
Named export for removing a key.
type StorageOptions
import type { StorageOptions } from 'get-storage'
import { StorageOptions } from 'get-storage'
Type-only import to avoid runtime overhead when only using types.

Demonstrates basic set, get with default, remove operations, custom storage option, and TypeScript generics.

import { getStorage, setStorage, removeStorage } from 'get-storage'; // Set a value (automatically JSON-serialized) setStorage('user', { name: 'Alice', age: 30 }); // Get a value with default fallback const user = getStorage('user', { name: 'Guest' }); console.log(user.name); // 'Alice' // Remove a key removeStorage('user'); // usage with sessionStorage (default is localStorage) import { setStorage } from 'get-storage'; setStorage('key', 'value', { storage: sessionStorage }); // TypeScript usage with generics const count = getStorage<number>('count', 0);
Debug
Known issues
breakingVersion 0.3.0 changed the import path from 'get-storage/lib' to 'get-storage'
fix
Update import to 'get-storage' directly
affects: <0.3.0
gotchaValues are JSON-serialized, so functions and undefined are lost on retrieval.
fix
Store only JSON-serializable data.
affects: >=0.0.0
deprecatedThe 'storageType' option has been deprecated in favor of 'storage' property.
fix
Use { storage: sessionStorage } instead of { storageType: 'session' }
affects: >=0.2.0 <0.3.0
gotchaDoes not support server-side rendering (SSR) — accessing window fails in Node.
fix
Conditionally import or use a polyfill for server environments.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'getItem')
Storage is undefined (e.g., in Node.js or when cookies are blocked).
fix
Check if window is defined: if (typeof window !== 'undefined') { /* use get-storage */ }
import { getStorage } from 'get-storage' // SyntaxError: Cannot use import statement outside a module
Using ES modules in a CommonJS project without proper configuration.
fix
Set 'type': 'module' in package.json or use dynamic import().
Uncaught TypeError: Converting circular structure to JSON
Storing an object with circular references.
fix
Ensure stored data has no circular references, or implement a custom serializer.
Upgrade
Version history
0.3.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
29 hits · last 30 days
node
28
OpenAI (training)
1
Resources
get-storage — npm install get-storage · libregistry