2.0.1 • Published 2 months ago
time-loom v2.0.1
Time Loom
A utility for creating delayed functions using debouncing and throttling.
Installation
npm install time-loom
Usage
import { debounce, throttle } from "time-loom";
// Example usage of debounce
const debouncedFunction = debounce(() => {
// Your function logic here
}, 500);
// Example usage of throttle
const throttledFunction = throttle(() => {
// Your function logic here
}, 1000);
API
debounce(fn, delay)
Creates a debounced function.
fn
: The function to debounce.delay
: The delay in milliseconds.options
: (Optional) Additional options for customization (e.g., { leading: true, trailing: false, maxWait: 1000 }).
Debounce Function Options:
leading (boolean)
: Whether to execute the function on the leading edge of the timeout (default: false).trailing (boolean)
: Whether to execute the function on the trailing edge of the timeout (default: true).maxWait (number)
: The maximum time to wait before triggering the function (default: undefined).
Debounce Function Methods:
cancel
: Cancels the scheduled execution of the debounced function.flush
: Executes the debounced function immediately.
throttle(fn, delay)
Creates a throttled function.
fn
: The function to throttle.delay
: The minimum time between invocations in milliseconds.options
: (Optional) Additional options for customization (e.g., { leading: false, trailing: true }).
Throttle Function Options:
leading (boolean)
: Whether to execute the function on the leading edge of the timeout (default: true).trailing (boolean)
: Whether to execute the function on the trailing edge of the timeout (default: true).
Throttle Function Methods:
cancel
: Cancels the scheduled execution of the throttled function.
Examples
- You can find more examples in the examples directory.
Author
- Muhammed Nabeel
License
This project is licensed under the MIT License - see the LICENSE file for details.