# fast-throttler

> This module provides a very fast and elegant way of throttling the invocation of any function

Latest version **1.0.2** (published 2017-11-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install fast-throttler
pnpm add fast-throttler
yarn add fast-throttler
bun add fast-throttler
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2017-11-07 |
| First published | 2016-08-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Harry Kalogirou |
| Maintainers | harkal |
| Keywords | throttling, throttle, rate, limiter |

## Links

- npm: https://www.npmjs.com/package/fast-throttler
- Repository: https://github.com/harkal/fast-throttler
- Homepage: https://github.com/harkal/fast-throttler#readme
- Issues: https://github.com/harkal/fast-throttler/issues
- npm.io page: https://npm.io/package/fast-throttler

## Dependencies (2)

- [bluebird](https://npm.io/package/bluebird.md) ^3.4.1
- [lru-cache](https://npm.io/package/lru-cache.md) ^4.0.1

## Recent versions

- 1.0.2 (latest) — 2017-11-07
- 1.0.1 — 2016-08-25
- 1.0.0 — 2016-08-25

## README

![alt text](https://github.com/Besssy/fast-throttler/blob/master/images/logo.png)

[![NPM Version](https://img.shields.io/npm/v/fast-throttler.svg)](https://www.npmjs.com/package/fast-throttler)

## Description
Throttle the amount of times your function runs by adding a limit.

## Installation

` npm install fast-throller --save `

## Simple Usage
```javascript 
const Throttler = require('fast-throttler'); 
var throttler = new Throttler({rate: 2}); //will throttle 2 requests per second 
```

For example, you can throttle a GET request per _product id_ in Express.js like this 

```javascript 
router.get('/product/:id', function(req, res){
  throttler(req.params.id)
    .then(function(){
       //...
       res.render('template', productData);
    })
    .catch(function(error){
       //...
       res.status(429); //Too many requests
    });
});
```

## Options

|Parameter|Type|Default Value|
|:---------:|:----:|:-------------:|
|Rate|Number|1024|
|Period|Number|1|
|Cost|Function|()=>1|
|Key|Function|(key)=>key|

## Events

|Name|Description|
|---------:|:----|
|onAllowed|Executes when throttler is operating within limits|
|onThrottled|Executes when throttler rate is overreached |

---
_Source: https://npm.io/package/fast-throttler · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
