es-toolkit 1.19.0-dev.615 → 1.19.0-dev.617

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.
@@ -1,3 +1,17 @@
1
+ interface ThrottleOptions {
2
+ /**
3
+ * An optional AbortSignal to cancel the debounced function.
4
+ */
5
+ signal?: AbortSignal;
6
+ /**
7
+ * An optional array specifying whether the function should be invoked on the leading edge, trailing edge, or both.
8
+ * If `edges` includes "leading", the function will be invoked at the start of the delay period.
9
+ * If `edges` includes "trailing", the function will be invoked at the end of the delay period.
10
+ * If both "leading" and "trailing" are included, the function will be invoked at both the start and end of the delay period.
11
+ * @default ["leading", "trailing"]
12
+ */
13
+ edges?: Array<'leading' | 'trailing'>;
14
+ }
1
15
  /**
2
16
  * Creates a throttled function that only invokes the provided function at most once
3
17
  * per every `throttleMs` milliseconds. Subsequent calls to the throttled function
@@ -24,6 +38,9 @@
24
38
  * throttledFunction(); // Will log 'Function executed'
25
39
  * }, 1000);
26
40
  */
27
- declare function throttle<F extends (...args: any[]) => void>(func: F, throttleMs: number): (...args: Parameters<F>) => void;
41
+ declare function throttle<F extends (...args: any[]) => void>(func: F, throttleMs: number, { signal, edges }?: ThrottleOptions): ((...args: Parameters<F>) => void) & {
42
+ cancel: () => void;
43
+ flush: () => void;
44
+ };
28
45
 
29
46
  export { throttle };
@@ -1,3 +1,17 @@
1
+ interface ThrottleOptions {
2
+ /**
3
+ * An optional AbortSignal to cancel the debounced function.
4
+ */
5
+ signal?: AbortSignal;
6
+ /**
7
+ * An optional array specifying whether the function should be invoked on the leading edge, trailing edge, or both.
8
+ * If `edges` includes "leading", the function will be invoked at the start of the delay period.
9
+ * If `edges` includes "trailing", the function will be invoked at the end of the delay period.
10
+ * If both "leading" and "trailing" are included, the function will be invoked at both the start and end of the delay period.
11
+ * @default ["leading", "trailing"]
12
+ */
13
+ edges?: Array<'leading' | 'trailing'>;
14
+ }
1
15
  /**
2
16
  * Creates a throttled function that only invokes the provided function at most once
3
17
  * per every `throttleMs` milliseconds. Subsequent calls to the throttled function
@@ -24,6 +38,9 @@
24
38
  * throttledFunction(); // Will log 'Function executed'
25
39
  * }, 1000);
26
40
  */
27
- declare function throttle<F extends (...args: any[]) => void>(func: F, throttleMs: number): (...args: Parameters<F>) => void;
41
+ declare function throttle<F extends (...args: any[]) => void>(func: F, throttleMs: number, { signal, edges }?: ThrottleOptions): ((...args: Parameters<F>) => void) & {
42
+ cancel: () => void;
43
+ flush: () => void;
44
+ };
28
45
 
29
46
  export { throttle };
@@ -1,13 +1,23 @@
1
- function throttle(func, throttleMs) {
2
- let lastCallTime;
3
- const throttledFunction = function (...args) {
4
- const now = Date.now();
5
- if (lastCallTime == null || now - lastCallTime >= throttleMs) {
6
- lastCallTime = now;
7
- func(...args);
1
+ import { debounce } from './debounce.mjs';
2
+
3
+ function throttle(func, throttleMs, { signal, edges = ['leading', 'trailing'] } = {}) {
4
+ let pendingAt = null;
5
+ const debounced = debounce(func, throttleMs, { signal, edges });
6
+ const throttled = function (...args) {
7
+ if (pendingAt == null) {
8
+ pendingAt = Date.now();
9
+ }
10
+ else {
11
+ if (Date.now() - pendingAt >= throttleMs) {
12
+ debounced.cancel();
13
+ debounced(...args);
14
+ }
8
15
  }
16
+ debounced(...args);
9
17
  };
10
- return throttledFunction;
18
+ throttled.cancel = debounced.cancel;
19
+ throttled.flush = debounced.flush;
20
+ return throttled;
11
21
  }
12
22
 
13
23
  export { throttle };
package/dist/index.d.mts CHANGED
@@ -96,6 +96,7 @@ export { toMerged } from './object/toMerged.mjs';
96
96
  export { mergeWith } from './object/mergeWith.mjs';
97
97
  export { isDate } from './predicate/isDate.mjs';
98
98
  export { isEqual } from './predicate/isEqual.mjs';
99
+ export { isNaN } from './predicate/isNaN.mjs';
99
100
  export { isNil } from './predicate/isNil.mjs';
100
101
  export { isNotNil } from './predicate/isNotNil.mjs';
101
102
  export { isNull } from './predicate/isNull.mjs';
package/dist/index.d.ts CHANGED
@@ -96,6 +96,7 @@ export { toMerged } from './object/toMerged.js';
96
96
  export { mergeWith } from './object/mergeWith.js';
97
97
  export { isDate } from './predicate/isDate.js';
98
98
  export { isEqual } from './predicate/isEqual.js';
99
+ export { isNaN } from './predicate/isNaN.js';
99
100
  export { isNil } from './predicate/isNil.js';
100
101
  export { isNotNil } from './predicate/isNotNil.js';
101
102
  export { isNull } from './predicate/isNull.js';
package/dist/index.js CHANGED
@@ -5,14 +5,14 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5
5
  const zipWith = require('./_chunk/zipWith-CDtN9Y.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-CXt9w3.js');
8
+ const rest = require('./_chunk/rest-pUyjvl.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');
12
12
  const math_index = require('./math/index.js');
13
13
  const object_index = require('./object/index.js');
14
14
  const toMerged = require('./_chunk/toMerged-Bzkqyz.js');
15
- const isWeakSet = require('./_chunk/isWeakSet-E_VMwB.js');
15
+ const isWeakSet = require('./_chunk/isWeakSet-vsS9b6.js');
16
16
  const isPlainObject = require('./_chunk/isPlainObject-BIekvL.js');
17
17
  const predicate_index = require('./predicate/index.js');
18
18
  const string_index = require('./string/index.js');
@@ -91,10 +91,10 @@ exports.once = rest.once;
91
91
  exports.partial = rest.partial;
92
92
  exports.partialRight = rest.partialRight;
93
93
  exports.rest = rest.rest;
94
- exports.throttle = rest.throttle;
95
94
  exports.unary = rest.unary;
96
95
  exports.curry = function_index.curry;
97
96
  exports.spread = function_index.spread;
97
+ exports.throttle = function_index.throttle;
98
98
  exports.clamp = range.clamp;
99
99
  exports.inRange = range.inRange;
100
100
  exports.mean = range.mean;
@@ -122,6 +122,7 @@ exports.isDate = isWeakSet.isDate;
122
122
  exports.isEqual = isWeakSet.isEqual;
123
123
  exports.isFunction = isWeakSet.isFunction;
124
124
  exports.isLength = isWeakSet.isLength;
125
+ exports.isNaN = isWeakSet.isNaN;
125
126
  exports.isNil = isWeakSet.isNil;
126
127
  exports.isNotNil = isWeakSet.isNotNil;
127
128
  exports.isNull = isWeakSet.isNull;
package/dist/index.mjs CHANGED
@@ -96,6 +96,7 @@ export { toMerged } from './object/toMerged.mjs';
96
96
  export { mergeWith } from './object/mergeWith.mjs';
97
97
  export { isDate } from './predicate/isDate.mjs';
98
98
  export { isEqual } from './predicate/isEqual.mjs';
99
+ export { isNaN } from './predicate/isNaN.mjs';
99
100
  export { isNil } from './predicate/isNil.mjs';
100
101
  export { isNotNil } from './predicate/isNotNil.mjs';
101
102
  export { isNull } from './predicate/isNull.mjs';
@@ -1,5 +1,6 @@
1
1
  export { isDate } from './isDate.mjs';
2
2
  export { isEqual } from './isEqual.mjs';
3
+ export { isNaN } from './isNaN.mjs';
3
4
  export { isNil } from './isNil.mjs';
4
5
  export { isNotNil } from './isNotNil.mjs';
5
6
  export { isNull } from './isNull.mjs';
@@ -1,5 +1,6 @@
1
1
  export { isDate } from './isDate.js';
2
2
  export { isEqual } from './isEqual.js';
3
+ export { isNaN } from './isNaN.js';
3
4
  export { isNil } from './isNil.js';
4
5
  export { isNotNil } from './isNotNil.js';
5
6
  export { isNull } from './isNull.js';
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const isWeakSet = require('../_chunk/isWeakSet-E_VMwB.js');
5
+ const isWeakSet = require('../_chunk/isWeakSet-vsS9b6.js');
6
6
  const isPlainObject = require('../_chunk/isPlainObject-BIekvL.js');
7
7
 
8
8
  function isRegExp(value) {
@@ -25,6 +25,7 @@ exports.isDate = isWeakSet.isDate;
25
25
  exports.isEqual = isWeakSet.isEqual;
26
26
  exports.isFunction = isWeakSet.isFunction;
27
27
  exports.isLength = isWeakSet.isLength;
28
+ exports.isNaN = isWeakSet.isNaN;
28
29
  exports.isNil = isWeakSet.isNil;
29
30
  exports.isNotNil = isWeakSet.isNotNil;
30
31
  exports.isNull = isWeakSet.isNull;
@@ -1,5 +1,6 @@
1
1
  export { isDate } from './isDate.mjs';
2
2
  export { isEqual } from './isEqual.mjs';
3
+ export { isNaN } from './isNaN.mjs';
3
4
  export { isNil } from './isNil.mjs';
4
5
  export { isNotNil } from './isNotNil.mjs';
5
6
  export { isNull } from './isNull.mjs';
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Checks if the value is NaN.
3
+ *
4
+ * @param {unknown} value - The value to check.
5
+ * @returns {value is typeof NaN} `true` if the value is NaN, `false` otherwise.
6
+ *
7
+ * @example
8
+ * isNaN(NaN); // true
9
+ * isNaN(0); // false
10
+ * isNaN('NaN'); // false
11
+ * isNaN(undefined); // false
12
+ */
13
+ declare function isNaN(value: unknown): value is typeof NaN;
14
+
15
+ export { isNaN };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Checks if the value is NaN.
3
+ *
4
+ * @param {unknown} value - The value to check.
5
+ * @returns {value is typeof NaN} `true` if the value is NaN, `false` otherwise.
6
+ *
7
+ * @example
8
+ * isNaN(NaN); // true
9
+ * isNaN(0); // false
10
+ * isNaN('NaN'); // false
11
+ * isNaN(undefined); // false
12
+ */
13
+ declare function isNaN(value: unknown): value is typeof NaN;
14
+
15
+ export { isNaN };
@@ -0,0 +1,5 @@
1
+ function isNaN(value) {
2
+ return Number.isNaN(value);
3
+ }
4
+
5
+ export { isNaN };
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.615+b402c8f4",
4
+ "version": "1.19.0-dev.617+c21874ef",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {