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.

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 is ESM-only; CommonJS require will fail. Use named import.

import { getStorage } from 'get-storage'

setStorage is a named export, not default.

import { setStorage } from 'get-storage'

Named export for removing a key.

import { removeStorage } from 'get-storage'

Type-only import to avoid runtime overhead when only using types.

import type { StorageOptions } from 'get-storage'

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 footguns
breakingVersion 0.3.0 changed the import path from 'get-storage/lib' to 'get-storage'
gotchaValues are JSON-serialized, so functions and undefined are lost on retrieval.
deprecatedThe 'storageType' option has been deprecated in favor of 'storage' property.
gotchaDoes not support server-side rendering (SSR) — accessing window fails in Node.
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
16 hits · last 30 days
bytedance
5
gptbot
3
amazonbot
3
Resources