limit-io

Simple queries limiter

Usage no npm install needed!

<script type="module">
  import limitIo from 'https://cdn.skypack.dev/limit-io';
</script>

README

NPM version Build Status NPM downloads Code quality

LIMIT-IO - This is a simple query limiter based on memory storage

Features

  • Two operating modes
  • Support ESM
  • Simple

Installation

Node.js 8.0.0 or newer is required

Yarn

Recommended, auto assembly

$ yarn add limit-io

NPM

$ npm i limit-io

API Reference

Limiter

import { Limiter } from 'limit-io';

Constructor

Initializing a new instance

const limiter = new Limiter(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();

TimeoutLimiter

Alias for Limiter

FireLimiter

The difference from Limiter is that it will be called as soon as there is enough for the specified number of calls