es-toolkit 1.2.2-dev.72 → 1.2.2

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.
Files changed (54) hide show
  1. package/dist/array/index.js +3 -4
  2. package/dist/array/index.js.map +1 -1
  3. package/dist/array/index.mjs +6 -6
  4. package/dist/array/intersection.js +1 -2
  5. package/dist/array/intersection.js.map +1 -1
  6. package/dist/array/intersection.mjs +1 -1
  7. package/dist/array/unionWith.js.map +1 -1
  8. package/dist/array/unionWith.mjs +2 -2
  9. package/dist/array/uniqBy.d.mts +6 -5
  10. package/dist/array/uniqBy.d.ts +6 -5
  11. package/dist/array/uniqBy.js +2 -2
  12. package/dist/array/uniqBy.js.map +1 -1
  13. package/dist/array/uniqBy.mjs +2 -2
  14. package/dist/array/uniqWith.d.mts +3 -2
  15. package/dist/array/uniqWith.d.ts +3 -2
  16. package/dist/array/uniqWith.js.map +1 -1
  17. package/dist/array/uniqWith.mjs +1 -1
  18. package/dist/array/xor.js +1 -2
  19. package/dist/array/xor.js.map +1 -1
  20. package/dist/array/xor.mjs +2 -2
  21. package/dist/array/xorWith.js.map +1 -1
  22. package/dist/array/xorWith.mjs +3 -3
  23. package/dist/{chunk-3KHI4I2X.mjs → chunk-5P2QE2VI.mjs} +2 -2
  24. package/dist/{chunk-WXIBCOES.mjs → chunk-62EFHAYX.mjs} +2 -2
  25. package/dist/{chunk-PYLGHB3F.mjs → chunk-7XTQCUMW.mjs} +2 -3
  26. package/dist/{chunk-PYLGHB3F.mjs.map → chunk-7XTQCUMW.mjs.map} +1 -1
  27. package/dist/chunk-GELVVASW.mjs +23 -0
  28. package/dist/chunk-GELVVASW.mjs.map +1 -0
  29. package/dist/chunk-LCYPY5SA.mjs +13 -0
  30. package/dist/chunk-LCYPY5SA.mjs.map +1 -0
  31. package/dist/{chunk-FCF2RHPW.mjs → chunk-LVB7BYUY.mjs} +2 -2
  32. package/dist/{chunk-2PFDLYQC.mjs → chunk-NXPEUTDI.mjs} +1 -1
  33. package/dist/chunk-NXPEUTDI.mjs.map +1 -0
  34. package/dist/function/debounce.d.mts +1 -18
  35. package/dist/function/debounce.d.ts +1 -18
  36. package/dist/function/debounce.js +3 -13
  37. package/dist/function/debounce.js.map +1 -1
  38. package/dist/function/debounce.mjs +1 -1
  39. package/dist/function/index.js +3 -13
  40. package/dist/function/index.js.map +1 -1
  41. package/dist/function/index.mjs +4 -4
  42. package/dist/index.js +6 -17
  43. package/dist/index.js.map +1 -1
  44. package/dist/index.mjs +20 -20
  45. package/dist/math/index.mjs +3 -3
  46. package/package.json +1 -1
  47. package/dist/chunk-2PFDLYQC.mjs.map +0 -1
  48. package/dist/chunk-ASFOKYTY.mjs +0 -13
  49. package/dist/chunk-ASFOKYTY.mjs.map +0 -1
  50. package/dist/chunk-GOXQV6DX.mjs +0 -33
  51. package/dist/chunk-GOXQV6DX.mjs.map +0 -1
  52. /package/dist/{chunk-3KHI4I2X.mjs.map → chunk-5P2QE2VI.mjs.map} +0 -0
  53. /package/dist/{chunk-WXIBCOES.mjs.map → chunk-62EFHAYX.mjs.map} +0 -0
  54. /package/dist/{chunk-FCF2RHPW.mjs.map → chunk-LVB7BYUY.mjs.map} +0 -0
@@ -1,12 +1,11 @@
1
1
  // src/array/intersection.ts
2
2
  function intersection(firstArr, secondArr) {
3
- const secondSet = new Set(secondArr);
4
3
  return firstArr.filter((item) => {
5
- return secondSet.has(item);
4
+ return secondArr.includes(item);
6
5
  });
7
6
  }
8
7
 
9
8
  export {
10
9
  intersection
11
10
  };
12
- //# sourceMappingURL=chunk-PYLGHB3F.mjs.map
11
+ //# sourceMappingURL=chunk-7XTQCUMW.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/array/intersection.ts"],"sourcesContent":["/**\n * Returns the intersection of two arrays.\n *\n * This function takes two arrays and returns a new array containing the elements that are\n * present in both arrays. It effectively filters out any elements from the first array that\n * are not found in the second array.\n *\n * @param {T[]} firstArr - The first array to compare.\n * @param {T[]} secondArr - The second array to compare.\n * @returns {T[]} A new array containing the elements that are present in both arrays.\n *\n * @example\n * const array1 = [1, 2, 3, 4, 5];\n * const array2 = [3, 4, 5, 6, 7];\n * const result = intersection(array1, array2);\n * // result will be [3, 4, 5] since these elements are in both arrays.\n */\nexport function intersection<T>(firstArr: readonly T[], secondArr: readonly T[]): T[] {\n const secondSet = new Set(secondArr);\n\n return firstArr.filter(item => {\n return secondSet.has(item);\n });\n}\n"],"mappings":";AAiBO,SAAS,aAAgB,UAAwB,WAA8B;AACpF,QAAM,YAAY,IAAI,IAAI,SAAS;AAEnC,SAAO,SAAS,OAAO,UAAQ;AAC7B,WAAO,UAAU,IAAI,IAAI;AAAA,EAC3B,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../src/array/intersection.ts"],"sourcesContent":["/**\n * Returns the intersection of two arrays.\n *\n * This function takes two arrays and returns a new array containing the elements that are\n * present in both arrays. It effectively filters out any elements from the first array that\n * are not found in the second array.\n *\n * @param {T[]} firstArr - The first array to compare.\n * @param {T[]} secondArr - The second array to compare.\n * @returns {T[]} A new array containing the elements that are present in both arrays.\n *\n * @example\n * const array1 = [1, 2, 3, 4, 5];\n * const array2 = [3, 4, 5, 6, 7];\n * const result = intersection(array1, array2);\n * // result will be [3, 4, 5] since these elements are in both arrays.\n */\nexport function intersection<T>(firstArr: readonly T[], secondArr: readonly T[]): T[] {\n return firstArr.filter(item => {\n return secondArr.includes(item);\n });\n}\n"],"mappings":";AAiBO,SAAS,aAAgB,UAAwB,WAA8B;AACpF,SAAO,SAAS,OAAO,UAAQ;AAC7B,WAAO,UAAU,SAAS,IAAI;AAAA,EAChC,CAAC;AACH;","names":[]}
@@ -0,0 +1,23 @@
1
+ // src/function/debounce.ts
2
+ function debounce(func, debounceMs) {
3
+ let timeoutId = null;
4
+ const debounced = function(...args) {
5
+ if (timeoutId != null) {
6
+ clearTimeout(timeoutId);
7
+ }
8
+ timeoutId = setTimeout(() => {
9
+ func(...args);
10
+ }, debounceMs);
11
+ };
12
+ debounced.cancel = function() {
13
+ if (timeoutId != null) {
14
+ clearTimeout(timeoutId);
15
+ }
16
+ };
17
+ return debounced;
18
+ }
19
+
20
+ export {
21
+ debounce
22
+ };
23
+ //# sourceMappingURL=chunk-GELVVASW.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/function/debounce.ts"],"sourcesContent":["/**\n * Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds\n * have elapsed since the last time the debounced function was invoked. The debounced function also has a `cancel`\n * method to cancel any pending execution.\n *\n * @param {F} func - The function to debounce.\n * @param {number} debounceMs - The number of milliseconds to delay.\n * @returns {F & { cancel: () => void }} A new debounced function with a `cancel` method.\n *\n * @example\n * const debouncedFunction = debounce(() => {\n * console.log('Function executed');\n * }, 1000);\n *\n * // Will log 'Function executed' after 1 second if not called again in that time\n * debouncedFunction();\n *\n * // Will not log anything as the previous call is canceled\n * debouncedFunction.cancel();\n */\nexport function debounce<F extends (...args: any[]) => void>(func: F, debounceMs: number): F & { cancel: () => void } {\n let timeoutId: number | NodeJS.Timeout | null = null;\n\n const debounced = function (...args: Parameters<F>) {\n if (timeoutId != null) {\n clearTimeout(timeoutId);\n }\n\n timeoutId = setTimeout(() => {\n func(...args);\n }, debounceMs);\n } as F & { cancel: () => void };\n\n debounced.cancel = function () {\n if (timeoutId != null) {\n clearTimeout(timeoutId);\n }\n };\n\n return debounced;\n}\n"],"mappings":";AAoBO,SAAS,SAA6C,MAAS,YAAgD;AACpH,MAAI,YAA4C;AAEhD,QAAM,YAAY,YAAa,MAAqB;AAClD,QAAI,aAAa,MAAM;AACrB,mBAAa,SAAS;AAAA,IACxB;AAEA,gBAAY,WAAW,MAAM;AAC3B,WAAK,GAAG,IAAI;AAAA,IACd,GAAG,UAAU;AAAA,EACf;AAEA,YAAU,SAAS,WAAY;AAC7B,QAAI,aAAa,MAAM;AACrB,mBAAa,SAAS;AAAA,IACxB;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,13 @@
1
+ import {
2
+ uniqWith
3
+ } from "./chunk-NXPEUTDI.mjs";
4
+
5
+ // src/array/uniqBy.ts
6
+ function uniqBy(arr, converter) {
7
+ return uniqWith(arr, (item1, item2) => converter(item1) === converter(item2));
8
+ }
9
+
10
+ export {
11
+ uniqBy
12
+ };
13
+ //# sourceMappingURL=chunk-LCYPY5SA.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/array/uniqBy.ts"],"sourcesContent":["import { uniqWith } from './uniqWith';\n\n/**\n * The `uniqBy` function takes an array as its first argument and a 'converter' function as the second. It maps the array elements using the converter function, then removes any duplicates.\n *\n * It filters out elements with the same value, meaning it does not check for duplicates in data types like Objects.\n *\n * @param {T[]} arr - The array to process.\n * @param {(item: T) => U} converter - The function used to convert the array elements.\n * @returns {T[]} A new array containing only the unique elements from the original array, based on the values returned by the converter function.\n *\n * @example\n * ```ts\n * uniqBy([1.2, 1.5, 2.1, 3.2, 5.7, 5.3, 7.19], Math.floor);\n * // [1.2, 2.1, 3.3, 5.7, 7.19]\n * ```\n */\nexport function uniqBy<T, U>(arr: readonly T[], converter: (item: T) => U): T[] {\n return uniqWith(arr, (item1, item2) => converter(item1) === converter(item2));\n}\n"],"mappings":";;;;;AAiBO,SAAS,OAAa,KAAmB,WAAgC;AAC9E,SAAO,SAAS,KAAK,CAAC,OAAO,UAAU,UAAU,KAAK,MAAM,UAAU,KAAK,CAAC;AAC9E;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unionWith
3
- } from "./chunk-3KHI4I2X.mjs";
3
+ } from "./chunk-5P2QE2VI.mjs";
4
4
  import {
5
5
  intersectionWith
6
6
  } from "./chunk-KLJRZJOR.mjs";
@@ -18,4 +18,4 @@ function xorWith(arr1, arr2, areElementsEqual) {
18
18
  export {
19
19
  xorWith
20
20
  };
21
- //# sourceMappingURL=chunk-FCF2RHPW.mjs.map
21
+ //# sourceMappingURL=chunk-LVB7BYUY.mjs.map
@@ -13,4 +13,4 @@ function uniqWith(arr, areItemsEqual) {
13
13
  export {
14
14
  uniqWith
15
15
  };
16
- //# sourceMappingURL=chunk-2PFDLYQC.mjs.map
16
+ //# sourceMappingURL=chunk-NXPEUTDI.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/array/uniqWith.ts"],"sourcesContent":["/**\n * The `uniqWith` function takes an array as its first argument and a 'comparator' function as the second.\n *\n * It evaluates the elements of the array using the comparator function, and if true is returned, it considers those elements as duplicates and removes them.\n *\n * @param {T[]} arr - The array to process.\n * @param {(item1: T, item2: T) => boolean} areItemsEqual - The function used to compare the array elements.\n * @returns {T[]} A new array containing only the unique elements from the original array, based on the values returned by the comparator function.\n *\n * @example\n * ```ts\n * uniqWith([1.2, 1.5, 2.1, 3.2, 5.7, 5.3, 7.19], (a, b) => Math.abs(a - b) < 1);\n * // [1.2, 3.2, 5.7, 7.19]\n * ```\n */\nexport function uniqWith<T>(arr: readonly T[], areItemsEqual: (item1: T, item2: T) => boolean): T[] {\n const result: T[] = [];\n\n for (const item of arr) {\n const isUniq = result.every(v => !areItemsEqual(v, item));\n\n if (isUniq) {\n result.push(item);\n }\n }\n\n return result;\n}\n"],"mappings":";AAeO,SAAS,SAAY,KAAmB,eAAqD;AAClG,QAAM,SAAc,CAAC;AAErB,aAAW,QAAQ,KAAK;AACtB,UAAM,SAAS,OAAO,MAAM,OAAK,CAAC,cAAc,GAAG,IAAI,CAAC;AAExD,QAAI,QAAQ;AACV,aAAO,KAAK,IAAI;AAAA,IAClB;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -1,6 +1,3 @@
1
- interface DebounceOptions {
2
- signal?: AbortSignal;
3
- }
4
1
  /**
5
2
  * Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds
6
3
  * have elapsed since the last time the debounced function was invoked. The debounced function also has a `cancel`
@@ -8,8 +5,6 @@ interface DebounceOptions {
8
5
  *
9
6
  * @param {F} func - The function to debounce.
10
7
  * @param {number} debounceMs - The number of milliseconds to delay.
11
- * @param {DebounceOptions} options - The options object.
12
- * @param {AbortSignal} options.signal - An optional AbortSignal to cancel the debounced function.
13
8
  * @returns {F & { cancel: () => void }} A new debounced function with a `cancel` method.
14
9
  *
15
10
  * @example
@@ -22,20 +17,8 @@ interface DebounceOptions {
22
17
  *
23
18
  * // Will not log anything as the previous call is canceled
24
19
  * debouncedFunction.cancel();
25
- *
26
- * // With AbortSignal
27
- * const controller = new AbortController();
28
- * const signal = controller.signal;
29
- * const debouncedWithSignal = debounce(() => {
30
- * console.log('Function executed');
31
- * }, 1000, { signal });
32
- *
33
- * debouncedWithSignal();
34
- *
35
- * // Will cancel the debounced function call
36
- * controller.abort();
37
20
  */
38
- declare function debounce<F extends (...args: any[]) => void>(func: F, debounceMs: number, { signal }?: DebounceOptions): F & {
21
+ declare function debounce<F extends (...args: any[]) => void>(func: F, debounceMs: number): F & {
39
22
  cancel: () => void;
40
23
  };
41
24
 
@@ -1,6 +1,3 @@
1
- interface DebounceOptions {
2
- signal?: AbortSignal;
3
- }
4
1
  /**
5
2
  * Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds
6
3
  * have elapsed since the last time the debounced function was invoked. The debounced function also has a `cancel`
@@ -8,8 +5,6 @@ interface DebounceOptions {
8
5
  *
9
6
  * @param {F} func - The function to debounce.
10
7
  * @param {number} debounceMs - The number of milliseconds to delay.
11
- * @param {DebounceOptions} options - The options object.
12
- * @param {AbortSignal} options.signal - An optional AbortSignal to cancel the debounced function.
13
8
  * @returns {F & { cancel: () => void }} A new debounced function with a `cancel` method.
14
9
  *
15
10
  * @example
@@ -22,20 +17,8 @@ interface DebounceOptions {
22
17
  *
23
18
  * // Will not log anything as the previous call is canceled
24
19
  * debouncedFunction.cancel();
25
- *
26
- * // With AbortSignal
27
- * const controller = new AbortController();
28
- * const signal = controller.signal;
29
- * const debouncedWithSignal = debounce(() => {
30
- * console.log('Function executed');
31
- * }, 1000, { signal });
32
- *
33
- * debouncedWithSignal();
34
- *
35
- * // Will cancel the debounced function call
36
- * controller.abort();
37
20
  */
38
- declare function debounce<F extends (...args: any[]) => void>(func: F, debounceMs: number, { signal }?: DebounceOptions): F & {
21
+ declare function debounce<F extends (...args: any[]) => void>(func: F, debounceMs: number): F & {
39
22
  cancel: () => void;
40
23
  };
41
24
 
@@ -23,31 +23,21 @@ __export(debounce_exports, {
23
23
  debounce: () => debounce
24
24
  });
25
25
  module.exports = __toCommonJS(debounce_exports);
26
- function debounce(func, debounceMs, { signal } = {}) {
26
+ function debounce(func, debounceMs) {
27
27
  let timeoutId = null;
28
28
  const debounced = function(...args) {
29
- if (timeoutId !== null) {
29
+ if (timeoutId != null) {
30
30
  clearTimeout(timeoutId);
31
31
  }
32
- if (signal == null ? void 0 : signal.aborted) {
33
- return;
34
- }
35
32
  timeoutId = setTimeout(() => {
36
33
  func(...args);
37
- timeoutId = null;
38
34
  }, debounceMs);
39
35
  };
40
- const onAbort = function() {
41
- debounced.cancel();
42
- };
43
36
  debounced.cancel = function() {
44
- if (timeoutId !== null) {
37
+ if (timeoutId != null) {
45
38
  clearTimeout(timeoutId);
46
- timeoutId = null;
47
39
  }
48
- signal == null ? void 0 : signal.removeEventListener("abort", onAbort);
49
40
  };
50
- signal == null ? void 0 : signal.addEventListener("abort", onAbort);
51
41
  return debounced;
52
42
  }
53
43
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/function/debounce.ts"],"sourcesContent":["interface DebounceOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds\n * have elapsed since the last time the debounced function was invoked. The debounced function also has a `cancel`\n * method to cancel any pending execution.\n *\n * @param {F} func - The function to debounce.\n * @param {number} debounceMs - The number of milliseconds to delay.\n * @param {DebounceOptions} options - The options object.\n * @param {AbortSignal} options.signal - An optional AbortSignal to cancel the debounced function.\n * @returns {F & { cancel: () => void }} A new debounced function with a `cancel` method.\n *\n * @example\n * const debouncedFunction = debounce(() => {\n * console.log('Function executed');\n * }, 1000);\n *\n * // Will log 'Function executed' after 1 second if not called again in that time\n * debouncedFunction();\n *\n * // Will not log anything as the previous call is canceled\n * debouncedFunction.cancel();\n *\n * // With AbortSignal\n * const controller = new AbortController();\n * const signal = controller.signal;\n * const debouncedWithSignal = debounce(() => {\n * console.log('Function executed');\n * }, 1000, { signal });\n *\n * debouncedWithSignal();\n *\n * // Will cancel the debounced function call\n * controller.abort();\n */\nexport function debounce<F extends (...args: any[]) => void>(\n func: F,\n debounceMs: number,\n { signal }: DebounceOptions = {}\n): F & { cancel: () => void } {\n let timeoutId: number | NodeJS.Timeout | null = null;\n\n const debounced = function (...args: Parameters<F>) {\n if (timeoutId !== null) {\n clearTimeout(timeoutId);\n }\n\n if (signal?.aborted) {\n return;\n }\n\n timeoutId = setTimeout(() => {\n func(...args);\n timeoutId = null;\n }, debounceMs);\n } as F & { cancel: () => void };\n\n const onAbort = function () {\n debounced.cancel();\n };\n\n debounced.cancel = function () {\n if (timeoutId !== null) {\n clearTimeout(timeoutId);\n timeoutId = null;\n }\n\n signal?.removeEventListener('abort', onAbort);\n };\n\n signal?.addEventListener('abort', onAbort);\n\n return debounced;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAsCO,SAAS,SACd,MACA,YACA,EAAE,OAAO,IAAqB,CAAC,GACH;AAC5B,MAAI,YAA4C;AAEhD,QAAM,YAAY,YAAa,MAAqB;AAClD,QAAI,cAAc,MAAM;AACtB,mBAAa,SAAS;AAAA,IACxB;AAEA,QAAI,iCAAQ,SAAS;AACnB;AAAA,IACF;AAEA,gBAAY,WAAW,MAAM;AAC3B,WAAK,GAAG,IAAI;AACZ,kBAAY;AAAA,IACd,GAAG,UAAU;AAAA,EACf;AAEA,QAAM,UAAU,WAAY;AAC1B,cAAU,OAAO;AAAA,EACnB;AAEA,YAAU,SAAS,WAAY;AAC7B,QAAI,cAAc,MAAM;AACtB,mBAAa,SAAS;AACtB,kBAAY;AAAA,IACd;AAEA,qCAAQ,oBAAoB,SAAS;AAAA,EACvC;AAEA,mCAAQ,iBAAiB,SAAS;AAElC,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/function/debounce.ts"],"sourcesContent":["/**\n * Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds\n * have elapsed since the last time the debounced function was invoked. The debounced function also has a `cancel`\n * method to cancel any pending execution.\n *\n * @param {F} func - The function to debounce.\n * @param {number} debounceMs - The number of milliseconds to delay.\n * @returns {F & { cancel: () => void }} A new debounced function with a `cancel` method.\n *\n * @example\n * const debouncedFunction = debounce(() => {\n * console.log('Function executed');\n * }, 1000);\n *\n * // Will log 'Function executed' after 1 second if not called again in that time\n * debouncedFunction();\n *\n * // Will not log anything as the previous call is canceled\n * debouncedFunction.cancel();\n */\nexport function debounce<F extends (...args: any[]) => void>(func: F, debounceMs: number): F & { cancel: () => void } {\n let timeoutId: number | NodeJS.Timeout | null = null;\n\n const debounced = function (...args: Parameters<F>) {\n if (timeoutId != null) {\n clearTimeout(timeoutId);\n }\n\n timeoutId = setTimeout(() => {\n func(...args);\n }, debounceMs);\n } as F & { cancel: () => void };\n\n debounced.cancel = function () {\n if (timeoutId != null) {\n clearTimeout(timeoutId);\n }\n };\n\n return debounced;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoBO,SAAS,SAA6C,MAAS,YAAgD;AACpH,MAAI,YAA4C;AAEhD,QAAM,YAAY,YAAa,MAAqB;AAClD,QAAI,aAAa,MAAM;AACrB,mBAAa,SAAS;AAAA,IACxB;AAEA,gBAAY,WAAW,MAAM;AAC3B,WAAK,GAAG,IAAI;AAAA,IACd,GAAG,UAAU;AAAA,EACf;AAEA,YAAU,SAAS,WAAY;AAC7B,QAAI,aAAa,MAAM;AACrB,mBAAa,SAAS;AAAA,IACxB;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  debounce
3
- } from "../chunk-GOXQV6DX.mjs";
3
+ } from "../chunk-GELVVASW.mjs";
4
4
  import "../chunk-2MM5EJJX.mjs";
5
5
  export {
6
6
  debounce
@@ -28,31 +28,21 @@ __export(function_exports, {
28
28
  module.exports = __toCommonJS(function_exports);
29
29
 
30
30
  // src/function/debounce.ts
31
- function debounce(func, debounceMs, { signal } = {}) {
31
+ function debounce(func, debounceMs) {
32
32
  let timeoutId = null;
33
33
  const debounced = function(...args) {
34
- if (timeoutId !== null) {
34
+ if (timeoutId != null) {
35
35
  clearTimeout(timeoutId);
36
36
  }
37
- if (signal == null ? void 0 : signal.aborted) {
38
- return;
39
- }
40
37
  timeoutId = setTimeout(() => {
41
38
  func(...args);
42
- timeoutId = null;
43
39
  }, debounceMs);
44
40
  };
45
- const onAbort = function() {
46
- debounced.cancel();
47
- };
48
41
  debounced.cancel = function() {
49
- if (timeoutId !== null) {
42
+ if (timeoutId != null) {
50
43
  clearTimeout(timeoutId);
51
- timeoutId = null;
52
44
  }
53
- signal == null ? void 0 : signal.removeEventListener("abort", onAbort);
54
45
  };
55
- signal == null ? void 0 : signal.addEventListener("abort", onAbort);
56
46
  return debounced;
57
47
  }
58
48
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/function/index.ts","../../src/function/debounce.ts","../../src/function/noop.ts","../../src/function/once.ts","../../src/function/throttle.ts"],"sourcesContent":["export { debounce } from './debounce';\nexport { noop } from './noop';\nexport { once } from './once';\nexport { throttle } from './throttle';\n","interface DebounceOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds\n * have elapsed since the last time the debounced function was invoked. The debounced function also has a `cancel`\n * method to cancel any pending execution.\n *\n * @param {F} func - The function to debounce.\n * @param {number} debounceMs - The number of milliseconds to delay.\n * @param {DebounceOptions} options - The options object.\n * @param {AbortSignal} options.signal - An optional AbortSignal to cancel the debounced function.\n * @returns {F & { cancel: () => void }} A new debounced function with a `cancel` method.\n *\n * @example\n * const debouncedFunction = debounce(() => {\n * console.log('Function executed');\n * }, 1000);\n *\n * // Will log 'Function executed' after 1 second if not called again in that time\n * debouncedFunction();\n *\n * // Will not log anything as the previous call is canceled\n * debouncedFunction.cancel();\n *\n * // With AbortSignal\n * const controller = new AbortController();\n * const signal = controller.signal;\n * const debouncedWithSignal = debounce(() => {\n * console.log('Function executed');\n * }, 1000, { signal });\n *\n * debouncedWithSignal();\n *\n * // Will cancel the debounced function call\n * controller.abort();\n */\nexport function debounce<F extends (...args: any[]) => void>(\n func: F,\n debounceMs: number,\n { signal }: DebounceOptions = {}\n): F & { cancel: () => void } {\n let timeoutId: number | NodeJS.Timeout | null = null;\n\n const debounced = function (...args: Parameters<F>) {\n if (timeoutId !== null) {\n clearTimeout(timeoutId);\n }\n\n if (signal?.aborted) {\n return;\n }\n\n timeoutId = setTimeout(() => {\n func(...args);\n timeoutId = null;\n }, debounceMs);\n } as F & { cancel: () => void };\n\n const onAbort = function () {\n debounced.cancel();\n };\n\n debounced.cancel = function () {\n if (timeoutId !== null) {\n clearTimeout(timeoutId);\n timeoutId = null;\n }\n\n signal?.removeEventListener('abort', onAbort);\n };\n\n signal?.addEventListener('abort', onAbort);\n\n return debounced;\n}\n","/**\n * A no-operation function that does nothing.\n * This can be used as a placeholder or default function.\n *\n * @example\n * noop(); // Does nothing\n *\n * @returns {void} This function does not return anything.\n */\nexport function noop(): void {}\n","/**\n * Creates a function that is restricted to invoking the provided function `func` once.\n * Repeated calls to the function will return the value from the first invocation.\n *\n * @param {F} func - The function to restrict.\n * @returns {F} A new function that invokes `func` once and caches the result.\n *\n * @example\n * const initialize = once(() => {\n * console.log('Initialized!');\n * return true;\n * });\n *\n * initialize(); // Logs: 'Initialized!' and returns true\n * initialize(); // Returns true without logging\n */\nexport function once<F extends () => any>(func: F): F {\n let called = false;\n let cache: ReturnType<F> | undefined;\n\n return function () {\n if (called) {\n return cache;\n }\n\n const result = func();\n\n called = true;\n cache = result;\n\n return result;\n } as F;\n}\n","/**\n * Creates a throttled function that only invokes the provided function at most once\n * per every `throttleMs` milliseconds. Subsequent calls to the throttled function\n * within the wait time will not trigger the execution of the original function.\n *\n * @param {F} func - The function to throttle.\n * @param {number} throttleMs - The number of milliseconds to throttle executions to.\n * @returns {F} A new throttled function that accepts the same parameters as the original function.\n *\n * @example\n * const throttledFunction = throttle(() => {\n * console.log('Function executed');\n * }, 1000);\n *\n * // Will log 'Function executed' immediately\n * throttledFunction();\n *\n * // Will not log anything as it is within the throttle time\n * throttledFunction();\n *\n * // After 1 second\n * setTimeout(() => {\n * throttledFunction(); // Will log 'Function executed'\n * }, 1000);\n */\nexport function throttle<F extends (...args: any[]) => void>(func: F, throttleMs: number) {\n let lastCallTime: number | null;\n\n const throttledFunction = function (...args: Parameters<F>) {\n const now = Date.now();\n\n if (lastCallTime == null || now - lastCallTime >= throttleMs) {\n lastCallTime = now;\n func(...args);\n }\n } as F;\n\n return throttledFunction;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACsCO,SAAS,SACd,MACA,YACA,EAAE,OAAO,IAAqB,CAAC,GACH;AAC5B,MAAI,YAA4C;AAEhD,QAAM,YAAY,YAAa,MAAqB;AAClD,QAAI,cAAc,MAAM;AACtB,mBAAa,SAAS;AAAA,IACxB;AAEA,QAAI,iCAAQ,SAAS;AACnB;AAAA,IACF;AAEA,gBAAY,WAAW,MAAM;AAC3B,WAAK,GAAG,IAAI;AACZ,kBAAY;AAAA,IACd,GAAG,UAAU;AAAA,EACf;AAEA,QAAM,UAAU,WAAY;AAC1B,cAAU,OAAO;AAAA,EACnB;AAEA,YAAU,SAAS,WAAY;AAC7B,QAAI,cAAc,MAAM;AACtB,mBAAa,SAAS;AACtB,kBAAY;AAAA,IACd;AAEA,qCAAQ,oBAAoB,SAAS;AAAA,EACvC;AAEA,mCAAQ,iBAAiB,SAAS;AAElC,SAAO;AACT;;;ACnEO,SAAS,OAAa;AAAC;;;ACOvB,SAAS,KAA0B,MAAY;AACpD,MAAI,SAAS;AACb,MAAI;AAEJ,SAAO,WAAY;AACjB,QAAI,QAAQ;AACV,aAAO;AAAA,IACT;AAEA,UAAM,SAAS,KAAK;AAEpB,aAAS;AACT,YAAQ;AAER,WAAO;AAAA,EACT;AACF;;;ACPO,SAAS,SAA6C,MAAS,YAAoB;AACxF,MAAI;AAEJ,QAAM,oBAAoB,YAAa,MAAqB;AAC1D,UAAM,MAAM,KAAK,IAAI;AAErB,QAAI,gBAAgB,QAAQ,MAAM,gBAAgB,YAAY;AAC5D,qBAAe;AACf,WAAK,GAAG,IAAI;AAAA,IACd;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/function/index.ts","../../src/function/debounce.ts","../../src/function/noop.ts","../../src/function/once.ts","../../src/function/throttle.ts"],"sourcesContent":["export { debounce } from './debounce';\nexport { noop } from './noop';\nexport { once } from './once';\nexport { throttle } from './throttle';\n","/**\n * Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds\n * have elapsed since the last time the debounced function was invoked. The debounced function also has a `cancel`\n * method to cancel any pending execution.\n *\n * @param {F} func - The function to debounce.\n * @param {number} debounceMs - The number of milliseconds to delay.\n * @returns {F & { cancel: () => void }} A new debounced function with a `cancel` method.\n *\n * @example\n * const debouncedFunction = debounce(() => {\n * console.log('Function executed');\n * }, 1000);\n *\n * // Will log 'Function executed' after 1 second if not called again in that time\n * debouncedFunction();\n *\n * // Will not log anything as the previous call is canceled\n * debouncedFunction.cancel();\n */\nexport function debounce<F extends (...args: any[]) => void>(func: F, debounceMs: number): F & { cancel: () => void } {\n let timeoutId: number | NodeJS.Timeout | null = null;\n\n const debounced = function (...args: Parameters<F>) {\n if (timeoutId != null) {\n clearTimeout(timeoutId);\n }\n\n timeoutId = setTimeout(() => {\n func(...args);\n }, debounceMs);\n } as F & { cancel: () => void };\n\n debounced.cancel = function () {\n if (timeoutId != null) {\n clearTimeout(timeoutId);\n }\n };\n\n return debounced;\n}\n","/**\n * A no-operation function that does nothing.\n * This can be used as a placeholder or default function.\n *\n * @example\n * noop(); // Does nothing\n *\n * @returns {void} This function does not return anything.\n */\nexport function noop(): void {}\n","/**\n * Creates a function that is restricted to invoking the provided function `func` once.\n * Repeated calls to the function will return the value from the first invocation.\n *\n * @param {F} func - The function to restrict.\n * @returns {F} A new function that invokes `func` once and caches the result.\n *\n * @example\n * const initialize = once(() => {\n * console.log('Initialized!');\n * return true;\n * });\n *\n * initialize(); // Logs: 'Initialized!' and returns true\n * initialize(); // Returns true without logging\n */\nexport function once<F extends () => any>(func: F): F {\n let called = false;\n let cache: ReturnType<F> | undefined;\n\n return function () {\n if (called) {\n return cache;\n }\n\n const result = func();\n\n called = true;\n cache = result;\n\n return result;\n } as F;\n}\n","/**\n * Creates a throttled function that only invokes the provided function at most once\n * per every `throttleMs` milliseconds. Subsequent calls to the throttled function\n * within the wait time will not trigger the execution of the original function.\n *\n * @param {F} func - The function to throttle.\n * @param {number} throttleMs - The number of milliseconds to throttle executions to.\n * @returns {F} A new throttled function that accepts the same parameters as the original function.\n *\n * @example\n * const throttledFunction = throttle(() => {\n * console.log('Function executed');\n * }, 1000);\n *\n * // Will log 'Function executed' immediately\n * throttledFunction();\n *\n * // Will not log anything as it is within the throttle time\n * throttledFunction();\n *\n * // After 1 second\n * setTimeout(() => {\n * throttledFunction(); // Will log 'Function executed'\n * }, 1000);\n */\nexport function throttle<F extends (...args: any[]) => void>(func: F, throttleMs: number) {\n let lastCallTime: number | null;\n\n const throttledFunction = function (...args: Parameters<F>) {\n const now = Date.now();\n\n if (lastCallTime == null || now - lastCallTime >= throttleMs) {\n lastCallTime = now;\n func(...args);\n }\n } as F;\n\n return throttledFunction;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACoBO,SAAS,SAA6C,MAAS,YAAgD;AACpH,MAAI,YAA4C;AAEhD,QAAM,YAAY,YAAa,MAAqB;AAClD,QAAI,aAAa,MAAM;AACrB,mBAAa,SAAS;AAAA,IACxB;AAEA,gBAAY,WAAW,MAAM;AAC3B,WAAK,GAAG,IAAI;AAAA,IACd,GAAG,UAAU;AAAA,EACf;AAEA,YAAU,SAAS,WAAY;AAC7B,QAAI,aAAa,MAAM;AACrB,mBAAa,SAAS;AAAA,IACxB;AAAA,EACF;AAEA,SAAO;AACT;;;AC/BO,SAAS,OAAa;AAAC;;;ACOvB,SAAS,KAA0B,MAAY;AACpD,MAAI,SAAS;AACb,MAAI;AAEJ,SAAO,WAAY;AACjB,QAAI,QAAQ;AACV,aAAO;AAAA,IACT;AAEA,UAAM,SAAS,KAAK;AAEpB,aAAS;AACT,YAAQ;AAER,WAAO;AAAA,EACT;AACF;;;ACPO,SAAS,SAA6C,MAAS,YAAoB;AACxF,MAAI;AAEJ,QAAM,oBAAoB,YAAa,MAAqB;AAC1D,UAAM,MAAM,KAAK,IAAI;AAErB,QAAI,gBAAgB,QAAQ,MAAM,gBAAgB,YAAY;AAC5D,qBAAe;AACf,WAAK,GAAG,IAAI;AAAA,IACd;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -1,16 +1,16 @@
1
1
  import "../chunk-N6EM6ETS.mjs";
2
- import {
3
- throttle
4
- } from "../chunk-XLO3QZVY.mjs";
5
2
  import {
6
3
  debounce
7
- } from "../chunk-GOXQV6DX.mjs";
4
+ } from "../chunk-GELVVASW.mjs";
8
5
  import {
9
6
  noop
10
7
  } from "../chunk-LKXCOLNY.mjs";
11
8
  import {
12
9
  once
13
10
  } from "../chunk-UFAA5WKR.mjs";
11
+ import {
12
+ throttle
13
+ } from "../chunk-XLO3QZVY.mjs";
14
14
  import "../chunk-2MM5EJJX.mjs";
15
15
  export {
16
16
  debounce,
package/dist/index.js CHANGED
@@ -159,9 +159,8 @@ function groupBy(arr, getKeyFromItem) {
159
159
 
160
160
  // src/array/intersection.ts
161
161
  function intersection(firstArr, secondArr) {
162
- const secondSet = new Set(secondArr);
163
162
  return firstArr.filter((item) => {
164
- return secondSet.has(item);
163
+ return secondArr.includes(item);
165
164
  });
166
165
  }
167
166
 
@@ -285,8 +284,8 @@ function unionWith(arr1, arr2, areItemsEqual) {
285
284
  }
286
285
 
287
286
  // src/array/uniqBy.ts
288
- function uniqBy(arr, mapper) {
289
- return uniqWith(arr, (item1, item2) => mapper(item1) === mapper(item2));
287
+ function uniqBy(arr, converter) {
288
+ return uniqWith(arr, (item1, item2) => converter(item1) === converter(item2));
290
289
  }
291
290
 
292
291
  // src/array/xor.ts
@@ -336,31 +335,21 @@ function zipWith(arr1, ...rest) {
336
335
  }
337
336
 
338
337
  // src/function/debounce.ts
339
- function debounce(func, debounceMs, { signal } = {}) {
338
+ function debounce(func, debounceMs) {
340
339
  let timeoutId = null;
341
340
  const debounced = function(...args) {
342
- if (timeoutId !== null) {
341
+ if (timeoutId != null) {
343
342
  clearTimeout(timeoutId);
344
343
  }
345
- if (signal == null ? void 0 : signal.aborted) {
346
- return;
347
- }
348
344
  timeoutId = setTimeout(() => {
349
345
  func(...args);
350
- timeoutId = null;
351
346
  }, debounceMs);
352
347
  };
353
- const onAbort = function() {
354
- debounced.cancel();
355
- };
356
348
  debounced.cancel = function() {
357
- if (timeoutId !== null) {
349
+ if (timeoutId != null) {
358
350
  clearTimeout(timeoutId);
359
- timeoutId = null;
360
351
  }
361
- signal == null ? void 0 : signal.removeEventListener("abort", onAbort);
362
352
  };
363
- signal == null ? void 0 : signal.addEventListener("abort", onAbort);
364
353
  return debounced;
365
354
  }
366
355