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

retry-loop

v1.0.2

Published

A lightweight, type-safe retry mechanism for TypeScript/JavaScript functions with customizable retry strategies

Readme

retry-loop

npm version

A lightweight, type-safe retry mechanism for TypeScript/JavaScript functions. retry-loop provides a simple yet powerful way to handle transient failures in asynchronous operations with customizable retry strategies.

Features

  • 🔄 Automatic retry mechanism for failed operations
  • ⚙️ Configurable retry attempts and delay intervals
  • 🎯 Type-safe implementation with TypeScript
  • 🔔 Customizable callbacks for error handling and retry events
  • 🎯 Flexible retry conditions through custom predicates
  • 🚀 Zero dependencies
  • 📦 Works with both Node.js and browser environments

Installation

# Using npm
npm install retry-loop

# Using yarn
yarn add retry-loop

# Using bun
bun add retry-loop

Quick Start

import retryLoop from 'retry-loop';

// Basic usage
const fetchWithRetry = retryLoop(async (url: string) => {
  const response = await fetch(url);
  if (!response.ok) throw new Error('Failed to fetch');
  return response.json();
});

// Advanced usage with options
const fetchWithAdvancedRetry = retryLoop(
  async (url: string) => {
    const response = await fetch(url);
    if (!response.ok) throw new Error('Failed to fetch');
    return response.json();
  },
  {
    retries: 5,
    delay: 1000,
    onError: (error) => console.error('Attempt failed:', error),
    onSuccess: (data) => console.log('Successfully fetched:', data),
    onRetry: (attempt) => console.log(`Retrying... Attempt ${attempt}`),
    shouldRetry: (error) => error instanceof Error && error.message.includes('timeout'),
  }
);

API Reference

retryLoop<T, Params extends any[]>(fn: (...args: Params) => Promise<T>, options?: RetryLoopOptions<T>)

Creates a retry-loop version of the provided async function.

Parameters

  • fn: The async function to make retry loop
  • options: Optional configuration object

Options

interface RetryLoopOptions<T> {
  retries?: number;          // Number of retry attempts (default: 3)
  delay?: number;            // Delay between retries in milliseconds (default: 500)
  onError?: (error: unknown) => void;  // Callback for error events
  onSuccess?: (result: T) => void;     // Callback for successful execution
  onRetry?: (attempt: number) => void; // Callback for retry events
  shouldRetry?: (error: unknown) => boolean; // Predicate to determine if retry should occur
}

Examples

Basic Retry

const getData = retryLoop(async (id: string) => {
  const response = await fetch(`/api/data/${id}`);
  return response.json();
});

Custom Retry Logic

const uploadFile = retryLoop(
  async (file: File) => {
    // Upload logic here
  },
  {
    retries: 5,
    delay: 2000,
    shouldRetry: (error) => {
      return error instanceof Error && 
        (error.message.includes('network') || 
         error.message.includes('timeout'));
    }
  }
);

With Event Handlers

const processData = retryLoop(
  async (data: any) => {
    // Processing logic here
  },
  {
    onError: (error) => console.error('Processing failed:', error),
    onSuccess: (result) => console.log('Processing successful:', result),
    onRetry: (attempt) => console.log(`Retry attempt ${attempt}`)
  }
);

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT