@avatijs/debounce 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/debouce.d.ts DELETED
@@ -1,72 +0,0 @@
1
- /**
2
- * Advanced debounce utility with TypeScript support
3
- * Provides a way to limit the rate at which a function can fire by delaying its execution
4
- * until after a specified amount of time has elapsed since its last invocation.
5
- * @module debounce
6
- */
7
- /**
8
- * Generic function type that can accept any arguments and return any value
9
- * Used as a constraint for functions that can be debounced
10
- */
11
- type AnyFunction = (...args: any[]) => any;
12
- /**
13
- * Configuration options for the debounce function
14
- * @interface DebounceOptions
15
- */
16
- interface DebounceOptions {
17
- /** Number of milliseconds to delay execution (default: 0) */
18
- readonly wait?: number;
19
- /** Whether to execute on the leading edge of the timeout (default: false) */
20
- readonly leading?: boolean;
21
- /** Whether to execute on the trailing edge of the timeout (default: true) */
22
- readonly trailing?: boolean;
23
- /** Maximum time the function can be delayed before forced execution */
24
- readonly maxWait?: number;
25
- /** Enable debug logging for troubleshooting */
26
- readonly debug?: boolean;
27
- /** AbortController signal for cancellation */
28
- readonly signal?: AbortSignal;
29
- onError?: (error: Error) => void;
30
- }
31
- /**
32
- * Interface for the debounced function, including utility methods
33
- * @interface DebouncedFunction
34
- * @template T - The type of the original function
35
- */
36
- interface DebouncedFunction<T extends AnyFunction> {
37
- /** Cancels any pending function invocations */
38
- readonly cancel: () => void;
39
- /** Immediately executes any pending function call */
40
- readonly flush: (...args: Parameters<T>) => Promise<Awaited<ReturnType<T>>>;
41
- /** Checks if there are any pending invocations */
42
- readonly pending: () => boolean;
43
- /** Cleans up resources used by the debounced function */
44
- readonly cleanup: () => void;
45
- /** The debounced function that wraps the original */
46
- (...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
47
- }
48
- /**
49
- * Creates a debounced version of the provided function that delays invoking func until after
50
- * wait milliseconds have elapsed since the last time the debounced function was invoked.
51
- *
52
- * @template T - The type of the function to debounce
53
- * @param {T} func - The function to debounce
54
- * @param {DebounceOptions} [options={}] - Configuration options
55
- * @returns {DebouncedFunction<T>} The debounced function
56
- * @throws {TypeError} If func is not a function
57
- * @throws {RangeError} If wait or maxWait values are invalid
58
- * @throws {Error} If neither leading nor trailing is true
59
- *
60
- * @example
61
- * const debouncedFn = debounce(async (x: number) => x * 2, { wait: 1000 });
62
- * await debouncedFn(5); // Will execute after 1000ms of inactivity
63
- * const debouncedFn = debounce(
64
- * async (x: number) => x * 2,
65
- * {
66
- * wait: 1000,
67
- * onError: (error) => console.error('Error in debounced function:', error)
68
- * }
69
- * );
70
- */
71
- declare function debounce<T extends AnyFunction>(func: T, options?: DebounceOptions): DebouncedFunction<T>;
72
- export { debounce, type DebouncedFunction, type DebounceOptions };
package/dist/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './debouce';