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

throttle-interval

v1.0.0

Published

Ensures that a function won't be called more times than specified within a time interval. Supports Promise and AbortSignal.

Readme

Throttle by Interval

Ensures that a function won't be called more times than specified within a time interval. Supports Promise and AbortSignal.

  • ECMAScript only. Works in any environment.
  • Tiny - 500 B minified, 260 B brotlied.
  • ESM, CJS and UMD bundles provided.
  • No dependencies.

Synopsis

Load three files from a service, which allows only one connection per second:

import throttle from 'throttle-interval'

const load = id => fetch(`http://data.com/${id}`).then(r => r.text())

const schedule = throttle(1000)

const [first, second, third] = await Promise.all([
  schedule(() => load(1)),
  schedule(() => load(2)),
  schedule(() => load(3))
])

Installation

This module can be installed locally by NPM or other package manager. If you use Node.js, make sure, that you use version 23 or newer:

npm i throttle-interval

When used in the browser, you can load the script from the CDN, ESM, UMD or global:

<script>
  import throttle from 'https://unpkg.com/[email protected]/lib/index.js'
</script>
<script src="https://unpkg.com/[email protected]/require.js"></script>
<script>
  require(
    ['https://unpkg.com/[email protected]/lib/index.umd.min.js'],
    function (throttle) {
    }
  )
</script>
<script src="https://unpkg.com/[email protected]/lib/index.umd.min.js"></script>
<script>
  const throttle = window.throttleInterval
</script>

Details

The worker function can be synchronous or asynchronous.

The worker function won't be executed synchronously right away, when scheduled. Its execution will be performed in the next event loop cycle by a zero setTimeout. It's safe to add callbacks to the promise returned from the scheduler function before the worker function gets executed.

If execution of a worker function takes longer than the throttling interval, the next worker function will be executed right after the previous one has finished. The throttling interval is a minimum time interval between two function executions.

If signal is passed to the scheduler function, it'll be passed to the worker function too. If the worker function performs multiple asynchronous calls, it should check the state of the signal and abort early, if it gets aborted.

API

/**
 * A worker function.
 *
 * @param options Optional settings for the worker, including an AbortSignal
 *                to cancel the execution of the worker function.
 * @returns The result of the worker function, or a promise that resolves to it.
 */
export type Worker<T = any> = (options?: { signal?: AbortSignal }) => T | Promise<T>

/**
 * Schedules a worker function.
 *
 * @param worker The function to be executed in a controlled manner.
 * @param options Optional settings for the scheduler, including an AbortSignal to cancel the execution.
 * @returns A promise that will be settled with the result of the worker function
 *          when the worker function has been executed.
 */
export type Scheduler<T = any> = (worker: Worker<T>, options?: { signal?: AbortSignal }) => Promise<T>

/**
 * Creates a scheduler function.
 *
 * @param interval The minimum time interval (in milliseconds) between the calls
 *                 of the throttled worker functions.
 * @returns A scheduler function that will call worker functions no more frequently
 *          than the specified interval.
 */
export default function throttle<T = any>(interval: number): Scheduler<T>

Examples

Passing an AbortSignal to the scheduler function will abort the worker function as early as possible without even executing it, if it hasn't been executed yet.

The worker function may access the AbortSignal, in the object passed to it as the first argument.

import throttle from 'throttle-interval'

const load = (id, signal) => fetch(`http://data.com/${id}`, { signal }).then(r => r.text())

const schedule = throttle(1000)

const controller = new AbortController()
const { signal } = controller

const [first, second, third] = await Promise.all([
  schedule(({ signal }) => load(1, signal), { signal }),
  schedule(({ signal }) => load(2, signal), { signal }),
  schedule(({ signal }) => load(3, signal), { signal })
])

controller.abort()
import throttle from 'throttle-interval'

const load = (id, signal) => fetch(`http://data.com/${id}`, { signal }).then(r => r.text())

const schedule = throttle(1000)

const controller = new AbortController()
const { signal } = controller

const [first, second, third] = await Promise.all([
  schedule(({ signal }) => load(1, signal), { signal }),
  schedule(({ signal }) => load(2, signal), { signal }),
  schedule(({ signal }) => load(3, signal), { signal })
])

controller.abort()

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Lint and test your code.

License

Copyright (c) 2026 Ferdinand Prantl

Licensed under the MIT license.