yf-limiter
version: 2.0.1
A limiter that prevent overflow from action / event / request ..
Installation
Node:
$ npm install yf-limiter
Example
Import
const YF = ;
Debounce
let count = 1 debounced = YF ; // '', '', '', '', called ...
Throttle
let throttled = YF ; // called, '', called, '', called, '', called, '', called ...
or ( pass, fail ):
let throttled = YF ; // called, '', called, '', called, '', called, '', called ...
Limiter
5 times function called will be allowed in every 10 second, the other would be rejected
let limited = YF ; // called, called, called, called, called, '', '', '', '', '', called, called ...
or ( pass, fail ):
let limited = YF ; // called, called, called, called, called, '', '', '', '', '', called, called ...
or ( split the timeline, pass last argument as true to create a split limiter, and name for each function called ):
let limited = YF ; // [1] 1, 1, 1, 1, 1, '', '', '' ...// [2] '', 2, 2, '', 2, 2, '', 2, '' ...// [3] '', 3, 3, 3, 3, 3, '', '' ...
API
YF.debounce(fn, timeout)
* Debounce a function called.
* @param {function} fn // function
* @param {int} timeout // time in million second
*
* @return {function} // the debounced function
YF.throttle(fn, timeout)
YF.throttle(timeout)
* Throttle a function called.
* @param {function} fn // function
* @param {int} timeout // time in million second
*
* @return {function} // the throttled function
YF.limiter(fn, limit, cycle)
YF.limiter(fn, limit, cycle, split)
* Limit a function called times in a time period.
* @param {function} fn // function
* @param {int} limit // number of allowed times
* @param {int} cycle // time in second
* @param {string} split // split the timeline by name
*
* @param {string} name // timeline name
*
* @return {function} // the limited function
License
MIT