Registry / storage / storage-manager

storage-manager

JSON →
library1.3.0jsnpmunverified

A lightweight browser-side web storage wrapper for localStorage and sessionStorage with TTL (time-to-live) support. Version 1.3.0 is the current stable release; the package sees infrequent updates. It differentiates from bare Web Storage API by adding automatic expiration of stored items, configurable in milliseconds, seconds, minutes, hours, or days, with optional automatic TTL refresh on get. Supports both LocalStorage and SessionStorage with a consistent API.

npm install storage-manager
INSTALL
IMPORT
SIG · STORAGE-MANAGER
S
storage-manager
storagejavascriptv1.3.0
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.

LocalStorage
import { LocalStorage } from 'storage-manager'
const LocalStorage = require('storage-manager'); // gives { LocalStorage, SessionStorage }
Named export; default export is not available.
SessionStorage
import { SessionStorage } from 'storage-manager'
import SessionStorage from 'storage-manager'; // default import does not exist
Named export; works identically to LocalStorage.
LocalStorage or SessionStorage
const { LocalStorage } = require('storage-manager')
const LocalStorage = require('storage-manager/LocalStorage') // wrong path
CommonJS destructuring is correct since all exports are named.

Shows how to import and use LocalStorage with TTL, get, remove, clearAll, and SessionStorage.

import { LocalStorage } from 'storage-manager'; // Set with TTL of 2 minutes LocalStorage.set('key', 'value', { minutes: 2 }); // Get (refreshes TTL by default) const val = LocalStorage.get('key'); // Remove LocalStorage.remove('key'); // Clear all LocalStorage.clearAll(); // SessionStorage works identically import { SessionStorage } from 'storage-manager'; SessionStorage.set('sessionKey', 'sessionValue', { seconds: 30 });
Debug
Known issues
gotchaTTL refresh is enabled by default on get(). If you set an item with { minutes: 2 }, each get() resets the expiration to 2 minutes from that moment. To disable this, set refreshTTL: false in options.
fix
Pass { minutes: 2, refreshTTL: false } to set() if you want the TTL to count down from the initial set time without refreshing.
affects: >=1.0.0
gotchaLocalStorage and SessionStorage rely on window.localStorage and window.sessionStorage respectively. They will throw if called in a non-browser environment (e.g., Node.js or server-side rendering).
fix
Always check for browser environment before using, e.g., if (typeof window !== 'undefined'). Consider using a polyfill or conditional import.
affects: >=1.0.0
gotchaThe package does not include TypeScript type definitions. You may need to install @types/storage-manager separately (if available) or declare your own module types.
fix
Create a .d.ts file: declare module 'storage-manager' { export class LocalStorage { ... } }
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'setItem')
window.localStorage is undefined (e.g., in Node.js or SSR).
fix
Ensure code runs only in browser: if (typeof window !== 'undefined') { LocalStorage.set('key', 'value'); }
Error: Invalid time unit. Use milliseconds, seconds, minutes, hours, days
Passing unsupported time unit or misspelling (e.g., 'minute' instead of 'minutes').
fix
Use only: 'milliseconds', 'seconds', 'minutes', 'hours', 'days'.
Uncaught ReferenceError: LocalStorage is not defined
Wrong import statement; using default import instead of named import.
fix
Use: import { LocalStorage } from 'storage-manager'
Upgrade
Version history
1.3.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
39 hits · last 30 days
node
36
Resources
storage-manager — npm install storage-manager · libregistry