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

flood-barrier

v0.1.0

Published

Limit how often your event handler can be called within a certain duration. Basically a debounce that allows multiple invocations before it triggers.

Downloads

41

Readme

flood-barrier

Limit how often your event handler can be called within a certain duration. Basically a debounce that allows multiple invocations before it triggers.

API

This module exports one function:

floodBarrier(config, func)

Return a "guard function" that proxies your function func when called at an acceptable rate (tracked as "heat"), and does something else when called excessively. The config argument is passed to floodBarrier.makeAdvisor and is described there below.

The config argument can be any of the following:

  • A config object as described below.
  • A false-y value, which means to use all defaults.
  • A positive finite number, which will be used as both the maxRepeats and cooldownSec option.

When giving a config object, these keys are understood:

  • maxRepeats: Intervene after this amount of repeated invocations. (The first invocation is not a repeat.) Default: 1
  • initialHeat: The number of invocations already accumulated. Default: 0
  • cooldownSec: The duration (in seconds) that must pass without an invocation in order to reset the heat, i.e. accept normal invocations again. Default: maxRepeats
  • memoValue: The initial value for the "memo" behavior (see onHot). Default: undefined
  • onHot: What to do when the guard function is called excessively.
    • 'noop', 'ignore', 'false', false or any false-y value (default): Just return false.
    • 'memo': Return the last known result of an acceptable invocation.
    • 'err': Throw a generic error.
    • an object with a .message property: Throw a custom error with that message and all other own properties of that object.
    • a function: Call this function instead of func. The context (this) of the invocation will be the guard function.

The guard function will hold these properties:

  • advisor: A function that just decides (returns a boolean) whether the invocation is acceptable. Increases heat if it is.

floodBarrier.makeAdvisor(config)

Return an advisor function as described above. Exposed for cases where you want to handle the guard decision in your own code.

Usage

:TODO: see test/usage.mjs.

See also

Known issues

  • Needs more/better tests and docs.

 

License

ISC