{"id":49264,"library":"safe-typed-storage","title":"safe-typed-storage","description":"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.","status":"active","version":"7.2.1","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","typescript"],"install":[{"cmd":"npm install safe-typed-storage","lang":"bash","label":"npm"},{"cmd":"yarn add safe-typed-storage","lang":"bash","label":"yarn"},{"cmd":"pnpm add safe-typed-storage","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only since v7. CommonJS not supported.","wrong":"const sts = require('safe-typed-storage')","symbol":"sts","correct":"import sts from 'safe-typed-storage'"},{"note":"Named export for creating storage with custom key and options.","wrong":"import createStorage from 'safe-typed-storage'","symbol":"createStorage","correct":"import { createStorage } from 'safe-typed-storage'"},{"note":"TypeScript type export for storage type string literal.","wrong":"import type { StorageType } from 'safe-typed-storage'","symbol":"StorageType","correct":"import { StorageType } from 'safe-typed-storage'"}],"quickstart":{"code":"import sts from 'safe-typed-storage';\n\nconst myStorage = sts('MY_KEY', { storage: 'localStorage' });\n\nmyStorage.set({ name: 'Alice', age: 30 });\nconst data = myStorage.get();\nconsole.log(data); // { name: 'Alice', age: 30 }\n\nmyStorage.remove();\nconsole.log(myStorage.get()); // null","lang":"typescript","description":"Demonstrates basic usage: import default function sts, create a storage instance with a key, set/get/remove serializable data."},"warnings":[{"fix":"Use import sts from 'safe-typed-storage' instead of import { sts } from 'safe-typed-storage'","message":"Default export sts replaces named exports in v7","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Replace createStorage(...) with sts(...)","message":"Named export 'createStorage' is deprecated since v7, use default sts instead","severity":"deprecated","affected_versions":">=7.0.0"},{"fix":"Check for null explicitly: const value = storage.get(); if (value === null) { /* handle missing */ }","message":"get() returns null if key not found or expired, not undefined","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use ttl: 60000 for 1 minute, not 60","message":"TTL is in milliseconds; common mistake is passing seconds","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Remove await from storage.set/get/remove calls","message":"Removed sync API in v6; all methods are synchronous but used to be promise-based","severity":"breaking","affected_versions":">=6.0.0"}],"env_vars":null,"search_vec":"'0.5':54 '7.2.1':23 'allow':24 'api':41 'avail':48 'browser':19,67 'check':45 'current':20 'easi':9 'fallback':35 'gzip':56 'javascript':70 'kb':55 'key':13 'key-valu':12 'librari':16 'localstorag':31,47 'memori':34 'node.js':69 'object':29 'provid':37 'retriev':27 'safe':2,6,62 'safe-typed-storag':1 'save':25 'secur':40 'serializ':28 'sessionstorag':32 'ship':57 'simpl':39 'stabl':21 'storag':4,15 'support':49 'tini':53 'ttl':50 'type':3,7,59 'typescript':58,71 'use':11,64 'valu':14 'version':22 'without':44 'work':43","created_at":"2026-06-07T17:00:53.367007+00:00","updated_at":"2026-06-07T17:00:53.367007+00:00","problems":[{"fix":"npm install safe-typed-storage and use import syntax.","cause":"Package not installed or CommonJS require used in ESM-only context.","error":"Cannot find module 'safe-typed-storage'"},{"fix":"Use import sts from 'safe-typed-storage' instead of import { sts } from 'safe-typed-storage'.","cause":"Named import when default export is used.","error":"TypeError: sts is not a function"},{"fix":"Specify type: const storage = sts<{ value: string }>('KEY', ...);","cause":"Missing generic type parameter for stored data type.","error":"Property 'set' does not exist on type 'StorageInstance<never>'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":null,"github":null,"docs":null,"changelog":null,"pypi":null,"npm":"safe-typed-storage","openapi_spec":null,"status_page":null,"smithery":null,"categories":["storage"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}