throttle-debounce-ts ·
Throttle and debounce functions written in Typescript.
Features:
- No thirdparty dependecies
- Easy to use
- ES Modules and CommonJS format
Install
npm i throttle-debounce-ts
Usage
Throttle
; const throttleFunc = ;
Debounce
; const debounceFunc = ;
Cancel
const throttleFunc = ;// will cancel throttleFuncthrottleFunc; const debounceFunc = ;// will cancel delay of debounceFunc// callback will exec immediately when you call debounceFunc next timedebounceFunc;
API
throttle(options, callback)
Returns: Function
Throttle execution of a function.
options
Type: Number
A zero-or-greater delay in milliseconds.
Type: Object
options.delay
A zero-or-greater delay in milliseconds.
options.leading
Optional, defaults to false. If it's true, the function will exec on the first call.
options.trailing
Optional, defaults to false. If it's true, the function will exec after last call.
callback
Type: Function
A function to be executed after delay milliseconds.
debounce(options, callback)
Returns: Function
Debounce execution of a function.
options
Type: Number
A zero-or-greater delay in milliseconds.
Type: Object
options.delay
A zero-or-greater delay in milliseconds.
options.leading
Optional, defaults to false. If it's true, the function will exec on the first call.
callback
Type: Function
A function to be executed after delay milliseconds.