safe (dont throw) versions of local and session storage

Usage no npm install needed!

<script type="module">
  import rpldySafeStorage from 'https://cdn.skypack.dev/@rpldy/safe-storage';


npm version circleci status codecov status bundlephobia badge rpldy storybook

Safe Storage

Internal package

provides safe versions of localStorage and sessionStorage that don't throw because of browser issues like safari in private mode.

exposes the same storage API as the browser's API -

In case storage isn't supported, the same API is available but will be replaced with no-op versions.


   $ yarn add @rpldy/safe-storage

   $ npm i @rpldy/safe-storage


All exports of this package are considered internal API and may change/disappear in any version: patch/minor/major


import { safeLocalStorage } from "@rpldy/safe-storage";

safeLocalStorage.setItem("test", "value");

const stored = safeLocalStorage.getItem("test");