bguard 0.2.0 → 0.3.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 (329) hide show
  1. package/README.md +562 -380
  2. package/lib/{CommonSchema-DJmQ3F_9.d.mts → CommonSchema-CiY7spmg.d.mts} +9 -1
  3. package/lib/{CommonSchema-9RtxTxdX.d.ts → CommonSchema-D9QVJBJe.d.ts} +9 -1
  4. package/lib/InferType.d.mts +1 -1
  5. package/lib/InferType.d.ts +1 -1
  6. package/lib/asserts/array/index.d.mts +1 -1
  7. package/lib/asserts/array/index.d.ts +1 -1
  8. package/lib/asserts/array/index.js +8 -6
  9. package/lib/asserts/array/index.js.map +1 -1
  10. package/lib/asserts/array/index.mjs +7 -5
  11. package/lib/asserts/array/index.mjs.map +1 -1
  12. package/lib/asserts/array/maxArrayLength.d.mts +22 -0
  13. package/lib/asserts/array/maxArrayLength.d.ts +22 -0
  14. package/lib/asserts/array/maxArrayLength.js +20 -0
  15. package/lib/asserts/array/maxArrayLength.js.map +1 -0
  16. package/lib/asserts/array/maxArrayLength.mjs +20 -0
  17. package/lib/asserts/array/maxArrayLength.mjs.map +1 -0
  18. package/lib/asserts/array/minArrayLength.d.mts +22 -0
  19. package/lib/asserts/array/minArrayLength.d.ts +22 -0
  20. package/lib/asserts/array/minArrayLength.js +20 -0
  21. package/lib/asserts/array/minArrayLength.js.map +1 -0
  22. package/lib/asserts/array/minArrayLength.mjs +20 -0
  23. package/lib/asserts/array/minArrayLength.mjs.map +1 -0
  24. package/lib/asserts/bigint/bigintMax.js +4 -4
  25. package/lib/asserts/bigint/bigintMax.mjs +2 -2
  26. package/lib/asserts/bigint/bigintMaxExcluded.js +4 -4
  27. package/lib/asserts/bigint/bigintMaxExcluded.mjs +2 -2
  28. package/lib/asserts/bigint/bigintMin.js +4 -4
  29. package/lib/asserts/bigint/bigintMin.mjs +2 -2
  30. package/lib/asserts/bigint/bigintMinExcluded.js +4 -4
  31. package/lib/asserts/bigint/bigintMinExcluded.mjs +2 -2
  32. package/lib/asserts/bigint/index.d.mts +1 -1
  33. package/lib/asserts/bigint/index.d.ts +1 -1
  34. package/lib/asserts/bigint/index.js +11 -10
  35. package/lib/asserts/bigint/index.js.map +1 -1
  36. package/lib/asserts/bigint/index.mjs +10 -9
  37. package/lib/asserts/bigint/index.mjs.map +1 -1
  38. package/lib/asserts/boolean/index.d.mts +1 -1
  39. package/lib/asserts/boolean/index.d.ts +1 -1
  40. package/lib/asserts/boolean/index.js +9 -7
  41. package/lib/asserts/boolean/index.js.map +1 -1
  42. package/lib/asserts/boolean/index.mjs +8 -6
  43. package/lib/asserts/boolean/index.mjs.map +1 -1
  44. package/lib/asserts/date/dateMax.js +6 -6
  45. package/lib/asserts/date/dateMax.js.map +1 -1
  46. package/lib/asserts/date/dateMax.mjs +5 -5
  47. package/lib/asserts/date/dateMax.mjs.map +1 -1
  48. package/lib/asserts/date/dateMin.js +6 -6
  49. package/lib/asserts/date/dateMin.js.map +1 -1
  50. package/lib/asserts/date/dateMin.mjs +5 -5
  51. package/lib/asserts/date/dateMin.mjs.map +1 -1
  52. package/lib/asserts/date/index.d.mts +1 -1
  53. package/lib/asserts/date/index.d.ts +1 -1
  54. package/lib/asserts/date/index.js +8 -6
  55. package/lib/asserts/date/index.js.map +1 -1
  56. package/lib/asserts/date/index.mjs +7 -5
  57. package/lib/asserts/date/index.mjs.map +1 -1
  58. package/lib/asserts/mix/equalTo.js +4 -4
  59. package/lib/asserts/mix/equalTo.mjs +3 -3
  60. package/lib/asserts/mix/index.d.mts +1 -1
  61. package/lib/asserts/mix/index.d.ts +1 -1
  62. package/lib/asserts/mix/index.js +7 -5
  63. package/lib/asserts/mix/index.js.map +1 -1
  64. package/lib/asserts/mix/index.mjs +6 -4
  65. package/lib/asserts/mix/index.mjs.map +1 -1
  66. package/lib/asserts/mix/oneOfValues.js +4 -4
  67. package/lib/asserts/mix/oneOfValues.mjs +3 -3
  68. package/lib/asserts/number/index.d.mts +1 -1
  69. package/lib/asserts/number/index.d.ts +1 -1
  70. package/lib/asserts/number/index.js +11 -10
  71. package/lib/asserts/number/index.js.map +1 -1
  72. package/lib/asserts/number/index.mjs +10 -9
  73. package/lib/asserts/number/index.mjs.map +1 -1
  74. package/lib/asserts/number/max.js +4 -4
  75. package/lib/asserts/number/max.mjs +2 -2
  76. package/lib/asserts/number/maxExcluded.js +4 -4
  77. package/lib/asserts/number/maxExcluded.mjs +2 -2
  78. package/lib/asserts/number/min.js +4 -4
  79. package/lib/asserts/number/min.mjs +2 -2
  80. package/lib/asserts/number/minExcluded.js +4 -4
  81. package/lib/asserts/number/minExcluded.mjs +2 -2
  82. package/lib/asserts/number/negative.js +4 -4
  83. package/lib/asserts/number/negative.mjs +2 -2
  84. package/lib/asserts/number/positive.js +4 -4
  85. package/lib/asserts/number/positive.mjs +2 -2
  86. package/lib/asserts/object/index.d.mts +1 -1
  87. package/lib/asserts/object/index.d.ts +1 -1
  88. package/lib/asserts/object/index.js +8 -6
  89. package/lib/asserts/object/index.js.map +1 -1
  90. package/lib/asserts/object/index.mjs +7 -5
  91. package/lib/asserts/object/index.mjs.map +1 -1
  92. package/lib/asserts/string/atLeastOneDigit.js +4 -4
  93. package/lib/asserts/string/atLeastOneDigit.mjs +2 -2
  94. package/lib/asserts/string/atLeastOneLowerChar.js +4 -4
  95. package/lib/asserts/string/atLeastOneLowerChar.mjs +2 -2
  96. package/lib/asserts/string/atLeastOneSpecialChar.js +4 -4
  97. package/lib/asserts/string/atLeastOneSpecialChar.mjs +2 -2
  98. package/lib/asserts/string/atLeastOneUpperChar.js +4 -4
  99. package/lib/asserts/string/atLeastOneUpperChar.mjs +2 -2
  100. package/lib/asserts/string/contains.js +4 -4
  101. package/lib/asserts/string/contains.mjs +2 -2
  102. package/lib/asserts/string/email.js +4 -4
  103. package/lib/asserts/string/email.mjs +2 -2
  104. package/lib/asserts/string/endsWith.js +4 -4
  105. package/lib/asserts/string/endsWith.mjs +2 -2
  106. package/lib/asserts/string/index.d.mts +1 -1
  107. package/lib/asserts/string/index.d.ts +1 -1
  108. package/lib/asserts/string/index.js +11 -10
  109. package/lib/asserts/string/index.js.map +1 -1
  110. package/lib/asserts/string/index.mjs +10 -9
  111. package/lib/asserts/string/index.mjs.map +1 -1
  112. package/lib/asserts/string/isValidDate.d.mts +21 -0
  113. package/lib/asserts/string/isValidDate.d.ts +21 -0
  114. package/lib/asserts/string/isValidDate.js +25 -0
  115. package/lib/asserts/string/isValidDate.js.map +1 -0
  116. package/lib/asserts/string/isValidDate.mjs +25 -0
  117. package/lib/asserts/string/isValidDate.mjs.map +1 -0
  118. package/lib/asserts/string/isValidDateTime.d.mts +35 -0
  119. package/lib/asserts/string/isValidDateTime.d.ts +35 -0
  120. package/lib/asserts/string/isValidDateTime.js +32 -0
  121. package/lib/asserts/string/isValidDateTime.js.map +1 -0
  122. package/lib/asserts/string/isValidDateTime.mjs +32 -0
  123. package/lib/asserts/string/isValidDateTime.mjs.map +1 -0
  124. package/lib/asserts/string/isValidTime.d.mts +29 -0
  125. package/lib/asserts/string/isValidTime.d.ts +29 -0
  126. package/lib/asserts/string/isValidTime.js +32 -0
  127. package/lib/asserts/string/isValidTime.js.map +1 -0
  128. package/lib/asserts/string/isValidTime.mjs +32 -0
  129. package/lib/asserts/string/isValidTime.mjs.map +1 -0
  130. package/lib/asserts/string/lowerCase.js +4 -4
  131. package/lib/asserts/string/lowerCase.mjs +2 -2
  132. package/lib/asserts/string/maxLength.js +4 -4
  133. package/lib/asserts/string/maxLength.mjs +2 -2
  134. package/lib/asserts/string/minLength.js +4 -4
  135. package/lib/asserts/string/minLength.mjs +2 -2
  136. package/lib/asserts/string/regExp.js +4 -4
  137. package/lib/asserts/string/regExp.mjs +2 -2
  138. package/lib/asserts/string/startsWith.js +4 -4
  139. package/lib/asserts/string/startsWith.mjs +2 -2
  140. package/lib/asserts/string/upperCase.js +4 -4
  141. package/lib/asserts/string/upperCase.mjs +2 -2
  142. package/lib/asserts/string/uuid.js +4 -4
  143. package/lib/asserts/string/uuid.mjs +2 -2
  144. package/lib/asserts/string/uuidV1.js +4 -4
  145. package/lib/asserts/string/uuidV1.mjs +2 -2
  146. package/lib/asserts/string/uuidV2.js +4 -4
  147. package/lib/asserts/string/uuidV2.mjs +2 -2
  148. package/lib/asserts/string/uuidV3.js +4 -4
  149. package/lib/asserts/string/uuidV3.mjs +2 -2
  150. package/lib/asserts/string/uuidV4.js +4 -4
  151. package/lib/asserts/string/uuidV4.mjs +2 -2
  152. package/lib/asserts/string/uuidV5.js +4 -4
  153. package/lib/asserts/string/uuidV5.mjs +2 -2
  154. package/lib/asserts/string/validUrl.js +4 -4
  155. package/lib/asserts/string/validUrl.mjs +2 -2
  156. package/lib/{chunk-32J4WVLE.js → chunk-2D5QE7F4.js} +17 -15
  157. package/lib/chunk-2D5QE7F4.js.map +1 -0
  158. package/lib/{chunk-XFR7Y4XX.mjs → chunk-2MFBOVP2.mjs} +3 -3
  159. package/lib/chunk-2MFBOVP2.mjs.map +1 -0
  160. package/lib/chunk-3IOQH3K4.js +74 -0
  161. package/lib/chunk-3IOQH3K4.js.map +1 -0
  162. package/lib/chunk-3ZPLJ5KC.js +14 -0
  163. package/lib/{chunk-LWAEUS2F.js.map → chunk-3ZPLJ5KC.js.map} +1 -1
  164. package/lib/{chunk-QV4JDW3T.mjs → chunk-4GDBM5LP.mjs} +2 -2
  165. package/lib/{chunk-PVOHKGBW.mjs → chunk-5HT3PYSG.mjs} +4 -4
  166. package/lib/chunk-5HT3PYSG.mjs.map +1 -0
  167. package/lib/{chunk-XZTZC73V.mjs → chunk-5LLJ22IG.mjs} +25 -17
  168. package/lib/chunk-5LLJ22IG.mjs.map +1 -0
  169. package/lib/{chunk-MRWZVTNH.mjs → chunk-ADSMWGDJ.mjs} +4 -4
  170. package/lib/{chunk-VGF3Y2EK.js → chunk-AN3VHQEQ.js} +7 -7
  171. package/lib/{chunk-VGF3Y2EK.js.map → chunk-AN3VHQEQ.js.map} +1 -1
  172. package/lib/chunk-AOUFWACR.mjs +74 -0
  173. package/lib/chunk-AOUFWACR.mjs.map +1 -0
  174. package/lib/{chunk-WK4O3HH4.js → chunk-AY7HKAG2.js} +2 -3
  175. package/lib/chunk-AY7HKAG2.js.map +1 -0
  176. package/lib/{chunk-M6OCVAUD.mjs → chunk-BUXOCPHI.mjs} +3 -3
  177. package/lib/{chunk-54RHVQFA.mjs → chunk-D42ISCFK.mjs} +2 -2
  178. package/lib/{chunk-5EIBKBYS.js → chunk-EU3ZZF7Y.js} +13 -13
  179. package/lib/chunk-EU3ZZF7Y.js.map +1 -0
  180. package/lib/{chunk-PEWNA24X.mjs → chunk-KBZUNXJB.mjs} +4 -4
  181. package/lib/chunk-KBZUNXJB.mjs.map +1 -0
  182. package/lib/chunk-LYNVPN3R.js +28 -0
  183. package/lib/chunk-LYNVPN3R.js.map +1 -0
  184. package/lib/{chunk-7XFLH6R2.mjs → chunk-NP64RC7B.mjs} +2 -3
  185. package/lib/chunk-NP64RC7B.mjs.map +1 -0
  186. package/lib/{chunk-YPAUFM3S.mjs → chunk-OHEMRF7Y.mjs} +3 -3
  187. package/lib/{chunk-QLVLZRHT.js → chunk-OJSTQQ3N.js} +5 -5
  188. package/lib/chunk-OJSTQQ3N.js.map +1 -0
  189. package/lib/{chunk-5AO66YV5.mjs → chunk-OKF3BVUD.mjs} +4 -4
  190. package/lib/{chunk-N6YMNLXG.js → chunk-OO6BTBVP.js} +11 -11
  191. package/lib/chunk-OO6BTBVP.js.map +1 -0
  192. package/lib/{chunk-SEIKS6G7.js → chunk-P6V6S6TZ.js} +19 -15
  193. package/lib/chunk-P6V6S6TZ.js.map +1 -0
  194. package/lib/{chunk-MTJJKWTP.js → chunk-PESVL5YJ.js} +7 -7
  195. package/lib/{chunk-MTJJKWTP.js.map → chunk-PESVL5YJ.js.map} +1 -1
  196. package/lib/{chunk-7GIRQ5EA.js → chunk-PIBDJJUU.js} +31 -23
  197. package/lib/chunk-PIBDJJUU.js.map +1 -0
  198. package/lib/{chunk-WPHJ4QTB.js → chunk-SPWF5IFU.js} +5 -5
  199. package/lib/{chunk-WPHJ4QTB.js.map → chunk-SPWF5IFU.js.map} +1 -1
  200. package/lib/{chunk-Z7OEFOAD.mjs → chunk-TQWUSDQD.mjs} +8 -8
  201. package/lib/chunk-TQWUSDQD.mjs.map +1 -0
  202. package/lib/{chunk-CQWI6YRI.js → chunk-UZ2PWO4O.js} +4 -4
  203. package/lib/{chunk-CQWI6YRI.js.map → chunk-UZ2PWO4O.js.map} +1 -1
  204. package/lib/{chunk-356HMXOP.js → chunk-VBTWYDEM.js} +4 -4
  205. package/lib/chunk-VBTWYDEM.js.map +1 -0
  206. package/lib/{chunk-4SPM2CSQ.js → chunk-W2GOLG3K.js} +5 -5
  207. package/lib/{chunk-4SPM2CSQ.js.map → chunk-W2GOLG3K.js.map} +1 -1
  208. package/lib/{chunk-GDSB7CDN.mjs → chunk-YBVMP4EI.mjs} +4 -4
  209. package/lib/chunk-YBVMP4EI.mjs.map +1 -0
  210. package/lib/{chunk-PJI3DRGP.mjs → chunk-YPAFWVDL.mjs} +4 -4
  211. package/lib/chunk-YPAFWVDL.mjs.map +1 -0
  212. package/lib/{chunk-UV4I7JZR.mjs → chunk-ZMEQCIRN.mjs} +16 -12
  213. package/lib/chunk-ZMEQCIRN.mjs.map +1 -0
  214. package/lib/{chunk-4SR7J2I4.js → chunk-ZVW3IHBW.js} +8 -8
  215. package/lib/chunk-ZVW3IHBW.js.map +1 -0
  216. package/lib/{chunk-TP5I237J.mjs → chunk-ZWE5Q37U.mjs} +14 -12
  217. package/lib/chunk-ZWE5Q37U.mjs.map +1 -0
  218. package/lib/codeGen.d.mts +1 -1
  219. package/lib/codeGen.d.ts +1 -1
  220. package/lib/codeGen.js +4 -4
  221. package/lib/codeGen.mjs +3 -3
  222. package/lib/exceptions.js +2 -2
  223. package/lib/exceptions.mjs +1 -1
  224. package/lib/helpers/core.d.mts +1 -1
  225. package/lib/helpers/core.d.ts +1 -1
  226. package/lib/helpers/core.js +4 -4
  227. package/lib/helpers/core.mjs +3 -3
  228. package/lib/helpers/isValidDateInner.d.mts +3 -0
  229. package/lib/helpers/isValidDateInner.d.ts +3 -0
  230. package/lib/helpers/isValidDateInner.js +7 -0
  231. package/lib/helpers/isValidDateInner.js.map +1 -0
  232. package/lib/helpers/isValidDateInner.mjs +7 -0
  233. package/lib/helpers/setStrictType.d.mts +1 -1
  234. package/lib/helpers/setStrictType.d.ts +1 -1
  235. package/lib/helpers/setStrictType.js +5 -5
  236. package/lib/helpers/setStrictType.mjs +4 -4
  237. package/lib/index.d.mts +1 -1
  238. package/lib/index.d.ts +1 -1
  239. package/lib/index.js +7 -7
  240. package/lib/index.mjs +6 -6
  241. package/lib/parse.d.mts +1 -1
  242. package/lib/parse.d.ts +1 -1
  243. package/lib/parse.js +6 -6
  244. package/lib/parse.mjs +5 -5
  245. package/lib/parseOrFail.d.mts +1 -1
  246. package/lib/parseOrFail.d.ts +1 -1
  247. package/lib/parseOrFail.js +6 -6
  248. package/lib/parseOrFail.mjs +5 -5
  249. package/lib/schemas/ArraySchema.d.mts +2 -2
  250. package/lib/schemas/ArraySchema.d.ts +2 -2
  251. package/lib/schemas/ArraySchema.js +8 -6
  252. package/lib/schemas/ArraySchema.js.map +1 -1
  253. package/lib/schemas/ArraySchema.mjs +7 -5
  254. package/lib/schemas/BigIntSchema.d.mts +3 -2
  255. package/lib/schemas/BigIntSchema.d.ts +3 -2
  256. package/lib/schemas/BigIntSchema.js +11 -10
  257. package/lib/schemas/BigIntSchema.js.map +1 -1
  258. package/lib/schemas/BigIntSchema.mjs +10 -9
  259. package/lib/schemas/BooleanSchema.d.mts +2 -2
  260. package/lib/schemas/BooleanSchema.d.ts +2 -2
  261. package/lib/schemas/BooleanSchema.js +9 -7
  262. package/lib/schemas/BooleanSchema.js.map +1 -1
  263. package/lib/schemas/BooleanSchema.mjs +8 -6
  264. package/lib/schemas/CommonSchema.d.mts +1 -1
  265. package/lib/schemas/CommonSchema.d.ts +1 -1
  266. package/lib/schemas/CommonSchema.js +7 -5
  267. package/lib/schemas/CommonSchema.js.map +1 -1
  268. package/lib/schemas/CommonSchema.mjs +6 -4
  269. package/lib/schemas/DateSchema.d.mts +2 -2
  270. package/lib/schemas/DateSchema.d.ts +2 -2
  271. package/lib/schemas/DateSchema.js +8 -6
  272. package/lib/schemas/DateSchema.js.map +1 -1
  273. package/lib/schemas/DateSchema.mjs +7 -5
  274. package/lib/schemas/NumberSchema.d.mts +2 -2
  275. package/lib/schemas/NumberSchema.d.ts +2 -2
  276. package/lib/schemas/NumberSchema.js +11 -10
  277. package/lib/schemas/NumberSchema.js.map +1 -1
  278. package/lib/schemas/NumberSchema.mjs +10 -9
  279. package/lib/schemas/ObjectSchema.d.mts +2 -2
  280. package/lib/schemas/ObjectSchema.d.ts +2 -2
  281. package/lib/schemas/ObjectSchema.js +8 -6
  282. package/lib/schemas/ObjectSchema.js.map +1 -1
  283. package/lib/schemas/ObjectSchema.mjs +7 -5
  284. package/lib/schemas/StringSchema.d.mts +3 -2
  285. package/lib/schemas/StringSchema.d.ts +3 -2
  286. package/lib/schemas/StringSchema.js +11 -10
  287. package/lib/schemas/StringSchema.js.map +1 -1
  288. package/lib/schemas/StringSchema.mjs +10 -9
  289. package/lib/translationMap.js +3 -3
  290. package/lib/translationMap.mjs +2 -2
  291. package/package.json +1 -1
  292. package/lib/chunk-2OINKFOA.js +0 -28
  293. package/lib/chunk-2OINKFOA.js.map +0 -1
  294. package/lib/chunk-32J4WVLE.js.map +0 -1
  295. package/lib/chunk-356HMXOP.js.map +0 -1
  296. package/lib/chunk-4SR7J2I4.js.map +0 -1
  297. package/lib/chunk-4UF67IQ2.mjs +0 -42
  298. package/lib/chunk-4UF67IQ2.mjs.map +0 -1
  299. package/lib/chunk-5EIBKBYS.js.map +0 -1
  300. package/lib/chunk-7GIRQ5EA.js.map +0 -1
  301. package/lib/chunk-7XFLH6R2.mjs.map +0 -1
  302. package/lib/chunk-EQNVYAKS.js +0 -42
  303. package/lib/chunk-EQNVYAKS.js.map +0 -1
  304. package/lib/chunk-GDSB7CDN.mjs.map +0 -1
  305. package/lib/chunk-LWAEUS2F.js +0 -14
  306. package/lib/chunk-N6YMNLXG.js.map +0 -1
  307. package/lib/chunk-PEWNA24X.mjs.map +0 -1
  308. package/lib/chunk-PJI3DRGP.mjs.map +0 -1
  309. package/lib/chunk-PVOHKGBW.mjs.map +0 -1
  310. package/lib/chunk-QLVLZRHT.js.map +0 -1
  311. package/lib/chunk-SEIKS6G7.js.map +0 -1
  312. package/lib/chunk-TP5I237J.mjs.map +0 -1
  313. package/lib/chunk-UV4I7JZR.mjs.map +0 -1
  314. package/lib/chunk-WK4O3HH4.js.map +0 -1
  315. package/lib/chunk-XFR7Y4XX.mjs.map +0 -1
  316. package/lib/chunk-XZTZC73V.mjs.map +0 -1
  317. package/lib/chunk-Z7OEFOAD.mjs.map +0 -1
  318. package/lib/helpers/isValidDate.d.mts +0 -3
  319. package/lib/helpers/isValidDate.d.ts +0 -3
  320. package/lib/helpers/isValidDate.js +0 -7
  321. package/lib/helpers/isValidDate.js.map +0 -1
  322. package/lib/helpers/isValidDate.mjs +0 -7
  323. /package/lib/{chunk-QV4JDW3T.mjs.map → chunk-4GDBM5LP.mjs.map} +0 -0
  324. /package/lib/{chunk-MRWZVTNH.mjs.map → chunk-ADSMWGDJ.mjs.map} +0 -0
  325. /package/lib/{chunk-M6OCVAUD.mjs.map → chunk-BUXOCPHI.mjs.map} +0 -0
  326. /package/lib/{chunk-54RHVQFA.mjs.map → chunk-D42ISCFK.mjs.map} +0 -0
  327. /package/lib/{chunk-YPAUFM3S.mjs.map → chunk-OHEMRF7Y.mjs.map} +0 -0
  328. /package/lib/{chunk-5AO66YV5.mjs.map → chunk-OKF3BVUD.mjs.map} +0 -0
  329. /package/lib/helpers/{isValidDate.mjs.map → isValidDateInner.mjs.map} +0 -0
package/README.md CHANGED
@@ -116,7 +116,7 @@ This would output a string:
116
116
  }
117
117
  ```
118
118
 
119
- 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.
119
+ > **Notice:** 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.
120
120
 
121
121
  #### Generating Named TypeScript Types with `codeGenWithName`
122
122
 
@@ -256,14 +256,25 @@ Explanation
256
256
 
257
257
  ### Chaining Methods
258
258
 
259
- - `nullable()`: Allows the value to be null.
260
- - `optional()`: Allows the value to be undefined.
259
+ - `nullable()`: Allows the value to be `null`.
260
+ - `optional()`: Allows the value to be `undefined`.
261
+ - `default(value: unknown)`: Sets a default value if the received value is `undefined`.
262
+
263
+
264
+ > **Notice:** You cannot chain `default()` and `optional()` together, as they are contradictory. The `optional()` method allows the value to be `undefined`, while the `default()` method assigns a value if `undefined`. Attempting to chain both will throw a `BuildSchemaError` with the message: `"Cannot call method 'default' after method 'optional'"`.
265
+
266
+
267
+ > **Notice:** Additionally, `default()` must be the last method in the chain because it validates during schema build time that the default value is compatible with the rest of the schema. For example, if the schema is `number()`, the default value cannot be a `string`.
268
+
261
269
 
262
270
  Example:
263
271
 
264
272
  ```typeScript
273
+ const schemaWithDefault = string().nullable().default('defaultString');
274
+ // This schema allows null values and sets 'defaultString' if the value is undefined.
265
275
 
266
- const schema = string().nullable().optional();
276
+ const optionalSchema = string().nullable().optional();
277
+ // This schema allows both null and undefined values, but it does not provide a default value.
267
278
  ```
268
279
 
269
280
  - String Literals:
@@ -454,717 +465,888 @@ Each key and message will be visible in text editors that support JSDoc IntelliS
454
465
 
455
466
  ### Built-in Custom Assert Documentation {#builtin_custom_assert_documentation}
456
467
 
457
- #### bigint
468
+ * [string](#assertdir_string)
469
+ * [atLeastOneDigit](#assert_atLeastOneDigit_string)
470
+ * [atLeastOneLowerChar](#assert_atLeastOneLowerChar_string)
471
+ * [atLeastOneSpecialChar](#assert_atLeastOneSpecialChar_string)
472
+ * [atLeastOneUpperChar](#assert_atLeastOneUpperChar_string)
473
+ * [contains](#assert_contains_string)
474
+ * [email](#assert_email_string)
475
+ * [endsWith](#assert_endsWith_string)
476
+ * [isValidDate](#assert_isValidDate_string)
477
+ * [isValidDateTime](#assert_isValidDateTime_string)
478
+ * [isValidTime](#assert_isValidTime_string)
479
+ * [lowerCase](#assert_lowerCase_string)
480
+ * [maxLength](#assert_maxLength_string)
481
+ * [minLength](#assert_minLength_string)
482
+ * [regExp](#assert_regExp_string)
483
+ * [startsWith](#assert_startsWith_string)
484
+ * [upperCase](#assert_upperCase_string)
485
+ * [uuid](#assert_uuid_string)
486
+ * [uuidV1](#assert_uuidV1_string)
487
+ * [uuidV2](#assert_uuidV2_string)
488
+ * [uuidV3](#assert_uuidV3_string)
489
+ * [uuidV4](#assert_uuidV4_string)
490
+ * [uuidV5](#assert_uuidV5_string)
491
+ * [validUrl](#assert_validUrl_string)
492
+ * [number](#assertdir_number)
493
+ * [max](#assert_max_number)
494
+ * [maxExcluded](#assert_maxExcluded_number)
495
+ * [min](#assert_min_number)
496
+ * [minExcluded](#assert_minExcluded_number)
497
+ * [negative](#assert_negative_number)
498
+ * [positive](#assert_positive_number)
499
+ * [array](#assertdir_array)
500
+ * [maxArrayLength](#assert_maxArrayLength_array)
501
+ * [minArrayLength](#assert_minArrayLength_array)
502
+ * [bigint](#assertdir_bigint)
503
+ * [bigintMax](#assert_bigintMax_bigint)
504
+ * [bigintMaxExcluded](#assert_bigintMaxExcluded_bigint)
505
+ * [bigintMin](#assert_bigintMin_bigint)
506
+ * [bigintMinExcluded](#assert_bigintMinExcluded_bigint)
507
+ * [date](#assertdir_date)
508
+ * [dateMax](#assert_dateMax_date)
509
+ * [dateMin](#assert_dateMin_date)
510
+ * [mix](#assertdir_mix)
511
+ * [equalTo](#assert_equalTo_mix)
512
+ * [oneOfValues](#assert_oneOfValues_mix)
513
+
514
+ #### string {#assertdir_string}
458
515
 
459
516
  <b>Prerequisites</b>
460
517
 
461
518
  ```typescript
462
- import { bigint } from 'bguard/bigint';
519
+ import { string } from 'bguard/string';
463
520
  ```
464
521
 
465
- * _Description_ Creates a new schema for validating bigint values.
522
+ * _Description_ Creates a new schema for validating string values.
466
523
  * _Example_
467
524
  ```typescript
468
- const schema = bigint();
469
- parseOrFail(schema, 42n); // Validates successfully
470
- parseOrFail(schema, 42); // Throws a validation error
471
- parseOrFail(schema, '42'); // Throws a validation error
525
+ const schema = string();
526
+ parseOrFail(schema, 'hello'); // Validates successfully
527
+ parseOrFail(schema, 123); // Throws a validation error
472
528
  ```
473
529
 
474
530
 
475
- ##### bigintMax (bigint)
531
+ ##### atLeastOneDigit (string) {#assert_atLeastOneDigit_string}
476
532
 
477
533
  ```typescript
478
- import { bigintMax } from 'bguard/bigint/bigintMax';
534
+ import { atLeastOneDigit } from 'bguard/string/atLeastOneDigit';
479
535
  ```
480
536
 
481
- * _Description_ Asserts that a bigint value does not exceed a specified maximum value.
482
- * _Param_ {bigint} expected The maximum allowable value.
483
- * _Throws_ {ValidationError} if the received value exceeds the expected maximum value.
537
+ * _Description_ Asserts that a string value contains at least one digit.
538
+ * _Throws_ {ValidationError} if the received value does not contain at least one digit.
484
539
  * _Example_
485
540
  ```typescript
486
- const schema = bigint().custom(bigintMax(100n));
487
- parseOrFail(schema, 99n); // Valid
488
- parseOrFail(schema, 100n); // Valid
489
- parseOrFail(schema, 101n); // Throws an error: 'The received value is greater than expected'
541
+ const schema = string().custom(atLeastOneDigit());
542
+ parseOrFail(schema, 'abc123'); // Valid
543
+ parseOrFail(schema, 'abcdef'); // Throws an error: 'The received value does not contain at least one digit'
490
544
  ```
491
- * _See_ Error Translation Key = 'bi:max'
545
+ * _See_ Error Translation Key = 's:atLeastOneDigit'
492
546
 
493
547
 
494
- ##### bigintMaxExcluded (bigint)
548
+ ##### atLeastOneLowerChar (string) {#assert_atLeastOneLowerChar_string}
495
549
 
496
550
  ```typescript
497
- import { bigintMaxExcluded } from 'bguard/bigint/bigintMaxExcluded';
551
+ import { atLeastOneLowerChar } from 'bguard/string/atLeastOneLowerChar';
498
552
  ```
499
553
 
500
- * _Description_ - Asserts that a bigint value is strictly less than a specified maximum value (i.e., the maximum value is excluded).
501
- * _Param_ {bigint} expected - The maximum allowable value, which is excluded.
502
- * _Throws_ {ValidationError} if the received value is greater than or equal to the expected maximum value.
554
+ * _Description_ Asserts that a string value contains at least one lowercase character.
555
+ * _Throws_ {ValidationError} if the received value does not contain at least one lowercase character.
503
556
  * _Example_
504
557
  ```typescript
505
- const schema = bigint().custom(bigintMaxExcluded(100n));
506
- parseOrFail(schema, 99n); // Valid
507
- parseOrFail(schema, 100n); // Throws an error: 'The received value is greater than or equal to expected'
508
- parseOrFail(schema, 101n); // Throws an error: 'The received value is greater than or equal to expected'
558
+ const schema = string().custom(atLeastOneLowerChar());
559
+ parseOrFail(schema, 'abcDEF'); // Valid
560
+ parseOrFail(schema, 'ABCDEF'); // Throws an error: 'The received value does not contain at least one lowercase character'
509
561
  ```
510
- * _See_ Error Translation Key = 'bi:maxExcluded'
562
+ * _See_ Error Translation Key = 's:atLeastOneLowerChar'
511
563
 
512
564
 
513
- ##### bigintMin (bigint)
565
+ ##### atLeastOneSpecialChar (string) {#assert_atLeastOneSpecialChar_string}
514
566
 
515
567
  ```typescript
516
- import { bigintMin } from 'bguard/bigint/bigintMin';
568
+ import { atLeastOneSpecialChar } from 'bguard/string/atLeastOneSpecialChar';
517
569
  ```
518
570
 
519
- * _Description_ Asserts that a bigint value is not less than a specified minimum value.
520
- * _Param_ {bigint} expected The minimum allowable value.
521
- * _Throws_ {ValidationError} if the received value is less than the expected minimum value.
571
+ * _Description_ Asserts that a string value contains at least one special character.
572
+ * _Param_ {string} [allowedSpecialChars=* '@!#%&()^~{}'] The string containing allowed special characters. Defaults to '*@!#%&()^~{}'.
573
+ * _Throws_ {ValidationError} if the received value does not contain at least one of the allowed special characters.
522
574
  * _Example_
523
575
  ```typescript
524
- const schema = bigint().custom(bigintMin(10n));
525
- parseOrFail(schema, 11n); // Valid
526
- parseOrFail(schema, 10n); // Valid
527
- parseOrFail(schema, 9n); // Throws an error: 'The received value is less than expected'
576
+ const schema = string().custom(atLeastOneSpecialChar()); // Default special characters
577
+ parseOrFail(schema, 'abc!def'); // Valid
578
+ parseOrFail(schema, 'abcdef'); // Throws an error: 'The received value does not contain at least one special character'
579
+
580
+ const customSchema = string().custom(atLeastOneSpecialChar('@$')); // Custom special characters
581
+ parseOrFail(customSchema, 'abc@def'); // Valid
582
+ parseOrFail(customSchema, 'abcdef'); // Throws an error: 'The received value does not contain at least one special character'
528
583
  ```
529
- * _See_ Error Translation Key = 'bi:min'
584
+ * _See_ Error Translation Key = 's:atLeastOneSpecialChar'
530
585
 
531
586
 
532
- ##### bigintMinExcluded (bigint)
587
+ ##### atLeastOneUpperChar (string) {#assert_atLeastOneUpperChar_string}
533
588
 
534
589
  ```typescript
535
- import { bigintMinExcluded } from 'bguard/bigint/bigintMinExcluded';
590
+ import { atLeastOneUpperChar } from 'bguard/string/atLeastOneUpperChar';
536
591
  ```
537
592
 
538
- * _Description_ Asserts that a bigint value is strictly greater than a specified minimum value (i.e., the minimum value is excluded).
539
- * _Param_ {bigint} expected The minimum allowable value, which is excluded.
540
- * _Throws_ {ValidationError} if the received value is less than or equal to the expected minimum value.
593
+ * _Description_ Asserts that a string value contains at least one uppercase character.
594
+ * _Throws_ {ValidationError} if the received value does not contain at least one uppercase character.
541
595
  * _Example_
542
596
  ```typescript
543
- const schema = bigint().custom(bigintMinExcluded(10n));
544
- parseOrFail(schema, 11n); // Valid
545
- parseOrFail(schema, 10n); // Throws an error: 'The received value is less than or equal to expected'
546
- parseOrFail(schema, 9n); // Throws an error: 'The received value is less than or equal to expected'
597
+ const schema = string().custom(atLeastOneUpperChar());
598
+ parseOrFail(schema, 'abcDEF'); // Valid
599
+ parseOrFail(schema, 'abcdef'); // Throws an error: 'The received value does not contain at least one uppercase character'
547
600
  ```
548
- * _See_ Error Translation Key = 'bi:minExcluded'
601
+ * _See_ Error Translation Key = 's:atLeastOneUpperChar'
602
+
603
+
604
+ ##### contains (string) {#assert_contains_string}
549
605
 
550
- #### date
551
-
552
- <b>Prerequisites</b>
553
-
554
606
  ```typescript
555
- import { date } from 'bguard/date';
607
+ import { contains } from 'bguard/string/contains';
556
608
  ```
557
-
558
- * _Description_ Creates a new schema for validating date values.
609
+
610
+ * _Description_ Asserts that a string value contains a specified substring.
611
+ * _Param_ {string} substring The substring that must be present in the string value.
612
+ * _Throws_ {ValidationError} if the received value does not contain the required substring.
559
613
  * _Example_
560
614
  ```typescript
561
- const schema = date();
562
- parseOrFail(schema, true); // Validates successfully
563
- parseOrFail(schema, 'true'); // Throws a validation error
615
+ const schema = string().custom(contains('foo'));
616
+ parseOrFail(schema, 'foobar'); // Valid
617
+ parseOrFail(schema, 'bar'); // Throws an error: 'The received value does not contain the required substring'
564
618
  ```
565
-
619
+ * _See_ Error Translation Key = 's:contains'
566
620
 
567
- ##### dateMax (date)
621
+
622
+ ##### email (string) {#assert_email_string}
568
623
 
569
624
  ```typescript
570
- import { dateMax } from 'bguard/date/dateMax';
625
+ import { email } from 'bguard/string/email';
571
626
  ```
572
627
 
573
- * _Description_ Asserts that a date value is not greater than a specified maximum value.
574
- * _Param_ {Date | string} expected The maximum allowable value.
575
- * _Throws_ {ValidationError} if the received value is greater than the expected maximum value.
628
+ * _Description_ Asserts that a string value matches the email pattern. The pattern checks for a basic email format.
629
+ * _Throws_ {ValidationError} if the received value does not match the email pattern.
576
630
  * _Example_
577
631
  ```typescript
578
- const schema = date().custom(dateMax('2024-12-31'));
579
- parseOrFail(schema, new Date('2024-12-30')); // Valid
580
- parseOrFail(schema, new Date('2024-12-31')); // Valid
581
- parseOrFail(schema, new Date('2025-01-01')); // Throws an error: 'The received value is greater than expected'
632
+ const schema = string().custom(email());
633
+ parseOrFail(schema, 'example@example.com'); // Valid
634
+ parseOrFail(schema, 'invalid-email'); // Throws an error: 'The received value does not match the required email pattern'
582
635
  ```
583
- * _See_ Error Translation Key = 'dt:max'
636
+ * _See_ - Error Translation Key = 's:email'
584
637
 
585
638
 
586
- ##### dateMin (date)
639
+ ##### endsWith (string) {#assert_endsWith_string}
587
640
 
588
641
  ```typescript
589
- import { dateMin } from 'bguard/date/dateMin';
642
+ import { endsWith } from 'bguard/string/endsWith';
590
643
  ```
591
644
 
592
- * _Description_ Asserts that a number value is not less than a specified minimum value.
593
- * _Param_ {Date | string} expected The minimum allowable value.
594
- * _Throws_ {ValidationError} if the received value is less than the expected minimum value.
645
+ * _Description_ Asserts that a string value ends with a specified substring.
646
+ * _Param_ {string} substring The substring that the string value must end with.
647
+ * _Throws_ {ValidationError} if the received value does not end with the required substring.
595
648
  * _Example_
596
649
  ```typescript
597
- const schema = date().custom(dateMin('2023-01-01'));
598
- parseOrFail(schema, new Date('2023-01-02')); // Valid
599
- parseOrFail(schema, new Date('2023-01-01')); // Valid
600
- parseOrFail(schema, new Date('2022-12-31')); // Throws an error: 'The received value is less than expected'
650
+ const schema = string().custom(endsWith('bar'));
651
+ parseOrFail(schema, 'foobar'); // Valid
652
+ parseOrFail(schema, 'foofoo'); // Throws an error: 'The received value does not end with the required substring'
601
653
  ```
602
- * _See_ Error Translation Key = 'dt:min'
654
+ * _See_ Error Translation Key = 's:endsWith'
655
+
656
+
657
+ ##### isValidDate (string) {#assert_isValidDate_string}
603
658
 
604
- #### mix
605
-
606
- <b>Prerequisites</b>
607
-
608
659
  ```typescript
609
- import { oneOfTypes } from 'bguard/mix';
660
+ import { isValidDate } from 'bguard/string/isValidDate';
610
661
  ```
611
-
612
- * _Description_ Creates a new schema for validating values that can match any one of the specified primitive types.
613
-
614
-
615
- * _Param_ {T} valueTypes - An array of primitive types that the value can match.
662
+
663
+ * _Description_ Asserts that a string is a valid date in the format YYYY-MM-DD.
664
+ * _Throws_ {ValidationError} if the received string is not a valid date.
616
665
  * _Example_
617
666
  ```typescript
618
- const schema = oneOfTypes(['string', 'number']);
619
- parseOrFail(schema, 'hello'); // Validates successfully
620
- parseOrFail(schema, 42); // Validates successfully
621
- parseOrFail(schema, true); // Throws a validation error
667
+ const schema = string().custom(isValidDate());
668
+ parseOrFail(schema, "2020-01-01"); // Valid
669
+ parseOrFail(schema, "2020-1-1"); // Throws an error: 'The received value is not a valid date'
670
+ parseOrFail(schema, "2020-01-32"); // Throws an error: 'The received value is not a valid date'
622
671
  ```
623
-
672
+ * _See_ Error Translation Key = 's:isValidDate'
673
+
624
674
 
625
- ##### equalTo (mix)
675
+ ##### isValidDateTime (string) {#assert_isValidDateTime_string}
626
676
 
627
677
  ```typescript
628
- import { equalTo } from 'bguard/mix/equalTo';
678
+ import { isValidDateTime } from 'bguard/string/isValidDateTime';
629
679
  ```
630
680
 
631
- * _Description_ Creates a custom assertion that checks if a value is equal to the expected value.
632
- * > **Notice:** It has already been implemented in the number, bigint and string schema. There is no need to use it as a custom assert.
633
- * _Param_ {unknown} expected The value that the received value is expected to match.
634
- * _Throws_ {ValidationError} If the received value does not match the expected value.
681
+ * _Description_ Asserts that a string value is a valid ISO 8601 datetime string.
682
+ * _Param_ {DateTimeOptions} options Options to control the validation:
683
+ - `offset`: If `true`, allows timezone offsets in the datetime string.
684
+ - `precision`: Specify the exact number of fractional second digits allowed (e.g., 3 for milliseconds).
685
+ * _Throws_ {ValidationError} if the received value is not a valid datetime string according to the options.
635
686
  * _Example_
636
687
  ```typescript
637
- const schema = number().custom(equalTo(5)); // Define a schema with a custom assertion
638
- parseOrFail(schema, 5); // Valid
639
- parseOrFail(schema, 3); // Throws an error: 'The received value is not equal to expected'
688
+ const schema = string().custom(isValidDateTime());
689
+ parseOrFail(schema, "2024-01-01T00:00:00Z"); // Valid
690
+ parseOrFail(schema, "2024-01-01T00:00:00.123Z"); // Valid
691
+ parseOrFail(schema, "2024-01-01T00:00:00+03:00"); // Invalid (no offsets allowed)
692
+
693
+ const schemaWithOffset = string().custom(isValidDateTime({ offset: true }));
694
+ parseOrFail(schemaWithOffset, "2024-01-01T00:00:00+04:00"); // Valid
695
+
696
+ const schemaWithPrecision = string().custom(isValidDateTime({ precision: 3 }));
697
+ parseOrFail(schemaWithPrecision, "2024-01-01T00:00:00.123Z"); // Valid
698
+ parseOrFail(schemaWithPrecision, "2024-01-01T00:00:00.123456Z"); // Invalid
640
699
  ```
641
- * _See_ Error Translation Key = 'm:equalTo'
700
+ * _See_ Error Translation Key = 's:isValidDateTime'
642
701
 
643
702
 
644
- ##### oneOfValues (mix)
703
+ ##### isValidTime (string) {#assert_isValidTime_string}
645
704
 
646
705
  ```typescript
647
- import { oneOfValues } from 'bguard/mix/oneOfValues';
706
+ import { isValidTime } from 'bguard/string/isValidTime';
648
707
  ```
649
708
 
650
- * _Description_ Creates a custom assertion that checks if a value is equal to the one of expected values.
651
- * > **Notice:** It has already been implemented in the number, bigint and string schema. There is no need to use it as a custom assert.
652
- * _Param_ {unknown} expected The value that the received value is expected to match.
653
- * _Throws_ {ValidationError} If the received value does not match at least one of the expected values.
709
+ * _Description_ Asserts that a string is a valid time in the format HH:mm:ss, with optional fractional seconds.
710
+ * _Param_ {IsValidTimeOptions} options Optional settings to configure the validation.
711
+ * _Throws_ {ValidationError} if the received string is not a valid time.
654
712
  * _Example_
655
713
  ```typescript
656
- const schema = number().custom(oneOfValues([5, 4])); // Define a schema with a custom assertion
657
- parseOrFail(schema, 5); // Valid
658
- parseOrFail(schema, 4); // Valid
659
- parseOrFail(schema, 3); // Throws an error: 'The received value is not equal to expected'
714
+ const schema = string().custom(isValidTime());
715
+ parseOrFail(schema, "00:00:00"); // Valid
716
+ parseOrFail(schema, "23:59:59.9999999"); // Valid
717
+ parseOrFail(schema, "00:00:00.256Z"); // Throws an error: 'The received value is not a valid time'
718
+
719
+ const schemaWithPrecision = string().custom(isValidTime({ precision: 3 }));
720
+ parseOrFail(schemaWithPrecision, "00:00:00.256"); // Valid
721
+ parseOrFail(schemaWithPrecision, "00:00:00"); // Throws an error: 'The received value is not a valid time'
660
722
  ```
661
- * _See_ Error Translation Key = 'm:oneOfValues'
723
+ * _See_ Error Translation Key = 's:isValidTime'
724
+
725
+
726
+ ##### lowerCase (string) {#assert_lowerCase_string}
662
727
 
663
- #### number
664
-
665
- <b>Prerequisites</b>
666
-
667
728
  ```typescript
668
- import { number } from 'bguard/number';
729
+ import { lowerCase } from 'bguard/string/lowerCase';
669
730
  ```
670
-
671
- * _Description_ Creates a new schema for validating number values.
731
+
732
+ * _Description_ Asserts that a string value is in lowercase.
733
+ * _Throws_ {ValidationError} if the received value is not in lowercase.
672
734
  * _Example_
673
735
  ```typescript
674
- const schema = number();
675
- parseOrFail(schema, 42); // Validates successfully
676
- parseOrFail(schema, '42'); // Throws a validation error
736
+ const schema = string().custom(lowerCase());
737
+ parseOrFail(schema, 'valid'); // Valid
738
+ parseOrFail(schema, 'Invalid'); // Throws an error: 'The received value is not in lowercase'
677
739
  ```
678
-
740
+ * _See_ Error Translation Key = 's:lowerCase'
679
741
 
680
- ##### max (number)
742
+
743
+ ##### maxLength (string) {#assert_maxLength_string}
681
744
 
682
745
  ```typescript
683
- import { max } from 'bguard/number/max';
746
+ import { maxLength } from 'bguard/string/maxLength';
684
747
  ```
685
748
 
686
- * _Description_ Asserts that a number value does not exceed a specified maximum value.
687
- * _Param_ {number} expected The maximum allowable value.
688
- * _Throws_ {ValidationError} if the received value exceeds the expected maximum value.
749
+ * _Description_ Asserts that the length of a string value is not greater than a specified maximum length.
750
+ * _Param_ {number} expected The maximum allowed length for the string.
751
+ * _Throws_ {ValidationError} if the length of the received value is greater than the expected length.
689
752
  * _Example_
690
753
  ```typescript
691
- const schema = number().custom(max(100));
692
- parseOrFail(schema, 99); // Valid
693
- parseOrFail(schema, 100); // Valid
694
- parseOrFail(schema, 101); // Throws an error: 'The received value is greater than expected'
754
+ const schema = string().custom(maxLength(10));
755
+ parseOrFail(schema, 'short'); // Valid
756
+ parseOrFail(schema, 'this is a very long string'); // Throws an error: 'The received value length is greater than expected'
695
757
  ```
696
- * _See_ Error Translation Key = 'n:max'
758
+ * _See_ Error Translation Key = 's:maxLength'
697
759
 
698
760
 
699
- ##### maxExcluded (number)
761
+ ##### minLength (string) {#assert_minLength_string}
700
762
 
701
763
  ```typescript
702
- import { maxExcluded } from 'bguard/number/maxExcluded';
764
+ import { minLength } from 'bguard/string/minLength';
703
765
  ```
704
766
 
705
- * _Description_ - Asserts that a number value is strictly less than a specified maximum value (i.e., the maximum value is excluded).
706
- * _Param_ {number} expected - The maximum allowable value, which is excluded.
707
- * _Throws_ {ValidationError} if the received value is greater than or equal to the expected maximum value.
767
+ * _Description_ Asserts that the length of a string value is not less than a specified minimum length.
768
+ * _Param_ {number} expected The minimum required length for the string.
769
+ * _Throws_ {ValidationError} if the length of the received value is less than the expected length.
708
770
  * _Example_
709
771
  ```typescript
710
- const schema = number().custom(maxExcluded(100));
711
- parseOrFail(schema, 99); // Valid
712
- parseOrFail(schema, 100); // Throws an error: 'The received value is greater than or equal to expected'
713
- parseOrFail(schema, 101); // Throws an error: 'The received value is greater than or equal to expected'
772
+ const schema = string().custom(minLength(5));
773
+ parseOrFail(schema, 'short'); // Throws an error: 'The received value length is less than expected'
774
+ parseOrFail(schema, 'adequate'); // Valid
714
775
  ```
715
- * _See_ Error Translation Key = 'n:maxExcluded'
776
+ * _See_ Error Translation Key = 's:minLength'
716
777
 
717
778
 
718
- ##### min (number)
779
+ ##### regExp (string) {#assert_regExp_string}
719
780
 
720
781
  ```typescript
721
- import { min } from 'bguard/number/min';
782
+ import { regExp } from 'bguard/string/regExp';
722
783
  ```
723
784
 
724
- * _Description_ Asserts that a number value is not less than a specified minimum value.
725
- * _Param_ {number} expected The minimum allowable value.
726
- * _Throws_ {ValidationError} if the received value is less than the expected minimum value.
785
+ * _Description_ Asserts that a string value matches a specified regular expression pattern.
786
+ * _Param_ {RegExp} expected The regular expression pattern that the string value should match.
787
+ * _Throws_ {ValidationError} if the received value does not match the expected pattern.
727
788
  * _Example_
728
789
  ```typescript
729
- const schema = number().custom(min(10));
730
- parseOrFail(schema, 11); // Valid
731
- parseOrFail(schema, 10); // Valid
732
- parseOrFail(schema, 9); // Throws an error: 'The received value is less than expected'
790
+ const schema = string().custom(regExp(/^[A-Za-z0-9]+$/)); // Validates against alphanumeric pattern
791
+ parseOrFail(schema, 'valid123'); // Valid
792
+ parseOrFail(schema, 'invalid!@#'); // Throws an error: 'The received value does not match the required text pattern'
733
793
  ```
734
- * _See_ Error Translation Key = 'n:min'
794
+ * _See_ Error Translation Key = 's:regExp'
735
795
 
736
796
 
737
- ##### minExcluded (number)
797
+ ##### startsWith (string) {#assert_startsWith_string}
738
798
 
739
799
  ```typescript
740
- import { minExcluded } from 'bguard/number/minExcluded';
800
+ import { startsWith } from 'bguard/string/startsWith';
741
801
  ```
742
802
 
743
- * _Description_ Asserts that a number value is strictly greater than a specified minimum value (i.e., the minimum value is excluded).
744
- * _Param_ {number} expected The minimum allowable value, which is excluded.
745
- * _Throws_ {ValidationError} if the received value is less than or equal to the expected minimum value.
803
+ * _Description_ Asserts that a string value starts with a specified substring.
804
+ * _Param_ {string} substring The substring that the string value must start with.
805
+ * _Throws_ {ValidationError} if the received value does not start with the required substring.
746
806
  * _Example_
747
807
  ```typescript
748
- const schema = number().custom(minExcluded(10));
749
- parseOrFail(schema, 11); // Valid
750
- parseOrFail(schema, 10); // Throws an error: 'The received value is less than or equal to expected'
751
- parseOrFail(schema, 9); // Throws an error: 'The received value is less than or equal to expected'
808
+ const schema = string().custom(startsWith('foo'));
809
+ parseOrFail(schema, 'foobar'); // Valid
810
+ parseOrFail(schema, 'barfoo'); // Throws an error: 'The received value does not start with the required substring'
752
811
  ```
753
- * _See_ Error Translation Key = 'n:minExcluded'
812
+ * _See_ Error Translation Key = 's:startsWith'
754
813
 
755
814
 
756
- ##### negative (number)
815
+ ##### upperCase (string) {#assert_upperCase_string}
757
816
 
758
817
  ```typescript
759
- import { negative } from 'bguard/number/negative';
818
+ import { upperCase } from 'bguard/string/upperCase';
760
819
  ```
761
820
 
762
- * _Description_ Asserts that a number value is negative (less than zero).
763
- * _Throws_ {ValidationError} if the received value is not negative.
821
+ * _Description_ Asserts that a string value is entirely in uppercase.
822
+ * _Throws_ {ValidationError} if the received value is not in uppercase.
764
823
  * _Example_
765
824
  ```typescript
766
- const schema = number().custom(negative());
767
- parseOrFail(schema, -10); // Valid
768
- parseOrFail(schema, 0); // Throws an error: 'The received value is not a negative number'
769
- parseOrFail(schema, 5); // Throws an error: 'The received value is not a negative number'
825
+ const schema = string().custom(upperCase());
826
+ parseOrFail(schema, 'VALID'); // Valid
827
+ parseOrFail(schema, 'INVALID'); // Throws an error: 'The received value is not in uppercase'
828
+ parseOrFail(schema, 'Valid'); // Throws an error: 'The received value is not in uppercase'
770
829
  ```
771
- * _See_ - Error Translation Key = 'n:negative'
830
+ * _See_ Error Translation Key = 's:upperCase'
772
831
 
773
832
 
774
- ##### positive (number)
833
+ ##### uuid (string) {#assert_uuid_string}
775
834
 
776
835
  ```typescript
777
- import { positive } from 'bguard/number/positive';
836
+ import { uuid } from 'bguard/string/uuid';
778
837
  ```
779
838
 
780
- * _Description_ Asserts that a number value is positive (greater than zero).
781
- * _Throws_ {ValidationError} if the received value is not positive.
839
+ * _Description_ Asserts that a string value matches the UUID format.
840
+ * _Throws_ {ValidationError} if the received value is not a valid UUID.
782
841
  * _Example_
783
842
  ```typescript
784
- const schema = number().custom(positive());
785
- parseOrFail(schema, 10); // Valid
786
- parseOrFail(schema, 0); // Throws an error: 'The received value is not a positive number'
787
- parseOrFail(schema, -5); // Throws an error: 'The received value is not a positive number'
843
+ const schema = string().custom(uuid());
844
+ parseOrFail(schema, '123e4567-e89b-12d3-a456-426614174000'); // Valid
845
+ parseOrFail(schema, 'invalid-uuid'); // Throws an error: 'The received value is not a valid UUID'
788
846
  ```
789
- * _See_ Error Translation Key = 'n:positive'
847
+ * _See_ Error Translation Key = 's:uuid'
848
+
849
+
850
+ ##### uuidV1 (string) {#assert_uuidV1_string}
790
851
 
791
- #### string
792
-
793
- <b>Prerequisites</b>
794
-
795
852
  ```typescript
796
- import { string } from 'bguard/string';
853
+ import { uuidV1 } from 'bguard/string/uuidV1';
797
854
  ```
798
-
799
- * _Description_ Creates a new schema for validating string values.
855
+
856
+ * _Description_ Asserts that a string value matches the UUID v1 format.
857
+ * _Throws_ {ValidationError} if the received value is not a valid UUID v1.
800
858
  * _Example_
801
859
  ```typescript
802
- const schema = string();
803
- parseOrFail(schema, 'hello'); // Validates successfully
804
- parseOrFail(schema, 123); // Throws a validation error
860
+ const schema = string().custom(uuidV1());
861
+ parseOrFail(schema, '550e8400-e29b-11d4-a716-446655440000'); // Valid
862
+ parseOrFail(schema, '550e8400-e29b-21d4-a716-446655440000'); // Throws an error: 'The received value is not a valid UUID v1'
863
+ parseOrFail(schema, 'invalid-uuid'); // Throws an error: 'The received value is not a valid UUID v1'
805
864
  ```
806
-
865
+ * _See_ Error Translation Key = 's:uuidV1'
807
866
 
808
- ##### atLeastOneDigit (string)
867
+
868
+ ##### uuidV2 (string) {#assert_uuidV2_string}
809
869
 
810
870
  ```typescript
811
- import { atLeastOneDigit } from 'bguard/string/atLeastOneDigit';
871
+ import { uuidV2 } from 'bguard/string/uuidV2';
812
872
  ```
813
873
 
814
- * _Description_ Asserts that a string value contains at least one digit.
815
- * _Throws_ {ValidationError} if the received value does not contain at least one digit.
874
+ * _Description_ Asserts that a string value matches the UUID v2 format.
875
+ * _Throws_ {ValidationError} if the received value is not a valid UUID v2.
816
876
  * _Example_
817
877
  ```typescript
818
- const schema = string().custom(atLeastOneDigit());
819
- parseOrFail(schema, 'abc123'); // Valid
820
- parseOrFail(schema, 'abcdef'); // Throws an error: 'The received value does not contain at least one digit'
878
+ const schema = string().custom(uuidV2());
879
+ parseOrFail(schema, '550e8400-e29b-21d4-a716-446655440000'); // Valid
880
+ parseOrFail(schema, '550e8400-e29b-31d4-d716-446655440000'); // Throws an error: 'The received value is not a valid UUID v2'
881
+ parseOrFail(schema, 'invalid-uuid'); // Throws an error: 'The received value is not a valid UUID v2'
821
882
  ```
822
- * _See_ Error Translation Key = 's:atLeastOneDigit'
883
+ * _See_ Error Translation Key = 's:uuidV2'
823
884
 
824
885
 
825
- ##### atLeastOneLowerChar (string)
886
+ ##### uuidV3 (string) {#assert_uuidV3_string}
826
887
 
827
888
  ```typescript
828
- import { atLeastOneLowerChar } from 'bguard/string/atLeastOneLowerChar';
889
+ import { uuidV3 } from 'bguard/string/uuidV3';
829
890
  ```
830
891
 
831
- * _Description_ Asserts that a string value contains at least one lowercase character.
832
- * _Throws_ {ValidationError} if the received value does not contain at least one lowercase character.
892
+ * _Description_ Asserts that a string value matches the UUID v3 format.
893
+ * _Throws_ {ValidationError} if the received value is not a valid UUID v3.
833
894
  * _Example_
834
895
  ```typescript
835
- const schema = string().custom(atLeastOneLowerChar());
836
- parseOrFail(schema, 'abcDEF'); // Valid
837
- parseOrFail(schema, 'ABCDEF'); // Throws an error: 'The received value does not contain at least one lowercase character'
896
+ const schema = string().custom(uuidV3());
897
+ parseOrFail(schema, '550e8400-e29b-38d1-a456-426614174000'); // Valid
898
+ parseOrFail(schema, '550e8400-e29b-28d1-a456-426614174000'); // Throws an error: 'The received value is not a valid UUID v3'
899
+ parseOrFail(schema, 'invalid-uuid'); // Throws an error: 'The received value is not a valid UUID v3'
838
900
  ```
839
- * _See_ Error Translation Key = 's:atLeastOneLowerChar'
901
+ * _See_ Error Translation Key = 's:uuidV3'
840
902
 
841
903
 
842
- ##### atLeastOneSpecialChar (string)
904
+ ##### uuidV4 (string) {#assert_uuidV4_string}
843
905
 
844
906
  ```typescript
845
- import { atLeastOneSpecialChar } from 'bguard/string/atLeastOneSpecialChar';
907
+ import { uuidV4 } from 'bguard/string/uuidV4';
846
908
  ```
847
909
 
848
- * _Description_ Asserts that a string value contains at least one special character.
849
- * _Param_ {string} [allowedSpecialChars=* '@!#%&()^~{}'] The string containing allowed special characters. Defaults to '*@!#%&()^~{}'.
850
- * _Throws_ {ValidationError} if the received value does not contain at least one of the allowed special characters.
910
+ * _Description_ Asserts that a string value matches the UUID v4 format.
911
+ * _Throws_ {ValidationError} if the received value is not a valid UUID v4.
851
912
  * _Example_
852
913
  ```typescript
853
- const schema = string().custom(atLeastOneSpecialChar()); // Default special characters
854
- parseOrFail(schema, 'abc!def'); // Valid
855
- parseOrFail(schema, 'abcdef'); // Throws an error: 'The received value does not contain at least one special character'
856
-
857
- const customSchema = string().custom(atLeastOneSpecialChar('@$')); // Custom special characters
858
- parseOrFail(customSchema, 'abc@def'); // Valid
859
- parseOrFail(customSchema, 'abcdef'); // Throws an error: 'The received value does not contain at least one special character'
914
+ const schema = string().custom(uuidV4());
915
+ parseOrFail(schema, '123e4567-e89b-42d3-a456-426614174000'); // Valid
916
+ parseOrFail(schema, '123e4567-e89b-12d3-a456-426614174000'); // Throws an error: 'The received value is not a valid UUID v4'
917
+ parseOrFail(schema, '123e4567-e89b-a2d3-a456-426614174000'); // Throws an error: 'The received value is not a valid UUID v4'
918
+ parseOrFail(schema, '123e4567-e89b-42d3-c456-426614174000'); // Throws an error: 'The received value is not a valid UUID v4'
919
+ parseOrFail(schema, 'invalid-uuid'); // Throws an error: 'The received value is not a valid UUID v4'
860
920
  ```
861
- * _See_ Error Translation Key = 's:atLeastOneSpecialChar'
921
+ * _See_ Error Translation Key = 's:uuidV4'
862
922
 
863
923
 
864
- ##### atLeastOneUpperChar (string)
924
+ ##### uuidV5 (string) {#assert_uuidV5_string}
865
925
 
866
926
  ```typescript
867
- import { atLeastOneUpperChar } from 'bguard/string/atLeastOneUpperChar';
927
+ import { uuidV5 } from 'bguard/string/uuidV5';
868
928
  ```
869
929
 
870
- * _Description_ Asserts that a string value contains at least one uppercase character.
871
- * _Throws_ {ValidationError} if the received value does not contain at least one uppercase character.
930
+ * _Description_ Asserts that a string value matches the UUID v5 format.
931
+ * _Throws_ {ValidationError} if the received value is not a valid UUID v5.
872
932
  * _Example_
873
933
  ```typescript
874
- const schema = string().custom(atLeastOneUpperChar());
875
- parseOrFail(schema, 'abcDEF'); // Valid
876
- parseOrFail(schema, 'abcdef'); // Throws an error: 'The received value does not contain at least one uppercase character'
934
+ const schema = string().custom(uuidV5());
935
+ parseOrFail(schema, '550e8400-e29b-51d4-a716-446655440000'); // Valid
936
+ parseOrFail(schema, '550e8400-e29b-41d4-a716-446655440000'); // Throws an error: 'The received value is not a valid UUID v5'
937
+ parseOrFail(schema, 'invalid-uuid'); // Throws an error: 'The received value is not a valid UUID v5'
877
938
  ```
878
- * _See_ Error Translation Key = 's:atLeastOneUpperChar'
939
+ * _See_ Error Translation Key = 's:uuidV5'
879
940
 
880
941
 
881
- ##### contains (string)
942
+ ##### validUrl (string) {#assert_validUrl_string}
882
943
 
883
944
  ```typescript
884
- import { contains } from 'bguard/string/contains';
945
+ import { validUrl } from 'bguard/string/validUrl';
885
946
  ```
886
947
 
887
- * _Description_ Asserts that a string value contains a specified substring.
888
- * _Param_ {string} substring The substring that must be present in the string value.
889
- * _Throws_ {ValidationError} if the received value does not contain the required substring.
948
+ * _Description_ Asserts that the string value is a valid URL with optional protocol validation.
949
+ * _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.
950
+ * _Throws_ {ValidationError} if the received value does not match the expected URL pattern.
890
951
  * _Example_
891
952
  ```typescript
892
- const schema = string().custom(contains('foo'));
893
- parseOrFail(schema, 'foobar'); // Valid
894
- parseOrFail(schema, 'bar'); // Throws an error: 'The received value does not contain the required substring'
953
+ const schema = string().custom(validUrl()); // Validates any URL starting with 'http://' or 'https://'
954
+ parseOrFail(schema, 'http://example.com'); // Valid
955
+ parseOrFail(schema, 'https://example.com'); // Valid
956
+ parseOrFail(schema, 'ftp://example.com'); // Throws an error
957
+ parseOrFail(schema, 'http:example.com'); // Throws an error
895
958
  ```
896
- * _See_ Error Translation Key = 's:contains'
959
+ * _See_ Error Translation Key = 's:url'
897
960
 
961
+ #### number {#assertdir_number}
962
+
963
+ <b>Prerequisites</b>
964
+
965
+ ```typescript
966
+ import { number } from 'bguard/number';
967
+ ```
968
+
969
+ * _Description_ Creates a new schema for validating number values.
970
+ * _Example_
971
+ ```typescript
972
+ const schema = number();
973
+ parseOrFail(schema, 42); // Validates successfully
974
+ parseOrFail(schema, '42'); // Throws a validation error
975
+ ```
976
+
898
977
 
899
- ##### email (string)
978
+ ##### max (number) {#assert_max_number}
900
979
 
901
980
  ```typescript
902
- import { email } from 'bguard/string/email';
981
+ import { max } from 'bguard/number/max';
903
982
  ```
904
983
 
905
- * _Description_ Asserts that a string value matches the email pattern. The pattern checks for a basic email format.
906
- * _Throws_ {ValidationError} if the received value does not match the email pattern.
984
+ * _Description_ Asserts that a number value does not exceed a specified maximum value.
985
+ * _Param_ {number} expected The maximum allowable value.
986
+ * _Throws_ {ValidationError} if the received value exceeds the expected maximum value.
907
987
  * _Example_
908
988
  ```typescript
909
- const schema = string().custom(email());
910
- parseOrFail(schema, 'example@example.com'); // Valid
911
- parseOrFail(schema, 'invalid-email'); // Throws an error: 'The received value does not match the required email pattern'
989
+ const schema = number().custom(max(100));
990
+ parseOrFail(schema, 99); // Valid
991
+ parseOrFail(schema, 100); // Valid
992
+ parseOrFail(schema, 101); // Throws an error: 'The received value is greater than expected'
912
993
  ```
913
- * _See_ - Error Translation Key = 's:email'
994
+ * _See_ Error Translation Key = 'n:max'
914
995
 
915
996
 
916
- ##### endsWith (string)
997
+ ##### maxExcluded (number) {#assert_maxExcluded_number}
917
998
 
918
999
  ```typescript
919
- import { endsWith } from 'bguard/string/endsWith';
1000
+ import { maxExcluded } from 'bguard/number/maxExcluded';
920
1001
  ```
921
1002
 
922
- * _Description_ Asserts that a string value ends with a specified substring.
923
- * _Param_ {string} substring The substring that the string value must end with.
924
- * _Throws_ {ValidationError} if the received value does not end with the required substring.
1003
+ * _Description_ - Asserts that a number value is strictly less than a specified maximum value (i.e., the maximum value is excluded).
1004
+ * _Param_ {number} expected - The maximum allowable value, which is excluded.
1005
+ * _Throws_ {ValidationError} if the received value is greater than or equal to the expected maximum value.
925
1006
  * _Example_
926
1007
  ```typescript
927
- const schema = string().custom(endsWith('bar'));
928
- parseOrFail(schema, 'foobar'); // Valid
929
- parseOrFail(schema, 'foofoo'); // Throws an error: 'The received value does not end with the required substring'
1008
+ const schema = number().custom(maxExcluded(100));
1009
+ parseOrFail(schema, 99); // Valid
1010
+ parseOrFail(schema, 100); // Throws an error: 'The received value is greater than or equal to expected'
1011
+ parseOrFail(schema, 101); // Throws an error: 'The received value is greater than or equal to expected'
930
1012
  ```
931
- * _See_ Error Translation Key = 's:endsWith'
1013
+ * _See_ Error Translation Key = 'n:maxExcluded'
932
1014
 
933
1015
 
934
- ##### lowerCase (string)
1016
+ ##### min (number) {#assert_min_number}
935
1017
 
936
1018
  ```typescript
937
- import { lowerCase } from 'bguard/string/lowerCase';
1019
+ import { min } from 'bguard/number/min';
938
1020
  ```
939
1021
 
940
- * _Description_ Asserts that a string value is in lowercase.
941
- * _Throws_ {ValidationError} if the received value is not in lowercase.
1022
+ * _Description_ Asserts that a number value is not less than a specified minimum value.
1023
+ * _Param_ {number} expected The minimum allowable value.
1024
+ * _Throws_ {ValidationError} if the received value is less than the expected minimum value.
942
1025
  * _Example_
943
1026
  ```typescript
944
- const schema = string().custom(lowerCase());
945
- parseOrFail(schema, 'valid'); // Valid
946
- parseOrFail(schema, 'Invalid'); // Throws an error: 'The received value is not in lowercase'
1027
+ const schema = number().custom(min(10));
1028
+ parseOrFail(schema, 11); // Valid
1029
+ parseOrFail(schema, 10); // Valid
1030
+ parseOrFail(schema, 9); // Throws an error: 'The received value is less than expected'
947
1031
  ```
948
- * _See_ Error Translation Key = 's:lowerCase'
1032
+ * _See_ Error Translation Key = 'n:min'
949
1033
 
950
1034
 
951
- ##### maxLength (string)
1035
+ ##### minExcluded (number) {#assert_minExcluded_number}
952
1036
 
953
1037
  ```typescript
954
- import { maxLength } from 'bguard/string/maxLength';
1038
+ import { minExcluded } from 'bguard/number/minExcluded';
955
1039
  ```
956
1040
 
957
- * _Description_ Asserts that the length of a string value is not greater than a specified maximum length.
958
- * _Param_ {number} expected The maximum allowed length for the string.
959
- * _Throws_ {ValidationError} if the length of the received value is greater than the expected length.
1041
+ * _Description_ Asserts that a number value is strictly greater than a specified minimum value (i.e., the minimum value is excluded).
1042
+ * _Param_ {number} expected The minimum allowable value, which is excluded.
1043
+ * _Throws_ {ValidationError} if the received value is less than or equal to the expected minimum value.
960
1044
  * _Example_
961
1045
  ```typescript
962
- const schema = string().custom(maxLength(10));
963
- parseOrFail(schema, 'short'); // Valid
964
- parseOrFail(schema, 'this is a very long string'); // Throws an error: 'The received value length is greater than expected'
1046
+ const schema = number().custom(minExcluded(10));
1047
+ parseOrFail(schema, 11); // Valid
1048
+ parseOrFail(schema, 10); // Throws an error: 'The received value is less than or equal to expected'
1049
+ parseOrFail(schema, 9); // Throws an error: 'The received value is less than or equal to expected'
965
1050
  ```
966
- * _See_ Error Translation Key = 's:maxLength'
1051
+ * _See_ Error Translation Key = 'n:minExcluded'
967
1052
 
968
1053
 
969
- ##### minLength (string)
1054
+ ##### negative (number) {#assert_negative_number}
970
1055
 
971
1056
  ```typescript
972
- import { minLength } from 'bguard/string/minLength';
1057
+ import { negative } from 'bguard/number/negative';
973
1058
  ```
974
1059
 
975
- * _Description_ Asserts that the length of a string value is not less than a specified minimum length.
976
- * _Param_ {number} expected The minimum required length for the string.
977
- * _Throws_ {ValidationError} if the length of the received value is less than the expected length.
1060
+ * _Description_ Asserts that a number value is negative (less than zero).
1061
+ * _Throws_ {ValidationError} if the received value is not negative.
978
1062
  * _Example_
979
1063
  ```typescript
980
- const schema = string().custom(minLength(5));
981
- parseOrFail(schema, 'short'); // Throws an error: 'The received value length is less than expected'
982
- parseOrFail(schema, 'adequate'); // Valid
1064
+ const schema = number().custom(negative());
1065
+ parseOrFail(schema, -10); // Valid
1066
+ parseOrFail(schema, 0); // Throws an error: 'The received value is not a negative number'
1067
+ parseOrFail(schema, 5); // Throws an error: 'The received value is not a negative number'
983
1068
  ```
984
- * _See_ Error Translation Key = 's:minLength'
1069
+ * _See_ - Error Translation Key = 'n:negative'
985
1070
 
986
1071
 
987
- ##### regExp (string)
1072
+ ##### positive (number) {#assert_positive_number}
988
1073
 
989
1074
  ```typescript
990
- import { regExp } from 'bguard/string/regExp';
1075
+ import { positive } from 'bguard/number/positive';
991
1076
  ```
992
1077
 
993
- * _Description_ Asserts that a string value matches a specified regular expression pattern.
994
- * _Param_ {RegExp} expected The regular expression pattern that the string value should match.
995
- * _Throws_ {ValidationError} if the received value does not match the expected pattern.
1078
+ * _Description_ Asserts that a number value is positive (greater than zero).
1079
+ * _Throws_ {ValidationError} if the received value is not positive.
996
1080
  * _Example_
997
1081
  ```typescript
998
- const schema = string().custom(regExp(/^[A-Za-z0-9]+$/)); // Validates against alphanumeric pattern
999
- parseOrFail(schema, 'valid123'); // Valid
1000
- parseOrFail(schema, 'invalid!@#'); // Throws an error: 'The received value does not match the required text pattern'
1082
+ const schema = number().custom(positive());
1083
+ parseOrFail(schema, 10); // Valid
1084
+ parseOrFail(schema, 0); // Throws an error: 'The received value is not a positive number'
1085
+ parseOrFail(schema, -5); // Throws an error: 'The received value is not a positive number'
1001
1086
  ```
1002
- * _See_ Error Translation Key = 's:regExp'
1087
+ * _See_ Error Translation Key = 'n:positive'
1003
1088
 
1089
+ #### array {#assertdir_array}
1090
+
1091
+ <b>Prerequisites</b>
1092
+
1093
+ ```typescript
1094
+ import { array } from 'bguard/array';
1095
+ ```
1096
+
1097
+ * _Description_ Creates a new schema for validating arrays where each element must match the specified schema.
1098
+
1099
+ * _Param_ {T} arraySchema - The schema that each element of the array must match.
1100
+ * _Example_
1101
+ ```typescript
1102
+ const schema = array(string());
1103
+ parseOrFail(schema, ['hello', 'world']); // Validates successfully
1104
+ parseOrFail(schema, ['hello', 123]); // Throws a validation error
1105
+ ```
1106
+
1004
1107
 
1005
- ##### startsWith (string)
1108
+ ##### maxArrayLength (array) {#assert_maxArrayLength_array}
1006
1109
 
1007
1110
  ```typescript
1008
- import { startsWith } from 'bguard/string/startsWith';
1111
+ import { maxArrayLength } from 'bguard/array/maxArrayLength';
1009
1112
  ```
1010
1113
 
1011
- * _Description_ Asserts that a string value starts with a specified substring.
1012
- * _Param_ {string} substring The substring that the string value must start with.
1013
- * _Throws_ {ValidationError} if the received value does not start with the required substring.
1114
+ * _Description_ Asserts that the length of an array is not greater than a specified maximum length.
1115
+ * _Param_ {number} expected The maximum allowed length for the array.
1116
+ * _Throws_ {ValidationError} if the length of the received value is greater than the expected length.
1014
1117
  * _Example_
1015
1118
  ```typescript
1016
- const schema = string().custom(startsWith('foo'));
1017
- parseOrFail(schema, 'foobar'); // Valid
1018
- parseOrFail(schema, 'barfoo'); // Throws an error: 'The received value does not start with the required substring'
1119
+ const schema = array(string()).custom(maxArrayLength(3));
1120
+ parseOrFail(schema, ['adequate', 'array']); // Valid
1121
+ parseOrFail(schema, ['adequate', 'array', 'length']); // Valid
1122
+ parseOrFail(schema, ['adequate', 'array', 'length', 'test']); // Throws an error: 'The received value length is greater than expected'
1019
1123
  ```
1020
- * _See_ Error Translation Key = 's:startsWith'
1124
+ * _See_ Error Translation Key = 'a:maxArrayLength'
1021
1125
 
1022
1126
 
1023
- ##### upperCase (string)
1127
+ ##### minArrayLength (array) {#assert_minArrayLength_array}
1024
1128
 
1025
1129
  ```typescript
1026
- import { upperCase } from 'bguard/string/upperCase';
1130
+ import { minArrayLength } from 'bguard/array/minArrayLength';
1027
1131
  ```
1028
1132
 
1029
- * _Description_ Asserts that a string value is entirely in uppercase.
1030
- * _Throws_ {ValidationError} if the received value is not in uppercase.
1133
+ * _Description_ Asserts that the length of na array is not less than a specified minimum length.
1134
+ * _Param_ {number} expected The minimum required length for the array.
1135
+ * _Throws_ {ValidationError} if the length of the received value is less than the expected length.
1031
1136
  * _Example_
1032
1137
  ```typescript
1033
- const schema = string().custom(upperCase());
1034
- parseOrFail(schema, 'VALID'); // Valid
1035
- parseOrFail(schema, 'INVALID'); // Throws an error: 'The received value is not in uppercase'
1036
- parseOrFail(schema, 'Valid'); // Throws an error: 'The received value is not in uppercase'
1138
+ const schema = array(string()).custom(minArrayLength(3));
1139
+ parseOrFail(schema, ['short', 'array']); // Throws an error: 'The received value length is less than expected'
1140
+ parseOrFail(schema, ['adequate', 'array', 'length']); // Valid
1141
+ parseOrFail(schema, ['adequate', 'array', 'length', 'test']); // Valid
1037
1142
  ```
1038
- * _See_ Error Translation Key = 's:upperCase'
1143
+ * _See_ Error Translation Key = 'a:minArrayLength'
1039
1144
 
1145
+ #### bigint {#assertdir_bigint}
1146
+
1147
+ <b>Prerequisites</b>
1148
+
1149
+ ```typescript
1150
+ import { bigint } from 'bguard/bigint';
1151
+ ```
1152
+
1153
+ * _Description_ Creates a new schema for validating bigint values.
1154
+ * _Example_
1155
+ ```typescript
1156
+ const schema = bigint();
1157
+ parseOrFail(schema, 42n); // Validates successfully
1158
+ parseOrFail(schema, 42); // Throws a validation error
1159
+ parseOrFail(schema, '42'); // Throws a validation error
1160
+ ```
1161
+
1040
1162
 
1041
- ##### uuid (string)
1163
+ ##### bigintMax (bigint) {#assert_bigintMax_bigint}
1042
1164
 
1043
1165
  ```typescript
1044
- import { uuid } from 'bguard/string/uuid';
1166
+ import { bigintMax } from 'bguard/bigint/bigintMax';
1045
1167
  ```
1046
1168
 
1047
- * _Description_ Asserts that a string value matches the UUID format.
1048
- * _Throws_ {ValidationError} if the received value is not a valid UUID.
1169
+ * _Description_ Asserts that a bigint value does not exceed a specified maximum value.
1170
+ * _Param_ {bigint} expected The maximum allowable value.
1171
+ * _Throws_ {ValidationError} if the received value exceeds the expected maximum value.
1049
1172
  * _Example_
1050
1173
  ```typescript
1051
- const schema = string().custom(uuid());
1052
- parseOrFail(schema, '123e4567-e89b-12d3-a456-426614174000'); // Valid
1053
- parseOrFail(schema, 'invalid-uuid'); // Throws an error: 'The received value is not a valid UUID'
1174
+ const schema = bigint().custom(bigintMax(100n));
1175
+ parseOrFail(schema, 99n); // Valid
1176
+ parseOrFail(schema, 100n); // Valid
1177
+ parseOrFail(schema, 101n); // Throws an error: 'The received value is greater than expected'
1054
1178
  ```
1055
- * _See_ Error Translation Key = 's:uuid'
1179
+ * _See_ Error Translation Key = 'bi:max'
1056
1180
 
1057
1181
 
1058
- ##### uuidV1 (string)
1182
+ ##### bigintMaxExcluded (bigint) {#assert_bigintMaxExcluded_bigint}
1059
1183
 
1060
1184
  ```typescript
1061
- import { uuidV1 } from 'bguard/string/uuidV1';
1185
+ import { bigintMaxExcluded } from 'bguard/bigint/bigintMaxExcluded';
1062
1186
  ```
1063
1187
 
1064
- * _Description_ Asserts that a string value matches the UUID v1 format.
1065
- * _Throws_ {ValidationError} if the received value is not a valid UUID v1.
1188
+ * _Description_ - Asserts that a bigint value is strictly less than a specified maximum value (i.e., the maximum value is excluded).
1189
+ * _Param_ {bigint} expected - The maximum allowable value, which is excluded.
1190
+ * _Throws_ {ValidationError} if the received value is greater than or equal to the expected maximum value.
1066
1191
  * _Example_
1067
1192
  ```typescript
1068
- const schema = string().custom(uuidV1());
1069
- parseOrFail(schema, '550e8400-e29b-11d4-a716-446655440000'); // Valid
1070
- parseOrFail(schema, '550e8400-e29b-21d4-a716-446655440000'); // Throws an error: 'The received value is not a valid UUID v1'
1071
- parseOrFail(schema, 'invalid-uuid'); // Throws an error: 'The received value is not a valid UUID v1'
1193
+ const schema = bigint().custom(bigintMaxExcluded(100n));
1194
+ parseOrFail(schema, 99n); // Valid
1195
+ parseOrFail(schema, 100n); // Throws an error: 'The received value is greater than or equal to expected'
1196
+ parseOrFail(schema, 101n); // Throws an error: 'The received value is greater than or equal to expected'
1072
1197
  ```
1073
- * _See_ Error Translation Key = 's:uuidV1'
1198
+ * _See_ Error Translation Key = 'bi:maxExcluded'
1074
1199
 
1075
1200
 
1076
- ##### uuidV2 (string)
1201
+ ##### bigintMin (bigint) {#assert_bigintMin_bigint}
1077
1202
 
1078
1203
  ```typescript
1079
- import { uuidV2 } from 'bguard/string/uuidV2';
1204
+ import { bigintMin } from 'bguard/bigint/bigintMin';
1080
1205
  ```
1081
1206
 
1082
- * _Description_ Asserts that a string value matches the UUID v2 format.
1083
- * _Throws_ {ValidationError} if the received value is not a valid UUID v2.
1207
+ * _Description_ Asserts that a bigint value is not less than a specified minimum value.
1208
+ * _Param_ {bigint} expected The minimum allowable value.
1209
+ * _Throws_ {ValidationError} if the received value is less than the expected minimum value.
1084
1210
  * _Example_
1085
1211
  ```typescript
1086
- const schema = string().custom(uuidV2());
1087
- parseOrFail(schema, '550e8400-e29b-21d4-a716-446655440000'); // Valid
1088
- parseOrFail(schema, '550e8400-e29b-31d4-d716-446655440000'); // Throws an error: 'The received value is not a valid UUID v2'
1089
- parseOrFail(schema, 'invalid-uuid'); // Throws an error: 'The received value is not a valid UUID v2'
1212
+ const schema = bigint().custom(bigintMin(10n));
1213
+ parseOrFail(schema, 11n); // Valid
1214
+ parseOrFail(schema, 10n); // Valid
1215
+ parseOrFail(schema, 9n); // Throws an error: 'The received value is less than expected'
1090
1216
  ```
1091
- * _See_ Error Translation Key = 's:uuidV2'
1217
+ * _See_ Error Translation Key = 'bi:min'
1092
1218
 
1093
1219
 
1094
- ##### uuidV3 (string)
1220
+ ##### bigintMinExcluded (bigint) {#assert_bigintMinExcluded_bigint}
1095
1221
 
1096
1222
  ```typescript
1097
- import { uuidV3 } from 'bguard/string/uuidV3';
1223
+ import { bigintMinExcluded } from 'bguard/bigint/bigintMinExcluded';
1098
1224
  ```
1099
1225
 
1100
- * _Description_ Asserts that a string value matches the UUID v3 format.
1101
- * _Throws_ {ValidationError} if the received value is not a valid UUID v3.
1226
+ * _Description_ Asserts that a bigint value is strictly greater than a specified minimum value (i.e., the minimum value is excluded).
1227
+ * _Param_ {bigint} expected The minimum allowable value, which is excluded.
1228
+ * _Throws_ {ValidationError} if the received value is less than or equal to the expected minimum value.
1102
1229
  * _Example_
1103
1230
  ```typescript
1104
- const schema = string().custom(uuidV3());
1105
- parseOrFail(schema, '550e8400-e29b-38d1-a456-426614174000'); // Valid
1106
- parseOrFail(schema, '550e8400-e29b-28d1-a456-426614174000'); // Throws an error: 'The received value is not a valid UUID v3'
1107
- parseOrFail(schema, 'invalid-uuid'); // Throws an error: 'The received value is not a valid UUID v3'
1231
+ const schema = bigint().custom(bigintMinExcluded(10n));
1232
+ parseOrFail(schema, 11n); // Valid
1233
+ parseOrFail(schema, 10n); // Throws an error: 'The received value is less than or equal to expected'
1234
+ parseOrFail(schema, 9n); // Throws an error: 'The received value is less than or equal to expected'
1108
1235
  ```
1109
- * _See_ Error Translation Key = 's:uuidV3'
1236
+ * _See_ Error Translation Key = 'bi:minExcluded'
1110
1237
 
1238
+ #### date {#assertdir_date}
1239
+
1240
+ <b>Prerequisites</b>
1241
+
1242
+ ```typescript
1243
+ import { date } from 'bguard/date';
1244
+ ```
1245
+
1246
+ * _Description_ Creates a new schema for validating date values.
1247
+ * _Example_
1248
+ ```typescript
1249
+ const schema = date();
1250
+ parseOrFail(schema, true); // Validates successfully
1251
+ parseOrFail(schema, 'true'); // Throws a validation error
1252
+ ```
1253
+
1111
1254
 
1112
- ##### uuidV4 (string)
1255
+ ##### dateMax (date) {#assert_dateMax_date}
1113
1256
 
1114
1257
  ```typescript
1115
- import { uuidV4 } from 'bguard/string/uuidV4';
1258
+ import { dateMax } from 'bguard/date/dateMax';
1116
1259
  ```
1117
1260
 
1118
- * _Description_ Asserts that a string value matches the UUID v4 format.
1119
- * _Throws_ {ValidationError} if the received value is not a valid UUID v4.
1261
+ * _Description_ Asserts that a date value is not greater than a specified maximum value.
1262
+ * _Param_ {Date | string} expected The maximum allowable value.
1263
+ * _Throws_ {ValidationError} if the received value is greater than the expected maximum value.
1120
1264
  * _Example_
1121
1265
  ```typescript
1122
- const schema = string().custom(uuidV4());
1123
- parseOrFail(schema, '123e4567-e89b-42d3-a456-426614174000'); // Valid
1124
- parseOrFail(schema, '123e4567-e89b-12d3-a456-426614174000'); // Throws an error: 'The received value is not a valid UUID v4'
1125
- parseOrFail(schema, '123e4567-e89b-a2d3-a456-426614174000'); // Throws an error: 'The received value is not a valid UUID v4'
1126
- parseOrFail(schema, '123e4567-e89b-42d3-c456-426614174000'); // Throws an error: 'The received value is not a valid UUID v4'
1127
- parseOrFail(schema, 'invalid-uuid'); // Throws an error: 'The received value is not a valid UUID v4'
1266
+ const schema = date().custom(dateMax('2024-12-31'));
1267
+ parseOrFail(schema, new Date('2024-12-30')); // Valid
1268
+ parseOrFail(schema, new Date('2024-12-31')); // Valid
1269
+ parseOrFail(schema, new Date('2025-01-01')); // Throws an error: 'The received value is greater than expected'
1128
1270
  ```
1129
- * _See_ Error Translation Key = 's:uuidV4'
1271
+ * _See_ Error Translation Key = 'dt:max'
1130
1272
 
1131
1273
 
1132
- ##### uuidV5 (string)
1274
+ ##### dateMin (date) {#assert_dateMin_date}
1133
1275
 
1134
1276
  ```typescript
1135
- import { uuidV5 } from 'bguard/string/uuidV5';
1277
+ import { dateMin } from 'bguard/date/dateMin';
1136
1278
  ```
1137
1279
 
1138
- * _Description_ Asserts that a string value matches the UUID v5 format.
1139
- * _Throws_ {ValidationError} if the received value is not a valid UUID v5.
1280
+ * _Description_ Asserts that a number value is not less than a specified minimum value.
1281
+ * _Param_ {Date | string} expected The minimum allowable value.
1282
+ * _Throws_ {ValidationError} if the received value is less than the expected minimum value.
1140
1283
  * _Example_
1141
1284
  ```typescript
1142
- const schema = string().custom(uuidV5());
1143
- parseOrFail(schema, '550e8400-e29b-51d4-a716-446655440000'); // Valid
1144
- parseOrFail(schema, '550e8400-e29b-41d4-a716-446655440000'); // Throws an error: 'The received value is not a valid UUID v5'
1145
- parseOrFail(schema, 'invalid-uuid'); // Throws an error: 'The received value is not a valid UUID v5'
1285
+ const schema = date().custom(dateMin('2023-01-01'));
1286
+ parseOrFail(schema, new Date('2023-01-02')); // Valid
1287
+ parseOrFail(schema, new Date('2023-01-01')); // Valid
1288
+ parseOrFail(schema, new Date('2022-12-31')); // Throws an error: 'The received value is less than expected'
1146
1289
  ```
1147
- * _See_ Error Translation Key = 's:uuidV5'
1290
+ * _See_ Error Translation Key = 'dt:min'
1148
1291
 
1292
+ #### mix {#assertdir_mix}
1293
+
1294
+ <b>Prerequisites</b>
1295
+
1296
+ ```typescript
1297
+ import { oneOfTypes } from 'bguard/mix';
1298
+ ```
1299
+
1300
+ * _Description_ Creates a new schema for validating values that can match any one of the specified primitive types.
1301
+
1302
+
1303
+ * _Param_ {T} valueTypes - An array of primitive types that the value can match.
1304
+ * _Example_
1305
+ ```typescript
1306
+ const schema = oneOfTypes(['string', 'number']);
1307
+ parseOrFail(schema, 'hello'); // Validates successfully
1308
+ parseOrFail(schema, 42); // Validates successfully
1309
+ parseOrFail(schema, true); // Throws a validation error
1310
+ ```
1311
+
1149
1312
 
1150
- ##### validUrl (string)
1313
+ ##### equalTo (mix) {#assert_equalTo_mix}
1151
1314
 
1152
1315
  ```typescript
1153
- import { validUrl } from 'bguard/string/validUrl';
1316
+ import { equalTo } from 'bguard/mix/equalTo';
1154
1317
  ```
1155
1318
 
1156
- * _Description_ Asserts that the string value is a valid URL with optional protocol validation.
1157
- * _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.
1158
- * _Throws_ {ValidationError} if the received value does not match the expected URL pattern.
1319
+ * _Description_ Creates a custom assertion that checks if a value is equal to the expected value.
1320
+ * > **Notice:** It has already been implemented in the number, bigint and string schema. There is no need to use it as a custom assert.
1321
+ * _Param_ {unknown} expected The value that the received value is expected to match.
1322
+ * _Throws_ {ValidationError} If the received value does not match the expected value.
1159
1323
  * _Example_
1160
1324
  ```typescript
1161
- const schema = string().custom(validUrl()); // Validates any URL starting with 'http://' or 'https://'
1162
- parseOrFail(schema, 'http://example.com'); // Valid
1163
- parseOrFail(schema, 'https://example.com'); // Valid
1164
- parseOrFail(schema, 'ftp://example.com'); // Throws an error
1165
- parseOrFail(schema, 'http:example.com'); // Throws an error
1325
+ const schema = number().custom(equalTo(5)); // Define a schema with a custom assertion
1326
+ parseOrFail(schema, 5); // Valid
1327
+ parseOrFail(schema, 3); // Throws an error: 'The received value is not equal to expected'
1166
1328
  ```
1167
- * _See_ Error Translation Key = 's:url'
1329
+ * _See_ Error Translation Key = 'm:equalTo'
1330
+
1331
+
1332
+ ##### oneOfValues (mix) {#assert_oneOfValues_mix}
1333
+
1334
+ ```typescript
1335
+ import { oneOfValues } from 'bguard/mix/oneOfValues';
1336
+ ```
1337
+
1338
+ * _Description_ Creates a custom assertion that checks if a value is equal to the one of expected values.
1339
+ * > **Notice:** It has already been implemented in the number, bigint and string schema. There is no need to use it as a custom assert.
1340
+ * _Param_ {unknown} expected The value that the received value is expected to match.
1341
+ * _Throws_ {ValidationError} If the received value does not match at least one of the expected values.
1342
+ * _Example_
1343
+ ```typescript
1344
+ const schema = number().custom(oneOfValues([5, 4])); // Define a schema with a custom assertion
1345
+ parseOrFail(schema, 5); // Valid
1346
+ parseOrFail(schema, 4); // Valid
1347
+ parseOrFail(schema, 3); // Throws an error: 'The received value is not equal to expected'
1348
+ ```
1349
+ * _See_ Error Translation Key = 'm:oneOfValues'
1168
1350
 
1169
1351
  ### Contributing
1170
1352
  Contributions are welcome! Please open an issue or submit a pull request for any bugs or feature requests.