npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@arraypress/safe-storage

v1.0.0

Published

Browser storage (localStorage / sessionStorage) that never throws. When storage is off (a private window, blocked site data) even touching it throws: here reads give null and writes do nothing, so the page carries on without it.

Downloads

174

Readme

@arraypress/safe-storage

Browser storage that never throws. localStorage and sessionStorage for what a page remembers — a theme, a session, a table's settings — where storage being off reads null and writes nothing, so the page carries on without it.

Zero dependencies. ESM-only. Safe to import anywhere: in Node or a Cloudflare Worker, where there's no storage at all, reads are null and writes do nothing.

Install

npm install @arraypress/safe-storage

Why this exists

Storage can be off: a private window, blocked site data, a sandboxed iframe. Then it isn't just empty — even touching localStorage throws a SecurityError, before you get to getItem. A full quota throws on setItem. So every read and write needs its own try/catch, and the one you forget takes the page down with it.

This package is those try/catch blocks, once.

Usage

import {
  readStored, writeStored,
  readStoredJson, writeStoredJson,
  isStorageAvailable,
} from '@arraypress/safe-storage';

// Strings
writeStored('local', 'theme', 'dark');
readStored('local', 'theme');          // 'dark' (null when missing, or storage is off)
writeStored('local', 'theme', null);   // null removes it

// JSON
writeStoredJson('session', 'table', { perPage: 25, sort: 'total' });
readStoredJson('session', 'table');    // { perPage: 25, sort: 'total' }
readStoredJson('session', 'nothing');  // null (missing, or not JSON)
writeStoredJson('session', 'table', null);

// Will writes stick?
isStorageAvailable('local');           // false in a private window with storage blocked

API

Every function takes an area first: 'local' for localStorage (kept across visits) or 'session' for sessionStorage (this tab).

readStored(area, key)

The stored string, or null when there's none — or storage is off.

writeStored(area, key, value)

Stores value (a string). With null, removes the key. When storage is off or full, does nothing.

writeStored('local', 'banner-dismissed', '1');
writeStored('local', 'banner-dismissed', null); // forget it

An empty string is a value, not a removal.

readStoredJson(area, key)

The parsed value, or null when there's none, it isn't JSON, or storage is off. A bad value never throws — someone else's half-written key just reads as nothing.

writeStoredJson(area, key, value)

Stores JSON.stringify(value). With null, removes the key. A value JSON can't write (undefined, a function, a cycle, a BigInt) writes nothing and leaves what was there.

isStorageAvailable(area)

true when a write to the area sticks right now: it stores and removes a probe key to find out. false when storage is off, missing, or full. Use it to say "settings won't be remembered in this window", not as a guard — the other functions are already safe.

TypeScript

Ships with .d.ts. readStoredJson is generic:

import { readStoredJson, type StorageArea } from '@arraypress/safe-storage';

interface TableSettings { perPage: number; sort: string }

const area: StorageArea = 'session';
const settings = readStoredJson<TableSettings>(area, 'table'); // TableSettings | null

The type parameter is a promise you make about what's stored, not a check — validate it if other code writes the same key.

License

MIT