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

expirix

v0.0.2

Published

A storage wrapper that adds expiration functionality to localStorage and sessionStorage

Readme

Expirix

⚠️ Alert: This package is not yet released. The API and features may change before the first stable version.

A storage wrapper that adds expiration functionality to localStorage or any other storage that follows the Storage interface.

Installation

npm install expirix

Examples

Basic Usage

import { wrapStorage } from "expirix";

// Create a storage wrapper with 30 seconds expiration
const storage = wrapStorage(localStorage, { expiresInSeconds: 30 });

// Store a value (will expire in 30 seconds)
storage.setItem("key", "value");

// Get the value (returns null if expired)
const value = storage.getItem("key");

Creating a reusable storage module

// app-storage.js
import { wrapStorage } from "expirix";

const wrappedLocalStorage = wrapStorage(localStorage, {
  expiresInSeconds: 3600,
});

export default wrappedLocalStorage;
// Using in your app
import storage from "./app-storage.js";

// Store user preferences that expire in 1 hour
storage.setItem("theme", "dark");
storage.setItem("language", "en");

// Later...
const theme = storage.getItem("theme"); // null if expired

API

wrapStorage(originalStorage, options?)

Wraps a Storage object to add expiration functionality.

Parameters:

  • originalStorage (Storage): The storage object (localStorage or sessionStorage)
  • options (object, optional):
    • expiresInSeconds (number, optional): Time in seconds after which stored items expire

Returns: A Storage-compatible object with expiration support

cleanupFactory(originalStorage, options?)

Creates a cleanup function to remove expired values and optionally wrap unwrapped values so that they can be cleaned up later on as well. Useful to cleanup keys that might not be requested by the app anymore.

Parameters:

  • originalStorage (Storage): The storage object (localStorage or sessionStorage)
  • options (object, optional):
    • expiresInSeconds (number, optional): Time in seconds after which stored items expire
    • runWhenBrowserIsIdle (boolean, optional): Whether to run cleanup when browser is idle (default: true)
    • wrapUnwrappedItems (boolean, optional): Whether to wrap non-wrapped items with expiration metadata (default: false) If turned on, this will wrap existing values in a JSON structure. Only use it if you are sure that whatever code reads these values can handle this.

Returns: An object with a runCleanup() method

Example:

import { cleanupFactory } from "expirix";

// Create cleanup that runs when browser is idle (default behavior)
const cleanup = cleanupFactory(localStorage, {
  expiresInSeconds: 3600, // 1 hour
});

// Run cleanup (will use requestIdleCallback if available, setTimeout as fallback)
cleanup.runCleanup();

// To run cleanup immediately instead:
const immediateCleanup = cleanupFactory(localStorage, {
  expiresInSeconds: 3600,
  runWhenBrowserIsIdle: false,
});

Wrapping Behavior Control

By default, cleanup operations only remove expired items but do not modify existing unwrapped values. You can control whether cleanup should wrap existing unwrapped items with the wrapUnwrappedItems option.

// Only clean up expired items, leave unwrapped items as-is (default)
const cleanupOnly = cleanupFactory(localStorage, {
  expiresInSeconds: 3600,
});

// Clean up expired items AND wrap unwrapped items
const cleanupAndWrap = cleanupFactory(localStorage, {
  expiresInSeconds: 3600,
  wrapUnwrappedItems: true,
});

This gives you fine-grained control over when existing data gets wrapped with expiration metadata.

Browser Idle Cleanup

By default, the library runs cleanup operations when the browser is idle, using the requestIdleCallback API when available, with a simple polyfill fallback for older browsers.

// Cleanup will run when browser is idle (default behavior)
const idleCleanup = cleanupFactory(localStorage, {
  expiresInSeconds: 3600,
});

idleCleanup.runCleanup(); // Schedules cleanup for when browser is idle

// To run cleanup immediately instead:
const immediateCleanup = cleanupFactory(localStorage, {
  expiresInSeconds: 3600,
  runWhenBrowserIsIdle: false,
});

requestIdleCallback Polyfill:

  • Uses native requestIdleCallback when available
  • Falls back to setTimeout with 1ms delay in older browsers

Features

  • Drop-in replacement for localStorage/sessionStorage
  • Automatic expiration - expired items are automatically removed
  • Backward compatible - handles existing non-wrapped values
  • TypeScript support with full type definitions
  • Zero dependencies

License

ISC