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

@sanely/ratelimit

v0.1.0

Published

Atomic rate limiting with pluggable stores

Readme

@sanely/ratelimit counts requests in a store that every instance of your application shares, so a limit holds across instances and restarts. Each check runs as one atomic step inside the store, so requests that arrive together can never pass a limit together.

You define limiters once and run them with plain functions. The package has no framework integrations. You write your own middleware for Hono, Express, or another framework in a few lines.

Features

  • Atomic. Each check runs as one indivisible step in the store, such as a Lua script in Redis.
  • Three algorithms. Fixed window, sliding window, and token bucket. A denied request spends nothing, the limiter checks the cost before it spends any units, and a denial reports the exact time the request can succeed.
  • Your Redis client as it is. Pass an ioredis, node-redis, iovalkey, or Bun client directly to its store, with no adapter and no type assertions.
  • Cloudflare Workers. Count in Durable Objects, one object for each key.
  • Safe on failure. When the store fails, the result is never a success, so a spending cap stays a cap.
  • One clock. Windows follow the store's clock, so instances with clocks that drift agree.
  • Composable. Limiters are definitions that plain functions run, so you can build middleware for any platform.
  • Typed. The input type of each limiter comes from how it identifies the caller.
  • No external dependencies. The only runtime dependency is @sanely/duration.

Install

npm install @sanely/ratelimit

The package needs Node.js 22 or later, or Bun 1.4 or later. The Durable Object store runs in Cloudflare Workers.

Get started

Create a limiter factory with a store, define a limiter, and run it:

import { buildLimiter, rateLimit, slidingWindow } from "@sanely/ratelimit"
import { redisStore } from "@sanely/ratelimit/stores/redis"
import Redis from "ioredis"

const redis = new Redis(process.env.REDIS_URL ?? "redis://localhost:6379")

const limiter = buildLimiter({
  store: redisStore(redis),
})

const perIp = limiter({
  name: "api:ip",
  algorithm: slidingWindow({ limit: 30, window: "1h" }),
})

const ip = "203.0.113.7" // The client IP that your platform or trusted proxy gives you.
const result = await rateLimit(perIp, ip)

if (!result.success) {
  // Refuse the request.
}

A window, an interval, or a timeout takes milliseconds or a time expression from @sanely/duration, such as "1h".

Documentation

How-to guides:

Reference:

Explanation:

Contributing

Read the architecture, testing guide, benchmarks, and root contributor guide before changing the package.

License

MIT. See LICENSE.