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
@@ -1,12 +1,143 @@
1
- # Assertion Functions
1
+ # Assertion
2
2
 
3
3
  [Assertion Functions][assertion_functions] are special functions that asserts certain conditions of your program.
4
4
 
5
+ It is introduced in TypeScript 3.7.
6
+
5
7
  They throw an error if the condition is not met, and return nothing otherwise.
6
8
 
7
9
  These assertion functions are typically used in runtime,
8
10
  so that that type of the value can be narrowed down.
9
11
 
12
+ ## assertType
13
+
14
+ `assertType<T>(subject)`:
15
+
16
+ ✔️ `immediate`
17
+
18
+ It ensures `subject` satisfies `T`.
19
+ It is similar to `const x: T = subject` without introducing an unused variable.
20
+ You need to specify `T` for it to work.
21
+
22
+ `assertType<T>(subject, validator)`:
23
+
24
+ `assertType<T>(subject, Class)`:
25
+
26
+ ✔️ `assertion function`, `runtime`
27
+
28
+ These overloads of `assertType` allow you to specify a `validator`.
29
+ With these overloads, `subject` can be `unknown` or `any`.
30
+
31
+ If `subject` fails the assertion,
32
+ a standard `TypeError` will be thrown and provide better error info.
33
+ For example:
34
+
35
+ ```ts
36
+ const s: unknown = 1
37
+
38
+ // TypeError: subject fails to satisfy s => typeof s === 'boolean'
39
+ assertType<boolean>(s, s => typeof s === 'boolean')
40
+ ```
41
+
42
+ The message beautification is provided by [`tersify`](https://github.com/unional/tersify).
43
+
44
+ `assertType.isUndefined(subject)`:
45
+
46
+ `assertType.isNull(subject)`:
47
+
48
+ `assertType.isNumber(subject)`:
49
+
50
+ `assertType.isBoolean(subject)`:
51
+
52
+ `assertType.isTrue(subject)`:
53
+
54
+ `assertType.isFalse(subject)`:
55
+
56
+ `assertType.isString(subject)`:
57
+
58
+ `assertType.isFunction(subject)`:
59
+
60
+ `assertType.isConstructor(subject)`:
61
+
62
+ `assertType.isError(subject)`:
63
+
64
+ ✔️ `immediate`, `assertion function`, `runtime`
65
+
66
+ Compiler and runtime assertion with type narrowing from `any`.
67
+ They assert the type of `subject` is that specific type.
68
+ i.e. union type will fail at type level:
69
+
70
+ ```ts
71
+ const s: number | undefined = undefined
72
+ assertType.isUndefined(s) // TypeScript complains
73
+ ```
74
+
75
+ They accept `any` and will be narrowed to the specific type.
76
+
77
+ ```ts
78
+ const s: any = undefined
79
+ assertType.isUndefined(s)
80
+ s // type is undefined
81
+ ```
82
+
83
+ `assertType.isNever(subject)`:
84
+
85
+ ✔️ `immediate`
86
+
87
+ Check if the subject type is `never`.
88
+ This function is not very useful in actual code as TypeScript will indicate the error.
89
+ But it can be useful when writing tests for types.
90
+
91
+ This is useful for variables. For type level only check, do the following:
92
+
93
+ ```ts
94
+ assertType.isTrue(true as Equal<YourType, never>)
95
+ ```
96
+
97
+ `assertType.noUndefined(subject)`:
98
+
99
+ `assertType.noNull(subject)`:
100
+
101
+ `assertType.noNumber(subject)`:
102
+
103
+ `assertType.noBoolean(subject)`:
104
+
105
+ `assertType.noTrue(subject)`:
106
+
107
+ `assertType.noFalse(subject)`:
108
+
109
+ `assertType.noString(subject)`:
110
+
111
+ `assertType.noFunction(subject)`:
112
+
113
+ `assertType.noError(subject)`:
114
+
115
+ ✔️ `immediate`, `runtime`
116
+
117
+ Compiler and runtime assertion.
118
+ Assert `subject` type does not contain the specific type.
119
+ Work against unions.
120
+
121
+ ```ts
122
+ const s: number | undefined = 1
123
+ assertType.noUndefined(s) // TypeScript complains
124
+ ```
125
+
126
+ They accept `subject` with type `any` or `unknown`,
127
+ the assertion will happen in runtime to ensure `subject` is the specific type.
128
+
129
+ `assertType.as<T>(subject)`:
130
+
131
+ ✔️ `immediate`
132
+
133
+ Assert `subject` as `T` inline.
134
+ This is useful to help TypeScript to adjust the type on the fly.
135
+
136
+ ```ts
137
+ let s: number | undefined = 1
138
+ assertType.as<1>(s) // `s` type is now `1`
139
+ ```
140
+
10
141
  ## References
11
142
 
12
143
  - [Handbook][assertion_functions]
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Cast a string to a bigint literal type if possible.
3
+ *
4
+ * ```ts
5
+ * StringToBigint<'1n'> // 1n
6
+ * StringToBigint<'-1n'> // -1n
7
+ * ```
8
+ */
9
+ export type StringToBigint<S extends string, Fail = never> = S extends `-0n`
10
+ ? 0n
11
+ : S extends `${infer N extends bigint}n`
12
+ ? N
13
+ : Fail
@@ -4,45 +4,45 @@
4
4
 
5
5
  ## Type Checking
6
6
 
7
- The `BigIntType<T>` and friends are used to check if a type is `bigint` or not.
7
+ The `BigintType<T>` and friends are used to check if a type is `bigint` or not.
8
8
 
9
9
  They are loose type checks, meaning they match `bigint` and bigint literals,
10
10
  as well as intersection types.
11
11
 
12
12
  ```ts
13
- import type { BigIntType } from 'type-plus'
13
+ import type { BigintType } from 'type-plus'
14
14
 
15
- type R = BigIntType<bigint> // bigint
15
+ type R = BigintType<bigint> // bigint
16
16
 
17
- type R = BigIntType<1n> // bigint
18
- type R = BigIntType<bigint & { a: 1}> // bigint
17
+ type R = BigintType<1n> // bigint
18
+ type R = BigintType<bigint & { a: 1}> // bigint
19
19
  ```
20
20
 
21
- - [`BigIntType<T, Then = T, Else = never>`](bigint_type.ts#L15): check if `T` is `bigint` or bigint literal.
22
- - [`IsBigInt<T, Then = true, Else = false`](bigint_type.ts#L33): is `T` `bigint`.
23
- - [`NotBigIntType<T, Then = T, Else = never>`](bigint_type.ts#L47): check if `T` is not `bigint`.
21
+ - [`BigintType<T, Then = T, Else = never>`](bigint_type.ts#L15): check if `T` is `bigint` or bigint literal.
22
+ - [`IsBigint<T, Then = true, Else = false`](bigint_type.ts#L33): is `T` `bigint`.
23
+ - [`NotBigintType<T, Then = T, Else = never>`](bigint_type.ts#L47): check if `T` is not `bigint`.
24
24
  - [`IsNotBigInt<T, Then = true, Else = false>`](bigint_type.ts#L61): is `T` not `bigint`.
25
25
 
26
26
  ---
27
27
 
28
- The `StrictBigIntType<T>` and friends are used to check if a type is exactly `bigint` or not.
28
+ The `StrictBigintType<T>` and friends are used to check if a type is exactly `bigint` or not.
29
29
 
30
30
  They are strict type checks, meaning they match only the type `bigint`,
31
31
  and not bigint literals or intersection types.
32
32
 
33
33
  ```ts
34
- import type { StrictBigIntType } from 'type-plus'
34
+ import type { StrictBigintType } from 'type-plus'
35
35
 
36
- type R = StrictBigIntType<bigint> // bigint
36
+ type R = StrictBigintType<bigint> // bigint
37
37
 
38
- type R = StrictBigIntType<1n> // never
39
- type R = StrictBigIntType<bigint & { a: 1}> // never
38
+ type R = StrictBigintType<1n> // never
39
+ type R = StrictBigintType<bigint & { a: 1}> // never
40
40
  ```
41
41
 
42
- - [`StrictBigIntType<T, Then = T, Else = never>`](strict_bigint_type.ts#L15): check if `T` is exactly `bigint`.
43
- - [`IsStrictBigInt<T, Then = true, Else = false`](strict_bigint_type.ts#L33): is `T` exactly `bigint`.
44
- - [`NotStrictBigIntType<T, Then = T, Else = never>`](strict_bigint_type.ts#L47): check if `T` is not exactly `bigint`.
45
- - [`IsNotStrictBigInt<T, Then = true, Else = false>`](strict_bigint_type.ts#L61): is `T` not exactly `bigint`.
42
+ - [`StrictBigintType<T, Then = T, Else = never>`](strict_bigint_type.ts#L15): check if `T` is exactly `bigint`.
43
+ - [`IsStrictBigint<T, Then = true, Else = false`](strict_bigint_type.ts#L33): is `T` exactly `bigint`.
44
+ - [`NotStrictBigintType<T, Then = T, Else = never>`](strict_bigint_type.ts#L47): check if `T` is not exactly `bigint`.
45
+ - [`IsNotStrictBigint<T, Then = true, Else = false>`](strict_bigint_type.ts#L61): is `T` not exactly `bigint`.
46
46
 
47
47
  ## References
48
48
 
package/ts/equal/equal.ts CHANGED
@@ -37,8 +37,12 @@ type IdentityEqual<A, B, Then, Else> = (<_>() => _ extends (A & _) | _ ? 1 : 2)
37
37
  * type R = Equal<[any], [1]> // false
38
38
  * type R = Equal<{ a: 1 }, { a: 1; b: 2 }> // false
39
39
  * ```
40
+ *
41
+ * Note that intersection type checks only works at first level.
42
+ * It cannot be check recursively,
43
+ * or else will run into infinite recursion if the type includes recursive types.
40
44
  */
41
- export type Equal<A, B, Then = true, Else = false> = [A, B] extends [B, A]
45
+ export type IsEqual<A, B, Then = true, Else = false> = [A, B] extends [B, A]
42
46
  ? BothNever<
43
47
  A,
44
48
  B,
@@ -60,7 +64,7 @@ export type Equal<A, B, Then = true, Else = false> = [A, B] extends [B, A]
60
64
  Properties<A>,
61
65
  Properties<B>,
62
66
  [A, B] extends [(...args: infer P1) => any, (...args: infer P2) => any]
63
- ? Equal<P1, P2, Then, Else>
67
+ ? IsEqual<P1, P2, Then, Else>
64
68
  : Then,
65
69
  Else
66
70
  >,
@@ -88,5 +92,51 @@ export type Equal<A, B, Then = true, Else = false> = [A, B] extends [B, A]
88
92
  * type R = NotEqual<[any], [1]> // true
89
93
  * type R = NotEqual<{ a: 1 }, { a: 1; b: 2 }> // true
90
94
  * ```
95
+ *
96
+ * Note that intersection type checks only works at first level.
97
+ * It cannot be check recursively,
98
+ * or else will run into infinite recursion if the type includes recursive types.
99
+ */
100
+ export type IsNotEqual<A, B, Then = true, Else = false> = IsEqual<A, B, Else, Then>
101
+
102
+ /**
103
+ * Checks `A` and `B` are equal.
104
+ *
105
+ * @deprecated this will be changed to `filter` variant in the future.
106
+ * Please use `IsEqual` for the `predicate` behavior.
107
+ *
108
+ * ```ts
109
+ * type R = Equal<1, 1> // true
110
+ * type R = Equal<any, any> // true
111
+ * type R = Equal<boolean, boolean> // true
112
+ * type R = Equal<true, true> // true
113
+ * type R = Equal<[1], [1]> // true
114
+ *
115
+ * type R = Equal<boolean, true> // false
116
+ * type R = Equal<any, 1> // false
117
+ * type R = Equal<[any], [1]> // false
118
+ * type R = Equal<{ a: 1 }, { a: 1; b: 2 }> // false
119
+ * ```
120
+ */
121
+ export type Equal<A, B, Then = true, Else = false> = IsEqual<A, B, Then, Else>
122
+
123
+ /**
124
+ * Checks `A` and `B` are not equal.
125
+ *
126
+ * @deprecated this will be changed to `filter` variant in the future.
127
+ * Please use `IsNotEqual` for the `predicate` behavior.
128
+ *
129
+ * ```ts
130
+ * type R = NotEqual<1, 1> // false
131
+ * type R = NotEqual<any, any> // false
132
+ * type R = NotEqual<boolean, boolean> // false
133
+ * type R = NotEqual<true, true> // false
134
+ * type R = NotEqual<[1], [1]> // false
135
+ *
136
+ * type R = NotEqual<boolean, true> // true
137
+ * type R = NotEqual<any, 1> // true
138
+ * type R = NotEqual<[any], [1]> // true
139
+ * type R = NotEqual<{ a: 1 }, { a: 1; b: 2 }> // true
140
+ * ```
91
141
  */
92
- export type NotEqual<A, B, Then = true, Else = false> = Equal<A, B, Else, Then>
142
+ export type NotEqual<A, B, Then = true, Else = false> = IsNotEqual<A, B, Then, Else>
@@ -1,27 +1,41 @@
1
- # Equal
1
+ # IsEqual
2
2
 
3
- `Equal<A, B>` and friends check if `A` and `B` are equal.
3
+ `IsEqual<A, B>` and friends check if `A` and `B` are equal.
4
4
 
5
5
  It is a type-level version of `===`.
6
6
  It handles special types (`any`, `unknown`, `never`, `void`) correctly.
7
7
 
8
8
  ```ts
9
- import { type Equal } from 'type-plus'
10
-
11
- type R = Equal<1, 1> // true
12
- type R = Equal<any, any> // true
13
- type R = Equal<boolean, boolean> // true
14
- type R = Equal<true, true> // true
15
- type R = Equal<[1], [1]> // true
16
-
17
- type R = Equal<boolean, true> // false
18
- type R = Equal<any, 1> // false
19
- type R = Equal<[any], [1]> // false
20
- type R = Equal<{ a: 1 }, { a: 1; b: 2 }> // false
9
+ import { type IsEqual } from 'type-plus'
10
+
11
+ type R = IsEqual<1, 1> // true
12
+ type R = IsEqual<any, any> // true
13
+ type R = IsEqual<boolean, boolean> // true
14
+ type R = IsEqual<true, true> // true
15
+ type R = IsEqual<[1], [1]> // true
16
+
17
+ type R = IsEqual<boolean, true> // false
18
+ type R = IsEqual<any, 1> // false
19
+ type R = IsEqual<[any], [1]> // false
20
+ type R = IsEqual<{ a: 1 }, { a: 1; b: 2 }> // false
21
21
  ```
22
22
 
23
- - [`Equal<A, B, Then = true, Else = false>`](equal.ts#L27): check if `A` and `B` are equal.
24
- - [`NotEqual<A, B, Then = true, Else = false>`](equal.ts#L88): check if `A` and `B` are not equal.
23
+ Note that intersection type checks only works at first level.
24
+ It cannot be check recursively,
25
+ or else will run into infinite recursion if the type includes recursive types.
26
+
27
+ i.e.
28
+
29
+ ```ts
30
+ // true
31
+ IsEqual<{ a: 1 } & { b: 2 }, { a: 1; b: 2 }>
32
+
33
+ // false
34
+ IsEqual<{ nested: { a: number; b: string } }, { nested: { a: number } & { b: string } }>
35
+ ```
36
+
37
+ - [`IsEqual<A, B, Then = true, Else = false>`](equal.ts#L27): check if `A` and `B` are equal.
38
+ - [`IsNotEqual<A, B, Then = true, Else = false>`](equal.ts#L88): check if `A` and `B` are not equal.
25
39
 
26
40
  ---
27
41
 
@@ -1,5 +1,5 @@
1
1
  import type { Brand } from '../nominal/index.js'
2
- import type { Equal } from '../equal/equal.js'
2
+ import type { IsEqual } from '../equal/equal.js'
3
3
  import type { Widen } from '../utils/index.js'
4
4
 
5
5
  export type Maybe<T> = Just<T> | None<T>
@@ -8,7 +8,7 @@ export type None<T> = Brand<'maybe', void> & { unwrap(): T }
8
8
 
9
9
  export function just<T>(
10
10
  value: T
11
- ): Equal<T, undefined | null> extends true ? None<T> : Just<Widen<NonNullable<T>>> {
11
+ ): IsEqual<T, undefined | null> extends true ? None<T> : Just<Widen<NonNullable<T>>> {
12
12
  // eslint-disable-next-line @typescript-eslint/no-unsafe-return
13
13
  return {
14
14
  unwrap() {
package/ts/index.ts CHANGED
@@ -1,12 +1,14 @@
1
1
  export { required, requiredDeep, unpartial } from 'unpartial'
2
2
  export type { IsAnyOrNever } from './any/any_or_never.js'
3
3
  export type { AnyType, IsAny, IsNotAny, NotAnyType } from './any/any_type.js'
4
- export type { At, Concat } from './array/array.js'
4
+ export type { At } from './array/array.at.js'
5
+ export type { Concat } from './array/array.concat.js'
5
6
  export * as ArrayPlus from './array/array_plus.js'
6
7
  export type { ArrayType, IsArray, IsNotArray, NotArrayType } from './array/array_type.js'
7
8
  export * from './array/index.js'
8
9
  export * from './assertion/assert_type.js'
9
10
  export type { BigintType, IsBigint, IsNotBigint, NotBigintType } from './bigint/bigint_type.js'
11
+ export type { StringToBigint } from './bigint/cast.js'
10
12
  export type {
11
13
  IsNotStrictBigint,
12
14
  IsStrictBigint,
@@ -24,7 +26,7 @@ export type {
24
26
  export type { IsNotTrue, IsTrue, NotTrueType, TrueType } from './boolean/true_type.js'
25
27
  export * from './class/index.js'
26
28
  export type { ComposableTypes, NonComposableTypes } from './composable_types.js'
27
- export type { Equal, NotEqual } from './equal/equal.js'
29
+ export type { Equal, IsEqual, IsNotEqual, NotEqual } from './equal/equal.js'
28
30
  export type { AnyFunction } from './function/any_function.js'
29
31
  export * from './function/extract_function.js'
30
32
  export type { FunctionType, IsFunction, IsNotFunction, NotFunctionType } from './function/function_type.js'
@@ -36,25 +38,25 @@ export type {
36
38
  } from './function/strict_function_type.js'
37
39
  export * from './functional/index.js'
38
40
  export type { JSONArray, JSONObject, JSONPrimitive, JSONTypes } from './json.js'
39
- export type {
40
- Abs,
41
- Add,
42
- Decrement,
43
- Digit,
44
- DigitArray,
45
- GreaterThan,
46
- Increment,
47
- Max,
48
- Subtract
49
- } from './math/index.js'
41
+ export type { Abs, Add, Decrement, GreaterThan, Increment, Max, Multiply, Subtract } from './math/index.js'
42
+ export * as MathPlus from './math/math_plus.js'
50
43
  export type { IsNever, IsNotNever, Is_Never, NeverType, NotNeverType, Not_Never } from './never/never_type.js'
51
44
  export * from './nodejs/index.js'
52
45
  export * from './nominal/index.js'
53
46
  export type { IsNotNull, IsNull, NotNullType, NullType } from './null/null_type.js'
54
- export type { Integer, IsInteger, IsNotInteger, IsWhole, NotInteger } from './number/integer.js'
55
- export type { IsNegative, IsNotNegative, Negative, NotNegative } from './number/negative.js'
47
+ export type { StringToNumber } from './number/cast.js'
56
48
  export * as NumberPlus from './number/number_plus.js'
57
49
  export type { IsNotNumber, IsNumber, NotNumberType, NumberType } from './number/number_type.js'
50
+ export type {
51
+ IsNotStrictNumber,
52
+ IsStrictNumber,
53
+ NotStrictNumberType,
54
+ StrictNumberType
55
+ } from './number/strict_number_type.js'
56
+ export type { NumericToString, StringToNumeric } from './numeric/cast.js'
57
+ export type { Integer, IsInteger, IsNotInteger, IsWhole, NotInteger } from './numeric/integer.js'
58
+ export type { IsNegative, IsNotNegative, Negative, NotNegative } from './numeric/negative.js'
59
+ export * as NumericPlus from './numeric/numeric_plus.js'
58
60
  export type {
59
61
  IsNotNumeric,
60
62
  IsNumeric,
@@ -62,14 +64,8 @@ export type {
62
64
  Numeric,
63
65
  NumericType,
64
66
  Zero
65
- } from './number/numeric_type.js'
66
- export type { IsNotPositive, IsPositive, NonPositive, Positive } from './number/positive.js'
67
- export type {
68
- IsNotStrictNumber,
69
- IsStrictNumber,
70
- NotStrictNumberType,
71
- StrictNumberType
72
- } from './number/strict_number_type.js'
67
+ } from './numeric/numeric_type.js'
68
+ export type { IsNotPositive, IsPositive, NonPositive, Positive } from './numeric/positive.js'
73
69
  export * from './object/index.js'
74
70
  export type { IsNotObject, IsObject, NotObjectType, ObjectType } from './object/object_type.js'
75
71
  export * from './predicates/index.js'
@@ -87,7 +83,10 @@ export type { IsNotString, IsString, NotStringType, StringType } from './string/
87
83
  export type { IsNotSymbol, IsSymbol, NotSymbolType, SymbolType } from './symbol/symbol_type.js'
88
84
  export * from './testing/stub.js'
89
85
  export * from './testing/test_type.js'
86
+ export * from './tuple/create_tuple.js'
87
+ export * as TuplePlus from './tuple/tuple_plus.js'
90
88
  export type { IsNotTuple, IsTuple, NotTupleType, TupleType } from './tuple/tuple_type.js'
89
+ export * from './type-guard/is_type.js'
91
90
  export type { Failed, FailedT } from './type/failed.js'
92
91
  export type { NoInfer } from './type/no_infer.js'
93
92
  export type {
@@ -100,4 +99,3 @@ export type { UnionKeys } from './union_keys.js'
100
99
  export type { IsNotUnknown, IsUnknown, NotUnknownType, UnknownType } from './unknown/unknown_type.js'
101
100
  export * from './utils/index.js'
102
101
  export type { IsNotVoid, IsVoid, NotVoidType, VoidType } from './void/void_type.js'
103
-
package/ts/math/README.md CHANGED
@@ -1,7 +1,97 @@
1
- # Math
2
-
3
- ## References
4
-
5
- - [Implementing Arithmetic Within TypeScript’s Type System](https://itnext.io/implementing-arithmetic-within-typescripts-type-system-a1ef140a6f6f)
6
- - [typepark](https://github.com/kgtkr/typepark)
7
- - [typical](https://github.com/KiaraGrouwstra/typical/tree/master/src)
1
+ # Math
2
+
3
+ ## Add
4
+
5
+ > `Add<A, B>` | `MathPlus.Add<A, B>`
6
+
7
+ Performs `A + B` which can be either `number` or `bigint`.
8
+
9
+ It supports positive, negative, floating point numbers.
10
+ It will perform coerce conversion if the necessary.
11
+
12
+ ```ts
13
+ Add<1, 2> // 3
14
+ Add<1.2, -2> // -0.8
15
+ Add<1n, 2.3> // 3.3 <-- converted to `number`
16
+ Add<9007199254740992, 1> // 9007199254740993n <-- converted to `bigint`
17
+ ```
18
+
19
+ ## Subtract
20
+
21
+ > `Subtract<A, B>` | `MathPlus.Subtract<A, B>`
22
+
23
+ Performs `A - B` which can be either `number` or `bigint`.
24
+
25
+ It supports positive, negative, floating point numbers.
26
+ It will perform coerce conversion if the necessary.
27
+
28
+ ```ts
29
+ Subtract<100, 2> // 98
30
+ Subtract<1.2, 2> // -0.8
31
+ Subtract<1n, 2.3> // -1.3 <-- converted to `number`
32
+ ```
33
+
34
+ ## Multiply
35
+
36
+ > `Multiply<A, B>` | `MathPlus.Multiply<A, B>`
37
+
38
+ Performs `A * B` which can be either `number` or `bigint`.
39
+
40
+ It supports positive, negative, floating point numbers.
41
+ It will perform coerce conversion if the necessary.
42
+
43
+ ```ts
44
+ Multiply<100, 2> // 200
45
+ Multiply<1.2, 2> // 2.4
46
+ Multiply<1n, 2.3> // 2.3 <-- converted to `number`
47
+ ```
48
+
49
+ ## GreaterThan
50
+
51
+ > `GreaterThan<A, B>` | `MathPlus.GreaterThan<A, B>`
52
+
53
+ Performs `A > B` which can be either `number` or `bigint`.
54
+
55
+ ```ts
56
+ GreaterThan<100, 2> // true
57
+ GreaterThan<-1, 2> // false
58
+ GreaterThan<1.2, 2> // false
59
+ ```
60
+
61
+ ## Max
62
+
63
+ > `Max<A, B>` | `MathPlus.Max<A, B>`
64
+
65
+ Performs `Math.max(A, B)` which can be either `number` or `bigint`.
66
+
67
+ ```ts
68
+ Max<100, 2> // 100
69
+ Max<-1, 2> // 2
70
+ Max<1.2, 2> // 2
71
+ ```
72
+
73
+ ## MathPlus
74
+
75
+ `MathPlus` contains all types and type utilities related to math.
76
+
77
+ ### [`MathPlus.ToNegative`](./math.to-negative.ts#L12)
78
+
79
+ > `MathPlus.ToNegative<N>`
80
+
81
+ Converts a number or bigint `N` to negative.
82
+ If `N` is already negative, it returns itself.
83
+
84
+ ```ts
85
+ MathPlus.ToNegative<5> // -5
86
+ MathPlus.ToNegative<0> // 0
87
+ MathPlus.ToNegative<-5> // -5
88
+ ```
89
+
90
+ ## References
91
+
92
+ - [Implementing Arithmetic Within TypeScript’s Type System](https://itnext.io/implementing-arithmetic-within-typescripts-type-system-a1ef140a6f6f)
93
+ - [typepark](https://github.com/kgtkr/typepark)
94
+ - [typical](https://github.com/KiaraGrouwstra/typical/tree/master/src)
95
+
96
+ - <https://stackoverflow.com/questions/3060064/how-computer-multiplies-2-numbers>
97
+ - <https://en.wikipedia.org/wiki/Binary_multiplier>
package/ts/math/abs.ts ADDED
@@ -0,0 +1,18 @@
1
+ import type { IsBigint } from '../bigint/bigint_type.js'
2
+ import type { IsNumber } from '../number/number_type.js'
3
+
4
+ /*
5
+ * Returns the absolute value of a number or bigint `N`.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * Abs<-5> // 5
10
+ * Abs<5> // 5
11
+ * Abs<-1n> // 1n // Where `1n` is a bigint
12
+ * ```
13
+ */
14
+ export type Abs<N extends number | bigint, Fail = never> = IsNumber<
15
+ N,
16
+ [number] extends [N] ? Fail : `${N}` extends `-${infer P extends number}` ? P : N,
17
+ IsBigint<N, [bigint] extends [N] ? Fail : `${N}` extends `-${infer P extends bigint}` ? P : N, Fail>
18
+ >
package/ts/math/add.ts ADDED
@@ -0,0 +1,14 @@
1
+ import type { NumericStruct } from './numeric_struct.js'
2
+
3
+ export type Add<A extends number | bigint, B extends number | bigint, Fail = never> = [
4
+ NumericStruct.FromNumeric<A, Fail>,
5
+ NumericStruct.FromNumeric<B, Fail>
6
+ ] extends [infer MA, infer MB]
7
+ ? MA extends NumericStruct
8
+ ? MB extends NumericStruct
9
+ ? NumericStruct.ToNumeric<NumericStruct.Add<MA, MB>>
10
+ : Fail
11
+ : Fail
12
+ : never
13
+
14
+ export type Increment<N extends number | bigint> = Add<N, 1>
@@ -0,0 +1,12 @@
1
+ import type { IsPositive } from '../numeric/positive.js'
2
+ import type { Subtract } from './subtract.js'
3
+
4
+ export type GreaterThan<A extends number | bigint, B extends number | bigint, Fail = never> = Subtract<
5
+ A,
6
+ B,
7
+ 'fail'
8
+ > extends infer R extends number
9
+ ? R extends 0
10
+ ? false
11
+ : IsPositive<R>
12
+ : Fail
package/ts/math/index.ts CHANGED
@@ -1,6 +1,7 @@
1
- export type { Abs } from './Abs.js'
2
- export type { Add, Increment } from './Add.js'
3
- export type { Digit, DigitArray } from './Digit.js'
4
- export type { GreaterThan } from './GreaterThan.js'
5
- export type { Max } from './Max.js'
6
- export type { Decrement, Subtract } from './Subtract.js'
1
+ export type { Abs } from './abs.js'
2
+ // export type { Digit, DigitArray } from './Digit.js'
3
+ export type { GreaterThan } from './greater_than.js'
4
+ export type { Max } from './max.js'
5
+ export type { Add, Increment } from './add.js'
6
+ export type { Multiply } from './multiply.js'
7
+ export type { Decrement, Subtract } from './subtract.js'
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Converts a number or bigint `N` to negative.
3
+ * If `N` is already negative, it returns itself.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * ToNegative<5> // -5
8
+ * ToNegative<0> // 0
9
+ * ToNegative<-5> // -5
10
+ * ```
11
+ */
12
+ export type ToNegative<N extends number | bigint> = N extends number
13
+ ? N extends 0
14
+ ? 0
15
+ : `-${N}` extends `${infer W extends number}`
16
+ ? W
17
+ : N
18
+ : N extends 0n
19
+ ? 0n
20
+ : `-${N}` extends `${infer W extends bigint}`
21
+ ? W
22
+ : N
@@ -0,0 +1,4 @@
1
+ export type { Add, Increment } from './add.js'
2
+ export type { ToNegative } from './math_plus.to_negative.js'
3
+ export type { Multiply } from './multiply.js'
4
+ export type { Decrement, Subtract } from './subtract.js'