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 🙏

© 2025 – Pkg Stats / Ryan Hefner

venkman

v2.0.0

Published

A simple throttling system

Downloads

10

Readme

Venkman

A simple, redis-based throttle-backoff system.

Back off man, I'm a Scientist.

-Peter Venkman, Ghostbusters

Usage:

import { BasicThrottle } from 'venkman';
const testThrottle = new BasicThrottle({
  initialWindow: 20,
  keyGenerator: ({ userId, messageId }) => `example:${userId}:{messageId}`,
  max: 3,
})

testThrottle.backoff('test').then((v) => v === true);
testThrottle.backoff('test').then((v) => v === true);
testThrottle.backoff('test').then((v) => v === true);
testThrottle.backoff('test').then((v) => v === false);

BasicThrottle constructor options:

initialWindow (required): time in seconds from the first request that the throttle counts until expiring. Value is in seconds (not milliseconds) due to redis's ttl granularity.

max (required): the number of requests allowed before rejecting future requests.

keyGenerator (required): should return a string when called with the backoff argument, used to determine which throttle the BasicThrottle is using.

extendWindow: if present, the ttl on the throttle is extended by this value in seconds for every request after the first.

permaBan: if present, this value is set as the ttl on the throttle whenever a request over max is made (so, after you've gone over the limit, you're cut off for 30 minutes)

redis: options passed to the redis client.

redisInstance: if you have created a redis client outside the Throttle and want to use that instead.

BasicThrottle methods:

backoff(arg: T): check to see if the throttle named by the keyGenerator callback is over max. Returns a promise that resolves to either true (at or under max) or false (over max).

close(): cleans up the redis instance. Call this if you didn't pass your own redis instance in and don't want to leak resources.

Important Collision Issue

BasicThrottle uses redis, which is globally-accessible. If you use the same keyGenerator and connect to the same redis db in two throttles, you'll be accessing the same state. This is good if you need global throttles (if you have many instances of an applications server), and bad if you didn't intend that.

Use the options.redis.db value to select the redis db you want to use (and increment it with different BasicThrottle instances if you want no chance of collisions), and / or make sure that your keyGenerator function is a one-to-one mapping rather than many-to-one, or else you'll get throttle collisions.