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

@rcompat/kv

v0.6.0

Published

Standard library key-value abstractions

Readme

@rcompat/kv

Key-value storage utilities for JavaScript runtimes.

What is @rcompat/kv?

A cross-runtime module providing key-value storage abstractions. Currently includes a singleton cache with symbol-based keys and lazy initialization. Works consistently across Node, Deno, and Bun.

Installation

npm install @rcompat/kv
pnpm add @rcompat/kv
yarn add @rcompat/kv
bun add @rcompat/kv

Usage

cache

A singleton key-value cache using symbols as keys. Supports lazy initialization.

import cache from "@rcompat/kv/cache";

// Define a symbol key
const CONFIG = Symbol("config");

// Get with initializer (runs only on first access)
const config = cache.get(CONFIG, () => ({
  apiUrl: "https://api.example.com",
  timeout: 5000,
}));

// Subsequent gets return the cached value
cache.get(CONFIG);  // Same object, initializer not called again

Lazy initialization

The initializer function is only called if the key doesn't exist yet.

import cache from "@rcompat/kv/cache";

const DB_CONNECTION = Symbol("db");

// Connection is established only on first access
function getDb() {
  return cache.get(DB_CONNECTION, () => {
    console.log("Connecting to database...");
    return createConnection();
  });
}

getDb();  // "Connecting to database..." - initializer runs
getDb();  // Returns cached connection, no log
getDb();  // Returns cached connection, no log

Symbol uniqueness

Each symbol is unique, even with the same description.

import cache from "@rcompat/kv/cache";

const KEY_A = Symbol("data");
const KEY_B = Symbol("data");

cache.get(KEY_A, () => "value A");
cache.get(KEY_B, () => "value B");

cache.get(KEY_A);  // "value A"
cache.get(KEY_B);  // "value B"
cache.get(Symbol("data"));  // undefined (different symbol)

API Reference

cache.get(key, init?)

declare function get<T>(key: symbol, init?: () => T): T | undefined;

Gets a value from the cache by symbol key, optionally initializing it.

| Parameter | Type | Description | |-----------|-------------|------------------------------------------| | key | symbol | The symbol key to look up | | init | () => T | Optional initializer called if key missing |

Returns: The cached value, or undefined if not found and no initializer provided.

Behavior:

  • If the key exists, returns the cached value
  • If the key doesn't exist and init is provided, calls init(), caches and returns the result
  • If the key doesn't exist and no init, returns undefined

Examples

Application-wide singletons

import cache from "@rcompat/kv/cache";

// Define keys for your singletons
const LOGGER = Symbol("logger");
const CONFIG = Symbol("config");
const HTTP_CLIENT = Symbol("http");

// Logger singleton
export function getLogger() {
  return cache.get(LOGGER, () => createLogger({
    level: "info",
    format: "json",
  }));
}

// Config singleton (loaded once)
export function getConfig() {
  return cache.get(CONFIG, () => loadConfigFromEnv());
}

// HTTP client singleton
export function getHttpClient() {
  return cache.get(HTTP_CLIENT, () => createHttpClient({
    timeout: 30000,
    retries: 3,
  }));
}

Module-level caching

// user-service.js
import cache from "@rcompat/kv/cache";

const USERS_CACHE = Symbol("users");

export function getUsers() {
  return cache.get(USERS_CACHE, async () => {
    const response = await fetch("/api/users");
    return response.json();
  });
}

Expensive computation caching

import cache from "@rcompat/kv/cache";

const COMPUTED_DATA = Symbol("computed");

function getComputedData() {
  return cache.get(COMPUTED_DATA, () => {
    console.log("Computing expensive data...");
    // This only runs once
    return heavyComputation();
  });
}

Cross-Runtime Compatibility

| Runtime | Supported | |---------|-----------| | Node.js | ✓ | | Deno | ✓ | | Bun | ✓ |

No configuration required — just import and use.

License

MIT

Contributing

See CONTRIBUTING.md in the repository root.