@ludeschersoftware/ratelimit
v1.0.0
Published
Rate limit function calls!
Readme
Rate limit function calls! Smooth out execution frequency and manage function calls over defined intervals.
✨ Features
- Rate limit function calls
- Queue-based management for delayed executions
- Fully typed with TypeScript
📦 Installation
npm install @ludeschersoftware/ratelimit
or with yarn:
yarn add @ludeschersoftware/ratelimit
🔹 Usage
1. RateLimit — rate limit your function calls
import RateLimit from "@ludeschersoftware/ratelimit";
// Create a rate limiter with a 100ms interval
const limiter = new RateLimit(100);
function sendRequest(data: string) {
console.log("Executing call with:", data);
}
// Add calls to the queue
limiter.add(sendRequest, "task-1");
limiter.add(sendRequest, "task-2");
➡️ Function calls are automatically scheduled and spaced out according to the specified interval.
📖 API
class RateLimit
Manages the execution queue and interval spacing.
constructor(intervalMs: number)add(fn: Function, ...args: any[]): void
🧪 Tests
The project uses Jest.
npm test
npm run test:coverage
📦 Module Support
This package ships with both:
CommonJS (
require)ES Modules (
import)
So it works in:
Node.js projects
Modern bundlers (Vite/Webpack/Rollup)
TypeScript projects
📜 License
MIT © Johannes Ludescher
