LIMIT-IO - This is a simple query limiter based on memory storage
Features
- Two operating modes
- Support ESM
- Simple
Installation
Node.js 18.0.0 or newer is required
-
Using
npm
(recommended)npm i limit-io
-
Using
Yarn
yarn add limit-io
-
Using
pnpm
pnpm add limit-io
API Reference
TimeoutLimiter
import { TimeoutLimiter } from 'limit-io';
Constructor
Initializing a new instance
const limiter = new TimeoutLimiter(recoveryInterval, amount)
Parameter | Type | Description |
---|---|---|
recoveryInterval | string | API ms |
amount | number | Number of available requests |
limit
Returns the limit on the number of calls
limiter.limit; // => number
amount
Returns the number of available calls
limiter.amount; // => number
recoveryTime
Returns the time to restore
limiter.recoveryTime; // => number
recoveryInterval
Returns the interval for the reset of requests
limiter.recoveryInterval; // => number
accept
Checks if there are enough calls to call
limiter.accept(amount); // => boolean
Parameter | Type | Description |
---|---|---|
amount | number | Number of requests requested |
reset
Clears the number of available calls
limiter.reset();
FireLimiter
The difference from Limiter is that it will be called as soon as there is enough for the specified number of calls