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-storageNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage: import default function sts, create a storage instance with a key, set/get/remove serializable data.
Use import sts from 'safe-typed-storage' instead of import { sts } from 'safe-typed-storage'Replace createStorage(...) with sts(...)
Check for null explicitly: const value = storage.get(); if (value === null) { /* handle missing */ }Use ttl: 60000 for 1 minute, not 60
Remove await from storage.set/get/remove calls
npm install safe-typed-storage and use import syntax.
Use import sts from 'safe-typed-storage' instead of import { sts } from 'safe-typed-storage'.Specify type: const storage = sts<{ value: string }>('KEY', ...);No dependency data recorded yet.