es-toolkit 1.1.0 → 1.2.0-dev.49

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 (61) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/array/difference.d.mts +1 -1
  3. package/dist/array/difference.d.ts +1 -1
  4. package/dist/array/difference.js +2 -3
  5. package/dist/array/difference.js.map +1 -1
  6. package/dist/array/difference.mjs +1 -1
  7. package/dist/array/differenceBy.d.mts +1 -1
  8. package/dist/array/differenceBy.d.ts +1 -1
  9. package/dist/array/differenceBy.js +2 -2
  10. package/dist/array/differenceBy.js.map +1 -1
  11. package/dist/array/differenceBy.mjs +1 -1
  12. package/dist/array/index.js +8 -8
  13. package/dist/array/index.js.map +1 -1
  14. package/dist/array/index.mjs +25 -25
  15. package/dist/array/shuffle.js +4 -3
  16. package/dist/array/shuffle.js.map +1 -1
  17. package/dist/array/shuffle.mjs +1 -1
  18. package/dist/array/xor.js +2 -3
  19. package/dist/array/xor.js.map +1 -1
  20. package/dist/array/xor.mjs +2 -2
  21. package/dist/array/xorBy.js +2 -2
  22. package/dist/array/xorBy.js.map +1 -1
  23. package/dist/array/xorBy.mjs +2 -2
  24. package/dist/{chunk-TULUUJ3E.mjs → chunk-4PNP6CKQ.mjs} +2 -2
  25. package/dist/chunk-HK5OJANS.mjs +12 -0
  26. package/dist/{chunk-PUQLVKMB.mjs.map → chunk-HK5OJANS.mjs.map} +1 -1
  27. package/dist/chunk-KPG3XQEN.mjs +14 -0
  28. package/dist/chunk-KPG3XQEN.mjs.map +1 -0
  29. package/dist/chunk-LKXCOLNY.mjs +8 -0
  30. package/dist/chunk-LKXCOLNY.mjs.map +1 -0
  31. package/dist/chunk-N6EM6ETS.mjs +1 -0
  32. package/dist/chunk-SORNYLIU.mjs +10 -0
  33. package/dist/{chunk-2PB2OCC6.mjs.map → chunk-SORNYLIU.mjs.map} +1 -1
  34. package/dist/{chunk-QC3SFAQJ.mjs → chunk-VKVA56XG.mjs} +2 -2
  35. package/dist/function/index.d.mts +1 -0
  36. package/dist/function/index.d.ts +1 -0
  37. package/dist/function/index.js +6 -0
  38. package/dist/function/index.js.map +1 -1
  39. package/dist/function/index.mjs +5 -1
  40. package/dist/function/noop.d.mts +12 -0
  41. package/dist/function/noop.d.ts +12 -0
  42. package/dist/function/noop.js +32 -0
  43. package/dist/function/noop.js.map +1 -0
  44. package/dist/function/noop.mjs +8 -0
  45. package/dist/function/noop.mjs.map +1 -0
  46. package/dist/index.d.mts +1 -0
  47. package/dist/index.d.ts +1 -0
  48. package/dist/index.js +14 -8
  49. package/dist/index.js.map +1 -1
  50. package/dist/index.mjs +45 -41
  51. package/dist/math/index.mjs +3 -3
  52. package/dist/predicate/index.mjs +3 -3
  53. package/package.json +1 -1
  54. package/dist/chunk-23DC774L.mjs +0 -13
  55. package/dist/chunk-23DC774L.mjs.map +0 -1
  56. package/dist/chunk-2PB2OCC6.mjs +0 -11
  57. package/dist/chunk-PUQLVKMB.mjs +0 -12
  58. package/dist/chunk-SYQTG4N4.mjs +0 -1
  59. /package/dist/{chunk-TULUUJ3E.mjs.map → chunk-4PNP6CKQ.mjs.map} +0 -0
  60. /package/dist/{chunk-SYQTG4N4.mjs.map → chunk-N6EM6ETS.mjs.map} +0 -0
  61. /package/dist/{chunk-QC3SFAQJ.mjs.map → chunk-VKVA56XG.mjs.map} +0 -0
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  xorBy
3
- } from "../chunk-TULUUJ3E.mjs";
3
+ } from "../chunk-4PNP6CKQ.mjs";
4
4
  import "../chunk-SPLO5OZW.mjs";
5
5
  import "../chunk-ANJSX6WH.mjs";
6
- import "../chunk-PUQLVKMB.mjs";
6
+ import "../chunk-HK5OJANS.mjs";
7
7
  import "../chunk-2MM5EJJX.mjs";
8
8
  export {
9
9
  xorBy
@@ -6,7 +6,7 @@ import {
6
6
  } from "./chunk-ANJSX6WH.mjs";
7
7
  import {
8
8
  differenceBy
9
- } from "./chunk-PUQLVKMB.mjs";
9
+ } from "./chunk-HK5OJANS.mjs";
10
10
 
11
11
  // src/array/xorBy.ts
12
12
  function xorBy(arr1, arr2, mapper) {
@@ -18,4 +18,4 @@ function xorBy(arr1, arr2, mapper) {
18
18
  export {
19
19
  xorBy
20
20
  };
21
- //# sourceMappingURL=chunk-TULUUJ3E.mjs.map
21
+ //# sourceMappingURL=chunk-4PNP6CKQ.mjs.map
@@ -0,0 +1,12 @@
1
+ // src/array/differenceBy.ts
2
+ function differenceBy(firstArr, secondArr, mapper) {
3
+ const mappedSecondSet = new Set(secondArr.map((item) => mapper(item)));
4
+ return firstArr.filter((item) => {
5
+ return !mappedSecondSet.has(mapper(item));
6
+ });
7
+ }
8
+
9
+ export {
10
+ differenceBy
11
+ };
12
+ //# sourceMappingURL=chunk-HK5OJANS.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/array/differenceBy.ts"],"sourcesContent":["/**\n * Computes the difference between two arrays after mapping their elements through a provided function.\n *\n * This function takes two arrays and a mapper function. It returns a new array containing the elements\n * that are present in the first array but not in the second array, based on the identity calculated\n * by the mapper function.\n *\n * Essentially, it filters out any elements from the first array that, when\n * mapped, match an element in the mapped version of the second array.\n *\n * @template T, U\n * @param {T[]} firstArr - The primary array from which to derive the difference.\n * @param {T[]} secondArr - The array containing elements to be excluded from the first array.\n * @param {(value: T) => U} mapper - The function to map the elements of both arrays. This function\n * is applied to each element in both arrays, and the comparison is made based on the mapped values.\n * @returns {T[]} A new array containing the elements from the first array that do not have a corresponding\n * mapped identity in the second array.\n *\n * @example\n * * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];\n * const array2 = [{ id: 2 }, { id: 4 }];\n * const mapper = item => item.id;\n * const result = differenceBy(array1, array2, mapper);\n * // result will be [{ id: 1 }, { id: 3 }] since the elements with id 2 are in both arrays and are excluded from the result.\n */\nexport function differenceBy<T, U>(firstArr: T[], secondArr: T[], mapper: (value: T) => U): T[] {\n const mappedSecondArr = secondArr.map(item => mapper(item));\n\n return firstArr.filter(item => {\n return !mappedSecondArr.includes(mapper(item));\n });\n}\n"],"mappings":";AAyBO,SAAS,aAAmB,UAAe,WAAgB,QAA8B;AAC9F,QAAM,kBAAkB,UAAU,IAAI,UAAQ,OAAO,IAAI,CAAC;AAE1D,SAAO,SAAS,OAAO,UAAQ;AAC7B,WAAO,CAAC,gBAAgB,SAAS,OAAO,IAAI,CAAC;AAAA,EAC/C,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../src/array/differenceBy.ts"],"sourcesContent":["/**\n * Computes the difference between two arrays after mapping their elements through a provided function.\n *\n * This function takes two arrays and a mapper function. It returns a new array containing the elements\n * that are present in the first array but not in the second array, based on the identity calculated\n * by the mapper function.\n *\n * Essentially, it filters out any elements from the first array that, when\n * mapped, match an element in the mapped version of the second array.\n *\n * @template T, U\n * @param {T[]} firstArr - The primary array from which to derive the difference.\n * @param {T[]} secondArr - The array containing elements to be excluded from the first array.\n * @param {(value: T) => U} mapper - The function to map the elements of both arrays. This function\n * is applied to each element in both arrays, and the comparison is made based on the mapped values.\n * @returns {T[]} A new array containing the elements from the first array that do not have a corresponding\n * mapped identity in the second array.\n *\n * @example\n * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];\n * const array2 = [{ id: 2 }, { id: 4 }];\n * const mapper = item => item.id;\n * const result = differenceBy(array1, array2, mapper);\n * // result will be [{ id: 1 }, { id: 3 }] since the elements with id 2 are in both arrays and are excluded from the result.\n */\nexport function differenceBy<T, U>(firstArr: T[], secondArr: T[], mapper: (value: T) => U): T[] {\n const mappedSecondSet = new Set(secondArr.map(item => mapper(item)));\n\n return firstArr.filter(item => {\n return !mappedSecondSet.has(mapper(item));\n });\n}\n"],"mappings":";AAyBO,SAAS,aAAmB,UAAe,WAAgB,QAA8B;AAC9F,QAAM,kBAAkB,IAAI,IAAI,UAAU,IAAI,UAAQ,OAAO,IAAI,CAAC,CAAC;AAEnE,SAAO,SAAS,OAAO,UAAQ;AAC7B,WAAO,CAAC,gBAAgB,IAAI,OAAO,IAAI,CAAC;AAAA,EAC1C,CAAC;AACH;","names":[]}
@@ -0,0 +1,14 @@
1
+ // src/array/shuffle.ts
2
+ function shuffle(arr) {
3
+ const result = arr.slice();
4
+ for (let i = result.length - 1; i >= 1; i--) {
5
+ const j = Math.floor(Math.random() * (i + 1));
6
+ [result[i], result[j]] = [result[j], result[i]];
7
+ }
8
+ return result;
9
+ }
10
+
11
+ export {
12
+ shuffle
13
+ };
14
+ //# sourceMappingURL=chunk-KPG3XQEN.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/array/shuffle.ts"],"sourcesContent":["/**\n * Randomizes the order of elements in an array using the Fisher-Yates algorithm.\n *\n * This function takes an array and returns a new array with its elements shuffled in a random order.\n *\n * @param {T[]} arr - The array to shuffle.\n * @returns {T[]} A new array with its elements shuffled in random order.\n *\n * @example\n * const array = [1, 2, 3, 4, 5];\n * const shuffledArray = shuffle(array);\n * // shuffledArray will be a new array with elements of array in random order, e.g., [3, 1, 4, 5, 2]\n */\nexport function shuffle<T>(arr: T[]): T[] {\n const result = arr.slice();\n\n /**\n * https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm\n */\n for (let i = result.length - 1; i >= 1; i--) {\n const j = Math.floor(Math.random() * (i + 1));\n [result[i], result[j]] = [result[j], result[i]];\n }\n\n return result;\n}\n"],"mappings":";AAaO,SAAS,QAAW,KAAe;AACxC,QAAM,SAAS,IAAI,MAAM;AAKzB,WAAS,IAAI,OAAO,SAAS,GAAG,KAAK,GAAG,KAAK;AAC3C,UAAM,IAAI,KAAK,MAAM,KAAK,OAAO,KAAK,IAAI,EAAE;AAC5C,KAAC,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC;AAAA,EAChD;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,8 @@
1
+ // src/function/noop.ts
2
+ function noop() {
3
+ }
4
+
5
+ export {
6
+ noop
7
+ };
8
+ //# sourceMappingURL=chunk-LKXCOLNY.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/function/noop.ts"],"sourcesContent":["/**\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"],"mappings":";AASO,SAAS,OAAa;AAAC;","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-N6EM6ETS.mjs.map
@@ -0,0 +1,10 @@
1
+ // src/array/difference.ts
2
+ function difference(firstArr, secondArr) {
3
+ const secondSet = new Set(secondArr);
4
+ return firstArr.filter((item) => !secondSet.has(item));
5
+ }
6
+
7
+ export {
8
+ difference
9
+ };
10
+ //# sourceMappingURL=chunk-SORNYLIU.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/array/difference.ts"],"sourcesContent":["/**\n * Computes the difference between two arrays.\n *\n * This function takes two arrays and returns a new array containing the elements\n * that are present in the first array but not in the second array. It effectively\n * filters out any elements from the first array that also appear in the second array.\n *\n * @template T\n * @param {T[]} firstArr - The array from which to derive the difference. This is the primary array\n * from which elements will be compared and filtered.\n * @param {T[]} secondArr - The array containing elements to be excluded from the first array.\n * Each element in this array will be checked against the first array, and if a match is found,\n * that element will be excluded from the result.\n * @returns {T[]} A new array containing the elements that are present in the first array but not\n * in the second array.\n *\n * @example\n * * const array1 = [1, 2, 3, 4, 5];\n * const array2 = [2, 4];\n * const result = difference(array1, array2);\n * // result will be [1, 3, 5] since 2 and 4 are in both arrays and are excluded from the result.\n */\nexport function difference<T>(firstArr: T[], secondArr: T[]): T[] {\n return firstArr.filter(item => {\n return !secondArr.includes(item);\n });\n}\n"],"mappings":";AAsBO,SAAS,WAAc,UAAe,WAAqB;AAChE,SAAO,SAAS,OAAO,UAAQ;AAC7B,WAAO,CAAC,UAAU,SAAS,IAAI;AAAA,EACjC,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../src/array/difference.ts"],"sourcesContent":["/**\n * Computes the difference between two arrays.\n *\n * This function takes two arrays and returns a new array containing the elements\n * that are present in the first array but not in the second array. It effectively\n * filters out any elements from the first array that also appear in the second array.\n *\n * @template T\n * @param {T[]} firstArr - The array from which to derive the difference. This is the primary array\n * from which elements will be compared and filtered.\n * @param {T[]} secondArr - The array containing elements to be excluded from the first array.\n * Each element in this array will be checked against the first array, and if a match is found,\n * that element will be excluded from the result.\n * @returns {T[]} A new array containing the elements that are present in the first array but not\n * in the second array.\n *\n * @example\n * const array1 = [1, 2, 3, 4, 5];\n * const array2 = [2, 4];\n * const result = difference(array1, array2);\n * // result will be [1, 3, 5] since 2 and 4 are in both arrays and are excluded from the result.\n */\nexport function difference<T>(firstArr: T[], secondArr: T[]): T[] {\n const secondSet = new Set(secondArr);\n\n return firstArr.filter(item => !secondSet.has(item));\n}\n"],"mappings":";AAsBO,SAAS,WAAc,UAAe,WAAqB;AAChE,QAAM,YAAY,IAAI,IAAI,SAAS;AAEnC,SAAO,SAAS,OAAO,UAAQ,CAAC,UAAU,IAAI,IAAI,CAAC;AACrD;","names":[]}
@@ -6,7 +6,7 @@ import {
6
6
  } from "./chunk-YNRYG5OB.mjs";
7
7
  import {
8
8
  difference
9
- } from "./chunk-2PB2OCC6.mjs";
9
+ } from "./chunk-SORNYLIU.mjs";
10
10
 
11
11
  // src/array/xor.ts
12
12
  function xor(arr1, arr2) {
@@ -16,4 +16,4 @@ function xor(arr1, arr2) {
16
16
  export {
17
17
  xor
18
18
  };
19
- //# sourceMappingURL=chunk-QC3SFAQJ.mjs.map
19
+ //# sourceMappingURL=chunk-VKVA56XG.mjs.map
@@ -1,3 +1,4 @@
1
1
  export { debounce } from './debounce.mjs';
2
+ export { noop } from './noop.mjs';
2
3
  export { once } from './once.mjs';
3
4
  export { throttle } from './throttle.mjs';
@@ -1,3 +1,4 @@
1
1
  export { debounce } from './debounce.js';
2
+ export { noop } from './noop.js';
2
3
  export { once } from './once.js';
3
4
  export { throttle } from './throttle.js';
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var function_exports = {};
22
22
  __export(function_exports, {
23
23
  debounce: () => debounce,
24
+ noop: () => noop,
24
25
  once: () => once,
25
26
  throttle: () => throttle
26
27
  });
@@ -45,6 +46,10 @@ function debounce(func, debounceMs) {
45
46
  return debounced;
46
47
  }
47
48
 
49
+ // src/function/noop.ts
50
+ function noop() {
51
+ }
52
+
48
53
  // src/function/once.ts
49
54
  function once(func) {
50
55
  let called = false;
@@ -75,6 +80,7 @@ function throttle(func, throttleMs) {
75
80
  // Annotate the CommonJS export names for ESM import in node:
76
81
  0 && (module.exports = {
77
82
  debounce,
83
+ noop,
78
84
  once,
79
85
  throttle
80
86
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/function/index.ts","../../src/function/debounce.ts","../../src/function/once.ts","../../src/function/throttle.ts"],"sourcesContent":["export { debounce } from './debounce';\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 * 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;;;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;;;ACxBO,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,7 +1,10 @@
1
- import "../chunk-SYQTG4N4.mjs";
1
+ import "../chunk-N6EM6ETS.mjs";
2
2
  import {
3
3
  debounce
4
4
  } from "../chunk-GELVVASW.mjs";
5
+ import {
6
+ noop
7
+ } from "../chunk-LKXCOLNY.mjs";
5
8
  import {
6
9
  once
7
10
  } from "../chunk-UFAA5WKR.mjs";
@@ -11,6 +14,7 @@ import {
11
14
  import "../chunk-2MM5EJJX.mjs";
12
15
  export {
13
16
  debounce,
17
+ noop,
14
18
  once,
15
19
  throttle
16
20
  };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * A no-operation function that does nothing.
3
+ * This can be used as a placeholder or default function.
4
+ *
5
+ * @example
6
+ * noop(); // Does nothing
7
+ *
8
+ * @returns {void} This function does not return anything.
9
+ */
10
+ declare function noop(): void;
11
+
12
+ export { noop };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * A no-operation function that does nothing.
3
+ * This can be used as a placeholder or default function.
4
+ *
5
+ * @example
6
+ * noop(); // Does nothing
7
+ *
8
+ * @returns {void} This function does not return anything.
9
+ */
10
+ declare function noop(): void;
11
+
12
+ export { noop };
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/function/noop.ts
21
+ var noop_exports = {};
22
+ __export(noop_exports, {
23
+ noop: () => noop
24
+ });
25
+ module.exports = __toCommonJS(noop_exports);
26
+ function noop() {
27
+ }
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {
30
+ noop
31
+ });
32
+ //# sourceMappingURL=noop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/function/noop.ts"],"sourcesContent":["/**\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AASO,SAAS,OAAa;AAAC;","names":[]}
@@ -0,0 +1,8 @@
1
+ import {
2
+ noop
3
+ } from "../chunk-LKXCOLNY.mjs";
4
+ import "../chunk-2MM5EJJX.mjs";
5
+ export {
6
+ noop
7
+ };
8
+ //# sourceMappingURL=noop.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/dist/index.d.mts CHANGED
@@ -29,6 +29,7 @@ export { xorWith } from './array/xorWith.mjs';
29
29
  export { zip } from './array/zip.mjs';
30
30
  export { zipWith } from './array/zipWith.mjs';
31
31
  export { debounce } from './function/debounce.mjs';
32
+ export { noop } from './function/noop.mjs';
32
33
  export { once } from './function/once.mjs';
33
34
  export { throttle } from './function/throttle.mjs';
34
35
  export { clamp } from './math/clamp.mjs';
package/dist/index.d.ts CHANGED
@@ -29,6 +29,7 @@ export { xorWith } from './array/xorWith.js';
29
29
  export { zip } from './array/zip.js';
30
30
  export { zipWith } from './array/zipWith.js';
31
31
  export { debounce } from './function/debounce.js';
32
+ export { noop } from './function/noop.js';
32
33
  export { once } from './function/once.js';
33
34
  export { throttle } from './function/throttle.js';
34
35
  export { clamp } from './math/clamp.js';
package/dist/index.js CHANGED
@@ -53,6 +53,7 @@ __export(src_exports, {
53
53
  isNotNil: () => isNotNil,
54
54
  isNull: () => isNull,
55
55
  isUndefined: () => isUndefined,
56
+ noop: () => noop,
56
57
  omit: () => omit,
57
58
  omitBy: () => omitBy,
58
59
  once: () => once,
@@ -99,16 +100,15 @@ function chunk(arr, size) {
99
100
 
100
101
  // src/array/difference.ts
101
102
  function difference(firstArr, secondArr) {
102
- return firstArr.filter((item) => {
103
- return !secondArr.includes(item);
104
- });
103
+ const secondSet = new Set(secondArr);
104
+ return firstArr.filter((item) => !secondSet.has(item));
105
105
  }
106
106
 
107
107
  // src/array/differenceBy.ts
108
108
  function differenceBy(firstArr, secondArr, mapper) {
109
- const mappedSecondArr = secondArr.map((item) => mapper(item));
109
+ const mappedSecondSet = new Set(secondArr.map((item) => mapper(item)));
110
110
  return firstArr.filter((item) => {
111
- return !mappedSecondArr.includes(mapper(item));
111
+ return !mappedSecondSet.has(mapper(item));
112
112
  });
113
113
  }
114
114
 
@@ -203,11 +203,12 @@ function sample(arr) {
203
203
 
204
204
  // src/array/shuffle.ts
205
205
  function shuffle(arr) {
206
- for (let i = arr.length - 1; i >= 1; i--) {
206
+ const result = arr.slice();
207
+ for (let i = result.length - 1; i >= 1; i--) {
207
208
  const j = Math.floor(Math.random() * (i + 1));
208
- [arr[i], arr[j]] = [arr[j], arr[i]];
209
+ [result[i], result[j]] = [result[j], result[i]];
209
210
  }
210
- return arr;
211
+ return result;
211
212
  }
212
213
 
213
214
  // src/array/take.ts
@@ -361,6 +362,10 @@ function debounce(func, debounceMs) {
361
362
  return debounced;
362
363
  }
363
364
 
365
+ // src/function/noop.ts
366
+ function noop() {
367
+ }
368
+
364
369
  // src/function/once.ts
365
370
  function once(func) {
366
371
  let called = false;
@@ -501,6 +506,7 @@ function delay(ms) {
501
506
  isNotNil,
502
507
  isNull,
503
508
  isUndefined,
509
+ noop,
504
510
  omit,
505
511
  omitBy,
506
512
  once,