bguard 0.0.9 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (424) hide show
  1. package/README.md +844 -26
  2. package/lib/{CommonSchema-BIe85W_A.d.mts → CommonSchema-BbGNki0L.d.ts} +7 -4
  3. package/lib/{CommonSchema-BIe85W_A.d.ts → CommonSchema-CjsYE4dC.d.mts} +7 -4
  4. package/lib/InferType.d.mts +2 -1
  5. package/lib/InferType.d.ts +2 -1
  6. package/lib/asserts/array/index.d.mts +4 -3
  7. package/lib/asserts/array/index.d.ts +4 -3
  8. package/lib/asserts/array/index.js +6 -6
  9. package/lib/asserts/array/index.mjs +5 -5
  10. package/lib/asserts/boolean/index.d.mts +4 -3
  11. package/lib/asserts/boolean/index.d.ts +4 -3
  12. package/lib/asserts/boolean/index.js +7 -6
  13. package/lib/asserts/boolean/index.js.map +1 -1
  14. package/lib/asserts/boolean/index.mjs +6 -5
  15. package/lib/asserts/mix/equalTo.d.mts +22 -0
  16. package/lib/asserts/mix/equalTo.d.ts +22 -0
  17. package/lib/asserts/mix/equalTo.js +9 -0
  18. package/lib/asserts/mix/equalTo.js.map +1 -0
  19. package/lib/asserts/mix/equalTo.mjs +9 -0
  20. package/lib/asserts/{common → mix}/index.d.mts +5 -4
  21. package/lib/asserts/{common → mix}/index.d.ts +5 -4
  22. package/lib/asserts/mix/index.js +10 -0
  23. package/lib/asserts/mix/index.js.map +1 -0
  24. package/lib/asserts/mix/index.mjs +10 -0
  25. package/lib/asserts/mix/oneOfValues.d.mts +23 -0
  26. package/lib/asserts/mix/oneOfValues.d.ts +23 -0
  27. package/lib/asserts/mix/oneOfValues.js +9 -0
  28. package/lib/asserts/mix/oneOfValues.js.map +1 -0
  29. package/lib/asserts/mix/oneOfValues.mjs +9 -0
  30. package/lib/asserts/number/index.d.mts +4 -3
  31. package/lib/asserts/number/index.d.ts +4 -3
  32. package/lib/asserts/number/index.js +11 -7
  33. package/lib/asserts/number/index.js.map +1 -1
  34. package/lib/asserts/number/index.mjs +10 -6
  35. package/lib/asserts/number/max.d.mts +15 -10
  36. package/lib/asserts/number/max.d.ts +15 -10
  37. package/lib/asserts/number/max.js +11 -4
  38. package/lib/asserts/number/max.js.map +1 -1
  39. package/lib/asserts/number/max.mjs +12 -5
  40. package/lib/asserts/number/max.mjs.map +1 -1
  41. package/lib/asserts/number/maxExcluded.d.mts +14 -9
  42. package/lib/asserts/number/maxExcluded.d.ts +14 -9
  43. package/lib/asserts/number/maxExcluded.js +11 -4
  44. package/lib/asserts/number/maxExcluded.js.map +1 -1
  45. package/lib/asserts/number/maxExcluded.mjs +12 -5
  46. package/lib/asserts/number/maxExcluded.mjs.map +1 -1
  47. package/lib/asserts/number/min.d.mts +15 -10
  48. package/lib/asserts/number/min.d.ts +15 -10
  49. package/lib/asserts/number/min.js +11 -4
  50. package/lib/asserts/number/min.js.map +1 -1
  51. package/lib/asserts/number/min.mjs +12 -5
  52. package/lib/asserts/number/min.mjs.map +1 -1
  53. package/lib/asserts/number/minExcluded.d.mts +15 -10
  54. package/lib/asserts/number/minExcluded.d.ts +15 -10
  55. package/lib/asserts/number/minExcluded.js +11 -4
  56. package/lib/asserts/number/minExcluded.js.map +1 -1
  57. package/lib/asserts/number/minExcluded.mjs +12 -5
  58. package/lib/asserts/number/minExcluded.mjs.map +1 -1
  59. package/lib/asserts/number/negative.d.mts +14 -9
  60. package/lib/asserts/number/negative.d.ts +14 -9
  61. package/lib/asserts/number/negative.js +11 -3
  62. package/lib/asserts/number/negative.js.map +1 -1
  63. package/lib/asserts/number/negative.mjs +12 -4
  64. package/lib/asserts/number/negative.mjs.map +1 -1
  65. package/lib/asserts/number/positive.d.mts +14 -9
  66. package/lib/asserts/number/positive.d.ts +14 -9
  67. package/lib/asserts/number/positive.js +11 -3
  68. package/lib/asserts/number/positive.js.map +1 -1
  69. package/lib/asserts/number/positive.mjs +12 -4
  70. package/lib/asserts/number/positive.mjs.map +1 -1
  71. package/lib/asserts/object/index.d.mts +4 -3
  72. package/lib/asserts/object/index.d.ts +4 -3
  73. package/lib/asserts/object/index.js +6 -6
  74. package/lib/asserts/object/index.mjs +5 -5
  75. package/lib/asserts/string/atLeastOneDigit.d.mts +20 -0
  76. package/lib/asserts/string/atLeastOneDigit.d.ts +20 -0
  77. package/lib/asserts/string/atLeastOneDigit.js +21 -0
  78. package/lib/asserts/string/atLeastOneDigit.js.map +1 -0
  79. package/lib/asserts/string/atLeastOneDigit.mjs +21 -0
  80. package/lib/asserts/string/atLeastOneDigit.mjs.map +1 -0
  81. package/lib/asserts/string/atLeastOneLowerChar.d.mts +20 -0
  82. package/lib/asserts/string/atLeastOneLowerChar.d.ts +20 -0
  83. package/lib/asserts/string/atLeastOneLowerChar.js +22 -0
  84. package/lib/asserts/string/atLeastOneLowerChar.js.map +1 -0
  85. package/lib/asserts/string/atLeastOneLowerChar.mjs +22 -0
  86. package/lib/asserts/string/atLeastOneLowerChar.mjs.map +1 -0
  87. package/lib/asserts/string/atLeastOneSpecialChar.d.mts +25 -0
  88. package/lib/asserts/string/atLeastOneSpecialChar.d.ts +25 -0
  89. package/lib/asserts/string/atLeastOneSpecialChar.js +26 -0
  90. package/lib/asserts/string/atLeastOneSpecialChar.js.map +1 -0
  91. package/lib/asserts/string/atLeastOneSpecialChar.mjs +26 -0
  92. package/lib/asserts/string/atLeastOneSpecialChar.mjs.map +1 -0
  93. package/lib/asserts/string/atLeastOneUpperChar.d.mts +20 -0
  94. package/lib/asserts/string/atLeastOneUpperChar.d.ts +20 -0
  95. package/lib/asserts/string/atLeastOneUpperChar.js +22 -0
  96. package/lib/asserts/string/atLeastOneUpperChar.js.map +1 -0
  97. package/lib/asserts/string/atLeastOneUpperChar.mjs +22 -0
  98. package/lib/asserts/string/atLeastOneUpperChar.mjs.map +1 -0
  99. package/lib/asserts/string/contains.d.mts +21 -0
  100. package/lib/asserts/string/contains.d.ts +21 -0
  101. package/lib/asserts/string/contains.js +22 -0
  102. package/lib/asserts/string/contains.js.map +1 -0
  103. package/lib/asserts/string/contains.mjs +22 -0
  104. package/lib/asserts/string/contains.mjs.map +1 -0
  105. package/lib/asserts/string/email.d.mts +13 -9
  106. package/lib/asserts/string/email.d.ts +13 -9
  107. package/lib/asserts/string/email.js +11 -4
  108. package/lib/asserts/string/email.js.map +1 -1
  109. package/lib/asserts/string/email.mjs +12 -5
  110. package/lib/asserts/string/email.mjs.map +1 -1
  111. package/lib/asserts/string/endsWith.d.mts +21 -0
  112. package/lib/asserts/string/endsWith.d.ts +21 -0
  113. package/lib/asserts/string/endsWith.js +22 -0
  114. package/lib/asserts/string/endsWith.js.map +1 -0
  115. package/lib/asserts/string/endsWith.mjs +22 -0
  116. package/lib/asserts/string/endsWith.mjs.map +1 -0
  117. package/lib/asserts/string/index.d.mts +4 -3
  118. package/lib/asserts/string/index.d.ts +4 -3
  119. package/lib/asserts/string/index.js +11 -7
  120. package/lib/asserts/string/index.js.map +1 -1
  121. package/lib/asserts/string/index.mjs +10 -6
  122. package/lib/asserts/string/lowerCase.d.mts +20 -0
  123. package/lib/asserts/string/lowerCase.d.ts +20 -0
  124. package/lib/asserts/string/lowerCase.js +20 -0
  125. package/lib/asserts/string/lowerCase.js.map +1 -0
  126. package/lib/asserts/string/lowerCase.mjs +20 -0
  127. package/lib/asserts/string/lowerCase.mjs.map +1 -0
  128. package/lib/asserts/string/maxLength.d.mts +14 -9
  129. package/lib/asserts/string/maxLength.d.ts +14 -9
  130. package/lib/asserts/string/maxLength.js +11 -4
  131. package/lib/asserts/string/maxLength.js.map +1 -1
  132. package/lib/asserts/string/maxLength.mjs +12 -5
  133. package/lib/asserts/string/maxLength.mjs.map +1 -1
  134. package/lib/asserts/string/minLength.d.mts +14 -9
  135. package/lib/asserts/string/minLength.d.ts +14 -9
  136. package/lib/asserts/string/minLength.js +11 -4
  137. package/lib/asserts/string/minLength.js.map +1 -1
  138. package/lib/asserts/string/minLength.mjs +12 -5
  139. package/lib/asserts/string/minLength.mjs.map +1 -1
  140. package/lib/asserts/string/regExp.d.mts +14 -9
  141. package/lib/asserts/string/regExp.d.ts +14 -9
  142. package/lib/asserts/string/regExp.js +11 -4
  143. package/lib/asserts/string/regExp.js.map +1 -1
  144. package/lib/asserts/string/regExp.mjs +12 -5
  145. package/lib/asserts/string/regExp.mjs.map +1 -1
  146. package/lib/asserts/string/startsWith.d.mts +21 -0
  147. package/lib/asserts/string/startsWith.d.ts +21 -0
  148. package/lib/asserts/string/startsWith.js +22 -0
  149. package/lib/asserts/string/startsWith.js.map +1 -0
  150. package/lib/asserts/string/startsWith.mjs +22 -0
  151. package/lib/asserts/string/startsWith.mjs.map +1 -0
  152. package/lib/asserts/string/upperCase.d.mts +21 -0
  153. package/lib/asserts/string/upperCase.d.ts +21 -0
  154. package/lib/asserts/string/upperCase.js +22 -0
  155. package/lib/asserts/string/upperCase.js.map +1 -0
  156. package/lib/asserts/string/upperCase.mjs +22 -0
  157. package/lib/asserts/string/upperCase.mjs.map +1 -0
  158. package/lib/asserts/string/uuid.d.mts +20 -0
  159. package/lib/asserts/string/uuid.d.ts +20 -0
  160. package/lib/asserts/string/uuid.js +23 -0
  161. package/lib/asserts/string/uuid.js.map +1 -0
  162. package/lib/asserts/string/uuid.mjs +23 -0
  163. package/lib/asserts/string/uuid.mjs.map +1 -0
  164. package/lib/asserts/string/uuidV1.d.mts +21 -0
  165. package/lib/asserts/string/uuidV1.d.ts +21 -0
  166. package/lib/asserts/string/uuidV1.js +23 -0
  167. package/lib/asserts/string/uuidV1.js.map +1 -0
  168. package/lib/asserts/string/uuidV1.mjs +23 -0
  169. package/lib/asserts/string/uuidV1.mjs.map +1 -0
  170. package/lib/asserts/string/uuidV2.d.mts +21 -0
  171. package/lib/asserts/string/uuidV2.d.ts +21 -0
  172. package/lib/asserts/string/uuidV2.js +23 -0
  173. package/lib/asserts/string/uuidV2.js.map +1 -0
  174. package/lib/asserts/string/uuidV2.mjs +23 -0
  175. package/lib/asserts/string/uuidV2.mjs.map +1 -0
  176. package/lib/asserts/string/uuidV3.d.mts +21 -0
  177. package/lib/asserts/string/uuidV3.d.ts +21 -0
  178. package/lib/asserts/string/uuidV3.js +23 -0
  179. package/lib/asserts/string/uuidV3.js.map +1 -0
  180. package/lib/asserts/string/uuidV3.mjs +23 -0
  181. package/lib/asserts/string/uuidV3.mjs.map +1 -0
  182. package/lib/asserts/string/uuidV4.d.mts +23 -0
  183. package/lib/asserts/string/uuidV4.d.ts +23 -0
  184. package/lib/asserts/string/uuidV4.js +23 -0
  185. package/lib/asserts/string/uuidV4.js.map +1 -0
  186. package/lib/asserts/string/uuidV4.mjs +23 -0
  187. package/lib/asserts/string/uuidV4.mjs.map +1 -0
  188. package/lib/asserts/string/uuidV5.d.mts +21 -0
  189. package/lib/asserts/string/uuidV5.d.ts +21 -0
  190. package/lib/asserts/string/uuidV5.js +23 -0
  191. package/lib/asserts/string/uuidV5.js.map +1 -0
  192. package/lib/asserts/string/uuidV5.mjs +23 -0
  193. package/lib/asserts/string/uuidV5.mjs.map +1 -0
  194. package/lib/asserts/string/validUrl.d.mts +23 -0
  195. package/lib/asserts/string/validUrl.d.ts +23 -0
  196. package/lib/asserts/string/validUrl.js +32 -0
  197. package/lib/asserts/string/validUrl.js.map +1 -0
  198. package/lib/asserts/string/validUrl.mjs +32 -0
  199. package/lib/asserts/string/validUrl.mjs.map +1 -0
  200. package/lib/{chunk-32IQXZRK.mjs → chunk-2PM3K3OE.mjs} +2 -2
  201. package/lib/{chunk-32IQXZRK.mjs.map → chunk-2PM3K3OE.mjs.map} +1 -1
  202. package/lib/{chunk-KCBOOOTF.mjs → chunk-32RSTOZ4.mjs} +2 -2
  203. package/lib/{chunk-KCBOOOTF.mjs.map → chunk-32RSTOZ4.mjs.map} +1 -1
  204. package/lib/chunk-3HTYHE2X.mjs +54 -0
  205. package/lib/chunk-3HTYHE2X.mjs.map +1 -0
  206. package/lib/chunk-3O4WCRC2.mjs +21 -0
  207. package/lib/chunk-3O4WCRC2.mjs.map +1 -0
  208. package/lib/chunk-42J6CHIO.js +7 -0
  209. package/lib/chunk-42J6CHIO.js.map +1 -0
  210. package/lib/chunk-4CYIMDP2.js +21 -0
  211. package/lib/chunk-4CYIMDP2.js.map +1 -0
  212. package/lib/chunk-5BVJ6YMH.js +54 -0
  213. package/lib/chunk-5BVJ6YMH.js.map +1 -0
  214. package/lib/chunk-6TH3DBDK.js +53 -0
  215. package/lib/chunk-6TH3DBDK.js.map +1 -0
  216. package/lib/chunk-7XFLH6R2.mjs +44 -0
  217. package/lib/chunk-7XFLH6R2.mjs.map +1 -0
  218. package/lib/chunk-ASZW6XRM.mjs +7 -0
  219. package/lib/chunk-ASZW6XRM.mjs.map +1 -0
  220. package/lib/{chunk-GEZME6V2.mjs → chunk-CCBCDJXS.mjs} +11 -6
  221. package/lib/chunk-CCBCDJXS.mjs.map +1 -0
  222. package/lib/chunk-DJSLA2ZV.js +27 -0
  223. package/lib/chunk-DJSLA2ZV.js.map +1 -0
  224. package/lib/{chunk-L7HUXYFV.mjs → chunk-DPBE7TAQ.mjs} +2 -2
  225. package/lib/chunk-DPBE7TAQ.mjs.map +1 -0
  226. package/lib/{chunk-APTTIN2L.js → chunk-EGEHSELT.js} +6 -6
  227. package/lib/chunk-EGEHSELT.js.map +1 -0
  228. package/lib/chunk-H7CPKW53.js +47 -0
  229. package/lib/chunk-H7CPKW53.js.map +1 -0
  230. package/lib/{chunk-A7I2JEQO.js → chunk-HDSGCAHH.js} +3 -3
  231. package/lib/{chunk-A7I2JEQO.js.map → chunk-HDSGCAHH.js.map} +1 -1
  232. package/lib/{chunk-L6A7NXUJ.js → chunk-IEUXIOL6.js} +3 -3
  233. package/lib/{chunk-L6A7NXUJ.js.map → chunk-IEUXIOL6.js.map} +1 -1
  234. package/lib/chunk-IRG4OQAB.js +63 -0
  235. package/lib/chunk-IRG4OQAB.js.map +1 -0
  236. package/lib/chunk-J4VKFJQK.js +21 -0
  237. package/lib/chunk-J4VKFJQK.js.map +1 -0
  238. package/lib/{chunk-A2SAWKJA.mjs → chunk-JDGZCBXF.mjs} +2 -2
  239. package/lib/{chunk-A2SAWKJA.mjs.map → chunk-JDGZCBXF.mjs.map} +1 -1
  240. package/lib/chunk-JPRCULRQ.mjs +61 -0
  241. package/lib/chunk-JPRCULRQ.mjs.map +1 -0
  242. package/lib/chunk-JSGZ7DKT.js +14 -0
  243. package/lib/chunk-JSGZ7DKT.js.map +1 -0
  244. package/lib/chunk-KQKJASVB.js +58 -0
  245. package/lib/chunk-KQKJASVB.js.map +1 -0
  246. package/lib/chunk-LEQCDD66.js +61 -0
  247. package/lib/chunk-LEQCDD66.js.map +1 -0
  248. package/lib/{chunk-AJ4WV5DG.mjs → chunk-MRISXZQ4.mjs} +3 -3
  249. package/lib/chunk-MRISXZQ4.mjs.map +1 -0
  250. package/lib/{chunk-A3UTB4RE.mjs → chunk-NDQM5OL4.mjs} +4 -4
  251. package/lib/chunk-NDQM5OL4.mjs.map +1 -0
  252. package/lib/chunk-NNFYXHLU.mjs +21 -0
  253. package/lib/chunk-NNFYXHLU.mjs.map +1 -0
  254. package/lib/chunk-P7IXNCJG.mjs +58 -0
  255. package/lib/chunk-P7IXNCJG.mjs.map +1 -0
  256. package/lib/chunk-PG2R7P7G.mjs +27 -0
  257. package/lib/chunk-PG2R7P7G.mjs.map +1 -0
  258. package/lib/chunk-PH2PMUZP.mjs +63 -0
  259. package/lib/chunk-PH2PMUZP.mjs.map +1 -0
  260. package/lib/{chunk-BGMR7A6X.mjs → chunk-PXBAS3GA.mjs} +2 -2
  261. package/lib/{chunk-BGMR7A6X.mjs.map → chunk-PXBAS3GA.mjs.map} +1 -1
  262. package/lib/chunk-QQNQ4IDN.js +13 -0
  263. package/lib/chunk-QQNQ4IDN.js.map +1 -0
  264. package/lib/{chunk-QKGQ4XZC.js → chunk-RD6TBCPQ.js} +3 -3
  265. package/lib/{chunk-QKGQ4XZC.js.map → chunk-RD6TBCPQ.js.map} +1 -1
  266. package/lib/chunk-RRQOET3X.js +28 -0
  267. package/lib/chunk-RRQOET3X.js.map +1 -0
  268. package/lib/chunk-RYVUYVEE.mjs +14 -0
  269. package/lib/chunk-RYVUYVEE.mjs.map +1 -0
  270. package/lib/{chunk-QYLH5ZAC.mjs → chunk-TCQY2R3U.mjs} +25 -4
  271. package/lib/chunk-TCQY2R3U.mjs.map +1 -0
  272. package/lib/{chunk-PJP63SJT.js → chunk-TKZ6FLLR.js} +3 -3
  273. package/lib/{chunk-PJP63SJT.js.map → chunk-TKZ6FLLR.js.map} +1 -1
  274. package/lib/{chunk-K2S3FS5K.js → chunk-VHEA4JZ5.js} +3 -3
  275. package/lib/{chunk-K2S3FS5K.js.map → chunk-VHEA4JZ5.js.map} +1 -1
  276. package/lib/{chunk-VPFIIM2X.js → chunk-WBERBAL4.js} +11 -6
  277. package/lib/chunk-WBERBAL4.js.map +1 -0
  278. package/lib/chunk-WK4O3HH4.js +44 -0
  279. package/lib/chunk-WK4O3HH4.js.map +1 -0
  280. package/lib/{chunk-3FEJUC3K.mjs → chunk-YML32TPA.mjs} +2 -2
  281. package/lib/{chunk-3FEJUC3K.mjs.map → chunk-YML32TPA.mjs.map} +1 -1
  282. package/lib/chunk-YUESB2WV.mjs +47 -0
  283. package/lib/chunk-YUESB2WV.mjs.map +1 -0
  284. package/lib/codeGen.d.mts +7 -0
  285. package/lib/codeGen.d.ts +7 -0
  286. package/lib/codeGen.js +51 -0
  287. package/lib/codeGen.js.map +1 -0
  288. package/lib/codeGen.mjs +51 -0
  289. package/lib/codeGen.mjs.map +1 -0
  290. package/lib/commonTypes.d.mts +31 -0
  291. package/lib/commonTypes.d.ts +31 -0
  292. package/lib/commonTypes.js +1 -0
  293. package/lib/commonTypes.js.map +1 -0
  294. package/lib/commonTypes.mjs +1 -0
  295. package/lib/exceptions.d.mts +4 -2
  296. package/lib/exceptions.d.ts +4 -2
  297. package/lib/exceptions.js +2 -2
  298. package/lib/exceptions.mjs +3 -3
  299. package/lib/helpers/constants.d.mts +3 -0
  300. package/lib/helpers/constants.d.ts +3 -0
  301. package/lib/helpers/constants.js +7 -0
  302. package/lib/helpers/constants.js.map +1 -0
  303. package/lib/helpers/constants.mjs +7 -0
  304. package/lib/helpers/constants.mjs.map +1 -0
  305. package/lib/helpers/core.d.mts +2 -0
  306. package/lib/helpers/core.d.ts +2 -0
  307. package/lib/helpers/core.js +10 -0
  308. package/lib/helpers/core.js.map +1 -0
  309. package/lib/helpers/core.mjs +10 -0
  310. package/lib/helpers/core.mjs.map +1 -0
  311. package/lib/helpers/setStrictType.d.mts +6 -0
  312. package/lib/helpers/setStrictType.d.ts +6 -0
  313. package/lib/helpers/setStrictType.js +9 -0
  314. package/lib/helpers/setStrictType.js.map +1 -0
  315. package/lib/helpers/setStrictType.mjs +9 -0
  316. package/lib/helpers/setStrictType.mjs.map +1 -0
  317. package/lib/index.d.mts +7 -4
  318. package/lib/index.d.ts +7 -4
  319. package/lib/index.js +32 -17
  320. package/lib/index.js.map +1 -1
  321. package/lib/index.mjs +37 -22
  322. package/lib/parse.d.mts +66 -0
  323. package/lib/parse.d.ts +66 -0
  324. package/lib/parse.js +10 -0
  325. package/lib/parse.js.map +1 -0
  326. package/lib/parse.mjs +10 -0
  327. package/lib/parse.mjs.map +1 -0
  328. package/lib/{parseSchema.d.mts → parseOrFail.d.mts} +16 -5
  329. package/lib/{parseSchema.d.ts → parseOrFail.d.ts} +16 -5
  330. package/lib/parseOrFail.js +10 -0
  331. package/lib/parseOrFail.js.map +1 -0
  332. package/lib/parseOrFail.mjs +10 -0
  333. package/lib/parseOrFail.mjs.map +1 -0
  334. package/lib/schemas/ArraySchema.d.mts +2 -1
  335. package/lib/schemas/ArraySchema.d.ts +2 -1
  336. package/lib/schemas/ArraySchema.js +5 -5
  337. package/lib/schemas/ArraySchema.mjs +4 -4
  338. package/lib/schemas/BooleanSchema.d.mts +2 -1
  339. package/lib/schemas/BooleanSchema.d.ts +2 -1
  340. package/lib/schemas/BooleanSchema.js +6 -5
  341. package/lib/schemas/BooleanSchema.js.map +1 -1
  342. package/lib/schemas/BooleanSchema.mjs +5 -4
  343. package/lib/schemas/CommonSchema.d.mts +2 -1
  344. package/lib/schemas/CommonSchema.d.ts +2 -1
  345. package/lib/schemas/CommonSchema.js +4 -4
  346. package/lib/schemas/CommonSchema.mjs +3 -3
  347. package/lib/schemas/NumberSchema.d.mts +13 -1
  348. package/lib/schemas/NumberSchema.d.ts +13 -1
  349. package/lib/schemas/NumberSchema.js +10 -6
  350. package/lib/schemas/NumberSchema.js.map +1 -1
  351. package/lib/schemas/NumberSchema.mjs +9 -5
  352. package/lib/schemas/ObjectSchema.d.mts +20 -1
  353. package/lib/schemas/ObjectSchema.d.ts +20 -1
  354. package/lib/schemas/ObjectSchema.js +5 -5
  355. package/lib/schemas/ObjectSchema.mjs +4 -4
  356. package/lib/schemas/StringSchema.d.mts +13 -1
  357. package/lib/schemas/StringSchema.d.ts +13 -1
  358. package/lib/schemas/StringSchema.js +10 -6
  359. package/lib/schemas/StringSchema.js.map +1 -1
  360. package/lib/schemas/StringSchema.mjs +9 -5
  361. package/lib/translationMap.d.mts +12 -0
  362. package/lib/translationMap.d.ts +12 -0
  363. package/lib/translationMap.js +14 -0
  364. package/lib/translationMap.js.map +1 -0
  365. package/lib/translationMap.mjs +14 -0
  366. package/lib/translationMap.mjs.map +1 -0
  367. package/package.json +23 -6
  368. package/lib/asserts/common/equalTo.d.mts +0 -29
  369. package/lib/asserts/common/equalTo.d.ts +0 -29
  370. package/lib/asserts/common/equalTo.js +0 -8
  371. package/lib/asserts/common/equalTo.js.map +0 -1
  372. package/lib/asserts/common/equalTo.mjs +0 -8
  373. package/lib/asserts/common/index.js +0 -10
  374. package/lib/asserts/common/index.js.map +0 -1
  375. package/lib/asserts/common/index.mjs +0 -10
  376. package/lib/chunk-2AP4OQMT.js +0 -26
  377. package/lib/chunk-2AP4OQMT.js.map +0 -1
  378. package/lib/chunk-5NCJN6D2.js +0 -70
  379. package/lib/chunk-5NCJN6D2.js.map +0 -1
  380. package/lib/chunk-5ZMICHV3.js +0 -21
  381. package/lib/chunk-5ZMICHV3.js.map +0 -1
  382. package/lib/chunk-63IQFNFO.mjs +0 -27
  383. package/lib/chunk-63IQFNFO.mjs.map +0 -1
  384. package/lib/chunk-A3UTB4RE.mjs.map +0 -1
  385. package/lib/chunk-AJ4WV5DG.mjs.map +0 -1
  386. package/lib/chunk-APTTIN2L.js.map +0 -1
  387. package/lib/chunk-AXOP6HPJ.js +0 -14
  388. package/lib/chunk-AXOP6HPJ.js.map +0 -1
  389. package/lib/chunk-FCFO5J5Y.mjs +0 -14
  390. package/lib/chunk-FCFO5J5Y.mjs.map +0 -1
  391. package/lib/chunk-GEZME6V2.mjs.map +0 -1
  392. package/lib/chunk-GNBSKTFV.js +0 -27
  393. package/lib/chunk-GNBSKTFV.js.map +0 -1
  394. package/lib/chunk-IQ3QYABE.js +0 -32
  395. package/lib/chunk-IQ3QYABE.js.map +0 -1
  396. package/lib/chunk-L7HUXYFV.mjs.map +0 -1
  397. package/lib/chunk-LHTJHMKJ.mjs +0 -27
  398. package/lib/chunk-LHTJHMKJ.mjs.map +0 -1
  399. package/lib/chunk-NOADI6PO.mjs +0 -21
  400. package/lib/chunk-NOADI6PO.mjs.map +0 -1
  401. package/lib/chunk-NWY33MFU.js +0 -13
  402. package/lib/chunk-NWY33MFU.js.map +0 -1
  403. package/lib/chunk-P3Y6IWFA.mjs +0 -70
  404. package/lib/chunk-P3Y6IWFA.mjs.map +0 -1
  405. package/lib/chunk-PDVXBE27.js +0 -27
  406. package/lib/chunk-PDVXBE27.js.map +0 -1
  407. package/lib/chunk-QJOXKH7A.mjs +0 -26
  408. package/lib/chunk-QJOXKH7A.mjs.map +0 -1
  409. package/lib/chunk-QYLH5ZAC.mjs.map +0 -1
  410. package/lib/chunk-VPFIIM2X.js.map +0 -1
  411. package/lib/chunk-YXHH5BF6.js +0 -28
  412. package/lib/chunk-YXHH5BF6.js.map +0 -1
  413. package/lib/core.d.mts +0 -1
  414. package/lib/core.d.ts +0 -1
  415. package/lib/core.js +0 -10
  416. package/lib/core.js.map +0 -1
  417. package/lib/core.mjs +0 -10
  418. package/lib/parseSchema.js +0 -9
  419. package/lib/parseSchema.js.map +0 -1
  420. package/lib/parseSchema.mjs +0 -9
  421. /package/lib/asserts/{common → mix}/equalTo.mjs.map +0 -0
  422. /package/lib/asserts/{common → mix}/index.mjs.map +0 -0
  423. /package/lib/{core.mjs.map → asserts/mix/oneOfValues.mjs.map} +0 -0
  424. /package/lib/{parseSchema.mjs.map → commonTypes.mjs.map} +0 -0
package/README.md CHANGED
@@ -4,7 +4,6 @@
4
4
 
5
5
  ![Coveralls branch](https://img.shields.io/coverallsCoverage/github/NBlasko/bguard) ![npm](https://img.shields.io/npm/dt/bguard) ![Known Vulnerabilities](https://snyk.io/test/github/NBlasko/bguard/badge.svg)
6
6
 
7
-
8
7
  ### Features
9
8
 
10
9
  - **Type Inference**: Automatically infer TypeScript types from your validation schemas.
@@ -31,7 +30,7 @@ Let's define a schema for a Student object:
31
30
 
32
31
  ```typeScript
33
32
 
34
- import { parseSchema, InferType, string, number, array, object, boolean } from 'bguard';
33
+ import { InferType, string, number, array, object, boolean } from 'bguard';
35
34
  import { email } from 'bguard/string/email';
36
35
  import { min } from 'bguard/number/min';
37
36
  import { max } from 'bguard/number/max';
@@ -58,9 +57,7 @@ const studentSchema = object({
58
57
  Using the InferType utility, you can infer the TypeScript type of the schema:
59
58
 
60
59
  ```typescript
61
-
62
60
  type StudentSchema = InferType<typeof studentSchema>;
63
-
64
61
  ```
65
62
 
66
63
  This will generate the following type:
@@ -81,13 +78,89 @@ type StudentSchema = {
81
78
 
82
79
  ```
83
80
 
84
- #### Validating Data
81
+ #### Generating TypeScript Types with `codeGen`
85
82
 
86
- To validate data against the defined schema, use the parseSchema function:
83
+ If you prefer to generate TypeScript types as a string, you can use the `codeGen` function:
87
84
 
88
85
  ```typeScript
86
+ import { codeGen } from 'bguard/codeGen';
87
+ ```
88
+
89
+ The `codeGen` function takes a schema and returns a string representing the inferred TypeScript type. This string can be written to a file or used in other ways where a static type definition is needed.
90
+
91
+ Example
92
+
93
+ ```typeScript
94
+ const typeString = codeGen(studentSchema);
95
+ console.log(typeString);
96
+ ```
89
97
 
90
- const studentData = {
98
+ This would output a string:
99
+
100
+ ```typeScript
101
+ {
102
+ email?: string | undefined;
103
+ age: number;
104
+ address: string | null;
105
+ classes: ({
106
+ name: string;
107
+ mandatory: boolean;
108
+ rooms: number[];
109
+ } | undefined)[];
110
+ verified?: boolean | undefined;
111
+ }
112
+ ```
113
+
114
+ Note: The returned string does not include a type name or the `=` symbol. You would need to add these manually if you want a complete type definition.
115
+
116
+ #### Generating Named TypeScript Types with `codeGenWithName`
117
+
118
+ For convenience, if you want to generate a complete type definition including a name, use the `codeGenWithName` function:
119
+
120
+ ```typeScript
121
+ import { codeGenWithName } from 'bguard/codeGen';
122
+ ```
123
+
124
+ This function takes two parameters: the name of the type and the schema.
125
+
126
+ Example:
127
+
128
+ ```typeScript
129
+ const namedTypeString = codeGenWithName('StudentSchema', studentSchema);
130
+ console.log(namedTypeString);
131
+ ```
132
+
133
+ This would output a string:
134
+
135
+ ```typeScript
136
+ type StudentSchema = {
137
+ email?: string | undefined;
138
+ age: number;
139
+ address: string | null;
140
+ classes: ({
141
+ name: string;
142
+ mandatory: boolean;
143
+ rooms: number[];
144
+ } | undefined)[];
145
+ verified?: boolean | undefined;
146
+ }
147
+ ```
148
+
149
+ #### Summary:
150
+
151
+ `codeGen(schema: CommonSchema): string` - Generates a string of the TypeScript type based on the schema. You need to manually add a type name and assignment if needed.
152
+
153
+ `codeGenWithName(typeName: string, schema: CommonSchema): string` - Generates a complete TypeScript type definition string, including the type keyword and type name.
154
+
155
+ ### Validating Data
156
+
157
+ This library provides two methods to parse data against schemas: `parse` and `parseOrFail`. These methods help in validating the data and obtaining structured errors if any issues are found during validation.
158
+
159
+ Let's use above mentioned `studentSchema` and:
160
+
161
+ ```typescript
162
+ // example of valid received data
163
+ const validStudentData = {
91
164
  age: 21,
92
165
  address: '123 Main St',
93
166
  classes: [
@@ -100,49 +173,794 @@ const studentData = {
100
173
  email: 'student@example.com',
101
174
  };
102
175
 
103
- const validatedData = parseSchema(studentSchema, studentData);
176
+ // example of invalid received data with multiple errors
177
+ const invalidStudentData = {
178
+ age: -5,
179
+ address: undefined,
180
+ classes: [
181
+ {
182
+ name: true,
183
+ mandatory: 'true',
184
+ rooms: null,
185
+ },
186
+ ],
187
+ email: 'invalid-example',
188
+ };
189
+ ```
190
+
191
+ #### `parse` Method
192
+
193
+ The `parse` method validates the data and returns a tuple containing errors and the parsed value. This method allows you to choose whether to collect all errors or stop at the first error using an options flag.
194
+
195
+ **Syntax:**
196
+
197
+ ```typescript
198
+ import { parse } from 'bguard';
199
+ // import other dependencies
200
+
201
+ const [errors, parsedValue] = parse(studentSchema, validStudentData, { getAllErrors: true });
202
+ ```
203
+
204
+ Returns:
205
+
206
+ - If validation succeeds: `[undefined, parsedValue]`
207
+ - If there are validation errors: `[ValidationErrorData[], undefined]`
208
+
209
+ Options:
210
+
211
+ - `lng`: Specifies the language for error messages. Default is `'default'`.
212
+ - `getAllErrors`: If `true`, collects all validation errors. If `false` or `undefined`, stops at the first error. Turning off `getAllErrors` provides a runtime optimization, as it stops validation at the first error, avoiding unnecessary checks for the remaining received value.
104
213
 
214
+ #### `parseOrFail` Method
105
215
 
216
+ The `parseOrFail` method validates the data and throws an error on the first validation failure. It is useful when you want to halt processing immediately upon encountering an error.
217
+
218
+ **Syntax:**
219
+
220
+ ```typeScript
221
+ import { parseOrFail } from 'bguard';
222
+ // import other dependencies
223
+
224
+ try {
225
+ // Attempt to parse and validate the studentData using the studentSchema
226
+ const validatedData = parseOrFail(studentSchema, validStudentData);
227
+ // If the data is valid, validatedData will contain the parsed value with inferred TypeScript types
228
+ } catch (error) {
229
+ // If the data does not conform to the schema, an error will be thrown
230
+ console.error(error.message); // Logs the first validation error message, if any
231
+ }
106
232
  ```
107
233
 
108
- If the data does not conform to the schema, an error will be thrown.
234
+ Throws:
235
+
236
+ - `ValidationError`: If any validation rule fails, this error is thrown with details of the first encountered error.
237
+
238
+ Options:
239
+
240
+ - `lng`: Specifies the language for error messages. Default is `'default'`.
241
+
242
+ ####
243
+
244
+ Explanation
109
245
 
246
+ - **`parse` Method**: This method returns a tuple where the first element is an array of validation errors (if any), and the second element is the successfully parsed value (or `undefined` if errors exist). It allows collecting all errors by setting the `getAllErrors` flag.
110
247
 
248
+ - **`parseOrFail` Method**: This method throws a `ValidationError` when the first validation rule fails, making it suitable for scenarios where early termination of validation is desired.
249
+
250
+ - **Options**: Both methods accept options for language settings and error collection, enhancing flexibility in handling validation processes.
111
251
 
112
252
  ### Chaining Methods
113
253
 
114
- - `nullable()`: Allows the value to be null.
115
- - `optional()`: Allows the value to be undefined.
254
+ - `nullable()`: Allows the value to be null.
255
+ - `optional()`: Allows the value to be undefined.
116
256
 
117
- Example:
257
+ Example:
118
258
 
119
- ```typeScript
259
+ ```typeScript
120
260
 
121
261
  const schema = string().nullable().optional();
122
262
  ```
123
263
 
124
- - String Literals:
125
- `string().equalTo('myStringValue')` will infer 'myStringValue' as the type.
126
-
127
- - Number Literals:
128
- `number().equalTo(42)` will infer 42 as the type.
129
-
130
- - Boolean Literals:
131
- `boolean().onlyTrue()` will infer true as the type.
132
- `boolean().onlyFalse()` will infer false as the type.
264
+ - String Literals:
265
+ `string().equalTo('myStringValue')` will infer <b>'myStringValue'</b> as the type.
266
+ `string().oneOfValues(['foo', 'bar'])` will infer <b>'foo' | 'bar'</b> as the type.
267
+
268
+ - Number Literals:
269
+ `number().equalTo(42)` will infer <b>42</b> as the type.
270
+ `number().oneOfValues([3, 5])` will infer <b>3 | 5</b> as the type.
271
+
272
+ - Boolean Literals:
273
+ `boolean().onlyTrue()` will infer <b>true</b> as the type.
274
+ `boolean().onlyFalse()` will infer <b>false</b> as the type.
133
275
 
276
+ ### Custom (Library Built-in) Assertions
134
277
 
278
+ The `custom` method allows you to extend the validation schema with additional asserts. These asserts can either be user-defined or selected from the comprehensive set provided by the library. This flexibility ensures that you can tailor validations to meet specific requirements beyond the standard methods available.
279
+ All built-in asserts are documented in the [Built-in Custom Assert Documentation](#builtin_custom_assert_documentation) section.
135
280
 
136
- ### Custom Assertions
137
- You can extend the validation with custom assertions:
281
+ Example
138
282
 
139
- ```typeScript
283
+ ```typeScript
140
284
  import { min } from 'bguard/number/min';
141
285
  import { max } from 'bguard/number/max';
142
286
 
143
287
  const ageSchema = number().custom(min(18), max(120));
144
288
  ```
145
- Assertions are imported from specific paths for better tree-shaking and smaller bundle sizes.
146
289
 
290
+ Library built-in assertions are imported from specific paths for better tree-shaking and smaller bundle sizes.
291
+
292
+ ### Create Custom Assertions
293
+
294
+ Bguard allows developers to create custom validation functions that can be integrated seamlessly with the library's existing functionality. Below is a detailed example demonstrating how to create a custom validation function, `minLength`, and how to properly document and map error messages for translations.
295
+
296
+ Example: Creating a `minLength` Custom Validation
297
+
298
+ ```typescript
299
+ import { guardException } from 'bguard/exceptions';
300
+ import { ExceptionContext, RequiredValidation } from 'bguard/commonTypes';
301
+ import { setToDefaultLocale } from 'bguard/translationMap';
302
+
303
+ const minLengthErrorMessage = 'The received value {{r}} is shorter than the expected length {{e}}';
304
+ const minLengthErrorKey = 'customPrefix:minLength';
305
+
306
+ export const minLength =
307
+ (expected: number): RequiredValidation =>
308
+ (received: string, ctx: ExceptionContext) => {
309
+ if (received.length < expected) {
310
+ guardException(expected, received, ctx, minLengthErrorKey);
311
+ }
312
+ };
313
+
314
+ minLength.key = minLengthErrorKey;
315
+ minLength.message = minLengthErrorMessage;
316
+ setToDefaultLocale(minLength);
317
+ ```
318
+
319
+ Explanation
320
+
321
+ - Error Key (`minLength.key`): This key (`'customPrefix:minLength'`) uniquely identifies the validation and is used for mapping error messages, especially when supporting multiple languages. It's essential to avoid collisions with built-in assertions, which use prefixes like `s:`, `n:`, and `b:` etc. More on that in [Common and Custom Translations](#common_and_custom_translations).
322
+
323
+ - Error Message (`minLength.message`): The message supports [interpolation](#translation), where `{{e}}` will be replaced by the expected value, and `{{r}}` will be replaced by the received value during validation .
324
+
325
+ - Exception Handling (`guardException`): This function is responsible for throwing the error when the validation fails. The `ctx` parameter must be passed to ensure the internal logic of the application works correctly.
326
+
327
+ - Localization Support (`setToDefaultLocale`): This function registers the default error message with its associated key. If you later decide to support multiple languages, you can easily map this key to different messages.
328
+
329
+ - Key Points for Developers:
330
+
331
+ 1. Always create unique error keys for custom validations to avoid potential conflicts with Bguard's built-in validations.
332
+ 2. Custom validations should use prefixes other than `s:`, `n:`, `b:`, and similar ones reserved for Bguard's internal validations.
333
+ 3. The `minLengthErrorMessage` serves as the default message. If you want to provide translations, you can do so by mapping the error key in the translationMap.
334
+ For single-language applications, you can override the default message by directly passing your custom message to `guardException`.
335
+
336
+ ### Translation {#translation}
337
+
338
+ Bguard provides default translations for error messages, but you can customize them as needed. Each potential error has an `errorKey` and `errorMessage`.
339
+
340
+ Example:
341
+
342
+ Consider the schema:
343
+
344
+ ```typeScript
345
+ const testSchema = object({ foo: number().custom(min(5)) });
346
+ ```
347
+
348
+ The `min` function has:
349
+
350
+ ```typeScript
351
+ const minErrorMessage = 'The received value is less than expected'; // Default error message
352
+ const minErrorKey = 'n:min'; // Error key
353
+ ```
354
+
355
+ If you want to change the error message for `min`, you can do so by importing the `setLocale` function and setting your custom message:
356
+
357
+ ```typeScript
358
+ import { setLocale } from 'bguard/translationMap';
359
+
360
+ setLocale('SR', {
361
+ 'n:min': 'The received value {{r}} found on path {{p}} is less than expected value {{e}}',
362
+ // ... continue adding other translations
363
+ });
364
+ ```
365
+
366
+ With this setup, in the translation namespace 'SR', if the received value is 4, you'll get an error message like:
367
+
368
+ `'The received value 4 found on path .foo is less than expected value 5'`
369
+
370
+ - `{{r}}` - Replaced with the received value.
371
+ - `{{p}}` - Replaced with the path to the error.
372
+ - `{{e}}` - Replaced with the expected value.
373
+
374
+ > **Notice:** Do not overwrite the 'default' namespace. If a translation is missing, it will fall back to the 'default' translation.
375
+
376
+ #### Using Translations
377
+
378
+ To apply the new translation, both `parse` and `parseOrFail` functions accept a lng property in the options object provided as the third parameter:
379
+
380
+ ```typeScript
381
+ parseOrFail(testSchema, { foo: 4 }, { lng: 'SR' });
382
+ // or
383
+ parse(testSchema, { foo: 4 }, { lng: 'SR' });
384
+ ```
385
+
386
+ #### Common and Custom Translations {#common_and_custom_translations}
387
+
388
+ We have two sets of translations: common errors and specific assertions.
389
+
390
+ <b>Common Error Translations</b>:
391
+
392
+ ```
393
+ 'c:optional': 'The required value is missing',
394
+ 'c:nullable': 'Value should not be null',
395
+ 'c:array': 'Expected an array but received a different type',
396
+ 'c:objectType': 'Expected an object but received a different type',
397
+ 'c:objectTypeAsArray': 'Expected an object but received an array. Invalid type of data',
398
+ 'c:unrecognizedProperty': 'This property is not allowed in the object',
399
+ 'c:requiredProperty': 'Missing required property in the object',
400
+ 'c:invalidType': 'Invalid type of data',
401
+ 'c:isBoolean': 'The received value is not {{e}}',
402
+ ```
403
+
404
+ <b>Custom Assertion Translations</b>:
405
+
406
+ For custom assertions, each key and message are located in separate files for better code splitting. There are multiple ways to identify a key:
407
+
408
+ <b>1.</b> Key Construction:
409
+ Keys are constructed as `'{typeId}:{functionName}'`, where `typeId` represents:
410
+
411
+ - c - common
412
+ - n - numbers
413
+ - s - strings
414
+ - b - boolean
415
+ - a - array
416
+ - o - object
417
+ - sy - symbol
418
+ - f - function
419
+ - bi - bigint
420
+ - m - mixed
421
+
422
+ Each `typeId` maps to the folder from which custom assertions are retrieved (except 'common', as explained above).
423
+
424
+ Example:
425
+
426
+ ```typeScript
427
+ import { maxLength } from 'bguard/string/maxLength';
428
+ ```
429
+
430
+ The function located in `'bguard/string/maxLength'` will have the key `'s:maxLength'`.
431
+
432
+ <b>2.</b> Assertion Function Properties:
433
+
434
+ Each assert function has two additional properties: `key` and `message`.
435
+
436
+ ```typeScript
437
+ import { maxLength } from 'bguard/string/maxLength';
438
+
439
+ console.log(maxLength.key); // Output: 's:maxLength'
440
+ console.log(maxLength.message); // Output: 'The received value length is greater than expected'
441
+ ```
442
+
443
+ > **Notice:** Do not directly change these values.
444
+
445
+ <b>3.</b> IDE Support:
446
+ Each key and message will be visible in text editors that support JSDoc IntelliSense.
447
+ ### Built-in Custom Assert Documentation {#builtin_custom_assert_documentation}
448
+
449
+ #### mix
450
+
451
+ ##### equalTo (mix)
452
+
453
+ ```typescript
454
+ import { equalTo } from 'bguard/mix/equalTo';
455
+ ```
456
+
457
+ * _Description_ Creates a custom assertion that checks if a value is equal to the expected value.
458
+ * > **Notice:** It has already been implemented in the number and string schema. There is no need to use it as a custom assert.
459
+ * _Param_ {unknown} expected The value that the received value is expected to match.
460
+ * _Throws_ {ValidationError} If the received value does not match the expected value.
461
+ * _Example_
462
+ ```typescript
463
+ const schema = number().custom(equalTo(5)); // Define a schema with a custom assertion
464
+ parseOrFail(schema, 5); // Valid
465
+ parseOrFail(schema, 3); // Throws an error: 'The received value is not equal to expected'
466
+ ```
467
+ * _See_ Error Translation Key = 'm:equalTo'
468
+
469
+
470
+ ##### oneOfValues (mix)
471
+
472
+ ```typescript
473
+ import { oneOfValues } from 'bguard/mix/oneOfValues';
474
+ ```
475
+
476
+ * _Description_ Creates a custom assertion that checks if a value is equal to the one of expected values.
477
+ * > **Notice:** It has already been implemented in the number and string schema. There is no need to use it as a custom assert.
478
+ * _Param_ {unknown} expected The value that the received value is expected to match.
479
+ * _Throws_ {ValidationError} If the received value does not match at least one of the expected values.
480
+ * _Example_
481
+ ```typescript
482
+ const schema = number().custom(oneOfValues([5, 4])); // Define a schema with a custom assertion
483
+ parseOrFail(schema, 5); // Valid
484
+ parseOrFail(schema, 4); // Valid
485
+ parseOrFail(schema, 3); // Throws an error: 'The received value is not equal to expected'
486
+ ```
487
+ * _See_ Error Translation Key = 'm:oneOfValues'
488
+
489
+ #### number
490
+
491
+ ##### max (number)
492
+
493
+ ```typescript
494
+ import { max } from 'bguard/number/max';
495
+ ```
496
+
497
+ * _Description_ Asserts that a number value does not exceed a specified maximum value.
498
+ * _Param_ {number} expected The maximum allowable value.
499
+ * _Throws_ {ValidationError} if the received value exceeds the expected maximum value.
500
+ * _Example_
501
+ ```typescript
502
+ const schema = number().custom(max(100));
503
+ parseOrFail(schema, 99); // Valid
504
+ parseOrFail(schema, 100); // Valid
505
+ parseOrFail(schema, 101); // Throws an error: 'The received value is greater than expected'
506
+ ```
507
+ * _See_ Error Translation Key = 'n:max'
508
+
509
+
510
+ ##### maxExcluded (number)
511
+
512
+ ```typescript
513
+ import { maxExcluded } from 'bguard/number/maxExcluded';
514
+ ```
515
+
516
+ * _Description_ - Asserts that a number value is strictly less than a specified maximum value (i.e., the maximum value is excluded).
517
+ * _Param_ {number} expected - The maximum allowable value, which is excluded.
518
+ * _Throws_ {ValidationError} if the received value is greater than or equal to the expected maximum value.
519
+ * _Example_
520
+ ```typescript
521
+ const schema = number().custom(maxExcluded(100));
522
+ parseOrFail(schema, 99); // Valid
523
+ parseOrFail(schema, 100); // Throws an error: 'The received value is greater than or equal to expected'
524
+ parseOrFail(schema, 101); // Throws an error: 'The received value is greater than or equal to expected'
525
+ ```
526
+ * _See_ Error Translation Key = 'n:maxExcluded'
527
+
528
+
529
+ ##### min (number)
530
+
531
+ ```typescript
532
+ import { min } from 'bguard/number/min';
533
+ ```
534
+
535
+ * _Description_ Asserts that a number value is not less than a specified minimum value.
536
+ * _Param_ {number} expected The minimum allowable value.
537
+ * _Throws_ {ValidationError} if the received value is less than the expected minimum value.
538
+ * _Example_
539
+ ```typescript
540
+ const schema = number().custom(min(10));
541
+ parseOrFail(schema, 11); // Valid
542
+ parseOrFail(schema, 10); // Valid
543
+ parseOrFail(schema, 9); // Throws an error: 'The received value is less than expected'
544
+ ```
545
+ * _See_ Error Translation Key = 'n:min'
546
+
547
+
548
+ ##### minExcluded (number)
549
+
550
+ ```typescript
551
+ import { minExcluded } from 'bguard/number/minExcluded';
552
+ ```
553
+
554
+ * _Description_ Asserts that a number value is strictly greater than a specified minimum value (i.e., the minimum value is excluded).
555
+ * _Param_ {number} expected The minimum allowable value, which is excluded.
556
+ * _Throws_ {ValidationError} if the received value is less than or equal to the expected minimum value.
557
+ * _Example_
558
+ ```typescript
559
+ const schema = number().custom(minExcluded(10));
560
+ parseOrFail(schema, 11); // Valid
561
+ parseOrFail(schema, 10); // Throws an error: 'The received value is less than or equal to expected'
562
+ parseOrFail(schema, 9); // Throws an error: 'The received value is less than or equal to expected'
563
+ ```
564
+ * _See_ Error Translation Key = 'n:minExcluded'
565
+
566
+
567
+ ##### negative (number)
568
+
569
+ ```typescript
570
+ import { negative } from 'bguard/number/negative';
571
+ ```
572
+
573
+ * _Description_ Asserts that a number value is negative (less than zero).
574
+ * _Throws_ {ValidationError} if the received value is not negative.
575
+ * _Example_
576
+ ```typescript
577
+ const schema = number().custom(negative());
578
+ parseOrFail(schema, -10); // Valid
579
+ parseOrFail(schema, 0); // Throws an error: 'The received value is not a negative number'
580
+ parseOrFail(schema, 5); // Throws an error: 'The received value is not a negative number'
581
+ ```
582
+ * _See_ - Error Translation Key = 'n:negative'
583
+
584
+
585
+ ##### positive (number)
586
+
587
+ ```typescript
588
+ import { positive } from 'bguard/number/positive';
589
+ ```
590
+
591
+ * _Description_ Asserts that a number value is positive (greater than zero).
592
+ * _Throws_ {ValidationError} if the received value is not positive.
593
+ * _Example_
594
+ ```typescript
595
+ const schema = number().custom(positive());
596
+ parseOrFail(schema, 10); // Valid
597
+ parseOrFail(schema, 0); // Throws an error: 'The received value is not a positive number'
598
+ parseOrFail(schema, -5); // Throws an error: 'The received value is not a positive number'
599
+ ```
600
+ * _See_ Error Translation Key = 'n:positive'
601
+
602
+ #### string
603
+
604
+ ##### atLeastOneDigit (string)
605
+
606
+ ```typescript
607
+ import { atLeastOneDigit } from 'bguard/string/atLeastOneDigit';
608
+ ```
609
+
610
+ * _Description_ Asserts that a string value contains at least one digit.
611
+ * _Throws_ {ValidationError} if the received value does not contain at least one digit.
612
+ * _Example_
613
+ ```typescript
614
+ const schema = string().custom(atLeastOneDigit());
615
+ parseOrFail(schema, 'abc123'); // Valid
616
+ parseOrFail(schema, 'abcdef'); // Throws an error: 'The received value does not contain at least one digit'
617
+ ```
618
+ * _See_ Error Translation Key = 's:atLeastOneDigit'
619
+
620
+
621
+ ##### atLeastOneLowerChar (string)
622
+
623
+ ```typescript
624
+ import { atLeastOneLowerChar } from 'bguard/string/atLeastOneLowerChar';
625
+ ```
626
+
627
+ * _Description_ Asserts that a string value contains at least one lowercase character.
628
+ * _Throws_ {ValidationError} if the received value does not contain at least one lowercase character.
629
+ * _Example_
630
+ ```typescript
631
+ const schema = string().custom(atLeastOneLowerChar());
632
+ parseOrFail(schema, 'abcDEF'); // Valid
633
+ parseOrFail(schema, 'ABCDEF'); // Throws an error: 'The received value does not contain at least one lowercase character'
634
+ ```
635
+ * _See_ Error Translation Key = 's:atLeastOneLowerChar'
636
+
637
+
638
+ ##### atLeastOneSpecialChar (string)
639
+
640
+ ```typescript
641
+ import { atLeastOneSpecialChar } from 'bguard/string/atLeastOneSpecialChar';
642
+ ```
643
+
644
+ * _Description_ Asserts that a string value contains at least one special character.
645
+ * _Param_ {string} [allowedSpecialChars=* '@!#%&()^~{}'] The string containing allowed special characters. Defaults to '*@!#%&()^~{}'.
646
+ * _Throws_ {ValidationError} if the received value does not contain at least one of the allowed special characters.
647
+ * _Example_
648
+ ```typescript
649
+ const schema = string().custom(atLeastOneSpecialChar()); // Default special characters
650
+ parseOrFail(schema, 'abc!def'); // Valid
651
+ parseOrFail(schema, 'abcdef'); // Throws an error: 'The received value does not contain at least one special character'
652
+
653
+ const customSchema = string().custom(atLeastOneSpecialChar('@$')); // Custom special characters
654
+ parseOrFail(customSchema, 'abc@def'); // Valid
655
+ parseOrFail(customSchema, 'abcdef'); // Throws an error: 'The received value does not contain at least one special character'
656
+ ```
657
+ * _See_ Error Translation Key = 's:atLeastOneSpecialChar'
658
+
659
+
660
+ ##### atLeastOneUpperChar (string)
661
+
662
+ ```typescript
663
+ import { atLeastOneUpperChar } from 'bguard/string/atLeastOneUpperChar';
664
+ ```
665
+
666
+ * _Description_ Asserts that a string value contains at least one uppercase character.
667
+ * _Throws_ {ValidationError} if the received value does not contain at least one uppercase character.
668
+ * _Example_
669
+ ```typescript
670
+ const schema = string().custom(atLeastOneUpperChar());
671
+ parseOrFail(schema, 'abcDEF'); // Valid
672
+ parseOrFail(schema, 'abcdef'); // Throws an error: 'The received value does not contain at least one uppercase character'
673
+ ```
674
+ * _See_ Error Translation Key = 's:atLeastOneUpperChar'
675
+
676
+
677
+ ##### contains (string)
678
+
679
+ ```typescript
680
+ import { contains } from 'bguard/string/contains';
681
+ ```
682
+
683
+ * _Description_ Asserts that a string value contains a specified substring.
684
+ * _Param_ {string} substring The substring that must be present in the string value.
685
+ * _Throws_ {ValidationError} if the received value does not contain the required substring.
686
+ * _Example_
687
+ ```typescript
688
+ const schema = string().custom(contains('foo'));
689
+ parseOrFail(schema, 'foobar'); // Valid
690
+ parseOrFail(schema, 'bar'); // Throws an error: 'The received value does not contain the required substring'
691
+ ```
692
+ * _See_ Error Translation Key = 's:contains'
693
+
694
+
695
+ ##### email (string)
696
+
697
+ ```typescript
698
+ import { email } from 'bguard/string/email';
699
+ ```
700
+
701
+ * _Description_ Asserts that a string value matches the email pattern. The pattern checks for a basic email format.
702
+ * _Throws_ {ValidationError} if the received value does not match the email pattern.
703
+ * _Example_
704
+ ```typescript
705
+ const schema = string().custom(email());
706
+ parseOrFail(schema, 'example@example.com'); // Valid
707
+ parseOrFail(schema, 'invalid-email'); // Throws an error: 'The received value does not match the required email pattern'
708
+ ```
709
+ * _See_ - Error Translation Key = 's:email'
710
+
711
+
712
+ ##### endsWith (string)
713
+
714
+ ```typescript
715
+ import { endsWith } from 'bguard/string/endsWith';
716
+ ```
717
+
718
+ * _Description_ Asserts that a string value ends with a specified substring.
719
+ * _Param_ {string} substring The substring that the string value must end with.
720
+ * _Throws_ {ValidationError} if the received value does not end with the required substring.
721
+ * _Example_
722
+ ```typescript
723
+ const schema = string().custom(endsWith('bar'));
724
+ parseOrFail(schema, 'foobar'); // Valid
725
+ parseOrFail(schema, 'foofoo'); // Throws an error: 'The received value does not end with the required substring'
726
+ ```
727
+ * _See_ Error Translation Key = 's:endsWith'
728
+
729
+
730
+ ##### lowerCase (string)
731
+
732
+ ```typescript
733
+ import { lowerCase } from 'bguard/string/lowerCase';
734
+ ```
735
+
736
+ * _Description_ Asserts that a string value is in lowercase.
737
+ * _Throws_ {ValidationError} if the received value is not in lowercase.
738
+ * _Example_
739
+ ```typescript
740
+ const schema = string().custom(lowerCase());
741
+ parseOrFail(schema, 'valid'); // Valid
742
+ parseOrFail(schema, 'Invalid'); // Throws an error: 'The received value is not in lowercase'
743
+ ```
744
+ * _See_ Error Translation Key = 's:lowerCase'
745
+
746
+
747
+ ##### maxLength (string)
748
+
749
+ ```typescript
750
+ import { maxLength } from 'bguard/string/maxLength';
751
+ ```
752
+
753
+ * _Description_ Asserts that the length of a string value is not greater than a specified maximum length.
754
+ * _Param_ {number} expected The maximum allowed length for the string.
755
+ * _Throws_ {ValidationError} if the length of the received value is greater than the expected length.
756
+ * _Example_
757
+ ```typescript
758
+ const schema = string().custom(maxLength(10));
759
+ parseOrFail(schema, 'short'); // Valid
760
+ parseOrFail(schema, 'this is a very long string'); // Throws an error: 'The received value length is greater than expected'
761
+ ```
762
+ * _See_ Error Translation Key = 's:maxLength'
763
+
764
+
765
+ ##### minLength (string)
766
+
767
+ ```typescript
768
+ import { minLength } from 'bguard/string/minLength';
769
+ ```
770
+
771
+ * _Description_ Asserts that the length of a string value is not less than a specified minimum length.
772
+ * _Param_ {number} expected The minimum required length for the string.
773
+ * _Throws_ {ValidationError} if the length of the received value is less than the expected length.
774
+ * _Example_
775
+ ```typescript
776
+ const schema = string().custom(minLength(5));
777
+ parseOrFail(schema, 'short'); // Throws an error: 'The received value length is less than expected'
778
+ parseOrFail(schema, 'adequate'); // Valid
779
+ ```
780
+ * _See_ Error Translation Key = 's:minLength'
781
+
782
+
783
+ ##### regExp (string)
784
+
785
+ ```typescript
786
+ import { regExp } from 'bguard/string/regExp';
787
+ ```
788
+
789
+ * _Description_ Asserts that a string value matches a specified regular expression pattern.
790
+ * _Param_ {RegExp} expected The regular expression pattern that the string value should match.
791
+ * _Throws_ {ValidationError} if the received value does not match the expected pattern.
792
+ * _Example_
793
+ ```typescript
794
+ const schema = string().custom(regExp(/^[A-Za-z0-9]+$/)); // Validates against alphanumeric pattern
795
+ parseOrFail(schema, 'valid123'); // Valid
796
+ parseOrFail(schema, 'invalid!@#'); // Throws an error: 'The received value does not match the required text pattern'
797
+ ```
798
+ * _See_ Error Translation Key = 's:regExp'
799
+
800
+
801
+ ##### startsWith (string)
802
+
803
+ ```typescript
804
+ import { startsWith } from 'bguard/string/startsWith';
805
+ ```
806
+
807
+ * _Description_ Asserts that a string value starts with a specified substring.
808
+ * _Param_ {string} substring The substring that the string value must start with.
809
+ * _Throws_ {ValidationError} if the received value does not start with the required substring.
810
+ * _Example_
811
+ ```typescript
812
+ const schema = string().custom(startsWith('foo'));
813
+ parseOrFail(schema, 'foobar'); // Valid
814
+ parseOrFail(schema, 'barfoo'); // Throws an error: 'The received value does not start with the required substring'
815
+ ```
816
+ * _See_ Error Translation Key = 's:startsWith'
817
+
818
+
819
+ ##### upperCase (string)
820
+
821
+ ```typescript
822
+ import { upperCase } from 'bguard/string/upperCase';
823
+ ```
824
+
825
+ * _Description_ Asserts that a string value is entirely in uppercase.
826
+ * _Throws_ {ValidationError} if the received value is not in uppercase.
827
+ * _Example_
828
+ ```typescript
829
+ const schema = string().custom(upperCase());
830
+ parseOrFail(schema, 'VALID'); // Valid
831
+ parseOrFail(schema, 'INVALID'); // Throws an error: 'The received value is not in uppercase'
832
+ parseOrFail(schema, 'Valid'); // Throws an error: 'The received value is not in uppercase'
833
+ ```
834
+ * _See_ Error Translation Key = 's:upperCase'
835
+
836
+
837
+ ##### uuid (string)
838
+
839
+ ```typescript
840
+ import { uuid } from 'bguard/string/uuid';
841
+ ```
842
+
843
+ * _Description_ Asserts that a string value matches the UUID format.
844
+ * _Throws_ {ValidationError} if the received value is not a valid UUID.
845
+ * _Example_
846
+ ```typescript
847
+ const schema = string().custom(uuid());
848
+ parseOrFail(schema, '123e4567-e89b-12d3-a456-426614174000'); // Valid
849
+ parseOrFail(schema, 'invalid-uuid'); // Throws an error: 'The received value is not a valid UUID'
850
+ ```
851
+ * _See_ Error Translation Key = 's:uuid'
852
+
853
+
854
+ ##### uuidV1 (string)
855
+
856
+ ```typescript
857
+ import { uuidV1 } from 'bguard/string/uuidV1';
858
+ ```
859
+
860
+ * _Description_ Asserts that a string value matches the UUID v1 format.
861
+ * _Throws_ {ValidationError} if the received value is not a valid UUID v1.
862
+ * _Example_
863
+ ```typescript
864
+ const schema = string().custom(uuidV1());
865
+ parseOrFail(schema, '550e8400-e29b-11d4-a716-446655440000'); // Valid
866
+ parseOrFail(schema, '550e8400-e29b-21d4-a716-446655440000'); // Throws an error: 'The received value is not a valid UUID v1'
867
+ parseOrFail(schema, 'invalid-uuid'); // Throws an error: 'The received value is not a valid UUID v1'
868
+ ```
869
+ * _See_ Error Translation Key = 's:uuidV1'
870
+
871
+
872
+ ##### uuidV2 (string)
873
+
874
+ ```typescript
875
+ import { uuidV2 } from 'bguard/string/uuidV2';
876
+ ```
877
+
878
+ * _Description_ Asserts that a string value matches the UUID v2 format.
879
+ * _Throws_ {ValidationError} if the received value is not a valid UUID v2.
880
+ * _Example_
881
+ ```typescript
882
+ const schema = string().custom(uuidV2());
883
+ parseOrFail(schema, '550e8400-e29b-21d4-a716-446655440000'); // Valid
884
+ parseOrFail(schema, '550e8400-e29b-31d4-d716-446655440000'); // Throws an error: 'The received value is not a valid UUID v2'
885
+ parseOrFail(schema, 'invalid-uuid'); // Throws an error: 'The received value is not a valid UUID v2'
886
+ ```
887
+ * _See_ Error Translation Key = 's:uuidV2'
888
+
889
+
890
+ ##### uuidV3 (string)
891
+
892
+ ```typescript
893
+ import { uuidV3 } from 'bguard/string/uuidV3';
894
+ ```
895
+
896
+ * _Description_ Asserts that a string value matches the UUID v3 format.
897
+ * _Throws_ {ValidationError} if the received value is not a valid UUID v3.
898
+ * _Example_
899
+ ```typescript
900
+ const schema = string().custom(uuidV3());
901
+ parseOrFail(schema, '550e8400-e29b-38d1-a456-426614174000'); // Valid
902
+ parseOrFail(schema, '550e8400-e29b-28d1-a456-426614174000'); // Throws an error: 'The received value is not a valid UUID v3'
903
+ parseOrFail(schema, 'invalid-uuid'); // Throws an error: 'The received value is not a valid UUID v3'
904
+ ```
905
+ * _See_ Error Translation Key = 's:uuidV3'
906
+
907
+
908
+ ##### uuidV4 (string)
909
+
910
+ ```typescript
911
+ import { uuidV4 } from 'bguard/string/uuidV4';
912
+ ```
913
+
914
+ * _Description_ Asserts that a string value matches the UUID v4 format.
915
+ * _Throws_ {ValidationError} if the received value is not a valid UUID v4.
916
+ * _Example_
917
+ ```typescript
918
+ const schema = string().custom(uuidV4());
919
+ parseOrFail(schema, '123e4567-e89b-42d3-a456-426614174000'); // Valid
920
+ parseOrFail(schema, '123e4567-e89b-12d3-a456-426614174000'); // Throws an error: 'The received value is not a valid UUID v4'
921
+ parseOrFail(schema, '123e4567-e89b-a2d3-a456-426614174000'); // Throws an error: 'The received value is not a valid UUID v4'
922
+ parseOrFail(schema, '123e4567-e89b-42d3-c456-426614174000'); // Throws an error: 'The received value is not a valid UUID v4'
923
+ parseOrFail(schema, 'invalid-uuid'); // Throws an error: 'The received value is not a valid UUID v4'
924
+ ```
925
+ * _See_ Error Translation Key = 's:uuidV4'
926
+
927
+
928
+ ##### uuidV5 (string)
929
+
930
+ ```typescript
931
+ import { uuidV5 } from 'bguard/string/uuidV5';
932
+ ```
933
+
934
+ * _Description_ Asserts that a string value matches the UUID v5 format.
935
+ * _Throws_ {ValidationError} if the received value is not a valid UUID v5.
936
+ * _Example_
937
+ ```typescript
938
+ const schema = string().custom(uuidV5());
939
+ parseOrFail(schema, '550e8400-e29b-51d4-a716-446655440000'); // Valid
940
+ parseOrFail(schema, '550e8400-e29b-41d4-a716-446655440000'); // Throws an error: 'The received value is not a valid UUID v5'
941
+ parseOrFail(schema, 'invalid-uuid'); // Throws an error: 'The received value is not a valid UUID v5'
942
+ ```
943
+ * _See_ Error Translation Key = 's:uuidV5'
944
+
945
+
946
+ ##### validUrl (string)
947
+
948
+ ```typescript
949
+ import { validUrl } from 'bguard/string/validUrl';
950
+ ```
951
+
952
+ * _Description_ Asserts that the string value is a valid URL with optional protocol validation.
953
+ * _Param_ {string} [protocol] The protocol that the URL must start with (e.g., 'http'). If not provided, any URL starting with 'http://' or 'https://' is considered valid.
954
+ * _Throws_ {ValidationError} if the received value does not match the expected URL pattern.
955
+ * _Example_
956
+ ```typescript
957
+ const schema = string().custom(validUrl()); // Validates any URL starting with 'http://' or 'https://'
958
+ parseOrFail(schema, 'http://example.com'); // Valid
959
+ parseOrFail(schema, 'https://example.com'); // Valid
960
+ parseOrFail(schema, 'ftp://example.com'); // Throws an error
961
+ parseOrFail(schema, 'http:example.com'); // Throws an error
962
+ ```
963
+ * _See_ Error Translation Key = 's:url'
964
+
147
965
  ### Contributing
148
966
  Contributions are welcome! Please open an issue or submit a pull request for any bugs or feature requests.