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

@yogeshyc/retryable

v0.1.0

Published

Async retry with exponential backoff, jitter, and AbortSignal support. Zero dependencies.

Readme

@yogeshyc/retryable

Async retry with exponential backoff, jitter, and AbortSignal support. Zero dependencies.

  • Exponential backoff with configurable factor and max delay
  • Full jitter for distributed systems (avoids thundering herd)
  • AbortSignal support — cancel retries from outside
  • onRetry hook with async support
  • retryIf — conditionally retry based on the error
  • Attempt context passed to your function
  • Dual CJS/ESM with full TypeScript types
  • Zero runtime dependencies

Install

npm install @yogeshyc/retryable

Quick Start

import { retry } from "@yogeshyc/retryable";

const data = await retry(() => fetch("/api/data").then((r) => r.json()), {
  retries: 5,
  delay: 500,
});

API

retry<T>(fn, options?): Promise<T>

Retries fn until it succeeds or all attempts are exhausted.

fn(context: AttemptContext) => Promise<T>

The async function to retry. Receives context:

interface AttemptContext {
  attempt: number;    // current attempt (starts at 1)
  remaining: number;  // retries remaining
  signal?: AbortSignal;
}

Options

interface RetryOptions {
  retries?: number;      // max retries (default: 3)
  delay?: number;        // initial delay in ms (default: 1000)
  factor?: number;       // backoff multiplier (default: 2)
  maxDelay?: number;     // max delay cap in ms (default: 30000)
  jitter?: boolean;      // randomize delay (default: true)
  signal?: AbortSignal;  // cancel retries
  onRetry?: (error: Error, attempt: number, delay: number) => void | boolean | Promise<void | boolean>;
  retryIf?: (error: Error) => boolean;
}

Examples

Exponential Backoff

await retry(() => callApi(), {
  retries: 5,
  delay: 200,    // 200ms, 400ms, 800ms, 1600ms, 3200ms
  factor: 2,
  jitter: false,
});

With AbortSignal

const controller = new AbortController();

// Cancel after 10 seconds
setTimeout(() => controller.abort(), 10_000);

const data = await retry(
  ({ signal }) => fetch("/api", { signal }).then((r) => r.json()),
  { signal: controller.signal },
);

Conditional Retry

await retry(() => callApi(), {
  retryIf: (error) => {
    // Only retry on network/5xx errors, not 4xx
    if (error instanceof TypeError) return true; // network error
    if ("status" in error && (error as any).status >= 500) return true;
    return false;
  },
});

Logging Retries

await retry(() => callApi(), {
  onRetry: (error, attempt, delay) => {
    console.warn(`Attempt ${attempt} failed: ${error.message}. Retrying in ${delay}ms...`);
  },
});

Stop Retrying Early

await retry(() => callApi(), {
  onRetry: (error) => {
    if (error.message.includes("FATAL")) return false; // stop retrying
  },
});

Backoff Formula

delay = min(initialDelay * factor ^ (attempt - 1), maxDelay)

With jitter enabled (default), the actual delay is randomized between 0 and the calculated delay (full jitter strategy).

License

MIT