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 🙏

© 2025 – Pkg Stats / Ryan Hefner

superload

v1.1.0

Published

Simplest possible batch loader (inspired by graphql/dataloader)

Readme

superload

Simplest possible batch loader.

  • Batches resource requests into a single call
  • No cache

Superload - A Simple Batched Resource Loader

The module exports the Superload class, which provides a simple way to batch asynchronous resource requests. It collects individual resource requests made within a short time frame (configurable) and consolidates them into a single batched call.

API Reference

Config<K, T>

This interface defines the configuration for a Superload instance (passed to the constructor):

  • delay? (number): An optional delay in milliseconds before processing queued requests. Defaults to 0.
  • id (key: K) => string: A function that returns a unique identifier for a given key. Used to deduplicate requests.
  • loader (keys: K[]) => Promise<(T | Error)[]>: A function that accepts an array of keys and returns a promise which resolves to an array of corresponding resources. This function is invoked when the batch is processed. The order of returned values must match the order of keys. Errors can be returned individually to signal issues on specific resources.

Superload<K, T>

The main class responsible for the batching logic:

  • constructor(config: Config<K, T>)

  • load(key: K): Promise<T>

    • Queues a single key for loading. If the same key is requested multiple times during a batching cycle, the returned promise is deduplicated and the key is only passed once to the loader.
  • loadMany(keys: K[]): Promise<T[]>

    • Accepts an array of keys, queues them for loading, and returns a promise that resolves when all keys have been processed. The order of returned values matches the order of keys.

Example Usage

import { Superload } from "superload";

async function fetchUsers(ids: string[]) {
  console.log("Fetching users for:", ids);
  // Replace the following with your actual data retrieval logic, e.g., database or API call
  return ids.map(id => ({ id, name: `User ${id}` }));
}

// Instantiate the Superload for user data
const userLoader = new Superload({
  delay: 0, // Optional batching delay in ms (default: 0)
  id: key => key, // Here, we use the key itself as the unique identifier
  loader: fetchUsers // Function to fetch users in batch
});

// Loading a single user
const user = await userLoader.load("user-1");
console.log("Loaded user:", user);

// Loading multiple users
const [user1, user2, user3] = await userLoader.loadMany([
  "user-1",
  "user-2",
  "user-3"
]);
console.log("Loaded users:", [user1, user2, user3]);

Error handling

  • If the batched call promise is rejected as a whole, every load and loadMany promise that depends on it is rejected with the same reason.
  • If the batched call resolves to an array containing some Error instances, the load and loadMany promises associated with these errors are rejected with the provided error.