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

universal-webstorage

v0.1.2

Published

A universal, lightweight utility for managing web storage (localStorage, sessionStorage, etc.) with support for JSON operations, TTL, bulk actions, and React hooks.

Readme

universal-webstorage

universal-webstorage is a lightweight, universal utility for managing web storage based on the MDN Web Storage API specification. It provides a consistent API for core storage operations, bulk actions, JSON handling, and TTL (time-to-live) support. The library works with localStorage, sessionStorage, or any custom storage-like interface.

Note: For React-specific hooks and functionality, please see the separate @aivron/sync-storage package.

Features

  • Core Storage Operations: Get, set, update, and remove individual keys.
  • Bulk Operations: Filter, update, and remove multiple keys based on a predicate.
  • JSON Support: Automatically stringify/parse JSON values for seamless object storage.
  • TTL (Time-To-Live) Support: Store items with an expiration time.
  • Universal: Works with localStorage, sessionStorage, or any storage-like interface.

Installation

Install via npm:

npm install universal-webstorage

Or via yarn:

yarn add universal-webstorage

Usage

Importing the Library

You can import individual functions or use the main entry point to access all utilities.

// Import specific functions:
import { setStorageItem, getStorageItem } from 'universal-webstorage';

// Or import the entire module:
import * as webstorage from 'universal-webstorage';

Basic Operations

Store a Key-Value Pair

import { setStorageItem } from 'universal-webstorage';

setStorageItem("userToken", "abc123");

Retrieve a Stored Item

import { getStorageItem } from 'universal-webstorage';

const token = getStorageItem("userToken");
console.log(token); // Output: "abc123"

Update a Stored Item

import { updateStorageItem } from 'universal-webstorage';

updateStorageItem("userToken", (current) =>
  current ? current + "_v2" : "defaultToken"
);

Remove a Stored Item

import { removeStorageItem } from 'universal-webstorage';

removeStorageItem("userToken");

Bulk Operations

Retrieve Multiple Items

For example, retrieve all keys that start with "app:":

import { getStorageItems } from 'universal-webstorage';

const appItems = getStorageItems((key) => key.startsWith("app:"));
console.log(appItems);

Update Multiple Items

import { updateStorageItems } from 'universal-webstorage';

updateStorageItems(
  (key) => key.startsWith("app:"),
  (current) => (current ? current.toUpperCase() : "")
);

Remove Multiple Items

import { removeStorageKeys } from 'universal-webstorage';

removeStorageKeys((key) => key.includes("temp"));

JSON Operations

Store a JSON Value

import { setJSONItem } from 'universal-webstorage';

setJSONItem("userData", { name: "Alice", age: 30 });

Retrieve a JSON Value

import { getJSONItem } from 'universal-webstorage';

const userData = getJSONItem<{ name: string; age: number }>("userData");
console.log(userData);

Update a JSON Value

import { updateJSONItem } from 'universal-webstorage';

updateJSONItem<{ name: string; age: number }>("userData", (current) => ({
  ...current,
  age: (current?.age || 0) + 1,
}));

TTL (Time-To-Live) Operations

Store an Item with TTL

Store an item that expires in 1 hour:

import { setStorageItemWithTTL } from 'universal-webstorage';

setStorageItemWithTTL("sessionData", "sessionValue", 3600 * 1000);

Retrieve an Item with TTL

import { getStorageItemWithTTL } from 'universal-webstorage';

const sessionValue = getStorageItemWithTTL("sessionData");
console.log(sessionValue);

MDN Reference

This library follows the MDN Web Storage API specification. For detailed information on how the Web Storage API works, refer to the MDN documentation.

API Reference

For detailed API documentation, please refer to the documentation website or review the source code in the repository.

Contributing

Contributions, issues, and feature requests are welcome! Please check the issues page if you want to contribute.

License

This project is licensed under the MIT License. See the LICENSE file for details.


Enjoy using universal-webstorage for all your web storage needs! If you have any questions or need further assistance, feel free to reach out.