es-toolkit 1.19.0-dev.618 → 1.19.0-dev.620

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.
@@ -2,30 +2,30 @@ import { property } from '../object/property.mjs';
2
2
  import { matches } from '../predicate/matches.mjs';
3
3
  import { matchesProperty } from '../predicate/matchesProperty.mjs';
4
4
 
5
- function findLastIndex(source, doesMatch, fromIndex = source.length - 1) {
5
+ function findLastIndex(arr, doesMatch, fromIndex = arr.length - 1) {
6
6
  if (fromIndex < 0) {
7
- fromIndex = Math.max(source.length + fromIndex, 0);
7
+ fromIndex = Math.max(arr.length + fromIndex, 0);
8
8
  }
9
9
  else {
10
- fromIndex = Math.min(fromIndex, source.length - 1);
10
+ fromIndex = Math.min(fromIndex, arr.length - 1);
11
11
  }
12
- source = source.slice(0, fromIndex + 1);
12
+ arr = arr.slice(0, fromIndex + 1);
13
13
  switch (typeof doesMatch) {
14
14
  case 'function': {
15
- return source.findLastIndex(doesMatch);
15
+ return arr.findLastIndex(doesMatch);
16
16
  }
17
17
  case 'object': {
18
18
  if (Array.isArray(doesMatch) && doesMatch.length === 2) {
19
19
  const key = doesMatch[0];
20
20
  const value = doesMatch[1];
21
- return source.findLastIndex(matchesProperty(key, value));
21
+ return arr.findLastIndex(matchesProperty(key, value));
22
22
  }
23
23
  else {
24
- return source.findLastIndex(matches(doesMatch));
24
+ return arr.findLastIndex(matches(doesMatch));
25
25
  }
26
26
  }
27
27
  case 'string': {
28
- return source.findLastIndex(property(doesMatch));
28
+ return arr.findLastIndex(property(doesMatch));
29
29
  }
30
30
  }
31
31
  }
@@ -65,7 +65,6 @@ declare function some<T>(arr: readonly T[], doesMatch: Partial<T>): boolean;
65
65
  * @param {T[]} arr The array to iterate over.
66
66
  * @param {((item: T, index: number, arr: any) => unknown) | Partial<T> | [keyof T, unknown] | string} [predicate=identity] The function invoked per iteration.
67
67
  * If a property name or an object is provided it will be used to create a predicate function.
68
- * @param guard
69
68
  * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
70
69
  *
71
70
  * @example
@@ -65,7 +65,6 @@ declare function some<T>(arr: readonly T[], doesMatch: Partial<T>): boolean;
65
65
  * @param {T[]} arr The array to iterate over.
66
66
  * @param {((item: T, index: number, arr: any) => unknown) | Partial<T> | [keyof T, unknown] | string} [predicate=identity] The function invoked per iteration.
67
67
  * If a property name or an object is provided it will be used to create a predicate function.
68
- * @param guard
69
68
  * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
70
69
  *
71
70
  * @example
@@ -14,6 +14,36 @@ interface ThrottleOptions {
14
14
  */
15
15
  trailing?: boolean;
16
16
  }
17
+ /**
18
+ * Creates a throttled function that only invokes the provided function at most once
19
+ * per every `throttleMs` milliseconds. Subsequent calls to the throttled function
20
+ * within the wait time will not trigger the execution of the original function.
21
+ *
22
+ * @template F - The type of function.
23
+ * @param {F} func - The function to throttle.
24
+ * @param {number} throttleMs - The number of milliseconds to throttle executions to.
25
+ * @param {ThrottleOptions} options - The options object
26
+ * @param {AbortSignal} options.signal - An optional AbortSignal to cancel the throttled function.
27
+ * @param {boolean} options.leading - If `true`, the function will be invoked on the leading edge of the timeout.
28
+ * @param {boolean} options.trailing - If `true`, the function will be invoked on the trailing edge of the timeout.
29
+ * @returns {(...args: Parameters<F>) => void} A new throttled function that accepts the same parameters as the original function.
30
+ *
31
+ * @example
32
+ * const throttledFunction = throttle(() => {
33
+ * console.log('Function executed');
34
+ * }, 1000);
35
+ *
36
+ * // Will log 'Function executed' immediately
37
+ * throttledFunction();
38
+ *
39
+ * // Will not log anything as it is within the throttle time
40
+ * throttledFunction();
41
+ *
42
+ * // After 1 second
43
+ * setTimeout(() => {
44
+ * throttledFunction(); // Will log 'Function executed'
45
+ * }, 1000);
46
+ */
17
47
  declare function throttle<F extends (...args: any[]) => any>(func: F, throttleMs?: number, options?: ThrottleOptions): ((...args: Parameters<F>) => ReturnType<F> | undefined) & {
18
48
  cancel: () => void;
19
49
  flush: () => void;
@@ -14,6 +14,36 @@ interface ThrottleOptions {
14
14
  */
15
15
  trailing?: boolean;
16
16
  }
17
+ /**
18
+ * Creates a throttled function that only invokes the provided function at most once
19
+ * per every `throttleMs` milliseconds. Subsequent calls to the throttled function
20
+ * within the wait time will not trigger the execution of the original function.
21
+ *
22
+ * @template F - The type of function.
23
+ * @param {F} func - The function to throttle.
24
+ * @param {number} throttleMs - The number of milliseconds to throttle executions to.
25
+ * @param {ThrottleOptions} options - The options object
26
+ * @param {AbortSignal} options.signal - An optional AbortSignal to cancel the throttled function.
27
+ * @param {boolean} options.leading - If `true`, the function will be invoked on the leading edge of the timeout.
28
+ * @param {boolean} options.trailing - If `true`, the function will be invoked on the trailing edge of the timeout.
29
+ * @returns {(...args: Parameters<F>) => void} A new throttled function that accepts the same parameters as the original function.
30
+ *
31
+ * @example
32
+ * const throttledFunction = throttle(() => {
33
+ * console.log('Function executed');
34
+ * }, 1000);
35
+ *
36
+ * // Will log 'Function executed' immediately
37
+ * throttledFunction();
38
+ *
39
+ * // Will not log anything as it is within the throttle time
40
+ * throttledFunction();
41
+ *
42
+ * // After 1 second
43
+ * setTimeout(() => {
44
+ * throttledFunction(); // Will log 'Function executed'
45
+ * }, 1000);
46
+ */
17
47
  declare function throttle<F extends (...args: any[]) => any>(func: F, throttleMs?: number, options?: ThrottleOptions): ((...args: Parameters<F>) => ReturnType<F> | undefined) & {
18
48
  cancel: () => void;
19
49
  flush: () => void;
@@ -75,7 +75,6 @@ export { cloneDeep } from '../object/cloneDeep.mjs';
75
75
  export { toMerged } from '../object/toMerged.mjs';
76
76
  export { isDate } from '../predicate/isDate.mjs';
77
77
  export { isEqual } from '../predicate/isEqual.mjs';
78
- export { isNaN } from '../predicate/isNaN.mjs';
79
78
  export { isNil } from '../predicate/isNil.mjs';
80
79
  export { isNotNil } from '../predicate/isNotNil.mjs';
81
80
  export { isNull } from '../predicate/isNull.mjs';
@@ -157,6 +156,8 @@ export { conforms } from './predicate/conforms.mjs';
157
156
  export { conformsTo } from './predicate/conformsTo.mjs';
158
157
  export { isInteger } from './predicate/isInteger.mjs';
159
158
  export { isSafeInteger } from './predicate/isSafeInteger.mjs';
159
+ export { isNumber } from './predicate/isNumber.mjs';
160
+ export { isNaN } from './predicate/isNaN.mjs';
160
161
  export { camelCase } from './string/camelCase.mjs';
161
162
  export { kebabCase } from './string/kebabCase.mjs';
162
163
  export { snakeCase } from './string/snakeCase.mjs';
@@ -75,7 +75,6 @@ export { cloneDeep } from '../object/cloneDeep.js';
75
75
  export { toMerged } from '../object/toMerged.js';
76
76
  export { isDate } from '../predicate/isDate.js';
77
77
  export { isEqual } from '../predicate/isEqual.js';
78
- export { isNaN } from '../predicate/isNaN.js';
79
78
  export { isNil } from '../predicate/isNil.js';
80
79
  export { isNotNil } from '../predicate/isNotNil.js';
81
80
  export { isNull } from '../predicate/isNull.js';
@@ -157,6 +156,8 @@ export { conforms } from './predicate/conforms.js';
157
156
  export { conformsTo } from './predicate/conformsTo.js';
158
157
  export { isInteger } from './predicate/isInteger.js';
159
158
  export { isSafeInteger } from './predicate/isSafeInteger.js';
159
+ export { isNumber } from './predicate/isNumber.js';
160
+ export { isNaN } from './predicate/isNaN.js';
160
161
  export { camelCase } from './string/camelCase.js';
161
162
  export { kebabCase } from './string/kebabCase.js';
162
163
  export { snakeCase } from './string/snakeCase.js';
@@ -8,7 +8,7 @@ const rest$1 = require('../_chunk/rest-pUyjvl.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');
11
- const isWeakSet$1 = require('../_chunk/isWeakSet-vsS9b6.js');
11
+ const isWeakSet$1 = require('../_chunk/isWeakSet-E_VMwB.js');
12
12
  const isPlainObject$1 = require('../_chunk/isPlainObject-BIekvL.js');
13
13
  const string_index = require('../string/index.js');
14
14
 
@@ -438,30 +438,30 @@ function findIndex(source, doesMatch) {
438
438
  }
439
439
  }
440
440
 
441
- function findLastIndex(source, doesMatch, fromIndex = source.length - 1) {
441
+ function findLastIndex(arr, doesMatch, fromIndex = arr.length - 1) {
442
442
  if (fromIndex < 0) {
443
- fromIndex = Math.max(source.length + fromIndex, 0);
443
+ fromIndex = Math.max(arr.length + fromIndex, 0);
444
444
  }
445
445
  else {
446
- fromIndex = Math.min(fromIndex, source.length - 1);
446
+ fromIndex = Math.min(fromIndex, arr.length - 1);
447
447
  }
448
- source = source.slice(0, fromIndex + 1);
448
+ arr = arr.slice(0, fromIndex + 1);
449
449
  switch (typeof doesMatch) {
450
450
  case 'function': {
451
- return source.findLastIndex(doesMatch);
451
+ return arr.findLastIndex(doesMatch);
452
452
  }
453
453
  case 'object': {
454
454
  if (Array.isArray(doesMatch) && doesMatch.length === 2) {
455
455
  const key = doesMatch[0];
456
456
  const value = doesMatch[1];
457
- return source.findLastIndex(matchesProperty(key, value));
457
+ return arr.findLastIndex(matchesProperty(key, value));
458
458
  }
459
459
  else {
460
- return source.findLastIndex(matches(doesMatch));
460
+ return arr.findLastIndex(matches(doesMatch));
461
461
  }
462
462
  }
463
463
  case 'string': {
464
- return source.findLastIndex(property(doesMatch));
464
+ return arr.findLastIndex(property(doesMatch));
465
465
  }
466
466
  }
467
467
  }
@@ -1300,6 +1300,17 @@ function isSafeInteger(value) {
1300
1300
  return Number.isSafeInteger(value);
1301
1301
  }
1302
1302
 
1303
+ function isNumber(value) {
1304
+ if (typeof value === 'object' && value != null && isWeakSet$1.getTag(value) === '[object Number]') {
1305
+ return true;
1306
+ }
1307
+ return typeof value === 'number';
1308
+ }
1309
+
1310
+ function isNaN(value) {
1311
+ return Number.isNaN(value);
1312
+ }
1313
+
1303
1314
  function toString(value) {
1304
1315
  if (value == null) {
1305
1316
  return '';
@@ -1572,7 +1583,6 @@ exports.isDate = isWeakSet$1.isDate;
1572
1583
  exports.isEqual = isWeakSet$1.isEqual;
1573
1584
  exports.isFunction = isWeakSet$1.isFunction;
1574
1585
  exports.isLength = isWeakSet$1.isLength;
1575
- exports.isNaN = isWeakSet$1.isNaN;
1576
1586
  exports.isNil = isWeakSet$1.isNil;
1577
1587
  exports.isNotNil = isWeakSet$1.isNotNil;
1578
1588
  exports.isNull = isWeakSet$1.isNull;
@@ -1622,6 +1632,8 @@ exports.isArrayLike = isArrayLike;
1622
1632
  exports.isBoolean = isBoolean;
1623
1633
  exports.isInteger = isInteger;
1624
1634
  exports.isMatch = isMatch;
1635
+ exports.isNaN = isNaN;
1636
+ exports.isNumber = isNumber;
1625
1637
  exports.isObject = isObject;
1626
1638
  exports.isPlainObject = isPlainObject;
1627
1639
  exports.isRegExp = isRegExp;
@@ -76,7 +76,6 @@ export { isObjectLike } from './predicate/isObjectLike.mjs';
76
76
  export { toMerged } from '../object/toMerged.mjs';
77
77
  export { isDate } from '../predicate/isDate.mjs';
78
78
  export { isEqual } from '../predicate/isEqual.mjs';
79
- export { isNaN } from '../predicate/isNaN.mjs';
80
79
  export { isNil } from '../predicate/isNil.mjs';
81
80
  export { isNotNil } from '../predicate/isNotNil.mjs';
82
81
  export { isNull } from '../predicate/isNull.mjs';
@@ -157,6 +156,8 @@ export { conforms } from './predicate/conforms.mjs';
157
156
  export { conformsTo } from './predicate/conformsTo.mjs';
158
157
  export { isInteger } from './predicate/isInteger.mjs';
159
158
  export { isSafeInteger } from './predicate/isSafeInteger.mjs';
159
+ export { isNumber } from './predicate/isNumber.mjs';
160
+ export { isNaN } from './predicate/isNaN.mjs';
160
161
  export { camelCase } from './string/camelCase.mjs';
161
162
  export { kebabCase } from './string/kebabCase.mjs';
162
163
  export { snakeCase } from './string/snakeCase.mjs';
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Checks if a given value is a number.
3
+ *
4
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `number`.
5
+ *
6
+ * @param {unknown} value The value to check if it is a number.
7
+ * @returns {value is number} Returns `true` if `value` is a number, else `false`.
8
+ *
9
+ * @example
10
+ * const value1 = 123;
11
+ * const value2 = 'abc';
12
+ * const value3 = true;
13
+ *
14
+ * console.log(isNumber(value1)); // true
15
+ * console.log(isNumber(value2)); // false
16
+ * console.log(isNumber(value3)); // false
17
+ */
18
+ declare function isNumber(value?: unknown): value is number;
19
+
20
+ export { isNumber };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Checks if a given value is a number.
3
+ *
4
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `number`.
5
+ *
6
+ * @param {unknown} value The value to check if it is a number.
7
+ * @returns {value is number} Returns `true` if `value` is a number, else `false`.
8
+ *
9
+ * @example
10
+ * const value1 = 123;
11
+ * const value2 = 'abc';
12
+ * const value3 = true;
13
+ *
14
+ * console.log(isNumber(value1)); // true
15
+ * console.log(isNumber(value2)); // false
16
+ * console.log(isNumber(value3)); // false
17
+ */
18
+ declare function isNumber(value?: unknown): value is number;
19
+
20
+ export { isNumber };
@@ -0,0 +1,10 @@
1
+ import { getTag } from '../_internal/getTag.mjs';
2
+
3
+ function isNumber(value) {
4
+ if (typeof value === 'object' && value != null && getTag(value) === '[object Number]') {
5
+ return true;
6
+ }
7
+ return typeof value === 'number';
8
+ }
9
+
10
+ export { isNumber };
@@ -3,7 +3,6 @@
3
3
  *
4
4
  * @param {string} str - The string from which leading and trailing characters will be trimmed.
5
5
  * @param {string | string[]} chars - The character(s) to remove from the end of the string. Defaults to `" "`.
6
- * @param guard
7
6
  * @returns {string} - The resulting string after the specified leading and trailing characters have been removed.
8
7
  *
9
8
  * @example
@@ -3,7 +3,6 @@
3
3
  *
4
4
  * @param {string} str - The string from which leading and trailing characters will be trimmed.
5
5
  * @param {string | string[]} chars - The character(s) to remove from the end of the string. Defaults to `" "`.
6
- * @param guard
7
6
  * @returns {string} - The resulting string after the specified leading and trailing characters have been removed.
8
7
  *
9
8
  * @example
@@ -3,7 +3,6 @@
3
3
  *
4
4
  * @param {string} str - The string from which trailing characters will be trimmed.
5
5
  * @param {string | string[]} chars - The character(s) to remove from the end of the string. Defaults to `" "`.
6
- * @param guard
7
6
  * @returns {string} - The resulting string after the specified trailing character has been removed.
8
7
  *
9
8
  * @example
@@ -3,7 +3,6 @@
3
3
  *
4
4
  * @param {string} str - The string from which trailing characters will be trimmed.
5
5
  * @param {string | string[]} chars - The character(s) to remove from the end of the string. Defaults to `" "`.
6
- * @param guard
7
6
  * @returns {string} - The resulting string after the specified trailing character has been removed.
8
7
  *
9
8
  * @example
@@ -3,7 +3,6 @@
3
3
  *
4
4
  * @param {string} str - The string from which leading characters will be trimmed.
5
5
  * @param {string | string[]} chars - The character(s) to remove from the end of the string. Defaults to `" "`.
6
- * @param guard
7
6
  * @returns {string} - The resulting string after the specified leading character has been removed.
8
7
  *
9
8
  * @example
@@ -3,7 +3,6 @@
3
3
  *
4
4
  * @param {string} str - The string from which leading characters will be trimmed.
5
5
  * @param {string | string[]} chars - The character(s) to remove from the end of the string. Defaults to `" "`.
6
- * @param guard
7
6
  * @returns {string} - The resulting string after the specified leading character has been removed.
8
7
  *
9
8
  * @example
package/dist/index.d.mts CHANGED
@@ -96,7 +96,6 @@ 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';
100
99
  export { isNil } from './predicate/isNil.mjs';
101
100
  export { isNotNil } from './predicate/isNotNil.mjs';
102
101
  export { isNull } from './predicate/isNull.mjs';
package/dist/index.d.ts CHANGED
@@ -96,7 +96,6 @@ 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';
100
99
  export { isNil } from './predicate/isNil.js';
101
100
  export { isNotNil } from './predicate/isNotNil.js';
102
101
  export { isNull } from './predicate/isNull.js';
package/dist/index.js CHANGED
@@ -12,7 +12,7 @@ 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-vsS9b6.js');
15
+ const isWeakSet = require('./_chunk/isWeakSet-E_VMwB.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');
@@ -122,7 +122,6 @@ 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;
126
125
  exports.isNil = isWeakSet.isNil;
127
126
  exports.isNotNil = isWeakSet.isNotNil;
128
127
  exports.isNull = isWeakSet.isNull;
package/dist/index.mjs CHANGED
@@ -96,7 +96,6 @@ 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';
100
99
  export { isNil } from './predicate/isNil.mjs';
101
100
  export { isNotNil } from './predicate/isNotNil.mjs';
102
101
  export { isNull } from './predicate/isNull.mjs';
@@ -1,6 +1,5 @@
1
1
  export { isDate } from './isDate.mjs';
2
2
  export { isEqual } from './isEqual.mjs';
3
- export { isNaN } from './isNaN.mjs';
4
3
  export { isNil } from './isNil.mjs';
5
4
  export { isNotNil } from './isNotNil.mjs';
6
5
  export { isNull } from './isNull.mjs';
@@ -1,6 +1,5 @@
1
1
  export { isDate } from './isDate.js';
2
2
  export { isEqual } from './isEqual.js';
3
- export { isNaN } from './isNaN.js';
4
3
  export { isNil } from './isNil.js';
5
4
  export { isNotNil } from './isNotNil.js';
6
5
  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-vsS9b6.js');
5
+ const isWeakSet = require('../_chunk/isWeakSet-E_VMwB.js');
6
6
  const isPlainObject = require('../_chunk/isPlainObject-BIekvL.js');
7
7
 
8
8
  function isRegExp(value) {
@@ -25,7 +25,6 @@ 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;
29
28
  exports.isNil = isWeakSet.isNil;
30
29
  exports.isNotNil = isWeakSet.isNotNil;
31
30
  exports.isNull = isWeakSet.isNull;
@@ -1,6 +1,5 @@
1
1
  export { isDate } from './isDate.mjs';
2
2
  export { isEqual } from './isEqual.mjs';
3
- export { isNaN } from './isNaN.mjs';
4
3
  export { isNil } from './isNil.mjs';
5
4
  export { isNotNil } from './isNotNil.mjs';
6
5
  export { isNull } from './isNull.mjs';
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.618+f53bfd5c",
4
+ "version": "1.19.0-dev.620+e32bd246",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {
File without changes
File without changes