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

@hm-soft/rate-limit

v0.1.0

Published

요청 속도 제한 — 슬라이딩 윈도우 / 토큰 버킷, 저장소 비의존 순수 로직 (의존성 0)

Readme

@hm-soft/rate-limit

요청 속도 제한 — 슬라이딩 윈도우 / 토큰 버킷. 저장소 비의존 순수 로직(상태는 직렬화 가능). 의존성 0, 시간 주입으로 테스트 친화. @hm-soft/account-lock과 보안 라인업.

설치

npm install @hm-soft/rate-limit

사용

import { slidingWindow, initialSlidingState, tokenBucket, initialBucketState } from "@hm-soft/rate-limit";

// 슬라이딩 윈도우 — IP당 1분에 60회
let state = (await store.get(ip)) ?? initialSlidingState();
const r = slidingWindow(state, { limit: 60, windowMs: 60_000 });
await store.set(ip, r.state);
if (!r.allowed) return res.status(429).header("Retry-After", Math.ceil(r.retryAfterMs / 1000));

// 토큰 버킷 — 버스트 10, 초당 2개 리필
const b = tokenBucket(bucketState, { capacity: 10, refillTokens: 2, refillIntervalMs: 1000 });
if (!b.allowed) throw new Error(`${b.retryAfterMs}ms 후 재시도`);

API

| 함수 | 설명 | |------|------| | initialSlidingState() | 빈 슬라이딩 상태 | | slidingWindow(state, {limit, windowMs}, now?) | → { state, allowed, remaining, retryAfterMs, resetAt } | | initialBucketState() | 빈 버킷 상태(첫 호출 시 가득) | | tokenBucket(state, {capacity, refillTokens, refillIntervalMs}, now?) | → { state, allowed, remaining, retryAfterMs } |

언제 무엇을

  • 슬라이딩 윈도우: "1분에 N회"처럼 정확한 횟수 제한. 정밀하지만 타임스탬프 보관.
  • 토큰 버킷: 버스트 허용 + 평균 속도 제한. 상태가 작고(토큰 수 + 시각) 가벼움.

상태는 키(IP·사용자ID)별로 직접 저장하세요. now 주입으로 결정적 테스트 가능.

License

Apache-2.0