ts-fortress 1.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 (318) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +324 -0
  3. package/dist/array/array-of-length.d.mts +6 -0
  4. package/dist/array/array-of-length.d.mts.map +1 -0
  5. package/dist/array/array-of-length.mjs +50 -0
  6. package/dist/array/array-of-length.mjs.map +1 -0
  7. package/dist/array/array.d.mts +6 -0
  8. package/dist/array/array.d.mts.map +1 -0
  9. package/dist/array/array.mjs +39 -0
  10. package/dist/array/array.mjs.map +1 -0
  11. package/dist/array/index.d.mts +5 -0
  12. package/dist/array/index.d.mts.map +1 -0
  13. package/dist/array/index.mjs +5 -0
  14. package/dist/array/index.mjs.map +1 -0
  15. package/dist/array/non-empty-array.d.mts +6 -0
  16. package/dist/array/non-empty-array.d.mts.map +1 -0
  17. package/dist/array/non-empty-array.mjs +46 -0
  18. package/dist/array/non-empty-array.mjs.map +1 -0
  19. package/dist/array/tuple.d.mts +9 -0
  20. package/dist/array/tuple.d.mts.map +1 -0
  21. package/dist/array/tuple.mjs +47 -0
  22. package/dist/array/tuple.mjs.map +1 -0
  23. package/dist/branded/brand.d.mts +11 -0
  24. package/dist/branded/brand.d.mts.map +1 -0
  25. package/dist/branded/brand.mjs +29 -0
  26. package/dist/branded/brand.mjs.map +1 -0
  27. package/dist/branded/index.d.mts +5 -0
  28. package/dist/branded/index.d.mts.map +1 -0
  29. package/dist/branded/index.mjs +20 -0
  30. package/dist/branded/index.mjs.map +1 -0
  31. package/dist/branded/number/finite-number.d.mts +3 -0
  32. package/dist/branded/number/finite-number.d.mts.map +1 -0
  33. package/dist/branded/number/finite-number.mjs +14 -0
  34. package/dist/branded/number/finite-number.mjs.map +1 -0
  35. package/dist/branded/number/index.d.mts +17 -0
  36. package/dist/branded/number/index.d.mts.map +1 -0
  37. package/dist/branded/number/index.mjs +17 -0
  38. package/dist/branded/number/index.mjs.map +1 -0
  39. package/dist/branded/number/int.d.mts +3 -0
  40. package/dist/branded/number/int.d.mts.map +1 -0
  41. package/dist/branded/number/int.mjs +14 -0
  42. package/dist/branded/number/int.mjs.map +1 -0
  43. package/dist/branded/number/int16.d.mts +3 -0
  44. package/dist/branded/number/int16.d.mts.map +1 -0
  45. package/dist/branded/number/int16.mjs +26 -0
  46. package/dist/branded/number/int16.mjs.map +1 -0
  47. package/dist/branded/number/int32.d.mts +3 -0
  48. package/dist/branded/number/int32.d.mts.map +1 -0
  49. package/dist/branded/number/int32.mjs +22 -0
  50. package/dist/branded/number/int32.mjs.map +1 -0
  51. package/dist/branded/number/non-negative-finite-number.d.mts +3 -0
  52. package/dist/branded/number/non-negative-finite-number.d.mts.map +1 -0
  53. package/dist/branded/number/non-negative-finite-number.mjs +14 -0
  54. package/dist/branded/number/non-negative-finite-number.mjs.map +1 -0
  55. package/dist/branded/number/non-zero-finite-number.d.mts +3 -0
  56. package/dist/branded/number/non-zero-finite-number.d.mts.map +1 -0
  57. package/dist/branded/number/non-zero-finite-number.mjs +14 -0
  58. package/dist/branded/number/non-zero-finite-number.mjs.map +1 -0
  59. package/dist/branded/number/non-zero-int.d.mts +3 -0
  60. package/dist/branded/number/non-zero-int.d.mts.map +1 -0
  61. package/dist/branded/number/non-zero-int.mjs +14 -0
  62. package/dist/branded/number/non-zero-int.mjs.map +1 -0
  63. package/dist/branded/number/non-zero-safe-int.d.mts +3 -0
  64. package/dist/branded/number/non-zero-safe-int.d.mts.map +1 -0
  65. package/dist/branded/number/non-zero-safe-int.mjs +14 -0
  66. package/dist/branded/number/non-zero-safe-int.mjs.map +1 -0
  67. package/dist/branded/number/positive-finite-number.d.mts +3 -0
  68. package/dist/branded/number/positive-finite-number.d.mts.map +1 -0
  69. package/dist/branded/number/positive-finite-number.mjs +22 -0
  70. package/dist/branded/number/positive-finite-number.mjs.map +1 -0
  71. package/dist/branded/number/positive-int.d.mts +3 -0
  72. package/dist/branded/number/positive-int.d.mts.map +1 -0
  73. package/dist/branded/number/positive-int.mjs +23 -0
  74. package/dist/branded/number/positive-int.mjs.map +1 -0
  75. package/dist/branded/number/positive-safe-int.d.mts +3 -0
  76. package/dist/branded/number/positive-safe-int.d.mts.map +1 -0
  77. package/dist/branded/number/positive-safe-int.mjs +24 -0
  78. package/dist/branded/number/positive-safe-int.mjs.map +1 -0
  79. package/dist/branded/number/safe-int.d.mts +3 -0
  80. package/dist/branded/number/safe-int.d.mts.map +1 -0
  81. package/dist/branded/number/safe-int.mjs +14 -0
  82. package/dist/branded/number/safe-int.mjs.map +1 -0
  83. package/dist/branded/number/safe-uint.d.mts +3 -0
  84. package/dist/branded/number/safe-uint.d.mts.map +1 -0
  85. package/dist/branded/number/safe-uint.mjs +23 -0
  86. package/dist/branded/number/safe-uint.mjs.map +1 -0
  87. package/dist/branded/number/uint.d.mts +3 -0
  88. package/dist/branded/number/uint.d.mts.map +1 -0
  89. package/dist/branded/number/uint.mjs +22 -0
  90. package/dist/branded/number/uint.mjs.map +1 -0
  91. package/dist/branded/number/uint16.d.mts +3 -0
  92. package/dist/branded/number/uint16.d.mts.map +1 -0
  93. package/dist/branded/number/uint16.mjs +26 -0
  94. package/dist/branded/number/uint16.mjs.map +1 -0
  95. package/dist/branded/number/uint32.d.mts +3 -0
  96. package/dist/branded/number/uint32.d.mts.map +1 -0
  97. package/dist/branded/number/uint32.mjs +24 -0
  98. package/dist/branded/number/uint32.mjs.map +1 -0
  99. package/dist/branded/simple-branded-number.d.mts +3 -0
  100. package/dist/branded/simple-branded-number.d.mts.map +1 -0
  101. package/dist/branded/simple-branded-number.mjs +15 -0
  102. package/dist/branded/simple-branded-number.mjs.map +1 -0
  103. package/dist/branded/simple-branded-string.d.mts +3 -0
  104. package/dist/branded/simple-branded-string.d.mts.map +1 -0
  105. package/dist/branded/simple-branded-string.mjs +15 -0
  106. package/dist/branded/simple-branded-string.mjs.map +1 -0
  107. package/dist/compose/index.d.mts +4 -0
  108. package/dist/compose/index.d.mts.map +1 -0
  109. package/dist/compose/index.mjs +4 -0
  110. package/dist/compose/index.mjs.map +1 -0
  111. package/dist/compose/intersection.d.mts +19 -0
  112. package/dist/compose/intersection.d.mts.map +1 -0
  113. package/dist/compose/intersection.mjs +38 -0
  114. package/dist/compose/intersection.mjs.map +1 -0
  115. package/dist/compose/merge-records.d.mts +15 -0
  116. package/dist/compose/merge-records.d.mts.map +1 -0
  117. package/dist/compose/merge-records.mjs +48 -0
  118. package/dist/compose/merge-records.mjs.map +1 -0
  119. package/dist/compose/union.d.mts +14 -0
  120. package/dist/compose/union.d.mts.map +1 -0
  121. package/dist/compose/union.mjs +33 -0
  122. package/dist/compose/union.mjs.map +1 -0
  123. package/dist/enum/enum.d.mts +6 -0
  124. package/dist/enum/enum.d.mts.map +1 -0
  125. package/dist/enum/enum.mjs +34 -0
  126. package/dist/enum/enum.mjs.map +1 -0
  127. package/dist/enum/index.d.mts +3 -0
  128. package/dist/enum/index.d.mts.map +1 -0
  129. package/dist/enum/index.mjs +3 -0
  130. package/dist/enum/index.mjs.map +1 -0
  131. package/dist/enum/uint-range.d.mts +8 -0
  132. package/dist/enum/uint-range.d.mts.map +1 -0
  133. package/dist/enum/uint-range.mjs +40 -0
  134. package/dist/enum/uint-range.mjs.map +1 -0
  135. package/dist/globals.d.mts +3 -0
  136. package/dist/index.d.mts +10 -0
  137. package/dist/index.d.mts.map +1 -0
  138. package/dist/index.mjs +50 -0
  139. package/dist/index.mjs.map +1 -0
  140. package/dist/primitives/bigint.d.mts +4 -0
  141. package/dist/primitives/bigint.d.mts.map +1 -0
  142. package/dist/primitives/bigint.mjs +12 -0
  143. package/dist/primitives/bigint.mjs.map +1 -0
  144. package/dist/primitives/boolean.d.mts +4 -0
  145. package/dist/primitives/boolean.d.mts.map +1 -0
  146. package/dist/primitives/boolean.mjs +12 -0
  147. package/dist/primitives/boolean.mjs.map +1 -0
  148. package/dist/primitives/index.d.mts +8 -0
  149. package/dist/primitives/index.d.mts.map +1 -0
  150. package/dist/primitives/index.mjs +8 -0
  151. package/dist/primitives/index.mjs.map +1 -0
  152. package/dist/primitives/null.d.mts +3 -0
  153. package/dist/primitives/null.d.mts.map +1 -0
  154. package/dist/primitives/null.mjs +11 -0
  155. package/dist/primitives/null.mjs.map +1 -0
  156. package/dist/primitives/number.d.mts +4 -0
  157. package/dist/primitives/number.d.mts.map +1 -0
  158. package/dist/primitives/number.mjs +12 -0
  159. package/dist/primitives/number.mjs.map +1 -0
  160. package/dist/primitives/string.d.mts +4 -0
  161. package/dist/primitives/string.d.mts.map +1 -0
  162. package/dist/primitives/string.mjs +12 -0
  163. package/dist/primitives/string.mjs.map +1 -0
  164. package/dist/primitives/symbol.d.mts +3 -0
  165. package/dist/primitives/symbol.d.mts.map +1 -0
  166. package/dist/primitives/symbol.mjs +11 -0
  167. package/dist/primitives/symbol.mjs.map +1 -0
  168. package/dist/primitives/undefined.d.mts +3 -0
  169. package/dist/primitives/undefined.d.mts.map +1 -0
  170. package/dist/primitives/undefined.mjs +11 -0
  171. package/dist/primitives/undefined.mjs.map +1 -0
  172. package/dist/record/index.d.mts +8 -0
  173. package/dist/record/index.d.mts.map +1 -0
  174. package/dist/record/index.mjs +8 -0
  175. package/dist/record/index.mjs.map +1 -0
  176. package/dist/record/key-value-record.d.mts +7 -0
  177. package/dist/record/key-value-record.d.mts.map +1 -0
  178. package/dist/record/key-value-record.mjs +52 -0
  179. package/dist/record/key-value-record.mjs.map +1 -0
  180. package/dist/record/keyof.d.mts +7 -0
  181. package/dist/record/keyof.d.mts.map +1 -0
  182. package/dist/record/keyof.mjs +15 -0
  183. package/dist/record/keyof.mjs.map +1 -0
  184. package/dist/record/omit.d.mts +8 -0
  185. package/dist/record/omit.d.mts.map +1 -0
  186. package/dist/record/omit.mjs +39 -0
  187. package/dist/record/omit.mjs.map +1 -0
  188. package/dist/record/optional.d.mts +5 -0
  189. package/dist/record/optional.d.mts.map +1 -0
  190. package/dist/record/optional.mjs +8 -0
  191. package/dist/record/optional.mjs.map +1 -0
  192. package/dist/record/partial.d.mts +13 -0
  193. package/dist/record/partial.d.mts.map +1 -0
  194. package/dist/record/partial.mjs +128 -0
  195. package/dist/record/partial.mjs.map +1 -0
  196. package/dist/record/pick.d.mts +8 -0
  197. package/dist/record/pick.d.mts.map +1 -0
  198. package/dist/record/pick.mjs +39 -0
  199. package/dist/record/pick.mjs.map +1 -0
  200. package/dist/record/record.d.mts +21 -0
  201. package/dist/record/record.d.mts.map +1 -0
  202. package/dist/record/record.mjs +53 -0
  203. package/dist/record/record.mjs.map +1 -0
  204. package/dist/tsconfig.json +1 -0
  205. package/dist/type.d.mts +27 -0
  206. package/dist/type.d.mts.map +1 -0
  207. package/dist/type.mjs +2 -0
  208. package/dist/type.mjs.map +1 -0
  209. package/dist/types.d.mts +2 -0
  210. package/dist/unknown.d.mts +3 -0
  211. package/dist/unknown.d.mts.map +1 -0
  212. package/dist/unknown.mjs +18 -0
  213. package/dist/unknown.mjs.map +1 -0
  214. package/dist/utils/create-assert-fn.d.mts +3 -0
  215. package/dist/utils/create-assert-fn.d.mts.map +1 -0
  216. package/dist/utils/create-assert-fn.mjs +12 -0
  217. package/dist/utils/create-assert-fn.mjs.map +1 -0
  218. package/dist/utils/create-cast-fn.d.mts +3 -0
  219. package/dist/utils/create-cast-fn.d.mts.map +1 -0
  220. package/dist/utils/create-cast-fn.mjs +13 -0
  221. package/dist/utils/create-cast-fn.mjs.map +1 -0
  222. package/dist/utils/create-is-fn.d.mts +3 -0
  223. package/dist/utils/create-is-fn.d.mts.map +1 -0
  224. package/dist/utils/create-is-fn.mjs +6 -0
  225. package/dist/utils/create-is-fn.mjs.map +1 -0
  226. package/dist/utils/create-primitive-type.d.mts +7 -0
  227. package/dist/utils/create-primitive-type.d.mts.map +1 -0
  228. package/dist/utils/create-primitive-type.mjs +24 -0
  229. package/dist/utils/create-primitive-type.mjs.map +1 -0
  230. package/dist/utils/create-type.d.mts +8 -0
  231. package/dist/utils/create-type.d.mts.map +1 -0
  232. package/dist/utils/create-type.mjs +19 -0
  233. package/dist/utils/create-type.mjs.map +1 -0
  234. package/dist/utils/index.d.mts +7 -0
  235. package/dist/utils/index.d.mts.map +1 -0
  236. package/dist/utils/index.mjs +7 -0
  237. package/dist/utils/index.mjs.map +1 -0
  238. package/dist/utils/validation-error-message.d.mts +2 -0
  239. package/dist/utils/validation-error-message.d.mts.map +1 -0
  240. package/dist/utils/validation-error-message.mjs +13 -0
  241. package/dist/utils/validation-error-message.mjs.map +1 -0
  242. package/package.json +102 -0
  243. package/src/array/array-of-length.mts +76 -0
  244. package/src/array/array-of-length.test.mts +113 -0
  245. package/src/array/array.mts +62 -0
  246. package/src/array/array.test.mts +84 -0
  247. package/src/array/index.mts +4 -0
  248. package/src/array/non-empty-array.mts +70 -0
  249. package/src/array/non-empty-array.test.mts +113 -0
  250. package/src/array/tuple.mts +72 -0
  251. package/src/array/tuple.test.mts +122 -0
  252. package/src/branded/brand.mts +70 -0
  253. package/src/branded/index.mts +4 -0
  254. package/src/branded/number/finite-number.mts +15 -0
  255. package/src/branded/number/index.mts +16 -0
  256. package/src/branded/number/int.mts +13 -0
  257. package/src/branded/number/int16.mts +25 -0
  258. package/src/branded/number/int32.mts +21 -0
  259. package/src/branded/number/non-negative-finite-number.mts +18 -0
  260. package/src/branded/number/non-zero-finite-number.mts +15 -0
  261. package/src/branded/number/non-zero-int.mts +15 -0
  262. package/src/branded/number/non-zero-safe-int.mts +15 -0
  263. package/src/branded/number/positive-finite-number.mts +23 -0
  264. package/src/branded/number/positive-int.mts +24 -0
  265. package/src/branded/number/positive-safe-int.mts +25 -0
  266. package/src/branded/number/safe-int.mts +13 -0
  267. package/src/branded/number/safe-uint.mts +24 -0
  268. package/src/branded/number/uint.mts +21 -0
  269. package/src/branded/number/uint16.mts +25 -0
  270. package/src/branded/number/uint32.mts +23 -0
  271. package/src/branded/simple-branded-number.mts +18 -0
  272. package/src/branded/simple-branded-string.mts +18 -0
  273. package/src/combination.test.mts +287 -0
  274. package/src/compose/index.mts +3 -0
  275. package/src/compose/intersection.mts +206 -0
  276. package/src/compose/intersection.test.mts +231 -0
  277. package/src/compose/merge-records.mts +218 -0
  278. package/src/compose/merge-records.test.mts +90 -0
  279. package/src/compose/union.mts +77 -0
  280. package/src/compose/union.test.mts +92 -0
  281. package/src/enum/enum.mts +53 -0
  282. package/src/enum/enum.test.mts +63 -0
  283. package/src/enum/index.mts +2 -0
  284. package/src/enum/uint-range.mts +63 -0
  285. package/src/enum/uint-range.test.mts +66 -0
  286. package/src/globals.d.mts +3 -0
  287. package/src/index.mts +9 -0
  288. package/src/primitives/bigint.mts +13 -0
  289. package/src/primitives/boolean.mts +13 -0
  290. package/src/primitives/index.mts +7 -0
  291. package/src/primitives/null.mts +9 -0
  292. package/src/primitives/number.mts +13 -0
  293. package/src/primitives/string.mts +13 -0
  294. package/src/primitives/symbol.mts +10 -0
  295. package/src/primitives/undefined.mts +9 -0
  296. package/src/record/index.mts +7 -0
  297. package/src/record/key-value-record.mts +84 -0
  298. package/src/record/key-value-record.test.mts +96 -0
  299. package/src/record/keyof.mts +31 -0
  300. package/src/record/keyof.test.mts +73 -0
  301. package/src/record/omit.mts +94 -0
  302. package/src/record/omit.test.mts +116 -0
  303. package/src/record/optional.mts +16 -0
  304. package/src/record/partial.mts +186 -0
  305. package/src/record/partial.test.mts +261 -0
  306. package/src/record/pick.mts +98 -0
  307. package/src/record/pick.test.mts +116 -0
  308. package/src/record/record.mts +105 -0
  309. package/src/record/record.test.mts +253 -0
  310. package/src/type.mts +30 -0
  311. package/src/unknown.mts +17 -0
  312. package/src/utils/create-assert-fn.mts +14 -0
  313. package/src/utils/create-cast-fn.mts +15 -0
  314. package/src/utils/create-is-fn.mts +7 -0
  315. package/src/utils/create-primitive-type.mts +35 -0
  316. package/src/utils/create-type.mts +28 -0
  317. package/src/utils/index.mts +6 -0
  318. package/src/utils/validation-error-message.mts +17 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,324 @@
1
+ # ts-fortress
2
+
3
+ TypeScript-first schema validation library with static type inference.
4
+
5
+ ts-fortress is a runtime validation library similar to [io-ts](https://github.com/gcanti/io-ts) and [zod](https://github.com/colinhacks/zod), designed to provide type-safe schema validation with excellent TypeScript integration and static type inference.
6
+
7
+ ## Features
8
+
9
+ - 🔒 **Type-safe validation** - Full TypeScript support with static type inference
10
+ - 🏗️ **Composable schemas** - Build complex validation schemas from simple building blocks
11
+ - 🎯 **Zero-runtime overhead** - Type information is inferred at compile time
12
+ - 🔄 **Result-based error handling** - Structured error reporting with `Result<T, Error[]>`
13
+ - 🏷️ **Branded types** - Rich collection of branded number types (Int, SafeInt, PositiveInt, etc.)
14
+ - ⚡ **Performance focused** - Minimal runtime overhead and optimized validation
15
+ - 🧩 **Functional composition** - Union, intersection, and merge operations for schema composition
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install ts-fortress
21
+ ```
22
+
23
+ ```bash
24
+ yarn add ts-fortress
25
+ ```
26
+
27
+ ```bash
28
+ pnpm add ts-fortress
29
+ ```
30
+
31
+ ## Quick Start
32
+
33
+ ```typescript
34
+ import * as t from 'ts-fortress';
35
+
36
+ // Define a schema
37
+ const User = t.record({
38
+ id: t.string(''),
39
+ name: t.string(''),
40
+ age: t.number(0),
41
+ email: t.string(''),
42
+ isActive: t.boolean(true),
43
+ });
44
+
45
+ // Infer TypeScript type
46
+ type User = t.TypeOf<typeof User>;
47
+ // ↑ { id: string; name: string; age: number; email: string; isActive: boolean }
48
+
49
+ // Validate data
50
+ const userData = {
51
+ id: '123',
52
+ name: 'John Doe',
53
+ age: 30,
54
+ email: 'john@example.com',
55
+ isActive: true,
56
+ };
57
+
58
+ if (User.is(userData)) {
59
+ // userData is now typed as User
60
+ console.log(`User: ${userData.name}, Age: ${userData.age}`);
61
+ }
62
+
63
+ // Get validation result with error details
64
+ const result = User.validate(userData);
65
+ if (result.isOk()) {
66
+ const user = result.value; // typed as User
67
+ } else {
68
+ console.error('Validation errors:', result.value); // string[] of error messages
69
+ }
70
+ ```
71
+
72
+ ## Core Concepts
73
+
74
+ ### Type Interface
75
+
76
+ Every validator in ts-fortress implements the `Type<A>` interface:
77
+
78
+ ```typescript
79
+ interface Type<A> {
80
+ typeName: string; // Human-readable type name
81
+ defaultValue: A; // Default value for this type
82
+ is: (a: unknown) => a is A; // Type guard function
83
+ assertIs: (a: unknown) => asserts a is A; // Type assertion
84
+ cast: (a: unknown) => A; // Cast with fallback to default
85
+ fill: (a: unknown) => A; // Fill missing values with defaults
86
+ validate: (a: unknown) => Result<A, string[]>; // Detailed validation
87
+ }
88
+ ```
89
+
90
+ ### Primitive Types
91
+
92
+ ```typescript
93
+ import * as t from 'ts-fortress';
94
+
95
+ // Basic primitives
96
+ const stringType = t.string('default');
97
+ const numberType = t.number(0);
98
+ const booleanType = t.boolean(false);
99
+ const nullType = t.nullType;
100
+ const undefinedType = t.undefinedType;
101
+
102
+ // Literal types
103
+ const statusType = t.stringLiteral('active');
104
+ const versionType = t.number(1);
105
+
106
+ // Arrays
107
+ const stringArrayType = t.array(t.string(''));
108
+ const nonEmptyArrayType = t.nonEmptyArray(t.number(0));
109
+
110
+ // Tuples
111
+ const coordinateType = t.tuple([t.number(0), t.number(0)]);
112
+ ```
113
+
114
+ ### Record Types
115
+
116
+ ```typescript
117
+ // Define object schemas
118
+ const PersonType = t.record({
119
+ firstName: t.string(''),
120
+ lastName: t.string(''),
121
+ age: t.number(0),
122
+ address: t.record({
123
+ street: t.string(''),
124
+ city: t.string(''),
125
+ zipCode: t.string(''),
126
+ }),
127
+ });
128
+
129
+ type Person = t.TypeOf<typeof PersonType>;
130
+
131
+ // Optional fields
132
+ const UserProfileType = t.record({
133
+ username: t.string(''),
134
+ bio: t.optional(t.string('')), // Optional field
135
+ settings: t.partial(
136
+ t.record({
137
+ // Partial record (all fields optional)
138
+ theme: t.string('light'),
139
+ notifications: t.boolean(true),
140
+ }),
141
+ ),
142
+ });
143
+ ```
144
+
145
+ ### Branded Types
146
+
147
+ ts-fortress provides extensive support for branded types to create domain-specific validation:
148
+
149
+ ```typescript
150
+ // Simple branded types
151
+ const UserId = t.simpleBrandedString('UserId', '');
152
+ const Weight = t.simpleBrandedNumber('Weight', 0);
153
+
154
+ type UserId = t.TypeOf<typeof UserId>; // Brand<string, 'UserId'>
155
+ type Weight = t.TypeOf<typeof Weight>; // Brand<number, 'Weight'>
156
+
157
+ // Rich number validation types
158
+ const PositiveInt = t.positiveInt(1);
159
+ const SafeInt = t.safeInt(0);
160
+ const UInt16 = t.uint16(0);
161
+
162
+ // Usage
163
+ const userIdResult = UserId.validate('user_123');
164
+ if (userIdResult.isOk()) {
165
+ const id: UserId = userIdResult.value;
166
+ }
167
+ ```
168
+
169
+ ### Union and Intersection Types
170
+
171
+ ```typescript
172
+ // Union types
173
+ const StatusType = t.union([
174
+ t.stringLiteral('pending'),
175
+ t.stringLiteral('completed'),
176
+ t.stringLiteral('failed'),
177
+ ]);
178
+
179
+ // Complex unions
180
+ const IdType = t.union([t.string(''), t.number(0)]);
181
+
182
+ // Intersection types
183
+ const TimestampedType = t.intersection([
184
+ t.record({ data: t.string('') }),
185
+ t.record({
186
+ createdAt: t.number(Date.now()),
187
+ updatedAt: t.number(Date.now()),
188
+ }),
189
+ ]);
190
+
191
+ // Merge records (similar to intersection but more specific)
192
+ const ExtendedUserType = t.mergeRecords([
193
+ PersonType,
194
+ t.record({
195
+ id: t.string(''),
196
+ email: t.string(''),
197
+ }),
198
+ ]);
199
+ ```
200
+
201
+ ### Enums
202
+
203
+ ```typescript
204
+ // String enums
205
+ const ColorEnum = t.enum(['red', 'green', 'blue'] as const);
206
+ type Color = t.TypeOf<typeof ColorEnum>; // 'red' | 'green' | 'blue'
207
+
208
+ // Numeric ranges
209
+ const DiceRoll = t.uintRange(1, 6, 1); // integers from 1 to 6
210
+ type DiceRoll = t.TypeOf<typeof DiceRoll>; // 1 | 2 | 3 | 4 | 5 | 6
211
+ ```
212
+
213
+ ## Error Handling
214
+
215
+ ts-fortress uses `Result<T, string[]>` for structured error handling:
216
+
217
+ ```typescript
218
+ const UserType = t.record({
219
+ name: t.string(''),
220
+ age: t.number(0),
221
+ });
222
+
223
+ const invalidData = { name: 123, age: 'not a number' };
224
+
225
+ const result = UserType.validate(invalidData);
226
+ if (result.isErr()) {
227
+ console.log(result.value);
228
+ // Array of error messages:
229
+ // ['Expected string at name, got number', 'Expected number at age, got string']
230
+ }
231
+
232
+ // Using assertions (throws on invalid data)
233
+ try {
234
+ UserType.assertIs(invalidData);
235
+ } catch (error) {
236
+ console.error('Validation failed:', error.message);
237
+ }
238
+ ```
239
+
240
+ ## Migration from io-ts
241
+
242
+ If you're coming from io-ts, here's how common patterns translate:
243
+
244
+ ```typescript
245
+ // io-ts style
246
+ import * as t from 'io-ts';
247
+
248
+ const UserCodec = t.type({
249
+ id: t.string,
250
+ name: t.string,
251
+ age: t.number,
252
+ });
253
+
254
+ type User = t.TypeOf<typeof UserCodec>;
255
+
256
+ // ts-fortress style
257
+ import * as t from 'ts-fortress';
258
+
259
+ const UserType = t.record({
260
+ id: t.string(''),
261
+ name: t.string(''),
262
+ age: t.number(0),
263
+ });
264
+
265
+ type User = t.TypeOf<typeof UserType>;
266
+ ```
267
+
268
+ Key differences:
269
+
270
+ - **Default values**: ts-fortress requires explicit default values for better type safety
271
+ - **Naming**: `record` instead of `type`, more explicit function names
272
+ - **Error handling**: Built-in `Result` type instead of `Either`
273
+ - **Branded types**: Rich collection of pre-built branded number types
274
+
275
+ ## API Reference
276
+
277
+ ### Primitives
278
+
279
+ - `t.string(defaultValue)` - String validation
280
+ - `t.number(defaultValue)` - Number validation
281
+ - `t.boolean(defaultValue)` - Boolean validation
282
+ - `t.nullType` / `t.undefinedType` - Null/undefined validation
283
+ - `t.stringLiteral(value)` - Literal string types
284
+
285
+ ### Collections
286
+
287
+ - `t.array(elementType, options?)` - Array validation
288
+ - `t.nonEmptyArray(elementType, options?)` - Non-empty array validation
289
+ - `t.tuple([...types])` - Fixed-length tuple validation
290
+ - `t.arrayOfLength(elementType, length, options?)` - Fixed-length array validation
291
+
292
+ ### Objects
293
+
294
+ - `t.record(schema, options?)` - Object validation
295
+ - `t.partial(recordType)` - Make all fields optional
296
+ - `t.optional(type)` - Optional field wrapper
297
+ - `t.pick(recordType, keys)` - Pick specific fields
298
+ - `t.omit(recordType, keys)` - Omit specific fields
299
+
300
+ ### Composition
301
+
302
+ - `t.union(types, options?)` - Union type validation
303
+ - `t.intersection(types)` - Intersection type validation
304
+ - `t.mergeRecords(recordTypes)` - Merge multiple record types
305
+
306
+ ### Branded Types
307
+
308
+ - `t.simpleBrandedString(brandName, defaultValue)` - Simple string branding
309
+ - `t.simpleBrandedNumber(brandName, defaultValue)` - Simple number branding
310
+ - Number types: `t.int()`, `t.safeInt()`, `t.positiveInt()`, `t.uint16()`, etc.
311
+
312
+ ### Utilities
313
+
314
+ - `t.TypeOf<T>` - Extract TypeScript type from validator
315
+ - `t.enum(values)` - Enum validation
316
+ - `t.uintRange(min, max, defaultValue)` - Integer range validation
317
+
318
+ ## Contributing
319
+
320
+ We welcome contributions! Please see our [contributing guidelines](CONTRIBUTING.md) for details.
321
+
322
+ ## License
323
+
324
+ This project is licensed under the Apache-2.0 License - see the [LICENSE](LICENSE) file for details.
@@ -0,0 +1,6 @@
1
+ import { type Type } from '../type.mjs';
2
+ export declare const arrayOfLength: <A, N extends SmallUint>(size: N, elementType: Type<A>, options?: Readonly<{
3
+ typeName?: string;
4
+ defaultValue?: ArrayOfLength<N, A>;
5
+ }>) => Type<ArrayOfLength<N, A>>;
6
+ //# sourceMappingURL=array-of-length.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array-of-length.d.mts","sourceRoot":"","sources":["../../src/array/array-of-length.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAQxC,eAAO,MAAM,aAAa,GAAI,CAAC,EAAE,CAAC,SAAS,SAAS,EAClD,MAAM,CAAC,EACP,aAAa,IAAI,CAAC,CAAC,CAAC,EACpB,UAAU,QAAQ,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CACpC,CAAC,KACD,IAAI,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,CA2D1B,CAAC"}
@@ -0,0 +1,50 @@
1
+ import { Arr, Result } from 'ts-data-forge';
2
+ import { createAssertFn } from '../utils/create-assert-fn.mjs';
3
+ import { createCastFn } from '../utils/create-cast-fn.mjs';
4
+ import { createIsFn } from '../utils/create-is-fn.mjs';
5
+ import { validationErrorMessage } from '../utils/validation-error-message.mjs';
6
+
7
+ const arrayOfLength = (size, elementType, options) => {
8
+ const { typeName,
9
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
10
+ defaultValue = Arr.create(size, elementType.defaultValue), } = options ?? {};
11
+ const typeNameFilled = typeName ?? `[${Arr.create(size, elementType.typeName).join(', ')}]`;
12
+ const validate = (a) => {
13
+ if (!Arr.isArray(a)) {
14
+ return Result.err([
15
+ validationErrorMessage(a, 'The value is expected to be an array'),
16
+ ]);
17
+ }
18
+ if (a.length !== size) {
19
+ return Result.err([
20
+ `The value is expected to be an array of length ${size}, but it is ${a.length}.`,
21
+ ]);
22
+ }
23
+ for (const [index, el] of a.entries()) {
24
+ const res = elementType.validate(el);
25
+ if (Result.isErr(res)) {
26
+ const message = validationErrorMessage(el, `The array element is expected to be <${elementType.typeName}>`, (str) => `but the actual value at index ${index} is '${str}'`);
27
+ return Result.err([message, ...res.value]);
28
+ }
29
+ }
30
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
31
+ return Result.ok(a);
32
+ };
33
+ const fill = (a) => Arr.isArray(a)
34
+ ? // TODO: remove as
35
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
36
+ Arr.map(Arr.seq(size), (i) => elementType.fill(a[i]))
37
+ : defaultValue;
38
+ return {
39
+ typeName: typeNameFilled,
40
+ defaultValue,
41
+ fill,
42
+ validate,
43
+ is: createIsFn(validate),
44
+ cast: createCastFn(validate),
45
+ assertIs: createAssertFn(validate),
46
+ };
47
+ };
48
+
49
+ export { arrayOfLength };
50
+ //# sourceMappingURL=array-of-length.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array-of-length.mjs","sources":["../../src/array/array-of-length.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;AASO,MAAM,aAAa,GAAG,CAC3B,IAAO,EACP,WAAoB,EACpB,OAGE,KAC2B;AAG7B,IAAA,MAAM,EACJ,QAAQ;;AAER,IAAA,YAAY,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,YAAY,CAAM,GAC/D,GAAG,OAAO,IAAI,EAAE;IAEjB,MAAM,cAAc,GAClB,QAAQ,IAAI,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA,CAAA,CAAG;AAEtE,IAAA,MAAM,QAAQ,GAAwB,CAAC,CAAC,KAAI;QAC1C,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;YACnB,OAAO,MAAM,CAAC,GAAG,CAAC;AAChB,gBAAA,sBAAsB,CAAC,CAAC,EAAE,sCAAsC,CAAC;AAClE,aAAA,CAAC;QACJ;AAEA,QAAA,IAAI,CAAC,CAAC,MAAM,KAAK,IAAI,EAAE;YACrB,OAAO,MAAM,CAAC,GAAG,CAAC;AAChB,gBAAA,CAAA,+CAAA,EAAkD,IAAI,CAAA,YAAA,EAAe,CAAC,CAAC,MAAM,CAAA,CAAA,CAAG;AACjF,aAAA,CAAC;QACJ;AAEA,QAAA,KAAK,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;YACrC,MAAM,GAAG,GAAG,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC;AAEpC,YAAA,IAAI,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;gBACrB,MAAM,OAAO,GAAG,sBAAsB,CACpC,EAAE,EACF,CAAA,qCAAA,EAAwC,WAAW,CAAC,QAAQ,CAAA,CAAA,CAAG,EAC/D,CAAC,GAAG,KAAK,CAAA,8BAAA,EAAiC,KAAK,CAAA,KAAA,EAAQ,GAAG,CAAA,CAAA,CAAG,CAC9D;AAED,gBAAA,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;YAC5C;QACF;;AAGA,QAAA,OAAO,MAAM,CAAC,EAAE,CAAC,CAAiB,CAAC;AACrC,IAAA,CAAC;AAED,IAAA,MAAM,IAAI,GAAoB,CAAC,CAAC,KAC9B,GAAG,CAAC,OAAO,CAAC,CAAC;AACX;;YAEG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,KAAK,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAa;UACjE,YAAY;IAElB,OAAO;AACL,QAAA,QAAQ,EAAE,cAAc;QACxB,YAAY;QACZ,IAAI;QACJ,QAAQ;AACR,QAAA,EAAE,EAAE,UAAU,CAAC,QAAQ,CAAC;AACxB,QAAA,IAAI,EAAE,YAAY,CAAC,QAAQ,CAAC;AAC5B,QAAA,QAAQ,EAAE,cAAc,CAAC,QAAQ,CAAC;KACnC;AACH;;;;"}
@@ -0,0 +1,6 @@
1
+ import { type Type } from '../type.mjs';
2
+ export declare const array: <A>(elementType: Type<A>, options?: Partial<Readonly<{
3
+ typeName: string;
4
+ defaultValue: readonly A[];
5
+ }>>) => Type<readonly A[]>;
6
+ //# sourceMappingURL=array.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array.d.mts","sourceRoot":"","sources":["../../src/array/array.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAQxC,eAAO,MAAM,KAAK,GAAI,CAAC,EACrB,aAAa,IAAI,CAAC,CAAC,CAAC,EACpB,UAAU,OAAO,CACf,QAAQ,CAAC;IACP,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,SAAS,CAAC,EAAE,CAAC;CAC5B,CAAC,CACH,KACA,IAAI,CAAC,SAAS,CAAC,EAAE,CA4CnB,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { Arr, Result } from 'ts-data-forge';
2
+ import { createAssertFn } from '../utils/create-assert-fn.mjs';
3
+ import { createCastFn } from '../utils/create-cast-fn.mjs';
4
+ import { createIsFn } from '../utils/create-is-fn.mjs';
5
+ import { validationErrorMessage } from '../utils/validation-error-message.mjs';
6
+
7
+ const array = (elementType, options) => {
8
+ const { typeName, defaultValue = [] } = options ?? {};
9
+ const typeNameFilled = typeName ?? `(${elementType.typeName})[]`;
10
+ const validate = (a) => {
11
+ if (!Arr.isArray(a)) {
12
+ return Result.err([
13
+ validationErrorMessage(a, 'The value is expected to be an array'),
14
+ ]);
15
+ }
16
+ for (const [index, el] of a.entries()) {
17
+ const res = elementType.validate(el);
18
+ if (Result.isErr(res)) {
19
+ const message = validationErrorMessage(el, `The array element is expected to be <${elementType.typeName}>`, (str) => `but the actual value at index ${index} is '${str}'`);
20
+ return Result.err([message, ...res.value]);
21
+ }
22
+ }
23
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
24
+ return Result.ok(a);
25
+ };
26
+ const fill = (a) => Arr.isArray(a) ? a.map((e) => elementType.fill(e)) : defaultValue;
27
+ return {
28
+ typeName: typeNameFilled,
29
+ defaultValue,
30
+ fill,
31
+ validate,
32
+ is: createIsFn(validate),
33
+ assertIs: createAssertFn(validate),
34
+ cast: createCastFn(validate),
35
+ };
36
+ };
37
+
38
+ export { array };
39
+ //# sourceMappingURL=array.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array.mjs","sources":["../../src/array/array.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;MASa,KAAK,GAAG,CACnB,WAAoB,EACpB,OAKC,KACqB;IAGtB,MAAM,EAAE,QAAQ,EAAE,YAAY,GAAG,EAAE,EAAE,GAAG,OAAO,IAAI,EAAE;IAErD,MAAM,cAAc,GAAW,QAAQ,IAAI,IAAI,WAAW,CAAC,QAAQ,CAAA,GAAA,CAAK;AAExE,IAAA,MAAM,QAAQ,GAAwB,CAAC,CAAC,KAAI;QAC1C,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;YACnB,OAAO,MAAM,CAAC,GAAG,CAAC;AAChB,gBAAA,sBAAsB,CAAC,CAAC,EAAE,sCAAsC,CAAC;AAClE,aAAA,CAAC;QACJ;AAEA,QAAA,KAAK,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;YACrC,MAAM,GAAG,GAAG,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC;AAEpC,YAAA,IAAI,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;gBACrB,MAAM,OAAO,GAAG,sBAAsB,CACpC,EAAE,EACF,CAAA,qCAAA,EAAwC,WAAW,CAAC,QAAQ,CAAA,CAAA,CAAG,EAC/D,CAAC,GAAG,KAAK,CAAA,8BAAA,EAAiC,KAAK,CAAA,KAAA,EAAQ,GAAG,CAAA,CAAA,CAAG,CAC9D;AAED,gBAAA,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;YAC5C;QACF;;AAGA,QAAA,OAAO,MAAM,CAAC,EAAE,CAAC,CAAM,CAAC;AAC1B,IAAA,CAAC;AAED,IAAA,MAAM,IAAI,GAAoB,CAAC,CAAC,KAC9B,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY;IAEnE,OAAO;AACL,QAAA,QAAQ,EAAE,cAAc;QACxB,YAAY;QACZ,IAAI;QACJ,QAAQ;AACR,QAAA,EAAE,EAAE,UAAU,CAAC,QAAQ,CAAC;AACxB,QAAA,QAAQ,EAAE,cAAc,CAAC,QAAQ,CAAC;AAClC,QAAA,IAAI,EAAE,YAAY,CAAC,QAAQ,CAAC;KAC7B;AACH;;;;"}
@@ -0,0 +1,5 @@
1
+ export * from './array-of-length.mjs';
2
+ export * from './array.mjs';
3
+ export * from './non-empty-array.mjs';
4
+ export * from './tuple.mjs';
5
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/array/index.mts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { arrayOfLength } from './array-of-length.mjs';
2
+ export { array } from './array.mjs';
3
+ export { nonEmptyArray } from './non-empty-array.mjs';
4
+ export { tuple } from './tuple.mjs';
5
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
@@ -0,0 +1,6 @@
1
+ import { type Type } from '../type.mjs';
2
+ export declare const nonEmptyArray: <A>(elementType: Type<A>, options?: Readonly<{
3
+ typeName?: string;
4
+ defaultValue?: NonEmptyArray<A>;
5
+ }>) => Type<NonEmptyArray<A>>;
6
+ //# sourceMappingURL=non-empty-array.d.mts.map