es-toolkit 1.19.0-dev.612 → 1.19.0-dev.613
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/_chunk/{rest-DofO_S.js → rest-CXt9w3.js} +5 -17
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/index.js +1 -1
- package/dist/function/debounce.d.mts +1 -9
- package/dist/function/debounce.d.ts +1 -9
- package/dist/function/debounce.mjs +5 -17
- package/dist/function/index.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/compat/index.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4
4
|
|
|
5
5
|
const zipWith = require('../_chunk/zipWith-CHjHmX.js');
|
|
6
6
|
const promise_index = require('../_chunk/index-BGZDR9.js');
|
|
7
|
-
const rest$1 = require('../_chunk/rest-
|
|
7
|
+
const rest$1 = require('../_chunk/rest-CXt9w3.js');
|
|
8
8
|
const range = require('../_chunk/range-BXlMmn.js');
|
|
9
9
|
const randomInt = require('../_chunk/randomInt-CF7bZK.js');
|
|
10
10
|
const toMerged = require('../_chunk/toMerged-Bzkqyz.js');
|
|
@@ -3,14 +3,6 @@ interface DebounceOptions {
|
|
|
3
3
|
* An optional AbortSignal to cancel the debounced function.
|
|
4
4
|
*/
|
|
5
5
|
signal?: AbortSignal;
|
|
6
|
-
/**
|
|
7
|
-
* An array specifying when the function should be called.
|
|
8
|
-
* - `'leading'`: If included, the function will be called immediately on the first call.
|
|
9
|
-
* - `'trailing'`: If included, the function will be called after `debounceMs` milliseconds have passed since the last call.
|
|
10
|
-
* - If both `'leading'` and `'trailing'` are included, the function will be called at both the start and end of the delay period. However, it must be called at least twice within `debounceMs` milliseconds for this to happen, as one debounced function call cannot trigger the function twice.
|
|
11
|
-
* @default ['trailing']
|
|
12
|
-
*/
|
|
13
|
-
edges?: Array<'leading' | 'trailing'>;
|
|
14
6
|
}
|
|
15
7
|
/**
|
|
16
8
|
* Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds
|
|
@@ -47,7 +39,7 @@ interface DebounceOptions {
|
|
|
47
39
|
* // Will cancel the debounced function call
|
|
48
40
|
* controller.abort();
|
|
49
41
|
*/
|
|
50
|
-
declare function debounce<F extends (...args: any[]) => void>(func: F, debounceMs: number, { signal
|
|
42
|
+
declare function debounce<F extends (...args: any[]) => void>(func: F, debounceMs: number, { signal }?: DebounceOptions): ((...args: Parameters<F>) => void) & {
|
|
51
43
|
cancel: () => void;
|
|
52
44
|
};
|
|
53
45
|
|
|
@@ -3,14 +3,6 @@ interface DebounceOptions {
|
|
|
3
3
|
* An optional AbortSignal to cancel the debounced function.
|
|
4
4
|
*/
|
|
5
5
|
signal?: AbortSignal;
|
|
6
|
-
/**
|
|
7
|
-
* An array specifying when the function should be called.
|
|
8
|
-
* - `'leading'`: If included, the function will be called immediately on the first call.
|
|
9
|
-
* - `'trailing'`: If included, the function will be called after `debounceMs` milliseconds have passed since the last call.
|
|
10
|
-
* - If both `'leading'` and `'trailing'` are included, the function will be called at both the start and end of the delay period. However, it must be called at least twice within `debounceMs` milliseconds for this to happen, as one debounced function call cannot trigger the function twice.
|
|
11
|
-
* @default ['trailing']
|
|
12
|
-
*/
|
|
13
|
-
edges?: Array<'leading' | 'trailing'>;
|
|
14
6
|
}
|
|
15
7
|
/**
|
|
16
8
|
* Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds
|
|
@@ -47,7 +39,7 @@ interface DebounceOptions {
|
|
|
47
39
|
* // Will cancel the debounced function call
|
|
48
40
|
* controller.abort();
|
|
49
41
|
*/
|
|
50
|
-
declare function debounce<F extends (...args: any[]) => void>(func: F, debounceMs: number, { signal
|
|
42
|
+
declare function debounce<F extends (...args: any[]) => void>(func: F, debounceMs: number, { signal }?: DebounceOptions): ((...args: Parameters<F>) => void) & {
|
|
51
43
|
cancel: () => void;
|
|
52
44
|
};
|
|
53
45
|
|
|
@@ -1,27 +1,15 @@
|
|
|
1
|
-
function debounce(func, debounceMs, { signal
|
|
1
|
+
function debounce(func, debounceMs, { signal } = {}) {
|
|
2
2
|
let timeoutId = null;
|
|
3
|
-
let pendingArgs = null;
|
|
4
|
-
const leading = edges.includes('leading');
|
|
5
|
-
const trailing = edges.includes('trailing');
|
|
6
3
|
const debounced = function (...args) {
|
|
7
|
-
if (signal?.aborted) {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
if (leading && timeoutId === null) {
|
|
11
|
-
func.apply(this, args);
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
pendingArgs = args;
|
|
15
|
-
}
|
|
16
4
|
if (timeoutId !== null) {
|
|
17
5
|
clearTimeout(timeoutId);
|
|
18
6
|
}
|
|
7
|
+
if (signal?.aborted) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
19
10
|
timeoutId = setTimeout(() => {
|
|
11
|
+
func(...args);
|
|
20
12
|
timeoutId = null;
|
|
21
|
-
if (trailing && pendingArgs != null) {
|
|
22
|
-
func.apply(this, pendingArgs);
|
|
23
|
-
pendingArgs = null;
|
|
24
|
-
}
|
|
25
13
|
}, debounceMs);
|
|
26
14
|
};
|
|
27
15
|
const onAbort = function () {
|
package/dist/function/index.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
5
5
|
const zipWith = require('./_chunk/zipWith-CHjHmX.js');
|
|
6
6
|
const array_index = require('./array/index.js');
|
|
7
7
|
const promise_index = require('./_chunk/index-BGZDR9.js');
|
|
8
|
-
const rest = require('./_chunk/rest-
|
|
8
|
+
const rest = require('./_chunk/rest-CXt9w3.js');
|
|
9
9
|
const function_index = require('./function/index.js');
|
|
10
10
|
const range = require('./_chunk/range-BXlMmn.js');
|
|
11
11
|
const randomInt = require('./_chunk/randomInt-CF7bZK.js');
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "es-toolkit",
|
|
3
3
|
"description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
|
|
4
|
-
"version": "1.19.0-dev.
|
|
4
|
+
"version": "1.19.0-dev.613+19eabc93",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|