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
package/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # es-toolkit Changelog
2
+
3
+ ## Version v1.0.0
4
+
5
+ Initial release. Released on May 31th, 2024.
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ ![](./docs/public/og.png)
2
+
3
+ # es-toolkit · [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/toss/slash/blob/main/LICENSE)
4
+
5
+ English | [한국어](./README-ko_kr.md)
6
+
7
+ es-toolkit is a state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.
8
+
9
+ - es-toolkit offers a variety of everyday utility functions with modern implementations, such as [debounce](https://es-toolkit.slash.page/reference/function/debounce.html), [delay](https://es-toolkit.slash.page/reference/promise/delay.html), [chunk](https://es-toolkit.slash.page/reference/array/chunk.html), [sum](https://es-toolkit.slash.page/reference/math/sum.html), and [pick](https://es-toolkit.slash.page/reference/object/pick.html).
10
+ - Designed with performance in mind, es-toolkit achieves [2-3× better performance](https://es-toolkit.slash.page/performance.html) in modern JavaScript environments.
11
+ - es-toolkit supports tree shaking out of the box, and [reduces JavaScript code by up to 97%](https://es-toolkit.slash.page/bundle-size.html) compared to other libraries.
12
+ - es-toolkit includes built-in TypeScript support, with straightforward yet robust types. It also provides useful type guards such as [isNotNil](https://es-toolkit.slash.page/reference/predicate/isNotNil.html).
13
+ - es-toolkit is battle-tested with 100% test coverage, ensuring reliability and robustness.
14
+
15
+
16
+ ## Contributing
17
+
18
+ We welcome contribution from everyone in the community. Read below for detailed contribution guide.
19
+
20
+ [CONTRIBUTING](./.github/CONTRIBUTING.md)
21
+
22
+ ## License
23
+
24
+ MIT © Viva Republica, Inc. See [LICENSE](./LICENSE) for details.
25
+
26
+ <a title="Toss" href="https://toss.im">
27
+ <picture>
28
+ <source media="(prefers-color-scheme: dark)" srcset="https://static.toss.im/logos/png/4x/logo-toss-reverse.png">
29
+ <img alt="Toss" src="https://static.toss.im/logos/png/4x/logo-toss.png" width="100">
30
+ </picture>
31
+ </a>
@@ -1,8 +1,24 @@
1
1
  /**
2
- * @name chunk
3
- * Separate an array into smaller arrays of length `size`.
4
- * If the array cannot be separated in equal size, the final sub-array will have the remaining elements.
5
- * @param arr The array to chunk
6
- * @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']]
7
23
  */
8
24
  export declare function chunk<T>(arr: T[], size: number): T[][];
@@ -1,7 +1,23 @@
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
  export declare function difference<T>(firstArr: T[], secondArr: T[]): T[];
@@ -1,8 +1,26 @@
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
  export declare function differenceBy<T, U>(firstArr: T[], secondArr: T[], mapper: (value: T) => U): T[];
@@ -1,8 +1,22 @@
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
  export declare function differenceWith<T>(firstArr: T[], secondArr: T[], areItemsEqual: (x: T, y: T) => boolean): T[];
@@ -1,7 +1,16 @@
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
  export declare function drop<T>(arr: T[], itemsCount: number): T[];
@@ -1,7 +1,16 @@
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
  export declare function dropRight<T>(arr: T[], itemsCount: number): T[];
@@ -1,7 +1,18 @@
1
1
  /**
2
- * @name dropRightWhile
3
- * Drop some elements from an array from the end, until `predicate` returns false.
4
- * @param arr The element to drop items from the end
5
- * @param canContinueDropping The predicate to check if the function can continue dropping elements.
2
+ * Removes elements from the end of an array until the predicate returns false.
3
+ *
4
+ * This function iterates over an array from the end and drops elements 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 {function(item: T): boolean} canContinueDropping - A predicate function that determines
9
+ * whether to continue dropping elements. The function is called with each element from the end,
10
+ * and dropping 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 = dropRightWhile(array, x => x > 3);
16
+ * // result will be [1, 2, 3] since elements greater than 3 are dropped from the end.
6
17
  */
7
18
  export declare function dropRightWhile<T>(arr: T[], canContinueDropping: (item: T) => boolean): T[];
@@ -1,7 +1,18 @@
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
  export declare function dropWhile<T>(arr: T[], canContinueDropping: (item: T) => boolean): T[];
@@ -1 +1,31 @@
1
- export declare function groupBy(): void;
1
+ /**
2
+ * Groups the elements 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 arrays of elements that share
6
+ * the same key.
7
+ *
8
+ * @param {T[]} arr - The array to group.
9
+ * @param {(item: T) => K} getKeyFromItem - A function that generates a key from an element.
10
+ * @returns {Record<K, T[]>} An object where each key is associated with an array of elements that
11
+ * share that key.
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 = groupBy(array, item => item.category);
20
+ * // result will be:
21
+ * // {
22
+ * // fruit: [
23
+ * // { category: 'fruit', name: 'apple' },
24
+ * // { category: 'fruit', name: 'banana' }
25
+ * // ],
26
+ * // vegetable: [
27
+ * // { category: 'vegetable', name: 'carrot' }
28
+ * // ]
29
+ * // }
30
+ */
31
+ export declare function groupBy<T, K extends string>(arr: T[], getKeyFromItem: (item: T) => K): Record<K, T[]>;
@@ -0,0 +1 @@
1
+ export {};