Registry / storage / safe-typed-storage

safe-typed-storage

JSON →
library7.2.1jsnpmunverified

A safe, typed, and easy to use key-value storage library for the browser. Current stable version 7.2.1. Allows saving and retrieving serializable objects to localStorage, sessionStorage, with memory fallback. It provides a simple, secure API that works without checking for localStorage availability, supports TTL, and is tiny (0.5kb gzipped). Ships TypeScript types and is safe to use in both browsers and Node.js.

npm install safe-typed-storage
INSTALL
IMPORT
SIG · SAFE-TYPED-STORAGE
S
safe-typed-storage
storagejavascriptv7.2.1
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.

sts
import sts from 'safe-typed-storage'
const sts = require('safe-typed-storage')
ESM-only since v7. CommonJS not supported.
createStorage
import { createStorage } from 'safe-typed-storage'
import createStorage from 'safe-typed-storage'
Named export for creating storage with custom key and options.
StorageType
import { StorageType } from 'safe-typed-storage'
import type { StorageType } from 'safe-typed-storage'
TypeScript type export for storage type string literal.

Demonstrates basic usage: import default function sts, create a storage instance with a key, set/get/remove serializable data.

import sts from 'safe-typed-storage'; const myStorage = sts('MY_KEY', { storage: 'localStorage' }); myStorage.set({ name: 'Alice', age: 30 }); const data = myStorage.get(); console.log(data); // { name: 'Alice', age: 30 } myStorage.remove(); console.log(myStorage.get()); // null
Debug
Known issues
breakingDefault export sts replaces named exports in v7
fix
Use import sts from 'safe-typed-storage' instead of import { sts } from 'safe-typed-storage'
affects: >=7.0.0
deprecatedNamed export 'createStorage' is deprecated since v7, use default sts instead
fix
Replace createStorage(...) with sts(...)
affects: >=7.0.0
gotchaget() returns null if key not found or expired, not undefined
fix
Check for null explicitly: const value = storage.get(); if (value === null) { /* handle missing */ }
affects: >=1.0.0
gotchaTTL is in milliseconds; common mistake is passing seconds
fix
Use ttl: 60000 for 1 minute, not 60
affects: >=1.0.0
breakingRemoved sync API in v6; all methods are synchronous but used to be promise-based
fix
Remove await from storage.set/get/remove calls
affects: >=6.0.0
Errors
Common errors & fixes
Cannot find module 'safe-typed-storage'
Package not installed or CommonJS require used in ESM-only context.
fix
npm install safe-typed-storage and use import syntax.
TypeError: sts is not a function
Named import when default export is used.
fix
Use import sts from 'safe-typed-storage' instead of import { sts } from 'safe-typed-storage'.
Property 'set' does not exist on type 'StorageInstance<never>'
Missing generic type parameter for stored data type.
fix
Specify type: const storage = sts<{ value: string }>('KEY', ...);
Upgrade
Version history
7.2.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
21 hits · last 30 days
node
18
Amazon
1
Resources
safe-typed-storage — npm install safe-typed-storage · libregistry