Registry / storage / expirable-storage

expirable-storage

JSON →
library1.0.0jsnpmunverified

Expirable data storage wrapper around localStorage and sessionStorage for the browser. Version 1.0.0 with no release cadence reported. Supports automatically expiring items based on a TTL in seconds, and removes expired entries on getItem access. Lightweight, TypeScript-first package with no dependencies. Differentiates from similar libraries (e.g., localForage, idb-keyval) by providing a simple, symmetrical expirable wrapper for both persistent and session scopes.

npm install expirable-storage
INSTALL
IMPORT
SIG · EXPIRABLE-STORAGE
E
expirable-storage
storagejavascriptv1.0.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.

expirableLocalStorage
import { expirableLocalStorage } from 'expirable-storage'
const expirableLocalStorage = require('expirable-storage')
Package is ESM-only, CommonJS require will fail.
expirableSessionStorage
import { expirableSessionStorage } from 'expirable-storage'
import expirableSessionStorage from 'expirable-storage'
expirableSessionStorage is a named export, not a default export.
type definitions
import type { ExpirableStorage } from 'expirable-storage'
If you need the type, import it explicitly.

Shows how to import and use both expirableLocalStorage and expirableSessionStorage with a 15-minute TTL.

import { expirableLocalStorage, expirableSessionStorage } from 'expirable-storage'; const expires = 900; // 900 seconds (15 minutes) expirableLocalStorage.setItem('key1', 'value1', expires); const val1 = expirableLocalStorage.getItem('key1'); console.log('localStorage value:', val1); expirableSessionStorage.setItem('key2', 'value2', expires); const val2 = expirableSessionStorage.getItem('key2'); console.log('sessionStorage value:', val2);
Debug
Known issues
gotchagetItem returns null if the item is expired, but does not automatically remove it from storage until getItem is called.
fix
Ensure you call getItem to trigger cleanup; consider a periodic cleanup if many keys accumulate.
affects: >=1.0.0
gotchaThe expires parameter is in seconds, not milliseconds.
fix
Always pass seconds, e.g., 900 for 15 minutes, not 900000.
affects: >=1.0.0
gotchaThe package only works in browser environments with localStorage and sessionStorage APIs. It will throw in Node.js.
fix
Check that the code runs in a browser or use a polyfill.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: expirableLocalStorage is not a function
Using a default import instead of named import.
fix
import { expirableLocalStorage } from 'expirable-storage';
Cannot find module 'expirable-storage' or its corresponding type declarations.
Missing npm install or TypeScript not resolving the package. The package ships types, but tsconfig may not be configured.
fix
Run 'npm install expirable-storage' and ensure 'node_modules' is in the include paths.
ReferenceError: localStorage is not defined
Running in a non-browser environment (e.g., Node.js, SSR).
fix
Only use this package in browser contexts or provide a localStorage polyfill.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
26 hits · last 30 days
node
24
Amazon
1
Resources
expirable-storage — npm install expirable-storage · libregistry