@vinicunca/perkakas 0.1.0 → 0.3.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 (605) hide show
  1. package/README.md +9 -0
  2. package/dist/commonjs/aria/index.js +17 -0
  3. package/dist/commonjs/aria/key-codes.js +25 -0
  4. package/dist/commonjs/array/all-pass.js +11 -0
  5. package/dist/commonjs/array/any-pass.js +11 -0
  6. package/dist/commonjs/array/chunk.js +17 -0
  7. package/dist/commonjs/array/compact.js +8 -0
  8. package/dist/commonjs/array/concat.js +11 -0
  9. package/dist/commonjs/array/count-by.js +22 -0
  10. package/dist/commonjs/array/difference-with.js +31 -0
  11. package/dist/commonjs/array/difference.js +32 -0
  12. package/dist/commonjs/array/drop-first-by.js +26 -0
  13. package/dist/commonjs/array/drop-last-while.js +16 -0
  14. package/dist/commonjs/array/drop-last.js +15 -0
  15. package/dist/commonjs/array/drop-while.js +16 -0
  16. package/dist/commonjs/array/drop.js +32 -0
  17. package/dist/commonjs/array/filter.js +41 -0
  18. package/dist/commonjs/array/find-index.js +46 -0
  19. package/dist/commonjs/array/find-last-index.js +24 -0
  20. package/dist/commonjs/array/find-last.js +24 -0
  21. package/dist/commonjs/array/find.js +38 -0
  22. package/dist/commonjs/array/first-by.js +22 -0
  23. package/dist/commonjs/array/first.js +26 -0
  24. package/dist/commonjs/array/flat-map-to-obj.js +25 -0
  25. package/dist/commonjs/array/flat-map.js +33 -0
  26. package/dist/commonjs/array/flatten-deep.js +48 -0
  27. package/dist/commonjs/array/flatten.js +32 -0
  28. package/dist/commonjs/array/for-each.js +40 -0
  29. package/dist/commonjs/array/group-by.js +33 -0
  30. package/dist/commonjs/array/has-at-least.js +11 -0
  31. package/dist/commonjs/array/index-by.js +24 -0
  32. package/dist/commonjs/array/index.js +81 -0
  33. package/dist/commonjs/array/intersection-with.js +31 -0
  34. package/dist/commonjs/array/intersection.js +32 -0
  35. package/dist/commonjs/array/join.js +11 -0
  36. package/dist/commonjs/array/last.js +11 -0
  37. package/dist/commonjs/array/length.js +11 -0
  38. package/dist/commonjs/array/map-to-obj.js +23 -0
  39. package/dist/commonjs/array/map.js +35 -0
  40. package/dist/commonjs/array/max-by.js +28 -0
  41. package/dist/commonjs/array/mean-by.js +26 -0
  42. package/dist/commonjs/array/merge-all.js +7 -0
  43. package/dist/commonjs/array/min-by.js +28 -0
  44. package/dist/commonjs/array/nth-by.js +12 -0
  45. package/dist/commonjs/array/only.js +14 -0
  46. package/dist/commonjs/array/partition.js +24 -0
  47. package/dist/commonjs/array/range.js +15 -0
  48. package/dist/commonjs/array/rank-by.js +17 -0
  49. package/dist/commonjs/array/reduce.js +19 -0
  50. package/dist/commonjs/array/reject.js +41 -0
  51. package/dist/commonjs/array/reverse.js +11 -0
  52. package/dist/commonjs/array/sample.js +34 -0
  53. package/dist/commonjs/array/shuffle.js +18 -0
  54. package/dist/commonjs/array/sort-by.js +52 -0
  55. package/dist/commonjs/array/sort.js +16 -0
  56. package/dist/commonjs/array/splice.js +13 -0
  57. package/dist/commonjs/array/split-at.js +13 -0
  58. package/dist/commonjs/array/split-when.js +17 -0
  59. package/dist/commonjs/array/sum-by.js +24 -0
  60. package/dist/commonjs/array/swap-indices.js +34 -0
  61. package/dist/commonjs/array/take-first-by.js +24 -0
  62. package/dist/commonjs/array/take-while.js +18 -0
  63. package/dist/commonjs/array/take.js +38 -0
  64. package/dist/commonjs/array/uniq-by.js +30 -0
  65. package/dist/commonjs/array/uniq-with.js +33 -0
  66. package/dist/commonjs/array/uniq.js +32 -0
  67. package/dist/commonjs/array/zip-obj.js +16 -0
  68. package/dist/commonjs/array/zip-with.js +23 -0
  69. package/dist/commonjs/array/zip.js +19 -0
  70. package/dist/commonjs/function/conditional.js +34 -0
  71. package/dist/commonjs/function/create-pipe.js +8 -0
  72. package/dist/commonjs/function/debounce.js +88 -0
  73. package/dist/commonjs/function/identity.js +7 -0
  74. package/dist/commonjs/function/index.js +25 -0
  75. package/dist/commonjs/function/noop.js +7 -0
  76. package/dist/commonjs/function/once.js +15 -0
  77. package/dist/commonjs/function/pipe.js +106 -0
  78. package/dist/commonjs/function/purry.js +20 -0
  79. package/dist/commonjs/function/sleep.js +9 -0
  80. package/dist/commonjs/guard/index.js +32 -0
  81. package/dist/commonjs/guard/is-array.js +7 -0
  82. package/dist/commonjs/guard/is-boolean.js +7 -0
  83. package/dist/commonjs/guard/is-date.js +7 -0
  84. package/dist/commonjs/guard/is-defined.js +13 -0
  85. package/dist/commonjs/guard/is-empty.js +19 -0
  86. package/dist/commonjs/guard/is-error.js +7 -0
  87. package/dist/commonjs/guard/is-function.js +7 -0
  88. package/dist/commonjs/guard/is-nil.js +7 -0
  89. package/dist/commonjs/guard/is-non-null.js +7 -0
  90. package/dist/commonjs/guard/is-not.js +9 -0
  91. package/dist/commonjs/guard/is-number.js +7 -0
  92. package/dist/commonjs/guard/is-object.js +11 -0
  93. package/dist/commonjs/guard/is-promise.js +7 -0
  94. package/dist/commonjs/guard/is-string.js +7 -0
  95. package/dist/commonjs/guard/is-symbol.js +7 -0
  96. package/dist/commonjs/guard/is-truthy.js +7 -0
  97. package/dist/commonjs/index.js +26 -0
  98. package/dist/commonjs/number/add.js +11 -0
  99. package/dist/commonjs/number/ceil.js +9 -0
  100. package/dist/commonjs/number/clamp.js +17 -0
  101. package/dist/commonjs/number/divide.js +11 -0
  102. package/dist/commonjs/number/floor.js +9 -0
  103. package/dist/commonjs/number/index.js +24 -0
  104. package/dist/commonjs/number/multiply.js +11 -0
  105. package/dist/commonjs/number/round.js +9 -0
  106. package/dist/commonjs/number/subtract.js +11 -0
  107. package/dist/commonjs/object/add-prop.js +14 -0
  108. package/dist/commonjs/object/clone.js +49 -0
  109. package/dist/commonjs/object/equals.js +71 -0
  110. package/dist/commonjs/object/for-each-obj.js +30 -0
  111. package/dist/commonjs/object/from-pairs.js +14 -0
  112. package/dist/commonjs/object/index.js +39 -0
  113. package/dist/commonjs/object/invert.js +15 -0
  114. package/dist/commonjs/object/keys.js +10 -0
  115. package/dist/commonjs/object/map-keys.js +16 -0
  116. package/dist/commonjs/object/map-values.js +16 -0
  117. package/dist/commonjs/object/merge-deep.js +31 -0
  118. package/dist/commonjs/object/merge.js +11 -0
  119. package/dist/commonjs/object/omit-by.js +20 -0
  120. package/dist/commonjs/object/omit.js +25 -0
  121. package/dist/commonjs/object/path-or.js +18 -0
  122. package/dist/commonjs/object/pick-by.js +20 -0
  123. package/dist/commonjs/object/pick.js +19 -0
  124. package/dist/commonjs/object/prop.js +7 -0
  125. package/dist/commonjs/object/set-path.js +26 -0
  126. package/dist/commonjs/object/set.js +14 -0
  127. package/dist/commonjs/object/swap-props.js +16 -0
  128. package/dist/commonjs/object/to-pairs.js +11 -0
  129. package/dist/commonjs/object/values.js +7 -0
  130. package/dist/commonjs/string/cases-types.js +2 -0
  131. package/dist/commonjs/string/cases.js +107 -0
  132. package/dist/commonjs/string/human-readable-file-size.js +16 -0
  133. package/dist/commonjs/string/index.js +21 -0
  134. package/dist/commonjs/string/random-string.js +10 -0
  135. package/dist/commonjs/string/slugify.js +13 -0
  136. package/dist/commonjs/string/string-to-path.js +18 -0
  137. package/dist/commonjs/type/index.js +17 -0
  138. package/dist/commonjs/type/type.js +13 -0
  139. package/dist/commonjs/utils/heap.js +43 -0
  140. package/dist/commonjs/utils/narrow.js +2 -0
  141. package/dist/commonjs/utils/paths.js +2 -0
  142. package/dist/commonjs/utils/purry-on.js +10 -0
  143. package/dist/commonjs/utils/purry-order-rules.js +66 -0
  144. package/dist/commonjs/utils/quick-select.js +31 -0
  145. package/dist/commonjs/utils/reduce-lazy.js +18 -0
  146. package/dist/commonjs/utils/swap-in-place.js +7 -0
  147. package/dist/commonjs/utils/to-lazy-indexed.js +7 -0
  148. package/dist/commonjs/utils/to-single.js +8 -0
  149. package/dist/commonjs/utils/types.js +2 -0
  150. package/dist/commonjs/utils/with-precision.js +23 -0
  151. package/dist/es/aria/index.js +1 -0
  152. package/dist/es/aria/key-codes.js +22 -0
  153. package/dist/es/array/all-pass.js +7 -0
  154. package/dist/es/array/any-pass.js +7 -0
  155. package/dist/es/array/chunk.js +13 -0
  156. package/dist/es/array/compact.js +4 -0
  157. package/dist/es/array/concat.js +7 -0
  158. package/dist/es/array/count-by.js +18 -0
  159. package/dist/es/array/difference-with.js +27 -0
  160. package/dist/es/array/difference.js +28 -0
  161. package/dist/es/array/drop-first-by.js +22 -0
  162. package/dist/es/array/drop-last-while.js +12 -0
  163. package/dist/es/array/drop-last.js +11 -0
  164. package/dist/es/array/drop-while.js +12 -0
  165. package/dist/es/array/drop.js +28 -0
  166. package/dist/es/array/filter.js +37 -0
  167. package/dist/es/array/find-index.js +42 -0
  168. package/dist/es/array/find-last-index.js +20 -0
  169. package/dist/es/array/find-last.js +20 -0
  170. package/dist/es/array/find.js +34 -0
  171. package/dist/es/array/first-by.js +18 -0
  172. package/dist/es/array/first.js +22 -0
  173. package/dist/es/array/flat-map-to-obj.js +21 -0
  174. package/dist/es/array/flat-map.js +29 -0
  175. package/dist/es/array/flatten-deep.js +44 -0
  176. package/dist/es/array/flatten.js +28 -0
  177. package/dist/es/array/for-each.js +36 -0
  178. package/dist/es/array/group-by.js +29 -0
  179. package/dist/es/array/has-at-least.js +7 -0
  180. package/dist/es/array/index-by.js +20 -0
  181. package/dist/es/array/index.js +65 -0
  182. package/dist/es/array/intersection-with.js +27 -0
  183. package/dist/es/array/intersection.js +28 -0
  184. package/dist/es/array/join.js +7 -0
  185. package/dist/es/array/last.js +7 -0
  186. package/dist/es/array/length.js +7 -0
  187. package/dist/es/array/map-to-obj.js +19 -0
  188. package/dist/es/array/map.js +31 -0
  189. package/dist/es/array/max-by.js +24 -0
  190. package/dist/es/array/mean-by.js +22 -0
  191. package/dist/es/array/merge-all.js +3 -0
  192. package/dist/es/array/min-by.js +24 -0
  193. package/dist/es/array/nth-by.js +8 -0
  194. package/dist/es/array/only.js +10 -0
  195. package/dist/es/array/partition.js +20 -0
  196. package/dist/es/array/range.js +11 -0
  197. package/dist/es/array/rank-by.js +13 -0
  198. package/dist/es/array/reduce.js +15 -0
  199. package/dist/es/array/reject.js +37 -0
  200. package/dist/es/array/reverse.js +7 -0
  201. package/dist/es/array/sample.js +30 -0
  202. package/dist/es/array/shuffle.js +14 -0
  203. package/dist/es/array/sort-by.js +48 -0
  204. package/dist/es/array/sort.js +12 -0
  205. package/dist/es/array/splice.js +9 -0
  206. package/dist/es/array/split-at.js +9 -0
  207. package/dist/es/array/split-when.js +13 -0
  208. package/dist/es/array/sum-by.js +20 -0
  209. package/dist/es/array/swap-indices.js +30 -0
  210. package/dist/es/array/take-first-by.js +20 -0
  211. package/dist/es/array/take-while.js +14 -0
  212. package/dist/es/array/take.js +34 -0
  213. package/dist/es/array/uniq-by.js +26 -0
  214. package/dist/es/array/uniq-with.js +29 -0
  215. package/dist/es/array/uniq.js +28 -0
  216. package/dist/es/array/zip-obj.js +12 -0
  217. package/dist/es/array/zip-with.js +19 -0
  218. package/dist/es/array/zip.js +15 -0
  219. package/dist/es/function/conditional.js +30 -0
  220. package/dist/es/function/create-pipe.js +4 -0
  221. package/dist/es/function/debounce.js +84 -0
  222. package/dist/es/function/identity.js +3 -0
  223. package/dist/es/function/index.js +9 -0
  224. package/dist/es/function/noop.js +3 -0
  225. package/dist/es/function/once.js +11 -0
  226. package/dist/es/function/pipe.js +102 -0
  227. package/dist/es/function/purry.js +16 -0
  228. package/dist/es/function/sleep.js +5 -0
  229. package/dist/es/guard/index.js +16 -0
  230. package/dist/es/guard/is-array.js +3 -0
  231. package/dist/es/guard/is-boolean.js +3 -0
  232. package/dist/es/guard/is-date.js +3 -0
  233. package/dist/es/guard/is-defined.js +9 -0
  234. package/dist/es/guard/is-empty.js +15 -0
  235. package/dist/es/guard/is-error.js +3 -0
  236. package/dist/es/guard/is-function.js +3 -0
  237. package/dist/es/guard/is-nil.js +3 -0
  238. package/dist/es/guard/is-non-null.js +3 -0
  239. package/dist/es/guard/is-not.js +5 -0
  240. package/dist/es/guard/is-number.js +3 -0
  241. package/dist/es/guard/is-object.js +7 -0
  242. package/dist/es/guard/is-promise.js +3 -0
  243. package/dist/es/guard/is-string.js +3 -0
  244. package/dist/es/guard/is-symbol.js +3 -0
  245. package/dist/es/guard/is-truthy.js +3 -0
  246. package/dist/es/index.js +9 -0
  247. package/dist/es/number/add.js +7 -0
  248. package/dist/es/number/ceil.js +5 -0
  249. package/dist/es/number/clamp.js +13 -0
  250. package/dist/es/number/divide.js +7 -0
  251. package/dist/es/number/floor.js +5 -0
  252. package/dist/es/number/index.js +8 -0
  253. package/dist/es/number/multiply.js +7 -0
  254. package/dist/es/number/round.js +5 -0
  255. package/dist/es/number/subtract.js +7 -0
  256. package/dist/es/object/add-prop.js +10 -0
  257. package/dist/es/object/clone.js +45 -0
  258. package/dist/es/object/equals.js +67 -0
  259. package/dist/es/object/for-each-obj.js +26 -0
  260. package/dist/es/object/from-pairs.js +10 -0
  261. package/dist/es/object/index.js +23 -0
  262. package/dist/es/object/invert.js +11 -0
  263. package/dist/es/object/keys.js +6 -0
  264. package/dist/es/object/map-keys.js +12 -0
  265. package/dist/es/object/map-values.js +12 -0
  266. package/dist/es/object/merge-deep.js +27 -0
  267. package/dist/es/object/merge.js +7 -0
  268. package/dist/es/object/omit-by.js +16 -0
  269. package/dist/es/object/omit.js +21 -0
  270. package/dist/es/object/path-or.js +14 -0
  271. package/dist/es/object/pick-by.js +16 -0
  272. package/dist/es/object/pick.js +15 -0
  273. package/dist/es/object/prop.js +3 -0
  274. package/dist/es/object/set-path.js +21 -0
  275. package/dist/es/object/set.js +10 -0
  276. package/dist/es/object/swap-props.js +12 -0
  277. package/dist/es/object/to-pairs.js +7 -0
  278. package/dist/es/object/values.js +3 -0
  279. package/dist/es/string/cases-types.js +1 -0
  280. package/dist/es/string/cases.js +93 -0
  281. package/dist/es/string/human-readable-file-size.js +12 -0
  282. package/dist/es/string/index.js +5 -0
  283. package/dist/es/string/random-string.js +6 -0
  284. package/dist/es/string/slugify.js +9 -0
  285. package/dist/es/string/string-to-path.js +14 -0
  286. package/dist/es/type/index.js +1 -0
  287. package/dist/es/type/type.js +9 -0
  288. package/dist/es/utils/heap.js +38 -0
  289. package/dist/es/utils/narrow.js +1 -0
  290. package/dist/es/utils/paths.js +1 -0
  291. package/dist/es/utils/purry-on.js +6 -0
  292. package/dist/es/utils/purry-order-rules.js +61 -0
  293. package/dist/es/utils/quick-select.js +27 -0
  294. package/dist/es/utils/reduce-lazy.js +14 -0
  295. package/dist/es/utils/swap-in-place.js +3 -0
  296. package/dist/es/utils/to-lazy-indexed.js +3 -0
  297. package/dist/es/utils/to-single.js +4 -0
  298. package/dist/es/utils/types.js +1 -0
  299. package/dist/es/utils/with-precision.js +19 -0
  300. package/dist/metadata.json +48311 -0
  301. package/dist/types/aria/index.d.ts +2 -0
  302. package/dist/types/aria/index.d.ts.map +1 -0
  303. package/dist/types/aria/key-codes.d.ts +26 -0
  304. package/dist/types/aria/key-codes.d.ts.map +1 -0
  305. package/dist/types/array/all-pass.d.ts +32 -0
  306. package/dist/types/array/all-pass.d.ts.map +1 -0
  307. package/dist/types/array/any-pass.d.ts +32 -0
  308. package/dist/types/array/any-pass.d.ts.map +1 -0
  309. package/dist/types/array/chunk.d.ts +29 -0
  310. package/dist/types/array/chunk.d.ts.map +1 -0
  311. package/dist/types/array/compact.d.ts +12 -0
  312. package/dist/types/array/compact.d.ts.map +1 -0
  313. package/dist/types/array/concat.d.ts +24 -0
  314. package/dist/types/array/concat.d.ts.map +1 -0
  315. package/dist/types/array/count-by.d.ts +20 -0
  316. package/dist/types/array/count-by.d.ts.map +1 -0
  317. package/dist/types/array/difference-with.d.ts +48 -0
  318. package/dist/types/array/difference-with.d.ts.map +1 -0
  319. package/dist/types/array/difference.d.ts +35 -0
  320. package/dist/types/array/difference.d.ts.map +1 -0
  321. package/dist/types/array/drop-first-by.d.ts +39 -0
  322. package/dist/types/array/drop-first-by.d.ts.map +1 -0
  323. package/dist/types/array/drop-last-while.d.ts +30 -0
  324. package/dist/types/array/drop-last-while.d.ts.map +1 -0
  325. package/dist/types/array/drop-last.d.ts +25 -0
  326. package/dist/types/array/drop-last.d.ts.map +1 -0
  327. package/dist/types/array/drop-while.d.ts +33 -0
  328. package/dist/types/array/drop-while.d.ts.map +1 -0
  329. package/dist/types/array/drop.d.ts +31 -0
  330. package/dist/types/array/drop.d.ts.map +1 -0
  331. package/dist/types/array/filter.d.ts +49 -0
  332. package/dist/types/array/filter.d.ts.map +1 -0
  333. package/dist/types/array/find-index.d.ts +67 -0
  334. package/dist/types/array/find-index.d.ts.map +1 -0
  335. package/dist/types/array/find-last-index.d.ts +43 -0
  336. package/dist/types/array/find-last-index.d.ts.map +1 -0
  337. package/dist/types/array/find-last.d.ts +45 -0
  338. package/dist/types/array/find-last.d.ts.map +1 -0
  339. package/dist/types/array/find.d.ts +59 -0
  340. package/dist/types/array/find.d.ts.map +1 -0
  341. package/dist/types/array/first-by.d.ts +57 -0
  342. package/dist/types/array/first-by.d.ts.map +1 -0
  343. package/dist/types/array/first.d.ts +35 -0
  344. package/dist/types/array/first.d.ts.map +1 -0
  345. package/dist/types/array/flat-map-to-obj.d.ts +50 -0
  346. package/dist/types/array/flat-map-to-obj.d.ts.map +1 -0
  347. package/dist/types/array/flat-map.d.ts +39 -0
  348. package/dist/types/array/flat-map.d.ts.map +1 -0
  349. package/dist/types/array/flatten-deep.d.ts +26 -0
  350. package/dist/types/array/flatten-deep.d.ts.map +1 -0
  351. package/dist/types/array/flatten.d.ts +23 -0
  352. package/dist/types/array/flatten.d.ts.map +1 -0
  353. package/dist/types/array/for-each.d.ts +57 -0
  354. package/dist/types/array/for-each.d.ts.map +1 -0
  355. package/dist/types/array/group-by.d.ts +36 -0
  356. package/dist/types/array/group-by.d.ts.map +1 -0
  357. package/dist/types/array/has-at-least.d.ts +47 -0
  358. package/dist/types/array/has-at-least.d.ts.map +1 -0
  359. package/dist/types/array/index-by.d.ts +34 -0
  360. package/dist/types/array/index-by.d.ts.map +1 -0
  361. package/dist/types/array/index.d.ts +66 -0
  362. package/dist/types/array/index.d.ts.map +1 -0
  363. package/dist/types/array/intersection-with.d.ts +54 -0
  364. package/dist/types/array/intersection-with.d.ts.map +1 -0
  365. package/dist/types/array/intersection.d.ts +30 -0
  366. package/dist/types/array/intersection.d.ts.map +1 -0
  367. package/dist/types/array/join.d.ts +45 -0
  368. package/dist/types/array/join.d.ts.map +1 -0
  369. package/dist/types/array/last.d.ts +24 -0
  370. package/dist/types/array/last.d.ts.map +1 -0
  371. package/dist/types/array/length.d.ts +14 -0
  372. package/dist/types/array/length.d.ts.map +1 -0
  373. package/dist/types/array/map-to-obj.d.ts +42 -0
  374. package/dist/types/array/map-to-obj.d.ts.map +1 -0
  375. package/dist/types/array/map.d.ts +62 -0
  376. package/dist/types/array/map.d.ts.map +1 -0
  377. package/dist/types/array/max-by.d.ts +39 -0
  378. package/dist/types/array/max-by.d.ts.map +1 -0
  379. package/dist/types/array/mean-by.d.ts +39 -0
  380. package/dist/types/array/mean-by.d.ts.map +1 -0
  381. package/dist/types/array/merge-all.d.ts +16 -0
  382. package/dist/types/array/merge-all.d.ts.map +1 -0
  383. package/dist/types/array/min-by.d.ts +39 -0
  384. package/dist/types/array/min-by.d.ts.map +1 -0
  385. package/dist/types/array/nth-by.d.ts +45 -0
  386. package/dist/types/array/nth-by.d.ts.map +1 -0
  387. package/dist/types/array/only.d.ts +36 -0
  388. package/dist/types/array/only.d.ts.map +1 -0
  389. package/dist/types/array/partition.d.ts +60 -0
  390. package/dist/types/array/partition.d.ts.map +1 -0
  391. package/dist/types/array/range.d.ts +22 -0
  392. package/dist/types/array/range.d.ts.map +1 -0
  393. package/dist/types/array/rank-by.d.ts +41 -0
  394. package/dist/types/array/rank-by.d.ts.map +1 -0
  395. package/dist/types/array/reduce.d.ts +35 -0
  396. package/dist/types/array/reduce.d.ts.map +1 -0
  397. package/dist/types/array/reject.d.ts +42 -0
  398. package/dist/types/array/reject.d.ts.map +1 -0
  399. package/dist/types/array/reverse.d.ts +25 -0
  400. package/dist/types/array/reverse.d.ts.map +1 -0
  401. package/dist/types/array/sample.d.ts +54 -0
  402. package/dist/types/array/sample.d.ts.map +1 -0
  403. package/dist/types/array/shuffle.d.ts +22 -0
  404. package/dist/types/array/shuffle.d.ts.map +1 -0
  405. package/dist/types/array/sort-by.d.ts +99 -0
  406. package/dist/types/array/sort-by.d.ts.map +1 -0
  407. package/dist/types/array/sort.d.ts +52 -0
  408. package/dist/types/array/sort.d.ts.map +1 -0
  409. package/dist/types/array/splice.d.ts +31 -0
  410. package/dist/types/array/splice.d.ts.map +1 -0
  411. package/dist/types/array/split-at.d.ts +26 -0
  412. package/dist/types/array/split-at.d.ts.map +1 -0
  413. package/dist/types/array/split-when.d.ts +24 -0
  414. package/dist/types/array/split-when.d.ts.map +1 -0
  415. package/dist/types/array/sum-by.d.ts +39 -0
  416. package/dist/types/array/sum-by.d.ts.map +1 -0
  417. package/dist/types/array/swap-indices.d.ts +68 -0
  418. package/dist/types/array/swap-indices.d.ts.map +1 -0
  419. package/dist/types/array/take-first-by.d.ts +43 -0
  420. package/dist/types/array/take-first-by.d.ts.map +1 -0
  421. package/dist/types/array/take-while.d.ts +24 -0
  422. package/dist/types/array/take-while.d.ts.map +1 -0
  423. package/dist/types/array/take.d.ts +30 -0
  424. package/dist/types/array/take.d.ts.map +1 -0
  425. package/dist/types/array/uniq-by.d.ts +22 -0
  426. package/dist/types/array/uniq-by.d.ts.map +1 -0
  427. package/dist/types/array/uniq-with.d.ts +44 -0
  428. package/dist/types/array/uniq-with.d.ts.map +1 -0
  429. package/dist/types/array/uniq.d.ts +24 -0
  430. package/dist/types/array/uniq.d.ts.map +1 -0
  431. package/dist/types/array/zip-obj.d.ts +26 -0
  432. package/dist/types/array/zip-obj.d.ts.map +1 -0
  433. package/dist/types/array/zip-with.d.ts +42 -0
  434. package/dist/types/array/zip-with.d.ts.map +1 -0
  435. package/dist/types/array/zip.d.ts +52 -0
  436. package/dist/types/array/zip.d.ts.map +1 -0
  437. package/dist/types/function/conditional.d.ts +108 -0
  438. package/dist/types/function/conditional.d.ts.map +1 -0
  439. package/dist/types/function/create-pipe.d.ts +19 -0
  440. package/dist/types/function/create-pipe.d.ts.map +1 -0
  441. package/dist/types/function/debounce.d.ts +92 -0
  442. package/dist/types/function/debounce.d.ts.map +1 -0
  443. package/dist/types/function/identity.d.ts +10 -0
  444. package/dist/types/function/identity.d.ts.map +1 -0
  445. package/dist/types/function/index.d.ts +10 -0
  446. package/dist/types/function/index.d.ts.map +1 -0
  447. package/dist/types/function/noop.d.ts +10 -0
  448. package/dist/types/function/noop.d.ts.map +1 -0
  449. package/dist/types/function/once.d.ts +13 -0
  450. package/dist/types/function/once.d.ts.map +1 -0
  451. package/dist/types/function/pipe.d.ts +32 -0
  452. package/dist/types/function/pipe.d.ts.map +1 -0
  453. package/dist/types/function/purry.d.ts +32 -0
  454. package/dist/types/function/purry.d.ts.map +1 -0
  455. package/dist/types/function/sleep.d.ts +12 -0
  456. package/dist/types/function/sleep.d.ts.map +1 -0
  457. package/dist/types/guard/index.d.ts +17 -0
  458. package/dist/types/guard/index.d.ts.map +1 -0
  459. package/dist/types/guard/is-array.d.ts +15 -0
  460. package/dist/types/guard/is-array.d.ts.map +1 -0
  461. package/dist/types/guard/is-boolean.d.ts +15 -0
  462. package/dist/types/guard/is-boolean.d.ts.map +1 -0
  463. package/dist/types/guard/is-date.d.ts +13 -0
  464. package/dist/types/guard/is-date.d.ts.map +1 -0
  465. package/dist/types/guard/is-defined.d.ts +22 -0
  466. package/dist/types/guard/is-defined.d.ts.map +1 -0
  467. package/dist/types/guard/is-empty.d.ts +19 -0
  468. package/dist/types/guard/is-empty.d.ts.map +1 -0
  469. package/dist/types/guard/is-error.d.ts +15 -0
  470. package/dist/types/guard/is-error.d.ts.map +1 -0
  471. package/dist/types/guard/is-function.d.ts +15 -0
  472. package/dist/types/guard/is-function.d.ts.map +1 -0
  473. package/dist/types/guard/is-nil.d.ts +14 -0
  474. package/dist/types/guard/is-nil.d.ts.map +1 -0
  475. package/dist/types/guard/is-non-null.d.ts +15 -0
  476. package/dist/types/guard/is-non-null.d.ts.map +1 -0
  477. package/dist/types/guard/is-not.d.ts +15 -0
  478. package/dist/types/guard/is-not.d.ts.map +1 -0
  479. package/dist/types/guard/is-number.d.ts +14 -0
  480. package/dist/types/guard/is-number.d.ts.map +1 -0
  481. package/dist/types/guard/is-object.d.ts +28 -0
  482. package/dist/types/guard/is-object.d.ts.map +1 -0
  483. package/dist/types/guard/is-promise.d.ts +14 -0
  484. package/dist/types/guard/is-promise.d.ts.map +1 -0
  485. package/dist/types/guard/is-string.d.ts +14 -0
  486. package/dist/types/guard/is-string.d.ts.map +1 -0
  487. package/dist/types/guard/is-symbol.d.ts +14 -0
  488. package/dist/types/guard/is-symbol.d.ts.map +1 -0
  489. package/dist/types/guard/is-truthy.d.ts +17 -0
  490. package/dist/types/guard/is-truthy.d.ts.map +1 -0
  491. package/dist/types/index.d.ts +10 -0
  492. package/dist/types/index.d.ts.map +1 -0
  493. package/dist/types/number/add.d.ts +29 -0
  494. package/dist/types/number/add.d.ts.map +1 -0
  495. package/dist/types/number/ceil.d.ts +35 -0
  496. package/dist/types/number/ceil.d.ts.map +1 -0
  497. package/dist/types/number/clamp.d.ts +38 -0
  498. package/dist/types/number/clamp.d.ts.map +1 -0
  499. package/dist/types/number/divide.d.ts +27 -0
  500. package/dist/types/number/divide.d.ts.map +1 -0
  501. package/dist/types/number/floor.d.ts +35 -0
  502. package/dist/types/number/floor.d.ts.map +1 -0
  503. package/dist/types/number/index.d.ts +9 -0
  504. package/dist/types/number/index.d.ts.map +1 -0
  505. package/dist/types/number/multiply.d.ts +27 -0
  506. package/dist/types/number/multiply.d.ts.map +1 -0
  507. package/dist/types/number/round.d.ts +35 -0
  508. package/dist/types/number/round.d.ts.map +1 -0
  509. package/dist/types/number/subtract.d.ts +29 -0
  510. package/dist/types/number/subtract.d.ts.map +1 -0
  511. package/dist/types/object/add-prop.d.ts +30 -0
  512. package/dist/types/object/add-prop.d.ts.map +1 -0
  513. package/dist/types/object/clone.d.ts +10 -0
  514. package/dist/types/object/clone.d.ts.map +1 -0
  515. package/dist/types/object/equals.d.ts +30 -0
  516. package/dist/types/object/equals.d.ts.map +1 -0
  517. package/dist/types/object/for-each-obj.d.ts +44 -0
  518. package/dist/types/object/for-each-obj.d.ts.map +1 -0
  519. package/dist/types/object/from-pairs.d.ts +38 -0
  520. package/dist/types/object/from-pairs.d.ts.map +1 -0
  521. package/dist/types/object/index.d.ts +24 -0
  522. package/dist/types/object/index.d.ts.map +1 -0
  523. package/dist/types/object/invert.d.ts +28 -0
  524. package/dist/types/object/invert.d.ts.map +1 -0
  525. package/dist/types/object/keys.d.ts +34 -0
  526. package/dist/types/object/keys.d.ts.map +1 -0
  527. package/dist/types/object/map-keys.d.ts +24 -0
  528. package/dist/types/object/map-keys.d.ts.map +1 -0
  529. package/dist/types/object/map-values.d.ts +25 -0
  530. package/dist/types/object/map-values.d.ts.map +1 -0
  531. package/dist/types/object/merge-deep.d.ts +32 -0
  532. package/dist/types/object/merge-deep.d.ts.map +1 -0
  533. package/dist/types/object/merge.d.ts +25 -0
  534. package/dist/types/object/merge.d.ts.map +1 -0
  535. package/dist/types/object/omit-by.d.ts +22 -0
  536. package/dist/types/object/omit-by.d.ts.map +1 -0
  537. package/dist/types/object/omit.d.ts +24 -0
  538. package/dist/types/object/omit.d.ts.map +1 -0
  539. package/dist/types/object/path-or.d.ts +76 -0
  540. package/dist/types/object/path-or.d.ts.map +1 -0
  541. package/dist/types/object/pick-by.d.ts +22 -0
  542. package/dist/types/object/pick-by.d.ts.map +1 -0
  543. package/dist/types/object/pick.d.ts +22 -0
  544. package/dist/types/object/pick.d.ts.map +1 -0
  545. package/dist/types/object/prop.d.ts +11 -0
  546. package/dist/types/object/prop.d.ts.map +1 -0
  547. package/dist/types/object/set-path.d.ts +29 -0
  548. package/dist/types/object/set-path.d.ts.map +1 -0
  549. package/dist/types/object/set.d.ts +26 -0
  550. package/dist/types/object/set.d.ts.map +1 -0
  551. package/dist/types/object/swap-props.d.ts +44 -0
  552. package/dist/types/object/swap-props.d.ts.map +1 -0
  553. package/dist/types/object/to-pairs.d.ts +33 -0
  554. package/dist/types/object/to-pairs.d.ts.map +1 -0
  555. package/dist/types/object/values.d.ts +20 -0
  556. package/dist/types/object/values.d.ts.map +1 -0
  557. package/dist/types/string/cases-types.d.ts +36 -0
  558. package/dist/types/string/cases-types.d.ts.map +1 -0
  559. package/dist/types/string/cases.d.ts +22 -0
  560. package/dist/types/string/cases.d.ts.map +1 -0
  561. package/dist/types/string/human-readable-file-size.d.ts +13 -0
  562. package/dist/types/string/human-readable-file-size.d.ts.map +1 -0
  563. package/dist/types/string/index.d.ts +6 -0
  564. package/dist/types/string/index.d.ts.map +1 -0
  565. package/dist/types/string/random-string.d.ts +10 -0
  566. package/dist/types/string/random-string.d.ts.map +1 -0
  567. package/dist/types/string/slugify.d.ts +12 -0
  568. package/dist/types/string/slugify.d.ts.map +1 -0
  569. package/dist/types/string/string-to-path.d.ts +11 -0
  570. package/dist/types/string/string-to-path.d.ts.map +1 -0
  571. package/dist/types/type/index.d.ts +2 -0
  572. package/dist/types/type/index.d.ts.map +1 -0
  573. package/dist/types/type/type.d.ts +19 -0
  574. package/dist/types/type/type.d.ts.map +1 -0
  575. package/dist/types/utils/heap.d.ts +24 -0
  576. package/dist/types/utils/heap.d.ts.map +1 -0
  577. package/dist/types/utils/narrow.d.ts +52 -0
  578. package/dist/types/utils/narrow.d.ts.map +1 -0
  579. package/dist/types/utils/paths.d.ts +9 -0
  580. package/dist/types/utils/paths.d.ts.map +1 -0
  581. package/dist/types/utils/purry-on.d.ts +7 -0
  582. package/dist/types/utils/purry-on.d.ts.map +1 -0
  583. package/dist/types/utils/purry-order-rules.d.ts +52 -0
  584. package/dist/types/utils/purry-order-rules.d.ts.map +1 -0
  585. package/dist/types/utils/quick-select.d.ts +18 -0
  586. package/dist/types/utils/quick-select.d.ts.map +1 -0
  587. package/dist/types/utils/reduce-lazy.d.ts +22 -0
  588. package/dist/types/utils/reduce-lazy.d.ts.map +1 -0
  589. package/dist/types/utils/swap-in-place.d.ts +5 -0
  590. package/dist/types/utils/swap-in-place.d.ts.map +1 -0
  591. package/dist/types/utils/to-lazy-indexed.d.ts +4 -0
  592. package/dist/types/utils/to-lazy-indexed.d.ts.map +1 -0
  593. package/dist/types/utils/to-single.d.ts +4 -0
  594. package/dist/types/utils/to-single.d.ts.map +1 -0
  595. package/dist/types/utils/types.d.ts +32 -0
  596. package/dist/types/utils/types.d.ts.map +1 -0
  597. package/dist/types/utils/with-precision.d.ts +2 -0
  598. package/dist/types/utils/with-precision.d.ts.map +1 -0
  599. package/package.json +35 -24
  600. package/dist/index.cjs +0 -2403
  601. package/dist/index.d.cts +0 -3378
  602. package/dist/index.d.ts +0 -3378
  603. package/dist/index.js +0 -2260
  604. package/dist/index.min.js +0 -2
  605. package/dist/index.min.js.map +0 -7
package/dist/index.d.ts DELETED
@@ -1,3378 +0,0 @@
1
- import { MergeDeep } from 'type-fest';
2
-
3
- /**
4
- * Using event.code is not predictable since each machine may have different output
5
- */
6
- declare const KEY_CODES: {
7
- readonly ALT: "Alt";
8
- readonly ARROW_DOWN: "ArrowDown";
9
- readonly ARROW_LEFT: "ArrowLeft";
10
- readonly ARROW_RIGHT: "ArrowRight";
11
- readonly ARROW_UP: "ArrowUp";
12
- readonly AT: "@";
13
- readonly BACKSPACE: "Backspace";
14
- readonly CTRL: "Control";
15
- readonly DELETE: "Delete";
16
- readonly END: "End";
17
- readonly ENTER: "Enter";
18
- readonly ESC: "Escape";
19
- readonly HOME: "Home";
20
- readonly KEY_F: "KEY_F";
21
- readonly META: "Meta";
22
- readonly PAGE_DOWN: "PageDown";
23
- readonly PAGE_UP: "PageUp";
24
- readonly SHIFT: "Shift";
25
- readonly SPACE: "Space";
26
- readonly TAB: "Tab";
27
- };
28
-
29
- /**
30
- * Determines whether all predicates returns true for the input data.
31
- * @param data The input data for predicates.
32
- * @param fns The list of predicates.
33
- * @signature
34
- * P.allPass(data, fns)
35
- * @example
36
- * const isDivisibleBy3 = (x: number) => x % 3 === 0
37
- * const isDivisibleBy4 = (x: number) => x % 4 === 0
38
- * const fns = [isDivisibleBy3, isDivisibleBy4]
39
- * P.allPass(12, fns) // => true
40
- * P.allPass(8, fns) // => false
41
- * @dataFirst
42
- * @category Array
43
- */
44
- declare function allPass<T>(data: T, fns: ReadonlyArray<(data: T) => boolean>): boolean;
45
- /**
46
- * Determines whether all predicates returns true for the input data.
47
- * @param fns The list of predicates.
48
- * @signature
49
- * P.allPass(fns)(data)
50
- * @example
51
- * const isDivisibleBy3 = (x: number) => x % 3 === 0
52
- * const isDivisibleBy4 = (x: number) => x % 4 === 0
53
- * const fns = [isDivisibleBy3, isDivisibleBy4]
54
- * P.allPass(fns)(12) // => true
55
- * P.allPass(fns)(8) // => false
56
- * @dataLast
57
- * @category Array
58
- */
59
- declare function allPass<T>(fns: ReadonlyArray<(data: T) => boolean>): (data: T) => boolean;
60
-
61
- /**
62
- * Determines whether any predicate returns true for the input data.
63
- * @param data The input data for predicates.
64
- * @param fns The list of predicates.
65
- * @signature
66
- * P.anyPass(data, fns)
67
- * @example
68
- * const isDivisibleBy3 = (x: number) => x % 3 === 0
69
- * const isDivisibleBy4 = (x: number) => x % 4 === 0
70
- * const fns = [isDivisibleBy3, isDivisibleBy4]
71
- * P.anyPass(8, fns) // => true
72
- * P.anyPass(11, fns) // => false
73
- * @dataFirst
74
- * @category Array
75
- */
76
- declare function anyPass<T>(data: T, fns: ReadonlyArray<(data: T) => boolean>): boolean;
77
- /**
78
- * Determines whether any predicate returns true for the input data.
79
- * @param fns The list of predicates.
80
- * @signature
81
- * P.anyPass(fns)(data)
82
- * @example
83
- * const isDivisibleBy3 = (x: number) => x % 3 === 0
84
- * const isDivisibleBy4 = (x: number) => x % 4 === 0
85
- * const fns = [isDivisibleBy3, isDivisibleBy4]
86
- * P.anyPass(fns)(8) // => true
87
- * P.anyPass(fns)(11) // => false
88
- * @dataLast
89
- * @category Array
90
- */
91
- declare function anyPass<T>(fns: ReadonlyArray<(data: T) => boolean>): (data: T) => boolean;
92
-
93
- type Pred<T, K> = (input: T) => K;
94
- type PredIndexed<T, K> = (input: T, index: number, array: Array<T>) => K;
95
- type PredIndexedOptional<T, K> = (input: T, index?: number, array?: Array<T>) => K;
96
- type NonEmptyArray<T> = [T, ...Array<T>];
97
- /**
98
- * This should only be used for defining generics which extend any kind of JS
99
- * array under the hood, this includes arrays *AND* tuples (of the form [x, y],
100
- * and of the form [x, ...y[]], etc...), and their readonly equivalent. This
101
- * allows us to be more inclusive to what functions can process.
102
- *
103
- * @example map<T extends ArrayLike>(items: T) { ... }
104
- *
105
- * We would've named this `ArrayLike`, but that's already used by typescript...
106
- *
107
- * @see This was inspired by the type-definition of Promise.all (https://github.com/microsoft/TypeScript/blob/1df5717b120cddd325deab8b0f2b2c3eecaf2b01/src/lib/es2015.promise.d.ts#L21)
108
- */
109
- type IterableContainer<T = unknown> = [] | ReadonlyArray<T>;
110
-
111
- type Chunked<T extends IterableContainer> = T[number] extends never ? [] : T extends readonly [...Array<unknown>, unknown] | readonly [unknown, ...Array<unknown>] ? NonEmptyArray<NonEmptyArray<T[number]>> : Array<NonEmptyArray<T[number]>>;
112
- /**
113
- * Split an array into groups the length of `size`. If `array` can't be split evenly, the final chunk will be the remaining elements.
114
- * @param array the array
115
- * @param size the length of the chunk
116
- * @signature
117
- * P.chunk(array, size)
118
- * @example
119
- * P.chunk(['a', 'b', 'c', 'd'], 2) // => [['a', 'b'], ['c', 'd']]
120
- * P.chunk(['a', 'b', 'c', 'd'], 3) // => [['a', 'b', 'c'], ['d']]
121
- * @dataFirst
122
- * @category Array
123
- */
124
- declare function chunk<T extends IterableContainer>(array: T, size: number): Chunked<T>;
125
- /**
126
- * Split an array into groups the length of `size`. If `array` can't be split evenly, the final chunk will be the remaining elements.
127
- * @param size the length of the chunk
128
- * @signature
129
- * P.chunk(size)(array)
130
- * @example
131
- * P.chunk(2)(['a', 'b', 'c', 'd']) // => [['a', 'b'], ['c', 'd']]
132
- * P.chunk(3)(['a', 'b', 'c', 'd']) // => [['a', 'b', 'c'], ['d']]
133
- * @dataLast
134
- * @category Array
135
- */
136
- declare function chunk<T extends IterableContainer>(size: number): (array: T) => Chunked<T>;
137
-
138
- /**
139
- * Filter out all falsey values. The values `false`, `null`, `0`, `""`, `undefined`, and `NaN` are falsey.
140
- * @param items the array to compact
141
- * @signature
142
- * P.compact(array)
143
- * @example
144
- * P.compact([0, 1, false, 2, '', 3]) // => [1, 2, 3]
145
- * @category Array
146
- * @pipeable
147
- */
148
- declare function compact<T>(items: ReadonlyArray<'' | 0 | T | false | null | undefined>): Array<T>;
149
-
150
- /**
151
- * Combines two arrays.
152
- * @param arr1 the first array
153
- * @param arr2 the second array
154
- * @signature
155
- * P.concat(arr1, arr2);
156
- * @example
157
- * P.concat([1, 2, 3], ['a']) // [1, 2, 3, 'a']
158
- * @dataFirst
159
- * @category Array
160
- */
161
- declare function concat<T, K>(arr1: ReadonlyArray<T>, arr2: ReadonlyArray<K>): Array<K | T>;
162
- /**
163
- * Combines two arrays.
164
- * @param arr2 the second array
165
- * @signature
166
- * P.concat(arr2)(arr1);
167
- * @example
168
- * P.concat(['a'])([1, 2, 3]) // [1, 2, 3, 'a']
169
- * @dataLast
170
- * @category Array
171
- */
172
- declare function concat<T, K>(arr2: ReadonlyArray<K>): (arr1: ReadonlyArray<T>) => Array<K | T>;
173
-
174
- /**
175
- * Counts how many values of the collection pass the specified predicate.
176
- * @param items The input data.
177
- * @param fn The predicate.
178
- * @signature
179
- * P.countBy(array, fn)
180
- * @example
181
- * P.countBy([1, 2, 3, 4, 5], x => x % 2 === 0) // => 2
182
- * @dataFirst
183
- * @indexed
184
- * @category Array
185
- */
186
- declare function countBy<T>(items: ReadonlyArray<T>, fn: Pred<T, boolean>): number;
187
- declare function countBy<T>(fn: Pred<T, boolean>): (array: ReadonlyArray<T>) => number;
188
- declare namespace countBy {
189
- function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, boolean>): number;
190
- function indexed<T>(fn: PredIndexed<T, boolean>): (array: ReadonlyArray<T>) => number;
191
- }
192
-
193
- type LazyResult<T> = LazyEmpty | LazyMany<T> | LazyNext<T>;
194
- interface LazyEmpty {
195
- done: boolean;
196
- hasMany?: false | undefined;
197
- hasNext: false;
198
- next?: undefined;
199
- }
200
- interface LazyNext<T> {
201
- done: boolean;
202
- hasMany?: false | undefined;
203
- hasNext: true;
204
- next: T;
205
- }
206
- interface LazyMany<T> {
207
- done: boolean;
208
- hasMany: true;
209
- hasNext: true;
210
- next: Array<T>;
211
- }
212
-
213
- type IsEquals$1<TFirst, TSecond> = (a: TFirst, b: TSecond) => boolean;
214
- /**
215
- * Excludes the values from `other` array.
216
- * Elements are compared by custom comparator isEquals.
217
- * @param array the source array
218
- * @param other the values to exclude
219
- * @param isEquals the comparator
220
- * @signature
221
- * P.differenceWith(array, other, isEquals)
222
- * @example
223
- * P.differenceWith(
224
- * [{a: 1}, {a: 2}, {a: 3}, {a: 4}],
225
- * [{a: 2}, {a: 5}, {a: 3}],
226
- * P.equals,
227
- * ) // => [{a: 1}, {a: 4}]
228
- * @dataFirst
229
- * @category Array
230
- * @pipeable
231
- */
232
- declare function differenceWith<TFirst, TSecond>(array: ReadonlyArray<TFirst>, other: ReadonlyArray<TSecond>, isEquals: IsEquals$1<TFirst, TSecond>): Array<TFirst>;
233
- /**
234
- * Excludes the values from `other` array.
235
- * Elements are compared by custom comparator isEquals.
236
- * @param other the values to exclude
237
- * @param isEquals the comparator
238
- * @signature
239
- * P.differenceWith(other, isEquals)(array)
240
- * @example
241
- * P.differenceWith(
242
- * [{a: 2}, {a: 5}, {a: 3}],
243
- * P.equals,
244
- * )([{a: 1}, {a: 2}, {a: 3}, {a: 4}]) // => [{a: 1}, {a: 4}]
245
- * P.pipe(
246
- * [{a: 1}, {a: 2}, {a: 3}, {a: 4}, {a: 5}, {a: 6}], // only 4 iterations
247
- * P.differenceWith([{a: 2}, {a: 3}], P.equals),
248
- * P.take(2),
249
- * ) // => [{a: 1}, {a: 4}]
250
- * @dataLast
251
- * @category Array
252
- * @pipeable
253
- */
254
- declare function differenceWith<TFirst, TSecond>(other: ReadonlyArray<TSecond>, isEquals: IsEquals$1<TFirst, TSecond>): (array: ReadonlyArray<TFirst>) => Array<TFirst>;
255
- declare namespace differenceWith {
256
- function lazy<TFirst, TSecond>(other: Array<TSecond>, isEquals: IsEquals$1<TFirst, TSecond>): (value: TFirst) => LazyResult<TFirst>;
257
- }
258
-
259
- /**
260
- * Excludes the values from `other` array.
261
- * @param array the source array
262
- * @param other the values to exclude
263
- * @signature
264
- * P.difference(array, other)
265
- * @example
266
- * P.difference([1, 2, 3, 4], [2, 5, 3]) // => [1, 4]
267
- * @dataFirst
268
- * @category Array
269
- * @pipeable
270
- */
271
- declare function difference<T>(array: ReadonlyArray<T>, other: ReadonlyArray<T>): Array<T>;
272
- /**
273
- * Excludes the values from `other` array.
274
- * @param other the values to exclude
275
- * @signature
276
- * P.difference(other)(array)
277
- * @example
278
- * P.difference([2, 5, 3])([1, 2, 3, 4]) // => [1, 4]
279
- * P.pipe(
280
- * [1, 2, 3, 4, 5, 6], // only 4 iterations
281
- * P.difference([2, 3]),
282
- * P.take(2)
283
- * ) // => [1, 4]
284
- * @dataLast
285
- * @category Array
286
- * @pipeable
287
- */
288
- declare function difference<T, K>(other: ReadonlyArray<T>): (array: ReadonlyArray<K>) => Array<T>;
289
- declare namespace difference {
290
- function lazy<T>(other: Array<T>): (value: T) => LazyResult<T>;
291
- }
292
-
293
- /**
294
- * Removes last `n` elements from the `array`.
295
- * @param array the target array
296
- * @param n the number of elements to skip
297
- * @signature
298
- * P.dropLast(array, n)
299
- * @example
300
- * P.dropLast([1, 2, 3, 4, 5], 2) // => [1, 2, 3]
301
- * @dataFirst
302
- * @category Array
303
- */
304
- declare function dropLast<T>(array: ReadonlyArray<T>, n: number): Array<T>;
305
- /**
306
- * Removes last `n` elements from the `array`.
307
- * @param n the number of elements to skip
308
- * @signature
309
- * P.dropLast(n)(array)
310
- * @example
311
- * P.dropLast(2)([1, 2, 3, 4, 5]) // => [1, 2, 3]
312
- * @dataLast
313
- * @category Array
314
- */
315
- declare function dropLast<T>(n: number): (array: ReadonlyArray<T>) => Array<T>;
316
-
317
- /**
318
- * Removes first `n` elements from the `array`.
319
- * @param array the target array
320
- * @param n the number of elements to skip
321
- * @signature
322
- * P.drop(array, n)
323
- * @example
324
- * P.drop([1, 2, 3, 4, 5], 2) // => [3, 4, 5]
325
- * @dataFirst
326
- * @pipeable
327
- * @category Array
328
- */
329
- declare function drop<T>(array: ReadonlyArray<T>, n: number): Array<T>;
330
- /**
331
- * Removes first `n` elements from the `array`.
332
- * @param n the number of elements to skip
333
- * @signature
334
- * P.drop(n)(array)
335
- * @example
336
- * P.drop(2)([1, 2, 3, 4, 5]) // => [3, 4, 5]
337
- * @dataLast
338
- * @pipeable
339
- * @category Array
340
- */
341
- declare function drop<T>(n: number): (array: ReadonlyArray<T>) => Array<T>;
342
- declare namespace drop {
343
- function lazy<T>(n: number): (value: T) => LazyResult<T>;
344
- }
345
-
346
- /**
347
- * Filter the elements of an array that meet the condition specified in a callback function.
348
- * @param array The array to filter.
349
- * @param fn the callback function.
350
- * @signature
351
- * P.filter(array, fn)
352
- * P.filter.indexed(array, fn)
353
- * @example
354
- * P.filter([1, 2, 3], x => x % 2 === 1) // => [1, 3]
355
- * P.filter.indexed([1, 2, 3], (x, i, array) => x % 2 === 1) // => [1, 3]
356
- * @dataFirst
357
- * @indexed
358
- * @pipeable
359
- * @category Array
360
- */
361
- declare function filter<T, S extends T>(array: ReadonlyArray<T>, fn: (value: T) => value is S): Array<S>;
362
- declare function filter<T>(array: ReadonlyArray<T>, fn: Pred<T, boolean>): Array<T>;
363
- /**
364
- * Filter the elements of an array that meet the condition specified in a callback function.
365
- * @param fn the callback function.
366
- * @signature
367
- * P.filter(fn)(array)
368
- * P.filter.indexed(fn)(array)
369
- * @example
370
- * P.pipe([1, 2, 3], P.filter(x => x % 2 === 1)) // => [1, 3]
371
- * P.pipe([1, 2, 3], P.filter.indexed((x, i) => x % 2 === 1)) // => [1, 3]
372
- * @dataLast
373
- * @indexed
374
- * @pipeable
375
- * @category Array
376
- */
377
- declare function filter<T, S extends T>(fn: (input: T) => input is S): (array: ReadonlyArray<T>) => Array<S>;
378
- declare function filter<T>(fn: Pred<T, boolean>): (array: ReadonlyArray<T>) => Array<T>;
379
- declare namespace filter {
380
- function indexed<T, S extends T>(array: ReadonlyArray<T>, fn: (input: T, index: number, array: Array<T>) => input is S): Array<S>;
381
- function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, boolean>): Array<T>;
382
- /**
383
- * @dataLast
384
- */
385
- function indexed<T, S extends T>(fn: (input: T, index: number, array: Array<T>) => input is S): (array: ReadonlyArray<T>) => Array<S>;
386
- function indexed<T>(fn: PredIndexed<T, boolean>): (array: ReadonlyArray<T>) => Array<T>;
387
- const lazy: <T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: T[] | undefined) => LazyResult<T>;
388
- const lazyIndexed: (<T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: T[] | undefined) => LazyResult<T>) & {
389
- indexed: true;
390
- };
391
- }
392
-
393
- /**
394
- * Returns the index of the first element in the array where predicate is true, and -1 otherwise.
395
- * @param items the array
396
- * @param fn the predicate
397
- * @signature
398
- * P.findIndex(items, fn)
399
- * P.findIndex.indexed(items, fn)
400
- * @example
401
- * P.findIndex([1, 3, 4, 6], n => n % 2 === 0) // => 2
402
- * P.findIndex.indexed([1, 3, 4, 6], (n, i) => n % 2 === 0) // => 2
403
- * @dataFirst
404
- * @indexed
405
- * @pipeable
406
- * @category Array
407
- */
408
- declare function findIndex<T>(items: ReadonlyArray<T>, fn: Pred<T, boolean>): number;
409
- /**
410
- * Returns the index of the first element in the array where predicate is true, and -1 otherwise.
411
- * @param fn the predicate
412
- * @signature
413
- * P.findIndex(fn)(items)
414
- * P.findIndex.indexed(fn)(items)
415
- * @example
416
- * P.pipe(
417
- * [1, 3, 4, 6],
418
- * P.findIndex(n => n % 2 === 0)
419
- * ) // => 2
420
- * P.pipe(
421
- * [1, 3, 4, 6],
422
- * P.findIndex.indexed((n, i) => n % 2 === 0)
423
- * ) // => 2
424
- * @dataLast
425
- * @indexed
426
- * @pipeable
427
- * @category Array
428
- */
429
- declare function findIndex<T>(fn: Pred<T, boolean>): (items: ReadonlyArray<T>) => number;
430
- declare namespace findIndex {
431
- function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, boolean>): number;
432
- function indexed<T>(fn: PredIndexed<T, boolean>): (array: ReadonlyArray<T>) => number;
433
- const lazy: (<T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: T[] | undefined) => {
434
- done: boolean;
435
- hasNext: boolean;
436
- next: number;
437
- } | {
438
- done: boolean;
439
- hasNext: boolean;
440
- next?: undefined;
441
- }) & {
442
- single: true;
443
- };
444
- const lazyIndexed: (<T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: T[] | undefined) => {
445
- done: boolean;
446
- hasNext: boolean;
447
- next: number;
448
- } | {
449
- done: boolean;
450
- hasNext: boolean;
451
- next?: undefined;
452
- }) & {
453
- indexed: true;
454
- } & {
455
- single: true;
456
- };
457
- }
458
-
459
- /**
460
- * Returns the index of the last element in the array where predicate is true, and -1 otherwise.
461
- * @param array the array
462
- * @param fn the predicate
463
- * @signature
464
- * P.findLastIndex(items, fn)
465
- * P.findLastIndex.indexed(items, fn)
466
- * @example
467
- * P.findLastIndex([1, 3, 4, 6], n => n % 2 === 1) // => 1
468
- * P.findLastIndex.indexed([1, 3, 4, 6], (n, i) => n % 2 === 1) // => 1
469
- * @dataFirst
470
- * @indexed
471
- * @pipeable
472
- * @category Array
473
- */
474
- declare function findLastIndex<T>(array: ReadonlyArray<T>, fn: Pred<T, boolean>): number;
475
- /**
476
- * Returns the index of the last element in the array where predicate is true, and -1 otherwise.
477
- * @param fn the predicate
478
- * @signature
479
- * P.findLastIndex(fn)(items)
480
- * P.findLastIndex.indexed(fn)(items)
481
- * @example
482
- * P.pipe(
483
- * [1, 3, 4, 6],
484
- * P.findLastIndex(n => n % 2 === 1)
485
- * ) // => 1
486
- * P.pipe(
487
- * [1, 3, 4, 6],
488
- * P.findLastIndex.indexed((n, i) => n % 2 === 1)
489
- * ) // => 1
490
- * @dataLast
491
- * @indexed
492
- * @pipeable
493
- * @category Array
494
- */
495
- declare function findLastIndex<T>(fn: Pred<T, boolean>): (array: ReadonlyArray<T>) => number;
496
- declare namespace findLastIndex {
497
- function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, boolean>): number;
498
- function indexed<T>(fn: PredIndexed<T, boolean>): (array: ReadonlyArray<T>) => number;
499
- }
500
-
501
- /**
502
- * Returns the value of the last element in the array where predicate is true, and undefined
503
- * otherwise.
504
- * @param array the array
505
- * @param fn the predicate
506
- * @signature
507
- * P.findLast(items, fn)
508
- * P.findLast.indexed(items, fn)
509
- * @example
510
- * P.findLast([1, 3, 4, 6], n => n % 2 === 1) // => 3
511
- * P.findLast.indexed([1, 3, 4, 6], (n, i) => n % 2 === 1) // => 3
512
- * @dataFirst
513
- * @indexed
514
- * @pipeable
515
- * @category Array
516
- */
517
- declare function findLast<T>(array: ReadonlyArray<T>, fn: Pred<T, boolean>): T | undefined;
518
- /**
519
- * Returns the value of the last element in the array where predicate is true, and undefined
520
- * otherwise.
521
- * @param fn the predicate
522
- * @signature
523
- * P.findLast(fn)(items)
524
- * P.findLast.indexed(fn)(items)
525
- * @example
526
- * P.pipe(
527
- * [1, 3, 4, 6],
528
- * P.findLast(n => n % 2 === 1)
529
- * ) // => 3
530
- * P.pipe(
531
- * [1, 3, 4, 6],
532
- * P.findLast.indexed((n, i) => n % 2 === 1)
533
- * ) // => 3
534
- * @dataLast
535
- * @indexed
536
- * @pipeable
537
- * @category Array
538
- */
539
- declare function findLast<T = never>(fn: Pred<T, boolean>): (array: ReadonlyArray<T>) => T | undefined;
540
- declare namespace findLast {
541
- function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, boolean>): T | undefined;
542
- function indexed<T>(fn: PredIndexed<T, boolean>): (array: ReadonlyArray<T>) => T | undefined;
543
- }
544
-
545
- /**
546
- * Returns the value of the first element in the array where predicate is true, and undefined otherwise.
547
- * @param items the array
548
- * @param fn the predicate
549
- * @signature
550
- * P.find(items, fn)
551
- * P.find.indexed(items, fn)
552
- * @example
553
- * P.find([1, 3, 4, 6], n => n % 2 === 0) // => 4
554
- * P.find.indexed([1, 3, 4, 6], (n, i) => n % 2 === 0) // => 4
555
- * @dataFirst
556
- * @indexed
557
- * @pipeable
558
- * @category Array
559
- */
560
- declare function find<T>(items: ReadonlyArray<T>, fn: Pred<T, boolean>): T | undefined;
561
- /**
562
- * Returns the value of the first element in the array where predicate is true, and undefined otherwise.
563
- * @param fn the predicate
564
- * @signature
565
- * P.find(fn)(items)
566
- * P.find.indexed(fn)(items)
567
- * @example
568
- * P.pipe(
569
- * [1, 3, 4, 6],
570
- * P.find(n => n % 2 === 0)
571
- * ) // => 4
572
- * P.pipe(
573
- * [1, 3, 4, 6],
574
- * P.find.indexed((n, i) => n % 2 === 0)
575
- * ) // => 4
576
- * @dataLast
577
- * @indexed
578
- * @pipeable
579
- * @category Array
580
- */
581
- declare function find<T = never>(fn: Pred<T, boolean>): (array: ReadonlyArray<T>) => T | undefined;
582
- declare namespace find {
583
- function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, boolean>): T | undefined;
584
- function indexed<T>(fn: PredIndexed<T, boolean>): (array: ReadonlyArray<T>) => T | undefined;
585
- const lazy: (<T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: T[] | undefined) => {
586
- done: boolean;
587
- hasNext: boolean;
588
- next: T;
589
- }) & {
590
- single: true;
591
- };
592
- const lazyIndexed: (<T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: T[] | undefined) => {
593
- done: boolean;
594
- hasNext: boolean;
595
- next: T;
596
- }) & {
597
- indexed: true;
598
- } & {
599
- single: true;
600
- };
601
- }
602
-
603
- type FirstOut<T extends IterableContainer> = T extends [] ? undefined : T extends readonly [unknown, ...Array<unknown>] ? T[0] : T extends readonly [...infer Pre, infer Last] ? Last | Pre[0] : T[0] | undefined;
604
- /**
605
- * Gets the first element of `array`.
606
- * Note: In `pipe`, use `first()` form instead of `first`. Otherwise, the inferred type is lost.
607
- * @param array the array
608
- * @signature
609
- * P.first(array)
610
- * @example
611
- * P.first([1, 2, 3]) // => 1
612
- * P.first([]) // => undefined
613
- * P.pipe(
614
- * [1, 2, 4, 8, 16],
615
- * P.filter(x => x > 3),
616
- * P.first(),
617
- * x => x + 1
618
- * ); // => 5
619
- *
620
- * @category Array
621
- * @pipeable
622
- */
623
- declare function first<T extends IterableContainer>(array: Readonly<T>): FirstOut<T>;
624
- declare function first<T extends IterableContainer>(): (array: Readonly<T>) => FirstOut<T>;
625
- declare namespace first {
626
- function lazy<T>(): (value: T) => {
627
- done: boolean;
628
- hasNext: boolean;
629
- next: T;
630
- };
631
- namespace lazy {
632
- const single = true;
633
- }
634
- }
635
-
636
- /**
637
- * Map each element of an array into an object using a defined callback function and flatten the result.
638
- * @param array The array to map.
639
- * @param fn The mapping function, which should return an Array of key-value pairs, similar to Object.fromEntries
640
- * @returns The new mapped object.
641
- * @signature
642
- * P.flatMapToObj(array, fn)
643
- * P.flatMapToObj.indexed(array, fn)
644
- * @example
645
- * P.flatMapToObj([1, 2, 3], (x) =>
646
- * x % 2 === 1 ? [[String(x), x]] : []
647
- * ) // => {1: 1, 3: 3}
648
- * P.flatMapToObj.indexed(['a', 'b'], (x, i) => [
649
- * [x, i],
650
- * [x + x, i + i],
651
- * ]) // => {a: 0, aa: 0, b: 1, bb: 2}
652
- * @dataFirst
653
- * @indexed
654
- * @category Array
655
- */
656
- declare function flatMapToObj<T, K extends keyof any, V>(array: ReadonlyArray<T>, fn: (element: T) => Array<[K, V]>): Record<K, V>;
657
- /**
658
- * Map each element of an array into an object using a defined callback function and flatten the result.
659
- * @param fn The mapping function, which should return an Array of key-value pairs, similar to Object.fromEntries
660
- * @returns The new mapped object.
661
- * @signature
662
- * P.flatMapToObj(fn)(array)
663
- * P.flatMapToObj(fn)(array)
664
- * @example
665
- * P.pipe(
666
- * [1, 2, 3],
667
- * P.flatMapToObj(x => (x % 2 === 1 ? [[String(x), x]] : []))
668
- * ) // => {1: 1, 3: 3}
669
- * P.pipe(
670
- * ['a', 'b'],
671
- * P.flatMapToObj.indexed((x, i) => [
672
- * [x, i],
673
- * [x + x, i + i],
674
- * ])
675
- * ) // => {a: 0, aa: 0, b: 1, bb: 2}
676
- * @dataLast
677
- * @indexed
678
- * @category Array
679
- */
680
- declare function flatMapToObj<T, K extends keyof any, V>(fn: (element: T) => Array<[K, V]>): (array: ReadonlyArray<T>) => Record<K, V>;
681
- declare namespace flatMapToObj {
682
- function indexed<T, K extends keyof any, V>(array: ReadonlyArray<T>, fn: (element: T, index: number, array: ReadonlyArray<T>) => Array<[K, V]>): Record<K, V>;
683
- function indexed<T, K extends keyof any, V>(fn: (element: T, index: number, array: ReadonlyArray<T>) => Array<[K, V]>): (array: ReadonlyArray<T>) => Record<K, V>;
684
- }
685
-
686
- /**
687
- * Map each element of an array using a defined callback function and flatten the mapped result.
688
- * @param array The array to map.
689
- * @param fn The function mapper.
690
- * @signature
691
- * P.flatMap(array, fn)
692
- * @example
693
- * P.flatMap([1, 2, 3], x => [x, x * 10]) // => [1, 10, 2, 20, 3, 30]
694
- * @dataFirst
695
- * @pipeable
696
- * @category Array
697
- */
698
- declare function flatMap<T, K>(array: ReadonlyArray<T>, fn: (input: T) => K | ReadonlyArray<K>): Array<K>;
699
- /**
700
- * Map each element of an array using a defined callback function and flatten the mapped result.
701
- * @param fn The function mapper.
702
- * @signature
703
- * P.flatMap(fn)(array)
704
- * @example
705
- * P.pipe([1, 2, 3], P.flatMap(x => [x, x * 10])) // => [1, 10, 2, 20, 3, 30]
706
- * @dataLast
707
- * @pipeable
708
- * @category Array
709
- */
710
- declare function flatMap<T, K>(fn: (input: T) => K | ReadonlyArray<K>): (array: ReadonlyArray<T>) => Array<K>;
711
- declare namespace flatMap {
712
- function lazy<T, K>(fn: (input: T) => K | ReadonlyArray<K>): (value: T) => {
713
- done: boolean;
714
- hasMany: boolean;
715
- hasNext: boolean;
716
- next: K & any[];
717
- } | {
718
- done: boolean;
719
- hasNext: boolean;
720
- next: K | readonly K[];
721
- hasMany?: undefined;
722
- };
723
- }
724
-
725
- type FlattenDeep<T> = T extends ReadonlyArray<infer K> ? FlattenDeep2<K> : T;
726
- type FlattenDeep2<T> = T extends ReadonlyArray<infer K> ? FlattenDeep3<K> : T;
727
- type FlattenDeep3<T> = T extends ReadonlyArray<infer K> ? FlattenDeep4<K> : T;
728
- type FlattenDeep4<T> = T extends ReadonlyArray<infer K> ? K : T;
729
- /**
730
- * Recursively flattens `array`.
731
- * Note: In `pipe`, use `flattenDeep()` form instead of `flattenDeep`. Otherwise, the inferred type is lost.
732
- * @param items the target array
733
- * @signature P.flattenDeep(array)
734
- * @example
735
- * P.flattenDeep([[1, 2], [[3], [4, 5]]]) // => [1, 2, 3, 4, 5]
736
- * P.pipe(
737
- * [[1, 2], [[3], [4, 5]]],
738
- * P.flattenDeep(),
739
- * ); // => [1, 2, 3, 4, 5]
740
- * @category Array
741
- * @pipeable
742
- */
743
- declare function flattenDeep<T>(items: ReadonlyArray<T>): Array<FlattenDeep<T>>;
744
- declare function flattenDeep<T>(): (items: ReadonlyArray<T>) => Array<FlattenDeep<T>>;
745
- declare namespace flattenDeep {
746
- function lazy(): (value: any) => LazyResult<any>;
747
- }
748
-
749
- type Flatten<T> = T extends ReadonlyArray<infer K> ? K : T;
750
- /**
751
- * Flattens `array` a single level deep.
752
- * Note: In `pipe`, use `flatten()` form instead of `flatten`. Otherwise, the inferred type is lost.
753
- * @param items the target array
754
- * @signature P.flatten(array)
755
- * @example
756
- * P.flatten([[1, 2], [3], [4, 5]]) // => [1, 2, 3, 4, 5]
757
- * P.pipe(
758
- * [[1, 2], [3], [4, 5]],
759
- * P.flatten(),
760
- * ); // => [1, 2, 3, 4, 5]
761
- * @category Array
762
- * @pipeable
763
- */
764
- declare function flatten<T>(items: ReadonlyArray<T>): Array<Flatten<T>>;
765
- declare function flatten<T>(): (items: ReadonlyArray<T>) => Array<Flatten<T>>;
766
- declare namespace flatten {
767
- function lazy<T>(): (next: T) => LazyResult<any>;
768
- }
769
-
770
- /**
771
- * Iterate an array using a defined callback function. The original array is returned instead of `void`.
772
- * @param array The array.
773
- * @param fn The callback function.
774
- * @returns The original array
775
- * @signature
776
- * P.forEach(array, fn)
777
- * P.forEach.indexed(array, fn)
778
- * @example
779
- * P.forEach([1, 2, 3], x => {
780
- * console.log(x)
781
- * }) // => [1, 2, 3]
782
- * P.forEach.indexed([1, 2, 3], (x, i) => {
783
- * console.log(x, i)
784
- * }) // => [1, 2, 3]
785
- * @dataFirst
786
- * @indexed
787
- * @pipeable
788
- * @category Array
789
- */
790
- declare function forEach<T>(array: ReadonlyArray<T>, fn: Pred<T, void>): Array<T>;
791
- /**
792
- * Iterate an array using a defined callback function. The original array is returned instead of `void`.
793
- * @param fn the function mapper
794
- * @signature
795
- * P.forEach(fn)(array)
796
- * P.forEach.indexed(fn)(array)
797
- * @example
798
- * P.pipe(
799
- * [1, 2, 3],
800
- * P.forEach(x => {
801
- * console.log(x)
802
- * })
803
- * ) // => [1, 2, 3]
804
- * P.pipe(
805
- * [1, 2, 3],
806
- * P.forEach.indexed((x, i) => {
807
- * console.log(x, i)
808
- * })
809
- * ) // => [1, 2, 3]
810
- * @dataLast
811
- * @indexed
812
- * @pipeable
813
- * @category Array
814
- */
815
- declare function forEach<T>(fn: Pred<T, void>): (array: ReadonlyArray<T>) => Array<T>;
816
- declare namespace forEach {
817
- function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, void>): Array<T>;
818
- function indexed<T>(fn: PredIndexed<T, void>): (array: ReadonlyArray<T>) => Array<T>;
819
- const lazy: <T>(fn: PredIndexedOptional<T, void>) => (value: T, index?: number | undefined, array?: T[] | undefined) => LazyResult<T>;
820
- const lazyIndexed: (<T>(fn: PredIndexedOptional<T, void>) => (value: T, index?: number | undefined, array?: T[] | undefined) => LazyResult<T>) & {
821
- indexed: true;
822
- };
823
- }
824
-
825
- interface Strict$6 {
826
- <Value, Key extends PropertyKey = PropertyKey>(items: ReadonlyArray<Value>, fn: (item: Value) => Key | undefined): StrictOut$2<Value, Key>;
827
- <Value, Key extends PropertyKey = PropertyKey>(fn: (item: Value) => Key | undefined): (items: ReadonlyArray<Value>) => StrictOut$2<Value, Key>;
828
- readonly indexed: {
829
- <Value, Key extends PropertyKey = PropertyKey>(fn: PredIndexed<Value, Key | undefined>): (items: ReadonlyArray<Value>) => StrictOut$2<Value, Key>;
830
- <Value, Key extends PropertyKey = PropertyKey>(items: ReadonlyArray<Value>, fn: PredIndexed<Value, Key | undefined>): StrictOut$2<Value, Key>;
831
- };
832
- }
833
- type StrictOut$2<Value, Key extends PropertyKey = PropertyKey> = string extends Key ? Record<Key, NonEmptyArray<Value>> : number extends Key ? Record<Key, NonEmptyArray<Value>> : symbol extends Key ? Record<Key, NonEmptyArray<Value>> : Partial<Record<Key, NonEmptyArray<Value>>>;
834
- /**
835
- * Splits a collection into sets, grouped by the result of running each value through `fn`.
836
- * @param items the items to group
837
- * @param fn the grouping function. When `undefined` is returned the item would
838
- * be skipped and not grouped under any key.
839
- * @signature
840
- * P.groupBy(array, fn)
841
- * P.groupBy.strict(array, fn)
842
- * @example
843
- * P.groupBy(['one', 'two', 'three'], x => x.length) // => {3: ['one', 'two'], 5: ['three']}
844
- * P.groupBy.strict([{a: 'cat'}, {a: 'dog'}] as const, prop('a')) // => {cat: [{a: 'cat'}], dog: [{a: 'dog'}]} typed Partial<Record<'cat' | 'dog', NonEmptyArray<{a: 'cat' | 'dog'}>>>
845
- * P.groupBy([0, 1], x => x % 2 === 0 ? 'even' : undefined) // => {even: [0]}
846
- * @dataFirst
847
- * @indexed
848
- * @strict
849
- * @category Array
850
- */
851
- declare function groupBy<T>(items: ReadonlyArray<T>, fn: (item: T) => PropertyKey | undefined): Record<PropertyKey, NonEmptyArray<T>>;
852
- declare function groupBy<T>(fn: (item: T) => PropertyKey | undefined): (array: ReadonlyArray<T>) => Record<PropertyKey, NonEmptyArray<T>>;
853
- declare namespace groupBy {
854
- function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, PropertyKey | undefined>): Record<string, NonEmptyArray<T>>;
855
- function indexed<T>(fn: PredIndexed<T, PropertyKey | undefined>): (array: ReadonlyArray<T>) => Record<string, NonEmptyArray<T>>;
856
- const strict: Strict$6;
857
- }
858
-
859
- /**
860
- * Converts a list of objects into an object indexing the objects by the given key.
861
- * @param array the array
862
- * @param fn the indexing function
863
- * @signature
864
- * P.indexBy(array, fn)
865
- * @example
866
- * P.indexBy(['one', 'two', 'three'], x => x.length) // => {3: 'two', 5: 'three'}
867
- * @dataFirst
868
- * @indexed
869
- * @category Array
870
- */
871
- declare function indexBy<T>(array: ReadonlyArray<T>, fn: (item: T) => any): Record<string, T>;
872
- /**
873
- * Converts a list of objects into an object indexing the objects by the given key.
874
- * @param fn the indexing function
875
- * @signature
876
- * P.indexBy(fn)(array)
877
- * @example
878
- * P.pipe(
879
- * ['one', 'two', 'three'],
880
- * P.indexBy(x => x.length)
881
- * ) // => {3: 'two', 5: 'three'}
882
- * @dataLast
883
- * @indexed
884
- * @category Array
885
- */
886
- declare function indexBy<T>(fn: (item: T) => any): (array: ReadonlyArray<T>) => Record<string, T>;
887
- declare namespace indexBy {
888
- function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, any>): Record<string, T>;
889
- function indexed<T>(fn: PredIndexed<T, any>): (array: ReadonlyArray<T>) => Record<string, T>;
890
- }
891
-
892
- /**
893
- * Returns a list of elements that exist in both array.
894
- * @param array the source array
895
- * @param other the second array
896
- * @signature
897
- * P.intersection(array, other)
898
- * @example
899
- * P.intersection([1, 2, 3], [2, 3, 5]) // => [2, 3]
900
- * @dataFirst
901
- * @category Array
902
- * @pipeable
903
- */
904
- declare function intersection<T>(array: ReadonlyArray<T>, other: ReadonlyArray<T>): Array<T>;
905
- /**
906
- * Returns a list of elements that exist in both array.
907
- * @param other the second array
908
- * @signature
909
- * P.intersection(other)(array)
910
- * @example
911
- * P.intersection([2, 3, 5])([1, 2, 3]) // => [2, 3]
912
- * @dataLast
913
- * @category Array
914
- * @pipeable
915
- */
916
- declare function intersection<T, K>(other: ReadonlyArray<T>): (source: ReadonlyArray<K>) => Array<T>;
917
- declare namespace intersection {
918
- function lazy<T>(other: Array<T>): (value: T) => LazyResult<T>;
919
- }
920
-
921
- type Comparator<TFirst, TSecond> = (a: TFirst, b: TSecond) => boolean;
922
- /**
923
- * Returns a list of intersecting values based on a custom
924
- * comparator function that compares elements of both arrays.
925
- * @param array the source array
926
- * @param other the second array
927
- * @param comparator the custom comparator
928
- * @signature
929
- * P.intersectionWith(array, other, comparator)
930
- * @example
931
- * P.intersectionWith(
932
- * [
933
- * { id: 1, name: 'Ryan' },
934
- * { id: 3, name: 'Emma' },
935
- * ],
936
- * [3, 5],
937
- * (a, b) => a.id === b,
938
- * ) // => [{ id: 3, name: 'Emma' }]
939
- * @dataFirst
940
- * @category Array
941
- * @pipeable
942
- */
943
- declare function intersectionWith<TFirst, TSecond>(array: ReadonlyArray<TFirst>, other: ReadonlyArray<TSecond>, comparator: Comparator<TFirst, TSecond>): Array<TFirst>;
944
- /**
945
- * Returns a list of intersecting values based on a custom
946
- * comparator function that compares elements of both arrays.
947
- * @param other the second array
948
- * @param comparator the custom comparator
949
- * @signature
950
- * P.intersectionWith(other, comparator)(array)
951
- * @example
952
- * P.intersectionWith(
953
- * [3, 5],
954
- * (a, b) => a.id === b
955
- * )([
956
- * { id: 1, name: 'Ryan' },
957
- * { id: 3, name: 'Emma' },
958
- * ]); // => [{ id: 3, name: 'Emma' }]
959
- * @dataLast
960
- * @category Array
961
- * @pipeable
962
- */
963
- declare function intersectionWith<TFirst, TSecond>(other: ReadonlyArray<TSecond>,
964
- /**
965
- * type inference doesn't work properly for the comparator's first parameter
966
- * in data last variant
967
- */
968
- comparator: Comparator<TFirst, TSecond>): (array: ReadonlyArray<TFirst>) => Array<TFirst>;
969
- declare namespace intersectionWith {
970
- function lazy<TFirst, TSecond>(other: Array<TSecond>, comparator: Comparator<TFirst, TSecond>): (value: TFirst) => LazyResult<TFirst>;
971
- }
972
-
973
- type Joinable = bigint | boolean | null | number | string | undefined;
974
- type Joined<T extends IterableContainer, Glue extends string> = T[number] extends never ? '' : T extends readonly [Joinable?] ? `${NullishCoalesce<T[0], ''>}` : T extends readonly [infer First, ...infer Tail] ? `${NullishCoalesce<First, ''>}${Glue}${Joined<Tail, Glue>}` : T extends readonly [...infer Head, infer Last] ? `${Joined<Head, Glue>}${Glue}${NullishCoalesce<Last, ''>}` : string;
975
- type NullishCoalesce<T, Fallback> = T extends Joinable ? T extends null | undefined ? Fallback | NonNullable<T> : T : never;
976
- /**
977
- * Joins the elements of the array by: casting them to a string and
978
- * concatenating them one to the other, with the provided glue string in between
979
- * every two elements.
980
- *
981
- * When called on a tuple and with stricter item types (union of literal values,
982
- * the result is strictly typed to the tuples shape and it's item types).
983
- *
984
- * @param data The array to join
985
- * @param glue The string to put in between every two elements
986
- * @signature
987
- * P.join(data, glue)
988
- * @example
989
- * P.join([1,2,3], ",") // => "1,2,3" (typed `string`)
990
- * P.join(['a','b','c'], "") // => "abc" (typed `string`)
991
- * P.join(['hello', 'world'] as const, " ") // => "hello world" (typed `hello world`)
992
- * @dataFirst
993
- * @category Array
994
- */
995
- declare function join<T extends [] | ReadonlyArray<Joinable>, Glue extends string>(data: T, glue: Glue): Joined<T, Glue>;
996
- /**
997
- * Joins the elements of the array by: casting them to a string and
998
- * concatenating them one to the other, with the provided glue string in between
999
- * every two elements.
1000
- *
1001
- * When called on a tuple and with stricter item types (union of literal values,
1002
- * the result is strictly typed to the tuples shape and it's item types).
1003
- *
1004
- * @param glue The string to put in between every two elements
1005
- * @signature
1006
- * P.join(glue)(data)
1007
- * @example
1008
- * P.pipe([1,2,3], P.join(",")) // => "1,2,3" (typed `string`)
1009
- * P.pipe(['a','b','c'], P.join("")) // => "abc" (typed `string`)
1010
- * P.pipe(['hello', 'world'] as const, P.join(" ")) // => "hello world" (typed `hello world`)
1011
- * @dataLast
1012
- * @category Array
1013
- */
1014
- declare function join<T extends [] | ReadonlyArray<Joinable>, Glue extends string>(glue: Glue): (data: T) => Joined<T, Glue>;
1015
-
1016
- /**
1017
- * Gets the last element of `array`.
1018
- * Note: In `pipe`, use `last()` form instead of `last`. Otherwise, the inferred type is lost.
1019
- * @param array the array
1020
- * @signature
1021
- * P.last(array)
1022
- * @example
1023
- * P.last([1, 2, 3]) // => 3
1024
- * P.last([]) // => undefined
1025
- * P.pipe(
1026
- * [1, 2, 4, 8, 16],
1027
- * P.filter(x => x > 3),
1028
- * P.last(),
1029
- * x => x + 1
1030
- * ); // => 17
1031
- *
1032
- * @category Array
1033
- * @pipeable
1034
- */
1035
- declare function last<T>(array: NonEmptyArray<T>): T;
1036
- declare function last<T>(array: ReadonlyArray<T>): T | undefined;
1037
- declare function last<T>(): (array: ReadonlyArray<T>) => T | undefined;
1038
-
1039
- type Enumerable<T> = ArrayLike<T> | Iterable<T>;
1040
- /**
1041
- * Counts values of the collection or iterable.
1042
- * @param items The input data.
1043
- * @signature
1044
- * P.length(array)
1045
- * @example
1046
- * P.length([1, 2, 3]) // => 3
1047
- * @category Array
1048
- */
1049
- declare function length<T>(items: Enumerable<T>): number;
1050
- declare function length<T>(): (items: Enumerable<T>) => number;
1051
-
1052
- interface Strict$5 {
1053
- <T extends IterableContainer, K>(items: T, mapper: Pred<T[number], K>): StrictOut$1<T, K>;
1054
- <T extends IterableContainer, K>(mapper: Pred<T[number], K>): (items: T) => StrictOut$1<T, K>;
1055
- readonly indexed: {
1056
- <T extends IterableContainer, K>(items: T, mapper: PredIndexed<T[number], K>): StrictOut$1<T, K>;
1057
- <T extends IterableContainer, K>(mapper: PredIndexed<T[number], K>): (items: T) => StrictOut$1<T, K>;
1058
- };
1059
- }
1060
- type StrictOut$1<T extends IterableContainer, K> = {
1061
- -readonly [P in keyof T]: K;
1062
- };
1063
- /**
1064
- * Map each element of an array using a defined callback function. If the input
1065
- * array is a tuple use the `strict` variant to maintain it's shape.
1066
- * @param array The array to map.
1067
- * @param fn The function mapper.
1068
- * @returns The new mapped array.
1069
- * @signature
1070
- * P.map(array, fn)
1071
- * P.map.indexed(array, fn)
1072
- * P.map.strict(array, fn)
1073
- * P.map.strict.indexed(array, fn)
1074
- * @example
1075
- * P.map([1, 2, 3], x => x * 2) // => [2, 4, 6], typed number[]
1076
- * P.map.indexed([0, 0, 0], (x, i) => i) // => [0, 1, 2], typed number[]
1077
- * P.map.strict([0, 0] as const, x => x + 1) // => [1, 1], typed [number, number]
1078
- * P.map.strict.indexed([0, 0] as const, (x, i) => x + i) // => [0, 1], typed [number, number]
1079
- * @dataFirst
1080
- * @indexed
1081
- * @pipeable
1082
- * @strict
1083
- * @category Array
1084
- */
1085
- declare function map<T, K>(array: ReadonlyArray<T>, fn: Pred<T, K>): Array<K>;
1086
- /**
1087
- * Map each value of an object using a defined callback function.
1088
- * @param fn the function mapper
1089
- * @signature
1090
- * P.map(fn)(array)
1091
- * P.map.indexed(fn)(array)
1092
- * @example
1093
- * P.pipe([0, 1, 2], P.map(x => x * 2)) // => [0, 2, 4]
1094
- * P.pipe([0, 0, 0], P.map.indexed((x, i) => i)) // => [0, 1, 2]
1095
- * @dataLast
1096
- * @indexed
1097
- * @pipeable
1098
- * @category Array
1099
- */
1100
- declare function map<T, K>(fn: Pred<T, K>): (array: ReadonlyArray<T>) => Array<K>;
1101
- declare namespace map {
1102
- function indexed<T, K>(array: ReadonlyArray<T>, fn: PredIndexed<T, K>): Array<K>;
1103
- function indexed<T, K>(fn: PredIndexed<T, K>): (array: ReadonlyArray<T>) => Array<K>;
1104
- const lazy: <T, K>(fn: PredIndexedOptional<T, K>) => (value: T, index?: number | undefined, array?: T[] | undefined) => LazyResult<K>;
1105
- const lazyIndexed: (<T, K>(fn: PredIndexedOptional<T, K>) => (value: T, index?: number | undefined, array?: T[] | undefined) => LazyResult<K>) & {
1106
- indexed: true;
1107
- };
1108
- const strict: Strict$5;
1109
- }
1110
-
1111
- /**
1112
- * Map each element of an array into an object using a defined callback function.
1113
- * @param array The array to map.
1114
- * @param fn The mapping function, which should return a tuple of [key, value], similar to Object.fromEntries
1115
- * @returns The new mapped object.
1116
- * @signature
1117
- * P.mapToObj(array, fn)
1118
- * P.mapToObj.indexed(array, fn)
1119
- * @example
1120
- * P.mapToObj([1, 2, 3], x => [String(x), x * 2]) // => {1: 2, 2: 4, 3: 6}
1121
- * P.mapToObj.indexed([0, 0, 0], (x, i) => [i, i]) // => {0: 0, 1: 1, 2: 2}
1122
- * @dataFirst
1123
- * @indexed
1124
- * @category Array
1125
- */
1126
- declare function mapToObj<T, K extends keyof any, V>(array: ReadonlyArray<T>, fn: (element: T) => [K, V]): Record<K, V>;
1127
- /**
1128
- * Map each element of an array into an object using a defined callback function.
1129
- * @param fn The mapping function, which should return a tuple of [key, value], similar to Object.fromEntries
1130
- * @returns The new mapped object.
1131
- * @signature
1132
- * P.mapToObj(fn)(array)
1133
- * P.mapToObj.indexed(fn)(array)
1134
- * @example
1135
- * P.pipe(
1136
- * [1, 2, 3],
1137
- * P.mapToObj(x => [String(x), x * 2])
1138
- * ) // => {1: 2, 2: 4, 3: 6}
1139
- * P.pipe(
1140
- * [0, 0, 0],
1141
- * P.mapToObj.indexed((x, i) => [i, i])
1142
- * ) // => {0: 0, 1: 1, 2: 2}
1143
- * @dataLast
1144
- * @indexed
1145
- * @category Array
1146
- */
1147
- declare function mapToObj<T, K extends keyof any, V>(fn: (element: T) => [K, V]): (array: ReadonlyArray<T>) => Record<K, V>;
1148
- declare namespace mapToObj {
1149
- function indexed<T, K extends keyof any, V>(array: ReadonlyArray<T>, fn: (element: T, index: number, array: ReadonlyArray<T>) => [K, V]): Record<K, V>;
1150
- function indexed<T, K extends keyof any, V>(fn: (element: T, index: number, array: ReadonlyArray<T>) => [K, V]): (array: ReadonlyArray<T>) => Record<K, V>;
1151
- }
1152
-
1153
- /**
1154
- * Returns the max element using the provided predicate.
1155
- * @param fn the predicate
1156
- * @signature
1157
- * P.maxBy(fn)(array)
1158
- * P.maxBy.indexed(fn)(array)
1159
- * @example
1160
- * P.pipe(
1161
- * [{a: 5}, {a: 1}, {a: 3}],
1162
- * P.maxBy(x => x.a)
1163
- * ) // { a: 5 }
1164
- * @dataLast
1165
- * @indexed
1166
- * @category Array
1167
- */
1168
- declare function maxBy<T>(fn: (item: T) => number): (items: ReadonlyArray<T>) => T | undefined;
1169
- /**
1170
- * Returns the max element using the provided predicate.
1171
- * @param items the array
1172
- * @param fn the predicate
1173
- * @signature
1174
- * P.maxBy(array, fn)
1175
- * P.maxBy.indexed(array, fn)
1176
- * @example
1177
- * P.maxBy(
1178
- * [{a: 5}, {a: 1}, {a: 3}],
1179
- * x => x.a
1180
- * ) // { a: 5 }
1181
- * @dataFirst
1182
- * @indexed
1183
- * @category Array
1184
- */
1185
- declare function maxBy<T>(items: ReadonlyArray<T>, fn: (item: T) => number): T | undefined;
1186
- declare namespace maxBy {
1187
- function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, number>): T | undefined;
1188
- function indexed<T>(fn: PredIndexed<T, number>): (array: ReadonlyArray<T>) => T | undefined;
1189
- }
1190
-
1191
- /**
1192
- * Returns the mean of the elements of an array using the provided predicate.
1193
- * @param fn predicate function
1194
- * @signature
1195
- * P.meanBy(fn)(array)
1196
- * P.meanBy.indexed(fn)(array)
1197
- * @example
1198
- * P.pipe(
1199
- * [{a: 5}, {a: 1}, {a: 3}],
1200
- * P.meanBy(x => x.a)
1201
- * ) // 3
1202
- * @dataLast
1203
- * @indexed
1204
- * @category Array
1205
- */
1206
- declare function meanBy<T>(fn: (item: T) => number): (items: ReadonlyArray<T>) => number;
1207
- /**
1208
- * Returns the mean of the elements of an array using the provided predicate.
1209
- * @param items the array
1210
- * @param fn predicate function
1211
- * @signature
1212
- * P.meanBy(array, fn)
1213
- * P.meanBy.indexed(array, fn)
1214
- * @example
1215
- * P.meanBy(
1216
- * [{a: 5}, {a: 1}, {a: 3}],
1217
- * x => x.a
1218
- * ) // 3
1219
- * @dataFirst
1220
- * @indexed
1221
- * @category Array
1222
- */
1223
- declare function meanBy<T>(items: ReadonlyArray<T>, fn: (item: T) => number): number;
1224
- declare namespace meanBy {
1225
- function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, number>): number;
1226
- function indexed<T>(fn: PredIndexed<T, number>): (array: ReadonlyArray<T>) => number;
1227
- }
1228
-
1229
- /**
1230
- * Merges a list of objects into a single object.
1231
- * @param array the array of objects
1232
- * @signature
1233
- * P.mergeAll(objects)
1234
- * @example
1235
- * P.mergeAll([{ a: 1, b: 1 }, { b: 2, c: 3 }, { d: 10 }]) // => { a: 1, b: 2, c: 3, d: 10 }
1236
- * @category Array
1237
- */
1238
- declare function mergeAll<A>(array: readonly [A]): A;
1239
- declare function mergeAll<A, B>(array: readonly [A, B]): A & B;
1240
- declare function mergeAll<A, B, C>(array: readonly [A, B, C]): A & B & C;
1241
- declare function mergeAll<A, B, C, D>(array: readonly [A, B, C, D]): A & B & C & D;
1242
- declare function mergeAll<A, B, C, D, E>(array: [A, B, C, D, E]): A & B & C & D & E;
1243
- declare function mergeAll(array: ReadonlyArray<object>): object;
1244
-
1245
- /**
1246
- * Returns the min element using the provided predicate.
1247
- * @param fn the predicate
1248
- * @signature
1249
- * P.minBy(fn)(array)
1250
- * P.minBy.indexed(fn)(array)
1251
- * @example
1252
- * P.pipe(
1253
- * [{a: 5}, {a: 1}, {a: 3}],
1254
- * P.minBy(x => x.a)
1255
- * ) // { a: 1 }
1256
- * @dataLast
1257
- * @indexed
1258
- * @category Array
1259
- */
1260
- declare function minBy<T>(fn: (item: T) => number): (items: ReadonlyArray<T>) => T | undefined;
1261
- /**
1262
- * Returns the min element using the provided predicate.
1263
- * @param items the array
1264
- * @param fn the predicate
1265
- * @signature
1266
- * P.minBy(array, fn)
1267
- * P.minBy.indexed(array, fn)
1268
- * @example
1269
- * P.minBy(
1270
- * [{a: 5}, {a: 1}, {a: 3}],
1271
- * x => x.a
1272
- * ) // { a: 1 }
1273
- * @dataFirst
1274
- * @indexed
1275
- * @category Array
1276
- */
1277
- declare function minBy<T>(items: ReadonlyArray<T>, fn: (item: T) => number): T | undefined;
1278
- declare namespace minBy {
1279
- function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, number>): T | undefined;
1280
- function indexed<T>(fn: PredIndexed<T, number>): (array: ReadonlyArray<T>) => T | undefined;
1281
- }
1282
-
1283
- /**
1284
- * Splits a collection into two groups, the first of which contains elements the `predicate` type guard passes, and the second one containing the rest.
1285
- * @param items the items to split
1286
- * @param predicate a type guard function to invoke on every item
1287
- * @returns the array of grouped elements.
1288
- * @signature
1289
- * P.partition(array, fn)
1290
- * @example
1291
- * P.partition(['one', 'two', 'forty two'], x => x.length === 3) // => [['one', 'two'], ['forty two']]
1292
- * @dataFirst
1293
- * @indexed
1294
- * @category Array
1295
- */
1296
- declare function partition<T, S extends T>(items: ReadonlyArray<T>, predicate: (item: T) => item is S): [Array<S>, Array<Exclude<T, S>>];
1297
- /**
1298
- * Splits a collection into two groups, the first of which contains elements the `predicate` function matches, and the second one containing the rest.
1299
- * @param items the items to split
1300
- * @param predicate the function invoked per iteration
1301
- * @returns the array of grouped elements.
1302
- * @signature
1303
- * P.partition(array, fn)
1304
- * @example
1305
- * P.partition(['one', 'two', 'forty two'], x => x.length === 3) // => [['one', 'two'], ['forty two']]
1306
- * @dataFirst
1307
- * @indexed
1308
- * @category Array
1309
- */
1310
- declare function partition<T>(items: ReadonlyArray<T>, predicate: (item: T) => boolean): [Array<T>, Array<T>];
1311
- /**
1312
- * Splits a collection into two groups, the first of which contains elements the `predicate` type guard passes, and the second one containing the rest.
1313
- * @param predicate the grouping function
1314
- * @returns the array of grouped elements.
1315
- * @signature
1316
- * P.partition(fn)(array)
1317
- * @example
1318
- * P.pipe(['one', 'two', 'forty two'], P.partition(x => x.length === 3)) // => [['one', 'two'], ['forty two']]
1319
- * @dataLast
1320
- * @indexed
1321
- * @category Array
1322
- */
1323
- declare function partition<T, S extends T>(predicate: (item: T) => item is S): (array: ReadonlyArray<T>) => [Array<S>, Array<Exclude<T, S>>];
1324
- /**
1325
- * Splits a collection into two groups, the first of which contains elements the `predicate` function matches, and the second one containing the rest.
1326
- * @param predicate the grouping function
1327
- * @returns the array of grouped elements.
1328
- * @signature
1329
- * P.partition(fn)(array)
1330
- * @example
1331
- * P.pipe(['one', 'two', 'forty two'], P.partition(x => x.length === 3)) // => [['one', 'two'], ['forty two']]
1332
- * @dataLast
1333
- * @indexed
1334
- * @category Array
1335
- */
1336
- declare function partition<T>(predicate: (item: T) => boolean): (array: ReadonlyArray<T>) => [Array<T>, Array<T>];
1337
- declare namespace partition {
1338
- function indexed<T>(array: ReadonlyArray<T>, predicate: PredIndexed<T, boolean>): [Array<T>, Array<T>];
1339
- function indexed<T>(predicate: PredIndexed<T, boolean>): (array: ReadonlyArray<T>) => [Array<T>, Array<T>];
1340
- }
1341
-
1342
- /**
1343
- * Returns a list of numbers from `start` (inclusive) to `end` (exclusive).
1344
- * @param start the start number
1345
- * @param end the end number
1346
- * @signature range(start, end)
1347
- * @example
1348
- * P.range(1, 5) // => [1, 2, 3, 4]
1349
- * @dataFirst
1350
- * @category Array
1351
- */
1352
- declare function range(start: number, end: number): Array<number>;
1353
- /**
1354
- * Returns a list of numbers from `start` (inclusive) to `end` (exclusive).
1355
- * @param end the end number
1356
- * @signature range(end)(start)
1357
- * @example
1358
- * P.range(5)(1) // => [1, 2, 3, 4]
1359
- * @dataFirst
1360
- * @category Array
1361
- */
1362
- declare function range(end: number): (start: number) => Array<number>;
1363
-
1364
- /**
1365
- * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
1366
- * @param items the array to reduce
1367
- * @param fn the callback function
1368
- * @param initialValue the initial value to use as an accumulator value in the callback function
1369
- * @signature
1370
- * P.reduce(items, fn, initialValue)
1371
- * P.reduce.indexed(items, fn, initialValue)
1372
- * @example
1373
- * P.reduce([1, 2, 3, 4, 5], (acc, x) => acc + x, 100) // => 115
1374
- * P.reduce.indexed([1, 2, 3, 4, 5], (acc, x, i, array) => acc + x, 100) // => 115
1375
- * @dataFirst
1376
- * @indexed
1377
- * @category Array
1378
- */
1379
- declare function reduce<T, K>(items: ReadonlyArray<T>, fn: (acc: K, item: T) => K, initialValue: K): K;
1380
- /**
1381
- * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
1382
- * @param fn the callback function
1383
- * @param initialValue the initial value to use as an accumulator value in the callback function
1384
- * @signature
1385
- * P.reduce(fn, initialValue)(array)
1386
- * @example
1387
- * P.pipe([1, 2, 3, 4, 5], P.reduce((acc, x) => acc + x, 100)) // => 115
1388
- * P.pipe([1, 2, 3, 4, 5], P.reduce.indexed((acc, x, i, array) => acc + x, 100)) // => 115
1389
- * @dataLast
1390
- * @indexed
1391
- * @category Array
1392
- */
1393
- declare function reduce<T, K>(fn: (acc: K, item: T) => K, initialValue: K): (items: ReadonlyArray<T>) => K;
1394
- declare namespace reduce {
1395
- function indexed<T, K>(array: ReadonlyArray<T>, fn: (acc: K, item: T, index: number, items: Array<T>) => K, initialValue: K): K;
1396
- function indexed<T, K>(fn: (acc: K, item: T, index: number, items: Array<T>) => K, initialValue: K): (array: ReadonlyArray<T>) => K;
1397
- }
1398
-
1399
- /**
1400
- * Reject the elements of an array that meet the condition specified in a callback function.
1401
- * @param items The array to reject.
1402
- * @param fn the callback function.
1403
- * @signature
1404
- * P.reject(array, fn)
1405
- * P.reject.indexed(array, fn)
1406
- * @example
1407
- * P.reject([1, 2, 3], x => x % 2 === 0) // => [1, 3]
1408
- * P.reject.indexed([1, 2, 3], (x, i, array) => x % 2 === 0) // => [1, 3]
1409
- * @dataFirst
1410
- * @indexed
1411
- * @pipeable
1412
- * @category Array
1413
- */
1414
- declare function reject<T>(items: ReadonlyArray<T>, fn: Pred<T, boolean>): Array<T>;
1415
- /**
1416
- * Reject the elements of an array that meet the condition specified in a callback function.
1417
- * @param fn the callback function.
1418
- * @signature
1419
- * P.reject(array, fn)
1420
- * P.reject.indexed(array, fn)
1421
- * @example
1422
- * P.reject([1, 2, 3], x => x % 2 === 0) // => [1, 3]
1423
- * P.reject.indexed([1, 2, 3], (x, i, array) => x % 2 === 0) // => [1, 3]
1424
- * @dataFirst
1425
- * @indexed
1426
- * @pipeable
1427
- * @category Array
1428
- */
1429
- declare function reject<T>(fn: Pred<T, boolean>): (items: ReadonlyArray<T>) => Array<T>;
1430
- declare namespace reject {
1431
- function indexed<T, K>(array: ReadonlyArray<T>, fn: PredIndexed<T, boolean>): Array<K>;
1432
- function indexed<T, K>(fn: PredIndexed<T, boolean>): (array: ReadonlyArray<T>) => Array<K>;
1433
- const lazy: <T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: T[] | undefined) => LazyResult<T>;
1434
- const lazyIndexed: (<T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: T[] | undefined) => LazyResult<T>) & {
1435
- indexed: true;
1436
- };
1437
- }
1438
-
1439
- type Reverse<T extends ReadonlyArray<unknown>, R extends ReadonlyArray<unknown> = []> = ReturnType<T extends IsNoTuple<T> ? () => [...T, ...R] : T extends readonly [infer F, ...infer L] ? () => Reverse<L, [F, ...R]> : () => R>;
1440
- type IsNoTuple<T> = T extends readonly [unknown, ...Array<unknown>] ? never : T;
1441
- /**
1442
- * Reverses array.
1443
- * @param array the array
1444
- * @signature
1445
- * P.reverse(arr);
1446
- * @example
1447
- * P.reverse([1, 2, 3]) // [3, 2, 1]
1448
- * @dataFirst
1449
- * @category Array
1450
- */
1451
- declare function reverse<T extends ReadonlyArray<unknown>>(array: T): Reverse<T>;
1452
- /**
1453
- * Reverses array.
1454
- * @signature
1455
- * P.reverse()(array);
1456
- * @example
1457
- * P.reverse()([1, 2, 3]) // [3, 2, 1]
1458
- * @dataLast
1459
- * @category Array
1460
- */
1461
- declare function reverse<T extends ReadonlyArray<unknown>>(): (array: T) => Reverse<T>;
1462
-
1463
- type Sampled<T extends IterableContainer, N extends number> = number extends N ? SampledGeneric<T> : undefined extends T[N] ? T : SampledLiteral<T, N>;
1464
- type SampledGeneric<T extends IterableContainer> = T[number] extends never ? T : T extends readonly [infer First, ...infer Rest] ? [First, ...SampledGeneric<Rest>] | SampledGeneric<Rest> : Array<T[number]>;
1465
- type SampledLiteral<T extends IterableContainer, N extends number, Iteration extends Array<unknown> = []> = Iteration['length'] extends N ? [] : T extends readonly [infer First, ...infer Tail] ? [
1466
- First | Tail[number],
1467
- ...SampledLiteral<Tail, N, [unknown, ...Iteration]>
1468
- ] : T extends readonly [...infer Head, infer Last] ? [...SampledLiteral<Head, N, [unknown, ...Iteration]>, Last] : [T[number], ...SampledLiteral<T, N, [unknown, ...Iteration]>] | SampledLiteral<T, N, [unknown, ...Iteration]>;
1469
- /**
1470
- * Returns a random subset of size `sampleSize` from `array`.
1471
- *
1472
- * Maintains and infers most of the typing information that could be passed
1473
- * along to the output. This means that when using tuples, the output will be
1474
- * a tuple too, and when using literals, those literals would be preserved.
1475
- *
1476
- * The items in the result are kept in the same order as they are in the input.
1477
- * If you need to get a shuffled response you can pipe the shuffle function
1478
- * after this one.
1479
- *
1480
- * @param data the array
1481
- * @param sampleSize the number of elements to take
1482
- * @signature
1483
- * P.sample(array, sampleSize)
1484
- * @example
1485
- * P.sample(["hello", "world"], 1); // => ["hello"] // typed string[]
1486
- * P.sample(["hello", "world"] as const, 1); // => ["world"] // typed ["hello" | "world"]
1487
- * @dataFirst
1488
- * @pipeable
1489
- * @category Array
1490
- */
1491
- declare function sample<T extends IterableContainer, N extends number = number>(data: T, sampleSize: N): Sampled<T, N>;
1492
- /**
1493
- * Returns a random subset of size `sampleSize` from `array`.
1494
- *
1495
- * Maintains and infers most of the typing information that could be passed
1496
- * along to the output. This means that when using tuples, the output will be
1497
- * a tuple too, and when using literals, those literals would be preserved.
1498
- *
1499
- * The items in the result are kept in the same order as they are in the input.
1500
- * If you need to get a shuffled response you can pipe the shuffle function
1501
- * after this one.
1502
- *
1503
- * @param sampleSize the number of elements to take
1504
- * @signature
1505
- * P.sample(sampleSize)(array)
1506
- * @example
1507
- * P.sample(1)(["hello", "world"]); // => ["hello"] // typed string[]
1508
- * P.sample(1)(["hello", "world"] as const); // => ["world"] // typed ["hello" | "world"]
1509
- * @dataLast
1510
- * @pipeable
1511
- * @category Array
1512
- */
1513
- declare function sample<T extends IterableContainer, N extends number = number>(sampleSize: N): (data: T) => Sampled<T, N>;
1514
-
1515
- /**
1516
- * Shuffles the input array, returning a new array with the same elements in a random order.
1517
- * @param items the array to shuffle
1518
- * @signature
1519
- * P.shuffle(array)
1520
- * @example
1521
- * P.shuffle([4, 2, 7, 5]) // => [7, 5, 4, 2]
1522
- * @category Array
1523
- * @dataFirst
1524
- */
1525
- declare function shuffle<T>(items: ReadonlyArray<T>): Array<T>;
1526
- /**
1527
- * Shuffles the input array, returning a new array with the same elements in a random order.
1528
- * @signature
1529
- * P.shuffle()(array)
1530
- * @example
1531
- * P.pipe([4, 2, 7, 5], P.shuffle()) // => [7, 5, 4, 2]
1532
- * @category Array
1533
- * @dataLast
1534
- */
1535
- declare function shuffle<T>(): (items: ReadonlyArray<T>) => Array<T>;
1536
-
1537
- interface Strict$4 {
1538
- <T extends IterableContainer>(items: T, cmp: (a: T[number], b: T[number]) => number): Sorted<T>;
1539
- <T extends IterableContainer>(cmp: (a: T[number], b: T[number]) => number): (items: T) => Sorted<T>;
1540
- }
1541
- type Sorted<T extends IterableContainer> = {
1542
- -readonly [P in keyof T]: T[number];
1543
- };
1544
- /**
1545
- * Sorts an array. The comparator function should accept two values at a time and return a negative number if the first value is smaller, a positive number if it's larger, and zero if they are equal.
1546
- * Sorting is based on a native `sort` function. It's not guaranteed to be stable.
1547
- *
1548
- * If the input array is more complex (non-empty array, tuple, etc...) use the
1549
- * strict mode to maintain it's shape.
1550
- *
1551
- * @param items the array to sort
1552
- * @param cmp the comparator function
1553
- * @signature
1554
- * P.sort(items, cmp)
1555
- * P.sort.strict(items, cmp)
1556
- * @example
1557
- * P.sort([4, 2, 7, 5], (a, b) => a - b) // => [2, 4, 5, 7] typed Array<number>
1558
- * P.sort.strict([4, 2] as [number, number], (a, b) => a - b) // [2, 4] typed [number, number]
1559
- * @dataFirst
1560
- * @category Array
1561
- * @strict
1562
- */
1563
- declare function sort<T>(items: ReadonlyArray<T>, cmp: (a: T, b: T) => number): Array<T>;
1564
- /**
1565
- * Sorts an array. The comparator function should accept two values at a time and return a negative number if the first value is smaller, a positive number if it's larger, and zero if they are equal.
1566
- * Sorting is based on a native `sort` function. It's not guaranteed to be stable.
1567
- *
1568
- * If the input array is more complex (non-empty array, tuple, etc...) use the
1569
- * strict mode to maintain it's shape.
1570
- *
1571
- * @param cmp the comparator function
1572
- * @signature
1573
- * P.sort(cmp)(items)
1574
- * P.sort.strict(cmp)(items)
1575
- * @example
1576
- * P.pipe([4, 2, 7, 5], P.sort((a, b) => a - b)) // => [2, 4, 5, 7] typed Array<number>
1577
- * P.pipe([4, 2] as [number, number], P.sort.strict((a, b) => a - b)) // => [2, 4] typed [number, number]
1578
- * @dataLast
1579
- * @category Array
1580
- * @strict
1581
- */
1582
- declare function sort<T>(cmp: (a: T, b: T) => number): (items: ReadonlyArray<T>) => Array<T>;
1583
- declare namespace sort {
1584
- const strict: Strict$4;
1585
- }
1586
-
1587
- declare const ALL_DIRECTIONS: readonly ["asc", "desc"];
1588
- type Direction = (typeof ALL_DIRECTIONS)[number];
1589
- type ComparablePrimitive = boolean | number | string;
1590
- type Comparable = {
1591
- valueOf(): ComparablePrimitive;
1592
- } | ComparablePrimitive;
1593
- type SortProjection<T> = (x: T) => Comparable;
1594
- type SortPair<T> = readonly [
1595
- projector: SortProjection<T>,
1596
- direction: Direction
1597
- ];
1598
- type SortRule<T> = SortPair<T> | SortProjection<T>;
1599
- interface Strict$3 {
1600
- <T extends IterableContainer>(...sortRules: Readonly<NonEmptyArray<SortRule<T[number]>>>): (array: T) => SortedBy<T>;
1601
- <T extends IterableContainer>(array: T, ...sortRules: Readonly<NonEmptyArray<SortRule<T[number]>>>): SortedBy<T>;
1602
- }
1603
- type SortedBy<T extends IterableContainer> = {
1604
- -readonly [P in keyof T]: T[number];
1605
- };
1606
- /**
1607
- * Sorts the list according to the supplied functions and directions.
1608
- * Sorting is based on a native `sort` function. It's not guaranteed to be stable.
1609
- *
1610
- * Directions are applied to functions in order and default to ascending if not specified.
1611
- *
1612
- * If the input array is more complex (non-empty array, tuple, etc...) use the
1613
- * strict mode to maintain it's shape.
1614
- *
1615
- * @param sortRules main sort rule
1616
- * @signature
1617
- * P.sortBy(sortRule, ...additionalSortRules)(array)
1618
- * P.sortBy.strict(sortRule, ...additionalSortRules)(array)
1619
- * @example
1620
- * P.pipe(
1621
- * [{ a: 1 }, { a: 3 }, { a: 7 }, { a: 2 }],
1622
- * P.sortBy(x => x.a)
1623
- * ) // => [{ a: 1 }, { a: 2 }, { a: 3 }, { a: 7 }] typed Array<{a:number}>
1624
- * P.pipe(
1625
- * [{ a: 1 }, { a: 3 }] as const,
1626
- * P.sortBy.strict(x => x.a)
1627
- * ) // => [{ a: 1 }, { a: 3 }] typed [{a: 1 | 3}, {a: 1 | 3}]
1628
- * @dataLast
1629
- * @category Array
1630
- * @strict
1631
- */
1632
- declare function sortBy<T>(...sortRules: Readonly<NonEmptyArray<SortRule<T>>>): (array: ReadonlyArray<T>) => Array<T>;
1633
- /**
1634
- * Sorts the list according to the supplied functions and directions.
1635
- * Sorting is based on a native `sort` function. It's not guaranteed to be stable.
1636
- *
1637
- * Directions are applied to functions in order and default to ascending if not specified.
1638
- *
1639
- * If the input array is more complex (non-empty array, tuple, etc...) use the
1640
- * strict mode to maintain it's shape.
1641
- *
1642
- * @param array the array to sort
1643
- * @param sortRules main sort rule
1644
- * @signature
1645
- * P.sortBy(array, sortRule, ...additionalSortRules)
1646
- * P.sortBy.strict(array, sortRule, ...additionalSortRules)
1647
- * @example
1648
- * P.sortBy(
1649
- * [{ a: 1 }, { a: 3 }, { a: 7 }, { a: 2 }],
1650
- * x => x.a
1651
- * )
1652
- * // => [{ a: 1 }, { a: 2 }, { a: 3 }, { a: 7 }] typed Array<{a:number}>
1653
- *
1654
- * P.sortBy(
1655
- * [
1656
- * {color: 'red', weight: 2},
1657
- * {color: 'blue', weight: 3},
1658
- * {color: 'green', weight: 1},
1659
- * {color: 'purple', weight: 1},
1660
- * ],
1661
- * [x => x.weight, 'asc'], x => x.color
1662
- * )
1663
- * // =>
1664
- * // {color: 'green', weight: 1},
1665
- * // {color: 'purple', weight: 1},
1666
- * // {color: 'red', weight: 2},
1667
- * // {color: 'blue', weight: 3},
1668
- * // typed Array<{color: string, weight: number}>
1669
- *
1670
- * P.sortBy.strict(
1671
- * [{ a: 1 }, { a: 3 }] as const,
1672
- * x => x.a
1673
- * )
1674
- * // => [{ a: 1 }, { a: 3 }] typed [{a: 1 | 3}, {a: 1 | 3}]
1675
- * @dataFirst
1676
- * @category Array
1677
- * @strict
1678
- */
1679
- declare function sortBy<T>(array: ReadonlyArray<T>, ...sortRules: Readonly<NonEmptyArray<SortRule<T>>>): Array<T>;
1680
- declare namespace sortBy {
1681
- const strict: Strict$3;
1682
- }
1683
-
1684
- /**
1685
- * Splits a given array at a given index.
1686
- * @param array the array to split
1687
- * @param index the index to split at
1688
- * @signature
1689
- * P.splitAt(array, index)
1690
- * @example
1691
- * P.splitAt([1, 2, 3], 1) // => [[1], [2, 3]]
1692
- * P.splitAt([1, 2, 3, 4, 5], -1) // => [[1, 2, 3, 4], [5]]
1693
- * @dataFirst
1694
- * @category Array
1695
- */
1696
- declare function splitAt<T>(array: ReadonlyArray<T>, index: number): [Array<T>, Array<T>];
1697
- /**
1698
- * Splits a given array at a given index.
1699
- * @param index the index to split at
1700
- * @signature
1701
- * P.splitAt(index)(array)
1702
- * @example
1703
- * P.splitAt(1)([1, 2, 3]) // => [[1], [2, 3]]
1704
- * P.splitAt(-1)([1, 2, 3, 4, 5]) // => [[1, 2, 3, 4], [5]]
1705
- * @dataLast
1706
- * @category Array
1707
- */
1708
- declare function splitAt<T>(index: number): (array: ReadonlyArray<T>) => [Array<T>, Array<T>];
1709
-
1710
- /**
1711
- * Splits a given array at the first index where the given predicate returns true.
1712
- * @param array the array to split
1713
- * @param fn the predicate
1714
- * @signature
1715
- * P.splitWhen(array, fn)
1716
- * @example
1717
- * P.splitWhen([1, 2, 3], x => x === 2) // => [[1], [2, 3]]
1718
- * @dataFirst
1719
- * @category Array
1720
- */
1721
- declare function splitWhen<T>(array: ReadonlyArray<T>, fn: (item: T) => boolean): [Array<T>, Array<T>];
1722
- /**
1723
- * Splits a given array at an index where the given predicate returns true.
1724
- * @param fn the predicate
1725
- * @signature
1726
- * P.splitWhen(fn)(array)
1727
- * @example
1728
- * P.splitWhen(x => x === 2)([1, 2, 3]) // => [[1], [2, 3]]
1729
- * @dataLast
1730
- * @category Array
1731
- */
1732
- declare function splitWhen<T>(fn: (item: T) => boolean): (array: ReadonlyArray<T>) => [Array<T>, Array<T>];
1733
-
1734
- /**
1735
- * Returns the sum of the elements of an array using the provided predicate.
1736
- * @param fn predicate function
1737
- * @signature
1738
- * P.sumBy(fn)(array)
1739
- * P.sumBy.indexed(fn)(array)
1740
- * @example
1741
- * P.pipe(
1742
- * [{a: 5}, {a: 1}, {a: 3}],
1743
- * P.sumBy(x => x.a)
1744
- * ) // 9
1745
- * @dataLast
1746
- * @indexed
1747
- * @category Array
1748
- */
1749
- declare function sumBy<T>(fn: (item: T) => number): (items: ReadonlyArray<T>) => number;
1750
- /**
1751
- * Returns the sum of the elements of an array using the provided predicate.
1752
- * @param items the array
1753
- * @param fn predicate function
1754
- * @signature
1755
- * P.sumBy(array, fn)
1756
- * P.sumBy.indexed(array, fn)
1757
- * @example
1758
- * P.sumBy(
1759
- * [{a: 5}, {a: 1}, {a: 3}],
1760
- * x => x.a
1761
- * ) // 9
1762
- * @dataFirst
1763
- * @indexed
1764
- * @category Array
1765
- */
1766
- declare function sumBy<T>(items: ReadonlyArray<T>, fn: (item: T) => number): number;
1767
- declare namespace sumBy {
1768
- function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, number>): number;
1769
- function indexed<T>(fn: PredIndexed<T, number>): (array: ReadonlyArray<T>) => number;
1770
- }
1771
-
1772
- /**
1773
- * @link https://github.com/sindresorhus/type-fest/blob/main/source/is-equal.d.ts
1774
- */
1775
- type isEqual<A, B> = (<G>() => G extends A ? 1 : 2) extends <G>() => G extends B ? 1 : 2 ? true : false;
1776
- type Difference<A extends number, B extends number> = TupleOfLength<A> extends [
1777
- ...infer U,
1778
- ...TupleOfLength<B>
1779
- ] ? U['length'] : never;
1780
- type isLessThan<A extends number, B extends number> = isEqual<A, B> extends true ? false : 0 extends A ? true : 0 extends B ? false : isLessThan<Difference<A, 1>, Difference<B, 1>>;
1781
- type TupleOfLength<L extends number, T extends IterableContainer = []> = T['length'] extends L ? T : TupleOfLength<L, [...T, unknown]>;
1782
- type IsNonNegative<T extends number> = number extends T ? false : `${T}` extends `-${string}` ? false : true;
1783
- type CharactersTuple<T extends string> = string extends T ? Array<string> : T extends `${infer C}${infer R}` ? [C, ...CharactersTuple<R>] : [];
1784
- type SwapArrayInternal<T extends IterableContainer, Index1 extends number, Index2 extends number, Position extends ReadonlyArray<unknown> = [], Original extends IterableContainer = T> = T extends readonly [infer AtPosition, ...infer Rest] ? [
1785
- Position['length'] extends Index1 ? Original[Index2] : Position['length'] extends Index2 ? Original[Index1] : AtPosition,
1786
- ...SwapArrayInternal<Rest, Index1, Index2, [
1787
- unknown,
1788
- ...Position
1789
- ], Original>
1790
- ] : T;
1791
- type SwapString<T extends string, K1 extends number, K2 extends number> = Joined<SwapArray<CharactersTuple<T>, K1, K2>, ''>;
1792
- type SwapArray<T extends IterableContainer, K1 extends number, K2 extends number> = IsNonNegative<K1> extends false ? Array<T[number]> : IsNonNegative<K2> extends false ? Array<T[number]> : isLessThan<K1, T['length']> extends false ? T : isLessThan<K2, T['length']> extends false ? T : SwapArrayInternal<T, K1, K2>;
1793
- type SwappedIndices<T extends IterableContainer | string, K1 extends number, K2 extends number> = T extends string ? SwapString<T, K1, K2> : T extends IterableContainer ? SwapArray<T, K1, K2> : never;
1794
- /**
1795
- * Swaps the positions of two elements in an array or string at the provided indices.
1796
- *
1797
- * Negative indices are supported and would be treated as an offset from the end of the array. The resulting type thought would be less strict than when using positive indices.
1798
- *
1799
- * If either index is out of bounds the result would be a shallow copy of the input, as-is.
1800
- *
1801
- * @param data the item to be manipulated. This can be an array, or a string.
1802
- * @param index1 the first index
1803
- * @param index2 the second index
1804
- *
1805
- * @signature
1806
- * swapIndices(data, index1, index2)
1807
- *
1808
- * @example
1809
- * swapIndices(['a', 'b', 'c'], 0, 1) // => ['b', 'a', 'c']
1810
- * swapIndices(['a', 'b', 'c'], 1, -1) // => ['c', 'b', 'a']
1811
- * swapIndices('abc', 0, 1) // => 'bac'
1812
- *
1813
- * @category Array
1814
- *
1815
- * @returns Returns the manipulated array or string.
1816
- *
1817
- * @dataFirst
1818
- */
1819
- declare function swapIndices<T extends IterableContainer | string, K1 extends number, K2 extends number>(data: T, index1: K1, index2: K2): SwappedIndices<T, K1, K2>;
1820
- /**
1821
- * @param index1 the first index
1822
- * @param index2 the second index
1823
- *
1824
- * @signature
1825
- * swapIndices(index1, index2)(data)
1826
- *
1827
- * @example
1828
- * swapIndices(0, 1)(['a', 'b', 'c']) // => ['b', 'a', 'c']
1829
- * swapIndices(0, -1)('abc') // => 'cba'
1830
- *
1831
- * @category Array
1832
- * @returns Returns the manipulated array or string.
1833
- * @dataLast
1834
- */
1835
- declare function swapIndices<K1 extends number, K2 extends number>(index1: K1, index2: K2): <T extends IterableContainer | string>(data: T) => SwappedIndices<T, K1, K2>;
1836
-
1837
- /**
1838
- * Returns the first `n` elements of `array`.
1839
- * @param array the array
1840
- * @param n the number of elements to take
1841
- * @signature
1842
- * P.take(array, n)
1843
- * @example
1844
- * P.take([1, 2, 3, 4, 3, 2, 1], 3) // => [1, 2, 3]
1845
- * @dataFirst
1846
- * @pipeable
1847
- * @category Array
1848
- */
1849
- declare function take<T>(array: ReadonlyArray<T>, n: number): Array<T>;
1850
- /**
1851
- * Returns the first `n` elements of `array`.
1852
- * @param n the number of elements to take
1853
- * @signature
1854
- * P.take(n)(array)
1855
- * @example
1856
- * P.pipe([1, 2, 3, 4, 3, 2, 1], P.take(n)) // => [1, 2, 3]
1857
- * @dataLast
1858
- * @pipeable
1859
- * @category Array
1860
- */
1861
- declare function take<T>(n: number): (array: ReadonlyArray<T>) => Array<T>;
1862
- declare namespace take {
1863
- function lazy<T>(n: number): (value: T) => LazyResult<T>;
1864
- }
1865
-
1866
- /**
1867
- * Returns elements from the array until predicate returns false.
1868
- * @param array the array
1869
- * @param fn the predicate
1870
- * @signature
1871
- * P.takeWhile(array, fn)
1872
- * @example
1873
- * P.takeWhile([1, 2, 3, 4, 3, 2, 1], x => x !== 4) // => [1, 2, 3]
1874
- * @dataFirst
1875
- * @category Array
1876
- */
1877
- declare function takeWhile<T>(array: ReadonlyArray<T>, fn: (item: T) => boolean): Array<T>;
1878
- /**
1879
- * Returns elements from the array until predicate returns false.
1880
- * @param fn the predicate
1881
- * @signature
1882
- * P.takeWhile(fn)(array)
1883
- * @example
1884
- * P.pipe([1, 2, 3, 4, 3, 2, 1], P.takeWhile(x => x !== 4)) // => [1, 2, 3]
1885
- * @dataLast
1886
- * @category Array
1887
- */
1888
- declare function takeWhile<T>(fn: (item: T) => boolean): (array: ReadonlyArray<T>) => Array<T>;
1889
-
1890
- /**
1891
- * Returns a new array containing only one copy of each element in the original list.
1892
- * Elements are compared by reference using Set.
1893
- * Note: In `pipe`, use `uniq()` form instead of `uniq`. Otherwise, the inferred type is lost.
1894
- * @param array
1895
- * @signature
1896
- * P.uniq(array)
1897
- * @example
1898
- * P.uniq([1, 2, 2, 5, 1, 6, 7]) // => [1, 2, 5, 6, 7]
1899
- * P.pipe(
1900
- * [1, 2, 2, 5, 1, 6, 7], // only 4 iterations
1901
- * P.uniq(),
1902
- * P.take(3)
1903
- * ) // => [1, 2, 5]
1904
- * @pipeable
1905
- * @category Array
1906
- */
1907
- declare function uniq<T>(array: ReadonlyArray<T>): Array<T>;
1908
- declare function uniq<T>(): (array: ReadonlyArray<T>) => Array<T>;
1909
- declare namespace uniq {
1910
- function lazy(): (value: any) => LazyResult<any>;
1911
- }
1912
-
1913
- declare function uniqBy<T, K>(array: ReadonlyArray<T>, transformer: (item: T) => K): Array<T>;
1914
- /**
1915
- * Returns a new array containing only one copy of each element in the original list transformed by a function.
1916
- * Elements are compared by reference using Set.
1917
- * @param array
1918
- * @signature
1919
- * P.uniqBy(array, fn)
1920
- * @example
1921
- * P.uniqBy(
1922
- * [{ n: 1 }, { n: 2 }, { n: 2 }, { n: 5 }, { n: 1 }, { n: 6 }, { n: 7 }],
1923
- * (obj) => obj.n,
1924
- * ) // => [{n: 1}, {n: 2}, {n: 5}, {n: 6}, {n: 7}]
1925
- * P.pipe(
1926
- * [{n: 1}, {n: 2}, {n: 2}, {n: 5}, {n: 1}, {n: 6}, {n: 7}], // only 4 iterations
1927
- * P.uniqBy(obj => obj.n),
1928
- * P.take(3)
1929
- * ) // => [{n: 1}, {n: 2}, {n: 5}]
1930
- * @pipeable
1931
- * @category Array
1932
- */
1933
- declare function uniqBy<T, K>(transformer: (item: T) => K): (array: ReadonlyArray<T>) => Array<T>;
1934
-
1935
- type IsEquals<T> = (a: T, b: T) => boolean;
1936
- declare function _lazy<T>(isEquals: IsEquals<T>): (value: T, index?: number, array?: Array<T>) => LazyResult<T>;
1937
- /**
1938
- * Returns a new array containing only one copy of each element in the original list.
1939
- * Elements are compared by custom comparator isEquals.
1940
- * @param array
1941
- * @param isEquals the comparator
1942
- * @signature
1943
- * P.uniqWith(array, isEquals)
1944
- * @example
1945
- * P.uniqWith(
1946
- * [{a: 1}, {a: 2}, {a: 2}, {a: 5}, {a: 1}, {a: 6}, {a: 7}],
1947
- * P.equals,
1948
- * ) // => [{a: 1}, {a: 2}, {a: 5}, {a: 6}, {a: 7}]
1949
- * @dataFirst
1950
- * @category Array
1951
- */
1952
- declare function uniqWith<T>(array: ReadonlyArray<T>, isEquals: IsEquals<T>): Array<T>;
1953
- /**
1954
- * Returns a new array containing only one copy of each element in the original list.
1955
- * Elements are compared by custom comparator isEquals.
1956
- * @param isEquals the comparator
1957
- * @signature P.uniqWith(isEquals)(array)
1958
- * @example
1959
- * P.uniqWith(P.equals)(
1960
- * [{a: 1}, {a: 2}, {a: 2}, {a: 5}, {a: 1}, {a: 6}, {a: 7}],
1961
- * ) // => [{a: 1}, {a: 2}, {a: 5}, {a: 6}, {a: 7}]
1962
- * P.pipe(
1963
- * [{a: 1}, {a: 2}, {a: 2}, {a: 5}, {a: 1}, {a: 6}, {a: 7}], // only 4 iterations
1964
- * P.uniqWith(P.equals),
1965
- * P.take(3)
1966
- * ) // => [{a: 1}, {a: 2}, {a: 5}]
1967
- * @dataLast
1968
- * @category Object
1969
- */
1970
- declare function uniqWith<T>(isEquals: IsEquals<T>): (array: ReadonlyArray<T>) => Array<T>;
1971
- declare namespace uniqWith {
1972
- const lazy: typeof _lazy & {
1973
- indexed: true;
1974
- };
1975
- }
1976
-
1977
- interface Strict$2 {
1978
- <F extends IterableContainer, S extends IterableContainer>(first: F, second: S): Zip<F, S>;
1979
- <S extends IterableContainer>(second: S): <F extends IterableContainer>(first: F) => Zip<F, S>;
1980
- }
1981
- type Zip<Left extends IterableContainer, Right extends IterableContainer> = Left extends readonly [] ? [] : Right extends readonly [] ? [] : Left extends readonly [infer LeftHead, ...infer LeftRest] ? Right extends readonly [infer RightHead, ...infer RightRest] ? [
1982
- [LeftHead, RightHead],
1983
- ...Zip<LeftRest, RightRest>
1984
- ] : [
1985
- [LeftHead, Right[number]],
1986
- ...Zip<LeftRest, Right>
1987
- ] : Right extends readonly [infer RightHead, ...infer RightRest] ? [[Left[number], RightHead], ...Zip<Left, RightRest>] : Array<[Left[number], Right[number]]>;
1988
- /**
1989
- * Creates a new list from two supplied lists by pairing up equally-positioned items.
1990
- * The length of the returned list will match the shortest of the two inputs.
1991
- *
1992
- * If the input array are tuples, you can use the strict option
1993
- * to get another tuple instead of a generic array type.
1994
- * @param first the first input list
1995
- * @param second the second input list
1996
- * @signature
1997
- * P.zip(first, second)
1998
- * @example
1999
- * P.zip([1, 2], ['a', 'b']) // => [[1, 'a'], [2, 'b']] (type: [number, string][])
2000
- * P.zip.strict([1, 2] as const, ['a', 'b'] as const) // => [[1, 'a'], [2, 'b']] (type: [[1, 'a'], [2, 'b']])
2001
- * @dataFirst
2002
- * @category Array
2003
- * @strict
2004
- */
2005
- declare function zip<F, S>(first: ReadonlyArray<F>, second: ReadonlyArray<S>): Array<[F, S]>;
2006
- /**
2007
- * Creates a new list from two supplied lists by pairing up equally-positioned items.
2008
- * The length of the returned list will match the shortest of the two inputs.
2009
- *
2010
- * If the input array are tuples, you can use the strict option
2011
- * to get another tuple instead of a generic array type.
2012
- * @param second the second input list
2013
- * @signature
2014
- * P.zip(second)(first)
2015
- * @example
2016
- * P.zip(['a', 'b'])([1, 2]) // => [[1, 'a'], [2, 'b']] (type: [number, string][])
2017
- * P.zip.strict(['a', 'b'] as const)([1, 2] as const) // => [[1, 'a'], [2, 'b']] (type: [[1, 'a'], [2, 'b']])
2018
- * @dataLast
2019
- * @category Array
2020
- * @strict
2021
- */
2022
- declare function zip<S>(second: ReadonlyArray<S>): <F>(first: ReadonlyArray<F>) => Array<[F, S]>;
2023
- declare namespace zip {
2024
- const strict: Strict$2;
2025
- }
2026
-
2027
- /**
2028
- * Creates a new object from two supplied lists by pairing up equally-positioned items.
2029
- * Key/value pairing is truncated to the length of the shorter of the two lists
2030
- * @param first the first input list
2031
- * @param second the second input list
2032
- * @signature
2033
- * P.zipObj(first, second)
2034
- * @example
2035
- * P.zipObj(['a', 'b'], [1, 2]) // => {a: 1, b: 2}
2036
- * @dataFirst
2037
- * @category Array
2038
- */
2039
- declare function zipObj<F extends number | string | symbol, S>(first: ReadonlyArray<F>, second: ReadonlyArray<S>): Record<F, S>;
2040
- /**
2041
- * Creates a new object from two supplied lists by pairing up equally-positioned items.
2042
- * Key/value pairing is truncated to the length of the shorter of the two lists
2043
- * @param second the second input list
2044
- * @signature
2045
- * P.zipObj(second)(first)
2046
- * @example
2047
- * P.zipObj([1, 2])(['a', 'b']) // => {a: 1, b: 2}
2048
- * @dataLast
2049
- * @category Array
2050
- */
2051
- declare function zipObj<S>(second: ReadonlyArray<S>): <F extends number | string | symbol>(first: ReadonlyArray<F>) => Record<F, S>;
2052
-
2053
- /**
2054
- * Creates a new list from two supplied lists by calling the supplied function
2055
- * with the same-positioned element from each list.
2056
- * @param first the first input list
2057
- * @param second the second input list
2058
- * @param fn the function applied to each position of the list
2059
- * @signature
2060
- * P.zipWith(first, second, fn)
2061
- * @example
2062
- * P.zipWith(['1', '2', '3'], ['a', 'b', 'c'], (a, b) => a + b) // => ['1a', '2b', '3c']
2063
- * @dataFirst
2064
- * @category Array
2065
- */
2066
- declare function zipWith<F, S, R>(first: Array<F>, second: Array<S>, fn: (f: F, s: S) => R): Array<R>;
2067
- /**
2068
- * Creates a new list from two supplied lists by calling the supplied function
2069
- * with the same-positioned element from each list.
2070
- * @param fn the function applied to each position of the list
2071
- * @signature
2072
- * P.zipWith(fn)(first, second)
2073
- * @example
2074
- * P.zipWith((a, b) => a + b)(['1', '2', '3'], ['a', 'b', 'c']) // => ['1a', '2b', '3c']
2075
- * @dataLast
2076
- * @category Array
2077
- */
2078
- declare function zipWith<F, S, R>(fn: (f: F, s: S) => R): (first: Array<F>, second: Array<S>) => Array<R>;
2079
- /**
2080
- * Creates a new list from two supplied lists by calling the supplied function
2081
- * with the same-positioned element from each list.
2082
- * @param fn the function applied to each position of the list
2083
- * @param second the second input list
2084
- * @signature
2085
- * P.zipWith(fn)(first, second)
2086
- * @example
2087
- * P.zipWith((a, b) => a + b, ['a', 'b', 'c'])(['1', '2', '3']) // => ['1a', '2b', '3c']
2088
- * @dataLast
2089
- * @category Array
2090
- */
2091
- declare function zipWith<F, S, R>(fn: (f: F, s: S) => R, second: Array<S>): (first: Array<F>) => Array<R>;
2092
-
2093
- /**
2094
- * Creates a data-last pipe function. First function must be always annotated. Other functions are automatically inferred.
2095
- * @signature
2096
- * P.createPipe(op1, op2, op3)(data);
2097
- * @example
2098
- * P.createPipe(
2099
- * (x: number) => x * 2,
2100
- * x => x * 3
2101
- * )(1) // => 6
2102
- * @category Function
2103
- */
2104
- declare function createPipe<A, B>(op1: (input: A) => B): (value: A) => B;
2105
- declare function createPipe<A, B, C>(op1: (input: A) => B, op2: (input: B) => C): (value: A) => C;
2106
- declare function createPipe<A, B, C, D>(op1: (input: A) => B, op2: (input: B) => C, op3: (input: C) => D): (value: A) => D;
2107
- declare function createPipe<A, B, C, D, E>(op1: (input: A) => B, op2: (input: B) => C, op3: (input: C) => D, op4: (input: D) => E): (value: A) => E;
2108
- declare function createPipe<A, B, C, D, E, F>(op1: (input: A) => B, op2: (input: B) => C, op3: (input: C) => D, op4: (input: D) => E, op5: (input: E) => F): (value: A) => F;
2109
- declare function createPipe<A, B, C, D, E, F, G>(op1: (input: A) => B, op2: (input: B) => C, op3: (input: C) => D, op4: (input: D) => E, op5: (input: E) => F, op6: (input: F) => G): (value: A) => G;
2110
- declare function createPipe<A, B, C, D, E, F, G, H>(op1: (input: A) => B, op2: (input: B) => C, op3: (input: C) => D, op4: (input: D) => E, op5: (input: E) => F, op6: (input: F) => G, op7: (input: G) => H): (value: A) => H;
2111
-
2112
- /**
2113
- * A function that always returns the param passed to it
2114
- * @signature
2115
- * P.identity(data)
2116
- * @example
2117
- * P.identity('foo') // => 'foo'
2118
- * @category Function
2119
- */
2120
- declare function identity<T>(value: T): T;
2121
-
2122
- /**
2123
- * A function that returns always `undefined`.
2124
- * @signature
2125
- * P.noop()
2126
- * @example
2127
- * onSomething(P.noop)
2128
- * @category Function
2129
- */
2130
- declare function noop(): undefined;
2131
-
2132
- /**
2133
- * Creates a function that is restricted to invoking `func` once. Repeat calls to the function return the value of the first invocation.
2134
- * @param fn the function to wrap
2135
- * @signature P.once(fn)
2136
- * @example
2137
- * const initialize = P.once(createApplication);
2138
- * initialize();
2139
- * initialize();
2140
- * // => `createApplication` is invoked once
2141
- * @category Function
2142
- */
2143
- declare function once<T>(fn: () => T): () => T;
2144
-
2145
- interface Debouncer<F extends (...args: any) => unknown, IsNullable extends boolean = true> {
2146
- /**
2147
- * The last computed value of the debounced function.
2148
- */
2149
- readonly cachedValue: ReturnType<F> | undefined;
2150
- /**
2151
- * Invoke the debounced function.
2152
- * @param args - same as the args for the debounced function.
2153
- * @returns - the last computed value of the debounced function with the
2154
- * latest args provided to it. If `timing` does not include `leading` then the
2155
- * the function would return `undefined` until the first cool-down period is
2156
- * over, otherwise the function would always return the return type of the
2157
- * debounced function.
2158
- */
2159
- readonly call: (...args: Parameters<F>) => ReturnType<F> | (true extends IsNullable ? undefined : never);
2160
- /**
2161
- * Cancels any debounced functions without calling them, effectively resetting
2162
- * the debouncer to the same state it is when initially created.
2163
- */
2164
- readonly cancel: () => void;
2165
- /**
2166
- * Similar to `cancel`, but would also trigger the `trailing` invocation if
2167
- * the debouncer would run one at the end of the cool-down period.
2168
- */
2169
- readonly flush: () => ReturnType<F> | undefined;
2170
- /**
2171
- * Is `true` when there is an active cool-down period currently debouncing
2172
- * invocations.
2173
- */
2174
- readonly isPending: boolean;
2175
- }
2176
- interface DebounceOptions {
2177
- readonly maxWaitMs?: number;
2178
- readonly waitMs?: number;
2179
- }
2180
- /**
2181
- * Wraps `func` with a debouncer object that "debounces" (delays) invocations of the function during a defined cool-down period (`waitMs`). It can be configured to invoke the function either at the start of the cool-down period, the end of it, or at both ends (`timing`).
2182
- * It can also be configured to allow invocations during the cool-down period (`maxWaitMs`).
2183
- * It stores the latest call's arguments so they could be used at the end of the cool-down period when invoking `func` (if configured to invoke the function at the end of the cool-down period).
2184
- * It stores the value returned by `func` whenever its invoked. This value is returned on every call, and is accessible via the `cachedValue` property of the debouncer. Its important to note that the value might be different from the value that would be returned from running `func` with the current arguments as it is a cached value from a previous invocation.
2185
- * **Important**: The cool-down period defines the minimum between two invocations, and not the maximum. The period will be **extended** each time a call is made until a full cool-down period has elapsed without any additional calls.
2186
- * @param func The function to debounce, the returned `call` function will have
2187
- * the exact same signature.
2188
- * @param options An object allowing further customization of the debouncer:
2189
- * - `timing?: 'leading' | 'trailing' |'both'`. The default is `'trailing'`.
2190
- * `leading` would result in the function being invoked at the start of the
2191
- * cool-down period; `trailing` would result in the function being invoked at
2192
- * the end of the cool-down period (using the args from the last call to the
2193
- * debouncer). When `both` is selected the `trailing` invocation would only
2194
- * take place if there were more than one call to the debouncer during the
2195
- * cool-down period. **DEFAULT: 'trailing'**
2196
- * - `waitMs?: number`. The length of the cool-down period in milliseconds. The
2197
- * debouncer would wait until this amount of time has passed without **any**
2198
- * additional calls to the debouncer before triggering the end-of-cool-down-
2199
- * period event. When this happens, the function would be invoked (if `timing`
2200
- * isn't `'leading'`) and the debouncer state would be reset. **DEFAULT: 0**
2201
- * - `maxWaitMs?: number`. The length of time since a debounced call (a call
2202
- * that the debouncer prevented from being invoked) was made until it would be
2203
- * invoked. Because the debouncer can be continually triggered and thus never
2204
- * reach the end of the cool-down period, this allows the function to still
2205
- * be invoked occasionally. IMPORTANT: This param is ignored when `timing` is
2206
- * `'leading'`.
2207
- * @returns a debouncer object. The main function is `call`. In addition to it
2208
- * the debouncer comes with the following additional functions and properties:
2209
- * - `cancel` method to cancel delayed `func` invocations
2210
- * - `flush` method to end the cool-down period immediately.
2211
- * - `cachedValue` the latest return value of an invocation (if one occurred).
2212
- * - `isPending` flag to check if there is an inflight cool-down window.
2213
- * @signature
2214
- * P.debounce(func, options);
2215
- * @example
2216
- * const debouncer = debounce(identity, { timing: 'trailing', waitMs: 1000 });
2217
- * const result1 = debouncer.call(1); // => undefined
2218
- * const result2 = debouncer.call(2); // => undefined
2219
- * // after 1 second
2220
- * const result3 = debouncer.call(3); // => 2
2221
- * // after 1 second
2222
- * debouncer.cachedValue; // => 3
2223
- * @dataFirst
2224
- * @category Function
2225
- * @see https://css-tricks.com/debouncing-throttling-explained-examples/
2226
- */
2227
- declare function debounce<F extends (...args: any) => any>(func: F, options: {
2228
- readonly timing?: 'trailing';
2229
- } & DebounceOptions): Debouncer<F>;
2230
- declare function debounce<F extends (...args: any) => any>(func: F, options: ({
2231
- readonly timing: 'both';
2232
- } & DebounceOptions) | ({
2233
- readonly timing: 'leading';
2234
- } & Omit<DebounceOptions, 'maxWaitMs'>)): Debouncer<F, false>;
2235
-
2236
- /**
2237
- * Perform left-to-right function composition.
2238
- * @param value The initial value.
2239
- * @param arguments the list of operations to apply.
2240
- * @signature P.pipe(data, op1, op2, op3)
2241
- * @example
2242
- * P.pipe(
2243
- * [1, 2, 3, 4],
2244
- * P.map(x => x * 2),
2245
- * arr => [arr[0] + arr[1], arr[2] + arr[3]],
2246
- * ) // => [6, 14]
2247
- *
2248
- *
2249
- * @dataFirst
2250
- * @category Function
2251
- */
2252
- declare function pipe<A, B>(value: A, op1: (input: A) => B): B;
2253
- declare function pipe<A, B, C>(value: A, op1: (input: A) => B, op2: (input: B) => C): C;
2254
- declare function pipe<A, B, C, D>(value: A, op1: (input: A) => B, op2: (input: B) => C, op3: (input: C) => D): D;
2255
- declare function pipe<A, B, C, D, E>(value: A, op1: (input: A) => B, op2: (input: B) => C, op3: (input: C) => D, op4: (input: D) => E): E;
2256
- declare function pipe<A, B, C, D, E, F>(value: A, op1: (input: A) => B, op2: (input: B) => C, op3: (input: C) => D, op4: (input: D) => E, op5: (input: E) => F): F;
2257
- declare function pipe<A, B, C, D, E, F, G>(value: A, op1: (input: A) => B, op2: (input: B) => C, op3: (input: C) => D, op4: (input: D) => E, op5: (input: E) => F, op6: (input: F) => G): G;
2258
- declare function pipe<A, B, C, D, E, F, G, H>(value: A, op1: (input: A) => B, op2: (input: B) => C, op3: (input: C) => D, op4: (input: D) => E, op5: (input: E) => F, op6: (input: F) => G, op7: (input: G) => H): H;
2259
- declare function pipe<A, B, C, D, E, F, G, H, I>(value: A, op1: (input: A) => B, op2: (input: B) => C, op3: (input: C) => D, op4: (input: D) => E, op5: (input: E) => F, op6: (input: F) => G, op7: (input: G) => H, op8: (input: H) => I): I;
2260
- declare function pipe<A, B, C, D, E, F, G, H, I, J>(value: A, op1: (input: A) => B, op2: (input: B) => C, op3: (input: C) => D, op4: (input: D) => E, op5: (input: E) => F, op6: (input: F) => G, op7: (input: G) => H, op8: (input: H) => I, op9: (input: I) => J): J;
2261
- declare function pipe<A, B, C, D, E, F, G, H, I, J, K>(value: A, op01: (input: A) => B, op02: (input: B) => C, op03: (input: C) => D, op04: (input: D) => E, op05: (input: E) => F, op06: (input: F) => G, op07: (input: G) => H, op08: (input: H) => I, op09: (input: I) => J, op10: (input: J) => K): K;
2262
- declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L>(value: A, op01: (input: A) => B, op02: (input: B) => C, op03: (input: C) => D, op04: (input: D) => E, op05: (input: E) => F, op06: (input: F) => G, op07: (input: G) => H, op08: (input: H) => I, op09: (input: I) => J, op10: (input: J) => K, op11: (input: K) => L): L;
2263
- declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M>(value: A, op01: (input: A) => B, op02: (input: B) => C, op03: (input: C) => D, op04: (input: D) => E, op05: (input: E) => F, op06: (input: F) => G, op07: (input: G) => H, op08: (input: H) => I, op09: (input: I) => J, op10: (input: J) => K, op11: (input: K) => L, op12: (input: L) => M): M;
2264
- declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(value: A, op01: (input: A) => B, op02: (input: B) => C, op03: (input: C) => D, op04: (input: D) => E, op05: (input: E) => F, op06: (input: F) => G, op07: (input: G) => H, op08: (input: H) => I, op09: (input: I) => J, op10: (input: J) => K, op11: (input: K) => L, op12: (input: L) => M, op13: (input: M) => N): N;
2265
- declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(value: A, op01: (input: A) => B, op02: (input: B) => C, op03: (input: C) => D, op04: (input: D) => E, op05: (input: E) => F, op06: (input: F) => G, op07: (input: G) => H, op08: (input: H) => I, op09: (input: I) => J, op10: (input: J) => K, op11: (input: K) => L, op12: (input: L) => M, op13: (input: M) => N, op14: (input: N) => O): O;
2266
- declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(value: A, op01: (input: A) => B, op02: (input: B) => C, op03: (input: C) => D, op04: (input: D) => E, op05: (input: E) => F, op06: (input: F) => G, op07: (input: G) => H, op08: (input: H) => I, op09: (input: I) => J, op10: (input: J) => K, op11: (input: K) => L, op12: (input: L) => M, op13: (input: M) => N, op14: (input: N) => O, op15: (input: O) => P): P;
2267
-
2268
- /**
2269
- * Creates a function with `data-first` and `data-last` signatures.
2270
- *
2271
- * `purry` is a dynamic function and it's not type safe. It should be wrapped by a function that have proper typings.
2272
- * Refer to the example below for correct usage.
2273
- *
2274
- * @param fn the function to purry.
2275
- * @param args the arguments
2276
- * @signature P.purry(fn, arguments);
2277
- * @exampleRaw
2278
- * function _findIndex(array, fn) {
2279
- * for (let i = 0; i < array.length; i++) {
2280
- * if (fn(array[i])) {
2281
- * return i;
2282
- * }
2283
- * }
2284
- * return -1;
2285
- * }
2286
- *
2287
- * // data-first
2288
- * function findIndex<T>(array: T[], fn: (item: T) => boolean): number;
2289
- *
2290
- * // data-last
2291
- * function findIndex<T>(fn: (item: T) => boolean): (array: T[]) => number;
2292
- *
2293
- * function findIndex() {
2294
- * return P.purry(_findIndex, arguments);
2295
- * }
2296
- * @category Function
2297
- */
2298
- declare function purry(fn: any, args: IArguments | ReadonlyArray<any>, lazy?: any): any;
2299
-
2300
- /**
2301
- * Delay execution for a given number of milliseconds.
2302
- *
2303
- * @param timeout the number of milliseconds to wait
2304
- * @signature
2305
- * P.sleep(timeout)
2306
- * @example
2307
- * P.sleep(1000) // => Promise<void>
2308
- * @category Function
2309
- */
2310
- declare function sleep(timeout: number): Promise<void>;
2311
-
2312
- type DefinitelyArray<T> = Extract<T, Array<any> | ReadonlyArray<any>> extends never ? ReadonlyArray<unknown> : Extract<T, Array<any> | ReadonlyArray<any>>;
2313
- /**
2314
- * A function that checks if the passed parameter is an Array and narrows its type accordingly
2315
- * @param data the variable to check
2316
- * @signature
2317
- * P.isArray(data)
2318
- * @returns true if the passed input is an Array, false otherwise
2319
- * @example
2320
- * P.isArray([5]) //=> true
2321
- * P.isArray([]) //=> true
2322
- * P.isArray('somethingElse') //=> false
2323
- * @category Guard
2324
- */
2325
- declare function isArray<T>(data: ReadonlyArray<unknown> | T): data is DefinitelyArray<T>;
2326
-
2327
- type DefinitelyBoolean<T> = Extract<T, boolean> extends never ? boolean : Extract<T, boolean> extends any ? boolean : Extract<T, number>;
2328
- /**
2329
- * A function that checks if the passed parameter is a boolean and narrows its type accordingly
2330
- * @param data the variable to check
2331
- * @signature
2332
- * P.isBoolean(data)
2333
- * @returns true if the passed input is a boolean, false otherwise
2334
- * @example
2335
- * P.isBoolean(true) //=> true
2336
- * P.isBoolean(false) //=> true
2337
- * P.isBoolean('somethingElse') //=> false
2338
- * @category Guard
2339
- */
2340
- declare function isBoolean<T>(data: T | boolean): data is DefinitelyBoolean<T>;
2341
-
2342
- /**
2343
- * A function that checks if the passed parameter is a Date and narrows its type accordingly
2344
- * @param data the variable to check
2345
- * @signature
2346
- * P.isDate(data)
2347
- * @returns true if the passed input is a Date, false otherwise
2348
- * @example
2349
- * P.isDate(new Date()) //=> true
2350
- * P.isDate('somethingElse') //=> false
2351
- * @category Guard
2352
- */
2353
- declare function isDate(data: unknown): data is Date;
2354
-
2355
- /**
2356
- * A function that checks if the passed parameter is defined and narrows its type accordingly.
2357
- * To test specifically for `undefined` (and not `null`) use the strict variant of this function.
2358
- * @param data the variable to check
2359
- * @signature
2360
- * P.isDefined(data)
2361
- * P.isDefined.strict(data)
2362
- * @returns true if the passed input is defined, false otherwise
2363
- * @example
2364
- * P.isDefined('string') //=> true
2365
- * P.isDefined(null) //=> false
2366
- * P.isDefined(undefined) //=> false
2367
- * P.isDefined.strict(null) //=> true
2368
- * P.isDefined.strict(undefined) //=> false
2369
- * @category Guard
2370
- * @strict
2371
- */
2372
- declare function isDefined<T>(data: T): data is NonNullable<T>;
2373
- declare namespace isDefined {
2374
- function strict<T>(data: T | undefined): data is T;
2375
- }
2376
-
2377
- /**
2378
- * A function that checks if the passed parameter is empty
2379
- * @param data the variable to check
2380
- * @signature
2381
- * P.isEmpty(data)
2382
- * @returns true if the passed input is empty, false otherwise
2383
- * @example
2384
- * P.isEmpty('') //=> true
2385
- * P.isEmpty([]) //=> true
2386
- * P.isEmpty({}) //=> true
2387
- * P.isEmpty('test') //=> false
2388
- * P.isEmpty([1, 2, 3]) //=> false
2389
- * P.isEmpty({ length: 0 }) //=> false
2390
- * @category Function
2391
- */
2392
- declare function isEmpty(data: string): data is '';
2393
- declare function isEmpty(data: [] | ReadonlyArray<unknown>): data is [];
2394
- declare function isEmpty<T extends Readonly<Record<PropertyKey, unknown>>>(data: T): data is Record<keyof T, never>;
2395
-
2396
- type DefinitelyError<T> = Extract<T, Error> extends never ? Error : Extract<T, Error>;
2397
- /**
2398
- * A function that checks if the passed parameter is an Error and narrows its type accordingly
2399
- * @param data the variable to check
2400
- * @signature
2401
- * P.isError(data)
2402
- * @returns true if the passed input is an Error, false otherwise
2403
- * @example
2404
- * P.isError(new Error('message')) //=> true
2405
- * P.isError('somethingElse') //=> false
2406
- * @category Guard
2407
- */
2408
- declare function isError<T>(data: Error | T): data is DefinitelyError<T>;
2409
-
2410
- type DefinitelyFunction<T> = Extract<T, Function> extends never ? Function : Extract<T, Function>;
2411
- /**
2412
- * A function that checks if the passed parameter is a Function and narrows its type accordingly
2413
- * @param data the variable to check
2414
- * @signature
2415
- * P.isFunction(data)
2416
- * @returns true if the passed input is a Function, false otherwise
2417
- * @example
2418
- * P.isFunction(() => {}) //=> true
2419
- * P.isFunction('somethingElse') //=> false
2420
- * @category Guard
2421
- */
2422
- declare function isFunction<T>(data: Function | T): data is DefinitelyFunction<T>;
2423
-
2424
- /**
2425
- * A function that checks if the passed parameter is Nil (null or undefined) and narrows its type accordingly
2426
- * @param data the variable to check
2427
- * @signature
2428
- * P.isNil(data)
2429
- * @returns true if the passed input is Nil (null or undefined), false otherwise
2430
- * @example
2431
- * P.isNil(undefined) //=> true
2432
- * P.isNil(null) //=> true
2433
- * P.isNil('somethingElse') //=> false
2434
- * @category Guard
2435
- */
2436
- declare function isNil<T>(data: T): data is Extract<T, null | undefined>;
2437
-
2438
- /**
2439
- * A function that checks if the passed parameter is not `null` and narrows its type accordingly.
2440
- * Notice that `undefined` is not null!
2441
- * @param data the variable to check
2442
- * @signature
2443
- * P.isNonNull(data)
2444
- * @returns true if the passed input is defined, false otherwise
2445
- * @example
2446
- * P.isNonNull('string') //=> true
2447
- * P.isNonNull(null) //=> false
2448
- * P.isNonNull(undefined) //=> true
2449
- * @category Guard
2450
- */
2451
- declare function isNonNull<T>(data: T | null): data is T;
2452
-
2453
- /**
2454
- * A function that takes a guard function as predicate and returns a guard that negates it
2455
- * @param predicate the guard function to negate
2456
- * @signature
2457
- * P.isNot(P.isTruthy)(data)
2458
- * @returns function A guard function
2459
- * @example
2460
- * P.isNot(P.isTruthy)(false) //=> true
2461
- * P.isNot(P.isTruthy)(true) //=> false
2462
- * @dataLast
2463
- * @category Guard
2464
- */
2465
- declare function isNot<T, S extends T>(predicate: (data: T) => data is S): (data: T) => data is Exclude<T, S>;
2466
- declare function isNot<T>(predicate: (data: T) => any): (data: T) => boolean;
2467
-
2468
- type DefinitelyNumber<T> = Extract<T, number> extends never ? number : Extract<T, number> extends any ? number : Extract<T, number>;
2469
- /**
2470
- * A function that checks if the passed parameter is a number and narrows its type accordingly
2471
- * @param data the variable to check
2472
- * @signature
2473
- * R.isNumber(data)
2474
- * @returns true if the passed input is a number, false otherwise
2475
- * @example
2476
- * R.isNumber(1) //=> true
2477
- * R.isNumber('notANumber') //=> false
2478
- * @category Guard
2479
- */
2480
- declare function isNumber<T>(data: T | number): data is DefinitelyNumber<T>;
2481
-
2482
- type DefinitelyObject<T> = Exclude<Extract<T, object>, Array<any> | Function | ReadonlyArray<any>> extends never ? Record<string, unknown> : Exclude<Extract<T, object>, Array<any> | Function | ReadonlyArray<any>>;
2483
- /**
2484
- * A function that checks if the passed parameter is of type Object and narrows its type accordingly
2485
- * @param data the variable to check
2486
- * @signature
2487
- * P.isObject(data)
2488
- * @returns true if the passed input is an Object, Promise, Date or Error, false otherwise
2489
- * @example
2490
- * P.isObject({}) //=> true
2491
- * P.isObject(Promise.resolve("something")) //=> true
2492
- * P.isObject(new Date()) //=> true
2493
- * P.isObject(new Error("error")) //=> true
2494
- * P.isObject('somethingElse') //=> false
2495
- * @category Guard
2496
- */
2497
- declare function isObject<T>(data: T | object): data is DefinitelyObject<T>;
2498
-
2499
- /**
2500
- * A function that checks if the passed parameter is a Promise and narrows its type accordingly
2501
- * @param data the variable to check
2502
- * @signature
2503
- * P.isPromise(data)
2504
- * @returns true if the passed input is a Promise, false otherwise
2505
- * @example
2506
- * P.isPromise(Promise.resolve(5)) //=> true
2507
- * P.isPromise(Promise.reject(5)) //=> true
2508
- * P.isPromise('somethingElse') //=> false
2509
- * @category Guard
2510
- */
2511
- declare function isPromise<T, S>(data: Promise<T> | S): data is Promise<T>;
2512
-
2513
- type DefinitelyString<T> = Extract<T, string> extends never ? string : Extract<T, string> extends any ? string : Extract<T, string>;
2514
- /**
2515
- * A function that checks if the passed parameter is a string and narrows its type accordingly
2516
- * @param data the variable to check
2517
- * @signature
2518
- * P.isString(data)
2519
- * @returns true if the passed input is a string, false otherwise
2520
- * @example
2521
- * P.isString('string') //=> true
2522
- * P.isString(1) //=> false
2523
- * @category Guard
2524
- */
2525
- declare function isString<T>(data: T | string): data is DefinitelyString<T>;
2526
-
2527
- /**
2528
- * A function that checks if the passed parameter is truthy and narrows its type accordingly
2529
- * @param data the variable to check
2530
- * @signature
2531
- * P.isTruthy(data)
2532
- * @returns true if the passed input is truthy, false otherwise
2533
- * @example
2534
- * P.isTruthy('somethingElse') //=> true
2535
- * P.isTruthy(null) //=> false
2536
- * P.isTruthy(undefined) //=> false
2537
- * P.isTruthy(false) //=> false
2538
- * P.isTruthy(0) //=> false
2539
- * P.isTruthy('') //=> false
2540
- * @category Guard
2541
- */
2542
- declare function isTruthy<T>(data: T): data is Exclude<T, '' | 0 | false | null | undefined>;
2543
-
2544
- /**
2545
- * Clamp the given value within the inclusive min and max bounds.
2546
- * @param value the number
2547
- * @param limits the bounds limits
2548
- * @param limits.min the minimal bounds limits
2549
- * @param limits.max the maximal bounds limits
2550
- * @signature
2551
- * P.clamp(value, { min, max });
2552
- * @example
2553
- * clamp(10, { min: 20 }) // => 20
2554
- * clamp(10, { max: 5 }) // => 5
2555
- * clamp(10, { max: 20, min: 5 }) // => 10
2556
- * @dataFirst
2557
- * @category Number
2558
- */
2559
- declare function clamp(value: number, limits: {
2560
- max?: number;
2561
- min?: number;
2562
- }): number;
2563
- /**
2564
- * Clamp the given value within the inclusive min and max bounds.
2565
- * @param limits the bounds limits
2566
- * @param limits.min the minimal bounds limits
2567
- * @param limits.max the maximal bounds limits
2568
- * @signature
2569
- * P.clamp({ min, max })(value);
2570
- * @example
2571
- * clamp({ min: 20 })(10) // => 20
2572
- * clamp({ max: 5 })(10) // => 5
2573
- * clamp({ max: 20, min: 5 })(10) // => 10
2574
- * @dataLast
2575
- * @category Number
2576
- */
2577
- declare function clamp(limits: {
2578
- max?: number;
2579
- min?: number;
2580
- }): (value: number) => number;
2581
-
2582
- /**
2583
- * Add a new property to an object.
2584
- * @param obj the target object
2585
- * @param prop the property name
2586
- * @param value the property value
2587
- * @signature
2588
- * P.addProp(obj, prop, value)
2589
- * @example
2590
- * P.addProp({firstName: 'john'}, 'lastName', 'doe') // => {firstName: 'john', lastName: 'doe'}
2591
- * @dataFirst
2592
- * @category Object
2593
- */
2594
- declare function addProp<T extends Record<PropertyKey, any>, K extends string, V>(obj: T, prop: K, value: V): T & {
2595
- [x in K]: V;
2596
- };
2597
- /**
2598
- * Add a new property to an object.
2599
- * @param prop the property name
2600
- * @param value the property value
2601
- * @signature
2602
- * P.addProp(prop, value)(obj)
2603
- * @example
2604
- * P.addProp('lastName', 'doe')({firstName: 'john'}) // => {firstName: 'john', lastName: 'doe'}
2605
- * @dataLast
2606
- * @category Object
2607
- */
2608
- declare function addProp<T extends Record<PropertyKey, any>, K extends string, V>(prop: K, value: V): (obj: T) => T & {
2609
- [x in K]: V;
2610
- };
2611
-
2612
- /**
2613
- * Creates a deep copy of the value. Supported types: `Array`, `Object`, `Number`, `String`, `Boolean`, `Date`, `RegExp`. Functions are assigned by reference rather than copied.
2614
- * @param value the object to clone
2615
- * @category Object
2616
- * @signature P.clone(value)
2617
- * @example P.clone({foo: 'bar'}) // {foo: 'bar'}
2618
- */
2619
- declare function clone<T>(value: T): T;
2620
-
2621
- /**
2622
- * Returns true if its arguments are equivalent, false otherwise.
2623
- * NOTE: Doesn't handle cyclical data structures.
2624
- * @param a the first object to compare
2625
- * @param b the second object to compare
2626
- * @signature
2627
- * P.equals(a, b)
2628
- * @example
2629
- * P.equals(1, 1) //=> true
2630
- * P.equals(1, '1') //=> false
2631
- * P.equals([1, 2, 3], [1, 2, 3]) //=> true
2632
- * @dataFirst
2633
- * @category Object
2634
- */
2635
- declare function equals(a: any, b: any): boolean;
2636
- /**
2637
- * Returns true if its arguments are equivalent, false otherwise.
2638
- * NOTE: Doesn't handle cyclical data structures.
2639
- * @param a the first object to compare
2640
- * @signature
2641
- * P.equals(b)(a)
2642
- * @example
2643
- * P.equals(1)(1) //=> true
2644
- * P.equals('1')(1) //=> false
2645
- * P.equals([1, 2, 3])([1, 2, 3]) //=> true
2646
- * @dataLast
2647
- * @category Object
2648
- */
2649
- declare function equals(a: any): (b: any) => boolean;
2650
-
2651
- type IndexedIteratee<T extends Record<PropertyKey, any>, K extends keyof T> = (value: T[K], key: K, obj: T) => void;
2652
- type UnindexedIteratee<T extends Record<PropertyKey, any>> = (value: T[keyof T]) => void;
2653
- /**
2654
- * Iterate an object using a defined callback function. The original object is returned.
2655
- * @param object The object.
2656
- * @param fn The callback function.
2657
- * @returns The original object
2658
- * @signature
2659
- * P.forEachObj(object, fn)
2660
- * @example
2661
- * P.forEachObj({a: 1}, (val) => {
2662
- * console.log(`${val}`)
2663
- * }) // "1"
2664
- * P.forEachObj.indexed({a: 1}, (val, key, obj) => {
2665
- * console.log(`${key}: ${val}`)
2666
- * }) // "a: 1"
2667
- * @dataFirst
2668
- * @category Object
2669
- */
2670
- declare function forEachObj<T extends Record<PropertyKey, any>>(object: T, fn: UnindexedIteratee<T>): T;
2671
- /**
2672
- * Iterate an object using a defined callback function. The original object is returned.
2673
- * @param fn The callback function.
2674
- * @signature
2675
- * P.forEachObj(fn)(object)
2676
- * @example
2677
- * P.pipe(
2678
- * {a: 1},
2679
- * P.forEachObj((val) => console.log(`${val}`))
2680
- * ) // "1"
2681
- * P.pipe(
2682
- * {a: 1},
2683
- * P.forEachObj.indexed((val, key) => console.log(`${key}: ${val}`))
2684
- * ) // "a: 1"
2685
- * @dataLast
2686
- * @category Object
2687
- */
2688
- declare function forEachObj<T extends Record<PropertyKey, any>>(fn: UnindexedIteratee<T>): (object: T) => T;
2689
- declare namespace forEachObj {
2690
- function indexed<T extends Record<PropertyKey, any>>(object: T, fn: IndexedIteratee<T, keyof T>): T;
2691
- function indexed<T extends Record<PropertyKey, any>>(fn: IndexedIteratee<T, keyof T>): (object: T) => T;
2692
- }
2693
-
2694
- type Entry<Key extends PropertyKey = PropertyKey, Value = unknown> = readonly [
2695
- key: Key,
2696
- value: Value
2697
- ];
2698
- type Strict$1 = <Entries extends IterableContainer<Entry>>(entries: Entries) => StrictOut<Entries>;
2699
- type StrictOut<Entries> = Entries extends readonly [infer First, ...infer Tail] ? FromPairsTuple<First, Tail> : Entries extends readonly [...infer Head, infer Last] ? FromPairsTuple<Last, Head> : Entries extends IterableContainer<Entry> ? FromPairsArray<Entries> : 'ERROR: Entries array-like could not be infered';
2700
- type FromPairsTuple<E, Rest> = E extends Entry ? Record<E[0], E[1]> & StrictOut<Rest> : 'ERROR: Array-like contains a non-entry element';
2701
- type FromPairsArray<Entries extends IterableContainer<Entry>> = string extends AllKeys$1<Entries> ? Record<string, Entries[number][1]> : number extends AllKeys$1<Entries> ? Record<number, Entries[number][1]> : symbol extends AllKeys$1<Entries> ? Record<symbol, Entries[number][1]> : FromPairsArrayWithLiteralKeys<Entries>;
2702
- type FromPairsArrayWithLiteralKeys<Entries extends IterableContainer<Entry>> = {
2703
- [K in AllKeys$1<Entries>]?: ValueForKey<Entries, K>;
2704
- };
2705
- type AllKeys$1<Entries extends IterableContainer<Entry>> = Extract<Entries[number], Entry>[0];
2706
- type ValueForKey<Entries extends IterableContainer<Entry>, K extends PropertyKey> = (Extract<Entries[number], Entry<K>> extends never ? Entries[number] : Extract<Entries[number], Entry<K>>)[1];
2707
- /**
2708
- * Creates a new object from an array of tuples by pairing up first and second elements as {[key]: value}.
2709
- * If a tuple is not supplied for any element in the array, the element will be ignored
2710
- * If duplicate keys exist, the tuple with the greatest index in the input array will be preferred.
2711
- *
2712
- * The strict option supports more sophisticated use-cases like those that would
2713
- * result when calling the strict `toPairs` function.
2714
- * @param pairs the list of input tuples
2715
- * @signature
2716
- * P.fromPairs(tuples)
2717
- * P.fromPairs.strict(tuples)
2718
- * @example
2719
- * P.fromPairs([['a', 'b'], ['c', 'd']]) // => {a: 'b', c: 'd'} (type: Record<string, string>)
2720
- * P.fromPairs.strict(['a', 1] as const) // => {a: 1} (type: {a: 1})
2721
- * @category Object
2722
- * @strict
2723
- */
2724
- declare function fromPairs<V>(pairs: ReadonlyArray<Entry<number, V>>): Record<number, V>;
2725
- declare function fromPairs<V>(pairs: ReadonlyArray<Entry<string, V>>): Record<string, V>;
2726
- declare namespace fromPairs {
2727
- const strict: Strict$1;
2728
- }
2729
-
2730
- type Inverted<T extends object> = T[keyof T] extends PropertyKey ? Record<T[keyof T], keyof T> : never;
2731
- /**
2732
- * Returns an object whose keys are values are swapped. If the object contains duplicate values,
2733
- * subsequent values will overwrite previous values.
2734
- * @param object the object
2735
- * @signature
2736
- * P.invert(object)
2737
- * @example
2738
- * P.invert({ a: "d", b: "e", c: "f" }) // => { d: "a", e: "b", f: "c" }
2739
- * @dataFirst
2740
- * @category Object
2741
- * @pipeable
2742
- */
2743
- declare function invert<T extends object>(object: T): Inverted<T>;
2744
- /**
2745
- * Returns an object whose keys are values are swapped. If the object contains duplicate values,
2746
- * subsequent values will overwrite previous values.
2747
- * @signature
2748
- * P.invert()(object)
2749
- * @example
2750
- * P.pipe({ a: "d", b: "e", c: "f" }, P.invert()); // => { d: "a", e: "b", f: "c" }
2751
- * @dataLast
2752
- * @category Object
2753
- * @pipeable
2754
- */
2755
- declare function invert<T extends object>(): (object: T) => Inverted<T>;
2756
-
2757
- /**
2758
- * Returns a new array containing the keys of the array or object.
2759
- * @param source Either an array or an object
2760
- * @signature
2761
- * P.keys(source)
2762
- * P.keys.strict(source)
2763
- * @example
2764
- * P.keys(['x', 'y', 'z']) // => ['0', '1', '2']
2765
- * P.keys({ a: 'x', b: 'y', c: 'z' }) // => ['a', 'b', 'c']
2766
- * P.pipe(
2767
- * { a: 'x', b: 'y', c: 'z' },
2768
- * P.keys,
2769
- * P.first
2770
- * ) // => 'a'
2771
- * P.keys.strict({ a: 'x', b: 'y', 5: 'z' } as const ) // => ['a', 'b', '5'], typed Array<'a' | 'b' | '5'>
2772
- * @pipeable
2773
- * @strict
2774
- * @category Object
2775
- */
2776
-
2777
- type Strict = <T extends object>(source: T) => Keys<T>;
2778
- type Keys<T> = T extends IterableContainer ? ArrayKeys<T> : ObjectKeys$1<T>;
2779
- type ArrayKeys<T extends IterableContainer> = {
2780
- -readonly [Index in keyof T]: Index extends number | string ? `${IsIndexAfterSpread<T, Index> extends true ? number : Index}` : never;
2781
- };
2782
- type IsIndexAfterSpread<T extends IterableContainer, Index extends number | string> = IndicesAfterSpread<T> extends never ? false : Index extends `${IndicesAfterSpread<T>}` ? true : false;
2783
- type IndicesAfterSpread<T extends [] | ReadonlyArray<unknown>, Iterations extends ReadonlyArray<unknown> = []> = T[number] extends never ? never : T extends readonly [unknown, ...infer Tail] ? IndicesAfterSpread<Tail, [unknown, ...Iterations]> : T extends readonly [...infer Head, unknown] ? IndicesAfterSpread<Head, [unknown, ...Iterations]> | Iterations['length'] : Iterations['length'];
2784
- type ObjectKeys$1<T> = T extends Record<PropertyKey, never> ? [] : Array<`${Exclude<keyof T, symbol>}`>;
2785
- declare function keys(source: ArrayLike<unknown> | Record<PropertyKey, unknown>): Array<string>;
2786
- declare namespace keys {
2787
- const strict: Strict;
2788
- }
2789
-
2790
- /**
2791
- * Maps keys of `object` and keeps the same values.
2792
- * @param object the object to map
2793
- * @param fn the mapping function
2794
- * @signature
2795
- * P.mapKeys(object, fn)
2796
- * @example
2797
- * P.mapKeys({a: 1, b: 2}, (key, value) => key + value) // => { a1: 1, b2: 2 }
2798
- * @dataFirst
2799
- * @category Object
2800
- */
2801
- declare function mapKeys<T, S extends keyof any>(object: T, fn: (key: keyof T, value: T[keyof T]) => S): Record<S, T[keyof T]>;
2802
- /**
2803
- * Maps keys of `object` and keeps the same values.
2804
- * @param fn the mapping function
2805
- * @signature
2806
- * P.mapKeys(fn)(object)
2807
- * @example
2808
- * P.pipe({a: 1, b: 2}, P.mapKeys((key, value) => key + value)) // => { a1: 1, b2: 2 }
2809
- * @dataLast
2810
- * @category Object
2811
- */
2812
- declare function mapKeys<T, S extends keyof any>(fn: (key: keyof T, value: T[keyof T]) => S): (object: T) => Record<S, T[keyof T]>;
2813
-
2814
- /**
2815
- * Maps values of `object` and keeps the same keys.
2816
- * @param object the object to map
2817
- * @param fn the mapping function
2818
- * @signature
2819
- * P.mapValues(object, fn)
2820
- * @example
2821
- * P.mapValues({a: 1, b: 2}, (value, key) => value + key) // => {a: '1a', b: '2b'}
2822
- * @dataFirst
2823
- * @category Object
2824
- */
2825
- declare function mapValues<T extends Record<PropertyKey, any>, S>(object: T, fn: (value: T[keyof T], key: keyof T) => S): Record<keyof T, S>;
2826
- /**
2827
- * Maps values of `object` and keeps the same keys.
2828
- * @param fn the mapping function
2829
- * @signature
2830
- * P.mapValues(fn)(object)
2831
- * @example
2832
- * P.pipe({a: 1, b: 2}, P.mapValues((value, key) => value + key)) // => {a: '1a', b: '2b'}
2833
- * @dataLast
2834
- * @category Object
2835
- */
2836
- declare function mapValues<T extends Record<PropertyKey, any>, S>(fn: (value: T[keyof T], key: keyof T) => S): (object: T) => Record<keyof T, S>;
2837
-
2838
- /**
2839
- * Merges two objects. The same as `Object.assign`.
2840
- * `b` object will override properties of `a`.
2841
- * @param a the first object
2842
- * @param b the second object
2843
- * @signature
2844
- * P.merge(a, b)
2845
- * @example
2846
- * P.merge({ x: 1, y: 2 }, { y: 10, z: 2 }) // => { x: 1, y: 10, z: 2 }
2847
- * @dataFirst
2848
- * @category Object
2849
- */
2850
- declare function merge<A, B>(a: A, b: B): A & B;
2851
- /**
2852
- * Merges two objects. The same as `Object.assign`. `b` object will override properties of `a`.
2853
- * @param b the second object
2854
- * @signature
2855
- * P.merge(b)(a)
2856
- * @example
2857
- * P.merge({ y: 10, z: 2 })({ x: 1, y: 2 }) // => { x: 1, y: 10, z: 2 }
2858
- * @dataLast
2859
- * @category Object
2860
- */
2861
- declare function merge<A, B>(b: B): (a: A) => A & B;
2862
-
2863
- /**
2864
- * Merges the `source` object into the `destination` object. The merge is similar to performing `{ ...destination, ... source }` (where disjoint values from each object would be copied as-is, and for any overlapping props the value from `source` would be used); But for *each prop* (`p`), if **both** `destination` and `source` have a **plain-object** as a value, the value would be taken as the result of recursively deepMerging them (`result.p === deepMerge(destination.p, source.p)`).
2865
- *
2866
- * @param destination - The object to merge into. In general, this object would have it's values overridden.
2867
- * @param source - The object to merge from. In general, shared keys would be taken from this object.
2868
- * @returns - The merged object.
2869
- * @signature
2870
- * P.mergeDeep(destination, source)
2871
- * @example
2872
- * P.mergeDeep({ foo: 'bar', x: 1 }, { foo: 'baz', y: 2 }) // => { foo: 'baz', x: 1, y: 2 }
2873
- * @dataFirst
2874
- * @category Object
2875
- */
2876
- declare function mergeDeep<Destination extends Record<string, unknown>, Source extends Record<string, unknown>>(destination: Destination, source: Source): MergeDeep<Destination, Source>;
2877
- /**
2878
- * Merges the `source` object into the `destination` object. The merge is similar to performing `{ ...destination, ... source }` (where disjoint values from each object would be copied as-is, and for any overlapping props the value from `source` would be used); But for *each prop* (`p`), if **both** `destination` and `source` have a **plain-object** as a value, the value would be taken as the result of recursively deepMerging them (`result.p === deepMerge(destination.p, source.p)`).
2879
- *
2880
- * @param source - The object to merge from. In general, shared keys would be taken from this object.
2881
- * @returns - The merged object.
2882
- * @signature
2883
- * P.mergeDeep(source)(destination)
2884
- * @example
2885
- * P.pipe(
2886
- * { foo: 'bar', x: 1 },
2887
- * P.mergeDeep({ foo: 'baz', y: 2 }),
2888
- * ); // => { foo: 'baz', x: 1, y: 2 }
2889
- * @dataLast
2890
- * @category Object
2891
- */
2892
- declare function mergeDeep<Destination extends Record<string, unknown>, Source extends Record<string, unknown>>(source: Source): (target: Destination) => MergeDeep<Destination, Source>;
2893
-
2894
- /**
2895
- * Returns a partial copy of an object omitting the keys specified.
2896
- * @param data the object
2897
- * @param propNames the property names
2898
- * @signature
2899
- * P.omit(obj, names);
2900
- * @example
2901
- * P.omit({ a: 1, b: 2, c: 3, d: 4 }, ['a', 'd']) // => { b: 2, c: 3 }
2902
- * @dataFirst
2903
- * @category Object
2904
- */
2905
- declare function omit<T extends object, K extends keyof T>(data: T, propNames: ReadonlyArray<K>): Omit<T, K>;
2906
- /**
2907
- * Returns a partial copy of an object omitting the keys specified.
2908
- * @param propNames the property names
2909
- * @signature
2910
- * P.omit(propNames)(obj);
2911
- * @example
2912
- * P.pipe({ a: 1, b: 2, c: 3, d: 4 }, P.omit(['a', 'd'])) // => { b: 2, c: 3 }
2913
- * @dataLast
2914
- * @category Object
2915
- */
2916
- declare function omit<T extends object, K extends keyof T>(propNames: ReadonlyArray<K>): (data: T) => Omit<T, K>;
2917
-
2918
- /**
2919
- * Returns a partial copy of an object omitting the keys matching predicate.
2920
- * @param object the target object
2921
- * @param fn the predicate
2922
- * @signature P.omitBy(object, fn)
2923
- * @example
2924
- * P.omitBy({a: 1, b: 2, A: 3, B: 4}, (val, key) => key.toUpperCase() === key) // => {a: 1, b: 2}
2925
- * @dataFirst
2926
- * @category Object
2927
- */
2928
- declare function omitBy<T>(object: T, fn: <K extends keyof T>(value: T[K], key: K) => boolean): T extends Record<keyof T, T[keyof T]> ? T : Partial<T>;
2929
- /**
2930
- * Returns a partial copy of an object omitting the keys matching predicate.
2931
- * @param fn the predicate
2932
- * @signature P.omitBy(fn)(object)
2933
- * @example
2934
- * P.omitBy((val, key) => key.toUpperCase() === key)({a: 1, b: 2, A: 3, B: 4}) // => {a: 1, b: 2}
2935
- * @dataLast
2936
- * @category Object
2937
- */
2938
- declare function omitBy<T>(fn: <K extends keyof T>(value: T[K], key: K) => boolean): (object: T) => T extends Record<keyof T, T[keyof T]> ? T : Partial<T>;
2939
-
2940
- /**
2941
- * Given a union of indexable types `T`, we derive an indexable type
2942
- * containing all of the keys of each variant of `T`. If a key is
2943
- * present in multiple variants of `T`, then the corresponding type in
2944
- * `Pathable<T>` will be the intersection of all types for that key.
2945
- * @example
2946
- * type T1 = Pathable<{a: number} | {a: string; b: boolean}>
2947
- * // {a: number | string; b: boolean}
2948
- *
2949
- * type T2 = Pathable<{a?: {b: string}}
2950
- * // {a: {b: string} | undefined}
2951
- *
2952
- * type T3 = Pathable<{a: string} | number>
2953
- * // {a: string}
2954
- *
2955
- * type T4 = Pathable<{a: number} | {a: string} | {b: boolean}>
2956
- * // {a: number | string; b: boolean}
2957
- *
2958
- * This type lets us answer the questions:
2959
- * - Given some object of type `T`, what keys might this object have?
2960
- * - If this object did happen to have a particular key, what values
2961
- * might that key have?
2962
- */
2963
- type Pathable<T> = {
2964
- [K in AllKeys<T>]: TypesForKey<T, K>;
2965
- };
2966
- type AllKeys<T> = T extends infer I ? keyof I : never;
2967
- type TypesForKey<T, K extends PropertyKey> = T extends infer I ? K extends keyof I ? I[K] : never : never;
2968
- type StrictlyRequired<T> = {
2969
- [K in keyof T]-?: NonNullable<T[K]>;
2970
- };
2971
- /**
2972
- * Given some `A` which is a key of at least one variant of `T`, derive
2973
- * `T[A]` for the cases where `A` is present in `T`, and `T[A]` is not
2974
- * null or undefined.
2975
- */
2976
- type PathValue1<T, A extends keyof Pathable<T>> = StrictlyRequired<Pathable<T>>[A];
2977
- /** All possible options after successfully reaching `T[A]` */
2978
- type Pathable1<T, A extends keyof Pathable<T>> = Pathable<PathValue1<T, A>>;
2979
- /** As `PathValue1`, but for `T[A][B]` */
2980
- type PathValue2<T, A extends keyof Pathable<T>, B extends keyof Pathable1<T, A>> = StrictlyRequired<Pathable1<T, A>>[B];
2981
- /** As `Pathable1`, but for `T[A][B]` */
2982
- type Pathable2<T, A extends keyof Pathable<T>, B extends keyof Pathable1<T, A>> = Pathable<PathValue2<T, A, B>>;
2983
- /** As `PathValue1`, but for `T[A][B][C]` */
2984
- type PathValue3<T, A extends keyof Pathable<T>, B extends keyof Pathable1<T, A>, C extends keyof Pathable2<T, A, B>> = StrictlyRequired<Pathable2<T, A, B>>[C];
2985
- /**
2986
- * Gets the value at `path` of `object`. If the resolved value is `undefined`, the `defaultValue` is returned in its place.
2987
- * @param object the target object
2988
- * @param path the path of the property to get
2989
- * @param defaultValue the default value
2990
- * @signature P.pathOr(object, array, defaultValue)
2991
- * @example
2992
- * P.pathOr({x: 10}, ['y'], 2) // 2
2993
- * P.pathOr({y: 10}, ['y'], 2) // 10
2994
- * @dataFirst
2995
- * @category Object
2996
- */
2997
- declare function pathOr<T, A extends keyof Pathable<T>>(object: T, path: readonly [A], defaultValue: PathValue1<T, A>): PathValue1<T, A>;
2998
- declare function pathOr<T, A extends keyof Pathable<T>, B extends keyof Pathable1<T, A>>(object: T, path: readonly [A, B], defaultValue: PathValue2<T, A, B>): PathValue2<T, A, B>;
2999
- declare function pathOr<T, A extends keyof Pathable<T>, B extends keyof Pathable1<T, A>, C extends keyof Pathable2<T, A, B>>(object: T, path: readonly [A, B, C], defaultValue: PathValue3<T, A, B, C>): PathValue3<T, A, B, C>;
3000
- /**
3001
- * Gets the value at `path` of `object`. If the resolved value is `undefined`, the `defaultValue` is returned in its place.
3002
- * @param path the path of the property to get
3003
- * @param defaultValue the default value
3004
- * @signature P.pathOr(array, defaultValue)(object)
3005
- * @example
3006
- * P.pipe({x: 10}, P.pathOr(['y'], 2)) // 2
3007
- * P.pipe({y: 10}, P.pathOr(['y'], 2)) // 10
3008
- * @dataLast
3009
- * @category Object
3010
- */
3011
- declare function pathOr<T, A extends keyof Pathable<T>>(path: readonly [A], defaultValue: PathValue1<T, A>): (object: T) => PathValue1<T, A>;
3012
- declare function pathOr<T, A extends keyof Pathable<T>, B extends keyof Pathable1<T, A>>(path: readonly [A, B], defaultValue: PathValue2<T, A, B>): (object: T) => PathValue2<T, A, B>;
3013
- declare function pathOr<T, A extends keyof Pathable<T>, B extends keyof Pathable1<T, A>, C extends keyof Pathable2<T, A, B>>(path: readonly [A, B, C], defaultValue: PathValue3<T, A, B, C>): (object: T) => PathValue3<T, A, B, C>;
3014
-
3015
- /**
3016
- * Creates an object composed of the picked `object` properties.
3017
- * @param object the target object
3018
- * @param names the properties names
3019
- * @signature P.pick(object, [prop1, prop2])
3020
- * @example
3021
- * P.pick({ a: 1, b: 2, c: 3, d: 4 }, ['a', 'd']) // => { a: 1, d: 4 }
3022
- * @dataFirst
3023
- * @category Object
3024
- */
3025
- declare function pick<T extends object, K extends keyof T>(object: T, names: ReadonlyArray<K>): Pick<T, K>;
3026
- /**
3027
- * Creates an object composed of the picked `object` properties.
3028
- * @param names the properties names
3029
- * @signature P.pick([prop1, prop2])(object)
3030
- * @example
3031
- * P.pipe({ a: 1, b: 2, c: 3, d: 4 }, P.pick(['a', 'd'])) // => { a: 1, d: 4 }
3032
- * @dataLast
3033
- * @category Object
3034
- */
3035
- declare function pick<T extends object, K extends keyof T>(names: ReadonlyArray<K>): (object: T) => Pick<T, K>;
3036
-
3037
- /**
3038
- * Creates an object composed of the picked `object` properties.
3039
- * @param object the target object
3040
- * @param fn the predicate
3041
- * @signature P.pickBy(object, fn)
3042
- * @example
3043
- * P.pickBy({a: 1, b: 2, A: 3, B: 4}, (val, key) => key.toUpperCase() === key) // => {A: 3, B: 4}
3044
- * @dataFirst
3045
- * @category Object
3046
- */
3047
- declare function pickBy<T>(object: T, fn: <K extends keyof T>(value: T[K], key: K) => boolean): T extends Record<keyof T, T[keyof T]> ? T : Partial<T>;
3048
- /**
3049
- * Creates an object composed of the picked `object` properties.
3050
- * @param fn the predicate
3051
- * @signature P.pickBy(fn)(object)
3052
- * @example
3053
- * P.pickBy((val, key) => key.toUpperCase() === key)({a: 1, b: 2, A: 3, B: 4}) // => {A: 3, B: 4}
3054
- * @dataLast
3055
- * @category Object
3056
- */
3057
- declare function pickBy<T>(fn: <K extends keyof T>(value: T[K], key: K) => boolean): (object: T) => T extends Record<keyof T, T[keyof T]> ? T : Partial<T>;
3058
-
3059
- /**
3060
- * Gets the value of the given property.
3061
- * @param propName the property name
3062
- * @signature P.prop(prop)(object)
3063
- * @example
3064
- * P.pipe({foo: 'bar'}, P.prop('foo')) // => 'bar'
3065
- * @dataLast
3066
- * @category Object
3067
- */
3068
- declare function prop<T, K extends keyof T>(propName: K): ({ [propName]: value }: T) => T[K];
3069
-
3070
- /**
3071
- * Sets the `value` at `prop` of `object`.
3072
- * @param obj the target method
3073
- * @param prop the property name
3074
- * @param value the value to set
3075
- * @signature
3076
- * P.set(obj, prop, value)
3077
- * @example
3078
- * P.set({ a: 1 }, 'a', 2) // => { a: 2 }
3079
- * @dataFirst
3080
- * @category Object
3081
- */
3082
- declare function set<T, K extends keyof T>(obj: T, prop: K, value: T[K]): T;
3083
- /**
3084
- * Sets the `value` at `prop` of `object`.
3085
- * @param prop the property name
3086
- * @param value the value to set
3087
- * @signature
3088
- * P.set(prop, value)(obj)
3089
- * @example
3090
- * P.pipe({ a: 1 }, P.set('a', 2)) // => { a: 2 }
3091
- * @dataLast
3092
- * @category Object
3093
- */
3094
- declare function set<T, K extends keyof T>(prop: K, value: T[K]): (obj: T) => T;
3095
-
3096
- /**
3097
- * Copied from ts-toolbelt
3098
- * https://github.com/millsp/ts-toolbelt/blob/master/sources/Function/Narrow.ts
3099
- */
3100
- /**
3101
- * Similar to [[Cast]] but with a custom fallback `Catch`. If it fails,
3102
- * it will enforce `Catch` instead of `A2`.
3103
- * @param A1 to check against
3104
- * @param A2 to try/test with
3105
- * @param Catch to fallback to if the test failed
3106
- * @returns `A1 | Catch`
3107
- * @example
3108
- * ```ts
3109
- * import {A} from 'ts-toolbelt'
3110
- *
3111
- * type test0 = A.Try<'42', string> // '42'
3112
- * type test1 = A.Try<'42', number> // never
3113
- * type test1 = A.Try<'42', number, 'tried'> // 'tried'
3114
- * ```
3115
- */
3116
- type Try<A1, A2, Catch = never> = A1 extends A2 ? A1 : Catch;
3117
- /**
3118
- * Describes types that can be narrowed
3119
- */
3120
- type Narrowable = bigint | boolean | number | string;
3121
- /**
3122
- * @hidden
3123
- */
3124
- type NarrowRaw<A> = {
3125
- [K in keyof A]: A[K] extends (...args: Array<any>) => any ? A[K] : NarrowRaw<A[K]>;
3126
- } | (A extends [] ? [] : never) | (A extends Narrowable ? A : never);
3127
- /**
3128
- * Prevent type widening on generic function parameters
3129
- * @param A to narrow
3130
- * @returns `A`
3131
- * @example
3132
- * ```ts
3133
- * import {F} from 'ts-toolbelt'
3134
- *
3135
- * declare function foo<A extends any[]>(x: F.Narrow<A>): A;
3136
- * declare function bar<A extends object>(x: F.Narrow<A>): A;
3137
- *
3138
- * const test0 = foo(['e', 2, true, {f: ['g', ['h']]}])
3139
- * // `A` inferred : ['e', 2, true, {f: ['g']}]
3140
- *
3141
- * const test1 = bar({a: 1, b: 'c', d: ['e', 2, true, {f: ['g']}]})
3142
- * // `A` inferred : {a: 1, b: 'c', d: ['e', 2, true, {f: ['g']}]}
3143
- * ```
3144
- */
3145
- type Narrow<A> = Try<A, [], NarrowRaw<A>>;
3146
-
3147
- type Path<Obj, Prefix extends Array<PropertyKey> = []> = Obj extends Primitive ? Prefix : Obj extends Array<infer Item> ? Path<Item, [...Prefix, number]> | Prefix : PathsOfObject<Obj, Prefix> | Prefix;
3148
- type PathsOfObject<Obj, Prefix extends Array<PropertyKey>> = {
3149
- [K in keyof Obj]: Path<Obj[K], [...Prefix, K]>;
3150
- }[keyof Obj];
3151
- type ValueAtPath<Obj, ObjPath extends Array<PropertyKey> = []> = ObjPath extends [] ? Obj : ObjPath extends [infer Head, ...infer Tail] ? Tail extends Array<PropertyKey> ? Head extends keyof Obj ? ValueAtPath<Obj[Head], Tail> : never : never : never;
3152
- type SupportsValueAtPath<Obj, Path extends Array<PropertyKey>, Value> = Value extends ValueAtPath<Obj, Path> ? Obj : never;
3153
- type Primitive = boolean | null | number | string | symbol | undefined;
3154
-
3155
- /**
3156
- * Sets the value at `path` of `object`. `path` can be an array or a path string.
3157
- * @param object the target method
3158
- * @param path the property name
3159
- * @param value the value to set
3160
- * @signature
3161
- * P.setPath(obj, path, value)
3162
- * @example
3163
- * P.setPath({ a: { b: 1 } }, ['a', 'b'], 2) // => { a: { b: 2 } }
3164
- * @dataFirst
3165
- * @category Object
3166
- */
3167
- declare function setPath<T, TPath extends Array<PropertyKey> & Path<T>>(object: T, path: Narrow<TPath>, value: ValueAtPath<T, TPath>): T;
3168
- /**
3169
- * Sets the value at `path` of `object`. `path` can be an array or a path string.
3170
- * @param path the property name
3171
- * @param value the value to set
3172
- * @signature
3173
- * P.setPath(path, value)
3174
- * @example
3175
- * P.pipe({ a: { b: 1 } }, P.setPath(['a', 'b'], 2)) // { a: { b: 2 } }
3176
- * @dataFirst
3177
- * @category Object
3178
- */
3179
- declare function setPath<TPath extends Array<PropertyKey>, Value>(path: Narrow<TPath>, value: Value): <Obj>(object: SupportsValueAtPath<Obj, TPath, Value>) => Obj;
3180
- declare function _setPath(object: any, path: Array<any>, defaultValue: any): any;
3181
-
3182
- type SwappedProps<T, K1 extends keyof T, K2 extends keyof T> = {
3183
- [K in keyof T]: T[K1 extends K ? K2 : K2 extends K ? K1 : K];
3184
- };
3185
- /**
3186
- * Swaps the positions of two properties in an object based on the provided keys.
3187
- *
3188
- * @param data the object to be manipulated
3189
- * @param key1 the first property key
3190
- * @param key2 the second property key
3191
- *
3192
- * @signature
3193
- * swap(data, key1, key2)
3194
- *
3195
- * @returns Returns the manipulated object.
3196
- *
3197
- * @example
3198
- * swap({a: 1, b: 2, c: 3}, 'a', 'b') // => {a: 2, b: 1, c: 3}
3199
- *
3200
- * @category Object
3201
- *
3202
- * @dataFirst
3203
- */
3204
- declare function swapProps<T extends object, K1 extends keyof T, K2 extends keyof T>(data: T, key1: K1, key2: K2): SwappedProps<T, K1, K2>;
3205
- /**
3206
- * Swaps the positions of two properties in an object based on the provided keys.
3207
- *
3208
- * @param key1 the first property key
3209
- * @param key2 the second property key
3210
- *
3211
- * @signature
3212
- * swap(key1, key2)(data)
3213
- *
3214
- * @example
3215
- * swap('a', 'b')({a: 1, b: 2, c: 3}) // => {a: 2, b: 1, c: 3}
3216
- *
3217
- * @returns Returns the manipulated object.
3218
- *
3219
- * @category Object
3220
- *
3221
- * @dataLast
3222
- */
3223
- declare function swapProps<T extends object, K1 extends keyof T, K2 extends keyof T>(key1: K1, key2: K2): (data: T) => SwappedProps<T, K1, K2>;
3224
-
3225
- type ObjectKeys<T extends object> = `${Exclude<keyof T, symbol>}`;
3226
- type ObjectValues<T extends Record<PropertyKey, unknown>> = Required<T>[ObjectKeys<T>];
3227
- type ObjectEntry<T extends Record<PropertyKey, unknown>> = [
3228
- ObjectKeys<T>,
3229
- ObjectValues<T>
3230
- ];
3231
- type ObjectEntries<T extends Record<PropertyKey, unknown>> = Array<ObjectEntry<T>>;
3232
- /**
3233
- * Returns an array of key/values of the enumerable properties of an object.
3234
- * @param object
3235
- * @signature
3236
- * P.toPairs(object)
3237
- * P.toPairs.strict(object)
3238
- * @example
3239
- * P.toPairs({ a: 1, b: 2, c: 3 }) // => [['a', 1], ['b', 2], ['c', 3]]
3240
- * P.toPairs.strict({ a: 1 } as const) // => [['a', 1]] typed Array<['a', 1]>
3241
- * @strict
3242
- * @category Object
3243
- */
3244
- declare function toPairs<T>(object: Record<string, T>): Array<[string, T]>;
3245
- declare namespace toPairs {
3246
- function strict<T extends Record<PropertyKey, unknown>>(object: T): ObjectEntries<T>;
3247
- }
3248
-
3249
- /**
3250
- * Returns a new array containing the values of the array or object.
3251
- * @param source Either an array or an object
3252
- * @signature
3253
- * P.values(source)
3254
- * @example
3255
- * P.values(['x', 'y', 'z']) // => ['x', 'y', 'z']
3256
- * P.values({ a: 'x', b: 'y', c: 'z' }) // => ['x', 'y', 'z']
3257
- * P.pipe(
3258
- * { a: 'x', b: 'y', c: 'z' },
3259
- * P.values,
3260
- * P.first
3261
- * ) // => 'x'
3262
- * @pipeable
3263
- * @category Object
3264
- */
3265
- type Values<T extends object> = T extends [] | ReadonlyArray<unknown> ? Array<T[number]> : Array<T[keyof T]>;
3266
- declare function values<T extends object>(source: T): Values<T>;
3267
-
3268
- type Splitter = '.' | '/' | '_' | '-';
3269
- type LastOfArray<T extends any[]> = T extends [...any, infer R] ? R : never;
3270
- type RemoveLastOfArray<T extends any[]> = T extends [...infer F, any] ? F : never;
3271
- type IsUpper<S extends string> = S extends Uppercase<S> ? true : false;
3272
- type IsLower<S extends string> = S extends Lowercase<S> ? true : false;
3273
- type SameLetterCase<X extends string, Y extends string> = IsUpper<X> extends IsUpper<Y> ? true : IsLower<X> extends IsLower<Y> ? true : false;
3274
- type FirstOfString<S extends string> = S extends `${infer F}${string}` ? F : never;
3275
- type RemoveFirstOfString<S extends string> = S extends `${string}${infer R}` ? R : never;
3276
- type SplitByCase<T, Separator extends string = Splitter, Accumulator extends unknown[] = []> = string extends Separator ? string[] : T extends `${infer F}${infer R}` ? [LastOfArray<Accumulator>] extends [never] ? SplitByCase<R, Separator, [F]> : LastOfArray<Accumulator> extends string ? R extends '' ? SplitByCase<R, Separator, [
3277
- ...RemoveLastOfArray<Accumulator>,
3278
- `${LastOfArray<Accumulator>}${F}`
3279
- ]> : SameLetterCase<F, FirstOfString<R>> extends true ? F extends Separator ? FirstOfString<R> extends Separator ? SplitByCase<R, Separator, [...Accumulator, '']> : IsUpper<FirstOfString<R>> extends true ? SplitByCase<RemoveFirstOfString<R>, Separator, [
3280
- ...Accumulator,
3281
- FirstOfString<R>
3282
- ]> : SplitByCase<R, Separator, [...Accumulator, '']> : SplitByCase<R, Separator, [
3283
- ...RemoveLastOfArray<Accumulator>,
3284
- `${LastOfArray<Accumulator>}${F}`
3285
- ]> : IsLower<F> extends true ? SplitByCase<RemoveFirstOfString<R>, Separator, [
3286
- ...RemoveLastOfArray<Accumulator>,
3287
- `${LastOfArray<Accumulator>}${F}`,
3288
- FirstOfString<R>
3289
- ]> : SplitByCase<R, Separator, [...Accumulator, F]> : never : Accumulator extends [] ? T extends '' ? [] : string[] : Accumulator;
3290
- type CapitalizedWords<T extends readonly string[], Accumulator extends string = ''> = T extends readonly [infer F extends string, ...infer R extends string[]] ? CapitalizedWords<R, `${Accumulator}${Capitalize<F>}`> : Accumulator;
3291
- type JoinLowercaseWords<T extends readonly string[], Joiner extends string, Accumulator extends string = ''> = T extends readonly [infer F extends string, ...infer R extends string[]] ? Accumulator extends '' ? JoinLowercaseWords<R, Joiner, `${Accumulator}${Lowercase<F>}`> : JoinLowercaseWords<R, Joiner, `${Accumulator}${Joiner}${Lowercase<F>}`> : Accumulator;
3292
- type PascalCase<T> = string extends T ? string : string[] extends T ? string : T extends string ? SplitByCase<T> extends readonly string[] ? CapitalizedWords<SplitByCase<T>> : never : T extends readonly string[] ? CapitalizedWords<T> : never;
3293
- type CamelCase<T> = string extends T ? string : string[] extends T ? string : Uncapitalize<PascalCase<T>>;
3294
- type JoinByCase<T, Joiner extends string> = string extends T ? string : string[] extends T ? string : T extends string ? SplitByCase<T> extends readonly string[] ? JoinLowercaseWords<SplitByCase<T>, Joiner> : never : T extends readonly string[] ? JoinLowercaseWords<T, Joiner> : never;
3295
-
3296
- declare function isUppercase(char?: string): boolean | undefined;
3297
- declare function splitByCase<T extends string>(string_: T): SplitByCase<T>;
3298
- declare function splitByCase<T extends string, Separator extends readonly string[]>(string_: T, separators: Separator): SplitByCase<T, Separator[number]>;
3299
- declare function toUpperFirst<S extends string>(string_: S): Capitalize<S>;
3300
- declare function toLowerFirst<S extends string>(string_: S): Uncapitalize<S>;
3301
- declare function toPascalCase(): '';
3302
- declare function toPascalCase<T extends readonly string[] | string>(string_?: T): PascalCase<T>;
3303
- declare function toCamelCase(): '';
3304
- declare function toCamelCase<T extends readonly string[] | string>(string_?: T): CamelCase<T>;
3305
- declare function toKebabCase(): '';
3306
- declare function toKebabCase<T extends readonly string[] | string>(string_?: T): JoinByCase<T, '-'>;
3307
- declare function toKebabCase<T extends readonly string[] | string, Joiner extends string>(string_: T, joiner: Joiner): JoinByCase<T, Joiner>;
3308
- declare function toSnakeCase(): '';
3309
- declare function toSnakeCase<T extends readonly string[] | string>(string_?: T): JoinByCase<T, '_'>;
3310
-
3311
- /**
3312
- * Returns human readable file size.
3313
- * @param bytes the file size in bytes
3314
- * @param base the base (1000 or 1024)
3315
- * @signature
3316
- * P.humanReadableFileSize(bytes, base)
3317
- * @example
3318
- * P.humanReadableFileSize(1000) // => '1.0 kB'
3319
- * P.humanReadableFileSize(2097152, 1024) // => '2.0 Mib'
3320
- * @category String
3321
- */
3322
- declare function humanReadableFileSize(bytes: number, base?: 1000 | 1024): string;
3323
-
3324
- /**
3325
- * Random a non-cryptographic random string from characters a-zA-Z0-9.
3326
- * @param length the length of the random string
3327
- * @signature randomString(length)
3328
- * @example
3329
- * randomString(5) // => aB92J
3330
- * @category String
3331
- */
3332
- declare function randomString(length: number): string;
3333
-
3334
- /**
3335
- * Turn any string into a URL/DOM safe string.
3336
- * @param str the string to slugify
3337
- * @signature
3338
- * P.slugify(str)
3339
- * @example
3340
- * P.slugify('FooBar') // => 'foobar'
3341
- * P.slugify('This!-is*&%#@^up!') // => 'this-is-up'
3342
- * @category String
3343
- */
3344
- declare function slugify(str: string): string;
3345
-
3346
- /**
3347
- * Converts a path string to an array of keys.
3348
- * @param path a string path
3349
- * @signature P.stringToPathArray(path)
3350
- * @example P.stringToPathArray('a.b[0].c') // => ['a', 'b', 0, 'c']
3351
- * @dataFirst
3352
- * @category String
3353
- */
3354
- declare function stringToPath<Path extends string>(path: Path): StringToPath<Path>;
3355
- type StringToPath<T extends string> = T extends '' ? [] : T extends `[${infer Head}].${infer Tail}` ? [Head, ...StringToPath<Tail>] : T extends `.${infer Head}${infer Tail}` ? [Head, ...StringToPath<Tail>] : T extends `${infer Head}${infer Tail}` ? [Head, ...StringToPath<Tail>] : [T];
3356
-
3357
- /**
3358
- * Gives a single-word string description of the (native) type of a value, returning such answers as 'Object', 'Number', 'Array', or 'Null'. Does not attempt to distinguish user Object types any further, reporting them all as 'Object'.
3359
- * @param val
3360
- * @signature
3361
- * P.type(obj)
3362
- * @example
3363
- * P.type({}); //=> "Object"
3364
- * P.type(1); //=> "Number"
3365
- * P.type(false); //=> "Boolean"
3366
- * P.type('s'); //=> "String"
3367
- * P.type(null); //=> "Null"
3368
- * P.type([]); //=> "Array"
3369
- * P.type(/[A-z]/); //=> "RegExp"
3370
- * P.type(() => {}); //=> "Function"
3371
- * P.type(undefined); //=> "Undefined"
3372
- * @category Type
3373
- */
3374
- declare function type(val: any): string;
3375
-
3376
- declare const isBrowser: boolean;
3377
-
3378
- export { type Joined, KEY_CODES, type StringToPath, _setPath, addProp, allPass, anyPass, chunk, clamp, clone, compact, concat, countBy, createPipe, debounce, difference, differenceWith, drop, dropLast, equals, filter, find, findIndex, findLast, findLastIndex, first, flatMap, flatMapToObj, flatten, flattenDeep, forEach, forEachObj, fromPairs, groupBy, humanReadableFileSize, identity, indexBy, intersection, intersectionWith, invert, isArray, isBoolean, isBrowser, isDate, isDefined, isEmpty, isError, isFunction, isNil, isNonNull, isNot, isNumber, isObject, isPromise, isString, isTruthy, isUppercase, join, keys, last, length, map, mapKeys, mapToObj, mapValues, maxBy, meanBy, merge, mergeAll, mergeDeep, minBy, noop, omit, omitBy, once, partition, pathOr, pick, pickBy, pipe, prop, purry, randomString, range, reduce, reject, reverse, sample, set, setPath, shuffle, sleep, slugify, sort, sortBy, splitAt, splitByCase, splitWhen, stringToPath, sumBy, swapIndices, swapProps, take, takeWhile, toCamelCase, toKebabCase, toLowerFirst, toPairs, toPascalCase, toSnakeCase, toUpperFirst, type, uniq, uniqBy, uniqWith, values, zip, zipObj, zipWith };