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

ttc-rate-limit

v0.1.13

Published

A rate limiting library with worker pool support for parallel timeout management

Readme

ttc_rate_limit

A rate limiting library with worker pool support for parallel timeout management.

Features

  • Core Rate Limiting: Token bucket and sliding window algorithms via RateLimiter
  • Cluster Management: Coordinate multiple rate limiters with Cluster for load balancing and failover

Installation

npm install ttc_rate_limit

Usage

Single Rate Limiter

import { RateLimiter } from 'ttc_rate_limit';

// Create a rate limiter for API calls
const apiLimiter = new RateLimiter({
  id: 'api-limiter',
  request: 100,          // 100 requests
  per: 'minute',         // per minute
  mode: 'spread',        // spread evenly over time
  cb: async (params) => {
    // Your API call here
    return await fetch('https://api.example.com', params);
  },
});

// Make a request (automatically rate-limited)
const result = await apiLimiter.invoke({ url: '/api/data' });

Rate Limiting Modes

  • spread: Distributes requests evenly over the time period. For 100 requests per minute, sends ~1.67 requests per second.
  • burst: Allows requests up to the limit instantly, then waits for the full time window to reset. For 100/minute, sends 100 requests at once, then waits 60 seconds.
  • hybrid: Combines burst and spread. Uses hybridRatio to divide the limit into smaller bursts. For 100/minute with hybridRatio: 10, sends 10 requests every 6 seconds.
// Burst mode example
const burstLimiter = new RateLimiter({
  id: 'burst-limiter',
  request: 100,
  per: 'minute',
  mode: 'burst',
  cb: async (input) => apiCall(input),
});

// Hybrid mode example
const hybridLimiter = new RateLimiter({
  id: 'hybrid-limiter',
  request: 100,
  per: 'minute',
  mode: 'hybrid',
  hybridRatio: 10,  // 10 bursts per 6 seconds
  cb: async (input) => apiCall(input),
});

Cluster Management

Use Cluster to manage multiple rate limiters and distribute tasks among them using load balancing strategies.

import { Cluster } from 'ttc_rate_limit';

type Task = { modelId: string; chatId: string; };

const cluster = new Cluster<Task, string>('roundrobin');

// Add multiple rate limiters
cluster.addOption({
  id: 'api-1',
  request: 100,
  per: 'minute',
  mode: 'hybrid',
  hybridRatio: 10,
  cb: async (task) => {
    // Process task with API 1
    return `Processed by API 1: ${task.modelId} - ${task.chatId}`;
  },
});

cluster.addOption({
  id: 'api-2',
  request: 50,
  per: 'minute',
  mode: 'spread',
  cb: async (task) => {
    // Process task with API 2
    return `Processed by API 2: ${task.modelId} - ${task.chatId}`;
  },
});

// Listen for events
cluster.on('completed', (data) => {
  console.log('Task completed:', data.response);
});

cluster.on('error', (data) => {
  console.error('Task error:', data.response);
});

// Invoke tasks (will be distributed among limiters)
for (let i = 0; i < 10; i++) {
  cluster.invoke({ modelId: 'gpt-4', chatId: `chat-${i}` });
}

Cluster Strategies

  • random: Randomly select a limiter for each task.
  • roundrobin: Cycle through limiters sequentially.

License

License

MIT