es-toolkit 0.0.1 → 1.0.0-dev.24

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 (236) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +31 -0
  3. package/dist/array/chunk.d.ts +21 -5
  4. package/dist/array/difference.d.ts +20 -4
  5. package/dist/array/differenceBy.d.ts +23 -5
  6. package/dist/array/differenceWith.d.ts +19 -5
  7. package/dist/array/drop.d.ts +13 -4
  8. package/dist/array/dropRight.d.ts +13 -4
  9. package/dist/array/dropRightWhile.d.ts +15 -4
  10. package/dist/array/dropWhile.d.ts +15 -4
  11. package/dist/array/groupBy.d.ts +31 -1
  12. package/dist/array/groupBy.spec.d.ts +1 -0
  13. package/dist/array/index.js +437 -224
  14. package/dist/array/intersection.d.ts +13 -6
  15. package/dist/array/intersectionBy.d.ts +17 -8
  16. package/dist/array/intersectionWith.d.ts +18 -8
  17. package/dist/array/partition.d.ts +19 -5
  18. package/dist/array/sample.d.ts +10 -3
  19. package/dist/array/shuffle.d.ts +11 -4
  20. package/dist/array/takeRight.d.ts +0 -2
  21. package/dist/array/union.d.ts +13 -6
  22. package/dist/array/unionBy.d.ts +0 -3
  23. package/dist/array/unionWith.d.ts +15 -9
  24. package/dist/array/uniq.d.ts +9 -8
  25. package/dist/array/xor.d.ts +0 -2
  26. package/dist/array/zip.d.ts +18 -6
  27. package/dist/array/zipWith.d.ts +26 -3
  28. package/dist/function/debounce.d.ts +4 -4
  29. package/dist/function/index.js +4 -5
  30. package/dist/function/once.d.ts +0 -1
  31. package/dist/index.js +651 -248
  32. package/dist/math/clamp.d.ts +16 -8
  33. package/dist/math/index.js +114 -29
  34. package/dist/math/round.d.ts +11 -8
  35. package/dist/math/sum.d.ts +10 -9
  36. package/dist/object/index.js +122 -12
  37. package/dist/object/omit.d.ts +13 -4
  38. package/dist/object/omitBy.d.ts +19 -1
  39. package/dist/object/omitBy.spec.d.ts +1 -0
  40. package/dist/object/pick.d.ts +13 -4
  41. package/dist/object/pickBy.d.ts +19 -1
  42. package/dist/object/pickBy.spec.d.ts +1 -0
  43. package/dist/predicate/index.js +58 -10
  44. package/dist/predicate/isNil.d.ts +17 -3
  45. package/dist/predicate/isNotNil.d.ts +7 -3
  46. package/dist/predicate/isNull.d.ts +17 -2
  47. package/dist/predicate/isUndefined.d.ts +17 -2
  48. package/dist/promise/delay.d.ts +17 -4
  49. package/dist/promise/index.js +16 -3
  50. package/esm/array/_virtual/_rollupPluginBabelHelpers.mjs +1 -37
  51. package/esm/array/chunk.mjs +28 -25
  52. package/esm/array/difference.mjs +20 -4
  53. package/esm/array/differenceBy.mjs +23 -5
  54. package/esm/array/differenceWith.mjs +19 -5
  55. package/esm/array/drop.mjs +13 -4
  56. package/esm/array/dropRight.mjs +13 -4
  57. package/esm/array/dropRightWhile.mjs +15 -4
  58. package/esm/array/dropWhile.mjs +15 -4
  59. package/esm/array/groupBy.mjs +51 -2
  60. package/esm/array/intersection.mjs +13 -6
  61. package/esm/array/intersectionBy.mjs +17 -8
  62. package/esm/array/intersectionWith.mjs +18 -8
  63. package/esm/array/partition.mjs +19 -5
  64. package/esm/array/sample.mjs +10 -3
  65. package/esm/array/shuffle.mjs +12 -5
  66. package/esm/array/takeRight.mjs +0 -2
  67. package/esm/array/union.mjs +14 -10
  68. package/esm/array/unionBy.mjs +0 -3
  69. package/esm/array/unionWith.mjs +16 -11
  70. package/esm/array/uniq.mjs +28 -9
  71. package/esm/array/xor.mjs +0 -2
  72. package/esm/array/zip.mjs +18 -6
  73. package/esm/array/zipWith.mjs +26 -3
  74. package/esm/function/debounce.mjs +4 -4
  75. package/esm/function/once.mjs +0 -1
  76. package/esm/math/_virtual/_rollupPluginBabelHelpers.mjs +66 -0
  77. package/esm/math/clamp.mjs +15 -7
  78. package/esm/math/round.mjs +11 -8
  79. package/esm/math/sum.mjs +25 -14
  80. package/esm/object/_virtual/_rollupPluginBabelHelpers.mjs +37 -1
  81. package/esm/object/omit.mjs +13 -4
  82. package/esm/object/omitBy.mjs +32 -2
  83. package/esm/object/pick.mjs +13 -4
  84. package/esm/object/pickBy.mjs +32 -2
  85. package/esm/predicate/isNil.mjs +17 -3
  86. package/esm/predicate/isNotNil.mjs +7 -3
  87. package/esm/predicate/isNull.mjs +17 -2
  88. package/esm/predicate/isUndefined.mjs +17 -2
  89. package/esm/promise/delay.mjs +16 -3
  90. package/package.json +17 -3
  91. package/.vscode/extensions.json +0 -7
  92. package/.vscode/settings.json +0 -10
  93. package/.yarn/sdks/eslint/bin/eslint.js +0 -20
  94. package/.yarn/sdks/eslint/lib/api.js +0 -20
  95. package/.yarn/sdks/eslint/lib/unsupported-api.js +0 -20
  96. package/.yarn/sdks/eslint/package.json +0 -14
  97. package/.yarn/sdks/integrations.yml +0 -5
  98. package/.yarn/sdks/prettier/bin/prettier.cjs +0 -20
  99. package/.yarn/sdks/prettier/index.cjs +0 -20
  100. package/.yarn/sdks/prettier/package.json +0 -7
  101. package/.yarn/sdks/typescript/bin/tsc +0 -20
  102. package/.yarn/sdks/typescript/bin/tsserver +0 -20
  103. package/.yarn/sdks/typescript/lib/tsc.js +0 -20
  104. package/.yarn/sdks/typescript/lib/tsserver.js +0 -225
  105. package/.yarn/sdks/typescript/lib/tsserverlibrary.js +0 -225
  106. package/.yarn/sdks/typescript/lib/typescript.js +0 -20
  107. package/.yarn/sdks/typescript/package.json +0 -10
  108. package/babel.config.js +0 -6
  109. package/coverage/.tmp/coverage-0.json +0 -1
  110. package/coverage/.tmp/coverage-1.json +0 -1
  111. package/coverage/.tmp/coverage-10.json +0 -1
  112. package/coverage/.tmp/coverage-11.json +0 -1
  113. package/coverage/.tmp/coverage-12.json +0 -1
  114. package/coverage/.tmp/coverage-13.json +0 -1
  115. package/coverage/.tmp/coverage-14.json +0 -1
  116. package/coverage/.tmp/coverage-15.json +0 -1
  117. package/coverage/.tmp/coverage-16.json +0 -1
  118. package/coverage/.tmp/coverage-17.json +0 -1
  119. package/coverage/.tmp/coverage-18.json +0 -1
  120. package/coverage/.tmp/coverage-19.json +0 -1
  121. package/coverage/.tmp/coverage-2.json +0 -1
  122. package/coverage/.tmp/coverage-20.json +0 -1
  123. package/coverage/.tmp/coverage-21.json +0 -1
  124. package/coverage/.tmp/coverage-22.json +0 -1
  125. package/coverage/.tmp/coverage-23.json +0 -1
  126. package/coverage/.tmp/coverage-24.json +0 -1
  127. package/coverage/.tmp/coverage-25.json +0 -1
  128. package/coverage/.tmp/coverage-26.json +0 -1
  129. package/coverage/.tmp/coverage-27.json +0 -1
  130. package/coverage/.tmp/coverage-28.json +0 -1
  131. package/coverage/.tmp/coverage-29.json +0 -1
  132. package/coverage/.tmp/coverage-3.json +0 -1
  133. package/coverage/.tmp/coverage-30.json +0 -1
  134. package/coverage/.tmp/coverage-4.json +0 -1
  135. package/coverage/.tmp/coverage-5.json +0 -1
  136. package/coverage/.tmp/coverage-6.json +0 -1
  137. package/coverage/.tmp/coverage-7.json +0 -1
  138. package/coverage/.tmp/coverage-8.json +0 -1
  139. package/coverage/.tmp/coverage-9.json +0 -1
  140. package/rollup.config.js +0 -5
  141. package/src/array/chunk.spec.ts +0 -27
  142. package/src/array/chunk.ts +0 -24
  143. package/src/array/difference.spec.ts +0 -10
  144. package/src/array/difference.ts +0 -11
  145. package/src/array/differenceBy.spec.ts +0 -9
  146. package/src/array/differenceBy.ts +0 -14
  147. package/src/array/differenceWith.spec.ts +0 -8
  148. package/src/array/differenceWith.ts +0 -14
  149. package/src/array/drop.spec.ts +0 -9
  150. package/src/array/drop.ts +0 -9
  151. package/src/array/dropRight.spec.ts +0 -9
  152. package/src/array/dropRight.ts +0 -9
  153. package/src/array/dropRightWhile.spec.ts +0 -16
  154. package/src/array/dropRightWhile.ts +0 -13
  155. package/src/array/dropWhile.spec.ts +0 -14
  156. package/src/array/dropWhile.ts +0 -10
  157. package/src/array/groupBy.ts +0 -3
  158. package/src/array/index.ts +0 -30
  159. package/src/array/intersection.spec.ts +0 -11
  160. package/src/array/intersection.ts +0 -15
  161. package/src/array/intersectionBy.spec.ts +0 -9
  162. package/src/array/intersectionBy.ts +0 -18
  163. package/src/array/intersectionWith.spec.ts +0 -9
  164. package/src/array/intersectionWith.ts +0 -18
  165. package/src/array/partition.spec.ts +0 -23
  166. package/src/array/partition.ts +0 -21
  167. package/src/array/sample.spec.ts +0 -11
  168. package/src/array/sample.ts +0 -10
  169. package/src/array/shuffle.spec.ts +0 -11
  170. package/src/array/shuffle.ts +0 -18
  171. package/src/array/take.spec.ts +0 -25
  172. package/src/array/take.ts +0 -25
  173. package/src/array/takeRight.spec.ts +0 -25
  174. package/src/array/takeRight.ts +0 -29
  175. package/src/array/takeRightWhile.spec.ts +0 -16
  176. package/src/array/takeRightWhile.ts +0 -26
  177. package/src/array/takeWhile.spec.ts +0 -34
  178. package/src/array/takeWhile.ts +0 -31
  179. package/src/array/union.spec.ts +0 -10
  180. package/src/array/union.ts +0 -14
  181. package/src/array/unionBy.spec.ts +0 -12
  182. package/src/array/unionBy.ts +0 -35
  183. package/src/array/unionWith.spec.ts +0 -23
  184. package/src/array/unionWith.ts +0 -18
  185. package/src/array/uniq.spec.ts +0 -8
  186. package/src/array/uniq.ts +0 -16
  187. package/src/array/uniqBy.spec.ts +0 -8
  188. package/src/array/uniqBy.ts +0 -17
  189. package/src/array/uniqWith.spec.ts +0 -16
  190. package/src/array/uniqWith.ts +0 -29
  191. package/src/array/xor.spec.ts +0 -13
  192. package/src/array/xor.ts +0 -25
  193. package/src/array/xorBy.spec.ts +0 -16
  194. package/src/array/xorBy.ts +0 -29
  195. package/src/array/xorWith.spec.ts +0 -16
  196. package/src/array/xorWith.ts +0 -28
  197. package/src/array/zip.spec.ts +0 -14
  198. package/src/array/zip.ts +0 -34
  199. package/src/array/zipWith.spec.ts +0 -13
  200. package/src/array/zipWith.ts +0 -23
  201. package/src/function/debounce.spec.ts +0 -76
  202. package/src/function/debounce.ts +0 -42
  203. package/src/function/index.ts +0 -3
  204. package/src/function/once.spec.ts +0 -31
  205. package/src/function/once.ts +0 -34
  206. package/src/function/throttle.spec.ts +0 -32
  207. package/src/function/throttle.ts +0 -39
  208. package/src/index.ts +0 -6
  209. package/src/math/clamp.spec.ts +0 -18
  210. package/src/math/clamp.ts +0 -17
  211. package/src/math/index.ts +0 -3
  212. package/src/math/round.spec.ts +0 -53
  213. package/src/math/round.ts +0 -16
  214. package/src/math/sum.spec.ts +0 -29
  215. package/src/math/sum.ts +0 -17
  216. package/src/object/index.ts +0 -4
  217. package/src/object/omit.spec.ts +0 -10
  218. package/src/object/omit.ts +0 -15
  219. package/src/object/omitBy.ts +0 -3
  220. package/src/object/pick.spec.ts +0 -10
  221. package/src/object/pick.ts +0 -15
  222. package/src/object/pickBy.ts +0 -3
  223. package/src/predicate/index.ts +0 -4
  224. package/src/predicate/isNil.spec.ts +0 -23
  225. package/src/predicate/isNil.ts +0 -8
  226. package/src/predicate/isNotNil.spec.ts +0 -29
  227. package/src/predicate/isNotNil.ts +0 -14
  228. package/src/predicate/isNull.spec.ts +0 -23
  229. package/src/predicate/isNull.ts +0 -8
  230. package/src/predicate/isUndefined.spec.ts +0 -23
  231. package/src/predicate/isUndefined.ts +0 -8
  232. package/src/promise/delay.spec.ts +0 -13
  233. package/src/promise/delay.ts +0 -10
  234. package/src/promise/index.ts +0 -1
  235. package/tsconfig.json +0 -12
  236. package/vitest.config.mts +0 -13
@@ -1,6 +1,21 @@
1
1
  /**
2
- * @name isNull
3
2
  * Checks if the given value is null.
4
- * @param x The value to test if it is null
3
+ *
4
+ * This function tests whether the provided value is strictly equal to `null`.
5
+ * It returns `true` if the value is `null`, and `false` otherwise.
6
+ *
7
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null`.
8
+ *
9
+ * @param {unknown} x - The value to test if it is null.
10
+ * @returns {x is null} True if the value is null, false otherwise.
11
+ *
12
+ * @example
13
+ * * const value1 = null;
14
+ * const value2 = undefined;
15
+ * const value3 = 42;
16
+ *
17
+ * console.log(isNull(value1)); // true
18
+ * console.log(isNull(value2)); // false
19
+ * console.log(isNull(value3)); // false
5
20
  */
6
21
  export declare function isNull(x: unknown): x is null;
@@ -1,6 +1,21 @@
1
1
  /**
2
- * @name isUndefined
3
2
  * Checks if the given value is undefined.
4
- * @param x The value to test if it is undefined
3
+ *
4
+ * This function tests whether the provided value is strictly equal to `undefined`.
5
+ * It returns `true` if the value is `undefined`, and `false` otherwise.
6
+ *
7
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `undefined`.
8
+ *
9
+ * @param {unknown} x - The value to test if it is undefined.
10
+ * @returns {x is undefined} true if the value is undefined, false otherwise.
11
+ *
12
+ * @example
13
+ * * const value1 = undefined;
14
+ * const value2 = null;
15
+ * const value3 = 42;
16
+ *
17
+ * console.log(isUndefined(value1)); // true
18
+ * console.log(isUndefined(value2)); // false
19
+ * console.log(isUndefined(value3)); // false
5
20
  */
6
21
  export declare function isUndefined(x: unknown): x is undefined;
@@ -1,6 +1,19 @@
1
1
  /**
2
- * @name delay
3
- * Pause the execution of a function for given milliseconds.
4
- * @param ms The amount of time to delay the function.
2
+ * Delays the execution of code for a specified number of milliseconds.
3
+ *
4
+ * This function returns a Promise that resolves after the specified delay, allowing you to use it
5
+ * with async/await to pause execution.
6
+ *
7
+ * @param {number} ms - The number of milliseconds to delay.
8
+ * @returns {Promise<void>} A Promise that resolves after the specified delay.
9
+ *
10
+ * @example
11
+ * async function foo() {
12
+ * console.log('Start');
13
+ * await delay(1000); // Delays execution for 1 second
14
+ * console.log('End');
15
+ * }
16
+ *
17
+ * foo();
5
18
  */
6
- export declare function delay(ms: number): Promise<unknown>;
19
+ export declare function delay(ms: number): Promise<void>;
@@ -3,9 +3,22 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  /**
6
- * @name delay
7
- * Pause the execution of a function for given milliseconds.
8
- * @param ms The amount of time to delay the function.
6
+ * Delays the execution of code for a specified number of milliseconds.
7
+ *
8
+ * This function returns a Promise that resolves after the specified delay, allowing you to use it
9
+ * with async/await to pause execution.
10
+ *
11
+ * @param {number} ms - The number of milliseconds to delay.
12
+ * @returns {Promise<void>} A Promise that resolves after the specified delay.
13
+ *
14
+ * @example
15
+ * async function foo() {
16
+ * console.log('Start');
17
+ * await delay(1000); // Delays execution for 1 second
18
+ * console.log('End');
19
+ * }
20
+ *
21
+ * foo();
9
22
  */
10
23
  function delay(ms) {
11
24
  return new Promise(function (resolve) {
@@ -1,42 +1,9 @@
1
- function _iterableToArrayLimit(r, l) {
2
- var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
3
- if (null != t) {
4
- var e,
5
- n,
6
- i,
7
- u,
8
- a = [],
9
- f = !0,
10
- o = !1;
11
- try {
12
- if (i = (t = t.call(r)).next, 0 === l) {
13
- if (Object(t) !== t) return;
14
- f = !1;
15
- } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
16
- } catch (r) {
17
- o = !0, n = r;
18
- } finally {
19
- try {
20
- if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
21
- } finally {
22
- if (o) throw n;
23
- }
24
- }
25
- return a;
26
- }
27
- }
28
- function _slicedToArray(arr, i) {
29
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
30
- }
31
1
  function _toConsumableArray(arr) {
32
2
  return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
33
3
  }
34
4
  function _arrayWithoutHoles(arr) {
35
5
  if (Array.isArray(arr)) return _arrayLikeToArray(arr);
36
6
  }
37
- function _arrayWithHoles(arr) {
38
- if (Array.isArray(arr)) return arr;
39
- }
40
7
  function _iterableToArray(iter) {
41
8
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
42
9
  }
@@ -56,9 +23,6 @@ function _arrayLikeToArray(arr, len) {
56
23
  function _nonIterableSpread() {
57
24
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
58
25
  }
59
- function _nonIterableRest() {
60
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
61
- }
62
26
  function _createForOfIteratorHelper(o, allowArrayLike) {
63
27
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
64
28
  if (!it) {
@@ -111,4 +75,4 @@ function _createForOfIteratorHelper(o, allowArrayLike) {
111
75
  };
112
76
  }
113
77
 
114
- export { _arrayLikeToArray as arrayLikeToArray, _arrayWithHoles as arrayWithHoles, _arrayWithoutHoles as arrayWithoutHoles, _createForOfIteratorHelper as createForOfIteratorHelper, _iterableToArray as iterableToArray, _iterableToArrayLimit as iterableToArrayLimit, _nonIterableRest as nonIterableRest, _nonIterableSpread as nonIterableSpread, _slicedToArray as slicedToArray, _toConsumableArray as toConsumableArray, _unsupportedIterableToArray as unsupportedIterableToArray };
78
+ export { _arrayLikeToArray as arrayLikeToArray, _arrayWithoutHoles as arrayWithoutHoles, _createForOfIteratorHelper as createForOfIteratorHelper, _iterableToArray as iterableToArray, _nonIterableSpread as nonIterableSpread, _toConsumableArray as toConsumableArray, _unsupportedIterableToArray as unsupportedIterableToArray };
@@ -1,33 +1,36 @@
1
- import { createForOfIteratorHelper as _createForOfIteratorHelper, slicedToArray as _slicedToArray } from './_virtual/_rollupPluginBabelHelpers.mjs';
2
-
3
1
  /**
4
- * @name chunk
5
- * Separate an array into smaller arrays of length `size`.
6
- * If the array cannot be separated in equal size, the final sub-array will have the remaining elements.
7
- * @param arr The array to chunk
8
- * @param size The size of smaller arrays
2
+ * Splits an array into smaller arrays of a specified length.
3
+ *
4
+ * This function takes an input array and divides it into multiple smaller arrays,
5
+ * each of a specified length. If the input array cannot be evenly divided,
6
+ * the final sub-array will contain the remaining elements.
7
+ *
8
+ * @template T The type of elements in the array.
9
+ * @param {T[]} arr - The array to be chunked into smaller arrays.
10
+ * @param {number} size - The size of each smaller array. Must be a positive integer.
11
+ * @returns {T[][]} A two-dimensional array where each sub-array has a maximum length of `size`.
12
+ * @throws {Error} Throws an error if `size` is not a positive integer.
13
+ *
14
+ * @example
15
+ * // Splits an array of numbers into sub-arrays of length 2
16
+ * chunk([1, 2, 3, 4, 5], 2);
17
+ * // Returns: [[1, 2], [3, 4], [5]]
18
+ *
19
+ * @example
20
+ * // Splits an array of strings into sub-arrays of length 3
21
+ * chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3);
22
+ * // Returns: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']]
9
23
  */
10
24
  function chunk(arr, size) {
11
25
  if (!Number.isInteger(size) || size <= 0) {
12
- throw new Error("Size must be an integer greater than zero.");
26
+ throw new Error('Size must be an integer greater than zero.');
13
27
  }
14
- var result = [];
15
- var _iterator = _createForOfIteratorHelper(arr.entries()),
16
- _step;
17
- try {
18
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
19
- var _step$value = _slicedToArray(_step.value, 2),
20
- index = _step$value[0],
21
- item = _step$value[1];
22
- if (index % size === 0) {
23
- result.push([]);
24
- }
25
- result[result.length - 1].push(item);
26
- }
27
- } catch (err) {
28
- _iterator.e(err);
29
- } finally {
30
- _iterator.f();
28
+ var chunkLength = Math.ceil(arr.length / size);
29
+ var result = Array(chunkLength);
30
+ for (var index = 0; index < chunkLength; index++) {
31
+ var start = index * size;
32
+ var end = start + size;
33
+ result[index] = arr.slice(start, end);
31
34
  }
32
35
  return result;
33
36
  }
@@ -1,8 +1,24 @@
1
1
  /**
2
- * @name difference
3
- * Returns the difference of two arrays.
4
- * @param firstArr The array to get the difference from
5
- * @param secondArr The elements to exclude from `firstArr`
2
+ * Computes the difference between two arrays.
3
+ *
4
+ * This function takes two arrays and returns a new array containing the elements
5
+ * that are present in the first array but not in the second array. It effectively
6
+ * filters out any elements from the first array that also appear in the second array.
7
+ *
8
+ * @template T
9
+ * @param {T[]} firstArr - The array from which to derive the difference. This is the primary array
10
+ * from which elements will be compared and filtered.
11
+ * @param {T[]} secondArr - The array containing elements to be excluded from the first array.
12
+ * Each element in this array will be checked against the first array, and if a match is found,
13
+ * that element will be excluded from the result.
14
+ * @returns {T[]} A new array containing the elements that are present in the first array but not
15
+ * in the second array.
16
+ *
17
+ * @example
18
+ * * const array1 = [1, 2, 3, 4, 5];
19
+ * const array2 = [2, 4];
20
+ * const result = difference(array1, array2);
21
+ * // result will be [1, 3, 5] since 2 and 4 are in both arrays and are excluded from the result.
6
22
  */
7
23
  function difference(firstArr, secondArr) {
8
24
  return firstArr.filter(function (item) {
@@ -1,9 +1,27 @@
1
1
  /**
2
- * @name differenceBy
3
- * Returns the difference of two arrays. The identity of two elements is calculated after the elements are mapped with `mapper`.
4
- * @param firstArr The array to get the difference from
5
- * @param secondArr The elements to exclude from `firstArr`
6
- * @param mapper The function to map the elements when calculating the difference
2
+ * Computes the difference between two arrays after mapping their elements through a provided function.
3
+ *
4
+ * This function takes two arrays and a mapper function. It returns a new array containing the elements
5
+ * that are present in the first array but not in the second array, based on the identity calculated
6
+ * by the mapper function.
7
+ *
8
+ * Essentially, it filters out any elements from the first array that, when
9
+ * mapped, match an element in the mapped version of the second array.
10
+ *
11
+ * @template T, U
12
+ * @param {T[]} firstArr - The primary array from which to derive the difference.
13
+ * @param {T[]} secondArr - The array containing elements to be excluded from the first array.
14
+ * @param {(value: T) => U} mapper - The function to map the elements of both arrays. This function
15
+ * is applied to each element in both arrays, and the comparison is made based on the mapped values.
16
+ * @returns {T[]} A new array containing the elements from the first array that do not have a corresponding
17
+ * mapped identity in the second array.
18
+ *
19
+ * @example
20
+ * * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
21
+ * const array2 = [{ id: 2 }, { id: 4 }];
22
+ * const mapper = item => item.id;
23
+ * const result = differenceBy(array1, array2, mapper);
24
+ * // result will be [{ id: 1 }, { id: 3 }] since the elements with id 2 are in both arrays and are excluded from the result.
7
25
  */
8
26
  function differenceBy(firstArr, secondArr, mapper) {
9
27
  var mappedSecondArr = secondArr.map(function (item) {
@@ -1,9 +1,23 @@
1
1
  /**
2
- * @name differenceWith
3
- * Returns the difference of two arrays. The identity of two elements is calculated with the function `areItemsEqual`.
4
- * @param firstArr The array to get the difference from
5
- * @param secondArr The elements to exclude from `firstArr`
6
- * @param areItemsEqual The function to determine whether two items are equal
2
+ * Computes the difference between two arrays based on a custom equality function.
3
+ *
4
+ * This function takes two arrays and a custom comparison function. It returns a new array containing
5
+ * the elements that are present in the first array but not in the second array. The comparison to determine
6
+ * if elements are equal is made using the provided custom function.
7
+ *
8
+ * @template T
9
+ * @param {T[]} firstArr - The array from which to get the difference.
10
+ * @param {T[]} secondArr - The array containing elements to exclude from the first array.
11
+ * @param {(x: T, y: T) => boolean} areItemsEqual - A function to determine if two items are equal.
12
+ * @returns {T[]} A new array containing the elements from the first array that do not match any elements in the second array
13
+ * according to the custom equality function.
14
+ *
15
+ * @example
16
+ * * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
17
+ * const array2 = [{ id: 2 }, { id: 4 }];
18
+ * const areItemsEqual = (a, b) => a.id === b.id;
19
+ * const result = differenceWith(array1, array2, areItemsEqual);
20
+ * // result will be [{ id: 1 }, { id: 3 }] since the elements with id 2 are considered equal and are excluded from the result.
7
21
  */
8
22
  function differenceWith(firstArr, secondArr, areItemsEqual) {
9
23
  return firstArr.filter(function (firstItem) {
@@ -1,8 +1,17 @@
1
1
  /**
2
- * @name drop
3
- * Drop some elements from an array from the beginning. This function returns a new array.
4
- * @param arr The element to drop items from the beginning
5
- * @param itemsCount The amount of elements to drop
2
+ * Removes a specified number of elements from the beginning of an array and returns the rest.
3
+ *
4
+ * This function takes an array and a number, and returns a new array with the specified number
5
+ * of elements removed from the start.
6
+ *
7
+ * @param {T[]} arr - The array from which to drop elements.
8
+ * @param {number} itemsCount - The number of elements to drop from the beginning of the array.
9
+ * @returns {T[]} A new array with the specified number of elements removed from the start.
10
+ *
11
+ * @example
12
+ * * const array = [1, 2, 3, 4, 5];
13
+ * const result = drop(array, 2);
14
+ * // result will be [3, 4, 5] since the first two elements are dropped.
6
15
  */
7
16
  function drop(arr, itemsCount) {
8
17
  return arr.slice(itemsCount);
@@ -1,8 +1,17 @@
1
1
  /**
2
- * @name dropRight
3
- * Drop some elements from an array from the end. This function returns a new array.
4
- * @param arr The element to drop items from the end
5
- * @param itemsCount The amount of elements to drop
2
+ * Removes a specified number of elements from the end of an array and returns the rest.
3
+ *
4
+ * This function takes an array and a number, and returns a new array with the specified number
5
+ * of elements removed from the end.
6
+ *
7
+ * @param {T[]} arr - The array from which to drop elements.
8
+ * @param {number} itemsCount - The number of elements to drop from the end of the array.
9
+ * @returns {T[]} A new array with the specified number of elements removed from the end.
10
+ *
11
+ * @example
12
+ * * const array = [1, 2, 3, 4, 5];
13
+ * const result = dropRight(array, 2);
14
+ * // result will be [1, 2, 3] since the last two elements are dropped.
6
15
  */
7
16
  function dropRight(arr, itemsCount) {
8
17
  return arr.slice(0, -itemsCount);
@@ -1,10 +1,21 @@
1
1
  import { dropWhile } from './dropWhile.mjs';
2
2
 
3
3
  /**
4
- * @name dropRightWhile
5
- * Drop some elements from an array from the end, until `predicate` returns false.
6
- * @param arr The element to drop items from the end
7
- * @param canContinueDropping The predicate to check if the function can continue dropping elements.
4
+ * Removes elements from the end of an array until the predicate returns false.
5
+ *
6
+ * This function iterates over an array from the end and drops elements until the provided
7
+ * predicate function returns false. It then returns a new array with the remaining elements.
8
+ *
9
+ * @param {T[]} arr - The array from which to drop elements.
10
+ * @param {function(item: T): boolean} canContinueDropping - A predicate function that determines
11
+ * whether to continue dropping elements. The function is called with each element from the end,
12
+ * and dropping continues as long as it returns true.
13
+ * @returns {T[]} A new array with the elements remaining after the predicate returns false.
14
+ *
15
+ * @example
16
+ * const array = [1, 2, 3, 4, 5];
17
+ * const result = dropRightWhile(array, x => x > 3);
18
+ * // result will be [1, 2, 3] since elements greater than 3 are dropped from the end.
8
19
  */
9
20
  function dropRightWhile(arr, canContinueDropping) {
10
21
  var reversed = arr.slice().reverse();
@@ -1,8 +1,19 @@
1
1
  /**
2
- * @name dropWhile
3
- * Drop some elements from an array from the beginning, until `predicate` returns false.
4
- * @param arr The element to drop items from the beginning
5
- * @param canContinueDropping The predicate to check if the function can continue dropping elements.
2
+ * Removes elements from the beginning of an array until the predicate returns false.
3
+ *
4
+ * This function iterates over an array and drops elements from the start until the provided
5
+ * predicate function returns false. It then returns a new array with the remaining elements.
6
+ *
7
+ * @param {T[]} arr - The array from which to drop elements.
8
+ * @param {(item: T) => boolean} canContinueDropping - A predicate function that determines
9
+ * whether to continue dropping elements. The function is called with each element, and dropping
10
+ * continues as long as it returns true.
11
+ * @returns {T[]} A new array with the elements remaining after the predicate returns false.
12
+ *
13
+ * @example
14
+ * const array = [1, 2, 3, 4, 5];
15
+ * const result = dropWhile(array, x => x < 3);
16
+ * // result will be [3, 4, 5] since elements less than 3 are dropped.
6
17
  */
7
18
  function dropWhile(arr, canContinueDropping) {
8
19
  var dropEndIndex = arr.findIndex(function (item) {
@@ -1,5 +1,54 @@
1
- function groupBy() {
2
- throw new Error('Not implemented');
1
+ import { createForOfIteratorHelper as _createForOfIteratorHelper } from './_virtual/_rollupPluginBabelHelpers.mjs';
2
+
3
+ /**
4
+ * Groups the elements of an array based on a provided key-generating function.
5
+ *
6
+ * This function takes an array and a function that generates a key from each element. It returns
7
+ * an object where the keys are the generated keys and the values are arrays of elements that share
8
+ * the same key.
9
+ *
10
+ * @param {T[]} arr - The array to group.
11
+ * @param {(item: T) => K} getKeyFromItem - A function that generates a key from an element.
12
+ * @returns {Record<K, T[]>} An object where each key is associated with an array of elements that
13
+ * share that key.
14
+ *
15
+ * @example
16
+ * const array = [
17
+ * { category: 'fruit', name: 'apple' },
18
+ * { category: 'fruit', name: 'banana' },
19
+ * { category: 'vegetable', name: 'carrot' }
20
+ * ];
21
+ * const result = groupBy(array, item => item.category);
22
+ * // result will be:
23
+ * // {
24
+ * // fruit: [
25
+ * // { category: 'fruit', name: 'apple' },
26
+ * // { category: 'fruit', name: 'banana' }
27
+ * // ],
28
+ * // vegetable: [
29
+ * // { category: 'vegetable', name: 'carrot' }
30
+ * // ]
31
+ * // }
32
+ */
33
+ function groupBy(arr, getKeyFromItem) {
34
+ var result = {};
35
+ var _iterator = _createForOfIteratorHelper(arr),
36
+ _step;
37
+ try {
38
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
39
+ var item = _step.value;
40
+ var key = getKeyFromItem(item);
41
+ if (result[key] == null) {
42
+ result[key] = [];
43
+ }
44
+ result[key].push(item);
45
+ }
46
+ } catch (err) {
47
+ _iterator.e(err);
48
+ } finally {
49
+ _iterator.f();
50
+ }
51
+ return result;
3
52
  }
4
53
 
5
54
  export { groupBy };
@@ -1,12 +1,19 @@
1
1
  /**
2
- * @name intersection
3
- * @description
4
2
  * Returns the intersection of two arrays.
5
- * @param firstArr The first array to get the intersection
6
- * @param secondArr The second array to get the intersection
3
+ *
4
+ * This function takes two arrays and returns a new array containing the elements that are
5
+ * present in both arrays. It effectively filters out any elements from the first array that
6
+ * are not found in the second array.
7
+ *
8
+ * @param {T[]} firstArr - The first array to compare.
9
+ * @param {T[]} secondArr - The second array to compare.
10
+ * @returns {T[]} A new array containing the elements that are present in both arrays.
11
+ *
7
12
  * @example
8
- * intersection([1, 2], [1, 3]) === [1]
9
- * intersection([1, 2, 3], [2, 3, 4]) === [2, 3]
13
+ * const array1 = [1, 2, 3, 4, 5];
14
+ * const array2 = [3, 4, 5, 6, 7];
15
+ * const result = intersection(array1, array2);
16
+ * // result will be [3, 4, 5] since these elements are in both arrays.
10
17
  */
11
18
  function intersection(firstArr, secondArr) {
12
19
  return firstArr.filter(function (item) {
@@ -1,13 +1,22 @@
1
1
  /**
2
- * @name intersectionBy
3
- * @description
4
- * Returns the intersection of two arrays. The identity of two elements is calculated after the elements are mapped with `mapper`.
5
- * @param firstArr The first array to get the intersection
6
- * @param secondArr The second array to get the intersection
7
- * @param mapper The function to map the elements when calculating the intersection
2
+ * Returns the intersection of two arrays based on a mapping function.
3
+ *
4
+ * This function takes two arrays and a mapping function. It returns a new array containing
5
+ * the elements from the first array that, when mapped using the provided function, have matching
6
+ * mapped elements in the second array. It effectively filters out any elements from the first array
7
+ * that do not have corresponding mapped values in the second array.
8
+ *
9
+ * @param {T[]} firstArr - The first array to compare.
10
+ * @param {T[]} secondArr - The second array to compare.
11
+ * @param {(item: T) => U} mapper - A function to map the elements of both arrays for comparison.
12
+ * @returns {T[]} A new array containing the elements from the first array that have corresponding mapped values in the second array.
13
+ *
8
14
  * @example
9
- * intersectionBy([1.2, 2.1], [1.4, 3.1], Math.floor) === [1.2]
10
- * intersectionBy([{ foo: 1 }, { foo: 2 }], [{ foo: 1 }, { foo: 3 }], x => x.foo) === [{ foo: 1 }]
15
+ * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
16
+ * const array2 = [{ id: 2 }, { id: 4 }];
17
+ * const mapper = item => item.id;
18
+ * const result = intersectionBy(array1, array2, mapper);
19
+ * // result will be [{ id: 2 }] since only this element has a matching id in both arrays.
11
20
  */
12
21
  function intersectionBy(firstArr, secondArr, mapper) {
13
22
  var mappedSecondArr = secondArr.map(function (x) {
@@ -1,13 +1,23 @@
1
1
  /**
2
- * @name intersectionWith
3
- * @description
4
- * Returns the intersection of two arrays. The identity of two elements is compared with `areItemsEqual`.
5
- * @param firstArr The first array to get the intersection
6
- * @param secondArr The second array to get the intersection
7
- * @param areItemsEqual The function to compare the identity of two elements
2
+ * Returns the intersection of two arrays based on a custom equality function.
3
+ *
4
+ * This function takes two arrays and a custom equality function. It returns a new array containing
5
+ * the elements from the first array that have matching elements in the second array, as determined
6
+ * by the custom equality function. It effectively filters out any elements from the first array that
7
+ * do not have corresponding matches in the second array according to the equality function.
8
+ *
9
+ * @param {T[]} firstArr - The first array to compare.
10
+ * @param {T[]} secondArr - The second array to compare.
11
+ * @param {(x: T, y: T) => boolean} areItemsEqual - A custom function to determine if two elements are equal.
12
+ * This function takes two arguments, one from each array, and returns `true` if the elements are considered equal, and `false` otherwise.
13
+ * @returns {T[]} A new array containing the elements from the first array that have corresponding matches in the second array according to the custom equality function.
14
+ *
8
15
  * @example
9
- * intersectionWith([1.2, 2.1], [1.4, 3.1], (x, y) => Math.floor(x) === Math.floor(y)) === [1.2]
10
- * intersectionWith([{ foo: 1 }, { foo: 2 }], [{ foo: 1 }, { foo: 3 }], (x, y) => x.foo === y.foo) === [{ foo: 1 }]
16
+ * * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
17
+ * const array2 = [{ id: 2 }, { id: 4 }];
18
+ * const areItemsEqual = (a, b) => a.id === b.id;
19
+ * const result = intersectionWith(array1, array2, areItemsEqual);
20
+ * // result will be [{ id: 2 }] since this element has a matching id in both arrays.
11
21
  */
12
22
  function intersectionWith(firstArr, secondArr, areItemsEqual) {
13
23
  return firstArr.filter(function (firstItem) {
@@ -1,11 +1,25 @@
1
1
  import { createForOfIteratorHelper as _createForOfIteratorHelper } from './_virtual/_rollupPluginBabelHelpers.mjs';
2
2
 
3
3
  /**
4
- * @name partition
5
- * @description
6
- * Creates two arrays: the first array includes items for which isInTruthy returns true, and the second array includes items for which isInTruthy returns false.
7
- * @param arr The array to split into two arrays
8
- * @param isInTruthy The predicate to tell whether an item is included in the first array
4
+ * Splits an array into two groups based on a predicate function.
5
+ *
6
+ * This function takes an array and a predicate function. It returns a tuple of two arrays:
7
+ * the first array contains elements for which the predicate function returns true, and
8
+ * the second array contains elements for which the predicate function returns false.
9
+ *
10
+ * @param {T[]} arr - The array to partition.
11
+ * @param {(value: T) => boolean} isInTruthy - A predicate function that determines
12
+ * whether an element should be placed in the truthy array. The function is called with each
13
+ * element of the array.
14
+ * @returns {[T[], T[]]} A tuple containing two arrays: the first array contains elements for
15
+ * which the predicate returned true, and the second array contains elements for which the
16
+ * predicate returned false.
17
+ *
18
+ * @example
19
+ * const array = [1, 2, 3, 4, 5];
20
+ * const isEven = x => x % 2 === 0;
21
+ * const [even, odd] = partition(array, isEven);
22
+ * // even will be [2, 4], and odd will be [1, 3, 5]
9
23
  */
10
24
  function partition(arr, isInTruthy) {
11
25
  var truthy = [];
@@ -1,8 +1,15 @@
1
1
  /**
2
- * @name sample
3
- * @description
4
2
  * Returns a random element from an array.
5
- * @param arr The element to get a random element
3
+ *
4
+ * This function takes an array and returns a single element selected randomly from the array.
5
+ *
6
+ * @param {T[]} arr - The array to sample from.
7
+ * @returns {T} A random element from the array.
8
+ *
9
+ * @example
10
+ * const array = [1, 2, 3, 4, 5];
11
+ * const randomElement = sample(array);
12
+ * // randomElement will be one of the elements from the array, selected randomly.
6
13
  */
7
14
  function sample(arr) {
8
15
  var randomIndex = Math.floor(Math.random() * arr.length);