type-plus 6.8.1 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (531) hide show
  1. package/README.md +1054 -355
  2. package/cjs/array/{array.d.ts → array.at.d.ts} +4 -14
  3. package/cjs/array/array.at.d.ts.map +1 -0
  4. package/cjs/array/{pad_left.js → array.at.js} +1 -1
  5. package/cjs/array/array.at.js.map +1 -0
  6. package/cjs/array/array.concat.d.ts +13 -0
  7. package/cjs/array/array.concat.d.ts.map +1 -0
  8. package/cjs/array/array.concat.js +3 -0
  9. package/cjs/array/array.concat.js.map +1 -0
  10. package/cjs/array/array.entries.d.ts +17 -0
  11. package/cjs/array/array.entries.d.ts.map +1 -0
  12. package/cjs/array/array.entries.js +3 -0
  13. package/cjs/array/array.entries.js.map +1 -0
  14. package/cjs/array/array.find.d.ts +21 -0
  15. package/cjs/array/array.find.d.ts.map +1 -0
  16. package/cjs/array/{find_first.js → array.find.js} +1 -1
  17. package/cjs/array/array.find.js.map +1 -0
  18. package/cjs/array/array.find_last.d.ts +17 -0
  19. package/cjs/array/array.find_last.d.ts.map +1 -0
  20. package/cjs/array/array.find_last.js +3 -0
  21. package/cjs/array/array.find_last.js.map +1 -0
  22. package/cjs/array/array.reverse.d.ts +2 -0
  23. package/cjs/array/array.reverse.d.ts.map +1 -0
  24. package/cjs/array/array.reverse.js +3 -0
  25. package/cjs/array/array.reverse.js.map +1 -0
  26. package/cjs/array/array.some.d.ts +29 -0
  27. package/cjs/array/array.some.d.ts.map +1 -0
  28. package/cjs/array/array.some.js +3 -0
  29. package/cjs/array/array.some.js.map +1 -0
  30. package/cjs/array/array_index.d.ts +8 -8
  31. package/cjs/array/array_index.d.ts.map +1 -1
  32. package/cjs/array/array_plus.d.ts +9 -1
  33. package/cjs/array/array_plus.d.ts.map +1 -1
  34. package/cjs/array/array_plus.split_at.d.ts +30 -0
  35. package/cjs/array/array_plus.split_at.d.ts.map +1 -0
  36. package/cjs/array/array_plus.split_at.js +3 -0
  37. package/cjs/array/array_plus.split_at.js.map +1 -0
  38. package/cjs/array/drop.d.ts +2 -2
  39. package/cjs/array/drop.d.ts.map +1 -1
  40. package/cjs/array/index.d.ts +4 -5
  41. package/cjs/array/index.d.ts.map +1 -1
  42. package/cjs/array/index.js +4 -5
  43. package/cjs/array/index.js.map +1 -1
  44. package/cjs/array/pad_start.d.ts +32 -0
  45. package/cjs/array/pad_start.d.ts.map +1 -0
  46. package/cjs/array/{find_last.js → pad_start.js} +1 -1
  47. package/cjs/array/pad_start.js.map +1 -0
  48. package/cjs/assertion/assert_type.d.ts +3 -0
  49. package/cjs/assertion/assert_type.d.ts.map +1 -1
  50. package/cjs/assertion/assert_type.js +3 -0
  51. package/cjs/assertion/assert_type.js.map +1 -1
  52. package/cjs/bigint/cast.d.ts +10 -0
  53. package/cjs/bigint/cast.d.ts.map +1 -0
  54. package/cjs/{array/some.js → bigint/cast.js} +1 -1
  55. package/cjs/bigint/cast.js.map +1 -0
  56. package/cjs/equal/equal.d.ts +51 -3
  57. package/cjs/equal/equal.d.ts.map +1 -1
  58. package/cjs/functional/Maybe.d.ts +2 -2
  59. package/cjs/functional/Maybe.d.ts.map +1 -1
  60. package/cjs/index.d.ts +16 -7
  61. package/cjs/index.d.ts.map +1 -1
  62. package/cjs/index.js +6 -1
  63. package/cjs/index.js.map +1 -1
  64. package/cjs/math/abs.d.ts +6 -0
  65. package/cjs/math/abs.d.ts.map +1 -0
  66. package/cjs/math/{Add.js → abs.js} +1 -1
  67. package/cjs/math/abs.js.map +1 -0
  68. package/cjs/math/add.d.ts +7 -0
  69. package/cjs/math/add.d.ts.map +1 -0
  70. package/cjs/math/{Max.js → add.js} +1 -1
  71. package/cjs/math/add.js.map +1 -0
  72. package/cjs/math/greater_than.d.ts +4 -0
  73. package/cjs/math/greater_than.d.ts.map +1 -0
  74. package/cjs/math/greater_than.js +3 -0
  75. package/cjs/math/greater_than.js.map +1 -0
  76. package/cjs/math/index.d.ts +6 -6
  77. package/cjs/math/index.d.ts.map +1 -1
  78. package/cjs/math/math_plus.d.ts +5 -0
  79. package/cjs/math/math_plus.d.ts.map +1 -0
  80. package/cjs/math/math_plus.js +3 -0
  81. package/cjs/math/math_plus.js.map +1 -0
  82. package/cjs/math/math_plus.to_negative.d.ts +13 -0
  83. package/cjs/math/math_plus.to_negative.d.ts.map +1 -0
  84. package/cjs/math/math_plus.to_negative.js +3 -0
  85. package/cjs/math/math_plus.to_negative.js.map +1 -0
  86. package/cjs/math/max.d.ts +4 -0
  87. package/cjs/math/max.d.ts.map +1 -0
  88. package/cjs/math/{Abs.js → max.js} +1 -1
  89. package/cjs/math/max.js.map +1 -0
  90. package/cjs/math/multiply.d.ts +6 -0
  91. package/cjs/math/multiply.d.ts.map +1 -0
  92. package/cjs/{array/array.js → math/multiply.js} +1 -1
  93. package/cjs/math/multiply.js.map +1 -0
  94. package/cjs/math/numeric_struct.d.ts +1469 -0
  95. package/cjs/math/numeric_struct.d.ts.map +1 -0
  96. package/cjs/math/numeric_struct.js +3 -0
  97. package/cjs/math/numeric_struct.js.map +1 -0
  98. package/cjs/math/subtract.d.ts +7 -0
  99. package/cjs/math/subtract.d.ts.map +1 -0
  100. package/cjs/math/subtract.js +3 -0
  101. package/cjs/math/subtract.js.map +1 -0
  102. package/cjs/nominal/brand.js +2 -2
  103. package/cjs/nominal/brand.js.map +1 -1
  104. package/cjs/nominal/flavor.js +2 -2
  105. package/cjs/nominal/flavor.js.map +1 -1
  106. package/cjs/number/cast.d.ts +10 -0
  107. package/cjs/number/cast.d.ts.map +1 -0
  108. package/cjs/number/cast.js +3 -0
  109. package/cjs/number/cast.js.map +1 -0
  110. package/cjs/number/number_array.d.ts +0 -2
  111. package/cjs/number/number_array.d.ts.map +1 -1
  112. package/cjs/number/number_array.js +14 -1
  113. package/cjs/number/number_array.js.map +1 -1
  114. package/cjs/number/number_plus.d.ts +4 -5
  115. package/cjs/number/number_plus.d.ts.map +1 -1
  116. package/cjs/number/strict_number_type.d.ts +12 -0
  117. package/cjs/number/strict_number_type.d.ts.map +1 -1
  118. package/cjs/numeric/cast.d.ts +27 -0
  119. package/cjs/numeric/cast.d.ts.map +1 -0
  120. package/cjs/numeric/cast.js +3 -0
  121. package/cjs/numeric/cast.js.map +1 -0
  122. package/{esm/number → cjs/numeric}/integer.d.ts +2 -0
  123. package/cjs/numeric/integer.d.ts.map +1 -0
  124. package/cjs/{number → numeric}/integer.js.map +1 -1
  125. package/cjs/numeric/negative.d.ts.map +1 -0
  126. package/cjs/{number → numeric}/negative.js.map +1 -1
  127. package/cjs/numeric/numeric_plus.d.ts +5 -0
  128. package/cjs/numeric/numeric_plus.d.ts.map +1 -0
  129. package/cjs/numeric/numeric_plus.js +3 -0
  130. package/cjs/numeric/numeric_plus.js.map +1 -0
  131. package/cjs/numeric/numeric_type.d.ts.map +1 -0
  132. package/cjs/{number → numeric}/numeric_type.js.map +1 -1
  133. package/cjs/{number → numeric}/positive.d.ts +2 -2
  134. package/cjs/numeric/positive.d.ts.map +1 -0
  135. package/cjs/{number → numeric}/positive.js.map +1 -1
  136. package/cjs/object/ANotB.d.ts +3 -3
  137. package/cjs/object/ANotB.d.ts.map +1 -1
  138. package/cjs/object/Partial.d.ts +6 -0
  139. package/cjs/object/Partial.d.ts.map +1 -1
  140. package/cjs/object/Required.d.ts +4 -0
  141. package/cjs/object/Required.d.ts.map +1 -1
  142. package/cjs/object/index.d.ts +1 -1
  143. package/cjs/object/index.d.ts.map +1 -1
  144. package/cjs/object/object_type.d.ts +1 -1
  145. package/cjs/object/split.d.ts +3 -1
  146. package/cjs/object/split.d.ts.map +1 -1
  147. package/cjs/object/split.js.map +1 -1
  148. package/cjs/predicates/CanAssign.d.ts +35 -0
  149. package/cjs/predicates/CanAssign.d.ts.map +1 -1
  150. package/cjs/predicates/CanAssign.js.map +1 -1
  151. package/cjs/predicates/Extends.d.ts +2 -2
  152. package/cjs/predicates/Extends.d.ts.map +1 -1
  153. package/cjs/predicates/index.d.ts +0 -1
  154. package/cjs/predicates/index.d.ts.map +1 -1
  155. package/cjs/predicates/index.js +0 -1
  156. package/cjs/predicates/index.js.map +1 -1
  157. package/cjs/testing/test_type.d.ts +125 -50
  158. package/cjs/testing/test_type.d.ts.map +1 -1
  159. package/cjs/testing/test_type.js +4 -141
  160. package/cjs/testing/test_type.js.map +1 -1
  161. package/cjs/tuple/create_tuple.d.ts +28 -0
  162. package/cjs/tuple/create_tuple.d.ts.map +1 -0
  163. package/cjs/{array → tuple}/create_tuple.js.map +1 -1
  164. package/cjs/tuple/tuple_plus.d.ts +2 -0
  165. package/cjs/tuple/tuple_plus.d.ts.map +1 -0
  166. package/cjs/tuple/tuple_plus.js +18 -0
  167. package/cjs/tuple/tuple_plus.js.map +1 -0
  168. package/cjs/tuple/tuple_plus.pad_start.d.ts +22 -0
  169. package/cjs/tuple/tuple_plus.pad_start.d.ts.map +1 -0
  170. package/cjs/tuple/tuple_plus.pad_start.js +3 -0
  171. package/cjs/tuple/tuple_plus.pad_start.js.map +1 -0
  172. package/cjs/{predicates/isType.d.ts → type-guard/is_type.d.ts} +5 -3
  173. package/cjs/type-guard/is_type.d.ts.map +1 -0
  174. package/cjs/{predicates/isType.js → type-guard/is_type.js} +8 -2
  175. package/cjs/type-guard/is_type.js.map +1 -0
  176. package/esm/array/{array.d.ts → array.at.d.ts} +4 -14
  177. package/esm/array/array.at.d.ts.map +1 -0
  178. package/esm/array/array.at.js +2 -0
  179. package/esm/array/array.at.js.map +1 -0
  180. package/esm/array/array.concat.d.ts +13 -0
  181. package/esm/array/array.concat.d.ts.map +1 -0
  182. package/esm/array/array.concat.js +2 -0
  183. package/esm/array/array.concat.js.map +1 -0
  184. package/esm/array/array.entries.d.ts +17 -0
  185. package/esm/array/array.entries.d.ts.map +1 -0
  186. package/esm/array/array.entries.js +2 -0
  187. package/esm/array/array.entries.js.map +1 -0
  188. package/esm/array/array.find.d.ts +21 -0
  189. package/esm/array/array.find.d.ts.map +1 -0
  190. package/esm/array/array.find.js +2 -0
  191. package/esm/array/array.find.js.map +1 -0
  192. package/esm/array/array.find_last.d.ts +17 -0
  193. package/esm/array/array.find_last.d.ts.map +1 -0
  194. package/esm/array/array.find_last.js +2 -0
  195. package/esm/array/array.find_last.js.map +1 -0
  196. package/esm/array/array.reverse.d.ts +2 -0
  197. package/esm/array/array.reverse.d.ts.map +1 -0
  198. package/esm/array/array.reverse.js +2 -0
  199. package/esm/array/array.reverse.js.map +1 -0
  200. package/esm/array/array.some.d.ts +29 -0
  201. package/esm/array/array.some.d.ts.map +1 -0
  202. package/esm/array/array.some.js +2 -0
  203. package/esm/array/array.some.js.map +1 -0
  204. package/esm/array/array_index.d.ts +8 -8
  205. package/esm/array/array_index.d.ts.map +1 -1
  206. package/esm/array/array_plus.d.ts +9 -1
  207. package/esm/array/array_plus.d.ts.map +1 -1
  208. package/esm/array/array_plus.split_at.d.ts +30 -0
  209. package/esm/array/array_plus.split_at.d.ts.map +1 -0
  210. package/esm/array/array_plus.split_at.js +2 -0
  211. package/esm/array/array_plus.split_at.js.map +1 -0
  212. package/esm/array/drop.d.ts +2 -2
  213. package/esm/array/drop.d.ts.map +1 -1
  214. package/esm/array/index.d.ts +4 -5
  215. package/esm/array/index.d.ts.map +1 -1
  216. package/esm/array/index.js +4 -5
  217. package/esm/array/index.js.map +1 -1
  218. package/esm/array/pad_start.d.ts +32 -0
  219. package/esm/array/pad_start.d.ts.map +1 -0
  220. package/esm/array/pad_start.js +2 -0
  221. package/esm/array/pad_start.js.map +1 -0
  222. package/esm/assertion/assert_type.d.ts +3 -0
  223. package/esm/assertion/assert_type.d.ts.map +1 -1
  224. package/esm/assertion/assert_type.js +3 -0
  225. package/esm/assertion/assert_type.js.map +1 -1
  226. package/esm/bigint/cast.d.ts +10 -0
  227. package/esm/bigint/cast.d.ts.map +1 -0
  228. package/esm/bigint/cast.js +2 -0
  229. package/esm/bigint/cast.js.map +1 -0
  230. package/esm/equal/equal.d.ts +51 -3
  231. package/esm/equal/equal.d.ts.map +1 -1
  232. package/esm/functional/Maybe.d.ts +2 -2
  233. package/esm/functional/Maybe.d.ts.map +1 -1
  234. package/esm/index.d.ts +16 -7
  235. package/esm/index.d.ts.map +1 -1
  236. package/esm/index.js +5 -0
  237. package/esm/index.js.map +1 -1
  238. package/esm/math/abs.d.ts +6 -0
  239. package/esm/math/abs.d.ts.map +1 -0
  240. package/esm/math/abs.js +2 -0
  241. package/esm/math/abs.js.map +1 -0
  242. package/esm/math/add.d.ts +7 -0
  243. package/esm/math/add.d.ts.map +1 -0
  244. package/esm/math/add.js +2 -0
  245. package/esm/math/add.js.map +1 -0
  246. package/esm/math/greater_than.d.ts +4 -0
  247. package/esm/math/greater_than.d.ts.map +1 -0
  248. package/esm/math/greater_than.js +2 -0
  249. package/esm/math/greater_than.js.map +1 -0
  250. package/esm/math/index.d.ts +6 -6
  251. package/esm/math/index.d.ts.map +1 -1
  252. package/esm/math/math_plus.d.ts +5 -0
  253. package/esm/math/math_plus.d.ts.map +1 -0
  254. package/esm/math/math_plus.js +2 -0
  255. package/esm/math/math_plus.js.map +1 -0
  256. package/esm/math/math_plus.to_negative.d.ts +13 -0
  257. package/esm/math/math_plus.to_negative.d.ts.map +1 -0
  258. package/esm/math/math_plus.to_negative.js +2 -0
  259. package/esm/math/math_plus.to_negative.js.map +1 -0
  260. package/esm/math/max.d.ts +4 -0
  261. package/esm/math/max.d.ts.map +1 -0
  262. package/esm/math/max.js +2 -0
  263. package/esm/math/max.js.map +1 -0
  264. package/esm/math/multiply.d.ts +6 -0
  265. package/esm/math/multiply.d.ts.map +1 -0
  266. package/esm/math/multiply.js +2 -0
  267. package/esm/math/multiply.js.map +1 -0
  268. package/esm/math/numeric_struct.d.ts +1469 -0
  269. package/esm/math/numeric_struct.d.ts.map +1 -0
  270. package/esm/math/numeric_struct.js +2 -0
  271. package/esm/math/numeric_struct.js.map +1 -0
  272. package/esm/math/subtract.d.ts +7 -0
  273. package/esm/math/subtract.d.ts.map +1 -0
  274. package/esm/math/subtract.js +2 -0
  275. package/esm/math/subtract.js.map +1 -0
  276. package/esm/nominal/brand.js +1 -1
  277. package/esm/nominal/brand.js.map +1 -1
  278. package/esm/nominal/flavor.js +1 -1
  279. package/esm/nominal/flavor.js.map +1 -1
  280. package/esm/number/cast.d.ts +10 -0
  281. package/esm/number/cast.d.ts.map +1 -0
  282. package/esm/number/cast.js +2 -0
  283. package/esm/number/cast.js.map +1 -0
  284. package/esm/number/number_array.d.ts +1 -2
  285. package/esm/number/number_array.d.ts.map +1 -1
  286. package/esm/number/number_array.js +14 -0
  287. package/esm/number/number_array.js.map +1 -1
  288. package/esm/number/number_plus.d.ts +4 -5
  289. package/esm/number/number_plus.d.ts.map +1 -1
  290. package/esm/number/strict_number_type.d.ts +12 -0
  291. package/esm/number/strict_number_type.d.ts.map +1 -1
  292. package/esm/numeric/cast.d.ts +27 -0
  293. package/esm/numeric/cast.d.ts.map +1 -0
  294. package/esm/numeric/cast.js +2 -0
  295. package/esm/numeric/cast.js.map +1 -0
  296. package/{cjs/number → esm/numeric}/integer.d.ts +2 -0
  297. package/esm/numeric/integer.d.ts.map +1 -0
  298. package/esm/{number → numeric}/integer.js.map +1 -1
  299. package/esm/numeric/negative.d.ts.map +1 -0
  300. package/esm/{number → numeric}/negative.js.map +1 -1
  301. package/esm/numeric/numeric_plus.d.ts +5 -0
  302. package/esm/numeric/numeric_plus.d.ts.map +1 -0
  303. package/esm/numeric/numeric_plus.js +2 -0
  304. package/esm/numeric/numeric_plus.js.map +1 -0
  305. package/esm/numeric/numeric_type.d.ts.map +1 -0
  306. package/esm/{number → numeric}/numeric_type.js.map +1 -1
  307. package/esm/{number → numeric}/positive.d.ts +2 -2
  308. package/esm/numeric/positive.d.ts.map +1 -0
  309. package/esm/{number → numeric}/positive.js.map +1 -1
  310. package/esm/object/ANotB.d.ts +3 -3
  311. package/esm/object/ANotB.d.ts.map +1 -1
  312. package/esm/object/Partial.d.ts +6 -0
  313. package/esm/object/Partial.d.ts.map +1 -1
  314. package/esm/object/Required.d.ts +4 -0
  315. package/esm/object/Required.d.ts.map +1 -1
  316. package/esm/object/index.d.ts +1 -1
  317. package/esm/object/index.d.ts.map +1 -1
  318. package/esm/object/object_type.d.ts +1 -1
  319. package/esm/object/split.d.ts +3 -1
  320. package/esm/object/split.d.ts.map +1 -1
  321. package/esm/object/split.js.map +1 -1
  322. package/esm/predicates/CanAssign.d.ts +35 -0
  323. package/esm/predicates/CanAssign.d.ts.map +1 -1
  324. package/esm/predicates/CanAssign.js.map +1 -1
  325. package/esm/predicates/Extends.d.ts +2 -2
  326. package/esm/predicates/Extends.d.ts.map +1 -1
  327. package/esm/predicates/index.d.ts +0 -1
  328. package/esm/predicates/index.d.ts.map +1 -1
  329. package/esm/predicates/index.js +0 -1
  330. package/esm/predicates/index.js.map +1 -1
  331. package/esm/testing/test_type.d.ts +125 -50
  332. package/esm/testing/test_type.d.ts.map +1 -1
  333. package/esm/testing/test_type.js +4 -141
  334. package/esm/testing/test_type.js.map +1 -1
  335. package/esm/tuple/create_tuple.d.ts +28 -0
  336. package/esm/tuple/create_tuple.d.ts.map +1 -0
  337. package/esm/{array → tuple}/create_tuple.js.map +1 -1
  338. package/esm/tuple/tuple_plus.d.ts +2 -0
  339. package/esm/tuple/tuple_plus.d.ts.map +1 -0
  340. package/esm/tuple/tuple_plus.js +2 -0
  341. package/esm/tuple/tuple_plus.js.map +1 -0
  342. package/esm/tuple/tuple_plus.pad_start.d.ts +22 -0
  343. package/esm/tuple/tuple_plus.pad_start.d.ts.map +1 -0
  344. package/esm/tuple/tuple_plus.pad_start.js +2 -0
  345. package/esm/tuple/tuple_plus.pad_start.js.map +1 -0
  346. package/esm/{predicates/isType.d.ts → type-guard/is_type.d.ts} +5 -3
  347. package/esm/type-guard/is_type.d.ts.map +1 -0
  348. package/esm/{predicates/isType.js → type-guard/is_type.js} +8 -2
  349. package/esm/type-guard/is_type.js.map +1 -0
  350. package/package.json +1 -1
  351. package/ts/array/{array.ts → array.at.ts} +10 -15
  352. package/ts/array/array.concat.ts +12 -0
  353. package/ts/array/array.entries.ts +24 -0
  354. package/ts/array/array.find.ts +32 -0
  355. package/ts/array/array.find_last.ts +27 -0
  356. package/ts/array/array.reverse.ts +16 -0
  357. package/ts/array/array.some.ts +53 -0
  358. package/ts/array/array_index.ts +16 -10
  359. package/ts/array/array_plus.split_at.ts +47 -0
  360. package/ts/array/array_plus.ts +9 -1
  361. package/ts/array/drop.ts +2 -2
  362. package/ts/array/index.ts +4 -5
  363. package/ts/array/pad_start.ts +43 -0
  364. package/ts/array/readme.md +184 -4
  365. package/ts/assertion/assert_type.ts +6 -0
  366. package/ts/assertion/readme.md +132 -1
  367. package/ts/bigint/cast.ts +13 -0
  368. package/ts/bigint/readme.md +17 -17
  369. package/ts/equal/equal.ts +53 -3
  370. package/ts/equal/readme.md +30 -16
  371. package/ts/functional/Maybe.ts +2 -2
  372. package/ts/index.ts +22 -24
  373. package/ts/math/README.md +97 -7
  374. package/ts/math/abs.ts +18 -0
  375. package/ts/math/add.ts +14 -0
  376. package/ts/math/greater_than.ts +12 -0
  377. package/ts/math/index.ts +7 -6
  378. package/ts/math/math_plus.to_negative.ts +22 -0
  379. package/ts/math/math_plus.ts +4 -0
  380. package/ts/math/max.ts +13 -0
  381. package/ts/math/multiply.ts +12 -0
  382. package/ts/math/numeric_struct.ts +658 -0
  383. package/ts/math/subtract.ts +14 -0
  384. package/ts/nominal/brand.ts +1 -1
  385. package/ts/nominal/flavor.ts +1 -1
  386. package/ts/number/cast.ts +17 -0
  387. package/ts/number/number_array.ts +14 -14
  388. package/ts/number/number_plus.ts +6 -6
  389. package/ts/number/readme.md +0 -108
  390. package/ts/number/strict_number_type.ts +12 -0
  391. package/ts/numeric/cast.ts +28 -0
  392. package/ts/{number → numeric}/integer.ts +2 -0
  393. package/ts/numeric/numeric_plus.ts +12 -0
  394. package/ts/{number → numeric}/positive.ts +2 -2
  395. package/ts/numeric/readme.md +115 -0
  396. package/ts/object/ANotB.ts +3 -3
  397. package/ts/object/Partial.ts +5 -0
  398. package/ts/object/Required.ts +4 -0
  399. package/ts/object/index.ts +1 -1
  400. package/ts/object/object_type.ts +1 -1
  401. package/ts/object/split.ts +3 -1
  402. package/ts/predicates/CanAssign.ts +46 -0
  403. package/ts/predicates/Extends.ts +2 -2
  404. package/ts/predicates/index.ts +0 -1
  405. package/ts/testing/test_type.ts +131 -88
  406. package/ts/tuple/create_tuple.ts +42 -0
  407. package/ts/tuple/tuple_plus.pad_start.ts +42 -0
  408. package/ts/tuple/tuple_plus.ts +1 -0
  409. package/ts/{predicates/isType.ts → type-guard/is_type.ts} +11 -3
  410. package/ts/type-guard/readme.md +37 -0
  411. package/cjs/array/array.d.ts.map +0 -1
  412. package/cjs/array/array.js.map +0 -1
  413. package/cjs/array/create_tuple.d.ts +0 -11
  414. package/cjs/array/create_tuple.d.ts.map +0 -1
  415. package/cjs/array/find_first.d.ts +0 -6
  416. package/cjs/array/find_first.d.ts.map +0 -1
  417. package/cjs/array/find_first.js.map +0 -1
  418. package/cjs/array/find_last.d.ts +0 -2
  419. package/cjs/array/find_last.d.ts.map +0 -1
  420. package/cjs/array/find_last.js.map +0 -1
  421. package/cjs/array/pad_left.d.ts +0 -6
  422. package/cjs/array/pad_left.d.ts.map +0 -1
  423. package/cjs/array/pad_left.js.map +0 -1
  424. package/cjs/array/some.d.ts +0 -8
  425. package/cjs/array/some.d.ts.map +0 -1
  426. package/cjs/array/some.js.map +0 -1
  427. package/cjs/math/Abs.d.ts +0 -3
  428. package/cjs/math/Abs.d.ts.map +0 -1
  429. package/cjs/math/Abs.js.map +0 -1
  430. package/cjs/math/Add.d.ts +0 -19
  431. package/cjs/math/Add.d.ts.map +0 -1
  432. package/cjs/math/Add.js.map +0 -1
  433. package/cjs/math/Digit.d.ts +0 -100
  434. package/cjs/math/Digit.d.ts.map +0 -1
  435. package/cjs/math/Digit.js +0 -3
  436. package/cjs/math/Digit.js.map +0 -1
  437. package/cjs/math/GreaterThan.d.ts +0 -13
  438. package/cjs/math/GreaterThan.d.ts.map +0 -1
  439. package/cjs/math/GreaterThan.js +0 -3
  440. package/cjs/math/GreaterThan.js.map +0 -1
  441. package/cjs/math/Max.d.ts +0 -4
  442. package/cjs/math/Max.d.ts.map +0 -1
  443. package/cjs/math/Max.js.map +0 -1
  444. package/cjs/math/Subtract.d.ts +0 -19
  445. package/cjs/math/Subtract.d.ts.map +0 -1
  446. package/cjs/math/Subtract.js +0 -3
  447. package/cjs/math/Subtract.js.map +0 -1
  448. package/cjs/number/integer.d.ts.map +0 -1
  449. package/cjs/number/negative.d.ts.map +0 -1
  450. package/cjs/number/numeric_type.d.ts.map +0 -1
  451. package/cjs/number/positive.d.ts.map +0 -1
  452. package/cjs/predicates/isType.d.ts.map +0 -1
  453. package/cjs/predicates/isType.js.map +0 -1
  454. package/esm/array/array.d.ts.map +0 -1
  455. package/esm/array/array.js +0 -2
  456. package/esm/array/array.js.map +0 -1
  457. package/esm/array/create_tuple.d.ts +0 -11
  458. package/esm/array/create_tuple.d.ts.map +0 -1
  459. package/esm/array/find_first.d.ts +0 -6
  460. package/esm/array/find_first.d.ts.map +0 -1
  461. package/esm/array/find_first.js +0 -2
  462. package/esm/array/find_first.js.map +0 -1
  463. package/esm/array/find_last.d.ts +0 -2
  464. package/esm/array/find_last.d.ts.map +0 -1
  465. package/esm/array/find_last.js +0 -2
  466. package/esm/array/find_last.js.map +0 -1
  467. package/esm/array/pad_left.d.ts +0 -6
  468. package/esm/array/pad_left.d.ts.map +0 -1
  469. package/esm/array/pad_left.js +0 -2
  470. package/esm/array/pad_left.js.map +0 -1
  471. package/esm/array/some.d.ts +0 -8
  472. package/esm/array/some.d.ts.map +0 -1
  473. package/esm/array/some.js +0 -2
  474. package/esm/array/some.js.map +0 -1
  475. package/esm/math/Abs.d.ts +0 -3
  476. package/esm/math/Abs.d.ts.map +0 -1
  477. package/esm/math/Abs.js +0 -2
  478. package/esm/math/Abs.js.map +0 -1
  479. package/esm/math/Add.d.ts +0 -19
  480. package/esm/math/Add.d.ts.map +0 -1
  481. package/esm/math/Add.js +0 -2
  482. package/esm/math/Add.js.map +0 -1
  483. package/esm/math/Digit.d.ts +0 -100
  484. package/esm/math/Digit.d.ts.map +0 -1
  485. package/esm/math/Digit.js +0 -2
  486. package/esm/math/Digit.js.map +0 -1
  487. package/esm/math/GreaterThan.d.ts +0 -13
  488. package/esm/math/GreaterThan.d.ts.map +0 -1
  489. package/esm/math/GreaterThan.js +0 -2
  490. package/esm/math/GreaterThan.js.map +0 -1
  491. package/esm/math/Max.d.ts +0 -4
  492. package/esm/math/Max.d.ts.map +0 -1
  493. package/esm/math/Max.js +0 -2
  494. package/esm/math/Max.js.map +0 -1
  495. package/esm/math/Subtract.d.ts +0 -19
  496. package/esm/math/Subtract.d.ts.map +0 -1
  497. package/esm/math/Subtract.js +0 -2
  498. package/esm/math/Subtract.js.map +0 -1
  499. package/esm/number/integer.d.ts.map +0 -1
  500. package/esm/number/negative.d.ts.map +0 -1
  501. package/esm/number/numeric_type.d.ts.map +0 -1
  502. package/esm/number/positive.d.ts.map +0 -1
  503. package/esm/predicates/isType.d.ts.map +0 -1
  504. package/esm/predicates/isType.js.map +0 -1
  505. package/ts/array/create_tuple.ts +0 -17
  506. package/ts/array/find_first.ts +0 -16
  507. package/ts/array/find_last.ts +0 -11
  508. package/ts/array/pad_left.ts +0 -16
  509. package/ts/array/some.ts +0 -33
  510. package/ts/math/Abs.ts +0 -7
  511. package/ts/math/Add.ts +0 -58
  512. package/ts/math/Digit.ts +0 -152
  513. package/ts/math/GreaterThan.ts +0 -55
  514. package/ts/math/Max.ts +0 -10
  515. package/ts/math/Subtract.ts +0 -57
  516. /package/cjs/{number → numeric}/integer.js +0 -0
  517. /package/cjs/{number → numeric}/negative.d.ts +0 -0
  518. /package/cjs/{number → numeric}/negative.js +0 -0
  519. /package/cjs/{number → numeric}/numeric_type.d.ts +0 -0
  520. /package/cjs/{number → numeric}/numeric_type.js +0 -0
  521. /package/cjs/{number → numeric}/positive.js +0 -0
  522. /package/cjs/{array → tuple}/create_tuple.js +0 -0
  523. /package/esm/{number → numeric}/integer.js +0 -0
  524. /package/esm/{number → numeric}/negative.d.ts +0 -0
  525. /package/esm/{number → numeric}/negative.js +0 -0
  526. /package/esm/{number → numeric}/numeric_type.d.ts +0 -0
  527. /package/esm/{number → numeric}/numeric_type.js +0 -0
  528. /package/esm/{number → numeric}/positive.js +0 -0
  529. /package/esm/{array → tuple}/create_tuple.js +0 -0
  530. /package/ts/{number → numeric}/negative.ts +0 -0
  531. /package/ts/{number → numeric}/numeric_type.ts +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "type-plus",
3
- "version": "6.8.1",
3
+ "version": "7.0.0",
4
4
  "description": "Provides additional types for TypeScript.",
5
5
  "homepage": "https://github.com/unional/type-plus",
6
6
  "bugs": {
@@ -1,3 +1,5 @@
1
+ import type { IsStrictNumber } from '../number/strict_number_type.js'
2
+ import type { TupleType } from '../tuple/tuple_type.js'
1
3
  import type { IndexAt } from './array_index.js'
2
4
 
3
5
  /**
@@ -13,21 +15,14 @@ import type { IndexAt } from './array_index.js'
13
15
  * type R = At<[1, 2, 3], -1> // 3
14
16
  * ```
15
17
  */
16
- export type At<A extends unknown[], N extends number, Fail = never> = IndexAt<A, N, Fail> extends infer I
18
+ export type At<A extends unknown[], N extends number, Fail = never> = IndexAt<
19
+ A,
20
+ N,
21
+ Fail,
22
+ Fail,
23
+ Fail
24
+ > extends infer I
17
25
  ? I extends number
18
- ? A[I]
26
+ ? TupleType<A, IsStrictNumber<I, A[I] | undefined, A[I]>, A[I] | undefined>
19
27
  : Fail
20
28
  : never
21
-
22
- /**
23
- * Concats two arrays.
24
- *
25
- * alias of: `[...A, ...B]`
26
- *
27
- * @alias ArrayPlus.Concat
28
- *
29
- * ```ts
30
- * type R = Concat<[1], [2, 3]> // [1, 2, 3]
31
- * ```
32
- */
33
- export type Concat<A extends unknown[], B extends unknown[]> = [...A, ...B]
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Concats two arrays or tuples.
3
+ *
4
+ * alias of: `[...A, ...B]`
5
+ *
6
+ * @alias ArrayPlus.Concat
7
+ *
8
+ * ```ts
9
+ * type R = Concat<[1], [2, 3]> // [1, 2, 3]
10
+ * ```
11
+ */
12
+ export type Concat<A extends unknown[], B extends unknown[]> = [...A, ...B]
@@ -0,0 +1,24 @@
1
+ import type { IsTuple } from '../tuple/tuple_type.js'
2
+ /**
3
+ * Returns an array of key-value pairs for every entry in the array or tuple.
4
+ *
5
+ * Note that this is not the same as `Array.entries(A)`,
6
+ * which returns an iterable interator.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * ArrayPlus.Entries<Array<string | number>> // Array<[number, string | number]>
11
+ * ArrayPlus.Entries<[1, 2, 3]> // [[0, 1], [1, 2], [2, 3]]
12
+ * ```
13
+ */
14
+ export type Entries<A extends unknown[]> = IsTuple<
15
+ A,
16
+ Device<A, []>,
17
+ A extends Array<infer T> ? Array<[number, T]> : never
18
+ >
19
+
20
+ type Device<A extends unknown[], R extends unknown[]> = A['length'] extends 0
21
+ ? R
22
+ : A extends [...infer F, infer N]
23
+ ? Device<F, [[F['length'], N], ...R]>
24
+ : never
@@ -0,0 +1,32 @@
1
+ import type { TupleType } from '../tuple/tuple_type.js'
2
+
3
+ /**
4
+ * Returns the first type in the array or tuple that matches the `Criteria`.
5
+ *
6
+ * If the `Criteria` is not met, it will return `never'.
7
+ *
8
+ * For `Array<T>`, it will return `T | undefined` if `T` satisfies `Criteria`.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * ArrayPlus.Find<Array<1 | 2 | 'x'>, number> // 1 | 2 | undefined
13
+ *
14
+ * ArrayPlus.Find<[true, 1, 'x', 3], string> // 'x'
15
+ * ```
16
+ */
17
+ export type FindFirst<A extends unknown[], Criteria> = TupleType<
18
+ A,
19
+ A['length'] extends 0
20
+ ? never
21
+ : A extends [infer Head, ...infer Tail]
22
+ ? Head extends Criteria
23
+ ? Head
24
+ : FindFirst<Tail, Criteria>
25
+ : never,
26
+ A extends Array<infer T> ? (T extends Criteria ? T | undefined : never) : never
27
+ >
28
+
29
+ /**
30
+ * @deprecated use FindFirst
31
+ */
32
+ export type First<A extends any[], Criteria> = FindFirst<A, Criteria>
@@ -0,0 +1,27 @@
1
+ import type { TupleType } from '../tuple/tuple_type.js'
2
+
3
+ /**
4
+ * Returns the last type in the array or tuple that matches the `Criteria`.
5
+ *
6
+ * If the `Criteria` is not met, it will return `never'.
7
+ *
8
+ * For `Array<T>`, it will return `T | undefined` if `T` satisfies `Criteria`.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * ArrayPlus.Find<Array<1 | 2 | 'x'>, number> // 1 | 2 | undefined
13
+ *
14
+ * ArrayPlus.Find<[true, 123, 'x', 321], number> // 321
15
+ * ```
16
+ */
17
+ export type FindLast<A extends Array<any>, Criteria> = TupleType<
18
+ A,
19
+ A['length'] extends 0
20
+ ? never
21
+ : A extends [...infer Heads, infer Last]
22
+ ? Last extends Criteria
23
+ ? Last
24
+ : FindLast<Heads, Criteria>
25
+ : never,
26
+ A extends Array<infer T> ? (T extends Criteria ? T | undefined : never) : never
27
+ >
@@ -0,0 +1,16 @@
1
+ /*
2
+ * Reverses the order of elements in the array or tuple.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * Reverse<Array<string | number>> // Array<string | number>
7
+ *
8
+ * Reverse<[1, 2, 3]> // [3, 2, 1]
9
+ * ```
10
+ *
11
+ * @param T The array type to reverse.
12
+ * @returns The reversed array type.
13
+ */
14
+ export type Reverse<A extends unknown[]> = A extends [infer First, ...infer Rest]
15
+ ? [...Reverse<Rest>, First]
16
+ : A
@@ -0,0 +1,53 @@
1
+ import type { IsEqual } from '../equal/equal.js'
2
+ import type { CanAssign } from '../index.js'
3
+ import type { Tail } from './tail.js'
4
+ import type { UnionOfValues } from './union_of_values.js'
5
+
6
+ /**
7
+ * Determines whether the array type `A` contains any elements that satisfies the specified `Criteria` type.
8
+ *
9
+ * It operates in `loose` mode by default,
10
+ * which means literal types satisfies their widened counterparts.
11
+ *
12
+ * You can also change it to `strict` mode.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * Some<string[], string> // true
17
+ * Some<['a', boolean], boolean> // true
18
+ * Some<['a', true], boolean> //true
19
+ *
20
+ * Some<['a', true], boolean, 'strict'> // false
21
+ * ```
22
+ */
23
+ export type Some<
24
+ A extends any[],
25
+ Criteria,
26
+ Mode extends 'strict' | 'loose' = 'loose',
27
+ Then = true,
28
+ Else = false
29
+ > = Mode extends 'strict' ? Some.Strict<A, Criteria, Then, Else> : Some.Loose<A, Criteria, Then, Else>
30
+
31
+ export namespace Some {
32
+ export type Strict<A extends unknown[], Criteria, Then, Else> = number extends A['length']
33
+ ? IsEqual<UnionOfValues<A>, Criteria> extends true
34
+ ? Then
35
+ : Else
36
+ : StrictTuple<A, Criteria, Then, Else>
37
+
38
+ export type StrictTuple<A extends unknown[], Criteria, Then, Else> = A['length'] extends 0
39
+ ? Else
40
+ : IsEqual<A[0], Criteria> extends true
41
+ ? Then
42
+ : StrictTuple<Tail<A>, Criteria, Then, Else>
43
+
44
+ export type Loose<A extends unknown[], Criteria, Then, Else> = number extends A['length']
45
+ ? CanAssign<UnionOfValues<A>, Criteria, Then, Else>
46
+ : LooseTuple<A, Criteria, Then, Else>
47
+
48
+ export type LooseTuple<A extends unknown[], Criteria, Then, Else> = A['length'] extends 0
49
+ ? Else
50
+ : A[0] extends Criteria
51
+ ? Then
52
+ : LooseTuple<Tail<A>, Criteria, Then, Else>
53
+ }
@@ -1,12 +1,12 @@
1
1
  import type { IsAny } from '../any/any_type.js'
2
- import type { Equal } from '../equal/equal.js'
3
- import type { Abs } from '../math/Abs.js'
4
- import type { GreaterThan } from '../math/GreaterThan.js'
5
- import type { Subtract } from '../math/Subtract.js'
2
+ import type { IsEqual } from '../equal/equal.js'
3
+ import type { Abs } from '../math/abs.js'
4
+ import type { GreaterThan } from '../math/greater_than.js'
5
+ import type { Subtract } from '../math/subtract.js'
6
6
  import type { IsNever } from '../never/never_type.js'
7
- import type { Integer } from '../number/integer.js'
8
- import type { Negative } from '../number/negative.js'
9
7
  import type { StrictNumberType } from '../number/strict_number_type.js'
8
+ import type { Integer } from '../numeric/integer.js'
9
+ import type { Negative } from '../numeric/negative.js'
10
10
 
11
11
  /**
12
12
  * Gets the normalized index to access the element of an array or tuple.
@@ -19,7 +19,13 @@ import type { StrictNumberType } from '../number/strict_number_type.js'
19
19
  * type R = IndexAt<['a', 'b', 'c'], -4> // never
20
20
  * ```
21
21
  */
22
- export type IndexAt<A extends Array<unknown>, N extends number, Fail = never> = Equal<
22
+ export type IndexAt<
23
+ A extends Array<unknown>,
24
+ N extends number,
25
+ Fail = never,
26
+ Upper = A['length'],
27
+ Lower = 0
28
+ > = IsEqual<
23
29
  A['length'],
24
30
  0,
25
31
  Fail,
@@ -32,8 +38,8 @@ export type IndexAt<A extends Array<unknown>, N extends number, Fail = never> =
32
38
  // A: tuple
33
39
  Negative<
34
40
  N,
35
- GreaterThan<Abs<N>, A['length']> extends true ? Fail : Subtract<A['length'], Abs<N>>,
36
- GreaterThan<A['length'], N> extends true ? N : Fail
41
+ GreaterThan<Abs<N>, A['length']> extends true ? Lower : Subtract<A['length'], Abs<N>>,
42
+ GreaterThan<A['length'], N> extends true ? N : Upper
37
43
  >
38
44
  >,
39
45
  // N: number or float
@@ -61,7 +67,7 @@ export type IndexAt<A extends Array<unknown>, N extends number, Fail = never> =
61
67
  * ```
62
68
  */
63
69
  export type IsIndexOutOfBound<A extends unknown[], N extends number, Then = true, Else = false> = IsNever<
64
- IndexAt<A, N>,
70
+ IndexAt<A, N, never, never, never>,
65
71
  Then,
66
72
  Else
67
73
  >
@@ -0,0 +1,47 @@
1
+ import type { IndexAt } from './array_index.js'
2
+ import { ArrayType } from './array_type.js'
3
+
4
+ /**
5
+ * Splits an array into two at the specified `Index`.
6
+ *
7
+ * If the `Index` is out of bounds,
8
+ * it will set to the boundary value, similar to `array.splice()`.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * SplitAt<[1, 2, 3, 4, 5], 0> // [[], [1, 2, 3, 4, 5]]
13
+ * SplitAt<[1, 2, 3, 4, 5], -5> // [[], [1, 2, 3, 4, 5]]
14
+ *
15
+ * SplitAt<[1, 2, 3, 4, 5], 2> // [[1, 2], [3, 4, 5]]
16
+ *
17
+ * SplitAt<[1, 2, 3, 4, 5], 4> // [[1, 2, 3, 4], [5]]
18
+ * SplitAt<[1, 2, 3, 4, 5], -1> // [[1, 2, 3, 4], [5]]
19
+ *
20
+ * SplitAt<[1, 2, 3, 4, 5], 5> // [[1, 2, 3, 4, 5], []]
21
+ *
22
+ * // out of bound resets to boundary
23
+ * SplitAt<[1, 2, 3, 4, 5], 6> // [[1, 2, 3, 4, 5], []]
24
+ * SplitAt<[1, 2, 3, 4, 5], -6> // [[], [1, 2, 3, 4, 5]]
25
+ * ```
26
+ */
27
+ export type SplitAt<A extends unknown[], Index extends number> = ArrayType<
28
+ A,
29
+ [A, A],
30
+ ArraySplitAtDevice<A, [], IndexAt<A, Index>>
31
+ >
32
+
33
+ /**
34
+ * Splits an array into two at the specified `Index`.
35
+ * The device does not work on negative index nor out of bound index.
36
+ *
37
+ * @internal
38
+ */
39
+ export type ArraySplitAtDevice<
40
+ A extends unknown[],
41
+ B extends unknown[],
42
+ Index extends number
43
+ > = Index extends B['length']
44
+ ? [B, A]
45
+ : A extends [infer Head, ...infer Tail]
46
+ ? ArraySplitAtDevice<Tail, [...B, Head], Index>
47
+ : never
@@ -1,2 +1,10 @@
1
- export type { At, Concat } from './array.js'
1
+ export type { At } from './array.at.js'
2
+ export type { Concat } from './array.concat.js'
3
+ export type { Entries } from './array.entries.js'
4
+ export type { FindFirst as Find } from './array.find.js'
5
+ export type { FindLast } from './array.find_last.js'
6
+ export type { Reverse } from './array.reverse.js'
7
+ export type { Some } from './array.some.js'
2
8
  export type { IndexAt, IsIndexOutOfBound } from './array_index.js'
9
+ export type { SplitAt } from './array_plus.split_at.js'
10
+ export type { PadStart } from './pad_start.js'
package/ts/array/drop.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Equal } from '../equal/equal.js'
1
+ import type { IsEqual } from '../equal/equal.js'
2
2
  import type { NonNull, NonUndefined } from '../utils/index.js'
3
3
 
4
4
  export type DropFirst<A extends any[]> = number extends A['length']
@@ -21,7 +21,7 @@ export type DropLast<A extends any[]> = number extends A['length']
21
21
  ? Heads
22
22
  : never
23
23
 
24
- type ExcludeUnionOfEmptyTuple<A> = Equal<A, []> extends true ? A : Exclude<A, []>
24
+ type ExcludeUnionOfEmptyTuple<A> = IsEqual<A, []> extends true ? A : Exclude<A, []>
25
25
 
26
26
  /**
27
27
  * drops entries matching `Criteria` in array or tuple `A`.
package/ts/array/index.ts CHANGED
@@ -1,17 +1,16 @@
1
1
  export * from './common_prop_keys.js'
2
- export * from './create_tuple.js'
3
2
  export * from './drop.js'
4
3
  export * from './filter.js'
5
- export * from './find_first.js'
6
- export * from './find_last.js'
4
+ export * from './array.find.js'
5
+ export * from './array.find_last.js'
7
6
  export * from './head.js'
8
7
  export * from './intersect_of_props.js'
9
8
  export * from './last.js'
10
9
  export * from './literal_array.js'
11
- export * from './pad_left.js'
10
+ export * from './pad_start.js'
12
11
  export * from './reduce_while.js'
13
12
  export * from './reverse.js'
14
- export * from './some.js'
13
+ export * from './array.some.js'
15
14
  export * from './tail.js'
16
15
  export * from './union_of_props.js'
17
16
  export * from './union_of_values.js'
@@ -0,0 +1,43 @@
1
+ import type { CanAssign } from '../index.js'
2
+ import type { CreateTuple } from '../tuple/create_tuple.js'
3
+ import type { PadStart as TuplePadStart } from '../tuple/tuple_plus.pad_start.js'
4
+ import type { UnionOfValues } from './union_of_values.js'
5
+
6
+ /**
7
+ * Pads the start of an array or tuple with `PadWith`.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * // Padding array
12
+ * PadStart<number[], 1, string> // [string, ...number[]]
13
+ *
14
+ * // Ignore if the type is compatible
15
+ * PadStart<number[], 2, number> // number[]
16
+ * PadStart<number[], 3, 1> // number[]
17
+ *
18
+ * // Padding tuple
19
+ * PadStart<[1, 2, 3], 5, 0> // [0, 0, 1, 2, 3]
20
+ *
21
+ * // Ignore if MaxLength is less than the length of the tuple
22
+ * PadStart<[1, 2, 3], 5, 0> // [0, 0, 1, 2, 3]
23
+ *
24
+ * // Default to unknown
25
+ * PadStart<[1, 2, 3], 5> // [unknown, unknown, 1, 2, 3]
26
+ * ```
27
+ */
28
+ export type PadStart<
29
+ A extends unknown[],
30
+ MaxLength extends number,
31
+ PadWith = unknown
32
+ > = number extends A['length']
33
+ ? MaxLength extends 0
34
+ ? A
35
+ : CanAssign<PadWith, UnionOfValues<A>> extends true
36
+ ? A
37
+ : PadStart<[...CreateTuple<MaxLength, PadWith>, ...A], MaxLength, PadWith>
38
+ : TuplePadStart<A, MaxLength, PadWith>
39
+
40
+ /**
41
+ * @deprecated use PadStart instead
42
+ */
43
+ export type PadLeft<A extends any[], Total extends number, PadWith = any> = PadStart<A, Total, PadWith>
@@ -19,10 +19,190 @@ type R = ArrayType<number[] | 1> // never
19
19
  type R = ArrayType<number[] & { a: 1 }> // never
20
20
  ```
21
21
 
22
- - [`ArrayType<T, Then = T, Else = never>`](array_type.ts#L15): check if `T` is exactly `Array<X>`.
23
- - [`IsArray<T, Then = true, Else = false`](array_type.ts#L33): is `T` exactly `Array<X>`.
24
- - [`NotArrayType<T, Then = T, Else = never>`](array_type.ts#L47): check if `T` is not exactly `Array<X>`.
25
- - [`IsNotArray<T, Then = true, Else = false>`](array_type.ts#L61): is `T` not exactly `Array<X>`.
22
+ - [`ArrayType<T, Then = T, Else = never>`](array_type.ts#L15): check if `T` is an array and not a tuple.
23
+ - [`IsArray<T, Then = true, Else = false`](array_type.ts#L33): is `T` an array and not a tuple.
24
+ - [`NotArrayType<T, Then = T, Else = never>`](array_type.ts#L47): check if `T` is not an array (can be a tuple).
25
+ - [`IsNotArray<T, Then = true, Else = false>`](array_type.ts#L61): is `T` not an array (can be a tuple).
26
+
27
+ ## ArrayPlus
28
+
29
+ `ArrayPlus` contains all types and type utilities related to array.
30
+ Whenever possible, these types and type utilities also work with *tuples*,
31
+ as *tuples* is a subset of array.
32
+
33
+ For *tuple* specific types and type utilities,
34
+ please check [`TuplePlus`](../tuple/readme.md#TuplePlus).
35
+
36
+ ### [`ArrayPlus.At`](./array.at.ts#L18)
37
+
38
+ > `ArrayPlus.At<A, N, Fail = never>`
39
+
40
+ Gets the type of the array or tuple `A` at index `N`.
41
+
42
+ For array, it will return the union of the type of the array value and `undefined`,
43
+ as there is no way to guarantee the array has value at `N`.
44
+
45
+ ```ts
46
+ type A = Array<string | number>
47
+
48
+ ArrayPlus.At<A, 0> // string | number | undefined
49
+ ```
50
+
51
+ For tuple, it will return the type of the tuple value at index `N`.
52
+
53
+ ```ts
54
+ type T = [number, string, 1, 2, 3]
55
+
56
+ ArrayPlus.At<T, 0> // number
57
+ ArrayPlus.At<T, -1> // 3
58
+ ```
59
+
60
+ If the `N` is out of bound,
61
+ or `N` is not a valid index,
62
+ `ArrayPlus.At` will return the `Fail` case, which defaults to `never`.
63
+
64
+ ### [`ArrayPlus.Concat`](./array.concat.ts#L12)
65
+
66
+ > `ArrayPlus.Concat<A, B>`
67
+
68
+ Concats two arrays or tuples.
69
+
70
+ It is just an alias of `[...A, ...B]`.
71
+ It is added for completeness.
72
+
73
+ You are encouraged to use `[...A, ...B]` directly.
74
+
75
+ ### [`ArrayPlus.Entries`](./array.entries.ts#L14)
76
+
77
+ > `ArrayPlus.Entries<A>`
78
+
79
+ Returns an array of key-value pairs for every entry in the array or tuple.
80
+
81
+ Note that this is not the same as `Array.entries(A)`,
82
+ which returns an iterable interator.
83
+
84
+ ```ts
85
+ ArrayPlus.Entries<Array<string | number>> // Array<[number, string | number]>
86
+ ArrayPlus.Entries<[1, 2, 3]> // [[0, 1], [1, 2], [2, 3]]
87
+ ```
88
+
89
+ ### [`ArrayPlus.Find`](./array.find.ts#L17)
90
+
91
+ > `ArrayPlus.Find<A, Criteria>
92
+
93
+ Returns the first type in the array or tuple that matches the `Criteria`.
94
+
95
+ If the `Criteria` is not met, it will return `never'.
96
+
97
+ For `Array<T>`, it will return `T | undefined` if `T` satisfies `Criteria`.
98
+
99
+ ```ts
100
+ ArrayPlus.Find<Array<1 | 2 | 'x'>, number> // 1 | 2 | undefined
101
+
102
+ ArrayPlus.Find<[true, 1, 'x', 3], string> // 'x'
103
+ ```
104
+
105
+ ### [`ArrayPlus.FindLast`](./array.find_last.ts#L17)
106
+
107
+ > `ArrayPlus.FindLast<A, Criteria>
108
+
109
+ Returns the last type in the array or tuple that matches the `Criteria`.
110
+
111
+ If the `Criteria` is not met, it will return `never'.
112
+
113
+ For `Array<T>`, it will return `T | undefined` if `T` satisfies `Criteria`.
114
+
115
+ ```ts
116
+ ArrayPlus.FindLast<Array<1 | 2 | 'x'>, number> // 1 | 2 | undefined
117
+
118
+ ArrayPlus.FindLast<[true, 123, 'x', 321], number> // 321
119
+ ```
120
+
121
+ ### [`ArrayPlus.Reverse`](./array.reverse.ts#L14)
122
+
123
+ > `ArrayPlus.Reverse<A>`
124
+
125
+ Reverses the order of the array or tuple.
126
+
127
+ ```ts
128
+ ArrayPlus.Reverse<[1, 2, 3]> // [3, 2, 1]
129
+ ```
130
+
131
+ ### [`ArrayPlus.SplitAt`](./array_plus.split_at.ts#L22)
132
+
133
+ > `ArrayPlus.SplitAt<A, Index>`
134
+
135
+ Splits the array or tuple at `Index`.
136
+
137
+ ```ts
138
+ ArrayPlus.SplitAt<[1, 2, 3], 1> // [[1, 2], [3]]
139
+ ```
140
+
141
+ ### [`ArrayPlus.Some`](./array.some.ts#L23)
142
+
143
+ > `ArrayPlus.Some<A, Criteria, Mode, Then, Else>`
144
+
145
+ Determines whether the array type `A` contains any elements that satisfies the specified `Criteria` type.
146
+
147
+ It operates in `loose` mode by default,
148
+ which means literal types satisfies their widened counterparts.
149
+ You can also change it to `strict` mode.
150
+
151
+ ```ts
152
+ Some<string[], string> // true
153
+ Some<['a', boolean], boolean> // true
154
+ Some<['a', true], boolean> //true
155
+
156
+ Some<['a', true], boolean, 'strict'> // false
157
+ ```
158
+
159
+ ## Builtin array methods
160
+
161
+ JavaScript has many builtin array methods.
162
+ We will try to bring them to the type-level.
163
+
164
+ Not all methods can be implemented in the type-level,
165
+ or in the same way.
166
+
167
+ For example, type-level does not support higher-level generics,
168
+ i.e. it is not possible to pass in a generic type and "invoke" it.
169
+
170
+ Therefore, methods like `map` and `reduce()` cannot be implemented generically.
171
+ They have to be implemented separately for each specific use case,
172
+ or with reduced capability.
173
+
174
+ They are exposed under the `ArrayPlus` namespace,
175
+ while some common ones are exposed at top-level.
176
+
177
+ Here are the list of array methods and their corresponding type-level functions, if availableL
178
+
179
+ - ✅ `at`: [`ArrayPlus.At`](#arrayplusat)
180
+ - ✅ `concat`: [`Concat` | `ArrayPlus.Concat`](#arrayplusconcat) (`[...A, ...B]`)
181
+ - 🚧 `copyWithin`: `CopyWithin<A, Target, Start, End>`
182
+ - ✴️ `entries`: [`ArrayPlus.Entries`](#arrayplusentries)
183
+ - 🚧 `every`: `Every<A, Criteria, Then = A, Else = never>`
184
+ - 🚧 `fill`: `Fill<A, V, Start, End>`
185
+ - ✴️ `find`: [`FindFirst` | `ArrayPlus.Find`](#arrayplusfind)
186
+ - ✴️ [`FindLast` | `ArrayPlus.FindLast`](#arrayplusfindlast)
187
+ - 🚧 `findIndex`: `FindIndex<A, Criteria> => number | number literal | never`
188
+ - 🚧 `flat`: `Flat<A>`
189
+ - 🚧 `flatMap`: `Flat<A, Criteria, R>`
190
+ - 🚧 `includes`:
191
+ - 🚧 `join`:
192
+ - 🚧 `keys`: `Range<0, T['length']>`?
193
+ - 🚧 `map`: `Map<A, Criteria, R>`
194
+ - 🚧 `pop`: `Pop<A>`
195
+ - 🧬 `push`: `[...A, T]`
196
+ - 🚧 `reduce`:
197
+ - 🚧 `reduceRight`:
198
+ - ✅ `reverse`: [`ArrayPlus.Reverse`](#arrayplusreverse)
199
+ - 🚧 `shift`:
200
+ - 🚧 `slice`:
201
+ - ✴️ `some`: [`Some` | `ArrayPlus.Some`](#arrayplussome)
202
+ - 🚧 `sort`:
203
+ - 🚧 `splice`:
204
+ - 🧬 `unshift`: `[T, ...A]`
205
+ - 🧬 `values`: `keyof A`
26
206
 
27
207
  ## References
28
208
 
@@ -8,6 +8,9 @@ import { AnyFunction } from '../function/any_function.js'
8
8
  */
9
9
  export function assertType<T>(subject: T): asserts subject is T
10
10
  export function assertType<T>(subject: unknown, validator: (s: T) => boolean): asserts subject is T
11
+ /**
12
+ * @deprecated this is not a failsafe test
13
+ */
11
14
  export function assertType<T extends new (...args: any) => any>(
12
15
  subject: unknown,
13
16
  constructor: T
@@ -78,6 +81,9 @@ assertType.noFunction = function <S>(subject: Exclude<S, AnyFunction>): void {
78
81
  if (typeof subject === 'function') throw TypeError(`subject is function`)
79
82
  }
80
83
 
84
+ /**
85
+ * @deprecated
86
+ */
81
87
  assertType.isConstructor = function (subject: AnyConstructor): asserts subject is AnyConstructor {
82
88
  if (!isConstructor(subject)) throw TypeError(`subject is not a constructor`)
83
89
  }