limit-io
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

NPM version Build Status NPM downloads

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

Package Sidebar

Install

npm i limit-io

Weekly Downloads

5

Version

3.0.0

License

MIT

Unpacked Size

16.7 kB

Total Files

10

Last publish

Collaborators

  • negezor