@marcopollacci/debouncing
v1.0.7
Published
Simple debounce utility function
Downloads
19
Maintainers
Readme
@marcopollacci/debouncing
A simple debounce utility function with cancel, cancelAndExecute, and pending support.
Installation
npm install @marcopollacci/debouncingUsage
import { debouncing } from "@marcopollacci/debouncing";
// Basic usage
const log = debouncing(() => console.log("Hello"));
log(); // waits 500ms before printing 'Hello' to the console
// Custom wait time
const log2 = debouncing(() => console.log("Hello after 1s"), 1000);
log2(); // waits 1000ms before printingExtra features
- Support for cancel, cancelAndExecute, and pending methods
const log = debouncing(() => console.log("Hello"), 1000);
log(); // schedules execution in 1s
// Cancel the pending execution
log.cancel();
// Check if execution is pending
console.log(log.pending()); // false (because we canceled)const log = debouncing(() => console.log("Hello"), 1000);
log(); // schedules execution in 1s
// Cancel the pending execution and execute immediately
console.log(log.cancelAndExecute()); // HelloRunning tests
This project uses Bun as the test runner.
npx bun test index.test.jsLicense
MIT
