es-toolkit 1.5.0 → 1.6.0-dev.113

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 (98) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/array/compact.d.mts +14 -0
  3. package/dist/array/compact.d.ts +14 -0
  4. package/dist/array/compact.js +39 -0
  5. package/dist/array/compact.js.map +1 -0
  6. package/dist/array/compact.mjs +8 -0
  7. package/dist/array/index.d.mts +3 -0
  8. package/dist/array/index.d.ts +3 -0
  9. package/dist/array/index.js +44 -8
  10. package/dist/array/index.js.map +1 -1
  11. package/dist/array/index.mjs +52 -40
  12. package/dist/array/keyBy.d.mts +28 -0
  13. package/dist/array/keyBy.d.ts +28 -0
  14. package/dist/array/keyBy.js +38 -0
  15. package/dist/array/keyBy.js.map +1 -0
  16. package/dist/array/keyBy.mjs +8 -0
  17. package/dist/array/maxBy.d.mts +8 -15
  18. package/dist/array/maxBy.d.ts +8 -15
  19. package/dist/array/maxBy.js +4 -4
  20. package/dist/array/maxBy.js.map +1 -1
  21. package/dist/array/maxBy.mjs +1 -1
  22. package/dist/array/minBy.d.mts +9 -8
  23. package/dist/array/minBy.d.ts +9 -8
  24. package/dist/array/minBy.js +4 -4
  25. package/dist/array/minBy.js.map +1 -1
  26. package/dist/array/minBy.mjs +1 -1
  27. package/dist/array/zipObject.d.mts +33 -0
  28. package/dist/array/zipObject.d.ts +33 -0
  29. package/dist/array/zipObject.js +37 -0
  30. package/dist/array/zipObject.js.map +1 -0
  31. package/dist/array/zipObject.mjs +8 -0
  32. package/dist/array/zipObject.mjs.map +1 -0
  33. package/dist/chunk-DA7GSKQ5.mjs +13 -0
  34. package/dist/chunk-DA7GSKQ5.mjs.map +1 -0
  35. package/dist/chunk-FXOABQRO.mjs +18 -0
  36. package/dist/chunk-FXOABQRO.mjs.map +1 -0
  37. package/dist/chunk-NKTBEEIT.mjs +15 -0
  38. package/dist/chunk-NKTBEEIT.mjs.map +1 -0
  39. package/dist/{chunk-7OU22ENP.mjs → chunk-NOFHNJ5C.mjs} +1 -1
  40. package/dist/{chunk-7OU22ENP.mjs.map → chunk-NOFHNJ5C.mjs.map} +1 -1
  41. package/dist/chunk-OIHARMNM.mjs +18 -0
  42. package/dist/chunk-OIHARMNM.mjs.map +1 -0
  43. package/dist/chunk-QVHWSUEH.mjs +1 -0
  44. package/dist/chunk-QVHWSUEH.mjs.map +1 -0
  45. package/dist/chunk-S3GNYAM2.mjs +13 -0
  46. package/dist/chunk-S3GNYAM2.mjs.map +1 -0
  47. package/dist/{chunk-LCP6FOCX.mjs → chunk-SYWMYQYJ.mjs} +5 -1
  48. package/dist/chunk-SYWMYQYJ.mjs.map +1 -0
  49. package/dist/chunk-V6MDTRGS.mjs +1 -0
  50. package/dist/chunk-V6MDTRGS.mjs.map +1 -0
  51. package/dist/{chunk-5UT77WON.mjs → chunk-WC5HFQXP.mjs} +2 -2
  52. package/dist/chunk-WC5HFQXP.mjs.map +1 -0
  53. package/dist/chunk-ZOTAORG3.mjs +14 -0
  54. package/dist/chunk-ZOTAORG3.mjs.map +1 -0
  55. package/dist/function/index.mjs +3 -3
  56. package/dist/index.d.mts +4 -0
  57. package/dist/index.d.ts +4 -0
  58. package/dist/index.js +64 -17
  59. package/dist/index.js.map +1 -1
  60. package/dist/index.mjs +85 -69
  61. package/dist/math/index.d.mts +1 -0
  62. package/dist/math/index.d.ts +1 -0
  63. package/dist/math/index.js +20 -9
  64. package/dist/math/index.js.map +1 -1
  65. package/dist/math/index.mjs +13 -9
  66. package/dist/math/mean.d.mts +16 -0
  67. package/dist/math/mean.d.ts +16 -0
  68. package/dist/math/mean.js +44 -0
  69. package/dist/math/mean.js.map +1 -0
  70. package/dist/math/mean.mjs +9 -0
  71. package/dist/math/mean.mjs.map +1 -0
  72. package/dist/math/random.d.mts +3 -0
  73. package/dist/math/random.d.ts +3 -0
  74. package/dist/math/random.js +4 -0
  75. package/dist/math/random.js.map +1 -1
  76. package/dist/math/random.mjs +1 -1
  77. package/dist/math/randomInt.d.mts +3 -0
  78. package/dist/math/randomInt.d.ts +3 -0
  79. package/dist/math/randomInt.js +4 -0
  80. package/dist/math/randomInt.js.map +1 -1
  81. package/dist/math/randomInt.mjs +2 -2
  82. package/dist/math/sum.d.mts +1 -1
  83. package/dist/math/sum.d.ts +1 -1
  84. package/dist/math/sum.js.map +1 -1
  85. package/dist/math/sum.mjs +1 -1
  86. package/dist/object/index.mjs +3 -3
  87. package/dist/predicate/index.mjs +6 -6
  88. package/package.json +1 -1
  89. package/dist/chunk-5UT77WON.mjs.map +0 -1
  90. package/dist/chunk-7LAMAYGN.mjs +0 -1
  91. package/dist/chunk-H23GUJVF.mjs +0 -18
  92. package/dist/chunk-H23GUJVF.mjs.map +0 -1
  93. package/dist/chunk-KZ5JY7J3.mjs +0 -18
  94. package/dist/chunk-KZ5JY7J3.mjs.map +0 -1
  95. package/dist/chunk-LCP6FOCX.mjs.map +0 -1
  96. package/dist/chunk-NP6PDX3E.mjs +0 -1
  97. /package/dist/{chunk-7LAMAYGN.mjs.map → array/compact.mjs.map} +0 -0
  98. /package/dist/{chunk-NP6PDX3E.mjs.map → array/keyBy.mjs.map} +0 -0
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Maps each element of an array based on a provided key-generating function.
3
+ *
4
+ * This function takes an array and a function that generates a key from each element. It returns
5
+ * an object where the keys are the generated keys and the values are the corresponding elements.
6
+ * If there are multiple elements generating the same key, the last element among them is used
7
+ * as the value.
8
+ *
9
+ * @param {T[]} arr - The array of elements to be mapped.
10
+ * @param {(item: T) => K} getKeyFromItem - A function that generates a key from an element.
11
+ * @returns {Record<K, T>} An object where keys are mapped to each element of an array.
12
+ *
13
+ * @example
14
+ * const array = [
15
+ * { category: 'fruit', name: 'apple' },
16
+ * { category: 'fruit', name: 'banana' },
17
+ * { category: 'vegetable', name: 'carrot' }
18
+ * ];
19
+ * const result = keyBy(array, item => item.category);
20
+ * // result will be:
21
+ * // {
22
+ * // fruit: { category: 'fruit', name: 'banana' },
23
+ * // vegetable: { category: 'vegetable', name: 'carrot' }
24
+ * // }
25
+ */
26
+ declare function keyBy<T, K extends string>(arr: readonly T[], getKeyFromItem: (item: T) => K): Record<K, T>;
27
+
28
+ export { keyBy };
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Maps each element of an array based on a provided key-generating function.
3
+ *
4
+ * This function takes an array and a function that generates a key from each element. It returns
5
+ * an object where the keys are the generated keys and the values are the corresponding elements.
6
+ * If there are multiple elements generating the same key, the last element among them is used
7
+ * as the value.
8
+ *
9
+ * @param {T[]} arr - The array of elements to be mapped.
10
+ * @param {(item: T) => K} getKeyFromItem - A function that generates a key from an element.
11
+ * @returns {Record<K, T>} An object where keys are mapped to each element of an array.
12
+ *
13
+ * @example
14
+ * const array = [
15
+ * { category: 'fruit', name: 'apple' },
16
+ * { category: 'fruit', name: 'banana' },
17
+ * { category: 'vegetable', name: 'carrot' }
18
+ * ];
19
+ * const result = keyBy(array, item => item.category);
20
+ * // result will be:
21
+ * // {
22
+ * // fruit: { category: 'fruit', name: 'banana' },
23
+ * // vegetable: { category: 'vegetable', name: 'carrot' }
24
+ * // }
25
+ */
26
+ declare function keyBy<T, K extends string>(arr: readonly T[], getKeyFromItem: (item: T) => K): Record<K, T>;
27
+
28
+ export { keyBy };
@@ -0,0 +1,38 @@
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/array/keyBy.ts
21
+ var keyBy_exports = {};
22
+ __export(keyBy_exports, {
23
+ keyBy: () => keyBy
24
+ });
25
+ module.exports = __toCommonJS(keyBy_exports);
26
+ function keyBy(arr, getKeyFromItem) {
27
+ const result = {};
28
+ for (const item of arr) {
29
+ const key = getKeyFromItem(item);
30
+ result[key] = item;
31
+ }
32
+ return result;
33
+ }
34
+ // Annotate the CommonJS export names for ESM import in node:
35
+ 0 && (module.exports = {
36
+ keyBy
37
+ });
38
+ //# sourceMappingURL=keyBy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/array/keyBy.ts"],"sourcesContent":["/**\n * Maps each element of an array based on a provided key-generating function.\n *\n * This function takes an array and a function that generates a key from each element. It returns\n * an object where the keys are the generated keys and the values are the corresponding elements.\n * If there are multiple elements generating the same key, the last element among them is used\n * as the value.\n *\n * @param {T[]} arr - The array of elements to be mapped.\n * @param {(item: T) => K} getKeyFromItem - A function that generates a key from an element.\n * @returns {Record<K, T>} An object where keys are mapped to each element of an array.\n *\n * @example\n * const array = [\n * { category: 'fruit', name: 'apple' },\n * { category: 'fruit', name: 'banana' },\n * { category: 'vegetable', name: 'carrot' }\n * ];\n * const result = keyBy(array, item => item.category);\n * // result will be:\n * // {\n * // fruit: { category: 'fruit', name: 'banana' },\n * // vegetable: { category: 'vegetable', name: 'carrot' }\n * // }\n */\nexport function keyBy<T, K extends string>(arr: readonly T[], getKeyFromItem: (item: T) => K): Record<K, T> {\n const result = {} as Record<K, T>;\n\n for (const item of arr) {\n const key = getKeyFromItem(item);\n result[key] = item;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAyBO,SAAS,MAA2B,KAAmB,gBAA8C;AAC1G,QAAM,SAAS,CAAC;AAEhB,aAAW,QAAQ,KAAK;AACtB,UAAM,MAAM,eAAe,IAAI;AAC/B,WAAO,GAAG,IAAI;AAAA,EAChB;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,8 @@
1
+ import {
2
+ keyBy
3
+ } from "../chunk-ZOTAORG3.mjs";
4
+ import "../chunk-2MM5EJJX.mjs";
5
+ export {
6
+ keyBy
7
+ };
8
+ //# sourceMappingURL=keyBy.mjs.map
@@ -1,21 +1,14 @@
1
1
  /**
2
- * Returns the element of the specified array that has the maximum value, according to the specified selector.
3
- *
4
- * This function takes an array of elements and a selector function, and returns the element with the maximum value according to the selector.
5
- *
6
- * @param {T[]} elements - An array of elements to be compared.
7
- * @param {(element: T) => number} selector - A function that takes an element and returns a number.
8
- * @returns {T} The element with the maximum value according to the selector.
2
+ * Finds the element in an array that has the maximum value when applying
3
+ * the `getValue` function to each element.
9
4
  *
5
+ * @param {T[]} items The array of elements to search.
6
+ * @param {(element: T) => number} getValue A function that selects a numeric value from each element.
7
+ * @returns {T} The element with the maximum value as determined by the `getValue` function.
10
8
  * @example
11
- * const people = [
12
- * { name: 'Mark', age: 25 },
13
- * { name: 'Nunu', age: 30 },
14
- * { name: 'Overmars', age: 20 }
15
- * ];
16
- * const result = maxBy(people, person => person.age);
17
- * // result will be { name: 'Nunu', age: 30 }
9
+ * maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
10
+ * maxBy([], x => x.a); // Returns: undefined
18
11
  */
19
- declare function maxBy<T>(elements: T[], selector: (element: T) => number): T;
12
+ declare function maxBy<T>(items: T[], getValue: (element: T) => number): T;
20
13
 
21
14
  export { maxBy };
@@ -1,21 +1,14 @@
1
1
  /**
2
- * Returns the element of the specified array that has the maximum value, according to the specified selector.
3
- *
4
- * This function takes an array of elements and a selector function, and returns the element with the maximum value according to the selector.
5
- *
6
- * @param {T[]} elements - An array of elements to be compared.
7
- * @param {(element: T) => number} selector - A function that takes an element and returns a number.
8
- * @returns {T} The element with the maximum value according to the selector.
2
+ * Finds the element in an array that has the maximum value when applying
3
+ * the `getValue` function to each element.
9
4
  *
5
+ * @param {T[]} items The array of elements to search.
6
+ * @param {(element: T) => number} getValue A function that selects a numeric value from each element.
7
+ * @returns {T} The element with the maximum value as determined by the `getValue` function.
10
8
  * @example
11
- * const people = [
12
- * { name: 'Mark', age: 25 },
13
- * { name: 'Nunu', age: 30 },
14
- * { name: 'Overmars', age: 20 }
15
- * ];
16
- * const result = maxBy(people, person => person.age);
17
- * // result will be { name: 'Nunu', age: 30 }
9
+ * maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
10
+ * maxBy([], x => x.a); // Returns: undefined
18
11
  */
19
- declare function maxBy<T>(elements: T[], selector: (element: T) => number): T;
12
+ declare function maxBy<T>(items: T[], getValue: (element: T) => number): T;
20
13
 
21
14
  export { maxBy };
@@ -23,11 +23,11 @@ __export(maxBy_exports, {
23
23
  maxBy: () => maxBy
24
24
  });
25
25
  module.exports = __toCommonJS(maxBy_exports);
26
- function maxBy(elements, selector) {
27
- let maxElement = elements[0];
26
+ function maxBy(items, getValue) {
27
+ let maxElement = items[0];
28
28
  let max = -Infinity;
29
- for (const element of elements) {
30
- const value = selector(element);
29
+ for (const element of items) {
30
+ const value = getValue(element);
31
31
  if (value > max) {
32
32
  max = value;
33
33
  maxElement = element;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/array/maxBy.ts"],"sourcesContent":["/**\n * Returns the element of the specified array that has the maximum value, according to the specified selector.\n *\n * This function takes an array of elements and a selector function, and returns the element with the maximum value according to the selector.\n *\n * @param {T[]} elements - An array of elements to be compared.\n * @param {(element: T) => number} selector - A function that takes an element and returns a number.\n * @returns {T} The element with the maximum value according to the selector.\n *\n * @example\n * const people = [\n * { name: 'Mark', age: 25 },\n * { name: 'Nunu', age: 30 },\n * { name: 'Overmars', age: 20 }\n * ];\n * const result = maxBy(people, person => person.age);\n * // result will be { name: 'Nunu', age: 30 }\n */\nexport function maxBy<T>(elements: T[], selector: (element: T) => number): T {\n let maxElement = elements[0];\n let max = -Infinity;\n\n for (const element of elements) {\n const value = selector(element);\n if (value > max) {\n max = value;\n maxElement = element;\n }\n }\n\n return maxElement;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBO,SAAS,MAAS,UAAe,UAAqC;AAC3E,MAAI,aAAa,SAAS,CAAC;AAC3B,MAAI,MAAM;AAEV,aAAW,WAAW,UAAU;AAC9B,UAAM,QAAQ,SAAS,OAAO;AAC9B,QAAI,QAAQ,KAAK;AACf,YAAM;AACN,mBAAa;AAAA,IACf;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/array/maxBy.ts"],"sourcesContent":["/**\n * Finds the element in an array that has the maximum value when applying\n * the `getValue` function to each element.\n *\n * @param {T[]} items The array of elements to search.\n * @param {(element: T) => number} getValue A function that selects a numeric value from each element.\n * @returns {T} The element with the maximum value as determined by the `getValue` function.\n * @example\n * maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }\n * maxBy([], x => x.a); // Returns: undefined\n */\nexport function maxBy<T>(items: T[], getValue: (element: T) => number): T {\n let maxElement = items[0];\n let max = -Infinity;\n\n for (const element of items) {\n const value = getValue(element);\n if (value > max) {\n max = value;\n maxElement = element;\n }\n }\n\n return maxElement;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAWO,SAAS,MAAS,OAAY,UAAqC;AACxE,MAAI,aAAa,MAAM,CAAC;AACxB,MAAI,MAAM;AAEV,aAAW,WAAW,OAAO;AAC3B,UAAM,QAAQ,SAAS,OAAO;AAC9B,QAAI,QAAQ,KAAK;AACf,YAAM;AACN,mBAAa;AAAA,IACf;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  maxBy
3
- } from "../chunk-KZ5JY7J3.mjs";
3
+ } from "../chunk-FXOABQRO.mjs";
4
4
  import "../chunk-2MM5EJJX.mjs";
5
5
  export {
6
6
  maxBy
@@ -1,13 +1,14 @@
1
1
  /**
2
- * Returns the minimum value in an array of numbers.
2
+ * Finds the element in an array that has the minimum value when applying
3
+ * the `getValue` function to each element.
3
4
  *
4
- * This function takes an array of elements and a selector function, and returns the element with the minimum value according to the selector.
5
- *
6
- * If the array is empty, the function returns `undefined`.
7
- *
8
- * @param elements An array of elements.
9
- * @param selector A function that selects a number from an element.
5
+ * @param {T[]} items The array of elements to search.
6
+ * @param {(element: T) => number} getValue A function that selects a numeric value from each element.
7
+ * @returns {T} The element with the minimum value as determined by the `getValue` function.
8
+ * @example
9
+ * minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 1 }
10
+ * minBy([], x => x.a); // Returns: undefined
10
11
  */
11
- declare function minBy<T>(elements: T[], selector: (element: T) => number): T;
12
+ declare function minBy<T>(items: T[], getValue: (element: T) => number): T;
12
13
 
13
14
  export { minBy };
@@ -1,13 +1,14 @@
1
1
  /**
2
- * Returns the minimum value in an array of numbers.
2
+ * Finds the element in an array that has the minimum value when applying
3
+ * the `getValue` function to each element.
3
4
  *
4
- * This function takes an array of elements and a selector function, and returns the element with the minimum value according to the selector.
5
- *
6
- * If the array is empty, the function returns `undefined`.
7
- *
8
- * @param elements An array of elements.
9
- * @param selector A function that selects a number from an element.
5
+ * @param {T[]} items The array of elements to search.
6
+ * @param {(element: T) => number} getValue A function that selects a numeric value from each element.
7
+ * @returns {T} The element with the minimum value as determined by the `getValue` function.
8
+ * @example
9
+ * minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 1 }
10
+ * minBy([], x => x.a); // Returns: undefined
10
11
  */
11
- declare function minBy<T>(elements: T[], selector: (element: T) => number): T;
12
+ declare function minBy<T>(items: T[], getValue: (element: T) => number): T;
12
13
 
13
14
  export { minBy };
@@ -23,11 +23,11 @@ __export(minBy_exports, {
23
23
  minBy: () => minBy
24
24
  });
25
25
  module.exports = __toCommonJS(minBy_exports);
26
- function minBy(elements, selector) {
27
- let minElement = elements[0];
26
+ function minBy(items, getValue) {
27
+ let minElement = items[0];
28
28
  let min = Infinity;
29
- for (const element of elements) {
30
- const value = selector(element);
29
+ for (const element of items) {
30
+ const value = getValue(element);
31
31
  if (value < min) {
32
32
  min = value;
33
33
  minElement = element;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/array/minBy.ts"],"sourcesContent":["/**\n * Returns the minimum value in an array of numbers.\n *\n * This function takes an array of elements and a selector function, and returns the element with the minimum value according to the selector.\n *\n * If the array is empty, the function returns `undefined`.\n *\n * @param elements An array of elements.\n * @param selector A function that selects a number from an element.\n */\nexport function minBy<T>(elements: T[], selector: (element: T) => number): T {\n let minElement = elements[0];\n let min = Infinity;\n\n for (const element of elements) {\n const value = selector(element);\n if (value < min) {\n min = value;\n minElement = element;\n }\n }\n\n return minElement;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAUO,SAAS,MAAS,UAAe,UAAqC;AAC3E,MAAI,aAAa,SAAS,CAAC;AAC3B,MAAI,MAAM;AAEV,aAAW,WAAW,UAAU;AAC9B,UAAM,QAAQ,SAAS,OAAO;AAC9B,QAAI,QAAQ,KAAK;AACf,YAAM;AACN,mBAAa;AAAA,IACf;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/array/minBy.ts"],"sourcesContent":["/**\n * Finds the element in an array that has the minimum value when applying\n * the `getValue` function to each element.\n *\n * @param {T[]} items The array of elements to search.\n * @param {(element: T) => number} getValue A function that selects a numeric value from each element.\n * @returns {T} The element with the minimum value as determined by the `getValue` function.\n * @example\n * minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 1 }\n * minBy([], x => x.a); // Returns: undefined\n */\nexport function minBy<T>(items: T[], getValue: (element: T) => number): T {\n let minElement = items[0];\n let min = Infinity;\n\n for (const element of items) {\n const value = getValue(element);\n if (value < min) {\n min = value;\n minElement = element;\n }\n }\n\n return minElement;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAWO,SAAS,MAAS,OAAY,UAAqC;AACxE,MAAI,aAAa,MAAM,CAAC;AACxB,MAAI,MAAM;AAEV,aAAW,WAAW,OAAO;AAC3B,UAAM,QAAQ,SAAS,OAAO;AAC9B,QAAI,QAAQ,KAAK;AACf,YAAM;AACN,mBAAa;AAAA,IACf;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  minBy
3
- } from "../chunk-H23GUJVF.mjs";
3
+ } from "../chunk-OIHARMNM.mjs";
4
4
  import "../chunk-2MM5EJJX.mjs";
5
5
  export {
6
6
  minBy
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Combines two arrays, one of property names and one of corresponding values, into a single object.
3
+ *
4
+ * This function takes two arrays: one containing property names and another containing corresponding values.
5
+ * It returns a new object where the property names from the first array are keys, and the corresponding elements
6
+ * from the second array are values. If the `keys` array is longer than the `values` array, the remaining keys will
7
+ * have `undefined` as their values.
8
+ *
9
+ * @param {P[]} keys - An array of property names.
10
+ * @param {V[]} values - An array of values corresponding to the property names.
11
+ * @returns {{ [K in P]: V }} A new object composed of the given property names and values.
12
+ *
13
+ * @example
14
+ * const keys = ['a', 'b', 'c'];
15
+ * const values = [1, 2, 3];
16
+ * const result = zipObject(keys, values);
17
+ * // result will be { a: 1, b: 2, c: 3 }
18
+ *
19
+ * const keys2 = ['a', 'b', 'c'];
20
+ * const values2 = [1, 2];
21
+ * const result2 = zipObject(keys2, values2);
22
+ * // result2 will be { a: 1, b: 2, c: undefined }
23
+ *
24
+ * const keys2 = ['a', 'b'];
25
+ * const values2 = [1, 2, 3];
26
+ * const result2 = zipObject(keys2, values2);
27
+ * // result2 will be { a: 1, b: 2 }
28
+ */
29
+ declare function zipObject<P extends string | number | symbol, V>(keys: P[], values: V[]): {
30
+ [K in P]: V;
31
+ };
32
+
33
+ export { zipObject };
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Combines two arrays, one of property names and one of corresponding values, into a single object.
3
+ *
4
+ * This function takes two arrays: one containing property names and another containing corresponding values.
5
+ * It returns a new object where the property names from the first array are keys, and the corresponding elements
6
+ * from the second array are values. If the `keys` array is longer than the `values` array, the remaining keys will
7
+ * have `undefined` as their values.
8
+ *
9
+ * @param {P[]} keys - An array of property names.
10
+ * @param {V[]} values - An array of values corresponding to the property names.
11
+ * @returns {{ [K in P]: V }} A new object composed of the given property names and values.
12
+ *
13
+ * @example
14
+ * const keys = ['a', 'b', 'c'];
15
+ * const values = [1, 2, 3];
16
+ * const result = zipObject(keys, values);
17
+ * // result will be { a: 1, b: 2, c: 3 }
18
+ *
19
+ * const keys2 = ['a', 'b', 'c'];
20
+ * const values2 = [1, 2];
21
+ * const result2 = zipObject(keys2, values2);
22
+ * // result2 will be { a: 1, b: 2, c: undefined }
23
+ *
24
+ * const keys2 = ['a', 'b'];
25
+ * const values2 = [1, 2, 3];
26
+ * const result2 = zipObject(keys2, values2);
27
+ * // result2 will be { a: 1, b: 2 }
28
+ */
29
+ declare function zipObject<P extends string | number | symbol, V>(keys: P[], values: V[]): {
30
+ [K in P]: V;
31
+ };
32
+
33
+ export { zipObject };
@@ -0,0 +1,37 @@
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/array/zipObject.ts
21
+ var zipObject_exports = {};
22
+ __export(zipObject_exports, {
23
+ zipObject: () => zipObject
24
+ });
25
+ module.exports = __toCommonJS(zipObject_exports);
26
+ function zipObject(keys, values) {
27
+ const result = {};
28
+ for (let i = 0; i < keys.length; i++) {
29
+ result[keys[i]] = values[i];
30
+ }
31
+ return result;
32
+ }
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ zipObject
36
+ });
37
+ //# sourceMappingURL=zipObject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/array/zipObject.ts"],"sourcesContent":["/**\n * Combines two arrays, one of property names and one of corresponding values, into a single object.\n *\n * This function takes two arrays: one containing property names and another containing corresponding values.\n * It returns a new object where the property names from the first array are keys, and the corresponding elements\n * from the second array are values. If the `keys` array is longer than the `values` array, the remaining keys will\n * have `undefined` as their values.\n *\n * @param {P[]} keys - An array of property names.\n * @param {V[]} values - An array of values corresponding to the property names.\n * @returns {{ [K in P]: V }} A new object composed of the given property names and values.\n *\n * @example\n * const keys = ['a', 'b', 'c'];\n * const values = [1, 2, 3];\n * const result = zipObject(keys, values);\n * // result will be { a: 1, b: 2, c: 3 }\n *\n * const keys2 = ['a', 'b', 'c'];\n * const values2 = [1, 2];\n * const result2 = zipObject(keys2, values2);\n * // result2 will be { a: 1, b: 2, c: undefined }\n *\n * const keys2 = ['a', 'b'];\n * const values2 = [1, 2, 3];\n * const result2 = zipObject(keys2, values2);\n * // result2 will be { a: 1, b: 2 }\n */\nexport function zipObject<P extends string | number | symbol, V>(keys: P[], values: V[]): { [K in P]: V } {\n const result = {} as { [K in P]: V };\n\n for (let i = 0; i < keys.length; i++) {\n result[keys[i]] = values[i];\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA4BO,SAAS,UAAiD,MAAW,QAA8B;AACxG,QAAM,SAAS,CAAC;AAEhB,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,WAAO,KAAK,CAAC,CAAC,IAAI,OAAO,CAAC;AAAA,EAC5B;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,8 @@
1
+ import {
2
+ zipObject
3
+ } from "../chunk-DA7GSKQ5.mjs";
4
+ import "../chunk-2MM5EJJX.mjs";
5
+ export {
6
+ zipObject
7
+ };
8
+ //# sourceMappingURL=zipObject.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,13 @@
1
+ // src/array/zipObject.ts
2
+ function zipObject(keys, values) {
3
+ const result = {};
4
+ for (let i = 0; i < keys.length; i++) {
5
+ result[keys[i]] = values[i];
6
+ }
7
+ return result;
8
+ }
9
+
10
+ export {
11
+ zipObject
12
+ };
13
+ //# sourceMappingURL=chunk-DA7GSKQ5.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/array/zipObject.ts"],"sourcesContent":["/**\n * Combines two arrays, one of property names and one of corresponding values, into a single object.\n *\n * This function takes two arrays: one containing property names and another containing corresponding values.\n * It returns a new object where the property names from the first array are keys, and the corresponding elements\n * from the second array are values. If the `keys` array is longer than the `values` array, the remaining keys will\n * have `undefined` as their values.\n *\n * @param {P[]} keys - An array of property names.\n * @param {V[]} values - An array of values corresponding to the property names.\n * @returns {{ [K in P]: V }} A new object composed of the given property names and values.\n *\n * @example\n * const keys = ['a', 'b', 'c'];\n * const values = [1, 2, 3];\n * const result = zipObject(keys, values);\n * // result will be { a: 1, b: 2, c: 3 }\n *\n * const keys2 = ['a', 'b', 'c'];\n * const values2 = [1, 2];\n * const result2 = zipObject(keys2, values2);\n * // result2 will be { a: 1, b: 2, c: undefined }\n *\n * const keys2 = ['a', 'b'];\n * const values2 = [1, 2, 3];\n * const result2 = zipObject(keys2, values2);\n * // result2 will be { a: 1, b: 2 }\n */\nexport function zipObject<P extends string | number | symbol, V>(keys: P[], values: V[]): { [K in P]: V } {\n const result = {} as { [K in P]: V };\n\n for (let i = 0; i < keys.length; i++) {\n result[keys[i]] = values[i];\n }\n\n return result;\n}\n"],"mappings":";AA4BO,SAAS,UAAiD,MAAW,QAA8B;AACxG,QAAM,SAAS,CAAC;AAEhB,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,WAAO,KAAK,CAAC,CAAC,IAAI,OAAO,CAAC;AAAA,EAC5B;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,18 @@
1
+ // src/array/maxBy.ts
2
+ function maxBy(items, getValue) {
3
+ let maxElement = items[0];
4
+ let max = -Infinity;
5
+ for (const element of items) {
6
+ const value = getValue(element);
7
+ if (value > max) {
8
+ max = value;
9
+ maxElement = element;
10
+ }
11
+ }
12
+ return maxElement;
13
+ }
14
+
15
+ export {
16
+ maxBy
17
+ };
18
+ //# sourceMappingURL=chunk-FXOABQRO.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/array/maxBy.ts"],"sourcesContent":["/**\n * Finds the element in an array that has the maximum value when applying\n * the `getValue` function to each element.\n *\n * @param {T[]} items The array of elements to search.\n * @param {(element: T) => number} getValue A function that selects a numeric value from each element.\n * @returns {T} The element with the maximum value as determined by the `getValue` function.\n * @example\n * maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }\n * maxBy([], x => x.a); // Returns: undefined\n */\nexport function maxBy<T>(items: T[], getValue: (element: T) => number): T {\n let maxElement = items[0];\n let max = -Infinity;\n\n for (const element of items) {\n const value = getValue(element);\n if (value > max) {\n max = value;\n maxElement = element;\n }\n }\n\n return maxElement;\n}\n"],"mappings":";AAWO,SAAS,MAAS,OAAY,UAAqC;AACxE,MAAI,aAAa,MAAM,CAAC;AACxB,MAAI,MAAM;AAEV,aAAW,WAAW,OAAO;AAC3B,UAAM,QAAQ,SAAS,OAAO;AAC9B,QAAI,QAAQ,KAAK;AACf,YAAM;AACN,mBAAa;AAAA,IACf;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,15 @@
1
+ // src/array/compact.ts
2
+ function compact(arr) {
3
+ const result = [];
4
+ for (const item of arr) {
5
+ if (item) {
6
+ result.push(item);
7
+ }
8
+ }
9
+ return result;
10
+ }
11
+
12
+ export {
13
+ compact
14
+ };
15
+ //# sourceMappingURL=chunk-NKTBEEIT.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/array/compact.ts"],"sourcesContent":["type NotFalsey<T> = Exclude<T, false | null | 0 | '' | undefined>;\n\n/**\n * Removes falsey values (false, null, 0, '', undefined, NaN) from an array.\n *\n * @param {readonly T[]} arr - The input array to remove falsey values.\n * @returns {Array<Exclude<T, false | null | 0 | '' | undefined>>} - A new array with all falsey values removed.\n *\n * @example\n * compact([0, 1, false, 2, '', 3, null, undefined, 4, NaN, 5]);\n * Returns: [1, 2, 3, 4, 5]\n */\nexport function compact<T>(arr: readonly T[]): Array<NotFalsey<T>> {\n const result: Array<NotFalsey<T>> = [];\n\n for (const item of arr) {\n if (item) {\n result.push(item as NotFalsey<T>);\n }\n }\n\n return result;\n}\n"],"mappings":";AAYO,SAAS,QAAW,KAAwC;AACjE,QAAM,SAA8B,CAAC;AAErC,aAAW,QAAQ,KAAK;AACtB,QAAI,MAAM;AACR,aAAO,KAAK,IAAoB;AAAA,IAClC;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -10,4 +10,4 @@ function sum(nums) {
10
10
  export {
11
11
  sum
12
12
  };
13
- //# sourceMappingURL=chunk-7OU22ENP.mjs.map
13
+ //# sourceMappingURL=chunk-NOFHNJ5C.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/math/sum.ts"],"sourcesContent":["/**\n * Calculates the sum of an array of numbers.\n *\n * This function takes an array of numbers and returns the sum of all the elements in the array.\n *\n * @param {number[]} nums - An array of numbers to be summed.\n * @returns {number} The sum of all the numbers in the array.\n *\n * @example\n * const numbers = [1, 2, 3, 4, 5];\n * const result = sum(numbers);\n * // result will be 15\n */\nexport function sum(nums: number[]): number {\n let result = 0;\n\n for (const num of nums) {\n result += num;\n }\n\n return result;\n}\n"],"mappings":";AAaO,SAAS,IAAI,MAAwB;AAC1C,MAAI,SAAS;AAEb,aAAW,OAAO,MAAM;AACtB,cAAU;AAAA,EACZ;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/math/sum.ts"],"sourcesContent":["/**\n * Calculates the sum of an array of numbers.\n *\n * This function takes an array of numbers and returns the sum of all the elements in the array.\n *\n * @param {number[]} nums - An array of numbers to be summed.\n * @returns {number} The sum of all the numbers in the array.\n *\n * @example\n * const numbers = [1, 2, 3, 4, 5];\n * const result = sum(numbers);\n * // result will be 15\n */\nexport function sum(nums: readonly number[]): number {\n let result = 0;\n\n for (const num of nums) {\n result += num;\n }\n\n return result;\n}\n"],"mappings":";AAaO,SAAS,IAAI,MAAiC;AACnD,MAAI,SAAS;AAEb,aAAW,OAAO,MAAM;AACtB,cAAU;AAAA,EACZ;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,18 @@
1
+ // src/array/minBy.ts
2
+ function minBy(items, getValue) {
3
+ let minElement = items[0];
4
+ let min = Infinity;
5
+ for (const element of items) {
6
+ const value = getValue(element);
7
+ if (value < min) {
8
+ min = value;
9
+ minElement = element;
10
+ }
11
+ }
12
+ return minElement;
13
+ }
14
+
15
+ export {
16
+ minBy
17
+ };
18
+ //# sourceMappingURL=chunk-OIHARMNM.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/array/minBy.ts"],"sourcesContent":["/**\n * Finds the element in an array that has the minimum value when applying\n * the `getValue` function to each element.\n *\n * @param {T[]} items The array of elements to search.\n * @param {(element: T) => number} getValue A function that selects a numeric value from each element.\n * @returns {T} The element with the minimum value as determined by the `getValue` function.\n * @example\n * minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 1 }\n * minBy([], x => x.a); // Returns: undefined\n */\nexport function minBy<T>(items: T[], getValue: (element: T) => number): T {\n let minElement = items[0];\n let min = Infinity;\n\n for (const element of items) {\n const value = getValue(element);\n if (value < min) {\n min = value;\n minElement = element;\n }\n }\n\n return minElement;\n}\n"],"mappings":";AAWO,SAAS,MAAS,OAAY,UAAqC;AACxE,MAAI,aAAa,MAAM,CAAC;AACxB,MAAI,MAAM;AAEV,aAAW,WAAW,OAAO;AAC3B,UAAM,QAAQ,SAAS,OAAO;AAC9B,QAAI,QAAQ,KAAK;AACf,YAAM;AACN,mBAAa;AAAA,IACf;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-QVHWSUEH.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,13 @@
1
+ import {
2
+ sum
3
+ } from "./chunk-NOFHNJ5C.mjs";
4
+
5
+ // src/math/mean.ts
6
+ function mean(nums) {
7
+ return sum(nums) / nums.length;
8
+ }
9
+
10
+ export {
11
+ mean
12
+ };
13
+ //# sourceMappingURL=chunk-S3GNYAM2.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/math/mean.ts"],"sourcesContent":["import { sum } from './sum';\n\n/**\n * Calculates the average of an array of numbers.\n *\n * If the array is empty, this function returns `NaN`.\n *\n * @param {number[]} nums - An array of numbers to calculate the avverage.\n * @returns {number} The average of all the numbers in the array.\n *\n * @example\n * const numbers = [1, 2, 3, 4, 5];\n * const result = average(numbers);\n * // result will be 3\n */\nexport function mean(nums: readonly number[]): number {\n return sum(nums) / nums.length;\n}\n"],"mappings":";;;;;AAeO,SAAS,KAAK,MAAiC;AACpD,SAAO,IAAI,IAAI,IAAI,KAAK;AAC1B;","names":[]}
@@ -1,5 +1,9 @@
1
1
  // src/math/random.ts
2
2
  function random(minimum, maximum) {
3
+ if (maximum == null) {
4
+ maximum = minimum;
5
+ minimum = 0;
6
+ }
3
7
  if (minimum >= maximum) {
4
8
  throw new Error("Invalid input: The maximum value must be greater than the minimum value.");
5
9
  }
@@ -9,4 +13,4 @@ function random(minimum, maximum) {
9
13
  export {
10
14
  random
11
15
  };
12
- //# sourceMappingURL=chunk-LCP6FOCX.mjs.map
16
+ //# sourceMappingURL=chunk-SYWMYQYJ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/math/random.ts"],"sourcesContent":["/**\n * Generate a random number within the given range.\n *\n * If only one argument is provided, a number between `0` and the given number is returned.\n *\n * @param {number} minimum - The lower bound (inclusive).\n * @param {number} maximum - The upper bound (exclusive).\n * @returns {number} A random number between minimum (inclusive) and maximum (exclusive). The number can be an integer or a decimal.\n * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.\n *\n * @example\n * const result1 = random(0, 5); // Returns a random number between 0 and 5.\n * const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown\n * const result3 = random(5, 5); // If the minimum is equal to the maximum, an error is thrown.\n */\nexport function random(maximum: number): number;\nexport function random(minimum: number, maximum: number): number;\nexport function random(minimum: number, maximum?: number): number {\n if (maximum == null) {\n maximum = minimum;\n minimum = 0;\n }\n\n if (minimum >= maximum) {\n throw new Error('Invalid input: The maximum value must be greater than the minimum value.');\n }\n\n return Math.random() * (maximum - minimum) + minimum;\n}\n"],"mappings":";AAiBO,SAAS,OAAO,SAAiB,SAA0B;AAChE,MAAI,WAAW,MAAM;AACnB,cAAU;AACV,cAAU;AAAA,EACZ;AAEA,MAAI,WAAW,SAAS;AACtB,UAAM,IAAI,MAAM,0EAA0E;AAAA,EAC5F;AAEA,SAAO,KAAK,OAAO,KAAK,UAAU,WAAW;AAC/C;","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-V6MDTRGS.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  random
3
- } from "./chunk-LCP6FOCX.mjs";
3
+ } from "./chunk-SYWMYQYJ.mjs";
4
4
 
5
5
  // src/math/randomInt.ts
6
6
  function randomInt(minimum, maximum) {
@@ -10,4 +10,4 @@ function randomInt(minimum, maximum) {
10
10
  export {
11
11
  randomInt
12
12
  };
13
- //# sourceMappingURL=chunk-5UT77WON.mjs.map
13
+ //# sourceMappingURL=chunk-WC5HFQXP.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/math/randomInt.ts"],"sourcesContent":["import { random } from './random';\n\n/**\n * Generates a random integer between minimum (inclusive) and maximum (exclusive).\n *\n * If only one argument is provided, a number between `0` and the given number is returned.\n *\n * @param {number} minimum - The lower bound (inclusive).\n * @param {number} maximum - The upper bound (exclusive).\n * @returns {number} A random integer between minimum (inclusive) and maximum (exclusive).\n * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.\n *\n * @example\n * const result = randomInt(0, 5); // result will be a random integer between 0 (inclusive) and 5 (exclusive)\n * const result2 = randomInt(5, 0); // This will throw an error\n */\nexport function randomInt(maximum: number): number;\nexport function randomInt(minimum: number, maximum: number): number;\nexport function randomInt(minimum: number, maximum?: number): number {\n return Math.floor(random(minimum, maximum!));\n}\n"],"mappings":";;;;;AAkBO,SAAS,UAAU,SAAiB,SAA0B;AACnE,SAAO,KAAK,MAAM,OAAO,SAAS,OAAQ,CAAC;AAC7C;","names":[]}
@@ -0,0 +1,14 @@
1
+ // src/array/keyBy.ts
2
+ function keyBy(arr, getKeyFromItem) {
3
+ const result = {};
4
+ for (const item of arr) {
5
+ const key = getKeyFromItem(item);
6
+ result[key] = item;
7
+ }
8
+ return result;
9
+ }
10
+
11
+ export {
12
+ keyBy
13
+ };
14
+ //# sourceMappingURL=chunk-ZOTAORG3.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/array/keyBy.ts"],"sourcesContent":["/**\n * Maps each element of an array based on a provided key-generating function.\n *\n * This function takes an array and a function that generates a key from each element. It returns\n * an object where the keys are the generated keys and the values are the corresponding elements.\n * If there are multiple elements generating the same key, the last element among them is used\n * as the value.\n *\n * @param {T[]} arr - The array of elements to be mapped.\n * @param {(item: T) => K} getKeyFromItem - A function that generates a key from an element.\n * @returns {Record<K, T>} An object where keys are mapped to each element of an array.\n *\n * @example\n * const array = [\n * { category: 'fruit', name: 'apple' },\n * { category: 'fruit', name: 'banana' },\n * { category: 'vegetable', name: 'carrot' }\n * ];\n * const result = keyBy(array, item => item.category);\n * // result will be:\n * // {\n * // fruit: { category: 'fruit', name: 'banana' },\n * // vegetable: { category: 'vegetable', name: 'carrot' }\n * // }\n */\nexport function keyBy<T, K extends string>(arr: readonly T[], getKeyFromItem: (item: T) => K): Record<K, T> {\n const result = {} as Record<K, T>;\n\n for (const item of arr) {\n const key = getKeyFromItem(item);\n result[key] = item;\n }\n\n return result;\n}\n"],"mappings":";AAyBO,SAAS,MAA2B,KAAmB,gBAA8C;AAC1G,QAAM,SAAS,CAAC;AAEhB,aAAW,QAAQ,KAAK;AACtB,UAAM,MAAM,eAAe,IAAI;AAC/B,WAAO,GAAG,IAAI;AAAA,EAChB;AAEA,SAAO;AACT;","names":[]}