ts-data-forge 14.6.1 → 14.6.2

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 (393) hide show
  1. package/dist/array/impl/array-utils-creation.mjs +126 -26
  2. package/dist/array/impl/array-utils-creation.mjs.map +1 -1
  3. package/dist/array/impl/array-utils-element-access.mjs +63 -30
  4. package/dist/array/impl/array-utils-element-access.mjs.map +1 -1
  5. package/dist/array/impl/array-utils-iterators.mjs +69 -53
  6. package/dist/array/impl/array-utils-iterators.mjs.map +1 -1
  7. package/dist/array/impl/array-utils-length-bounded-array-cast.mjs +109 -73
  8. package/dist/array/impl/array-utils-length-bounded-array-cast.mjs.map +1 -1
  9. package/dist/array/impl/array-utils-length-bounded-array-guard.mjs +71 -33
  10. package/dist/array/impl/array-utils-length-bounded-array-guard.mjs.map +1 -1
  11. package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs +102 -73
  12. package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs.map +1 -1
  13. package/dist/array/impl/array-utils-length-bounded-tuple-guard.mjs +77 -33
  14. package/dist/array/impl/array-utils-length-bounded-tuple-guard.mjs.map +1 -1
  15. package/dist/array/impl/array-utils-modification.mjs +75 -122
  16. package/dist/array/impl/array-utils-modification.mjs.map +1 -1
  17. package/dist/array/impl/array-utils-reducing-value.mjs +100 -150
  18. package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
  19. package/dist/array/impl/array-utils-search.mjs +110 -134
  20. package/dist/array/impl/array-utils-search.mjs.map +1 -1
  21. package/dist/array/impl/array-utils-set-op.mjs +146 -38
  22. package/dist/array/impl/array-utils-set-op.mjs.map +1 -1
  23. package/dist/array/impl/array-utils-size.mjs +10 -8
  24. package/dist/array/impl/array-utils-size.mjs.map +1 -1
  25. package/dist/array/impl/array-utils-slice-clamped.mjs +13 -50
  26. package/dist/array/impl/array-utils-slice-clamped.mjs.map +1 -1
  27. package/dist/array/impl/array-utils-slicing.mjs +94 -78
  28. package/dist/array/impl/array-utils-slicing.mjs.map +1 -1
  29. package/dist/array/impl/array-utils-transformation.mjs +291 -199
  30. package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
  31. package/dist/array/impl/array-utils-validation.mjs +54 -56
  32. package/dist/array/impl/array-utils-validation.mjs.map +1 -1
  33. package/dist/array/impl/index.mjs +17 -17
  34. package/dist/array/impl/index.mjs.map +1 -1
  35. package/dist/array/index.mjs +2 -3
  36. package/dist/array/index.mjs.map +1 -1
  37. package/dist/collections/imap-mapped.mjs +335 -292
  38. package/dist/collections/imap-mapped.mjs.map +1 -1
  39. package/dist/collections/imap.mjs +280 -239
  40. package/dist/collections/imap.mjs.map +1 -1
  41. package/dist/collections/index.mjs +7 -7
  42. package/dist/collections/index.mjs.map +1 -1
  43. package/dist/collections/iset-mapped.mjs +448 -265
  44. package/dist/collections/iset-mapped.mjs.map +1 -1
  45. package/dist/collections/iset.mjs +328 -201
  46. package/dist/collections/iset.mjs.map +1 -1
  47. package/dist/collections/queue.mjs +183 -151
  48. package/dist/collections/queue.mjs.map +1 -1
  49. package/dist/collections/stack.mjs +169 -140
  50. package/dist/collections/stack.mjs.map +1 -1
  51. package/dist/entry-point.mjs +4 -77
  52. package/dist/entry-point.mjs.map +1 -1
  53. package/dist/expect-type.mjs +70 -4
  54. package/dist/expect-type.mjs.map +1 -1
  55. package/dist/functional/async-result/async-result.mjs +2 -3
  56. package/dist/functional/async-result/async-result.mjs.map +1 -1
  57. package/dist/functional/async-result/impl/async-result-flat-map.mjs +19 -21
  58. package/dist/functional/async-result/impl/async-result-flat-map.mjs.map +1 -1
  59. package/dist/functional/async-result/impl/async-result-from-promise.mjs +9 -10
  60. package/dist/functional/async-result/impl/async-result-from-promise.mjs.map +1 -1
  61. package/dist/functional/async-result/impl/async-result-from-throwable.mjs +12 -14
  62. package/dist/functional/async-result/impl/async-result-from-throwable.mjs.map +1 -1
  63. package/dist/functional/async-result/impl/async-result-map-err.mjs +16 -19
  64. package/dist/functional/async-result/impl/async-result-map-err.mjs.map +1 -1
  65. package/dist/functional/async-result/impl/async-result-map.mjs +16 -19
  66. package/dist/functional/async-result/impl/async-result-map.mjs.map +1 -1
  67. package/dist/functional/async-result/impl/async-result-unwrap-or.mjs +36 -9
  68. package/dist/functional/async-result/impl/async-result-unwrap-or.mjs.map +1 -1
  69. package/dist/functional/async-result/impl/index.mjs +8 -7
  70. package/dist/functional/async-result/impl/index.mjs.map +1 -1
  71. package/dist/functional/async-result/impl/types.mjs +2 -2
  72. package/dist/functional/async-result/impl/types.mjs.map +1 -1
  73. package/dist/functional/async-result/index.mjs +2 -3
  74. package/dist/functional/async-result/index.mjs.map +1 -1
  75. package/dist/functional/index.mjs +7 -11
  76. package/dist/functional/index.mjs.map +1 -1
  77. package/dist/functional/match.mjs +27 -13
  78. package/dist/functional/match.mjs.map +1 -1
  79. package/dist/functional/optional/impl/index.mjs +19 -18
  80. package/dist/functional/optional/impl/index.mjs.map +1 -1
  81. package/dist/functional/optional/impl/optional-expect-to-be.mjs +16 -18
  82. package/dist/functional/optional/impl/optional-expect-to-be.mjs.map +1 -1
  83. package/dist/functional/optional/impl/optional-filter.mjs +17 -19
  84. package/dist/functional/optional/impl/optional-filter.mjs.map +1 -1
  85. package/dist/functional/optional/impl/optional-flat-map.mjs +13 -15
  86. package/dist/functional/optional/impl/optional-flat-map.mjs.map +1 -1
  87. package/dist/functional/optional/impl/optional-from-nullable.mjs +26 -5
  88. package/dist/functional/optional/impl/optional-from-nullable.mjs.map +1 -1
  89. package/dist/functional/optional/impl/optional-is-none.mjs +21 -5
  90. package/dist/functional/optional/impl/optional-is-none.mjs.map +1 -1
  91. package/dist/functional/optional/impl/optional-is-optional.mjs +26 -8
  92. package/dist/functional/optional/impl/optional-is-optional.mjs.map +1 -1
  93. package/dist/functional/optional/impl/optional-is-some.mjs +22 -5
  94. package/dist/functional/optional/impl/optional-is-some.mjs.map +1 -1
  95. package/dist/functional/optional/impl/optional-map.mjs +16 -18
  96. package/dist/functional/optional/impl/optional-map.mjs.map +1 -1
  97. package/dist/functional/optional/impl/optional-match.mjs +16 -18
  98. package/dist/functional/optional/impl/optional-match.mjs.map +1 -1
  99. package/dist/functional/optional/impl/optional-none.mjs +18 -5
  100. package/dist/functional/optional/impl/optional-none.mjs.map +1 -1
  101. package/dist/functional/optional/impl/optional-or-else.mjs +13 -15
  102. package/dist/functional/optional/impl/optional-or-else.mjs.map +1 -1
  103. package/dist/functional/optional/impl/optional-some.mjs +23 -7
  104. package/dist/functional/optional/impl/optional-some.mjs.map +1 -1
  105. package/dist/functional/optional/impl/optional-to-nullable.mjs +28 -5
  106. package/dist/functional/optional/impl/optional-to-nullable.mjs.map +1 -1
  107. package/dist/functional/optional/impl/optional-unwrap-or.mjs +12 -14
  108. package/dist/functional/optional/impl/optional-unwrap-or.mjs.map +1 -1
  109. package/dist/functional/optional/impl/optional-unwrap-throw.mjs +34 -9
  110. package/dist/functional/optional/impl/optional-unwrap-throw.mjs.map +1 -1
  111. package/dist/functional/optional/impl/optional-unwrap.mjs +6 -9
  112. package/dist/functional/optional/impl/optional-unwrap.mjs.map +1 -1
  113. package/dist/functional/optional/impl/optional-zip.mjs +36 -5
  114. package/dist/functional/optional/impl/optional-zip.mjs.map +1 -1
  115. package/dist/functional/optional/impl/tag.mjs +4 -5
  116. package/dist/functional/optional/impl/tag.mjs.map +1 -1
  117. package/dist/functional/optional/impl/types.mjs +2 -2
  118. package/dist/functional/optional/impl/types.mjs.map +1 -1
  119. package/dist/functional/optional/index.mjs +2 -3
  120. package/dist/functional/optional/index.mjs.map +1 -1
  121. package/dist/functional/optional/optional.mjs +2 -3
  122. package/dist/functional/optional/optional.mjs.map +1 -1
  123. package/dist/functional/pipe.mjs +42 -14
  124. package/dist/functional/pipe.mjs.map +1 -1
  125. package/dist/functional/result/impl/index.mjs +28 -27
  126. package/dist/functional/result/impl/index.mjs.map +1 -1
  127. package/dist/functional/result/impl/result-err.mjs +29 -7
  128. package/dist/functional/result/impl/result-err.mjs.map +1 -1
  129. package/dist/functional/result/impl/result-expect-to-be.mjs +17 -18
  130. package/dist/functional/result/impl/result-expect-to-be.mjs.map +1 -1
  131. package/dist/functional/result/impl/result-flat-map.mjs +18 -21
  132. package/dist/functional/result/impl/result-flat-map.mjs.map +1 -1
  133. package/dist/functional/result/impl/result-fold.mjs +18 -21
  134. package/dist/functional/result/impl/result-fold.mjs.map +1 -1
  135. package/dist/functional/result/impl/result-from-optional.mjs +17 -20
  136. package/dist/functional/result/impl/result-from-optional.mjs.map +1 -1
  137. package/dist/functional/result/impl/result-from-promise.mjs +37 -8
  138. package/dist/functional/result/impl/result-from-promise.mjs.map +1 -1
  139. package/dist/functional/result/impl/result-from-throwable.mjs +41 -14
  140. package/dist/functional/result/impl/result-from-throwable.mjs.map +1 -1
  141. package/dist/functional/result/impl/result-is-err.mjs +21 -5
  142. package/dist/functional/result/impl/result-is-err.mjs.map +1 -1
  143. package/dist/functional/result/impl/result-is-ok.mjs +21 -5
  144. package/dist/functional/result/impl/result-is-ok.mjs.map +1 -1
  145. package/dist/functional/result/impl/result-is-result.mjs +25 -7
  146. package/dist/functional/result/impl/result-is-result.mjs.map +1 -1
  147. package/dist/functional/result/impl/result-map-err.mjs +18 -21
  148. package/dist/functional/result/impl/result-map-err.mjs.map +1 -1
  149. package/dist/functional/result/impl/result-map.mjs +18 -21
  150. package/dist/functional/result/impl/result-map.mjs.map +1 -1
  151. package/dist/functional/result/impl/result-match.mjs +17 -21
  152. package/dist/functional/result/impl/result-match.mjs.map +1 -1
  153. package/dist/functional/result/impl/result-ok.mjs +29 -7
  154. package/dist/functional/result/impl/result-ok.mjs.map +1 -1
  155. package/dist/functional/result/impl/result-or-else.mjs +14 -15
  156. package/dist/functional/result/impl/result-or-else.mjs.map +1 -1
  157. package/dist/functional/result/impl/result-safe-try.mjs +32 -21
  158. package/dist/functional/result/impl/result-safe-try.mjs.map +1 -1
  159. package/dist/functional/result/impl/result-safe-unwrap.mjs +40 -12
  160. package/dist/functional/result/impl/result-safe-unwrap.mjs.map +1 -1
  161. package/dist/functional/result/impl/result-swap.mjs +23 -8
  162. package/dist/functional/result/impl/result-swap.mjs.map +1 -1
  163. package/dist/functional/result/impl/result-to-optional.mjs +30 -7
  164. package/dist/functional/result/impl/result-to-optional.mjs.map +1 -1
  165. package/dist/functional/result/impl/result-unwrap-err-or.mjs +13 -14
  166. package/dist/functional/result/impl/result-unwrap-err-or.mjs.map +1 -1
  167. package/dist/functional/result/impl/result-unwrap-err-throw.mjs +43 -20
  168. package/dist/functional/result/impl/result-unwrap-err-throw.mjs.map +1 -1
  169. package/dist/functional/result/impl/result-unwrap-err.mjs +33 -8
  170. package/dist/functional/result/impl/result-unwrap-err.mjs.map +1 -1
  171. package/dist/functional/result/impl/result-unwrap-ok-or.mjs +13 -14
  172. package/dist/functional/result/impl/result-unwrap-ok-or.mjs.map +1 -1
  173. package/dist/functional/result/impl/result-unwrap-ok.mjs +6 -9
  174. package/dist/functional/result/impl/result-unwrap-ok.mjs.map +1 -1
  175. package/dist/functional/result/impl/result-unwrap-throw.mjs +38 -11
  176. package/dist/functional/result/impl/result-unwrap-throw.mjs.map +1 -1
  177. package/dist/functional/result/impl/result-zip.mjs +35 -5
  178. package/dist/functional/result/impl/result-zip.mjs.map +1 -1
  179. package/dist/functional/result/impl/tag.mjs +4 -5
  180. package/dist/functional/result/impl/tag.mjs.map +1 -1
  181. package/dist/functional/result/impl/types.mjs +2 -2
  182. package/dist/functional/result/impl/types.mjs.map +1 -1
  183. package/dist/functional/result/index.mjs +2 -3
  184. package/dist/functional/result/index.mjs.map +1 -1
  185. package/dist/functional/result/result.mjs +2 -3
  186. package/dist/functional/result/result.mjs.map +1 -1
  187. package/dist/functional/ternary-result/impl/index.mjs +29 -28
  188. package/dist/functional/ternary-result/impl/index.mjs.map +1 -1
  189. package/dist/functional/ternary-result/impl/tag.mjs +6 -6
  190. package/dist/functional/ternary-result/impl/tag.mjs.map +1 -1
  191. package/dist/functional/ternary-result/impl/ternary-result-err.mjs +17 -7
  192. package/dist/functional/ternary-result/impl/ternary-result-err.mjs.map +1 -1
  193. package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs +15 -18
  194. package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs.map +1 -1
  195. package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs +28 -32
  196. package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs.map +1 -1
  197. package/dist/functional/ternary-result/impl/ternary-result-fold.mjs +24 -26
  198. package/dist/functional/ternary-result/impl/ternary-result-fold.mjs.map +1 -1
  199. package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +21 -8
  200. package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs.map +1 -1
  201. package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +28 -13
  202. package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs.map +1 -1
  203. package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs +19 -5
  204. package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs.map +1 -1
  205. package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs +21 -5
  206. package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs.map +1 -1
  207. package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +28 -8
  208. package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs.map +1 -1
  209. package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs +20 -5
  210. package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs.map +1 -1
  211. package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs +17 -18
  212. package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs.map +1 -1
  213. package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs +20 -23
  214. package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs.map +1 -1
  215. package/dist/functional/ternary-result/impl/ternary-result-map.mjs +24 -26
  216. package/dist/functional/ternary-result/impl/ternary-result-map.mjs.map +1 -1
  217. package/dist/functional/ternary-result/impl/ternary-result-ok.mjs +18 -7
  218. package/dist/functional/ternary-result/impl/ternary-result-ok.mjs.map +1 -1
  219. package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs +11 -14
  220. package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs.map +1 -1
  221. package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs +24 -10
  222. package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs.map +1 -1
  223. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs +11 -14
  224. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs.map +1 -1
  225. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs +30 -19
  226. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs.map +1 -1
  227. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs +20 -8
  228. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs.map +1 -1
  229. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs +11 -14
  230. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs.map +1 -1
  231. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs +7 -9
  232. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs.map +1 -1
  233. package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs +30 -22
  234. package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs.map +1 -1
  235. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs +11 -14
  236. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs.map +1 -1
  237. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs +27 -17
  238. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs.map +1 -1
  239. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs +20 -8
  240. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs.map +1 -1
  241. package/dist/functional/ternary-result/impl/ternary-result-warn.mjs +21 -8
  242. package/dist/functional/ternary-result/impl/ternary-result-warn.mjs.map +1 -1
  243. package/dist/functional/ternary-result/impl/ternary-result-zip.mjs +47 -19
  244. package/dist/functional/ternary-result/impl/ternary-result-zip.mjs.map +1 -1
  245. package/dist/functional/ternary-result/impl/types.mjs +2 -2
  246. package/dist/functional/ternary-result/impl/types.mjs.map +1 -1
  247. package/dist/functional/ternary-result/impl/variant-name.mjs +12 -14
  248. package/dist/functional/ternary-result/impl/variant-name.mjs.map +1 -1
  249. package/dist/functional/ternary-result/index.mjs +2 -3
  250. package/dist/functional/ternary-result/index.mjs.map +1 -1
  251. package/dist/functional/ternary-result/ternary-result.mjs +2 -3
  252. package/dist/functional/ternary-result/ternary-result.mjs.map +1 -1
  253. package/dist/guard/has-key.mjs +43 -4
  254. package/dist/guard/has-key.mjs.map +1 -1
  255. package/dist/guard/index.mjs +8 -8
  256. package/dist/guard/index.mjs.map +1 -1
  257. package/dist/guard/is-non-empty-string.mjs +39 -4
  258. package/dist/guard/is-non-empty-string.mjs.map +1 -1
  259. package/dist/guard/is-non-null-object.mjs +36 -4
  260. package/dist/guard/is-non-null-object.mjs.map +1 -1
  261. package/dist/guard/is-primitive.mjs +46 -15
  262. package/dist/guard/is-primitive.mjs.map +1 -1
  263. package/dist/guard/is-record.mjs +89 -6
  264. package/dist/guard/is-record.mjs.map +1 -1
  265. package/dist/guard/is-type.mjs +404 -19
  266. package/dist/guard/is-type.mjs.map +1 -1
  267. package/dist/guard/key-is-in.mjs +42 -4
  268. package/dist/guard/key-is-in.mjs.map +1 -1
  269. package/dist/index.mjs +12 -65
  270. package/dist/index.mjs.map +1 -1
  271. package/dist/iterator/index.mjs +2 -2
  272. package/dist/iterator/index.mjs.map +1 -1
  273. package/dist/iterator/range.mjs +19 -57
  274. package/dist/iterator/range.mjs.map +1 -1
  275. package/dist/json/index.mjs +2 -2
  276. package/dist/json/index.mjs.map +1 -1
  277. package/dist/json/json.mjs +346 -105
  278. package/dist/json/json.mjs.map +1 -1
  279. package/dist/number/branded-types/finite-number.mjs +148 -137
  280. package/dist/number/branded-types/finite-number.mjs.map +1 -1
  281. package/dist/number/branded-types/index.mjs +33 -33
  282. package/dist/number/branded-types/index.mjs.map +1 -1
  283. package/dist/number/branded-types/int.mjs +245 -209
  284. package/dist/number/branded-types/int.mjs.map +1 -1
  285. package/dist/number/branded-types/int16.mjs +141 -131
  286. package/dist/number/branded-types/int16.mjs.map +1 -1
  287. package/dist/number/branded-types/int32.mjs +141 -131
  288. package/dist/number/branded-types/int32.mjs.map +1 -1
  289. package/dist/number/branded-types/negative-finite-number.mjs +155 -149
  290. package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
  291. package/dist/number/branded-types/negative-int.mjs +125 -110
  292. package/dist/number/branded-types/negative-int.mjs.map +1 -1
  293. package/dist/number/branded-types/negative-safe-int.mjs +126 -115
  294. package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
  295. package/dist/number/branded-types/non-negative-finite-number.mjs +164 -154
  296. package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
  297. package/dist/number/branded-types/non-negative-int16.mjs +137 -125
  298. package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
  299. package/dist/number/branded-types/non-negative-int32.mjs +137 -125
  300. package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
  301. package/dist/number/branded-types/non-positive-finite-number.mjs +143 -139
  302. package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
  303. package/dist/number/branded-types/non-positive-int.mjs +116 -99
  304. package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
  305. package/dist/number/branded-types/non-positive-safe-int.mjs +118 -107
  306. package/dist/number/branded-types/non-positive-safe-int.mjs.map +1 -1
  307. package/dist/number/branded-types/non-zero-finite-number.mjs +144 -129
  308. package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
  309. package/dist/number/branded-types/non-zero-int.mjs +102 -82
  310. package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
  311. package/dist/number/branded-types/non-zero-int16.mjs +118 -105
  312. package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
  313. package/dist/number/branded-types/non-zero-int32.mjs +118 -105
  314. package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
  315. package/dist/number/branded-types/non-zero-safe-int.mjs +122 -108
  316. package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
  317. package/dist/number/branded-types/non-zero-uint16.mjs +118 -104
  318. package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
  319. package/dist/number/branded-types/non-zero-uint32.mjs +118 -104
  320. package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
  321. package/dist/number/branded-types/positive-finite-number.mjs +167 -160
  322. package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
  323. package/dist/number/branded-types/positive-int.mjs +260 -224
  324. package/dist/number/branded-types/positive-int.mjs.map +1 -1
  325. package/dist/number/branded-types/positive-int16.mjs +134 -122
  326. package/dist/number/branded-types/positive-int16.mjs.map +1 -1
  327. package/dist/number/branded-types/positive-int32.mjs +134 -122
  328. package/dist/number/branded-types/positive-int32.mjs.map +1 -1
  329. package/dist/number/branded-types/positive-safe-int.mjs +292 -258
  330. package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
  331. package/dist/number/branded-types/positive-uint16.mjs +134 -122
  332. package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
  333. package/dist/number/branded-types/positive-uint32.mjs +134 -122
  334. package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
  335. package/dist/number/branded-types/safe-int.mjs +284 -255
  336. package/dist/number/branded-types/safe-int.mjs.map +1 -1
  337. package/dist/number/branded-types/safe-uint.mjs +135 -124
  338. package/dist/number/branded-types/safe-uint.mjs.map +1 -1
  339. package/dist/number/branded-types/uint.mjs +248 -211
  340. package/dist/number/branded-types/uint.mjs.map +1 -1
  341. package/dist/number/branded-types/uint16.mjs +132 -121
  342. package/dist/number/branded-types/uint16.mjs.map +1 -1
  343. package/dist/number/branded-types/uint32.mjs +132 -121
  344. package/dist/number/branded-types/uint32.mjs.map +1 -1
  345. package/dist/number/enum/index.mjs +3 -3
  346. package/dist/number/enum/index.mjs.map +1 -1
  347. package/dist/number/enum/int8.mjs +146 -131
  348. package/dist/number/enum/int8.mjs.map +1 -1
  349. package/dist/number/enum/uint8.mjs +133 -119
  350. package/dist/number/enum/uint8.mjs.map +1 -1
  351. package/dist/number/index.mjs +6 -37
  352. package/dist/number/index.mjs.map +1 -1
  353. package/dist/number/num-arithmetic-types.mjs +42 -1
  354. package/dist/number/num-arithmetic-types.mjs.map +1 -1
  355. package/dist/number/num.mjs +541 -83
  356. package/dist/number/num.mjs.map +1 -1
  357. package/dist/number/refined-number-utils.mjs +294 -133
  358. package/dist/number/refined-number-utils.mjs.map +1 -1
  359. package/dist/object/index.mjs +2 -2
  360. package/dist/object/index.mjs.map +1 -1
  361. package/dist/object/object.mjs +355 -202
  362. package/dist/object/object.mjs.map +1 -1
  363. package/dist/others/cast-mutable.mjs +38 -11
  364. package/dist/others/cast-mutable.mjs.map +1 -1
  365. package/dist/others/cast-readonly.mjs +37 -11
  366. package/dist/others/cast-readonly.mjs.map +1 -1
  367. package/dist/others/debounce-function.mjs +22 -11
  368. package/dist/others/debounce-function.mjs.map +1 -1
  369. package/dist/others/fast-deep-equal.mjs +70 -51
  370. package/dist/others/fast-deep-equal.mjs.map +1 -1
  371. package/dist/others/if-then.mjs +32 -5
  372. package/dist/others/if-then.mjs.map +1 -1
  373. package/dist/others/index.mjs +10 -10
  374. package/dist/others/index.mjs.map +1 -1
  375. package/dist/others/map-nullable.mjs +11 -13
  376. package/dist/others/map-nullable.mjs.map +1 -1
  377. package/dist/others/memoize-function.mjs +14 -16
  378. package/dist/others/memoize-function.mjs.map +1 -1
  379. package/dist/others/tuple.mjs +52 -4
  380. package/dist/others/tuple.mjs.map +1 -1
  381. package/dist/others/unknown-to-string.mjs +91 -47
  382. package/dist/others/unknown-to-string.mjs.map +1 -1
  383. package/dist/promise/index.mjs +2 -2
  384. package/dist/promise/index.mjs.map +1 -1
  385. package/dist/promise/promise.mjs +51 -10
  386. package/dist/promise/promise.mjs.map +1 -1
  387. package/dist/string/index.mjs +2 -2
  388. package/dist/string/index.mjs.map +1 -1
  389. package/dist/string/str.mjs +250 -83
  390. package/dist/string/str.mjs.map +1 -1
  391. package/dist/types.mjs +3 -2
  392. package/dist/types.mjs.map +1 -1
  393. package/package.json +5 -6
@@ -1 +1 @@
1
- {"version":3,"file":"array-utils-length-bounded-array-cast.mjs","sources":["../../../src/array/impl/array-utils-length-bounded-array-cast.mts"],"sourcesContent":["import {\n type BoundedLengthArray,\n type FixedLengthArray,\n type MaxLengthArray,\n type MinLengthArray,\n type NonEmptyArray,\n type SupportedLength,\n} from 'ts-type-forge';\nimport {\n isBoundedLengthArray,\n isFixedLengthArray,\n isMaxLengthArray,\n isMinLengthArray,\n} from './array-utils-length-bounded-array-guard.mjs';\n\n/**\n * Casts an array to `FixedLengthArray<Length, E>` after checking that it has\n * exactly `length` elements.\n *\n * Use this instead of writing `xs as unknown as FixedLengthArray<N, E>`: the\n * length is verified at runtime, and the original array type (e.g. tuple\n * types) is preserved via intersection, so the result also benefits from the\n * structural tuple prefix (in-range indexed access without `undefined` under\n * `noUncheckedIndexedAccess`).\n *\n * The length argument comes first, matching the type-parameter order of\n * `FixedLengthArray<Length, Elm>`. Omitting the array returns a function that\n * casts one, which is convenient for `pipe`/`map`.\n *\n * @example\n *\n * ```ts\n * const rgb = Arr.asFixedLengthArray(3, [255, 128, 0]);\n *\n * const atMost5: MaxLengthArray<5, number> = rgb; // OK (3 <= 5)\n * const red: number = rgb[0]; // OK — no `undefined`\n *\n * // curried version\n * const asRgb = Arr.asFixedLengthArray(3);\n * const green = asRgb([0, 255, 0]);\n *\n * // Arr.asFixedLengthArray(3, [255, 128]); // throws TypeError\n * ```\n *\n * @template Length - The exact number of elements.\n * @template Xs - The input array type (tuple types are preserved).\n * @param length - The exact number of elements.\n * @param xs - The array to cast.\n * @returns `xs` typed as `FixedLengthArray<Length, Xs[number]> & Xs`.\n * @throws {TypeError} If `xs.length !== length`.\n */\nexport function asFixedLengthArray<\n Length extends SupportedLength,\n Xs extends readonly unknown[],\n>(length: Length, xs: Xs): FixedLengthArray<Length, Xs[number]> & Xs;\n\n// Curried version\nexport function asFixedLengthArray<Length extends SupportedLength>(\n length: Length,\n): <Xs extends readonly unknown[]>(\n xs: Xs,\n) => FixedLengthArray<Length, Xs[number]> & Xs;\n\nexport function asFixedLengthArray<E>(\n ...args:\n | readonly [length: SupportedLength, xs: readonly E[]]\n | readonly [length: SupportedLength]\n): readonly E[] | ((xs: readonly E[]) => readonly E[]) {\n switch (args.length) {\n case 2:\n return asFixedLengthArrayImpl(...args);\n\n case 1:\n return (xs) => asFixedLengthArrayImpl(args[0], xs);\n }\n}\n\nconst asFixedLengthArrayImpl = <E,>(\n length: SupportedLength,\n xs: readonly E[],\n): readonly E[] => {\n const actualLength = xs.length;\n\n if (!isFixedLengthArray(length, xs)) {\n throw new TypeError(\n `Expected an array of length ${length}, got an array of length ${actualLength}`,\n );\n }\n\n return xs;\n};\n\n/**\n * Casts an array to `MinLengthArray<MinLength, E>` after checking that it has\n * at least `minLength` elements.\n *\n * Use this instead of writing `xs as unknown as MinLengthArray<N, E>`: the\n * length is verified at runtime, and the original array type (e.g. tuple\n * types) is preserved via intersection, so the result also benefits from the\n * structural tuple prefix (indexed access below `min(N, 10)` without\n * `undefined` under `noUncheckedIndexedAccess`).\n *\n * The length argument comes first, matching the type-parameter order of\n * `MinLengthArray<MinLength, Elm>`. Omitting the array returns a function that\n * casts one, which is convenient for `pipe`/`map`.\n *\n * @example\n *\n * ```ts\n * const history = Arr.asMinLengthArray(3, [0, 1, 2, 3]);\n *\n * const nonEmpty: MinLengthArray<1, number> = history; // OK (3 >= 1)\n * const first: number = history[0]; // OK — no `undefined`\n *\n * // curried version\n * const asHistory = Arr.asMinLengthArray(3);\n * const next = asHistory([4, 5, 6, 7]);\n *\n * // Arr.asMinLengthArray(3, [0]); // throws TypeError\n * ```\n *\n * @template MinLength - The minimum number of elements (inclusive).\n * @template Xs - The input array type (tuple types are preserved).\n * @param minLength - The minimum number of elements (inclusive).\n * @param xs - The array to cast.\n * @returns `xs` typed as `MinLengthArray<MinLength, Xs[number]> & Xs`.\n * @throws {TypeError} If `xs.length < minLength`.\n */\nexport function asMinLengthArray<\n MinLength extends SupportedLength,\n Xs extends readonly unknown[],\n>(minLength: MinLength, xs: Xs): MinLengthArray<MinLength, Xs[number]> & Xs;\n\n// Curried version\nexport function asMinLengthArray<MinLength extends SupportedLength>(\n minLength: MinLength,\n): <Xs extends readonly unknown[]>(\n xs: Xs,\n) => MinLengthArray<MinLength, Xs[number]> & Xs;\n\nexport function asMinLengthArray<E>(\n ...args:\n | readonly [minLength: SupportedLength, xs: readonly E[]]\n | readonly [minLength: SupportedLength]\n): readonly E[] | ((xs: readonly E[]) => readonly E[]) {\n switch (args.length) {\n case 2:\n return asMinLengthArrayImpl(...args);\n\n case 1:\n return (xs) => asMinLengthArrayImpl(args[0], xs);\n }\n}\n\nconst asMinLengthArrayImpl = <E,>(\n minLength: SupportedLength,\n xs: readonly E[],\n): readonly E[] => {\n const actualLength = xs.length;\n\n if (!isMinLengthArray(minLength, xs)) {\n throw new TypeError(\n `Expected an array of length >= ${minLength}, got an array of length ${actualLength}`,\n );\n }\n\n return xs;\n};\n\n/**\n * Casts an array to `MaxLengthArray<MaxLength, E>` after checking that it has\n * at most `maxLength` elements.\n *\n * Use this instead of writing `xs as unknown as MaxLengthArray<N, E>`: the\n * length is verified at runtime, and the original array type (e.g. tuple\n * types) is preserved via intersection.\n *\n * The length argument comes first, matching the type-parameter order of\n * `MaxLengthArray<MaxLength, Elm>`. Omitting the array returns a function that\n * casts one, which is convenient for `pipe`/`map`.\n *\n * @example\n *\n * ```ts\n * const tags = Arr.asMaxLengthArray(8, ['a', 'b', 'c']);\n *\n * const relaxed: MaxLengthArray<16, string> = tags; // OK (8 <= 16)\n *\n * // curried version\n * const asTags = Arr.asMaxLengthArray(8);\n * const more = asTags(['d', 'e']);\n *\n * // Arr.asMaxLengthArray(2, ['a', 'b', 'c']); // throws TypeError\n * ```\n *\n * @template MaxLength - The maximum number of elements (inclusive).\n * @template Xs - The input array type (tuple types are preserved).\n * @param maxLength - The maximum number of elements (inclusive).\n * @param xs - The array to cast.\n * @returns `xs` typed as `MaxLengthArray<MaxLength, Xs[number]> & Xs`.\n * @throws {TypeError} If `xs.length > maxLength`.\n */\nexport function asMaxLengthArray<\n MaxLength extends SupportedLength,\n Xs extends readonly unknown[],\n>(maxLength: MaxLength, xs: Xs): MaxLengthArray<MaxLength, Xs[number]> & Xs;\n\n// Curried version\nexport function asMaxLengthArray<MaxLength extends SupportedLength>(\n maxLength: MaxLength,\n): <Xs extends readonly unknown[]>(\n xs: Xs,\n) => MaxLengthArray<MaxLength, Xs[number]> & Xs;\n\nexport function asMaxLengthArray<E>(\n ...args:\n | readonly [maxLength: SupportedLength, xs: readonly E[]]\n | readonly [maxLength: SupportedLength]\n): readonly E[] | ((xs: readonly E[]) => readonly E[]) {\n switch (args.length) {\n case 2:\n return asMaxLengthArrayImpl(...args);\n\n case 1:\n return (xs) => asMaxLengthArrayImpl(args[0], xs);\n }\n}\n\nconst asMaxLengthArrayImpl = <E,>(\n maxLength: SupportedLength,\n xs: readonly E[],\n): readonly E[] => {\n const actualLength = xs.length;\n\n if (!isMaxLengthArray(maxLength, xs)) {\n throw new TypeError(\n `Expected an array of length <= ${maxLength}, got an array of length ${actualLength}`,\n );\n }\n\n return xs;\n};\n\n/**\n * Casts an array to `BoundedLengthArray<MinLength, MaxLength, E>` after\n * checking that its length is within the inclusive range\n * `[minLength, maxLength]`.\n *\n * Use this instead of writing\n * `xs as unknown as BoundedLengthArray<Min, Max, E>`: the length is verified\n * at runtime, and the original array type (e.g. tuple types) is preserved via\n * intersection.\n *\n * The length arguments come first, matching the type-parameter order of\n * `BoundedLengthArray<MinLength, MaxLength, Elm>`. Omitting the array returns a\n * function that casts one, which is convenient for `pipe`/`map`.\n *\n * @example\n *\n * ```ts\n * const selection = Arr.asBoundedLengthArray(1, 5, [1, 2, 3]);\n *\n * const relaxed: BoundedLengthArray<0, 100, number> = selection; // OK\n *\n * // curried version\n * const asSelection = Arr.asBoundedLengthArray(1, 5);\n * const next = asSelection([4, 5]);\n *\n * // Arr.asBoundedLengthArray(1, 5, []); // throws TypeError\n * ```\n *\n * @template MinLength - The minimum number of elements (inclusive).\n * @template MaxLength - The maximum number of elements (inclusive).\n * @template Xs - The input array type (tuple types are preserved).\n * @param minLength - The minimum number of elements (inclusive).\n * @param maxLength - The maximum number of elements (inclusive).\n * @param xs - The array to cast.\n * @returns `xs` typed as\n * `BoundedLengthArray<MinLength, MaxLength, Xs[number]> & Xs`.\n * @throws {TypeError} If `xs.length < minLength || xs.length > maxLength`.\n */\nexport function asBoundedLengthArray<\n MinLength extends SupportedLength,\n MaxLength extends SupportedLength,\n Xs extends readonly unknown[],\n>(\n minLength: MinLength,\n maxLength: MaxLength,\n xs: Xs,\n): BoundedLengthArray<MinLength, MaxLength, Xs[number]> & Xs;\n\n// Curried version\nexport function asBoundedLengthArray<\n MinLength extends SupportedLength,\n MaxLength extends SupportedLength,\n>(\n minLength: MinLength,\n maxLength: MaxLength,\n): <Xs extends readonly unknown[]>(\n xs: Xs,\n) => BoundedLengthArray<MinLength, MaxLength, Xs[number]> & Xs;\n\nexport function asBoundedLengthArray<E>(\n ...args:\n | readonly [\n minLength: SupportedLength,\n maxLength: SupportedLength,\n xs: readonly E[],\n ]\n | readonly [minLength: SupportedLength, maxLength: SupportedLength]\n): readonly E[] | ((xs: readonly E[]) => readonly E[]) {\n switch (args.length) {\n case 3:\n return asBoundedLengthArrayImpl(...args);\n\n case 2:\n return (xs) => asBoundedLengthArrayImpl(args[0], args[1], xs);\n }\n}\n\nconst asBoundedLengthArrayImpl = <E,>(\n minLength: SupportedLength,\n maxLength: SupportedLength,\n xs: readonly E[],\n): readonly E[] => {\n const actualLength = xs.length;\n\n if (!isBoundedLengthArray(minLength, maxLength, xs)) {\n throw new TypeError(\n `Expected an array of length in [${minLength}, ${maxLength}], got an array of length ${actualLength}`,\n );\n }\n\n return xs;\n};\n\n/**\n * Casts an array to `FixedLengthArray<0, E>` after checking that it is empty.\n *\n * `Arr.isEmpty` narrows to that same type, so this is its cast counterpart —\n * the length-0 specialization of {@link asFixedLengthArray}. Use this instead\n * of writing `xs as unknown as FixedLengthArray<0, E>`: the length is verified\n * at runtime, and the original array type is preserved via intersection.\n *\n * @example\n *\n * ```ts\n * const nothing = Arr.asEmptyArray([]);\n *\n * const atMost5: MaxLengthArray<5, never> = nothing; // OK (0 <= 5)\n *\n * // Arr.asEmptyArray([1]); // throws TypeError\n * ```\n *\n * @template Xs - The input array type (tuple types are preserved).\n * @param xs - The array to cast.\n * @returns `xs` typed as `FixedLengthArray<0, Xs[number]> & Xs`.\n * @throws {TypeError} If `xs` is not empty.\n */\nexport const asEmptyArray = <Xs extends readonly unknown[]>(\n xs: Xs,\n): FixedLengthArray<0, Xs[number]> & Xs => {\n if (!isFixedLengthArray(0, xs)) {\n throw new TypeError(\n `Expected an empty array, got an array of length ${xs.length}`,\n );\n }\n\n return xs;\n};\n\n/**\n * Casts an array to `NonEmptyArray<E>` after checking that it has at least one\n * element.\n *\n * `NonEmptyArray<E>` is an alias of `MinLengthArray<1, E>`, so this is the\n * length-1 specialization of {@link asMinLengthArray}. Use this instead of\n * writing `xs as unknown as NonEmptyArray<E>`: the length is verified at\n * runtime, and the original array type (e.g. tuple types) is preserved via\n * intersection, so the result also benefits from the structural tuple prefix\n * (`xs[0]` without `undefined` under `noUncheckedIndexedAccess`).\n *\n * @example\n *\n * ```ts\n * const history = Arr.asNonEmptyArray([0, 1, 2, 3]);\n *\n * const first: number = history[0]; // OK — no `undefined`\n *\n * // Arr.asNonEmptyArray([]); // throws TypeError\n * ```\n *\n * @template Xs - The input array type (tuple types are preserved).\n * @param xs - The array to cast.\n * @returns `xs` typed as `NonEmptyArray<Xs[number]> & Xs`.\n * @throws {TypeError} If `xs` is empty.\n */\nexport const asNonEmptyArray = <Xs extends readonly unknown[]>(\n xs: Xs,\n): NonEmptyArray<Xs[number]> & Xs => {\n if (!isMinLengthArray(1, xs)) {\n throw new TypeError('Expected a non-empty array, got an empty array');\n }\n\n return xs;\n};\n"],"names":[],"mappings":";;AA+DO,SAAS,sBACX,IAAA,EAGkD;AACrD,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA;AACH,MAAA,OAAO,sBAAA,CAAuB,GAAG,IAAI,CAAA;AAAA,IAEvC,KAAK,CAAA;AACH,MAAA,OAAO,CAAC,EAAA,KAAO,sBAAA,CAAuB,IAAA,CAAK,CAAC,GAAG,EAAE,CAAA;AAAA;AAEvD;AAEA,MAAM,sBAAA,GAAyB,CAC7B,MAAA,EACA,EAAA,KACiB;AACjB,EAAA,MAAM,eAAe,EAAA,CAAG,MAAA;AAExB,EAAA,IAAI,CAAC,kBAAA,CAAmB,MAAA,EAAQ,EAAE,CAAA,EAAG;AACnC,IAAA,MAAM,IAAI,SAAA;AAAA,MACR,CAAA,4BAAA,EAA+B,MAAM,CAAA,yBAAA,EAA4B,YAAY,CAAA;AAAA,KAC/E;AAAA,EACF;AAEA,EAAA,OAAO,EAAA;AACT,CAAA;AAkDO,SAAS,oBACX,IAAA,EAGkD;AACrD,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA;AACH,MAAA,OAAO,oBAAA,CAAqB,GAAG,IAAI,CAAA;AAAA,IAErC,KAAK,CAAA;AACH,MAAA,OAAO,CAAC,EAAA,KAAO,oBAAA,CAAqB,IAAA,CAAK,CAAC,GAAG,EAAE,CAAA;AAAA;AAErD;AAEA,MAAM,oBAAA,GAAuB,CAC3B,SAAA,EACA,EAAA,KACiB;AACjB,EAAA,MAA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MAAA;AAExB,EAAA,IAAI,CAAC,oBAAA,CAAqB,SAAA,EAAW,SAAA,EAAW,EAAE,CAAA,EAAG;AACnD,IAAA,MAAM,IAAI,SAAA;AAAA,MACR,CAAA,gCAAA,EAAmC,SAAS,CAAA,EAAA,EAAK,SAAS,6BAA6B,YAAY,CAAA;AAAA,KACrG;AAAA,EACF;AAEA,EAAA,OAAO,EAAA;AACT,CAAA;AAyBO,MAAM,YAAA,GAAe,CAC1B,EAAA,KACyC;AACzC,EAAA,IAAI,CAAC,kBAAA,CAAmB,CAAA,EAAG,EAAE,CAAA,EAAG;AAC9B,IAAA,MAAM,IAAI,SAAA;AAAA,MACR,CAAA,gDAAA,EAAmD,GAAG,MAAM,CAAA;AAAA,KAC9D;AAAA,EACF;AAEA,EAAA,OAAO,EAAA;AACT;AA4BO,MAAM,eAAA,GAAkB,CAC7B,EAAA,KACmC;AACnC,EAAA,IAAI,CAAC,gBAAA,CAAiB,CAAA,EAAG,EAAE,CAAA,EAAG;AAC5B,IAAA,MAAM,IAAI,UAAU,gDAAgD,CAAA;AAAA,EACtE;AAEA,EAAA,OAAO,EAAA;AACT;;;;"}
1
+ {"version":3,"file":"array-utils-length-bounded-array-cast.mjs","sourceRoot":"","sources":["../../../src/array/impl/array-utils-length-bounded-array-cast.mts"],"names":[],"mappings":"AAQA,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,8CAA8C,CAAC;AAkDtD,MAAM,UAAU,kBAAkB,CAChC,GAAG,IAEmC;IAEtC,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;QACpB,KAAK,CAAC;YACJ,OAAO,sBAAsB,CAAC,GAAG,IAAI,CAAC,CAAC;QAEzC,KAAK,CAAC;YACJ,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACvD,CAAC;AACH,CAAC;AAED,MAAM,s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D,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,EAAM,EAC0B,EAAE;IAClC,IAAI,CAAC,gBAAgB,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,SAAS,CAAC,gDAAgD,CAAC,CAAC;IACxE,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC"}
@@ -1,41 +1,79 @@
1
- function isMinLengthArray(...args) {
2
- switch (args.length) {
3
- case 2:
4
- return hasMinLength(...args);
5
- case 1:
6
- return (xs) => hasMinLength(args[0], xs);
7
- }
1
+ export function isMinLengthArray(...args) {
2
+ switch (args.length) {
3
+ case 2:
4
+ return hasMinLength(...args);
5
+ case 1:
6
+ return (xs) => hasMinLength(args[0], xs);
7
+ }
8
8
  }
9
9
  const hasMinLength = (minLength, xs) => xs.length >= minLength;
10
- function isMaxLengthArray(...args) {
11
- switch (args.length) {
12
- case 2:
13
- return hasMaxLength(...args);
14
- case 1:
15
- return (xs) => hasMaxLength(args[0], xs);
16
- }
10
+ export function isMaxLengthArray(...args) {
11
+ switch (args.length) {
12
+ case 2:
13
+ return hasMaxLength(...args);
14
+ case 1:
15
+ return (xs) => hasMaxLength(args[0], xs);
16
+ }
17
17
  }
18
18
  const hasMaxLength = (maxLength, xs) => xs.length <= maxLength;
19
- function isBoundedLengthArray(...args) {
20
- switch (args.length) {
21
- case 3:
22
- return hasBoundedLength(...args);
23
- case 2:
24
- return (xs) => hasBoundedLength(args[0], args[1], xs);
25
- }
19
+ export function isBoundedLengthArray(...args) {
20
+ switch (args.length) {
21
+ case 3:
22
+ return hasBoundedLength(...args);
23
+ case 2:
24
+ return (xs) => hasBoundedLength(args[0], args[1], xs);
25
+ }
26
26
  }
27
27
  const hasBoundedLength = (minLength, maxLength, xs) => xs.length >= minLength && xs.length <= maxLength;
28
- function isFixedLengthArray(...args) {
29
- switch (args.length) {
30
- case 2:
31
- return hasFixedLength(...args);
32
- case 1:
33
- return (xs) => hasFixedLength(args[0], xs);
34
- }
28
+ export function isFixedLengthArray(...args) {
29
+ switch (args.length) {
30
+ case 2:
31
+ return hasFixedLength(...args);
32
+ case 1:
33
+ return (xs) => hasFixedLength(args[0], xs);
34
+ }
35
35
  }
36
36
  const hasFixedLength = (length, xs) => xs.length === length;
37
- const isEmpty = (array) => array.length === 0;
38
- const isNonEmpty = (array) => array.length > 0;
39
-
40
- export { isBoundedLengthArray, isEmpty, isFixedLengthArray, isMaxLengthArray, isMinLengthArray, isNonEmpty };
41
- //# sourceMappingURL=array-utils-length-bounded-array-guard.mjs.map
37
+ /**
38
+ * Type guard that checks if an array is empty.
39
+ *
40
+ * @example
41
+ *
42
+ * ```ts
43
+ * const emptyNumbers: readonly number[] = [] as const;
44
+ *
45
+ * const words = ['Ada', 'Lovelace'] as const;
46
+ *
47
+ * assert.isTrue(Arr.isEmpty(emptyNumbers));
48
+ *
49
+ * assert.isFalse(Arr.isEmpty(words));
50
+ *
51
+ * if (Arr.isEmpty(emptyNumbers)) {
52
+ * // `isEmpty` narrows to the branded `FixedLengthArray<0, number>`, so the
53
+ * // expected value is annotated with the unbranded type.
54
+ * assert.deepStrictEqual<readonly number[]>(emptyNumbers, []);
55
+ * }
56
+ * ```
57
+ */
58
+ export const isEmpty = (array) => array.length === 0;
59
+ /**
60
+ * Type guard that checks if an array is non-empty.
61
+ *
62
+ * @example
63
+ *
64
+ * ```ts
65
+ * const users: readonly Readonly<{ id: number }>[] = [{ id: 1 }] as const;
66
+ *
67
+ * const emptyUsers: readonly Readonly<{ id: number }>[] = [] as const;
68
+ *
69
+ * assert.isTrue(Arr.isNonEmpty(users));
70
+ *
71
+ * assert.isFalse(Arr.isNonEmpty(emptyUsers));
72
+ *
73
+ * if (Arr.isNonEmpty(users)) {
74
+ * assert.deepStrictEqual(users[0], { id: 1 });
75
+ * }
76
+ * ```
77
+ */
78
+ export const isNonEmpty = (array) => array.length > 0;
79
+ //# sourceMappingURL=array-utils-length-bounded-array-guard.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"array-utils-length-bounded-array-guard.mjs","sources":["../../../src/array/impl/array-utils-length-bounded-array-guard.mts"],"sourcesContent":["import {\n type BoundedLengthArray,\n type FixedLengthArray,\n type MaxLengthArray,\n type MinLengthArray,\n type SupportedLength,\n} from 'ts-type-forge';\n\n/**\n * Type guard that checks if an array has at least `minLength` elements.\n *\n * **Type Narrowing Behavior:**\n *\n * - Narrows the input to `MinLengthArray<MinLength, E>` while preserving the\n * original array type (e.g. tuple types) via intersection.\n * - The length constraint lives only in the brand, so this stays cheap for the\n * type checker even when the element type is large — unlike\n * `isMinLengthTuple`, which narrows to a structural tuple type.\n * - The result participates in the length-constraint subtyping relation: for\n * example, a value narrowed to `MinLengthArray<3, E>` is assignable to\n * `MinLengthArray<1, E>`.\n *\n * The length argument comes first, matching the type-parameter order of\n * `MinLengthArray<MinLength, Elm>`. Omitting the array returns a reusable type\n * guard, which is convenient for `filter`/`pipe`.\n *\n * @example\n *\n * ```ts\n * const input: readonly number[] = [0, 1, 2, 3] as const;\n *\n * assert.isTrue(Arr.isMinLengthArray(3, input));\n *\n * assert.isFalse(Arr.isMinLengthArray(3, [0]));\n *\n * if (Arr.isMinLengthArray(3, input)) {\n * const history: MinLengthArray<3, number> = input;\n *\n * const nonEmpty: MinLengthArray<1, number> = input; // OK (3 >= 1)\n *\n * assert.deepStrictEqual(history[0], 0);\n *\n * assert.deepStrictEqual(nonEmpty[0], 0);\n * }\n *\n * // curried version\n * const hasThree = Arr.isMinLengthArray(3);\n *\n * assert.isTrue(hasThree(input));\n * ```\n *\n * @template MinLength - The minimum number of elements (inclusive).\n * @template Xs - The input array type (tuple types are preserved).\n * @param minLength - The minimum number of elements (inclusive).\n * @param xs - The array to check.\n * @returns `true` if `xs.length >= minLength`, `false` otherwise. When `true`,\n * TypeScript narrows `xs` to `MinLengthArray<MinLength, Xs[number]> & Xs`.\n */\nexport function isMinLengthArray<\n MinLength extends SupportedLength,\n Xs extends readonly unknown[],\n>(\n minLength: MinLength,\n xs: Xs,\n): xs is MinLengthArray<MinLength, Xs[number]> & Xs;\n\n// Curried version\nexport function isMinLengthArray<MinLength extends SupportedLength>(\n minLength: MinLength,\n): <Xs extends readonly unknown[]>(\n xs: Xs,\n) => xs is MinLengthArray<MinLength, Xs[number]> & Xs;\n\nexport function isMinLengthArray(\n ...args:\n | readonly [minLength: SupportedLength, xs: readonly unknown[]]\n | readonly [minLength: SupportedLength]\n): boolean | ((xs: readonly unknown[]) => boolean) {\n switch (args.length) {\n case 2:\n return hasMinLength(...args);\n\n case 1:\n return (xs) => hasMinLength(args[0], xs);\n }\n}\n\nconst hasMinLength = (\n minLength: SupportedLength,\n xs: readonly unknown[],\n): boolean => xs.length >= minLength;\n\n/**\n * Type guard that checks if an array has at most `maxLength` elements.\n *\n * **Type Narrowing Behavior:**\n *\n * - Narrows the input to `MaxLengthArray<MaxLength, E>` while preserving the\n * original array type (e.g. tuple types) via intersection.\n * - The length constraint lives only in the brand, so this stays cheap for the\n * type checker even when the element type is large — unlike\n * `isMaxLengthTuple`, which narrows to a union of tuple types.\n * - The result participates in the length-constraint subtyping relation: for\n * example, a value narrowed to `MaxLengthArray<8, E>` is assignable to\n * `MaxLengthArray<16, E>`.\n *\n * The length argument comes first, matching the type-parameter order of\n * `MaxLengthArray<MaxLength, Elm>`. Omitting the array returns a reusable type\n * guard, which is convenient for `filter`/`pipe`.\n *\n * @example\n *\n * ```ts\n * const input: readonly string[] = ['a', 'b', 'c'] as const;\n *\n * assert.isTrue(Arr.isMaxLengthArray(8, input));\n *\n * assert.isFalse(Arr.isMaxLengthArray(2, input));\n *\n * if (Arr.isMaxLengthArray(8, input)) {\n * const tags: MaxLengthArray<8, string> = input;\n *\n * const relaxed: MaxLengthArray<16, string> = input; // OK (8 <= 16)\n *\n * assert.deepStrictEqual(tags.length, 3);\n *\n * assert.deepStrictEqual(relaxed.length, 3);\n * }\n *\n * // curried version\n * const fitsInEight = Arr.isMaxLengthArray(8);\n *\n * assert.isTrue(fitsInEight(input));\n * ```\n *\n * @template MaxLength - The maximum number of elements (inclusive).\n * @template Xs - The input array type (tuple types are preserved).\n * @param maxLength - The maximum number of elements (inclusive).\n * @param xs - The array to check.\n * @returns `true` if `xs.length <= maxLength`, `false` otherwise. When `true`,\n * TypeScript narrows `xs` to `MaxLengthArray<MaxLength, Xs[number]> & Xs`.\n */\nexport function isMaxLengthArray<\n MaxLength extends SupportedLength,\n Xs extends readonly unknown[],\n>(\n maxLength: MaxLength,\n xs: Xs,\n): xs is MaxLengthArray<MaxLength, Xs[number]> & Xs;\n\n// Curried version\nexport function isMaxLengthArray<MaxLength extends SupportedLength>(\n maxLength: MaxLength,\n): <Xs extends readonly unknown[]>(\n xs: Xs,\n) => xs is MaxLengthArray<MaxLength, Xs[number]> & Xs;\n\nexport function isMaxLengthArray(\n ...args:\n | readonly [maxLength: SupportedLength, xs: readonly unknown[]]\n | readonly [maxLength: SupportedLength]\n): boolean | ((xs: readonly unknown[]) => boolean) {\n switch (args.length) {\n case 2:\n return hasMaxLength(...args);\n\n case 1:\n return (xs) => hasMaxLength(args[0], xs);\n }\n}\n\nconst hasMaxLength = (\n maxLength: SupportedLength,\n xs: readonly unknown[],\n): boolean => xs.length <= maxLength;\n\n/**\n * Type guard that checks if an array's length is within the inclusive range\n * `[minLength, maxLength]`.\n *\n * **Type Narrowing Behavior:**\n *\n * - Narrows the input to `BoundedLengthArray<MinLength, MaxLength, E>` while\n * preserving the original array type (e.g. tuple types) via intersection.\n * - Since `BoundedLengthArray` is the intersection of `MinLengthArray` and\n * `MaxLengthArray`, the narrowed value is assignable to both, and both\n * bounds can be weakened independently.\n * - The length constraint lives only in the brand, so this stays cheap for the\n * type checker even when the element type is large — unlike\n * `isBoundedLengthTuple`, which narrows to a union of tuple types.\n *\n * The length arguments come first, matching the type-parameter order of\n * `BoundedLengthArray<MinLength, MaxLength, Elm>`. Omitting the array returns a\n * reusable type guard, which is convenient for `filter`/`pipe`.\n *\n * @example\n *\n * ```ts\n * const input: readonly number[] = [1, 2, 3] as const;\n *\n * assert.isTrue(Arr.isBoundedLengthArray(1, 5, input));\n *\n * assert.isFalse(Arr.isBoundedLengthArray(1, 5, []));\n *\n * if (Arr.isBoundedLengthArray(1, 5, input)) {\n * const selection: BoundedLengthArray<1, 5, number> = input;\n *\n * const relaxed: BoundedLengthArray<0, 100, number> = input; // OK ([1, 5] ⊆ [0, 100])\n *\n * assert.deepStrictEqual(selection[0], 1);\n *\n * assert.deepStrictEqual(relaxed.length, 3);\n * }\n *\n * // curried version\n * const isSmallSelection = Arr.isBoundedLengthArray(1, 5);\n *\n * assert.isTrue(isSmallSelection(input));\n * ```\n *\n * @template MinLength - The minimum number of elements (inclusive).\n * @template MaxLength - The maximum number of elements (inclusive).\n * @template Xs - The input array type (tuple types are preserved).\n * @param minLength - The minimum number of elements (inclusive).\n * @param maxLength - The maximum number of elements (inclusive).\n * @param xs - The array to check.\n * @returns `true` if `minLength <= xs.length && xs.length <= maxLength`,\n * `false` otherwise. When `true`, TypeScript narrows `xs` to\n * `BoundedLengthArray<MinLength, MaxLength, Xs[number]> & Xs`.\n */\nexport function isBoundedLengthArray<\n MinLength extends SupportedLength,\n MaxLength extends SupportedLength,\n Xs extends readonly unknown[],\n>(\n minLength: MinLength,\n maxLength: MaxLength,\n xs: Xs,\n): xs is BoundedLengthArray<MinLength, MaxLength, Xs[number]> & Xs;\n\n// Curried version\nexport function isBoundedLengthArray<\n MinLength extends SupportedLength,\n MaxLength extends SupportedLength,\n>(\n minLength: MinLength,\n maxLength: MaxLength,\n): <Xs extends readonly unknown[]>(\n xs: Xs,\n) => xs is BoundedLengthArray<MinLength, MaxLength, Xs[number]> & Xs;\n\nexport function isBoundedLengthArray(\n ...args:\n | readonly [\n minLength: SupportedLength,\n maxLength: SupportedLength,\n xs: readonly unknown[],\n ]\n | readonly [minLength: SupportedLength, maxLength: SupportedLength]\n): boolean | ((xs: readonly unknown[]) => boolean) {\n switch (args.length) {\n case 3:\n return hasBoundedLength(...args);\n\n case 2:\n return (xs) => hasBoundedLength(args[0], args[1], xs);\n }\n}\n\nconst hasBoundedLength = (\n minLength: SupportedLength,\n maxLength: SupportedLength,\n xs: readonly unknown[],\n): boolean => xs.length >= minLength && xs.length <= maxLength;\n\n/**\n * Type guard that checks if an array has exactly `length` elements.\n *\n * **Type Narrowing Behavior:**\n *\n * - Narrows the input to `FixedLengthArray<Length, E>` while preserving the\n * original array type (e.g. tuple types) via intersection.\n * - Since `FixedLengthArray<Length, E>` is defined as\n * `BoundedLengthArray<Length, Length, E>`, the narrowed value is assignable\n * to any `MinLengthArray<N, E>` with `N <= Length` and any\n * `MaxLengthArray<N, E>` with `N >= Length`.\n * - The length constraint lives only in the brand, so this stays cheap for the\n * type checker even when the element type is large — unlike\n * `isFixedLengthTuple`, which narrows to a structural tuple type.\n *\n * The length argument comes first, matching the type-parameter order of\n * `FixedLengthArray<Length, Elm>`. Omitting the array returns a reusable type\n * guard, which is convenient for `filter`/`pipe`.\n *\n * @example\n *\n * ```ts\n * const input: readonly number[] = [255, 128, 0] as const;\n *\n * assert.isTrue(Arr.isFixedLengthArray(3, input));\n *\n * assert.isFalse(Arr.isFixedLengthArray(4, input));\n *\n * if (Arr.isFixedLengthArray(3, input)) {\n * const rgb: FixedLengthArray<3, number> = input;\n *\n * const atMost5: MaxLengthArray<5, number> = input; // OK (3 <= 5)\n *\n * assert.deepStrictEqual(rgb[0], 255);\n *\n * assert.deepStrictEqual(atMost5.length, 3);\n * }\n *\n * // curried version\n * const isRgb = Arr.isFixedLengthArray(3);\n *\n * assert.isTrue(isRgb(input));\n * ```\n *\n * @template Length - The exact number of elements.\n * @template Xs - The input array type (tuple types are preserved).\n * @param length - The exact number of elements.\n * @param xs - The array to check.\n * @returns `true` if `xs.length === length`, `false` otherwise. When `true`,\n * TypeScript narrows `xs` to `FixedLengthArray<Length, Xs[number]> & Xs`.\n */\nexport function isFixedLengthArray<\n Length extends SupportedLength,\n Xs extends readonly unknown[],\n>(length: Length, xs: Xs): xs is FixedLengthArray<Length, Xs[number]> & Xs;\n\n// Curried version\nexport function isFixedLengthArray<Length extends SupportedLength>(\n length: Length,\n): <Xs extends readonly unknown[]>(\n xs: Xs,\n) => xs is FixedLengthArray<Length, Xs[number]> & Xs;\n\nexport function isFixedLengthArray(\n ...args:\n | readonly [length: SupportedLength, xs: readonly unknown[]]\n | readonly [length: SupportedLength]\n): boolean | ((xs: readonly unknown[]) => boolean) {\n switch (args.length) {\n case 2:\n return hasFixedLength(...args);\n\n case 1:\n return (xs) => hasFixedLength(args[0], xs);\n }\n}\n\nconst hasFixedLength = (\n length: SupportedLength,\n xs: readonly unknown[],\n): boolean => xs.length === length;\n\n/**\n * Type guard that checks if an array is empty.\n *\n * @example\n *\n * ```ts\n * const emptyNumbers: readonly number[] = [] as const;\n *\n * const words = ['Ada', 'Lovelace'] as const;\n *\n * assert.isTrue(Arr.isEmpty(emptyNumbers));\n *\n * assert.isFalse(Arr.isEmpty(words));\n *\n * if (Arr.isEmpty(emptyNumbers)) {\n * // `isEmpty` narrows to the branded `FixedLengthArray<0, number>`, so the\n * // expected value is annotated with the unbranded type.\n * assert.deepStrictEqual<readonly number[]>(emptyNumbers, []);\n * }\n * ```\n */\nexport const isEmpty = <Xs extends readonly unknown[]>(\n array: Xs,\n): array is FixedLengthArray<0, Xs[number]> & Xs => array.length === 0;\n\n/**\n * Type guard that checks if an array is non-empty.\n *\n * @example\n *\n * ```ts\n * const users: readonly Readonly<{ id: number }>[] = [{ id: 1 }] as const;\n *\n * const emptyUsers: readonly Readonly<{ id: number }>[] = [] as const;\n *\n * assert.isTrue(Arr.isNonEmpty(users));\n *\n * assert.isFalse(Arr.isNonEmpty(emptyUsers));\n *\n * if (Arr.isNonEmpty(users)) {\n * assert.deepStrictEqual(users[0], { id: 1 });\n * }\n * ```\n */\nexport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AAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA;AACH,MAAA,OAAO,cAAA,CAAe,GAAG,IAAI,CAAA;AAAA,IAE/B,KAAK,CAAA;AACH,MAAA,OAAO,CAAC,EAAA,KAAO,cAAA,CAAe,IAAA,CAAK,CAAC,GAAG,EAAE,CAAA;AAAA;AAE/C;AAEA,MAAM,cAAA,GAAiB,CACrB,MAAA,EACA,EAAA,KACY,GAAG,MAAA,KAAW,MAAA;AAuBrB,MAAM,OAAA,GAAU,CACrB,KAAA,KACkD,KAAA,CAAM,MAAA,KAAW;AAqB9D,MAAM,UAAA,GAAa,CACxB,KAAA,KACgD,KAAA,CAAM,MAAA,GAAS;;;;"}
1
+ {"version":3,"file":"array-utils-length-bounded-array-guard.mjs","sourceRoot":"","sources":["../../../src/array/impl/array-utils-length-bounded-array-guard.mts"],"names":[],"mappings":"AAyEA,MAAM,UAAU,gBAAgB,CAC9B,GAAG,IAEsC;IAEzC,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;QACpB,KAAK,CAAC;YACJ,OAAO,YAAY,CAAC,GAAG,IAAI,CAAC,CAAC;QAE/B,KAAK,CAAC;YACJ,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC;AAED,MAAM,YAAY,GAAG,CACnB,SAA0B,EAC1B,EAAsB,EACb,EAAE,CAAC,EAAE,CAAC,MAAM,IAAI,SAAS,CAAC;AAmErC,MAAM,UAAU,gBAAgB,CAC9B,GAAG,IAEsC;IAEzC,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;QACpB,KAAK,CAAC;YACJ,OAAO,YAAY,CAAC,GAAG,IAAI,CAAC,CAAC;QAE/B,KAAK,CAAC;YACJ,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC7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CACxB,KAAS,EACoC,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC"}
@@ -1,87 +1,116 @@
1
- import { isEmptyTuple, isMinLengthTuple, isBoundedLengthTuple, isFixedLengthTuple, isMaxLengthTuple } from './array-utils-length-bounded-tuple-guard.mjs';
2
-
3
- function asFixedLengthTuple(...args) {
4
- switch (args.length) {
5
- case 2:
6
- return asFixedLengthTupleImpl(...args);
7
- case 1:
8
- return (xs) => asFixedLengthTupleImpl(args[0], xs);
9
- }
1
+ import { isBoundedLengthTuple, isEmptyTuple, isFixedLengthTuple, isMaxLengthTuple, isMinLengthTuple, } from './array-utils-length-bounded-tuple-guard.mjs';
2
+ export function asFixedLengthTuple(...args) {
3
+ switch (args.length) {
4
+ case 2:
5
+ return asFixedLengthTupleImpl(...args);
6
+ case 1:
7
+ return (xs) => asFixedLengthTupleImpl(args[0], xs);
8
+ }
10
9
  }
11
10
  const asFixedLengthTupleImpl = (length, xs) => {
12
- const actualLength = xs.length;
13
- if (!isFixedLengthTuple(length, xs)) {
14
- throw new TypeError(
15
- `Expected an array of length ${length}, got an array of length ${actualLength}`
16
- );
17
- }
18
- return xs;
11
+ const actualLength = xs.length;
12
+ if (!isFixedLengthTuple(length, xs)) {
13
+ throw new TypeError(`Expected an array of length ${length}, got an array of length ${actualLength}`);
14
+ }
15
+ return xs;
19
16
  };
20
- function asMinLengthTuple(...args) {
21
- switch (args.length) {
22
- case 2:
23
- return asMinLengthTupleImpl(...args);
24
- case 1:
25
- return (xs) => asMinLengthTupleImpl(args[0], xs);
26
- }
17
+ export function asMinLengthTuple(...args) {
18
+ switch (args.length) {
19
+ case 2:
20
+ return asMinLengthTupleImpl(...args);
21
+ case 1:
22
+ return (xs) => asMinLengthTupleImpl(args[0], xs);
23
+ }
27
24
  }
28
25
  const asMinLengthTupleImpl = (minLength, xs) => {
29
- const actualLength = xs.length;
30
- if (!isMinLengthTuple(minLength, xs)) {
31
- throw new TypeError(
32
- `Expected an array of length >= ${minLength}, got an array of length ${actualLength}`
33
- );
34
- }
35
- return xs;
26
+ const actualLength = xs.length;
27
+ if (!isMinLengthTuple(minLength, xs)) {
28
+ throw new TypeError(`Expected an array of length >= ${minLength}, got an array of length ${actualLength}`);
29
+ }
30
+ return xs;
36
31
  };
37
- function asMaxLengthTuple(...args) {
38
- switch (args.length) {
39
- case 2:
40
- return asMaxLengthTupleImpl(...args);
41
- case 1:
42
- return (xs) => asMaxLengthTupleImpl(args[0], xs);
43
- }
32
+ export function asMaxLengthTuple(...args) {
33
+ switch (args.length) {
34
+ case 2:
35
+ return asMaxLengthTupleImpl(...args);
36
+ case 1:
37
+ return (xs) => asMaxLengthTupleImpl(args[0], xs);
38
+ }
44
39
  }
45
40
  const asMaxLengthTupleImpl = (maxLength, xs) => {
46
- const actualLength = xs.length;
47
- if (!isMaxLengthTuple(maxLength, xs)) {
48
- throw new TypeError(
49
- `Expected an array of length <= ${maxLength}, got an array of length ${actualLength}`
50
- );
51
- }
52
- return xs;
41
+ const actualLength = xs.length;
42
+ if (!isMaxLengthTuple(maxLength, xs)) {
43
+ throw new TypeError(`Expected an array of length <= ${maxLength}, got an array of length ${actualLength}`);
44
+ }
45
+ return xs;
53
46
  };
54
- function asBoundedLengthTuple(...args) {
55
- switch (args.length) {
56
- case 3:
57
- return asBoundedLengthTupleImpl(...args);
58
- case 2:
59
- return (xs) => asBoundedLengthTupleImpl(...args, xs);
60
- }
47
+ export function asBoundedLengthTuple(...args) {
48
+ switch (args.length) {
49
+ case 3:
50
+ return asBoundedLengthTupleImpl(...args);
51
+ case 2:
52
+ return (xs) => asBoundedLengthTupleImpl(...args, xs);
53
+ }
61
54
  }
62
55
  const asBoundedLengthTupleImpl = (min, max, xs) => {
63
- const actualLength = xs.length;
64
- if (!isBoundedLengthTuple(min, max, xs)) {
65
- throw new TypeError(
66
- `Expected an array of length in [${min}, ${max}], got an array of length ${actualLength}`
67
- );
68
- }
69
- return xs;
56
+ const actualLength = xs.length;
57
+ if (!isBoundedLengthTuple(min, max, xs)) {
58
+ throw new TypeError(`Expected an array of length in [${min}, ${max}], got an array of length ${actualLength}`);
59
+ }
60
+ return xs;
70
61
  };
71
- const asEmptyTuple = (xs) => {
72
- if (!isEmptyTuple(xs)) {
73
- throw new TypeError(
74
- `Expected an empty array, got an array of length ${xs.length}`
75
- );
76
- }
77
- return xs;
62
+ /**
63
+ * Casts an array to the structural empty tuple after checking that it is
64
+ * empty.
65
+ *
66
+ * This is the structural counterpart of `asEmptyArray`, and the length-0
67
+ * specialization of {@link asFixedLengthTuple}.
68
+ *
69
+ * @example
70
+ *
71
+ * ```ts
72
+ * const nothing = Arr.asEmptyTuple([]);
73
+ *
74
+ * // Arr.asEmptyTuple([1]); // throws TypeError
75
+ * ```
76
+ *
77
+ * @template Xs - The input array type (tuple types are preserved).
78
+ * @param xs - The array to cast.
79
+ * @returns `xs` typed as `readonly [] & Xs`.
80
+ * @throws {TypeError} If `xs` is not empty.
81
+ */
82
+ export const asEmptyTuple = (xs) => {
83
+ if (!isEmptyTuple(xs)) {
84
+ throw new TypeError(`Expected an empty array, got an array of length ${xs.length}`);
85
+ }
86
+ return xs;
78
87
  };
79
- const asNonEmptyTuple = (xs) => {
80
- if (!isMinLengthTuple(1, xs)) {
81
- throw new TypeError("Expected a non-empty array, got an empty array");
82
- }
83
- return xs;
88
+ /**
89
+ * Casts an array to `MinLengthTuple<1, E>` after checking that it has at least
90
+ * one element.
91
+ *
92
+ * This is the structural counterpart of `asNonEmptyArray`, and the length-1
93
+ * specialization of {@link asMinLengthTuple}.
94
+ *
95
+ * @example
96
+ *
97
+ * ```ts
98
+ * const values = Arr.asNonEmptyTuple([1, 2, 3]);
99
+ *
100
+ * const first: number = values[0]; // OK — no `undefined`
101
+ *
102
+ * // Arr.asNonEmptyTuple([]); // throws TypeError
103
+ * ```
104
+ *
105
+ * @template Xs - The input array type (tuple types are preserved).
106
+ * @param xs - The array to cast.
107
+ * @returns `xs` typed as `MinLengthTuple<1, Xs[number]> & Xs`.
108
+ * @throws {TypeError} If `xs` is empty.
109
+ */
110
+ export const asNonEmptyTuple = (xs) => {
111
+ if (!isMinLengthTuple(1, xs)) {
112
+ throw new TypeError('Expected a non-empty array, got an empty array');
113
+ }
114
+ return xs;
84
115
  };
85
-
86
- export { asBoundedLengthTuple, asEmptyTuple, asFixedLengthTuple, asMaxLengthTuple, asMinLengthTuple, asNonEmptyTuple };
87
- //# sourceMappingURL=array-utils-length-bounded-tuple-cast.mjs.map
116
+ //# sourceMappingURL=array-utils-length-bounded-tuple-cast.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"array-utils-length-bounded-tuple-cast.mjs","sources":["../../../src/array/impl/array-utils-length-bounded-tuple-cast.mts"],"sourcesContent":["import {\n type BoundedLengthTuple,\n type FixedLengthTuple,\n type MaxLengthTuple,\n type MinLengthTuple,\n} from 'ts-type-forge';\nimport { type SizeType } from '../../types.mjs';\nimport {\n isBoundedLengthTuple,\n isEmptyTuple,\n isFixedLengthTuple,\n isMaxLengthTuple,\n isMinLengthTuple,\n} from './array-utils-length-bounded-tuple-guard.mjs';\n\n/**\n * Casts an array to `FixedLengthTuple<Length, E>` after checking that it has\n * exactly `length` elements.\n *\n * This is the structural counterpart of `asFixedLengthArray`: it produces a\n * tuple type rather than the branded `FixedLengthArray`. Prefer the branded\n * one unless you specifically need the structural type — the brand keeps\n * type-checking cost independent of the element type and of the bound.\n *\n * The length argument comes first, matching the type-parameter order of\n * `FixedLengthTuple<Length, Elm>`. Omitting the array returns a function that\n * casts one.\n *\n * @example\n *\n * ```ts\n * const rgb = Arr.asFixedLengthTuple(3, [255, 128, 0]);\n *\n * const red: number = rgb[0]; // OK — no `undefined`\n *\n * // curried version\n * const asRgb = Arr.asFixedLengthTuple(3);\n *\n * // Arr.asFixedLengthTuple(3, [255, 128]); // throws TypeError\n * ```\n *\n * @template Length - The exact number of elements.\n * @template Xs - The input array type (tuple types are preserved).\n * @param length - The exact number of elements.\n * @param xs - The array to cast.\n * @returns `xs` typed as `FixedLengthTuple<Length, Xs[number]> & Xs`.\n * @throws {TypeError} If `xs.length !== length`.\n */\nexport function asFixedLengthTuple<\n Length extends SizeType.ArgArr,\n Xs extends readonly unknown[],\n>(length: Length, xs: Xs): FixedLengthTuple<Length, Xs[number]> & Xs;\n\n// Curried version\nexport function asFixedLengthTuple<Length extends SizeType.ArgArr>(\n length: Length,\n): <Xs extends readonly unknown[]>(\n xs: Xs,\n) => FixedLengthTuple<Length, Xs[number]> & Xs;\n\nexport function asFixedLengthTuple(\n ...args:\n | readonly [length: SizeType.ArgArr, xs: readonly unknown[]]\n | readonly [length: SizeType.ArgArr]\n): readonly unknown[] | ((xs: readonly unknown[]) => readonly unknown[]) {\n switch (args.length) {\n case 2:\n return asFixedLengthTupleImpl(...args);\n\n case 1:\n return (xs) => asFixedLengthTupleImpl(args[0], xs);\n }\n}\n\nconst asFixedLengthTupleImpl = (\n length: SizeType.ArgArr,\n xs: readonly unknown[],\n): readonly unknown[] => {\n const actualLength = xs.length;\n\n if (!isFixedLengthTuple(length, xs)) {\n throw new TypeError(\n `Expected an array of length ${length}, got an array of length ${actualLength}`,\n );\n }\n\n return xs;\n};\n\n/**\n * Casts an array to `MinLengthTuple<MinLength, E>` after checking that it has\n * at least `minLength` elements.\n *\n * This is the structural counterpart of `asMinLengthArray`; see\n * {@link asFixedLengthTuple} for when to prefer which.\n *\n * @example\n *\n * ```ts\n * const history = Arr.asMinLengthTuple(3, [0, 1, 2, 3]);\n *\n * const first: number = history[0]; // OK — no `undefined`\n *\n * // curried version\n * const asHistory = Arr.asMinLengthTuple(3);\n *\n * // Arr.asMinLengthTuple(3, [0, 1]); // throws TypeError\n * ```\n *\n * @template MinLength - The minimum number of elements (inclusive).\n * @template Xs - The input array type (tuple types are preserved).\n * @param minLength - The minimum number of elements (inclusive).\n * @param xs - The array to cast.\n * @returns `xs` typed as `MinLengthTuple<MinLength, Xs[number]> & Xs`.\n * @throws {TypeError} If `xs.length < minLength`.\n */\nexport function asMinLengthTuple<\n MinLength extends SizeType.ArgArr,\n Xs extends readonly unknown[],\n>(minLength: MinLength, xs: Xs): MinLengthTuple<MinLength, Xs[number]> & Xs;\n\n// Curried version\nexport function asMinLengthTuple<MinLength extends SizeType.ArgArr>(\n minLength: MinLength,\n): <Xs extends readonly unknown[]>(\n xs: Xs,\n) => MinLengthTuple<MinLength, Xs[number]> & Xs;\n\nexport function asMinLengthTuple(\n ...args:\n | readonly [minLength: SizeType.ArgArr, xs: readonly unknown[]]\n | readonly [minLength: SizeType.ArgArr]\n): readonly unknown[] | ((xs: readonly unknown[]) => readonly unknown[]) {\n switch (args.length) {\n case 2:\n return asMinLengthTupleImpl(...args);\n\n case 1:\n return (xs) => asMinLengthTupleImpl(args[0], xs);\n }\n}\n\nconst asMinLengthTupleImpl = (\n minLength: SizeType.ArgArr,\n xs: readonly unknown[],\n): readonly unknown[] => {\n const actualLength = xs.length;\n\n if (!isMinLengthTuple(minLength, xs)) {\n throw new TypeError(\n `Expected an array of length >= ${minLength}, got an array of length ${actualLength}`,\n );\n }\n\n return xs;\n};\n\n/**\n * Casts an array to `MaxLengthTuple<MaxLength, E>` after checking that it has\n * at most `maxLength` elements.\n *\n * This is the structural counterpart of `asMaxLengthArray`; see\n * {@link asFixedLengthTuple} for when to prefer which.\n *\n * @example\n *\n * ```ts\n * const tags = Arr.asMaxLengthTuple(8, ['a', 'b', 'c']);\n *\n * // curried version\n * const asTags = Arr.asMaxLengthTuple(8);\n *\n * // Arr.asMaxLengthTuple(2, ['a', 'b', 'c']); // throws TypeError\n * ```\n *\n * @template MaxLength - The maximum number of elements (inclusive).\n * @template Xs - The input array type (tuple types are preserved).\n * @param maxLength - The maximum number of elements (inclusive).\n * @param xs - The array to cast.\n * @returns `xs` typed as `MaxLengthTuple<MaxLength, Xs[number]> & Xs`.\n * @throws {TypeError} If `xs.length > maxLength`.\n */\nexport function asMaxLengthTuple<\n MaxLength extends SizeType.ArgArr,\n Xs extends readonly unknown[],\n>(maxLength: MaxLength, xs: Xs): MaxLengthTuple<MaxLength, Xs[number]> & Xs;\n\n// Curried version\nexport function asMaxLengthTuple<MaxLength extends SizeType.ArgArr>(\n maxLength: MaxLength,\n): <Xs extends readonly unknown[]>(\n xs: Xs,\n) => MaxLengthTuple<MaxLength, Xs[number]> & Xs;\n\nexport function asMaxLengthTuple(\n ...args:\n | readonly [maxLength: SizeType.ArgArr, xs: readonly unknown[]]\n | readonly [maxLength: SizeType.ArgArr]\n): readonly unknown[] | ((xs: readonly unknown[]) => readonly unknown[]) {\n switch (args.length) {\n case 2:\n return asMaxLengthTupleImpl(...args);\n\n case 1:\n return (xs) => asMaxLengthTupleImpl(args[0], xs);\n }\n}\n\nconst asMaxLengthTupleImpl = (\n maxLength: SizeType.ArgArr,\n xs: readonly unknown[],\n): readonly unknown[] => {\n const actualLength = xs.length;\n\n if (!isMaxLengthTuple(maxLength, xs)) {\n throw new TypeError(\n `Expected an array of length <= ${maxLength}, got an array of length ${actualLength}`,\n );\n }\n\n return xs;\n};\n\n/**\n * Casts an array to `BoundedLengthTuple<Min, Max, E>` after checking that its\n * length is within the inclusive range `[min, max]`.\n *\n * This is the structural counterpart of `asBoundedLengthArray`; see\n * {@link asFixedLengthTuple} for when to prefer which.\n *\n * @example\n *\n * ```ts\n * const selection = Arr.asBoundedLengthTuple(1, 5, [1, 2, 3]);\n *\n * // curried version\n * const asSelection = Arr.asBoundedLengthTuple(1, 5);\n *\n * // Arr.asBoundedLengthTuple(1, 2, [1, 2, 3]); // throws TypeError\n * ```\n *\n * @template Min - The minimum number of elements (inclusive).\n * @template Max - The maximum number of elements (inclusive).\n * @template Xs - The input array type (tuple types are preserved).\n * @param min - The minimum number of elements (inclusive).\n * @param max - The maximum number of elements (inclusive).\n * @param xs - The array to cast.\n * @returns `xs` typed as `BoundedLengthTuple<Min, Max, Xs[number]> & Xs`.\n * @throws {TypeError} If `xs.length` is outside `[min, max]`.\n */\nexport function asBoundedLengthTuple<\n Min extends SizeType.ArgArr,\n Max extends SizeType.ArgArr,\n Xs extends readonly unknown[],\n>(min: Min, max: Max, xs: Xs): BoundedLengthTuple<Min, Max, Xs[number]> & Xs;\n\n// Curried version\nexport function asBoundedLengthTuple<\n Min extends SizeType.ArgArr,\n Max extends SizeType.ArgArr,\n>(\n min: Min,\n max: Max,\n): <Xs extends readonly unknown[]>(\n xs: Xs,\n) => BoundedLengthTuple<Min, Max, Xs[number]> & Xs;\n\nexport function asBoundedLengthTuple(\n ...args:\n | readonly [\n min: SizeType.ArgArr,\n max: SizeType.ArgArr,\n xs: readonly unknown[],\n ]\n | readonly [min: SizeType.ArgArr, max: SizeType.ArgArr]\n): readonly unknown[] | ((xs: readonly unknown[]) => readonly unknown[]) {\n switch (args.length) {\n case 3:\n return asBoundedLengthTupleImpl(...args);\n\n case 2:\n return (xs) => asBoundedLengthTupleImpl(...args, xs);\n }\n}\n\nconst asBoundedLengthTupleImpl = (\n min: SizeType.ArgArr,\n max: SizeType.ArgArr,\n xs: readonly unknown[],\n): readonly unknown[] => {\n const actualLength = xs.length;\n\n if (!isBoundedLengthTuple(min, max, xs)) {\n throw new TypeError(\n `Expected an array of length in [${min}, ${max}], got an array of length ${actualLength}`,\n );\n }\n\n return xs;\n};\n\n/**\n * Casts an array to the structural empty tuple after checking that it is\n * empty.\n *\n * This is the structural counterpart of `asEmptyArray`, and the length-0\n * specialization of {@link asFixedLengthTuple}.\n *\n * @example\n *\n * ```ts\n * const nothing = Arr.asEmptyTuple([]);\n *\n * // Arr.asEmptyTuple([1]); // throws TypeError\n * ```\n *\n * @template Xs - The input array type (tuple types are preserved).\n * @param xs - The array to cast.\n * @returns `xs` typed as `readonly [] & Xs`.\n * @throws {TypeError} If `xs` is not empty.\n */\nexport const asEmptyTuple = <Xs extends readonly unknown[]>(\n xs: Xs,\n): readonly [] & Xs => {\n if (!isEmptyTuple(xs)) {\n throw new TypeError(\n `Expected an empty array, got an array of length ${xs.length}`,\n );\n }\n\n return xs;\n};\n\n/**\n * Casts an array to `MinLengthTuple<1, E>` after checking that it has at least\n * one element.\n *\n * This is the structural counterpart of `asNonEmptyArray`, and the length-1\n * specialization of {@link asMinLengthTuple}.\n *\n * @example\n *\n * ```ts\n * const values = Arr.asNonEmptyTuple([1, 2, 3]);\n *\n * const first: number = values[0]; // OK — no `undefined`\n *\n * // Arr.asNonEmptyTuple([]); // throws TypeError\n * ```\n *\n * @template Xs - The input array type (tuple types are preserved).\n * @param xs - The array to cast.\n * @returns `xs` typed as `MinLengthTuple<1, Xs[number]> & Xs`.\n * @throws {TypeError} If `xs` is empty.\n */\nexport const asNonEmptyTuple = <Xs extends readonly unknown[]>(\n xs: Xs,\n): MinLengthTuple<1, Xs[number]> & Xs => {\n if (!isMinLengthTuple(1, xs)) {\n throw new TypeError('Expected a non-empty array, got an empty array');\n }\n\n return xs;\n};\n"],"names":[],"mappings":";;AA4DO,SAAS,sBACX,IAAA,EAGoE;AACvE,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA;AACH,MAAA,OAAO,sBAAA,CAAuB,GAAG,IAAI,CAAA;AAAA,IAEvC,KAAK,CAAA;AACH,MAAA,OAAO,CAAC,EAAA,KAAO,sBAAA,CAAuB,IAAA,CAAK,CAAC,GAAG,EAAE,CAAA;AAAA;AAEvD;AAEA,MAAM,sBAAA,GAAyB,CAC7B,MAAA,EACA,EAAA,KACuB;AACvB,EAAA,MAAM,eAAe,EAAA,CAAG,MAAA;AAExB,EAAA,IAAI,CAAC,kBAAA,CAAmB,MAAA,EAAQ,EAAE,CAAA,EAAG;AACnC,IAAA,MAAM,IAAI,SAAA;AAAA,MACR,CAAA,4BAAA,EAA+B,MAAM,CAAA,yBAAA,EAA4B,YAAY,CAAA;AAAA,KAC/E;AAAA,EACF;AAEA,EAAA,OAAO,EAAA;AACT,CAAA;AAyCO,SAAS,oBACX,IAAA,EAGoE;AACvE,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA;AACH,MAAA,OAAO,oBAAA,CAAqB,G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C,EAAA,KAAO,wBAAA,CAAyB,GAAG,MAAM,EAAE,CAAA;AAAA;AAEzD;AAEA,MAAM,wBAAA,GAA2B,CAC/B,GAAA,EACA,GAAA,EACA,EAAA,KACuB;AACvB,EAAA,MAAM,eAAe,EAAA,CAAG,MAAA;AAExB,EAAA,IAAI,CAAC,oBAAA,CAAqB,GAAA,EAAK,GAAA,EAAK,EAAE,CAAA,EAAG;AACvC,IAAA,MAAM,IAAI,SAAA;AAAA,MACR,CAAA,gCAAA,EAAmC,GAAG,CAAA,EAAA,EAAK,GAAG,6BAA6B,YAAY,CAAA;AAAA,KACzF;AAAA,EACF;AAEA,EAAA,OAAO,EAAA;AACT,CAAA;AAsBO,MAAM,YAAA,GAAe,CAC1B,EAAA,KACqB;AACrB,EAAA,IAAI,CAAC,YAAA,CAAa,EAAE,CAAA,EAAG;AACrB,IAAA,MAAM,IAAI,SAAA;AAAA,MACR,CAAA,gDAAA,EAAmD,GAAG,MAAM,CAAA;AAAA,KAC9D;AAAA,EACF;AAEA,EAAA,OAAO,EAAA;AACT;AAwBO,MAAM,eAAA,GAAkB,CAC7B,EAAA,KACuC;AACvC,EAAA,IAAI,CAAC,gBAAA,CAAiB,CAAA,EAAG,EAAE,CAAA,EAAG;AAC5B,IAAA,MAAM,IAAI,UAAU,gDAAgD,CAAA;AAAA,EACtE;AAEA,EAAA,OAAO,EAAA;AACT;;;;"}
1
+ {"version":3,"file":"array-utils-length-bounded-tuple-cast.mjs","sourceRoot":"","sources":["../../../src/array/impl/array-utils-length-bounded-tuple-cast.mts"],"names":[],"mappings":"AAOA,OAAO,EACL,oBAAoB,EACpB,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,8CAA8C,CAAC;AA+CtD,MAAM,UAAU,kBAAkB,CAChC,GAAG,IAEmC;IAEtC,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;QACpB,KAAK,CAAC;YACJ,OAAO,sBAAsB,CAAC,GAAG,IAAI,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AAC,YAAY,CAAC,EAAE,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,SAAS,CACjB,mDAAmD,EAAE,CAAC,MAAM,EAAE,CAC/D,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,EAAM,EAC8B,EAAE;IACtC,IAAI,CAAC,gBAAgB,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,SAAS,CAAC,gDAAgD,CAAC,CAAC;IACxE,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC"}
@@ -1,41 +1,85 @@
1
- const isEmptyTuple = (array) => array.length === 0;
2
- const isNonEmptyTuple = (array) => array.length >= 1;
3
- function isFixedLengthTuple(...args) {
4
- switch (args.length) {
5
- case 2:
6
- return hasFixedLength(args[0], args[1]);
7
- case 1:
8
- return (array) => hasFixedLength(args[0], array);
9
- }
1
+ /**
2
+ * Type guard that checks if an array is empty, narrowing it to the structural
3
+ * empty tuple.
4
+ *
5
+ * This is the structural counterpart of `isEmpty`: it narrows to `readonly []`
6
+ * rather than to the branded `FixedLengthArray<0, E>`. Prefer `isEmpty` unless
7
+ * you specifically need the structural type.
8
+ *
9
+ * @example
10
+ *
11
+ * ```ts
12
+ * const values: readonly number[] = [] as const;
13
+ *
14
+ * assert.isTrue(Arr.isEmptyTuple(values));
15
+ *
16
+ * assert.isFalse(Arr.isEmptyTuple([1] as const));
17
+ * ```
18
+ *
19
+ * @template E - The element type.
20
+ * @param array - The array to check.
21
+ * @returns `true` if `array.length === 0`. When `true`, TypeScript narrows
22
+ * `array` to `readonly []`.
23
+ */
24
+ export const isEmptyTuple = (array) => array.length === 0;
25
+ /**
26
+ * Type guard that checks if an array is non-empty, narrowing it to the
27
+ * structural non-empty tuple.
28
+ *
29
+ * This is the structural counterpart of `isNonEmpty`: it narrows to
30
+ * `MinLengthTuple<1, E>` rather than to the branded `MinLengthArray<1, E>`.
31
+ * Prefer `isNonEmpty` unless you specifically need the structural type.
32
+ *
33
+ * @example
34
+ *
35
+ * ```ts
36
+ * const values: readonly number[] = [1, 2] as const;
37
+ *
38
+ * assert.isTrue(Arr.isNonEmptyTuple(values));
39
+ *
40
+ * assert.isFalse(Arr.isNonEmptyTuple([] as const));
41
+ * ```
42
+ *
43
+ * @template E - The element type.
44
+ * @param array - The array to check.
45
+ * @returns `true` if `array.length >= 1`. When `true`, TypeScript narrows
46
+ * `array` to `MinLengthTuple<1, E>`.
47
+ */
48
+ export const isNonEmptyTuple = (array) => array.length >= 1;
49
+ export function isFixedLengthTuple(...args) {
50
+ switch (args.length) {
51
+ case 2:
52
+ return hasFixedLength(args[0], args[1]);
53
+ case 1:
54
+ return (array) => hasFixedLength(args[0], array);
55
+ }
10
56
  }
11
57
  const hasFixedLength = (len, array) => array.length === len;
12
- function isMinLengthTuple(...args) {
13
- switch (args.length) {
14
- case 2:
15
- return hasMinLength(args[0], args[1]);
16
- case 1:
17
- return (array) => hasMinLength(args[0], array);
18
- }
58
+ export function isMinLengthTuple(...args) {
59
+ switch (args.length) {
60
+ case 2:
61
+ return hasMinLength(args[0], args[1]);
62
+ case 1:
63
+ return (array) => hasMinLength(args[0], array);
64
+ }
19
65
  }
20
66
  const hasMinLength = (len, array) => array.length >= len;
21
- function isMaxLengthTuple(...args) {
22
- switch (args.length) {
23
- case 2:
24
- return hasMaxLength(args[0], args[1]);
25
- case 1:
26
- return (array) => hasMaxLength(args[0], array);
27
- }
67
+ export function isMaxLengthTuple(...args) {
68
+ switch (args.length) {
69
+ case 2:
70
+ return hasMaxLength(args[0], args[1]);
71
+ case 1:
72
+ return (array) => hasMaxLength(args[0], array);
73
+ }
28
74
  }
29
75
  const hasMaxLength = (len, array) => array.length <= len;
30
- function isBoundedLengthTuple(...args) {
31
- switch (args.length) {
32
- case 3:
33
- return isWithinBounds(args[0], args[1], args[2]);
34
- case 2:
35
- return (array) => isWithinBounds(args[0], args[1], array);
36
- }
76
+ export function isBoundedLengthTuple(...args) {
77
+ switch (args.length) {
78
+ case 3:
79
+ return isWithinBounds(args[0], args[1], args[2]);
80
+ case 2:
81
+ return (array) => isWithinBounds(args[0], args[1], array);
82
+ }
37
83
  }
38
84
  const isWithinBounds = (min, max, array) => array.length >= min && array.length <= max;
39
-
40
- export { isBoundedLengthTuple, isEmptyTuple, isFixedLengthTuple, isMaxLengthTuple, isMinLengthTuple, isNonEmptyTuple };
41
- //# sourceMappingURL=array-utils-length-bounded-tuple-guard.mjs.map
85
+ //# sourceMappingURL=array-utils-length-bounded-tuple-guard.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"array-utils-length-bounded-tuple-guard.mjs","sources":["../../../src/array/impl/array-utils-length-bounded-tuple-guard.mts"],"sourcesContent":["import {\n type BoundedLengthTuple,\n type FixedLengthTuple,\n type MaxLengthTuple,\n type MinLengthTuple,\n} from 'ts-type-forge';\nimport { type SizeType } from '../../types.mjs';\n\n/**\n * Type guard that checks if an array is empty, narrowing it to the structural\n * empty tuple.\n *\n * This is the structural counterpart of `isEmpty`: it narrows to `readonly []`\n * rather than to the branded `FixedLengthArray<0, E>`. Prefer `isEmpty` unless\n * you specifically need the structural type.\n *\n * @example\n *\n * ```ts\n * const values: readonly number[] = [] as const;\n *\n * assert.isTrue(Arr.isEmptyTuple(values));\n *\n * assert.isFalse(Arr.isEmptyTuple([1] as const));\n * ```\n *\n * @template E - The element type.\n * @param array - The array to check.\n * @returns `true` if `array.length === 0`. When `true`, TypeScript narrows\n * `array` to `readonly []`.\n */\nexport const isEmptyTuple = <E,>(array: readonly E[]): array is readonly [] =>\n array.length === 0;\n\n/**\n * Type guard that checks if an array is non-empty, narrowing it to the\n * structural non-empty tuple.\n *\n * This is the structural counterpart of `isNonEmpty`: it narrows to\n * `MinLengthTuple<1, E>` rather than to the branded `MinLengthArray<1, E>`.\n * Prefer `isNonEmpty` unless you specifically need the structural type.\n *\n * @example\n *\n * ```ts\n * const values: readonly number[] = [1, 2] as const;\n *\n * assert.isTrue(Arr.isNonEmptyTuple(values));\n *\n * assert.isFalse(Arr.isNonEmptyTuple([] as const));\n * ```\n *\n * @template E - The element type.\n * @param array - The array to check.\n * @returns `true` if `array.length >= 1`. When `true`, TypeScript narrows\n * `array` to `MinLengthTuple<1, E>`.\n */\nexport const isNonEmptyTuple = <E,>(\n array: readonly E[],\n): array is MinLengthTuple<1, E> => array.length >= 1;\n\n/**\n * Checks if an array has a specific length.\n *\n * @example\n *\n * ```ts\n * const pair: readonly number[] = [1, 2] as const;\n *\n * const triple: readonly number[] = [1, 2, 3] as const;\n *\n * assert.isTrue(Arr.isFixedLengthTuple(2, pair));\n *\n * assert.isFalse(Arr.isFixedLengthTuple(2, triple));\n *\n * if (Arr.isFixedLengthTuple(2, pair)) {\n * assert.deepStrictEqual(pair, [1, 2]);\n * }\n * ```\n */\nexport function isFixedLengthTuple<N extends SizeType.ArgArr, E>(\n len: N,\n array: readonly E[],\n): array is FixedLengthTuple<N, E>;\n\n// Curried version\nexport function isFixedLengthTuple<N extends SizeType.ArgArr>(\n len: N,\n): <E>(array: readonly E[]) => array is FixedLengthTuple<N, E>;\n\nexport function isFixedLengthTuple(\n ...args:\n | readonly [len: SizeType.ArgArr, array: readonly unknown[]]\n | readonly [len: SizeType.ArgArr]\n): boolean | ((array: readonly unknown[]) => boolean) {\n switch (args.length) {\n case 2:\n return hasFixedLength(args[0], args[1]);\n\n case 1:\n return (array) => hasFixedLength(args[0], array);\n }\n}\n\nconst hasFixedLength = (\n len: SizeType.ArgArr,\n array: readonly unknown[],\n): boolean => array.length === len;\n\n/**\n * Checks if an array has at least a specific length.\n *\n * @example\n *\n * ```ts\n * const queue: readonly string[] = ['task-1', 'task-2'] as const;\n *\n * const emptyQueue: readonly string[] = [] as const;\n *\n * assert.isTrue(Arr.isMinLengthTuple(1, queue));\n *\n * assert.isFalse(Arr.isMinLengthTuple(1, emptyQueue));\n *\n * if (Arr.isMinLengthTuple(1, queue)) {\n * assert.isTrue(queue[0] === 'task-1');\n * }\n * ```\n */\nexport function isMinLengthTuple<N extends SizeType.ArgArr, E>(\n len: N,\n array: readonly E[],\n): array is MinLengthTuple<N, E>;\n\n// Curried version\nexport function isMinLengthTuple<N extends SizeType.ArgArr>(\n len: N,\n): <E>(array: readonly E[]) => array is MinLengthTuple<N, E>;\n\nexport function isMinLengthTuple(\n ...args:\n | readonly [len: SizeType.ArgArr, array: readonly unknown[]]\n | readonly [len: SizeType.ArgArr]\n): boolean | ((array: readonly unknown[]) => boolean) {\n switch (args.length) {\n case 2:\n return hasMinLength(args[0], args[1]);\n\n case 1:\n return (array) => hasMinLength(args[0], array);\n }\n}\n\nconst hasMinLength = (\n len: SizeType.ArgArr,\n array: readonly unknown[],\n): boolean => array.length >= len;\n\n/**\n * Checks if an array has at most a specific length.\n *\n * @example\n *\n * ```ts\n * const pair: readonly number[] = [1, 2] as const;\n *\n * const triple: readonly number[] = [1, 2, 3] as const;\n *\n * assert.isTrue(Arr.isMaxLengthTuple(2, pair));\n *\n * assert.isFalse(Arr.isMaxLengthTuple(2, triple));\n *\n * if (Arr.isMaxLengthTuple(2, pair)) {\n * assert.isTrue(pair.length <= 2);\n * }\n * ```\n */\nexport function isMaxLengthTuple<N extends SizeType.ArgArr, E>(\n len: N,\n array: readonly E[],\n): array is MaxLengthTuple<N, E>;\n\n// Curried version\nexport function isMaxLengthTuple<N extends SizeType.ArgArr>(\n len: N,\n): <E>(array: readonly E[]) => array is MaxLengthTuple<N, E>;\n\nexport function isMaxLengthTuple(\n ...args:\n | readonly [len: SizeType.ArgArr, array: readonly unknown[]]\n | readonly [len: SizeType.ArgArr]\n): boolean | ((array: readonly unknown[]) => boolean) {\n switch (args.length) {\n case 2:\n return hasMaxLength(args[0], args[1]);\n\n case 1:\n return (array) => hasMaxLength(args[0], array);\n }\n}\n\nconst hasMaxLength = (\n len: SizeType.ArgArr,\n array: readonly unknown[],\n): boolean => array.length <= len;\n\n/**\n * Checks if an array's length is within a specific inclusive range.\n *\n * @example\n *\n * ```ts\n * const pair: readonly number[] = [1, 2] as const;\n *\n * const quad: readonly number[] = [1, 2, 3, 4] as const;\n *\n * assert.isTrue(Arr.isBoundedLengthTuple(1, 3, pair));\n *\n * assert.isFalse(Arr.isBoundedLengthTuple(1, 3, quad));\n *\n * if (Arr.isBoundedLengthTuple(1, 3, pair)) {\n * assert.isTrue(pair.length >= 1 && pair.length <= 3);\n * }\n * ```\n */\nexport function isBoundedLengthTuple<\n Min extends SizeType.ArgArr,\n Max extends SizeType.ArgArr,\n E,\n>(\n min: Min,\n max: Max,\n array: readonly E[],\n): array is BoundedLengthTuple<Min, Max, E>;\n\n// Curried version\nexport function isBoundedLengthTuple<\n Min extends SizeType.ArgArr,\n Max extends SizeType.ArgArr,\n>(\n min: Min,\n max: Max,\n): <E>(array: readonly E[]) => array is BoundedLengthTuple<Min, Max, E>;\n\nexport function isBoundedLengthTuple(\n ...args:\n | readonly [\n min: SizeType.ArgArr,\n max: SizeType.ArgArr,\n array: readonly unknown[],\n ]\n | readonly [min: SizeType.ArgArr, max: SizeType.ArgArr]\n): boolean | ((array: readonly unknown[]) => boolean) {\n switch (args.length) {\n case 3:\n return isWithinBounds(args[0], args[1], args[2]);\n\n case 2:\n return (array) => isWithinBounds(args[0], args[1], array);\n }\n}\n\nconst isWithinBounds = (\n min: SizeType.ArgArr,\n max: SizeType.ArgArr,\n array: readonly unknown[],\n): boolean => array.length >= min && array.length <= max;\n"],"names":[],"mappings":"AA+BO,MAAM,YAAA,GAAe,CAAK,KAAA,KAC/B,KAAA,CAAM,MAAA,KAAW;AAyBZ,MAAM,eAAA,GAAkB,CAC7B,KAAA,KACkC,KAAA,CAAM,MAAA,IAAU;AA+B7C,SAAS,sBACX,IAAA,EAGiD;AACpD,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA;AACH,MAAA,OAAO,eAAe,IAAA,CAAK,CAAC,CAAA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CAAe,IAAA,CAAK,CAAC,CAAA,EAAG,IAAA,CAAK,CAAC,CAAA,EAAG,KAAK,CAAA;AAAA;AAE9D;AAEA,MAAM,cAAA,GAAiB,CACrB,GAAA,EACA,GAAA,EACA,UACY,KAAA,CAAM,MAAA,IAAU,GAAA,IAAO,KAAA,CAAM,MAAA,IAAU,GAAA;;;;"}
1
+ {"version":3,"file":"array-utils-length-bounded-tuple-guard.mjs","sourceRoot":"","sources":["../../../src/array/impl/array-utils-length-bounded-tuple-guard.mts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAK,KAAmB,EAAwB,EAAE,CAC5E,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;AAErB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,KAAmB,EACY,EAAE,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC;AA+BtD,MAAM,UAAU,kBAAkB,CAChC,GAAG,IAEgC;IAEnC,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;QACpB,KAAK,CAAC;YACJ,OAAO,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAE1C,KAAK,CAAC;YACJ,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACrD,CAAC;AACH,CAAC;AAED,MAAM,cAAc,GAAG,CACrB,GAAoB,EACpB,KAAyB,EAChB,EAAE,CAAC,KAAK,CAAC,MAAM,KAAK,GAAG,CAAC;AA+BnC,MAAM,UAAU,gBAAgB,CAC9B,GAAG,IAEgC;IAEnC,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;QACpB,KAAK,CAAC;YACJ,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,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