safe-storage (v1.0.2) provides drop-in replacements for localStorage and sessionStorage that gracefully fall back to an in-memory implementation when the native browser storages are unavailable or throw errors (e.g., Safari private mode). No dependencies, no build step, and supports both ESM and CommonJS. Unlike other storage wrappers, it specifically targets the Safari private browsing bug and does not introduce any new API surface — it exactly mirrors the native Storage interface. Released in 2017, stable with no recent updates.
npm install safe-storageNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates basic setItem, getItem, length, and clear methods for both safeLocalStorage and safeSessionStorage.
Wrap calls in a try-catch if you need to handle quota exceeded errors, or use a different library that handles that case.
Consider using a more modern alternative like 'localforage' or 'storage-factory' that provides a similar fallback but with more features and active maintenance.
Do not use this library on the server side for persistent data; use a dedicated database or file-based storage instead.
Use named import: `import { safeLocalStorage } from 'safe-storage'`Install the package: `npm install safe-storage`. Ensure tsconfig.json includes 'node_modules' in 'types' or 'typeRoots'.
Ensure the import is at the top of the file and that the module is correctly installed. Check for circular dependencies.
No dependency data recorded yet.