2.0.1 • Published 2 months ago

time-loom v2.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
2 months ago

Time Loom

npm version License

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

License

This project is licensed under the MIT License - see the LICENSE file for details.

2.0.1

2 months ago

2.0.0

2 months ago

1.2.1

4 months ago

1.2.0

5 months ago

1.1.1

5 months ago

1.1.0

5 months ago

1.0.3

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago