es-toolkit 0.0.1

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 (303) hide show
  1. package/.vscode/extensions.json +7 -0
  2. package/.vscode/settings.json +10 -0
  3. package/.yarn/sdks/eslint/bin/eslint.js +20 -0
  4. package/.yarn/sdks/eslint/lib/api.js +20 -0
  5. package/.yarn/sdks/eslint/lib/unsupported-api.js +20 -0
  6. package/.yarn/sdks/eslint/package.json +14 -0
  7. package/.yarn/sdks/integrations.yml +5 -0
  8. package/.yarn/sdks/prettier/bin/prettier.cjs +20 -0
  9. package/.yarn/sdks/prettier/index.cjs +20 -0
  10. package/.yarn/sdks/prettier/package.json +7 -0
  11. package/.yarn/sdks/typescript/bin/tsc +20 -0
  12. package/.yarn/sdks/typescript/bin/tsserver +20 -0
  13. package/.yarn/sdks/typescript/lib/tsc.js +20 -0
  14. package/.yarn/sdks/typescript/lib/tsserver.js +225 -0
  15. package/.yarn/sdks/typescript/lib/tsserverlibrary.js +225 -0
  16. package/.yarn/sdks/typescript/lib/typescript.js +20 -0
  17. package/.yarn/sdks/typescript/package.json +10 -0
  18. package/babel.config.js +6 -0
  19. package/coverage/.tmp/coverage-0.json +1 -0
  20. package/coverage/.tmp/coverage-1.json +1 -0
  21. package/coverage/.tmp/coverage-10.json +1 -0
  22. package/coverage/.tmp/coverage-11.json +1 -0
  23. package/coverage/.tmp/coverage-12.json +1 -0
  24. package/coverage/.tmp/coverage-13.json +1 -0
  25. package/coverage/.tmp/coverage-14.json +1 -0
  26. package/coverage/.tmp/coverage-15.json +1 -0
  27. package/coverage/.tmp/coverage-16.json +1 -0
  28. package/coverage/.tmp/coverage-17.json +1 -0
  29. package/coverage/.tmp/coverage-18.json +1 -0
  30. package/coverage/.tmp/coverage-19.json +1 -0
  31. package/coverage/.tmp/coverage-2.json +1 -0
  32. package/coverage/.tmp/coverage-20.json +1 -0
  33. package/coverage/.tmp/coverage-21.json +1 -0
  34. package/coverage/.tmp/coverage-22.json +1 -0
  35. package/coverage/.tmp/coverage-23.json +1 -0
  36. package/coverage/.tmp/coverage-24.json +1 -0
  37. package/coverage/.tmp/coverage-25.json +1 -0
  38. package/coverage/.tmp/coverage-26.json +1 -0
  39. package/coverage/.tmp/coverage-27.json +1 -0
  40. package/coverage/.tmp/coverage-28.json +1 -0
  41. package/coverage/.tmp/coverage-29.json +1 -0
  42. package/coverage/.tmp/coverage-3.json +1 -0
  43. package/coverage/.tmp/coverage-30.json +1 -0
  44. package/coverage/.tmp/coverage-4.json +1 -0
  45. package/coverage/.tmp/coverage-5.json +1 -0
  46. package/coverage/.tmp/coverage-6.json +1 -0
  47. package/coverage/.tmp/coverage-7.json +1 -0
  48. package/coverage/.tmp/coverage-8.json +1 -0
  49. package/coverage/.tmp/coverage-9.json +1 -0
  50. package/dist/array/chunk.d.ts +8 -0
  51. package/dist/array/chunk.spec.d.ts +1 -0
  52. package/dist/array/difference.d.ts +7 -0
  53. package/dist/array/difference.spec.d.ts +1 -0
  54. package/dist/array/differenceBy.d.ts +8 -0
  55. package/dist/array/differenceBy.spec.d.ts +1 -0
  56. package/dist/array/differenceWith.d.ts +8 -0
  57. package/dist/array/differenceWith.spec.d.ts +1 -0
  58. package/dist/array/drop.d.ts +7 -0
  59. package/dist/array/drop.spec.d.ts +1 -0
  60. package/dist/array/dropRight.d.ts +7 -0
  61. package/dist/array/dropRight.spec.d.ts +1 -0
  62. package/dist/array/dropRightWhile.d.ts +7 -0
  63. package/dist/array/dropRightWhile.spec.d.ts +1 -0
  64. package/dist/array/dropWhile.d.ts +7 -0
  65. package/dist/array/dropWhile.spec.d.ts +1 -0
  66. package/dist/array/groupBy.d.ts +1 -0
  67. package/dist/array/index.d.ts +30 -0
  68. package/dist/array/index.js +778 -0
  69. package/dist/array/intersection.d.ts +11 -0
  70. package/dist/array/intersection.spec.d.ts +1 -0
  71. package/dist/array/intersectionBy.d.ts +12 -0
  72. package/dist/array/intersectionBy.spec.d.ts +1 -0
  73. package/dist/array/intersectionWith.d.ts +12 -0
  74. package/dist/array/intersectionWith.spec.d.ts +1 -0
  75. package/dist/array/partition.d.ts +8 -0
  76. package/dist/array/partition.spec.d.ts +1 -0
  77. package/dist/array/sample.d.ts +7 -0
  78. package/dist/array/sample.spec.d.ts +1 -0
  79. package/dist/array/shuffle.d.ts +7 -0
  80. package/dist/array/shuffle.spec.d.ts +1 -0
  81. package/dist/array/take.d.ts +23 -0
  82. package/dist/array/take.spec.d.ts +1 -0
  83. package/dist/array/takeRight.d.ts +23 -0
  84. package/dist/array/takeRight.spec.d.ts +1 -0
  85. package/dist/array/takeRightWhile.d.ts +18 -0
  86. package/dist/array/takeRightWhile.spec.d.ts +1 -0
  87. package/dist/array/takeWhile.d.ts +19 -0
  88. package/dist/array/takeWhile.spec.d.ts +1 -0
  89. package/dist/array/union.d.ts +10 -0
  90. package/dist/array/union.spec.d.ts +1 -0
  91. package/dist/array/unionBy.d.ts +24 -0
  92. package/dist/array/unionBy.spec.d.ts +1 -0
  93. package/dist/array/unionWith.d.ts +14 -0
  94. package/dist/array/unionWith.spec.d.ts +1 -0
  95. package/dist/array/uniq.d.ts +14 -0
  96. package/dist/array/uniq.spec.d.ts +1 -0
  97. package/dist/array/uniqBy.d.ts +12 -0
  98. package/dist/array/uniqBy.spec.d.ts +1 -0
  99. package/dist/array/uniqWith.d.ts +12 -0
  100. package/dist/array/uniqWith.spec.d.ts +1 -0
  101. package/dist/array/xor.d.ts +19 -0
  102. package/dist/array/xor.spec.d.ts +1 -0
  103. package/dist/array/xorBy.d.ts +20 -0
  104. package/dist/array/xorBy.spec.d.ts +1 -0
  105. package/dist/array/xorWith.d.ts +19 -0
  106. package/dist/array/xorWith.spec.d.ts +1 -0
  107. package/dist/array/zip.d.ts +13 -0
  108. package/dist/array/zip.spec.d.ts +1 -0
  109. package/dist/array/zipWith.d.ts +9 -0
  110. package/dist/array/zipWith.spec.d.ts +1 -0
  111. package/dist/function/debounce.d.ts +24 -0
  112. package/dist/function/debounce.spec.d.ts +1 -0
  113. package/dist/function/index.d.ts +3 -0
  114. package/dist/function/index.js +113 -0
  115. package/dist/function/once.d.ts +18 -0
  116. package/dist/function/once.spec.d.ts +1 -0
  117. package/dist/function/throttle.d.ts +26 -0
  118. package/dist/function/throttle.spec.d.ts +1 -0
  119. package/dist/index.d.ts +6 -0
  120. package/dist/index.js +1111 -0
  121. package/dist/math/clamp.d.ts +11 -0
  122. package/dist/math/clamp.spec.d.ts +1 -0
  123. package/dist/math/index.d.ts +3 -0
  124. package/dist/math/index.js +63 -0
  125. package/dist/math/round.d.ts +13 -0
  126. package/dist/math/round.spec.d.ts +1 -0
  127. package/dist/math/sum.d.ts +13 -0
  128. package/dist/math/sum.spec.d.ts +1 -0
  129. package/dist/object/index.d.ts +4 -0
  130. package/dist/object/index.js +176 -0
  131. package/dist/object/omit.d.ts +7 -0
  132. package/dist/object/omit.spec.d.ts +1 -0
  133. package/dist/object/omitBy.d.ts +1 -0
  134. package/dist/object/pick.d.ts +7 -0
  135. package/dist/object/pick.spec.d.ts +1 -0
  136. package/dist/object/pickBy.d.ts +1 -0
  137. package/dist/predicate/index.d.ts +4 -0
  138. package/dist/predicate/index.js +50 -0
  139. package/dist/predicate/isNil.d.ts +6 -0
  140. package/dist/predicate/isNil.spec.d.ts +1 -0
  141. package/dist/predicate/isNotNil.d.ts +12 -0
  142. package/dist/predicate/isNotNil.spec.d.ts +1 -0
  143. package/dist/predicate/isNull.d.ts +6 -0
  144. package/dist/predicate/isNull.spec.d.ts +1 -0
  145. package/dist/predicate/isUndefined.d.ts +6 -0
  146. package/dist/predicate/isUndefined.spec.d.ts +1 -0
  147. package/dist/promise/delay.d.ts +6 -0
  148. package/dist/promise/delay.spec.d.ts +1 -0
  149. package/dist/promise/index.d.ts +1 -0
  150. package/dist/promise/index.js +16 -0
  151. package/esm/_virtual/_rollupPluginBabelHelpers.mjs +163 -0
  152. package/esm/array/_virtual/_rollupPluginBabelHelpers.mjs +114 -0
  153. package/esm/array/chunk.mjs +35 -0
  154. package/esm/array/difference.mjs +13 -0
  155. package/esm/array/differenceBy.mjs +17 -0
  156. package/esm/array/differenceWith.mjs +16 -0
  157. package/esm/array/drop.mjs +11 -0
  158. package/esm/array/dropRight.mjs +11 -0
  159. package/esm/array/dropRightWhile.mjs +15 -0
  160. package/esm/array/dropWhile.mjs +14 -0
  161. package/esm/array/groupBy.mjs +5 -0
  162. package/esm/array/index.mjs +30 -0
  163. package/esm/array/intersection.mjs +17 -0
  164. package/esm/array/intersectionBy.mjs +21 -0
  165. package/esm/array/intersectionWith.mjs +20 -0
  166. package/esm/array/partition.mjs +32 -0
  167. package/esm/array/sample.mjs +12 -0
  168. package/esm/array/shuffle.mjs +20 -0
  169. package/esm/array/take.mjs +27 -0
  170. package/esm/array/takeRight.mjs +30 -0
  171. package/esm/array/takeRightWhile.mjs +27 -0
  172. package/esm/array/takeWhile.mjs +41 -0
  173. package/esm/array/union.mjs +19 -0
  174. package/esm/array/unionBy.mjs +38 -0
  175. package/esm/array/unionWith.mjs +21 -0
  176. package/esm/array/uniq.mjs +18 -0
  177. package/esm/array/uniqBy.mjs +20 -0
  178. package/esm/array/uniqWith.mjs +39 -0
  179. package/esm/array/xor.mjs +27 -0
  180. package/esm/array/xorBy.mjs +30 -0
  181. package/esm/array/xorWith.mjs +29 -0
  182. package/esm/array/zip.mjs +40 -0
  183. package/esm/array/zipWith.mjs +31 -0
  184. package/esm/function/debounce.mjs +39 -0
  185. package/esm/function/index.mjs +3 -0
  186. package/esm/function/once.mjs +32 -0
  187. package/esm/function/throttle.mjs +38 -0
  188. package/esm/index.mjs +45 -0
  189. package/esm/math/clamp.mjs +18 -0
  190. package/esm/math/index.mjs +3 -0
  191. package/esm/math/round.mjs +19 -0
  192. package/esm/math/sum.mjs +22 -0
  193. package/esm/object/_virtual/_rollupPluginBabelHelpers.mjs +115 -0
  194. package/esm/object/index.mjs +4 -0
  195. package/esm/object/omit.mjs +26 -0
  196. package/esm/object/omitBy.mjs +5 -0
  197. package/esm/object/pick.mjs +26 -0
  198. package/esm/object/pickBy.mjs +5 -0
  199. package/esm/predicate/index.mjs +4 -0
  200. package/esm/predicate/isNil.mjs +10 -0
  201. package/esm/predicate/isNotNil.mjs +16 -0
  202. package/esm/predicate/isNull.mjs +10 -0
  203. package/esm/predicate/isUndefined.mjs +10 -0
  204. package/esm/promise/delay.mjs +12 -0
  205. package/esm/promise/index.mjs +1 -0
  206. package/package.json +94 -0
  207. package/rollup.config.js +5 -0
  208. package/src/array/chunk.spec.ts +27 -0
  209. package/src/array/chunk.ts +24 -0
  210. package/src/array/difference.spec.ts +10 -0
  211. package/src/array/difference.ts +11 -0
  212. package/src/array/differenceBy.spec.ts +9 -0
  213. package/src/array/differenceBy.ts +14 -0
  214. package/src/array/differenceWith.spec.ts +8 -0
  215. package/src/array/differenceWith.ts +14 -0
  216. package/src/array/drop.spec.ts +9 -0
  217. package/src/array/drop.ts +9 -0
  218. package/src/array/dropRight.spec.ts +9 -0
  219. package/src/array/dropRight.ts +9 -0
  220. package/src/array/dropRightWhile.spec.ts +16 -0
  221. package/src/array/dropRightWhile.ts +13 -0
  222. package/src/array/dropWhile.spec.ts +14 -0
  223. package/src/array/dropWhile.ts +10 -0
  224. package/src/array/groupBy.ts +3 -0
  225. package/src/array/index.ts +30 -0
  226. package/src/array/intersection.spec.ts +11 -0
  227. package/src/array/intersection.ts +15 -0
  228. package/src/array/intersectionBy.spec.ts +9 -0
  229. package/src/array/intersectionBy.ts +18 -0
  230. package/src/array/intersectionWith.spec.ts +9 -0
  231. package/src/array/intersectionWith.ts +18 -0
  232. package/src/array/partition.spec.ts +23 -0
  233. package/src/array/partition.ts +21 -0
  234. package/src/array/sample.spec.ts +11 -0
  235. package/src/array/sample.ts +10 -0
  236. package/src/array/shuffle.spec.ts +11 -0
  237. package/src/array/shuffle.ts +18 -0
  238. package/src/array/take.spec.ts +25 -0
  239. package/src/array/take.ts +25 -0
  240. package/src/array/takeRight.spec.ts +25 -0
  241. package/src/array/takeRight.ts +29 -0
  242. package/src/array/takeRightWhile.spec.ts +16 -0
  243. package/src/array/takeRightWhile.ts +26 -0
  244. package/src/array/takeWhile.spec.ts +34 -0
  245. package/src/array/takeWhile.ts +31 -0
  246. package/src/array/union.spec.ts +10 -0
  247. package/src/array/union.ts +14 -0
  248. package/src/array/unionBy.spec.ts +12 -0
  249. package/src/array/unionBy.ts +35 -0
  250. package/src/array/unionWith.spec.ts +23 -0
  251. package/src/array/unionWith.ts +18 -0
  252. package/src/array/uniq.spec.ts +8 -0
  253. package/src/array/uniq.ts +16 -0
  254. package/src/array/uniqBy.spec.ts +8 -0
  255. package/src/array/uniqBy.ts +17 -0
  256. package/src/array/uniqWith.spec.ts +16 -0
  257. package/src/array/uniqWith.ts +29 -0
  258. package/src/array/xor.spec.ts +13 -0
  259. package/src/array/xor.ts +25 -0
  260. package/src/array/xorBy.spec.ts +16 -0
  261. package/src/array/xorBy.ts +29 -0
  262. package/src/array/xorWith.spec.ts +16 -0
  263. package/src/array/xorWith.ts +28 -0
  264. package/src/array/zip.spec.ts +14 -0
  265. package/src/array/zip.ts +34 -0
  266. package/src/array/zipWith.spec.ts +13 -0
  267. package/src/array/zipWith.ts +23 -0
  268. package/src/function/debounce.spec.ts +76 -0
  269. package/src/function/debounce.ts +42 -0
  270. package/src/function/index.ts +3 -0
  271. package/src/function/once.spec.ts +31 -0
  272. package/src/function/once.ts +34 -0
  273. package/src/function/throttle.spec.ts +32 -0
  274. package/src/function/throttle.ts +39 -0
  275. package/src/index.ts +6 -0
  276. package/src/math/clamp.spec.ts +18 -0
  277. package/src/math/clamp.ts +17 -0
  278. package/src/math/index.ts +3 -0
  279. package/src/math/round.spec.ts +53 -0
  280. package/src/math/round.ts +16 -0
  281. package/src/math/sum.spec.ts +29 -0
  282. package/src/math/sum.ts +17 -0
  283. package/src/object/index.ts +4 -0
  284. package/src/object/omit.spec.ts +10 -0
  285. package/src/object/omit.ts +15 -0
  286. package/src/object/omitBy.ts +3 -0
  287. package/src/object/pick.spec.ts +10 -0
  288. package/src/object/pick.ts +15 -0
  289. package/src/object/pickBy.ts +3 -0
  290. package/src/predicate/index.ts +4 -0
  291. package/src/predicate/isNil.spec.ts +23 -0
  292. package/src/predicate/isNil.ts +8 -0
  293. package/src/predicate/isNotNil.spec.ts +29 -0
  294. package/src/predicate/isNotNil.ts +14 -0
  295. package/src/predicate/isNull.spec.ts +23 -0
  296. package/src/predicate/isNull.ts +8 -0
  297. package/src/predicate/isUndefined.spec.ts +23 -0
  298. package/src/predicate/isUndefined.ts +8 -0
  299. package/src/promise/delay.spec.ts +13 -0
  300. package/src/promise/delay.ts +10 -0
  301. package/src/promise/index.ts +1 -0
  302. package/tsconfig.json +12 -0
  303. package/vitest.config.mts +13 -0
@@ -0,0 +1,114 @@
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
+ function _toConsumableArray(arr) {
32
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
33
+ }
34
+ function _arrayWithoutHoles(arr) {
35
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
36
+ }
37
+ function _arrayWithHoles(arr) {
38
+ if (Array.isArray(arr)) return arr;
39
+ }
40
+ function _iterableToArray(iter) {
41
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
42
+ }
43
+ function _unsupportedIterableToArray(o, minLen) {
44
+ if (!o) return;
45
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
46
+ var n = Object.prototype.toString.call(o).slice(8, -1);
47
+ if (n === "Object" && o.constructor) n = o.constructor.name;
48
+ if (n === "Map" || n === "Set") return Array.from(o);
49
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
50
+ }
51
+ function _arrayLikeToArray(arr, len) {
52
+ if (len == null || len > arr.length) len = arr.length;
53
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
54
+ return arr2;
55
+ }
56
+ function _nonIterableSpread() {
57
+ 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
+ }
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
+ function _createForOfIteratorHelper(o, allowArrayLike) {
63
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
64
+ if (!it) {
65
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
66
+ if (it) o = it;
67
+ var i = 0;
68
+ var F = function () {};
69
+ return {
70
+ s: F,
71
+ n: function () {
72
+ if (i >= o.length) return {
73
+ done: true
74
+ };
75
+ return {
76
+ done: false,
77
+ value: o[i++]
78
+ };
79
+ },
80
+ e: function (e) {
81
+ throw e;
82
+ },
83
+ f: F
84
+ };
85
+ }
86
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
87
+ }
88
+ var normalCompletion = true,
89
+ didErr = false,
90
+ err;
91
+ return {
92
+ s: function () {
93
+ it = it.call(o);
94
+ },
95
+ n: function () {
96
+ var step = it.next();
97
+ normalCompletion = step.done;
98
+ return step;
99
+ },
100
+ e: function (e) {
101
+ didErr = true;
102
+ err = e;
103
+ },
104
+ f: function () {
105
+ try {
106
+ if (!normalCompletion && it.return != null) it.return();
107
+ } finally {
108
+ if (didErr) throw err;
109
+ }
110
+ }
111
+ };
112
+ }
113
+
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 };
@@ -0,0 +1,35 @@
1
+ import { createForOfIteratorHelper as _createForOfIteratorHelper, slicedToArray as _slicedToArray } from './_virtual/_rollupPluginBabelHelpers.mjs';
2
+
3
+ /**
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
9
+ */
10
+ function chunk(arr, size) {
11
+ if (!Number.isInteger(size) || size <= 0) {
12
+ throw new Error("Size must be an integer greater than zero.");
13
+ }
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();
31
+ }
32
+ return result;
33
+ }
34
+
35
+ export { chunk };
@@ -0,0 +1,13 @@
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`
6
+ */
7
+ function difference(firstArr, secondArr) {
8
+ return firstArr.filter(function (item) {
9
+ return !secondArr.includes(item);
10
+ });
11
+ }
12
+
13
+ export { difference };
@@ -0,0 +1,17 @@
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
7
+ */
8
+ function differenceBy(firstArr, secondArr, mapper) {
9
+ var mappedSecondArr = secondArr.map(function (item) {
10
+ return mapper(item);
11
+ });
12
+ return firstArr.filter(function (item) {
13
+ return !mappedSecondArr.includes(mapper(item));
14
+ });
15
+ }
16
+
17
+ export { differenceBy };
@@ -0,0 +1,16 @@
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
7
+ */
8
+ function differenceWith(firstArr, secondArr, areItemsEqual) {
9
+ return firstArr.filter(function (firstItem) {
10
+ return secondArr.every(function (secondItem) {
11
+ return !areItemsEqual(firstItem, secondItem);
12
+ });
13
+ });
14
+ }
15
+
16
+ export { differenceWith };
@@ -0,0 +1,11 @@
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
6
+ */
7
+ function drop(arr, itemsCount) {
8
+ return arr.slice(itemsCount);
9
+ }
10
+
11
+ export { drop };
@@ -0,0 +1,11 @@
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
6
+ */
7
+ function dropRight(arr, itemsCount) {
8
+ return arr.slice(0, -itemsCount);
9
+ }
10
+
11
+ export { dropRight };
@@ -0,0 +1,15 @@
1
+ import { dropWhile } from './dropWhile.mjs';
2
+
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.
8
+ */
9
+ function dropRightWhile(arr, canContinueDropping) {
10
+ var reversed = arr.slice().reverse();
11
+ var dropped = dropWhile(reversed, canContinueDropping);
12
+ return dropped.slice().reverse();
13
+ }
14
+
15
+ export { dropRightWhile };
@@ -0,0 +1,14 @@
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.
6
+ */
7
+ function dropWhile(arr, canContinueDropping) {
8
+ var dropEndIndex = arr.findIndex(function (item) {
9
+ return !canContinueDropping(item);
10
+ });
11
+ return arr.slice(dropEndIndex);
12
+ }
13
+
14
+ export { dropWhile };
@@ -0,0 +1,5 @@
1
+ function groupBy() {
2
+ throw new Error('Not implemented');
3
+ }
4
+
5
+ export { groupBy };
@@ -0,0 +1,30 @@
1
+ export { chunk } from './chunk.mjs';
2
+ export { difference } from './difference.mjs';
3
+ export { differenceBy } from './differenceBy.mjs';
4
+ export { differenceWith } from './differenceWith.mjs';
5
+ export { drop } from './drop.mjs';
6
+ export { dropRight } from './dropRight.mjs';
7
+ export { dropRightWhile } from './dropRightWhile.mjs';
8
+ export { dropWhile } from './dropWhile.mjs';
9
+ export { groupBy } from './groupBy.mjs';
10
+ export { intersection } from './intersection.mjs';
11
+ export { intersectionBy } from './intersectionBy.mjs';
12
+ export { intersectionWith } from './intersectionWith.mjs';
13
+ export { partition } from './partition.mjs';
14
+ export { sample } from './sample.mjs';
15
+ export { shuffle } from './shuffle.mjs';
16
+ export { take } from './take.mjs';
17
+ export { takeRight } from './takeRight.mjs';
18
+ export { takeRightWhile } from './takeRightWhile.mjs';
19
+ export { takeWhile } from './takeWhile.mjs';
20
+ export { union } from './union.mjs';
21
+ export { unionBy } from './unionBy.mjs';
22
+ export { unionWith } from './unionWith.mjs';
23
+ export { uniq } from './uniq.mjs';
24
+ export { uniqBy } from './uniqBy.mjs';
25
+ export { uniqWith } from './uniqWith.mjs';
26
+ export { xor } from './xor.mjs';
27
+ export { xorBy } from './xorBy.mjs';
28
+ export { xorWith } from './xorWith.mjs';
29
+ export { zip } from './zip.mjs';
30
+ export { zipWith } from './zipWith.mjs';
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @name intersection
3
+ * @description
4
+ * 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
7
+ * @example
8
+ * intersection([1, 2], [1, 3]) === [1]
9
+ * intersection([1, 2, 3], [2, 3, 4]) === [2, 3]
10
+ */
11
+ function intersection(firstArr, secondArr) {
12
+ return firstArr.filter(function (item) {
13
+ return secondArr.includes(item);
14
+ });
15
+ }
16
+
17
+ export { intersection };
@@ -0,0 +1,21 @@
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
8
+ * @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 }]
11
+ */
12
+ function intersectionBy(firstArr, secondArr, mapper) {
13
+ var mappedSecondArr = secondArr.map(function (x) {
14
+ return mapper(x);
15
+ });
16
+ return firstArr.filter(function (item) {
17
+ return mappedSecondArr.includes(mapper(item));
18
+ });
19
+ }
20
+
21
+ export { intersectionBy };
@@ -0,0 +1,20 @@
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
8
+ * @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 }]
11
+ */
12
+ function intersectionWith(firstArr, secondArr, areItemsEqual) {
13
+ return firstArr.filter(function (firstItem) {
14
+ return secondArr.some(function (secondItem) {
15
+ return areItemsEqual(firstItem, secondItem);
16
+ });
17
+ });
18
+ }
19
+
20
+ export { intersectionWith };
@@ -0,0 +1,32 @@
1
+ import { createForOfIteratorHelper as _createForOfIteratorHelper } from './_virtual/_rollupPluginBabelHelpers.mjs';
2
+
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
9
+ */
10
+ function partition(arr, isInTruthy) {
11
+ var truthy = [];
12
+ var falsy = [];
13
+ var _iterator = _createForOfIteratorHelper(arr),
14
+ _step;
15
+ try {
16
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
17
+ var item = _step.value;
18
+ if (isInTruthy(item)) {
19
+ truthy.push(item);
20
+ } else {
21
+ falsy.push(item);
22
+ }
23
+ }
24
+ } catch (err) {
25
+ _iterator.e(err);
26
+ } finally {
27
+ _iterator.f();
28
+ }
29
+ return [truthy, falsy];
30
+ }
31
+
32
+ export { partition };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @name sample
3
+ * @description
4
+ * Returns a random element from an array.
5
+ * @param arr The element to get a random element
6
+ */
7
+ function sample(arr) {
8
+ var randomIndex = Math.floor(Math.random() * arr.length);
9
+ return arr[randomIndex];
10
+ }
11
+
12
+ export { sample };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @name shuffle
3
+ * @description
4
+ * Randomize the order of an array.
5
+ * @param arr The array to shuffle
6
+ */
7
+ function shuffle(arr) {
8
+ /**
9
+ * https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm
10
+ */
11
+ for (var i = arr.length - 1; i >= 1; i--) {
12
+ var j = Math.floor(Math.random() * i);
13
+ var _ref = [arr[j], arr[i]];
14
+ arr[i] = _ref[0];
15
+ arr[j] = _ref[1];
16
+ }
17
+ return arr;
18
+ }
19
+
20
+ export { shuffle };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Returns a new array containing the first `count` elements from the input array `arr`.
3
+ * If `count` is greater than the length of `arr`, the entire array is returned.
4
+ *
5
+ * @template T - Type of elements in the input array.
6
+ *
7
+ * @param {T[]} arr - The array to take elements from.
8
+ * @param {number} count - The number of elements to take.
9
+ * @returns {T[]} A new array containing the first `count` elements from `arr`.
10
+ *
11
+ * @example
12
+ * // Returns [1, 2, 3]
13
+ * take([1, 2, 3, 4, 5], 3);
14
+ *
15
+ * @example
16
+ * // Returns ['a', 'b']
17
+ * take(['a', 'b', 'c'], 2);
18
+ *
19
+ * @example
20
+ * // Returns [1, 2, 3]
21
+ * take([1, 2, 3], 5);
22
+ */
23
+ function take(arr, count) {
24
+ return arr.slice(0, count);
25
+ }
26
+
27
+ export { take };
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Returns a new array containing the last `count` elements from the input array `arr`.
3
+ * If `count` is greater than the length of `arr`, the entire array is returned.
4
+ *
5
+ * @template T - Type of elements in the input array.
6
+ *
7
+ * @param {T[]} arr - The array to take elements from.
8
+ * @param {number} count - The number of elements to take.
9
+ * @returns {T[]} A new array containing the last `count` elements from `arr`.
10
+ *
11
+ * @example
12
+ * // Returns [4, 5]
13
+ * takeRight([1, 2, 3, 4, 5], 2);
14
+ *
15
+ * @example
16
+ * // Returns ['b', 'c']
17
+ * takeRight(['a', 'b', 'c'], 2);
18
+ *
19
+ * @example
20
+ * // Returns [1, 2, 3]
21
+ * takeRight([1, 2, 3], 5);
22
+ */
23
+ function takeRight(arr, count) {
24
+ if (count === 0) {
25
+ return [];
26
+ }
27
+ return arr.slice(-count);
28
+ }
29
+
30
+ export { takeRight };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Takes elements from the end of the array while the predicate function returns `true`.
3
+ *
4
+ * @template T - Type of elements in the input array.
5
+ *
6
+ * @param {T[]} arr - The array to take elements from.
7
+ * @param {function(T): boolean} shouldContinueTaking - The function invoked per element.
8
+ * @returns {T[]} A new array containing the elements taken from the end while the predicate returns `true`.
9
+ *
10
+ * @example
11
+ * // Returns [3, 2, 1]
12
+ * takeRightWhile([5, 4, 3, 2, 1], n => n < 4);
13
+ *
14
+ * @example
15
+ * // Returns []
16
+ * takeRightWhile([1, 2, 3], n => n > 3);
17
+ */
18
+ function takeRightWhile(arr, shouldContinueTaking) {
19
+ for (var i = arr.length - 1; i >= 0; i--) {
20
+ if (!shouldContinueTaking(arr[i])) {
21
+ return arr.slice(i + 1);
22
+ }
23
+ }
24
+ return arr.slice();
25
+ }
26
+
27
+ export { takeRightWhile };
@@ -0,0 +1,41 @@
1
+ import { createForOfIteratorHelper as _createForOfIteratorHelper } from './_virtual/_rollupPluginBabelHelpers.mjs';
2
+
3
+ /**
4
+ * Returns a new array containing the leading elements of the provided array
5
+ * that satisfy the provided predicate function. It stops taking elements as soon
6
+ * as an element does not satisfy the predicate.
7
+ *
8
+ * @template T - The type of elements in the array.
9
+ * @param {T[]} arr - The array to process.
10
+ * @param {(element: T) => boolean} shouldContinueTaking - The predicate function that is called with each element. Elements are included in the result as long as this function returns true.
11
+ * @returns {T[]} A new array containing the leading elements that satisfy the predicate.
12
+ *
13
+ * @example
14
+ * // Returns [1, 2]
15
+ * takeWhile([1, 2, 3, 4], x => x < 3);
16
+ *
17
+ * @example
18
+ * // Returns []
19
+ * takeWhile([1, 2, 3, 4], x => x > 3);
20
+ */
21
+ function takeWhile(arr, shouldContinueTaking) {
22
+ var result = [];
23
+ var _iterator = _createForOfIteratorHelper(arr),
24
+ _step;
25
+ try {
26
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
27
+ var item = _step.value;
28
+ if (!shouldContinueTaking(item)) {
29
+ break;
30
+ }
31
+ result.push(item);
32
+ }
33
+ } catch (err) {
34
+ _iterator.e(err);
35
+ } finally {
36
+ _iterator.f();
37
+ }
38
+ return result;
39
+ }
40
+
41
+ export { takeWhile };
@@ -0,0 +1,19 @@
1
+ import { uniq } from './uniq.mjs';
2
+
3
+ /**
4
+ * `union` function returns the union of the arrays passed as arguments.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * union([2], [1, 2]);
9
+ * // [2, 1]
10
+ * ```
11
+ */
12
+ function union() {
13
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
14
+ args[_key] = arguments[_key];
15
+ }
16
+ return uniq(args.flat());
17
+ }
18
+
19
+ export { union };
@@ -0,0 +1,38 @@
1
+ import { toConsumableArray as _toConsumableArray } from './_virtual/_rollupPluginBabelHelpers.mjs';
2
+
3
+ /**
4
+ * Creates an array of unique values, in order, from all given arrays using a provided mapping function to determine equality.
5
+ *
6
+ * @template T - Type of elements in the input arrays.
7
+ * @template U - Type of the values returned by the mapping function.
8
+ *
9
+ * @param {T[]} arr1 - The first array.
10
+ * @param {T[]} arr2 - The second array.
11
+ * @param {function(item: T): U} mapper - The function to map array elements to comparison values.
12
+ * @returns {T[]} A new array containing the union of unique elements from `arr1` and `arr2`, based on the values returned by the mapping function.
13
+ *
14
+ * @example
15
+ * // Custom mapping function for numbers (modulo comparison)
16
+ * const moduloMapper = (x) => x % 3;
17
+ * unionBy([1, 2, 3], [4, 5, 6], moduloMapper);
18
+ * // Returns [1, 2, 3]
19
+ *
20
+ * @example
21
+ * // Custom mapping function for objects with an 'id' property
22
+ * const idMapper = (obj) => obj.id;
23
+ * unionBy([{ id: 1 }, { id: 2 }], [{ id: 2 }, { id: 3 }], idMapper);
24
+ * // Returns [{ id: 1 }, { id: 2 }, { id: 3 }]
25
+ */
26
+ function unionBy(arr1, arr2, mapper) {
27
+ var map = new Map();
28
+ for (var _i = 0, _arr = [].concat(_toConsumableArray(arr1), _toConsumableArray(arr2)); _i < _arr.length; _i++) {
29
+ var item = _arr[_i];
30
+ var key = mapper(item);
31
+ if (!map.has(key)) {
32
+ map.set(key, item);
33
+ }
34
+ }
35
+ return _toConsumableArray(map.values());
36
+ }
37
+
38
+ export { unionBy };
@@ -0,0 +1,21 @@
1
+ import { toConsumableArray as _toConsumableArray } from './_virtual/_rollupPluginBabelHelpers.mjs';
2
+ import { uniqWith } from './uniqWith.mjs';
3
+
4
+ /**
5
+ * `unionWith` function returns the union of multiple arrays passed as arguments. During this process, it removes any duplicated elements.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * unionWith(
10
+ * [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }],
11
+ * [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }],
12
+ * (x, y) => x === y
13
+ * );
14
+ * // [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
15
+ * ```
16
+ */
17
+ function unionWith(arr1, arr2, areItemsEqual) {
18
+ return uniqWith([].concat(_toConsumableArray(arr1), _toConsumableArray(arr2)), areItemsEqual);
19
+ }
20
+
21
+ export { unionWith };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @name uniq
3
+ * @description
4
+ * `uniq` removes duplicated elements from the array given as an argument.
5
+ *
6
+ * It filters out elements with the same value, so duplicates of data types like Objects are not checked.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * uniq([1, 1, 2, 3, 5, 5, 7, 'foo', 'bar', 'bar']);
11
+ * // [1, 2, 3, 5, 7, 'foo', 'bar']
12
+ * ```
13
+ */
14
+ function uniq(arr) {
15
+ return Array.from(new Set(arr));
16
+ }
17
+
18
+ export { uniq };