Gathering detailed insights and metrics for p-debounce-throttle
Gathering detailed insights and metrics for p-debounce-throttle
Implement debounce and throttle function with TypeScript.
npm install p-debounce-throttle
Typescript
Module System
Node Version
NPM Version
68.3
Supply Chain
85.2
Quality
75.4
Maintenance
100
Vulnerability
100
License
TypeScript (96.99%)
JavaScript (3.01%)
Total Downloads
443
Last Day
1
Last Week
3
Last Month
15
Last Year
120
1 Stars
17 Commits
2 Watching
1 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
0.2.1
Package Id
p-debounce-throttle@0.2.1
Unpacked Size
10.87 kB
Size
4.14 kB
File Count
10
NPM Version
9.5.0
Node Version
18.14.2
Publised On
20 Apr 2023
Cumulative downloads
Total Downloads
Last day
-50%
1
Compared to previous day
Last week
-72.7%
3
Compared to previous week
Last month
200%
15
Compared to previous month
Last year
-62.8%
120
Compared to previous year
Debounce creates a new function g
, which when called will delay the invocation of the original function f
until n
milliseconds, BUT drop previous pending delayed emissions if a new invocation is made before n
milliseconds.
It's very useful for scenarios when it's better to limit the number of times the function is called. E.g. think of search input which fetches data from API. It's enough display search results after user has stopped entering characters for some time.
npm i p-debounce-throttle -S
1import { debounce } from "ts-debounce"; 2 3const debouncedFunction = debounce(originalFunction, waitMilliseconds, options);
originalFunction
waitMilliseconds
options
isImmediate
(boolean)
true
then originalFunction
will be called immediately, but on subsequent calls of the debounced function original function won't be called, unless waitMilliseconds
passed after last callmaxWait
(number)
originalFunction
after maxWait
time has passed, even if the debounced function is called in the meantime
wait
is set to 100
and maxWait
to 200
, then if the debounced function is called every 50ms, then the original function will be called after 200ms anywaycallback
(function)
originalFunction
is debounced and receives as first parameter returned data from originalFunction
The returned debounced function can be cancelled by calling cancel()
on it.
1const debouncedFunction = debounce(originalFunction, waitMilliseconds, options); 2 3debouncedFunction.cancel();
ts-debounce-throttle
has Promise support. Everytime you call debounced function a promise is returned which will be resolved when the original function will be finally called. This promise will be rejected, if the debounced function will be cancelled.
You can also debounce a function f
which returns a promise. The returned promise(s) will resolve (unless cancelled) with the return value of the original function.
1const asyncFunction = async () => "value"; 2const g = debounce(asyncFunction); 3const returnValue = await g(); 4returnValue === "value"; // true
This implementation is based upon following sources:
No vulnerabilities found.
No security vulnerabilities found.