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

@se-oss/throttle

v1.0.0

Published

A utility for rate-limiting function calls.

Downloads

45

Readme

@se-oss/throttle

CI NPM Version MIT License npm bundle size Install Size

@se-oss/throttle is a utility for rate-limiting function calls. It is designed for modern applications that require fine-grained control over asynchronous operations, offering features like strict mode, weighted throttling, and abort signals.


📦 Installation

npm install @se-oss/throttle

pnpm

pnpm install @se-oss/throttle

yarn

yarn add @se-oss/throttle

📖 Usage

Basic Throttling

Throttle a function to be called at most twice per second.

import { throttle } from '@se-oss/throttle';

const now = Date.now();

const throttled = throttle(
  async (index: number) => {
    const secDiff = ((Date.now() - now) / 1000).toFixed();
    return `${index}: ${secDiff}s`;
  },
  {
    limit: 2,
    interval: 1000,
  }
);

for (let index = 1; index <= 6; index++) {
  (async () => {
    console.log(await throttled(index));
  })();
}
//=> 1: 0s
//=> 2: 0s
//=> 3: 1s
//=> 4: 1s
//=> 5: 2s
//=> 6: 2s

Abort Signal

Abort pending executions using an AbortSignal.

import { throttle } from '@se-oss/throttle';

const controller = new AbortController();

const throttled = throttle(
  () => {
    console.log('Executing...');
  },
  {
    limit: 2,
    interval: 1000,
    signal: controller.signal,
  }
);

await throttled();
await throttled();
controller.abort('aborted');
await throttled();
//=> Executing...
//=> Executing...
//=> Promise rejected with reason `aborted`

onDelay

Get notified when function calls are delayed.

import { throttle } from '@se-oss/throttle';

const throttled = throttle(
  (a, b) => {
    console.log(`Executing with ${a} ${b}...`);
  },
  {
    limit: 2,
    interval: 1000,
    onDelay: (a, b) => {
      console.log(`Call is delayed for ${a} ${b}`);
    },
  }
);

await throttled(1, 2);
await throttled(3, 4);
await throttled(5, 6);
//=> Executing with 1 2...
//=> Executing with 3 4...
//=> Call is delayed for 5 6
//=> Executing with 5 6...

weight

Use the weight option to assign a custom cost to each function call.

import { throttle } from '@se-oss/throttle';

// API allows 100 points per second.
// Each call costs 1 point + 1 point per item.
const throttled = throttle(
  async (itemCount: number) => {
    // Fetch data
  },
  {
    limit: 100,
    interval: 1000,
    weight: (itemCount: number) => 1 + itemCount,
  }
);

await throttled(10); // Costs 11 points
await throttled(50); // Costs 51 points

queueSize

Check the number of queued items.

import { throttle } from '@se-oss/throttle';

const accurateData = throttle(() => fetch('...'), {
  limit: 1,
  interval: 1000,
});
const fallbackData = () => fetch('...');

async function getData() {
  if (accurateData.queueSize >= 5) {
    return fallbackData(); // Use fallback when queue is full
  }

  return accurateData();
}

📚 Documentation

For all configuration options, please see the API docs.

🤝 Contributing

Want to contribute? Awesome! To show your support is to star the project, or to raise issues on GitHub

Thanks again for your support, it is much appreciated! 🙏

License

MIT © Shahrad Elahi and contributors.