es-toolkit 1.48.1 → 1.49.0

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 (403) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/array/chunkBy.d.mts +32 -0
  3. package/dist/array/chunkBy.d.ts +32 -0
  4. package/dist/array/chunkBy.js +42 -0
  5. package/dist/array/chunkBy.mjs +42 -0
  6. package/dist/array/index.d.mts +2 -1
  7. package/dist/array/index.d.ts +2 -1
  8. package/dist/array/index.js +2 -0
  9. package/dist/array/index.mjs +2 -1
  10. package/dist/array/take.d.mts +1 -7
  11. package/dist/array/take.d.ts +1 -7
  12. package/dist/array/take.js +1 -9
  13. package/dist/array/take.mjs +1 -9
  14. package/dist/array/takeRight.d.mts +2 -2
  15. package/dist/array/takeRight.d.ts +2 -2
  16. package/dist/array/takeRight.js +2 -4
  17. package/dist/array/takeRight.mjs +2 -4
  18. package/dist/array/windowed.d.mts +1 -1
  19. package/dist/array/windowed.d.ts +1 -1
  20. package/dist/browser.global.js +3 -3
  21. package/dist/compat/array/chunk.js +4 -2
  22. package/dist/compat/array/chunk.mjs +4 -2
  23. package/dist/compat/array/differenceBy.js +5 -5
  24. package/dist/compat/array/differenceBy.mjs +5 -5
  25. package/dist/compat/array/drop.d.mts +2 -3
  26. package/dist/compat/array/drop.d.ts +2 -3
  27. package/dist/compat/array/drop.js +4 -4
  28. package/dist/compat/array/drop.mjs +4 -4
  29. package/dist/compat/array/dropRight.js +1 -1
  30. package/dist/compat/array/dropRight.mjs +1 -1
  31. package/dist/compat/array/dropRightWhile.d.mts +1 -1
  32. package/dist/compat/array/dropRightWhile.d.ts +1 -1
  33. package/dist/compat/array/dropRightWhile.js +5 -4
  34. package/dist/compat/array/dropRightWhile.mjs +5 -4
  35. package/dist/compat/array/dropWhile.d.mts +2 -2
  36. package/dist/compat/array/dropWhile.d.ts +2 -2
  37. package/dist/compat/array/dropWhile.js +4 -4
  38. package/dist/compat/array/dropWhile.mjs +4 -4
  39. package/dist/compat/array/findLast.js +1 -1
  40. package/dist/compat/array/findLast.mjs +1 -1
  41. package/dist/compat/array/includes.js +1 -1
  42. package/dist/compat/array/includes.mjs +1 -1
  43. package/dist/compat/array/nth.js +1 -1
  44. package/dist/compat/array/nth.mjs +1 -1
  45. package/dist/compat/array/slice.js +1 -1
  46. package/dist/compat/array/slice.mjs +1 -1
  47. package/dist/compat/array/sortedIndexBy.js +1 -1
  48. package/dist/compat/array/sortedIndexBy.mjs +1 -1
  49. package/dist/compat/array/take.js +2 -2
  50. package/dist/compat/array/take.mjs +2 -2
  51. package/dist/compat/array/takeRight.js +1 -1
  52. package/dist/compat/array/takeRight.mjs +1 -1
  53. package/dist/compat/compat.js +4 -4
  54. package/dist/compat/compat.mjs +4 -4
  55. package/dist/compat/index.js +4 -4
  56. package/dist/compat/index.mjs +4 -4
  57. package/dist/compat/math/add.js +1 -1
  58. package/dist/compat/math/add.mjs +1 -1
  59. package/dist/compat/math/divide.js +1 -1
  60. package/dist/compat/math/divide.mjs +1 -1
  61. package/dist/compat/math/multiply.js +1 -1
  62. package/dist/compat/math/multiply.mjs +1 -1
  63. package/dist/compat/math/random.js +3 -1
  64. package/dist/compat/math/random.mjs +3 -1
  65. package/dist/compat/math/subtract.js +1 -1
  66. package/dist/compat/math/subtract.mjs +1 -1
  67. package/dist/compat/object/get.js +1 -1
  68. package/dist/compat/object/get.mjs +1 -1
  69. package/dist/compat/object/omitBy.js +1 -1
  70. package/dist/compat/object/omitBy.mjs +1 -1
  71. package/dist/compat/object/pick.js +1 -1
  72. package/dist/compat/object/pick.mjs +1 -1
  73. package/dist/compat/object/pickBy.js +1 -1
  74. package/dist/compat/object/pickBy.mjs +1 -1
  75. package/dist/compat/string/repeat.js +1 -1
  76. package/dist/compat/string/repeat.mjs +1 -1
  77. package/dist/fp/_internal/lazy.js +58 -0
  78. package/dist/fp/_internal/lazy.mjs +57 -0
  79. package/dist/fp/array/at.d.mts +20 -0
  80. package/dist/fp/array/at.d.ts +20 -0
  81. package/dist/fp/array/at.js +25 -0
  82. package/dist/fp/array/at.mjs +25 -0
  83. package/dist/fp/array/cartesianProduct.d.mts +61 -0
  84. package/dist/fp/array/cartesianProduct.d.ts +61 -0
  85. package/dist/fp/array/cartesianProduct.js +9 -0
  86. package/dist/fp/array/cartesianProduct.mjs +9 -0
  87. package/dist/fp/array/chunk.d.mts +19 -0
  88. package/dist/fp/array/chunk.d.ts +19 -0
  89. package/dist/fp/array/chunk.js +24 -0
  90. package/dist/fp/array/chunk.mjs +24 -0
  91. package/dist/fp/array/chunkBy.d.mts +20 -0
  92. package/dist/fp/array/chunkBy.d.ts +20 -0
  93. package/dist/fp/array/chunkBy.js +25 -0
  94. package/dist/fp/array/chunkBy.mjs +25 -0
  95. package/dist/fp/array/combinations.d.mts +21 -0
  96. package/dist/fp/array/combinations.d.ts +21 -0
  97. package/dist/fp/array/combinations.js +26 -0
  98. package/dist/fp/array/combinations.mjs +26 -0
  99. package/dist/fp/array/compact.d.mts +22 -0
  100. package/dist/fp/array/compact.d.ts +22 -0
  101. package/dist/fp/array/compact.js +31 -0
  102. package/dist/fp/array/compact.mjs +30 -0
  103. package/dist/fp/array/countBy.d.mts +21 -0
  104. package/dist/fp/array/countBy.d.ts +21 -0
  105. package/dist/fp/array/countBy.js +26 -0
  106. package/dist/fp/array/countBy.mjs +26 -0
  107. package/dist/fp/array/difference.d.mts +21 -0
  108. package/dist/fp/array/difference.d.ts +21 -0
  109. package/dist/fp/array/difference.js +32 -0
  110. package/dist/fp/array/difference.mjs +31 -0
  111. package/dist/fp/array/differenceBy.d.mts +22 -0
  112. package/dist/fp/array/differenceBy.d.ts +22 -0
  113. package/dist/fp/array/differenceBy.js +33 -0
  114. package/dist/fp/array/differenceBy.mjs +32 -0
  115. package/dist/fp/array/differenceWith.d.mts +22 -0
  116. package/dist/fp/array/differenceWith.d.ts +22 -0
  117. package/dist/fp/array/differenceWith.js +32 -0
  118. package/dist/fp/array/differenceWith.mjs +31 -0
  119. package/dist/fp/array/drop.d.mts +20 -0
  120. package/dist/fp/array/drop.d.ts +20 -0
  121. package/dist/fp/array/drop.js +31 -0
  122. package/dist/fp/array/drop.mjs +30 -0
  123. package/dist/fp/array/dropRight.d.mts +20 -0
  124. package/dist/fp/array/dropRight.d.ts +20 -0
  125. package/dist/fp/array/dropRight.js +25 -0
  126. package/dist/fp/array/dropRight.mjs +25 -0
  127. package/dist/fp/array/dropRightWhile.d.mts +20 -0
  128. package/dist/fp/array/dropRightWhile.d.ts +20 -0
  129. package/dist/fp/array/dropRightWhile.js +25 -0
  130. package/dist/fp/array/dropRightWhile.mjs +25 -0
  131. package/dist/fp/array/dropWhile.d.mts +20 -0
  132. package/dist/fp/array/dropWhile.d.ts +20 -0
  133. package/dist/fp/array/dropWhile.js +36 -0
  134. package/dist/fp/array/dropWhile.mjs +36 -0
  135. package/dist/fp/array/filter.d.mts +45 -0
  136. package/dist/fp/array/filter.d.ts +45 -0
  137. package/dist/fp/array/filter.js +13 -0
  138. package/dist/fp/array/filter.mjs +12 -0
  139. package/dist/fp/array/find.d.mts +39 -0
  140. package/dist/fp/array/find.d.ts +39 -0
  141. package/dist/fp/array/find.js +8 -0
  142. package/dist/fp/array/find.mjs +8 -0
  143. package/dist/fp/array/findIndex.d.mts +20 -0
  144. package/dist/fp/array/findIndex.d.ts +20 -0
  145. package/dist/fp/array/findIndex.js +24 -0
  146. package/dist/fp/array/findIndex.mjs +24 -0
  147. package/dist/fp/array/findLast.d.mts +39 -0
  148. package/dist/fp/array/findLast.d.ts +39 -0
  149. package/dist/fp/array/findLast.js +11 -0
  150. package/dist/fp/array/findLast.mjs +11 -0
  151. package/dist/fp/array/findLastIndex.d.mts +20 -0
  152. package/dist/fp/array/findLastIndex.d.ts +20 -0
  153. package/dist/fp/array/findLastIndex.js +25 -0
  154. package/dist/fp/array/findLastIndex.mjs +25 -0
  155. package/dist/fp/array/flatMap.d.mts +28 -0
  156. package/dist/fp/array/flatMap.d.ts +28 -0
  157. package/dist/fp/array/flatMap.js +39 -0
  158. package/dist/fp/array/flatMap.mjs +38 -0
  159. package/dist/fp/array/flatMapDeep.d.mts +23 -0
  160. package/dist/fp/array/flatMapDeep.d.ts +23 -0
  161. package/dist/fp/array/flatMapDeep.js +38 -0
  162. package/dist/fp/array/flatMapDeep.mjs +37 -0
  163. package/dist/fp/array/flatten.d.mts +21 -0
  164. package/dist/fp/array/flatten.d.ts +21 -0
  165. package/dist/fp/array/flatten.js +39 -0
  166. package/dist/fp/array/flatten.mjs +38 -0
  167. package/dist/fp/array/flattenDeep.d.mts +21 -0
  168. package/dist/fp/array/flattenDeep.d.ts +21 -0
  169. package/dist/fp/array/flattenDeep.js +36 -0
  170. package/dist/fp/array/flattenDeep.mjs +35 -0
  171. package/dist/fp/array/forEach.d.mts +22 -0
  172. package/dist/fp/array/forEach.d.ts +22 -0
  173. package/dist/fp/array/forEach.js +33 -0
  174. package/dist/fp/array/forEach.mjs +32 -0
  175. package/dist/fp/array/groupBy.d.mts +21 -0
  176. package/dist/fp/array/groupBy.d.ts +21 -0
  177. package/dist/fp/array/groupBy.js +26 -0
  178. package/dist/fp/array/groupBy.mjs +26 -0
  179. package/dist/fp/array/head.d.mts +35 -0
  180. package/dist/fp/array/head.d.ts +35 -0
  181. package/dist/fp/array/head.js +9 -0
  182. package/dist/fp/array/head.mjs +9 -0
  183. package/dist/fp/array/index.d.mts +69 -0
  184. package/dist/fp/array/index.d.ts +69 -0
  185. package/dist/fp/array/index.js +68 -0
  186. package/dist/fp/array/index.mjs +68 -0
  187. package/dist/fp/array/initial.d.mts +19 -0
  188. package/dist/fp/array/initial.d.ts +19 -0
  189. package/dist/fp/array/initial.js +24 -0
  190. package/dist/fp/array/initial.mjs +24 -0
  191. package/dist/fp/array/intersection.d.mts +21 -0
  192. package/dist/fp/array/intersection.d.ts +21 -0
  193. package/dist/fp/array/intersection.js +32 -0
  194. package/dist/fp/array/intersection.mjs +31 -0
  195. package/dist/fp/array/intersectionBy.d.mts +22 -0
  196. package/dist/fp/array/intersectionBy.d.ts +22 -0
  197. package/dist/fp/array/intersectionBy.js +33 -0
  198. package/dist/fp/array/intersectionBy.mjs +32 -0
  199. package/dist/fp/array/intersectionWith.d.mts +22 -0
  200. package/dist/fp/array/intersectionWith.d.ts +22 -0
  201. package/dist/fp/array/intersectionWith.js +32 -0
  202. package/dist/fp/array/intersectionWith.mjs +31 -0
  203. package/dist/fp/array/isSubset.d.mts +20 -0
  204. package/dist/fp/array/isSubset.d.ts +20 -0
  205. package/dist/fp/array/isSubset.js +25 -0
  206. package/dist/fp/array/isSubset.mjs +25 -0
  207. package/dist/fp/array/isSubsetWith.d.mts +21 -0
  208. package/dist/fp/array/isSubsetWith.d.ts +21 -0
  209. package/dist/fp/array/isSubsetWith.js +26 -0
  210. package/dist/fp/array/isSubsetWith.mjs +26 -0
  211. package/dist/fp/array/join.d.mts +20 -0
  212. package/dist/fp/array/join.d.ts +20 -0
  213. package/dist/fp/array/join.js +24 -0
  214. package/dist/fp/array/join.mjs +24 -0
  215. package/dist/fp/array/keyBy.d.mts +21 -0
  216. package/dist/fp/array/keyBy.d.ts +21 -0
  217. package/dist/fp/array/keyBy.js +26 -0
  218. package/dist/fp/array/keyBy.mjs +26 -0
  219. package/dist/fp/array/last.d.mts +35 -0
  220. package/dist/fp/array/last.d.ts +35 -0
  221. package/dist/fp/array/last.js +9 -0
  222. package/dist/fp/array/last.mjs +9 -0
  223. package/dist/fp/array/length.d.mts +18 -0
  224. package/dist/fp/array/length.d.ts +18 -0
  225. package/dist/fp/array/length.js +22 -0
  226. package/dist/fp/array/length.mjs +22 -0
  227. package/dist/fp/array/map.d.mts +27 -0
  228. package/dist/fp/array/map.d.ts +27 -0
  229. package/dist/fp/array/map.js +36 -0
  230. package/dist/fp/array/map.mjs +35 -0
  231. package/dist/fp/array/maxBy.d.mts +37 -0
  232. package/dist/fp/array/maxBy.d.ts +37 -0
  233. package/dist/fp/array/maxBy.js +9 -0
  234. package/dist/fp/array/maxBy.mjs +9 -0
  235. package/dist/fp/array/minBy.d.mts +37 -0
  236. package/dist/fp/array/minBy.d.ts +37 -0
  237. package/dist/fp/array/minBy.js +9 -0
  238. package/dist/fp/array/minBy.mjs +9 -0
  239. package/dist/fp/array/orderBy.d.mts +21 -0
  240. package/dist/fp/array/orderBy.d.ts +21 -0
  241. package/dist/fp/array/orderBy.js +26 -0
  242. package/dist/fp/array/orderBy.mjs +26 -0
  243. package/dist/fp/array/partition.d.mts +39 -0
  244. package/dist/fp/array/partition.d.ts +39 -0
  245. package/dist/fp/array/partition.js +9 -0
  246. package/dist/fp/array/partition.mjs +9 -0
  247. package/dist/fp/array/reverse.d.mts +19 -0
  248. package/dist/fp/array/reverse.d.ts +19 -0
  249. package/dist/fp/array/reverse.js +23 -0
  250. package/dist/fp/array/reverse.mjs +23 -0
  251. package/dist/fp/array/sample.d.mts +18 -0
  252. package/dist/fp/array/sample.d.ts +18 -0
  253. package/dist/fp/array/sample.js +23 -0
  254. package/dist/fp/array/sample.mjs +23 -0
  255. package/dist/fp/array/sampleSize.d.mts +20 -0
  256. package/dist/fp/array/sampleSize.d.ts +20 -0
  257. package/dist/fp/array/sampleSize.js +25 -0
  258. package/dist/fp/array/sampleSize.mjs +25 -0
  259. package/dist/fp/array/shuffle.d.mts +19 -0
  260. package/dist/fp/array/shuffle.d.ts +19 -0
  261. package/dist/fp/array/shuffle.js +24 -0
  262. package/dist/fp/array/shuffle.mjs +24 -0
  263. package/dist/fp/array/sortBy.d.mts +26 -0
  264. package/dist/fp/array/sortBy.d.ts +26 -0
  265. package/dist/fp/array/sortBy.js +31 -0
  266. package/dist/fp/array/sortBy.mjs +31 -0
  267. package/dist/fp/array/tail.d.mts +19 -0
  268. package/dist/fp/array/tail.d.ts +19 -0
  269. package/dist/fp/array/tail.js +24 -0
  270. package/dist/fp/array/tail.mjs +24 -0
  271. package/dist/fp/array/take.d.mts +26 -0
  272. package/dist/fp/array/take.d.ts +26 -0
  273. package/dist/fp/array/take.js +39 -0
  274. package/dist/fp/array/take.mjs +38 -0
  275. package/dist/fp/array/takeRight.d.mts +20 -0
  276. package/dist/fp/array/takeRight.d.ts +20 -0
  277. package/dist/fp/array/takeRight.js +25 -0
  278. package/dist/fp/array/takeRight.mjs +25 -0
  279. package/dist/fp/array/takeRightWhile.d.mts +20 -0
  280. package/dist/fp/array/takeRightWhile.d.ts +20 -0
  281. package/dist/fp/array/takeRightWhile.js +25 -0
  282. package/dist/fp/array/takeRightWhile.mjs +25 -0
  283. package/dist/fp/array/takeWhile.d.mts +21 -0
  284. package/dist/fp/array/takeWhile.d.ts +21 -0
  285. package/dist/fp/array/takeWhile.js +32 -0
  286. package/dist/fp/array/takeWhile.mjs +31 -0
  287. package/dist/fp/array/toFilled.d.mts +23 -0
  288. package/dist/fp/array/toFilled.d.ts +23 -0
  289. package/dist/fp/array/toFilled.js +30 -0
  290. package/dist/fp/array/toFilled.mjs +30 -0
  291. package/dist/fp/array/union.d.mts +20 -0
  292. package/dist/fp/array/union.d.ts +20 -0
  293. package/dist/fp/array/union.js +25 -0
  294. package/dist/fp/array/union.mjs +25 -0
  295. package/dist/fp/array/unionBy.d.mts +22 -0
  296. package/dist/fp/array/unionBy.d.ts +22 -0
  297. package/dist/fp/array/unionBy.js +27 -0
  298. package/dist/fp/array/unionBy.mjs +27 -0
  299. package/dist/fp/array/unionWith.d.mts +21 -0
  300. package/dist/fp/array/unionWith.d.ts +21 -0
  301. package/dist/fp/array/unionWith.js +26 -0
  302. package/dist/fp/array/unionWith.mjs +26 -0
  303. package/dist/fp/array/uniq.d.mts +21 -0
  304. package/dist/fp/array/uniq.d.ts +21 -0
  305. package/dist/fp/array/uniq.js +36 -0
  306. package/dist/fp/array/uniq.mjs +36 -0
  307. package/dist/fp/array/uniqBy.d.mts +21 -0
  308. package/dist/fp/array/uniqBy.d.ts +21 -0
  309. package/dist/fp/array/uniqBy.js +38 -0
  310. package/dist/fp/array/uniqBy.mjs +38 -0
  311. package/dist/fp/array/uniqWith.d.mts +20 -0
  312. package/dist/fp/array/uniqWith.d.ts +20 -0
  313. package/dist/fp/array/uniqWith.js +35 -0
  314. package/dist/fp/array/uniqWith.mjs +35 -0
  315. package/dist/fp/array/unzip.d.mts +20 -0
  316. package/dist/fp/array/unzip.d.ts +20 -0
  317. package/dist/fp/array/unzip.js +24 -0
  318. package/dist/fp/array/unzip.mjs +24 -0
  319. package/dist/fp/array/unzipWith.d.mts +21 -0
  320. package/dist/fp/array/unzipWith.d.ts +21 -0
  321. package/dist/fp/array/unzipWith.js +26 -0
  322. package/dist/fp/array/unzipWith.mjs +26 -0
  323. package/dist/fp/array/windowed.d.mts +25 -0
  324. package/dist/fp/array/windowed.d.ts +25 -0
  325. package/dist/fp/array/windowed.js +50 -0
  326. package/dist/fp/array/windowed.mjs +50 -0
  327. package/dist/fp/array/without.d.mts +19 -0
  328. package/dist/fp/array/without.d.ts +19 -0
  329. package/dist/fp/array/without.js +30 -0
  330. package/dist/fp/array/without.mjs +29 -0
  331. package/dist/fp/array/xor.d.mts +20 -0
  332. package/dist/fp/array/xor.d.ts +20 -0
  333. package/dist/fp/array/xor.js +25 -0
  334. package/dist/fp/array/xor.mjs +25 -0
  335. package/dist/fp/array/xorBy.d.mts +22 -0
  336. package/dist/fp/array/xorBy.d.ts +22 -0
  337. package/dist/fp/array/xorBy.js +27 -0
  338. package/dist/fp/array/xorBy.mjs +27 -0
  339. package/dist/fp/array/xorWith.d.mts +21 -0
  340. package/dist/fp/array/xorWith.d.ts +21 -0
  341. package/dist/fp/array/xorWith.js +26 -0
  342. package/dist/fp/array/xorWith.mjs +26 -0
  343. package/dist/fp/array/zip.d.mts +61 -0
  344. package/dist/fp/array/zip.d.ts +61 -0
  345. package/dist/fp/array/zip.js +9 -0
  346. package/dist/fp/array/zip.mjs +9 -0
  347. package/dist/fp/array/zipObject.d.mts +21 -0
  348. package/dist/fp/array/zipObject.d.ts +21 -0
  349. package/dist/fp/array/zipObject.js +26 -0
  350. package/dist/fp/array/zipObject.mjs +26 -0
  351. package/dist/fp/array/zipWith.d.mts +57 -0
  352. package/dist/fp/array/zipWith.d.ts +57 -0
  353. package/dist/fp/array/zipWith.js +9 -0
  354. package/dist/fp/array/zipWith.mjs +9 -0
  355. package/dist/fp/index.d.mts +75 -0
  356. package/dist/fp/index.d.ts +75 -0
  357. package/dist/fp/index.js +150 -0
  358. package/dist/fp/index.mjs +77 -0
  359. package/dist/fp/math/add.d.mts +17 -0
  360. package/dist/fp/math/add.d.ts +17 -0
  361. package/dist/fp/math/add.js +21 -0
  362. package/dist/fp/math/add.mjs +21 -0
  363. package/dist/fp/math/index.d.mts +2 -0
  364. package/dist/fp/math/index.d.ts +2 -0
  365. package/dist/fp/math/index.js +2 -0
  366. package/dist/fp/math/index.mjs +2 -0
  367. package/dist/fp/math/multiply.d.mts +17 -0
  368. package/dist/fp/math/multiply.d.ts +17 -0
  369. package/dist/fp/math/multiply.js +21 -0
  370. package/dist/fp/math/multiply.mjs +21 -0
  371. package/dist/fp/object/index.d.mts +2 -0
  372. package/dist/fp/object/index.d.ts +2 -0
  373. package/dist/fp/object/index.js +2 -0
  374. package/dist/fp/object/index.mjs +2 -0
  375. package/dist/fp/object/omit.d.mts +18 -0
  376. package/dist/fp/object/omit.d.ts +18 -0
  377. package/dist/fp/object/omit.js +23 -0
  378. package/dist/fp/object/omit.mjs +23 -0
  379. package/dist/fp/object/pick.d.mts +19 -0
  380. package/dist/fp/object/pick.d.ts +19 -0
  381. package/dist/fp/object/pick.js +24 -0
  382. package/dist/fp/object/pick.mjs +24 -0
  383. package/dist/fp/pipe.d.mts +235 -0
  384. package/dist/fp/pipe.d.ts +235 -0
  385. package/dist/fp/pipe.js +116 -0
  386. package/dist/fp/pipe.mjs +116 -0
  387. package/dist/index.d.mts +3 -1
  388. package/dist/index.d.ts +3 -1
  389. package/dist/index.js +4 -0
  390. package/dist/index.mjs +3 -1
  391. package/dist/predicate/index.d.mts +2 -1
  392. package/dist/predicate/index.d.ts +2 -1
  393. package/dist/predicate/index.js +2 -0
  394. package/dist/predicate/index.mjs +2 -1
  395. package/dist/predicate/isIterable.d.mts +26 -0
  396. package/dist/predicate/isIterable.d.ts +26 -0
  397. package/dist/predicate/isIterable.js +28 -0
  398. package/dist/predicate/isIterable.mjs +28 -0
  399. package/dist/string/trimStart.js +1 -0
  400. package/dist/string/trimStart.mjs +1 -0
  401. package/fp.d.ts +1 -0
  402. package/fp.js +1 -0
  403. package/package.json +22 -1
@@ -0,0 +1,39 @@
1
+ //#region src/fp/array/findLast.d.ts
2
+ /**
3
+ * Creates a function that returns the last value accepted by a type guard.
4
+ *
5
+ * The predicate receives the value, index, and full input array while scanning
6
+ * from right to left. The returned function returns undefined when no value matches.
7
+ *
8
+ * @template T - The type of elements in the array.
9
+ * @template S - The narrowed element type accepted by the type guard.
10
+ * @param predicate - Type guard called with each value, index, and array from right to left.
11
+ * @returns A function that maps a readonly array to the last matching value, or undefined.
12
+ *
13
+ * @example
14
+ * import { findLast, pipe } from 'es-toolkit/fp';
15
+ *
16
+ * const isString = (value: string | number): value is string => typeof value === 'string';
17
+ * pipe([1, 'a', 2, 'b'], findLast(isString));
18
+ * // => 'b'
19
+ */
20
+ declare function findLast<T, S extends T>(predicate: (value: T, index: number, array: readonly T[]) => value is S): (array: readonly T[]) => S | undefined;
21
+ /**
22
+ * Creates a function that returns the last value matching a predicate.
23
+ *
24
+ * The predicate receives the value, index, and full input array while scanning
25
+ * from right to left. The returned function returns undefined when no value matches.
26
+ *
27
+ * @template T - The type of elements in the array.
28
+ * @param predicate - Predicate called with each value, index, and array from right to left.
29
+ * @returns A function that maps a readonly array to the last matching value, or undefined.
30
+ *
31
+ * @example
32
+ * import { findLast, pipe } from 'es-toolkit/fp';
33
+ *
34
+ * pipe([{ id: 1 }, { id: 2 }, { id: 1 }], findLast(item => item.id === 1));
35
+ * // => { id: 1 }
36
+ */
37
+ declare function findLast<T>(predicate: (value: T, index: number, array: readonly T[]) => boolean): (array: readonly T[]) => T | undefined;
38
+ //#endregion
39
+ export { findLast };
@@ -0,0 +1,11 @@
1
+ //#region src/fp/array/findLast.ts
2
+ function findLast(predicate) {
3
+ return function(array) {
4
+ for (let index = array.length - 1; index >= 0; index--) {
5
+ const value = array[index];
6
+ if (predicate(value, index, array)) return value;
7
+ }
8
+ };
9
+ }
10
+ //#endregion
11
+ exports.findLast = findLast;
@@ -0,0 +1,11 @@
1
+ //#region src/fp/array/findLast.ts
2
+ function findLast(predicate) {
3
+ return function(array) {
4
+ for (let index = array.length - 1; index >= 0; index--) {
5
+ const value = array[index];
6
+ if (predicate(value, index, array)) return value;
7
+ }
8
+ };
9
+ }
10
+ //#endregion
11
+ export { findLast };
@@ -0,0 +1,20 @@
1
+ //#region src/fp/array/findLastIndex.d.ts
2
+ /**
3
+ * Creates a function that returns the index of the last value matching a predicate.
4
+ *
5
+ * The predicate receives the value, index, and full input array while scanning from right
6
+ * to left. The returned function returns -1 when no value matches.
7
+ *
8
+ * @template T - The type of elements in the array.
9
+ * @param predicate - Called with each value, index, and array from right to left until it returns true.
10
+ * @returns A function that maps a readonly array to the last matching index, or -1.
11
+ *
12
+ * @example
13
+ * import { findLastIndex, pipe } from 'es-toolkit/fp';
14
+ *
15
+ * pipe([1, 2, 3, 2], findLastIndex(value => value === 2));
16
+ * // => 3
17
+ */
18
+ declare function findLastIndex<T>(predicate: (value: T, index: number, array: readonly T[]) => boolean): (array: readonly T[]) => number;
19
+ //#endregion
20
+ export { findLastIndex };
@@ -0,0 +1,20 @@
1
+ //#region src/fp/array/findLastIndex.d.ts
2
+ /**
3
+ * Creates a function that returns the index of the last value matching a predicate.
4
+ *
5
+ * The predicate receives the value, index, and full input array while scanning from right
6
+ * to left. The returned function returns -1 when no value matches.
7
+ *
8
+ * @template T - The type of elements in the array.
9
+ * @param predicate - Called with each value, index, and array from right to left until it returns true.
10
+ * @returns A function that maps a readonly array to the last matching index, or -1.
11
+ *
12
+ * @example
13
+ * import { findLastIndex, pipe } from 'es-toolkit/fp';
14
+ *
15
+ * pipe([1, 2, 3, 2], findLastIndex(value => value === 2));
16
+ * // => 3
17
+ */
18
+ declare function findLastIndex<T>(predicate: (value: T, index: number, array: readonly T[]) => boolean): (array: readonly T[]) => number;
19
+ //#endregion
20
+ export { findLastIndex };
@@ -0,0 +1,25 @@
1
+ //#region src/fp/array/findLastIndex.ts
2
+ /**
3
+ * Creates a function that returns the index of the last value matching a predicate.
4
+ *
5
+ * The predicate receives the value, index, and full input array while scanning from right
6
+ * to left. The returned function returns -1 when no value matches.
7
+ *
8
+ * @template T - The type of elements in the array.
9
+ * @param predicate - Called with each value, index, and array from right to left until it returns true.
10
+ * @returns A function that maps a readonly array to the last matching index, or -1.
11
+ *
12
+ * @example
13
+ * import { findLastIndex, pipe } from 'es-toolkit/fp';
14
+ *
15
+ * pipe([1, 2, 3, 2], findLastIndex(value => value === 2));
16
+ * // => 3
17
+ */
18
+ function findLastIndex(predicate) {
19
+ return function(array) {
20
+ for (let index = array.length - 1; index >= 0; index--) if (predicate(array[index], index, array)) return index;
21
+ return -1;
22
+ };
23
+ }
24
+ //#endregion
25
+ exports.findLastIndex = findLastIndex;
@@ -0,0 +1,25 @@
1
+ //#region src/fp/array/findLastIndex.ts
2
+ /**
3
+ * Creates a function that returns the index of the last value matching a predicate.
4
+ *
5
+ * The predicate receives the value, index, and full input array while scanning from right
6
+ * to left. The returned function returns -1 when no value matches.
7
+ *
8
+ * @template T - The type of elements in the array.
9
+ * @param predicate - Called with each value, index, and array from right to left until it returns true.
10
+ * @returns A function that maps a readonly array to the last matching index, or -1.
11
+ *
12
+ * @example
13
+ * import { findLastIndex, pipe } from 'es-toolkit/fp';
14
+ *
15
+ * pipe([1, 2, 3, 2], findLastIndex(value => value === 2));
16
+ * // => 3
17
+ */
18
+ function findLastIndex(predicate) {
19
+ return function(array) {
20
+ for (let index = array.length - 1; index >= 0; index--) if (predicate(array[index], index, array)) return index;
21
+ return -1;
22
+ };
23
+ }
24
+ //#endregion
25
+ export { findLastIndex };
@@ -0,0 +1,28 @@
1
+ //#region src/fp/array/flatMap.d.ts
2
+ /**
3
+ * Creates a function that maps every element to an array with `callback` and
4
+ * concatenates the results, equivalent to `Array.prototype.flatMap`. Use it
5
+ * with {@link pipe}.
6
+ *
7
+ * The returned function is **lazy-capable**: inside a {@link pipe} it is fused
8
+ * with adjacent lazy functions and runs element-by-element, so a trailing
9
+ * `take` can terminate the walk early without expanding the rest of the input.
10
+ *
11
+ * @template T - The type of elements in the input array.
12
+ * @template U - The type of elements in the output array.
13
+ * @param callback - Called with `(value, index)` for each element; returns an
14
+ * array whose elements are flattened into the output.
15
+ * @returns A function that maps a `readonly T[]` to a new `U[]`.
16
+ *
17
+ * @example
18
+ * import { pipe, flatMap } from 'es-toolkit/fp';
19
+ *
20
+ * pipe([1, 2, 3], flatMap(x => [x, x * 10])); // => [1, 10, 2, 20, 3, 30]
21
+ *
22
+ * @example
23
+ * // Returning an empty array drops the element.
24
+ * pipe([1, 2, 3, 4], flatMap(x => (x % 2 === 0 ? [x] : []))); // => [2, 4]
25
+ */
26
+ declare function flatMap<T, U>(callback: (value: T, index: number) => U[]): (array: readonly T[]) => U[];
27
+ //#endregion
28
+ export { flatMap };
@@ -0,0 +1,28 @@
1
+ //#region src/fp/array/flatMap.d.ts
2
+ /**
3
+ * Creates a function that maps every element to an array with `callback` and
4
+ * concatenates the results, equivalent to `Array.prototype.flatMap`. Use it
5
+ * with {@link pipe}.
6
+ *
7
+ * The returned function is **lazy-capable**: inside a {@link pipe} it is fused
8
+ * with adjacent lazy functions and runs element-by-element, so a trailing
9
+ * `take` can terminate the walk early without expanding the rest of the input.
10
+ *
11
+ * @template T - The type of elements in the input array.
12
+ * @template U - The type of elements in the output array.
13
+ * @param callback - Called with `(value, index)` for each element; returns an
14
+ * array whose elements are flattened into the output.
15
+ * @returns A function that maps a `readonly T[]` to a new `U[]`.
16
+ *
17
+ * @example
18
+ * import { pipe, flatMap } from 'es-toolkit/fp';
19
+ *
20
+ * pipe([1, 2, 3], flatMap(x => [x, x * 10])); // => [1, 10, 2, 20, 3, 30]
21
+ *
22
+ * @example
23
+ * // Returning an empty array drops the element.
24
+ * pipe([1, 2, 3, 4], flatMap(x => (x % 2 === 0 ? [x] : []))); // => [2, 4]
25
+ */
26
+ declare function flatMap<T, U>(callback: (value: T, index: number) => U[]): (array: readonly T[]) => U[];
27
+ //#endregion
28
+ export { flatMap };
@@ -0,0 +1,39 @@
1
+ const require_flatMap = require("../../array/flatMap.js");
2
+ const require_lazy = require("../_internal/lazy.js");
3
+ //#region src/fp/array/flatMap.ts
4
+ /**
5
+ * Creates a function that maps every element to an array with `callback` and
6
+ * concatenates the results, equivalent to `Array.prototype.flatMap`. Use it
7
+ * with {@link pipe}.
8
+ *
9
+ * The returned function is **lazy-capable**: inside a {@link pipe} it is fused
10
+ * with adjacent lazy functions and runs element-by-element, so a trailing
11
+ * `take` can terminate the walk early without expanding the rest of the input.
12
+ *
13
+ * @template T - The type of elements in the input array.
14
+ * @template U - The type of elements in the output array.
15
+ * @param callback - Called with `(value, index)` for each element; returns an
16
+ * array whose elements are flattened into the output.
17
+ * @returns A function that maps a `readonly T[]` to a new `U[]`.
18
+ *
19
+ * @example
20
+ * import { pipe, flatMap } from 'es-toolkit/fp';
21
+ *
22
+ * pipe([1, 2, 3], flatMap(x => [x, x * 10])); // => [1, 10, 2, 20, 3, 30]
23
+ *
24
+ * @example
25
+ * // Returning an empty array drops the element.
26
+ * pipe([1, 2, 3, 4], flatMap(x => (x % 2 === 0 ? [x] : []))); // => [2, 4]
27
+ */
28
+ function flatMap(callback) {
29
+ function flatMapEager(array) {
30
+ return require_flatMap.flatMap(array, callback);
31
+ }
32
+ const flatMapLazy = require_lazy.createLazyFunction((value, index, emit) => {
33
+ const items = callback(value, index);
34
+ for (let i = 0; i < items.length; i++) emit(items[i]);
35
+ });
36
+ return require_lazy.combineEagerAndLazyFunctions(flatMapEager, flatMapLazy);
37
+ }
38
+ //#endregion
39
+ exports.flatMap = flatMap;
@@ -0,0 +1,38 @@
1
+ import { flatMap as flatMap$1 } from "../../array/flatMap.mjs";
2
+ import { combineEagerAndLazyFunctions, createLazyFunction } from "../_internal/lazy.mjs";
3
+ //#region src/fp/array/flatMap.ts
4
+ /**
5
+ * Creates a function that maps every element to an array with `callback` and
6
+ * concatenates the results, equivalent to `Array.prototype.flatMap`. Use it
7
+ * with {@link pipe}.
8
+ *
9
+ * The returned function is **lazy-capable**: inside a {@link pipe} it is fused
10
+ * with adjacent lazy functions and runs element-by-element, so a trailing
11
+ * `take` can terminate the walk early without expanding the rest of the input.
12
+ *
13
+ * @template T - The type of elements in the input array.
14
+ * @template U - The type of elements in the output array.
15
+ * @param callback - Called with `(value, index)` for each element; returns an
16
+ * array whose elements are flattened into the output.
17
+ * @returns A function that maps a `readonly T[]` to a new `U[]`.
18
+ *
19
+ * @example
20
+ * import { pipe, flatMap } from 'es-toolkit/fp';
21
+ *
22
+ * pipe([1, 2, 3], flatMap(x => [x, x * 10])); // => [1, 10, 2, 20, 3, 30]
23
+ *
24
+ * @example
25
+ * // Returning an empty array drops the element.
26
+ * pipe([1, 2, 3, 4], flatMap(x => (x % 2 === 0 ? [x] : []))); // => [2, 4]
27
+ */
28
+ function flatMap(callback) {
29
+ function flatMapEager(array) {
30
+ return flatMap$1(array, callback);
31
+ }
32
+ return combineEagerAndLazyFunctions(flatMapEager, createLazyFunction((value, index, emit) => {
33
+ const items = callback(value, index);
34
+ for (let i = 0; i < items.length; i++) emit(items[i]);
35
+ }));
36
+ }
37
+ //#endregion
38
+ export { flatMap };
@@ -0,0 +1,23 @@
1
+ import { ExtractNestedArrayType } from "../../array/flattenDeep.mjs";
2
+
3
+ //#region src/fp/array/flatMapDeep.d.ts
4
+ /**
5
+ * Creates a function that maps each element and recursively flattens the mapped values.
6
+ *
7
+ * The iteratee receives each value and index. The returned function is lazy-capable inside
8
+ * {@link pipe}; a trailing short-circuiting operator can stop before later input values are mapped.
9
+ *
10
+ * @template T - The type of elements in the input array.
11
+ * @template U - The type returned by the iteratee before recursive flattening.
12
+ * @param iteratee - Called with each value and index to produce values to flatten.
13
+ * @returns A function that maps a readonly array to a deeply flattened array.
14
+ *
15
+ * @example
16
+ * import { flatMapDeep, pipe } from 'es-toolkit/fp';
17
+ *
18
+ * pipe([1, 2], flatMapDeep(value => [[value, value * 10]]));
19
+ * // => [1, 10, 2, 20]
20
+ */
21
+ declare function flatMapDeep<T, U>(iteratee: (item: T, index: number) => U): (array: readonly T[]) => Array<ExtractNestedArrayType<U>>;
22
+ //#endregion
23
+ export { flatMapDeep };
@@ -0,0 +1,23 @@
1
+ import { ExtractNestedArrayType } from "../../array/flattenDeep.js";
2
+
3
+ //#region src/fp/array/flatMapDeep.d.ts
4
+ /**
5
+ * Creates a function that maps each element and recursively flattens the mapped values.
6
+ *
7
+ * The iteratee receives each value and index. The returned function is lazy-capable inside
8
+ * {@link pipe}; a trailing short-circuiting operator can stop before later input values are mapped.
9
+ *
10
+ * @template T - The type of elements in the input array.
11
+ * @template U - The type returned by the iteratee before recursive flattening.
12
+ * @param iteratee - Called with each value and index to produce values to flatten.
13
+ * @returns A function that maps a readonly array to a deeply flattened array.
14
+ *
15
+ * @example
16
+ * import { flatMapDeep, pipe } from 'es-toolkit/fp';
17
+ *
18
+ * pipe([1, 2], flatMapDeep(value => [[value, value * 10]]));
19
+ * // => [1, 10, 2, 20]
20
+ */
21
+ declare function flatMapDeep<T, U>(iteratee: (item: T, index: number) => U): (array: readonly T[]) => Array<ExtractNestedArrayType<U>>;
22
+ //#endregion
23
+ export { flatMapDeep };
@@ -0,0 +1,38 @@
1
+ const require_flatMapDeep = require("../../array/flatMapDeep.js");
2
+ const require_lazy = require("../_internal/lazy.js");
3
+ //#region src/fp/array/flatMapDeep.ts
4
+ /**
5
+ * Creates a function that maps each element and recursively flattens the mapped values.
6
+ *
7
+ * The iteratee receives each value and index. The returned function is lazy-capable inside
8
+ * {@link pipe}; a trailing short-circuiting operator can stop before later input values are mapped.
9
+ *
10
+ * @template T - The type of elements in the input array.
11
+ * @template U - The type returned by the iteratee before recursive flattening.
12
+ * @param iteratee - Called with each value and index to produce values to flatten.
13
+ * @returns A function that maps a readonly array to a deeply flattened array.
14
+ *
15
+ * @example
16
+ * import { flatMapDeep, pipe } from 'es-toolkit/fp';
17
+ *
18
+ * pipe([1, 2], flatMapDeep(value => [[value, value * 10]]));
19
+ * // => [1, 10, 2, 20]
20
+ */
21
+ function flatMapDeep(iteratee) {
22
+ function flatMapDeepEager(array) {
23
+ return require_flatMapDeep.flatMapDeep(array, (item, index) => iteratee(item, index));
24
+ }
25
+ const flatMapDeepLazy = require_lazy.createLazyFunction((value, index, emit) => {
26
+ emitDeep(iteratee(value, index), emit);
27
+ });
28
+ return require_lazy.combineEagerAndLazyFunctions(flatMapDeepEager, flatMapDeepLazy);
29
+ }
30
+ function emitDeep(value, emit) {
31
+ if (Array.isArray(value)) {
32
+ for (let index = 0; index < value.length; index++) emitDeep(value[index], emit);
33
+ return;
34
+ }
35
+ emit(value);
36
+ }
37
+ //#endregion
38
+ exports.flatMapDeep = flatMapDeep;
@@ -0,0 +1,37 @@
1
+ import { flatMapDeep as flatMapDeep$1 } from "../../array/flatMapDeep.mjs";
2
+ import { combineEagerAndLazyFunctions, createLazyFunction } from "../_internal/lazy.mjs";
3
+ //#region src/fp/array/flatMapDeep.ts
4
+ /**
5
+ * Creates a function that maps each element and recursively flattens the mapped values.
6
+ *
7
+ * The iteratee receives each value and index. The returned function is lazy-capable inside
8
+ * {@link pipe}; a trailing short-circuiting operator can stop before later input values are mapped.
9
+ *
10
+ * @template T - The type of elements in the input array.
11
+ * @template U - The type returned by the iteratee before recursive flattening.
12
+ * @param iteratee - Called with each value and index to produce values to flatten.
13
+ * @returns A function that maps a readonly array to a deeply flattened array.
14
+ *
15
+ * @example
16
+ * import { flatMapDeep, pipe } from 'es-toolkit/fp';
17
+ *
18
+ * pipe([1, 2], flatMapDeep(value => [[value, value * 10]]));
19
+ * // => [1, 10, 2, 20]
20
+ */
21
+ function flatMapDeep(iteratee) {
22
+ function flatMapDeepEager(array) {
23
+ return flatMapDeep$1(array, (item, index) => iteratee(item, index));
24
+ }
25
+ return combineEagerAndLazyFunctions(flatMapDeepEager, createLazyFunction((value, index, emit) => {
26
+ emitDeep(iteratee(value, index), emit);
27
+ }));
28
+ }
29
+ function emitDeep(value, emit) {
30
+ if (Array.isArray(value)) {
31
+ for (let index = 0; index < value.length; index++) emitDeep(value[index], emit);
32
+ return;
33
+ }
34
+ emit(value);
35
+ }
36
+ //#endregion
37
+ export { flatMapDeep };
@@ -0,0 +1,21 @@
1
+ //#region src/fp/array/flatten.d.ts
2
+ /**
3
+ * Creates a function that flattens an array up to the specified depth.
4
+ *
5
+ * The returned function is lazy-capable inside {@link pipe}. A trailing
6
+ * short-circuiting operator can stop before later nested values are visited.
7
+ *
8
+ * @template T - The type of elements in the array.
9
+ * @template D - The depth to which nested arrays should be flattened.
10
+ * @param depth - The flattening depth. Defaults to 1.
11
+ * @returns A function that maps the piped array to a flattened array.
12
+ *
13
+ * @example
14
+ * import { flatten, pipe } from 'es-toolkit/fp';
15
+ *
16
+ * pipe([1, [2, [3]]], flatten(2));
17
+ * // => [1, 2, 3]
18
+ */
19
+ declare function flatten<T, D extends number = 1>(depth?: D): (array: readonly T[]) => Array<FlatArray<T[], D>>;
20
+ //#endregion
21
+ export { flatten };
@@ -0,0 +1,21 @@
1
+ //#region src/fp/array/flatten.d.ts
2
+ /**
3
+ * Creates a function that flattens an array up to the specified depth.
4
+ *
5
+ * The returned function is lazy-capable inside {@link pipe}. A trailing
6
+ * short-circuiting operator can stop before later nested values are visited.
7
+ *
8
+ * @template T - The type of elements in the array.
9
+ * @template D - The depth to which nested arrays should be flattened.
10
+ * @param depth - The flattening depth. Defaults to 1.
11
+ * @returns A function that maps the piped array to a flattened array.
12
+ *
13
+ * @example
14
+ * import { flatten, pipe } from 'es-toolkit/fp';
15
+ *
16
+ * pipe([1, [2, [3]]], flatten(2));
17
+ * // => [1, 2, 3]
18
+ */
19
+ declare function flatten<T, D extends number = 1>(depth?: D): (array: readonly T[]) => Array<FlatArray<T[], D>>;
20
+ //#endregion
21
+ export { flatten };
@@ -0,0 +1,39 @@
1
+ const require_flatten = require("../../array/flatten.js");
2
+ const require_lazy = require("../_internal/lazy.js");
3
+ //#region src/fp/array/flatten.ts
4
+ /**
5
+ * Creates a function that flattens an array up to the specified depth.
6
+ *
7
+ * The returned function is lazy-capable inside {@link pipe}. A trailing
8
+ * short-circuiting operator can stop before later nested values are visited.
9
+ *
10
+ * @template T - The type of elements in the array.
11
+ * @template D - The depth to which nested arrays should be flattened.
12
+ * @param depth - The flattening depth. Defaults to 1.
13
+ * @returns A function that maps the piped array to a flattened array.
14
+ *
15
+ * @example
16
+ * import { flatten, pipe } from 'es-toolkit/fp';
17
+ *
18
+ * pipe([1, [2, [3]]], flatten(2));
19
+ * // => [1, 2, 3]
20
+ */
21
+ function flatten(depth = 1) {
22
+ const flooredDepth = Math.floor(depth);
23
+ function flattenEager(array) {
24
+ return require_flatten.flatten(array, depth);
25
+ }
26
+ const flattenLazy = require_lazy.createLazyFunction((value, _index, emit) => {
27
+ emitFlattened(value, 0, flooredDepth, emit);
28
+ });
29
+ return require_lazy.combineEagerAndLazyFunctions(flattenEager, flattenLazy);
30
+ }
31
+ function emitFlattened(value, currentDepth, maxDepth, emit) {
32
+ if (Array.isArray(value) && currentDepth < maxDepth) {
33
+ for (let index = 0; index < value.length; index++) emitFlattened(value[index], currentDepth + 1, maxDepth, emit);
34
+ return;
35
+ }
36
+ emit(value);
37
+ }
38
+ //#endregion
39
+ exports.flatten = flatten;
@@ -0,0 +1,38 @@
1
+ import { flatten as flatten$1 } from "../../array/flatten.mjs";
2
+ import { combineEagerAndLazyFunctions, createLazyFunction } from "../_internal/lazy.mjs";
3
+ //#region src/fp/array/flatten.ts
4
+ /**
5
+ * Creates a function that flattens an array up to the specified depth.
6
+ *
7
+ * The returned function is lazy-capable inside {@link pipe}. A trailing
8
+ * short-circuiting operator can stop before later nested values are visited.
9
+ *
10
+ * @template T - The type of elements in the array.
11
+ * @template D - The depth to which nested arrays should be flattened.
12
+ * @param depth - The flattening depth. Defaults to 1.
13
+ * @returns A function that maps the piped array to a flattened array.
14
+ *
15
+ * @example
16
+ * import { flatten, pipe } from 'es-toolkit/fp';
17
+ *
18
+ * pipe([1, [2, [3]]], flatten(2));
19
+ * // => [1, 2, 3]
20
+ */
21
+ function flatten(depth = 1) {
22
+ const flooredDepth = Math.floor(depth);
23
+ function flattenEager(array) {
24
+ return flatten$1(array, depth);
25
+ }
26
+ return combineEagerAndLazyFunctions(flattenEager, createLazyFunction((value, _index, emit) => {
27
+ emitFlattened(value, 0, flooredDepth, emit);
28
+ }));
29
+ }
30
+ function emitFlattened(value, currentDepth, maxDepth, emit) {
31
+ if (Array.isArray(value) && currentDepth < maxDepth) {
32
+ for (let index = 0; index < value.length; index++) emitFlattened(value[index], currentDepth + 1, maxDepth, emit);
33
+ return;
34
+ }
35
+ emit(value);
36
+ }
37
+ //#endregion
38
+ export { flatten };
@@ -0,0 +1,21 @@
1
+ import { ExtractNestedArrayType } from "../../array/flattenDeep.mjs";
2
+
3
+ //#region src/fp/array/flattenDeep.d.ts
4
+ /**
5
+ * Creates a function that recursively flattens an array.
6
+ *
7
+ * The returned function is lazy-capable inside {@link pipe}. A trailing
8
+ * short-circuiting operator can stop before later nested values are visited.
9
+ *
10
+ * @template T - The type of elements in the array.
11
+ * @returns A function that maps the piped array to a deeply flattened array.
12
+ *
13
+ * @example
14
+ * import { flattenDeep, pipe } from 'es-toolkit/fp';
15
+ *
16
+ * pipe([1, [2, [3]]], flattenDeep());
17
+ * // => [1, 2, 3]
18
+ */
19
+ declare function flattenDeep<T>(): (array: readonly T[]) => Array<ExtractNestedArrayType<T>>;
20
+ //#endregion
21
+ export { flattenDeep };
@@ -0,0 +1,21 @@
1
+ import { ExtractNestedArrayType } from "../../array/flattenDeep.js";
2
+
3
+ //#region src/fp/array/flattenDeep.d.ts
4
+ /**
5
+ * Creates a function that recursively flattens an array.
6
+ *
7
+ * The returned function is lazy-capable inside {@link pipe}. A trailing
8
+ * short-circuiting operator can stop before later nested values are visited.
9
+ *
10
+ * @template T - The type of elements in the array.
11
+ * @returns A function that maps the piped array to a deeply flattened array.
12
+ *
13
+ * @example
14
+ * import { flattenDeep, pipe } from 'es-toolkit/fp';
15
+ *
16
+ * pipe([1, [2, [3]]], flattenDeep());
17
+ * // => [1, 2, 3]
18
+ */
19
+ declare function flattenDeep<T>(): (array: readonly T[]) => Array<ExtractNestedArrayType<T>>;
20
+ //#endregion
21
+ export { flattenDeep };
@@ -0,0 +1,36 @@
1
+ const require_flattenDeep = require("../../array/flattenDeep.js");
2
+ const require_lazy = require("../_internal/lazy.js");
3
+ //#region src/fp/array/flattenDeep.ts
4
+ /**
5
+ * Creates a function that recursively flattens an array.
6
+ *
7
+ * The returned function is lazy-capable inside {@link pipe}. A trailing
8
+ * short-circuiting operator can stop before later nested values are visited.
9
+ *
10
+ * @template T - The type of elements in the array.
11
+ * @returns A function that maps the piped array to a deeply flattened array.
12
+ *
13
+ * @example
14
+ * import { flattenDeep, pipe } from 'es-toolkit/fp';
15
+ *
16
+ * pipe([1, [2, [3]]], flattenDeep());
17
+ * // => [1, 2, 3]
18
+ */
19
+ function flattenDeep() {
20
+ function flattenDeepEager(array) {
21
+ return require_flattenDeep.flattenDeep(array);
22
+ }
23
+ const flattenDeepLazy = require_lazy.createLazyFunction((value, _index, emit) => {
24
+ emitDeep(value, emit);
25
+ });
26
+ return require_lazy.combineEagerAndLazyFunctions(flattenDeepEager, flattenDeepLazy);
27
+ }
28
+ function emitDeep(value, emit) {
29
+ if (Array.isArray(value)) {
30
+ for (let index = 0; index < value.length; index++) emitDeep(value[index], emit);
31
+ return;
32
+ }
33
+ emit(value);
34
+ }
35
+ //#endregion
36
+ exports.flattenDeep = flattenDeep;
@@ -0,0 +1,35 @@
1
+ import { flattenDeep as flattenDeep$1 } from "../../array/flattenDeep.mjs";
2
+ import { combineEagerAndLazyFunctions, createLazyFunction } from "../_internal/lazy.mjs";
3
+ //#region src/fp/array/flattenDeep.ts
4
+ /**
5
+ * Creates a function that recursively flattens an array.
6
+ *
7
+ * The returned function is lazy-capable inside {@link pipe}. A trailing
8
+ * short-circuiting operator can stop before later nested values are visited.
9
+ *
10
+ * @template T - The type of elements in the array.
11
+ * @returns A function that maps the piped array to a deeply flattened array.
12
+ *
13
+ * @example
14
+ * import { flattenDeep, pipe } from 'es-toolkit/fp';
15
+ *
16
+ * pipe([1, [2, [3]]], flattenDeep());
17
+ * // => [1, 2, 3]
18
+ */
19
+ function flattenDeep() {
20
+ function flattenDeepEager(array) {
21
+ return flattenDeep$1(array);
22
+ }
23
+ return combineEagerAndLazyFunctions(flattenDeepEager, createLazyFunction((value, _index, emit) => {
24
+ emitDeep(value, emit);
25
+ }));
26
+ }
27
+ function emitDeep(value, emit) {
28
+ if (Array.isArray(value)) {
29
+ for (let index = 0; index < value.length; index++) emitDeep(value[index], emit);
30
+ return;
31
+ }
32
+ emit(value);
33
+ }
34
+ //#endregion
35
+ export { flattenDeep };