function-threshold

0.2.0 • Public • Published

function-threshold

NPM version

Limit the amount of times a function can be called in a specific timeframe and throw an error if the limit is exceeded.

Installation

with npm

npm install function-threshold

with yarn

yarn add function-threshold

Example

var FunctionThreshold = require('function-threshold');
 
function myFunction(suffix) {
  console.log('hooray, hello ' + suffix + '!');
}
 
// limit to 5 executions per 10 seconds (10.000 ms)
var threshold = new FunctionThreshold(myFunction, 5, 10000);
 
// call the function somewhere. It will throw an exception if limit is exceeded
threshold.call('world');
 

Dependencies (0)

    Dev Dependencies (12)

    Package Sidebar

    Install

    npm i function-threshold

    Weekly Downloads

    1

    Version

    0.2.0

    License

    MIT

    Last publish

    Collaborators

    • frebo