bguard 0.3.0 → 0.4.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 (290) hide show
  1. package/README.md +270 -122
  2. package/lib/CommonSchema-DOh3bsL-.d.ts +110 -0
  3. package/lib/CommonSchema-wi9MOXGF.d.mts +110 -0
  4. package/lib/InferType.d.mts +6 -14
  5. package/lib/InferType.d.ts +6 -14
  6. package/lib/asserts/array/index.d.mts +6 -5
  7. package/lib/asserts/array/index.d.ts +6 -5
  8. package/lib/asserts/array/index.js +7 -7
  9. package/lib/asserts/array/index.js.map +1 -1
  10. package/lib/asserts/array/index.mjs +6 -6
  11. package/lib/asserts/array/index.mjs.map +1 -1
  12. package/lib/asserts/array/maxArrayLength.js +4 -4
  13. package/lib/asserts/array/maxArrayLength.mjs +2 -2
  14. package/lib/asserts/array/minArrayLength.js +4 -4
  15. package/lib/asserts/array/minArrayLength.mjs +2 -2
  16. package/lib/asserts/bigint/bigintMax.js +4 -4
  17. package/lib/asserts/bigint/bigintMax.mjs +2 -2
  18. package/lib/asserts/bigint/bigintMaxExcluded.js +4 -4
  19. package/lib/asserts/bigint/bigintMaxExcluded.mjs +2 -2
  20. package/lib/asserts/bigint/bigintMin.js +4 -4
  21. package/lib/asserts/bigint/bigintMin.mjs +2 -2
  22. package/lib/asserts/bigint/bigintMinExcluded.js +4 -4
  23. package/lib/asserts/bigint/bigintMinExcluded.mjs +2 -2
  24. package/lib/asserts/bigint/index.d.mts +5 -4
  25. package/lib/asserts/bigint/index.d.ts +5 -4
  26. package/lib/asserts/bigint/index.js +10 -10
  27. package/lib/asserts/bigint/index.js.map +1 -1
  28. package/lib/asserts/bigint/index.mjs +9 -9
  29. package/lib/asserts/bigint/index.mjs.map +1 -1
  30. package/lib/asserts/boolean/index.d.mts +5 -4
  31. package/lib/asserts/boolean/index.d.ts +5 -4
  32. package/lib/asserts/boolean/index.js +8 -8
  33. package/lib/asserts/boolean/index.js.map +1 -1
  34. package/lib/asserts/boolean/index.mjs +7 -7
  35. package/lib/asserts/boolean/index.mjs.map +1 -1
  36. package/lib/asserts/date/dateMax.js +5 -5
  37. package/lib/asserts/date/dateMax.mjs +2 -2
  38. package/lib/asserts/date/dateMin.js +5 -5
  39. package/lib/asserts/date/dateMin.mjs +2 -2
  40. package/lib/asserts/date/index.d.mts +5 -4
  41. package/lib/asserts/date/index.d.ts +5 -4
  42. package/lib/asserts/date/index.js +7 -7
  43. package/lib/asserts/date/index.js.map +1 -1
  44. package/lib/asserts/date/index.mjs +6 -6
  45. package/lib/asserts/date/index.mjs.map +1 -1
  46. package/lib/asserts/mix/equalTo.js +4 -4
  47. package/lib/asserts/mix/equalTo.mjs +3 -3
  48. package/lib/asserts/mix/index.d.mts +5 -4
  49. package/lib/asserts/mix/index.d.ts +5 -4
  50. package/lib/asserts/mix/index.js +6 -6
  51. package/lib/asserts/mix/index.js.map +1 -1
  52. package/lib/asserts/mix/index.mjs +5 -5
  53. package/lib/asserts/mix/index.mjs.map +1 -1
  54. package/lib/asserts/mix/oneOfValues.js +4 -4
  55. package/lib/asserts/mix/oneOfValues.mjs +3 -3
  56. package/lib/asserts/number/index.d.mts +4 -3
  57. package/lib/asserts/number/index.d.ts +4 -3
  58. package/lib/asserts/number/index.js +10 -10
  59. package/lib/asserts/number/index.js.map +1 -1
  60. package/lib/asserts/number/index.mjs +9 -9
  61. package/lib/asserts/number/index.mjs.map +1 -1
  62. package/lib/asserts/number/max.js +4 -4
  63. package/lib/asserts/number/max.mjs +2 -2
  64. package/lib/asserts/number/maxExcluded.js +4 -4
  65. package/lib/asserts/number/maxExcluded.mjs +2 -2
  66. package/lib/asserts/number/min.js +4 -4
  67. package/lib/asserts/number/min.mjs +2 -2
  68. package/lib/asserts/number/minExcluded.js +4 -4
  69. package/lib/asserts/number/minExcluded.mjs +2 -2
  70. package/lib/asserts/number/negative.js +4 -4
  71. package/lib/asserts/number/negative.mjs +2 -2
  72. package/lib/asserts/number/positive.js +4 -4
  73. package/lib/asserts/number/positive.mjs +2 -2
  74. package/lib/asserts/object/index.d.mts +6 -5
  75. package/lib/asserts/object/index.d.ts +6 -5
  76. package/lib/asserts/object/index.js +7 -7
  77. package/lib/asserts/object/index.js.map +1 -1
  78. package/lib/asserts/object/index.mjs +6 -6
  79. package/lib/asserts/object/index.mjs.map +1 -1
  80. package/lib/asserts/object/maxKeys.d.mts +30 -0
  81. package/lib/asserts/object/maxKeys.d.ts +30 -0
  82. package/lib/asserts/object/maxKeys.js +23 -0
  83. package/lib/asserts/object/maxKeys.js.map +1 -0
  84. package/lib/asserts/object/maxKeys.mjs +23 -0
  85. package/lib/asserts/object/maxKeys.mjs.map +1 -0
  86. package/lib/asserts/string/atLeastOneDigit.js +4 -4
  87. package/lib/asserts/string/atLeastOneDigit.mjs +2 -2
  88. package/lib/asserts/string/atLeastOneLowerChar.js +4 -4
  89. package/lib/asserts/string/atLeastOneLowerChar.mjs +2 -2
  90. package/lib/asserts/string/atLeastOneSpecialChar.js +4 -4
  91. package/lib/asserts/string/atLeastOneSpecialChar.mjs +2 -2
  92. package/lib/asserts/string/atLeastOneUpperChar.js +4 -4
  93. package/lib/asserts/string/atLeastOneUpperChar.mjs +2 -2
  94. package/lib/asserts/string/contains.js +4 -4
  95. package/lib/asserts/string/contains.mjs +2 -2
  96. package/lib/asserts/string/email.js +4 -4
  97. package/lib/asserts/string/email.mjs +2 -2
  98. package/lib/asserts/string/endsWith.js +4 -4
  99. package/lib/asserts/string/endsWith.mjs +2 -2
  100. package/lib/asserts/string/index.d.mts +5 -4
  101. package/lib/asserts/string/index.d.ts +5 -4
  102. package/lib/asserts/string/index.js +10 -10
  103. package/lib/asserts/string/index.js.map +1 -1
  104. package/lib/asserts/string/index.mjs +9 -9
  105. package/lib/asserts/string/index.mjs.map +1 -1
  106. package/lib/asserts/string/isValidDate.js +4 -4
  107. package/lib/asserts/string/isValidDate.mjs +2 -2
  108. package/lib/asserts/string/isValidDateTime.js +4 -4
  109. package/lib/asserts/string/isValidDateTime.mjs +2 -2
  110. package/lib/asserts/string/isValidTime.js +5 -5
  111. package/lib/asserts/string/isValidTime.mjs +2 -2
  112. package/lib/asserts/string/lowerCase.js +4 -4
  113. package/lib/asserts/string/lowerCase.mjs +2 -2
  114. package/lib/asserts/string/maxLength.js +4 -4
  115. package/lib/asserts/string/maxLength.mjs +2 -2
  116. package/lib/asserts/string/minLength.js +4 -4
  117. package/lib/asserts/string/minLength.mjs +2 -2
  118. package/lib/asserts/string/regExp.js +4 -4
  119. package/lib/asserts/string/regExp.mjs +2 -2
  120. package/lib/asserts/string/startsWith.js +4 -4
  121. package/lib/asserts/string/startsWith.mjs +2 -2
  122. package/lib/asserts/string/upperCase.js +4 -4
  123. package/lib/asserts/string/upperCase.mjs +2 -2
  124. package/lib/asserts/string/uuid.js +4 -4
  125. package/lib/asserts/string/uuid.mjs +2 -2
  126. package/lib/asserts/string/uuidV1.js +4 -4
  127. package/lib/asserts/string/uuidV1.mjs +2 -2
  128. package/lib/asserts/string/uuidV2.js +4 -4
  129. package/lib/asserts/string/uuidV2.mjs +2 -2
  130. package/lib/asserts/string/uuidV3.js +4 -4
  131. package/lib/asserts/string/uuidV3.mjs +2 -2
  132. package/lib/asserts/string/uuidV4.js +4 -4
  133. package/lib/asserts/string/uuidV4.mjs +2 -2
  134. package/lib/asserts/string/uuidV5.js +4 -4
  135. package/lib/asserts/string/uuidV5.mjs +2 -2
  136. package/lib/asserts/string/validUrl.js +4 -4
  137. package/lib/asserts/string/validUrl.mjs +2 -2
  138. package/lib/{chunk-OJSTQQ3N.js → chunk-2KQASECD.js} +5 -5
  139. package/lib/{chunk-OJSTQQ3N.js.map → chunk-2KQASECD.js.map} +1 -1
  140. package/lib/{chunk-AY7HKAG2.js → chunk-5P6AZJCN.js} +5 -3
  141. package/lib/chunk-5P6AZJCN.js.map +1 -0
  142. package/lib/{chunk-AN3VHQEQ.js → chunk-5WHCMWXK.js} +12 -9
  143. package/lib/chunk-5WHCMWXK.js.map +1 -0
  144. package/lib/{chunk-UZ2PWO4O.js → chunk-5YYRBKDP.js} +4 -4
  145. package/lib/{chunk-UZ2PWO4O.js.map → chunk-5YYRBKDP.js.map} +1 -1
  146. package/lib/{chunk-YPAFWVDL.mjs → chunk-6D5W7SSQ.mjs} +4 -4
  147. package/lib/chunk-6D5W7SSQ.mjs.map +1 -0
  148. package/lib/chunk-7NBOVYSP.mjs +136 -0
  149. package/lib/chunk-7NBOVYSP.mjs.map +1 -0
  150. package/lib/{chunk-5LLJ22IG.mjs → chunk-BNCT7NOR.mjs} +21 -7
  151. package/lib/chunk-BNCT7NOR.mjs.map +1 -0
  152. package/lib/{chunk-BUXOCPHI.mjs → chunk-C3EDEQ3W.mjs} +3 -3
  153. package/lib/{chunk-TQWUSDQD.mjs → chunk-CHUPE6SJ.mjs} +6 -6
  154. package/lib/chunk-CHUPE6SJ.mjs.map +1 -0
  155. package/lib/{chunk-ZVW3IHBW.js → chunk-ECBOZ3BM.js} +8 -8
  156. package/lib/chunk-ECBOZ3BM.js.map +1 -0
  157. package/lib/{chunk-NP64RC7B.mjs → chunk-FGZKNBDP.mjs} +5 -3
  158. package/lib/chunk-FGZKNBDP.mjs.map +1 -0
  159. package/lib/{chunk-ZWE5Q37U.mjs → chunk-FP5QAEVQ.mjs} +6 -6
  160. package/lib/chunk-FP5QAEVQ.mjs.map +1 -0
  161. package/lib/{chunk-PESVL5YJ.js → chunk-G55SHHAR.js} +10 -8
  162. package/lib/chunk-G55SHHAR.js.map +1 -0
  163. package/lib/{chunk-4GDBM5LP.mjs → chunk-H32B3NHW.mjs} +2 -2
  164. package/lib/{chunk-D42ISCFK.mjs → chunk-H6LHV3EA.mjs} +2 -2
  165. package/lib/{chunk-SPWF5IFU.js → chunk-HP3DRZWK.js} +5 -5
  166. package/lib/{chunk-SPWF5IFU.js.map → chunk-HP3DRZWK.js.map} +1 -1
  167. package/lib/{chunk-W2GOLG3K.js → chunk-IZ3CBVEE.js} +5 -5
  168. package/lib/{chunk-W2GOLG3K.js.map → chunk-IZ3CBVEE.js.map} +1 -1
  169. package/lib/{chunk-OHEMRF7Y.mjs → chunk-K7X6DVM2.mjs} +3 -3
  170. package/lib/{chunk-KBZUNXJB.mjs → chunk-LPR3G5T3.mjs} +4 -4
  171. package/lib/{chunk-KBZUNXJB.mjs.map → chunk-LPR3G5T3.mjs.map} +1 -1
  172. package/lib/{chunk-2MFBOVP2.mjs → chunk-MHBY5OIQ.mjs} +3 -3
  173. package/lib/{chunk-EU3ZZF7Y.js → chunk-MLNQZ445.js} +13 -13
  174. package/lib/chunk-MLNQZ445.js.map +1 -0
  175. package/lib/chunk-QIDWASOC.js +14 -0
  176. package/lib/{chunk-3ZPLJ5KC.js.map → chunk-QIDWASOC.js.map} +1 -1
  177. package/lib/chunk-SHJVKSEZ.js +136 -0
  178. package/lib/chunk-SHJVKSEZ.js.map +1 -0
  179. package/lib/{chunk-ADSMWGDJ.mjs → chunk-TRGMD7LA.mjs} +7 -5
  180. package/lib/chunk-TRGMD7LA.mjs.map +1 -0
  181. package/lib/{chunk-OKF3BVUD.mjs → chunk-TV5IZY4L.mjs} +9 -6
  182. package/lib/chunk-TV5IZY4L.mjs.map +1 -0
  183. package/lib/{chunk-OO6BTBVP.js → chunk-U4USIJV3.js} +11 -11
  184. package/lib/{chunk-OO6BTBVP.js.map → chunk-U4USIJV3.js.map} +1 -1
  185. package/lib/{chunk-P6V6S6TZ.js → chunk-UUY7DPHK.js} +12 -12
  186. package/lib/chunk-UUY7DPHK.js.map +1 -0
  187. package/lib/chunk-VW4RMQD4.js +28 -0
  188. package/lib/{chunk-LYNVPN3R.js.map → chunk-VW4RMQD4.js.map} +1 -1
  189. package/lib/{chunk-ZMEQCIRN.mjs → chunk-WK4FJ5GD.mjs} +6 -6
  190. package/lib/chunk-WK4FJ5GD.mjs.map +1 -0
  191. package/lib/{chunk-PIBDJJUU.js → chunk-X762EUSZ.js} +31 -17
  192. package/lib/chunk-X762EUSZ.js.map +1 -0
  193. package/lib/{chunk-5HT3PYSG.mjs → chunk-YUMUCQKL.mjs} +4 -4
  194. package/lib/{chunk-5HT3PYSG.mjs.map → chunk-YUMUCQKL.mjs.map} +1 -1
  195. package/lib/{chunk-2D5QE7F4.js → chunk-Z6QU36MM.js} +12 -12
  196. package/lib/chunk-Z6QU36MM.js.map +1 -0
  197. package/lib/codeGen.d.mts +2 -1
  198. package/lib/codeGen.d.ts +2 -1
  199. package/lib/codeGen.js +3 -3
  200. package/lib/codeGen.mjs +2 -2
  201. package/lib/commonTypes.d.mts +26 -2
  202. package/lib/commonTypes.d.ts +26 -2
  203. package/lib/exceptions.d.mts +3 -2
  204. package/lib/exceptions.d.ts +3 -2
  205. package/lib/exceptions.js +2 -2
  206. package/lib/exceptions.mjs +1 -1
  207. package/lib/helpers/core.d.mts +2 -1
  208. package/lib/helpers/core.d.ts +2 -1
  209. package/lib/helpers/core.js +3 -3
  210. package/lib/helpers/core.mjs +2 -2
  211. package/lib/helpers/setStrictType.d.mts +2 -1
  212. package/lib/helpers/setStrictType.d.ts +2 -1
  213. package/lib/helpers/setStrictType.js +4 -4
  214. package/lib/helpers/setStrictType.mjs +3 -3
  215. package/lib/index.d.mts +1 -8
  216. package/lib/index.d.ts +1 -8
  217. package/lib/index.js +6 -6
  218. package/lib/index.mjs +5 -5
  219. package/lib/parse.d.mts +1 -8
  220. package/lib/parse.d.ts +1 -8
  221. package/lib/parse.js +5 -5
  222. package/lib/parse.mjs +4 -4
  223. package/lib/parseOrFail.d.mts +1 -8
  224. package/lib/parseOrFail.d.ts +1 -8
  225. package/lib/parseOrFail.js +5 -5
  226. package/lib/parseOrFail.mjs +4 -4
  227. package/lib/schemas/ArraySchema.d.mts +3 -6
  228. package/lib/schemas/ArraySchema.d.ts +3 -6
  229. package/lib/schemas/ArraySchema.js +7 -7
  230. package/lib/schemas/ArraySchema.mjs +6 -6
  231. package/lib/schemas/BigIntSchema.d.mts +6 -9
  232. package/lib/schemas/BigIntSchema.d.ts +6 -9
  233. package/lib/schemas/BigIntSchema.js +10 -10
  234. package/lib/schemas/BigIntSchema.mjs +9 -9
  235. package/lib/schemas/BooleanSchema.d.mts +6 -9
  236. package/lib/schemas/BooleanSchema.d.ts +6 -9
  237. package/lib/schemas/BooleanSchema.js +8 -8
  238. package/lib/schemas/BooleanSchema.mjs +7 -7
  239. package/lib/schemas/CommonSchema.d.mts +2 -1
  240. package/lib/schemas/CommonSchema.d.ts +2 -1
  241. package/lib/schemas/CommonSchema.js +6 -6
  242. package/lib/schemas/CommonSchema.mjs +5 -5
  243. package/lib/schemas/DateSchema.d.mts +2 -1
  244. package/lib/schemas/DateSchema.d.ts +2 -1
  245. package/lib/schemas/DateSchema.js +7 -7
  246. package/lib/schemas/DateSchema.mjs +6 -6
  247. package/lib/schemas/NumberSchema.d.mts +6 -9
  248. package/lib/schemas/NumberSchema.d.ts +6 -9
  249. package/lib/schemas/NumberSchema.js +10 -10
  250. package/lib/schemas/NumberSchema.mjs +9 -9
  251. package/lib/schemas/ObjectSchema.d.mts +3 -5
  252. package/lib/schemas/ObjectSchema.d.ts +3 -5
  253. package/lib/schemas/ObjectSchema.js +7 -7
  254. package/lib/schemas/ObjectSchema.mjs +6 -6
  255. package/lib/schemas/StringSchema.d.mts +6 -9
  256. package/lib/schemas/StringSchema.d.ts +6 -9
  257. package/lib/schemas/StringSchema.js +10 -10
  258. package/lib/schemas/StringSchema.mjs +9 -9
  259. package/lib/translationMap.js +3 -3
  260. package/lib/translationMap.mjs +2 -2
  261. package/package.json +1 -1
  262. package/lib/CommonSchema-CiY7spmg.d.mts +0 -71
  263. package/lib/CommonSchema-D9QVJBJe.d.ts +0 -71
  264. package/lib/chunk-2D5QE7F4.js.map +0 -1
  265. package/lib/chunk-3IOQH3K4.js +0 -74
  266. package/lib/chunk-3IOQH3K4.js.map +0 -1
  267. package/lib/chunk-3ZPLJ5KC.js +0 -14
  268. package/lib/chunk-5LLJ22IG.mjs.map +0 -1
  269. package/lib/chunk-ADSMWGDJ.mjs.map +0 -1
  270. package/lib/chunk-AN3VHQEQ.js.map +0 -1
  271. package/lib/chunk-AOUFWACR.mjs +0 -74
  272. package/lib/chunk-AOUFWACR.mjs.map +0 -1
  273. package/lib/chunk-AY7HKAG2.js.map +0 -1
  274. package/lib/chunk-EU3ZZF7Y.js.map +0 -1
  275. package/lib/chunk-LYNVPN3R.js +0 -28
  276. package/lib/chunk-NP64RC7B.mjs.map +0 -1
  277. package/lib/chunk-OKF3BVUD.mjs.map +0 -1
  278. package/lib/chunk-P6V6S6TZ.js.map +0 -1
  279. package/lib/chunk-PESVL5YJ.js.map +0 -1
  280. package/lib/chunk-PIBDJJUU.js.map +0 -1
  281. package/lib/chunk-TQWUSDQD.mjs.map +0 -1
  282. package/lib/chunk-YPAFWVDL.mjs.map +0 -1
  283. package/lib/chunk-ZMEQCIRN.mjs.map +0 -1
  284. package/lib/chunk-ZVW3IHBW.js.map +0 -1
  285. package/lib/chunk-ZWE5Q37U.mjs.map +0 -1
  286. /package/lib/{chunk-BUXOCPHI.mjs.map → chunk-C3EDEQ3W.mjs.map} +0 -0
  287. /package/lib/{chunk-4GDBM5LP.mjs.map → chunk-H32B3NHW.mjs.map} +0 -0
  288. /package/lib/{chunk-D42ISCFK.mjs.map → chunk-H6LHV3EA.mjs.map} +0 -0
  289. /package/lib/{chunk-OHEMRF7Y.mjs.map → chunk-K7X6DVM2.mjs.map} +0 -0
  290. /package/lib/{chunk-2MFBOVP2.mjs.map → chunk-MHBY5OIQ.mjs.map} +0 -0
package/README.md CHANGED
@@ -4,7 +4,82 @@
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
- ### Features
7
+ Table of contents
8
+
9
+ * [Features](#h3_features)
10
+ * [Installation](#h3_installation)
11
+ * [Usage](#h3_usage)
12
+ * [Defining a Schema](#h4_usage_defining_a_schema)
13
+ * [Inferring TypeScript Types](#h4_usage_inferring_typescript_types)
14
+ * [Generating TypeScript Types with `codeGen`](#h4_usage_generating_typescript_types_with_codeGen)
15
+ * [Generating Named TypeScript Types with `codeGenWithName`](#h4_usage_generating_typescript_types_with_codeGenWithName)
16
+ * [Summary:](#h4_usage_summary)
17
+ * [Validating Data](#h3_validating_data)
18
+ * [`parse` Method](#h4_validating_data_parse)
19
+ * [`parseOrFail` Method](#h4_validating_data_parseOrFail)
20
+ * [Chaining Methods](#h3_chaining_methods)
21
+ * [nullable()](#h4_chaining_nullable)
22
+ * [optional()](#h4_chaining_optional)
23
+ * [id(value: string)](#h4_chaining_id)
24
+ * [description(value: string)](#h4_chaining_description)
25
+ * [Literals](#h3_literals)
26
+ * [Custom (Library Built-in) Assertions](#h3_custom_builtin_assertions)
27
+ * [Create Custom Assertions](#h3_create_custom_assertions)
28
+ * [Translation](#translation)
29
+ * [Using Translations](#h4_using_translation)
30
+ * [Common and Custom Translations](#common_and_custom_translations)
31
+
32
+ * [Built-in Custom Assert Documentation](#builtin_custom_assert_documentation)
33
+
34
+ * [string](#assertdir_string)
35
+ * [atLeastOneDigit](#assert_atLeastOneDigit_string)
36
+ * [atLeastOneLowerChar](#assert_atLeastOneLowerChar_string)
37
+ * [atLeastOneSpecialChar](#assert_atLeastOneSpecialChar_string)
38
+ * [atLeastOneUpperChar](#assert_atLeastOneUpperChar_string)
39
+ * [contains](#assert_contains_string)
40
+ * [email](#assert_email_string)
41
+ * [endsWith](#assert_endsWith_string)
42
+ * [isValidDate](#assert_isValidDate_string)
43
+ * [isValidDateTime](#assert_isValidDateTime_string)
44
+ * [isValidTime](#assert_isValidTime_string)
45
+ * [lowerCase](#assert_lowerCase_string)
46
+ * [maxLength](#assert_maxLength_string)
47
+ * [minLength](#assert_minLength_string)
48
+ * [regExp](#assert_regExp_string)
49
+ * [startsWith](#assert_startsWith_string)
50
+ * [upperCase](#assert_upperCase_string)
51
+ * [uuid](#assert_uuid_string)
52
+ * [uuidV1](#assert_uuidV1_string)
53
+ * [uuidV2](#assert_uuidV2_string)
54
+ * [uuidV3](#assert_uuidV3_string)
55
+ * [uuidV4](#assert_uuidV4_string)
56
+ * [uuidV5](#assert_uuidV5_string)
57
+ * [validUrl](#assert_validUrl_string)
58
+ * [number](#assertdir_number)
59
+ * [max](#assert_max_number)
60
+ * [maxExcluded](#assert_maxExcluded_number)
61
+ * [min](#assert_min_number)
62
+ * [minExcluded](#assert_minExcluded_number)
63
+ * [negative](#assert_negative_number)
64
+ * [positive](#assert_positive_number)
65
+ * [array](#assertdir_array)
66
+ * [maxArrayLength](#assert_maxArrayLength_array)
67
+ * [minArrayLength](#assert_minArrayLength_array)
68
+ * [bigint](#assertdir_bigint)
69
+ * [bigintMax](#assert_bigintMax_bigint)
70
+ * [bigintMaxExcluded](#assert_bigintMaxExcluded_bigint)
71
+ * [bigintMin](#assert_bigintMin_bigint)
72
+ * [bigintMinExcluded](#assert_bigintMinExcluded_bigint)
73
+ * [date](#assertdir_date)
74
+ * [dateMax](#assert_dateMax_date)
75
+ * [dateMin](#assert_dateMin_date)
76
+ * [mix](#assertdir_mix)
77
+ * [equalTo](#assert_equalTo_mix)
78
+ * [oneOfValues](#assert_oneOfValues_mix)
79
+ * [object](#assertdir_object)
80
+ * [maxKeys](#assert_maxKeys_object)
81
+
82
+ ### <a id="h3_features"> Features </a>
8
83
 
9
84
  - **Type Inference**: Automatically infer TypeScript types from your validation schemas.
10
85
  - **Custom Assertions**: Add custom validation logic for your schemas.
@@ -14,17 +89,17 @@
14
89
  - **Small Bundle Size**: Each assertion is in its own file, minimizing your final bundle size.
15
90
  - **Lightweight**: No dependencies and optimized for performance.
16
91
 
17
- ### Installation
92
+ ### <a id="h3_installation"> Installation </a>
18
93
 
19
94
  ```bash
20
95
  npm install bguard
21
96
  ```
22
97
 
23
- ### Usage
98
+ ### <a id="h3_usage"> Usage </a>
24
99
 
25
100
  Here’s a basic example of how to use `bguard` to define and validate a schema.
26
101
 
27
- #### Defining a Schema
102
+ #### <a id="h4_usage_defining_a_schema"> Defining a Schema </a>
28
103
 
29
104
  Let's define a schema for a Student object:
30
105
 
@@ -57,7 +132,7 @@ const studentSchema = object({
57
132
 
58
133
  ```
59
134
 
60
- #### Inferring TypeScript Types
135
+ #### <a id="h4_usage_inferring_typescript_types"> Inferring TypeScript Types </a>
61
136
 
62
137
  Using the InferType utility, you can infer the TypeScript type of the schema:
63
138
 
@@ -83,7 +158,7 @@ type StudentSchema = {
83
158
 
84
159
  ```
85
160
 
86
- #### Generating TypeScript Types with `codeGen`
161
+ #### <a id="h4_usage_generating_typescript_types_with_codeGen"> Generating TypeScript Types with `codeGen` </a>
87
162
 
88
163
  If you prefer to generate TypeScript types as a string, you can use the `codeGen` function:
89
164
 
@@ -118,7 +193,7 @@ This would output a string:
118
193
 
119
194
  > **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
195
 
121
- #### Generating Named TypeScript Types with `codeGenWithName`
196
+ #### <a id="h4_usage_generating_typescript_types_with_codeGenWithName"> Generating Named TypeScript Types with `codeGenWithName` </a>
122
197
 
123
198
  For convenience, if you want to generate a complete type definition including a name, use the `codeGenWithName` function:
124
199
 
@@ -150,14 +225,13 @@ type StudentSchema = {
150
225
  verified?: boolean | undefined;
151
226
  }
152
227
  ```
153
-
154
- #### Summary:
228
+ #### <a id="h4_usage_summary"> Summary: </a>
155
229
 
156
230
  `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.
157
231
 
158
232
  `codeGenWithName(typeName: string, schema: CommonSchema): string` - Generates a complete TypeScript type definition string, including the type keyword and type name.
159
233
 
160
- ### Validating Data
234
+ ### <a id="h3_validating_data"> Validating Data </a>
161
235
 
162
236
  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.
163
237
 
@@ -193,7 +267,7 @@ const invalidStudentData = {
193
267
  };
194
268
  ```
195
269
 
196
- #### `parse` Method
270
+ #### <a id="h4_validating_data_parse"> `parse` Method </a>
197
271
 
198
272
  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.
199
273
 
@@ -216,7 +290,7 @@ Options:
216
290
  - `lng`: Specifies the language for error messages. Default is `'default'`.
217
291
  - `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.
218
292
 
219
- #### `parseOrFail` Method
293
+ #### <a id="h4_validating_data_parseOrFail"> `parseOrFail` Method </a>
220
294
 
221
295
  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.
222
296
 
@@ -244,8 +318,6 @@ Options:
244
318
 
245
319
  - `lng`: Specifies the language for error messages. Default is `'default'`.
246
320
 
247
- ####
248
-
249
321
  Explanation
250
322
 
251
323
  - **`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.
@@ -254,11 +326,31 @@ Explanation
254
326
 
255
327
  - **Options**: Both methods accept options for language settings and error collection, enhancing flexibility in handling validation processes.
256
328
 
257
- ### Chaining Methods
329
+ ### <a id="h3_chaining_methods"> Chaining Methods </a>
330
+
331
+ #### <a id="h4_chaining_nullable"> nullable() </a>
332
+
333
+ Allows the value to be `null`.
334
+
335
+ Example:
336
+
337
+ ```typeScript
338
+ const nullableSchema = string().nullable().optional();
339
+ // This schema allows string or null values.
340
+ ```
341
+
342
+ #### <a id="h4_chaining_optional"> optional() </a>
343
+ Allows the value to be `undefined`.
344
+
345
+ _Example_:
346
+
347
+ ```typeScript
348
+ const optionalSchema = string().nullable().optional();
349
+ // This schema allows string or undefined values.
350
+ ```
258
351
 
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`.
352
+ #### <a id="h4_chaining_default"> default(value: InferType<this>)</a>
353
+ Sets a default value if the received value is `undefined`. The default value must match the inferred type of the schema, ensuring compatibility.
262
354
 
263
355
 
264
356
  > **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'"`.
@@ -266,8 +358,7 @@ Explanation
266
358
 
267
359
  > **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
360
 
269
-
270
- Example:
361
+ _Example_:
271
362
 
272
363
  ```typeScript
273
364
  const schemaWithDefault = string().nullable().default('defaultString');
@@ -276,20 +367,76 @@ const schemaWithDefault = string().nullable().default('defaultString');
276
367
  const optionalSchema = string().nullable().optional();
277
368
  // This schema allows both null and undefined values, but it does not provide a default value.
278
369
  ```
370
+ #### <a id="h4_chaining_id"> id(value: string) </a>
371
+
372
+ Assigns a unique identifier to the schema, useful for tracking or mapping validation errors. The `id` can be accessed via `err.meta?.id` in case of a validation error.
373
+
374
+ #### <a id="h4_chaining_description"> description(value: string) </a>
375
+
376
+ Provides a description for the schema, which can be used to give more context about the validation error. The `description` can be accessed via `err.meta?.description` in case of a validation error.
377
+
378
+ _Example_:
379
+
380
+ ```typeScript
381
+ const addressSchema = string()
382
+ .id('address')
383
+ .description('Users address');
384
+ // This schema validates that string and assigns an ID and description for better error handling.
385
+
386
+ try {
387
+ parseOrFail(addressSchema, undefined);
388
+ } catch (e) {
389
+ const err = e as ValidationError;
390
+ console.log(err.message); // Output: 'The required value is missing'
391
+ console.log(err.pathToError); // Output: ''
392
+ console.log(err.meta?.id); // Output: 'address'
393
+ console.log(err.meta?.description); // Output: 'Users address'
394
+ }
395
+ ```
396
+ #### <a id="h4_chaining_transformbeforevalidation"> transformBeforeValidation\<In\>(cb: TransformCallback<In, InferType\<Schema>\>) </a>
397
+
398
+ This method allows you to apply a transformation to the input value before any validation occurs. The transformation is applied before the schema's other methods (like `nullable`, `custom`, etc.). The callback function can receive an input of type `unknown` by default, but you can specify the type if you know it, such as `string`. The return value of the callback must be of the same type as the inferred type of the schema, ensuring that the overall type does not change.
399
+
400
+ <b>Order of Execution</b>:
401
+ First, transformations specified using transformBeforeValidation are applied.
402
+ Then, the schema checks for null or undefined based on methods like `nullable` or `optional`.
403
+ Finally, the `custom` validations and type checks are performed.
404
+
405
+ This method is particularly useful for normalizing or preparing data before validation, such as trimming whitespace, converting empty strings to null, or handling other preprocessing needs.
406
+
407
+ > **Notice:** Like default, `transformBeforeValidation` should be placed at the end of the chain. This ensures that the transformation is correctly applied after all other type checks are resolved, preserving the expected type.
279
408
 
280
- - String Literals:
409
+ _Example_:
410
+
411
+ ```typescript
412
+ const stringOrNullSchema = string()
413
+ .nullable()
414
+ .custom(minLength(3))
415
+ .transformBeforeValidation((val) => val + '') // First, transform value to a string
416
+ .transformBeforeValidation((val: string) => (val === '' ? null : val)); // Second, convert empty strings to null
417
+
418
+ // Parsing 'test' will pass as 'test' is a valid string longer than 3 characters.
419
+ parseOrFail(stringOrNullSchema, 'test');
420
+
421
+ // Parsing '' will be transformed to null and will pass due to .nullable().
422
+ parseOrFail(stringOrNullSchema, '');
423
+ ```
424
+
425
+ ### <a id="h3_literals"> Literals </a>
426
+
427
+ - <b>String Literals</b>:
281
428
  `string().equalTo('myStringValue')` will infer <b>'myStringValue'</b> as the type.
282
429
  `string().oneOfValues(['foo', 'bar'])` will infer <b>'foo' | 'bar'</b> as the type.
283
430
 
284
- - Number Literals:
431
+ - <b>Number Literals</b>:
285
432
  `number().equalTo(42)` will infer <b>42</b> as the type.
286
433
  `number().oneOfValues([3, 5])` will infer <b>3 | 5</b> as the type.
287
434
 
288
- - Boolean Literals:
435
+ - <b>Boolean Literals</b>:
289
436
  `boolean().onlyTrue()` will infer <b>true</b> as the type.
290
437
  `boolean().onlyFalse()` will infer <b>false</b> as the type.
291
438
 
292
- ### Custom (Library Built-in) Assertions
439
+ ### <a id="h3_custom_builtin_assertions"> Custom (Library Built-in) Assertions </a>
293
440
 
294
441
  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.
295
442
  All built-in asserts are documented in the [Built-in Custom Assert Documentation](#builtin_custom_assert_documentation) section.
@@ -305,7 +452,7 @@ const ageSchema = number().custom(min(18), max(120));
305
452
 
306
453
  Library built-in assertions are imported from specific paths for better tree-shaking and smaller bundle sizes.
307
454
 
308
- ### Create Custom Assertions
455
+ ### <a id="h3_create_custom_assertions"> Create Custom Assertions </a>
309
456
 
310
457
  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.
311
458
 
@@ -349,7 +496,7 @@ Explanation
349
496
  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.
350
497
  For single-language applications, you can override the default message by directly passing your custom message to `guardException`.
351
498
 
352
- ### Translation {#translation}
499
+ ### <a id="translation"> Translation </a>
353
500
 
354
501
  Bguard provides default translations for error messages, but you can customize them as needed. Each potential error has an `errorKey` and `errorMessage`.
355
502
 
@@ -389,7 +536,7 @@ With this setup, in the translation namespace 'SR', if the received value is 4,
389
536
 
390
537
  > **Notice:** Do not overwrite the 'default' namespace. If a translation is missing, it will fall back to the 'default' translation.
391
538
 
392
- #### Using Translations
539
+ #### <a id="h4_using_translation"> Using Translations </a>
393
540
 
394
541
  To apply the new translation, both `parse` and `parseOrFail` functions accept a lng property in the options object provided as the third parameter:
395
542
 
@@ -399,7 +546,7 @@ parseOrFail(testSchema, { foo: 4 }, { lng: 'SR' });
399
546
  parse(testSchema, { foo: 4 }, { lng: 'SR' });
400
547
  ```
401
548
 
402
- #### Common and Custom Translations {#common_and_custom_translations}
549
+ #### <a id="common_and_custom_translations"> Common and Custom Translations </a>
403
550
 
404
551
  We have two sets of translations: common errors and specific assertions.
405
552
 
@@ -462,56 +609,9 @@ console.log(maxLength.message); // Output: 'The received value length is greater
462
609
 
463
610
  <b>3.</b> IDE Support:
464
611
  Each key and message will be visible in text editors that support JSDoc IntelliSense.
612
+ ### <a id="builtin_custom_assert_documentation"> Built-in Custom Assert Documentation </a>
465
613
 
466
- ### Built-in Custom Assert Documentation {#builtin_custom_assert_documentation}
467
-
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}
614
+ #### <a id="assertdir_string"> string </a>
515
615
 
516
616
  <b>Prerequisites</b>
517
617
 
@@ -528,7 +628,7 @@ import { string } from 'bguard/string';
528
628
  ```
529
629
 
530
630
 
531
- ##### atLeastOneDigit (string) {#assert_atLeastOneDigit_string}
631
+ ##### <a id="assert_atLeastOneDigit_string"> atLeastOneDigit </a>
532
632
 
533
633
  ```typescript
534
634
  import { atLeastOneDigit } from 'bguard/string/atLeastOneDigit';
@@ -545,7 +645,7 @@ import { atLeastOneDigit } from 'bguard/string/atLeastOneDigit';
545
645
  * _See_ Error Translation Key = 's:atLeastOneDigit'
546
646
 
547
647
 
548
- ##### atLeastOneLowerChar (string) {#assert_atLeastOneLowerChar_string}
648
+ ##### <a id="assert_atLeastOneLowerChar_string"> atLeastOneLowerChar </a>
549
649
 
550
650
  ```typescript
551
651
  import { atLeastOneLowerChar } from 'bguard/string/atLeastOneLowerChar';
@@ -562,7 +662,7 @@ import { atLeastOneLowerChar } from 'bguard/string/atLeastOneLowerChar';
562
662
  * _See_ Error Translation Key = 's:atLeastOneLowerChar'
563
663
 
564
664
 
565
- ##### atLeastOneSpecialChar (string) {#assert_atLeastOneSpecialChar_string}
665
+ ##### <a id="assert_atLeastOneSpecialChar_string"> atLeastOneSpecialChar </a>
566
666
 
567
667
  ```typescript
568
668
  import { atLeastOneSpecialChar } from 'bguard/string/atLeastOneSpecialChar';
@@ -584,7 +684,7 @@ import { atLeastOneSpecialChar } from 'bguard/string/atLeastOneSpecialChar';
584
684
  * _See_ Error Translation Key = 's:atLeastOneSpecialChar'
585
685
 
586
686
 
587
- ##### atLeastOneUpperChar (string) {#assert_atLeastOneUpperChar_string}
687
+ ##### <a id="assert_atLeastOneUpperChar_string"> atLeastOneUpperChar </a>
588
688
 
589
689
  ```typescript
590
690
  import { atLeastOneUpperChar } from 'bguard/string/atLeastOneUpperChar';
@@ -601,7 +701,7 @@ import { atLeastOneUpperChar } from 'bguard/string/atLeastOneUpperChar';
601
701
  * _See_ Error Translation Key = 's:atLeastOneUpperChar'
602
702
 
603
703
 
604
- ##### contains (string) {#assert_contains_string}
704
+ ##### <a id="assert_contains_string"> contains </a>
605
705
 
606
706
  ```typescript
607
707
  import { contains } from 'bguard/string/contains';
@@ -619,7 +719,7 @@ import { contains } from 'bguard/string/contains';
619
719
  * _See_ Error Translation Key = 's:contains'
620
720
 
621
721
 
622
- ##### email (string) {#assert_email_string}
722
+ ##### <a id="assert_email_string"> email </a>
623
723
 
624
724
  ```typescript
625
725
  import { email } from 'bguard/string/email';
@@ -636,7 +736,7 @@ import { email } from 'bguard/string/email';
636
736
  * _See_ - Error Translation Key = 's:email'
637
737
 
638
738
 
639
- ##### endsWith (string) {#assert_endsWith_string}
739
+ ##### <a id="assert_endsWith_string"> endsWith </a>
640
740
 
641
741
  ```typescript
642
742
  import { endsWith } from 'bguard/string/endsWith';
@@ -654,7 +754,7 @@ import { endsWith } from 'bguard/string/endsWith';
654
754
  * _See_ Error Translation Key = 's:endsWith'
655
755
 
656
756
 
657
- ##### isValidDate (string) {#assert_isValidDate_string}
757
+ ##### <a id="assert_isValidDate_string"> isValidDate </a>
658
758
 
659
759
  ```typescript
660
760
  import { isValidDate } from 'bguard/string/isValidDate';
@@ -672,7 +772,7 @@ import { isValidDate } from 'bguard/string/isValidDate';
672
772
  * _See_ Error Translation Key = 's:isValidDate'
673
773
 
674
774
 
675
- ##### isValidDateTime (string) {#assert_isValidDateTime_string}
775
+ ##### <a id="assert_isValidDateTime_string"> isValidDateTime </a>
676
776
 
677
777
  ```typescript
678
778
  import { isValidDateTime } from 'bguard/string/isValidDateTime';
@@ -700,7 +800,7 @@ import { isValidDateTime } from 'bguard/string/isValidDateTime';
700
800
  * _See_ Error Translation Key = 's:isValidDateTime'
701
801
 
702
802
 
703
- ##### isValidTime (string) {#assert_isValidTime_string}
803
+ ##### <a id="assert_isValidTime_string"> isValidTime </a>
704
804
 
705
805
  ```typescript
706
806
  import { isValidTime } from 'bguard/string/isValidTime';
@@ -723,7 +823,7 @@ import { isValidTime } from 'bguard/string/isValidTime';
723
823
  * _See_ Error Translation Key = 's:isValidTime'
724
824
 
725
825
 
726
- ##### lowerCase (string) {#assert_lowerCase_string}
826
+ ##### <a id="assert_lowerCase_string"> lowerCase </a>
727
827
 
728
828
  ```typescript
729
829
  import { lowerCase } from 'bguard/string/lowerCase';
@@ -740,7 +840,7 @@ import { lowerCase } from 'bguard/string/lowerCase';
740
840
  * _See_ Error Translation Key = 's:lowerCase'
741
841
 
742
842
 
743
- ##### maxLength (string) {#assert_maxLength_string}
843
+ ##### <a id="assert_maxLength_string"> maxLength </a>
744
844
 
745
845
  ```typescript
746
846
  import { maxLength } from 'bguard/string/maxLength';
@@ -758,7 +858,7 @@ import { maxLength } from 'bguard/string/maxLength';
758
858
  * _See_ Error Translation Key = 's:maxLength'
759
859
 
760
860
 
761
- ##### minLength (string) {#assert_minLength_string}
861
+ ##### <a id="assert_minLength_string"> minLength </a>
762
862
 
763
863
  ```typescript
764
864
  import { minLength } from 'bguard/string/minLength';
@@ -776,7 +876,7 @@ import { minLength } from 'bguard/string/minLength';
776
876
  * _See_ Error Translation Key = 's:minLength'
777
877
 
778
878
 
779
- ##### regExp (string) {#assert_regExp_string}
879
+ ##### <a id="assert_regExp_string"> regExp </a>
780
880
 
781
881
  ```typescript
782
882
  import { regExp } from 'bguard/string/regExp';
@@ -794,7 +894,7 @@ import { regExp } from 'bguard/string/regExp';
794
894
  * _See_ Error Translation Key = 's:regExp'
795
895
 
796
896
 
797
- ##### startsWith (string) {#assert_startsWith_string}
897
+ ##### <a id="assert_startsWith_string"> startsWith </a>
798
898
 
799
899
  ```typescript
800
900
  import { startsWith } from 'bguard/string/startsWith';
@@ -812,7 +912,7 @@ import { startsWith } from 'bguard/string/startsWith';
812
912
  * _See_ Error Translation Key = 's:startsWith'
813
913
 
814
914
 
815
- ##### upperCase (string) {#assert_upperCase_string}
915
+ ##### <a id="assert_upperCase_string"> upperCase </a>
816
916
 
817
917
  ```typescript
818
918
  import { upperCase } from 'bguard/string/upperCase';
@@ -830,7 +930,7 @@ import { upperCase } from 'bguard/string/upperCase';
830
930
  * _See_ Error Translation Key = 's:upperCase'
831
931
 
832
932
 
833
- ##### uuid (string) {#assert_uuid_string}
933
+ ##### <a id="assert_uuid_string"> uuid </a>
834
934
 
835
935
  ```typescript
836
936
  import { uuid } from 'bguard/string/uuid';
@@ -847,7 +947,7 @@ import { uuid } from 'bguard/string/uuid';
847
947
  * _See_ Error Translation Key = 's:uuid'
848
948
 
849
949
 
850
- ##### uuidV1 (string) {#assert_uuidV1_string}
950
+ ##### <a id="assert_uuidV1_string"> uuidV1 </a>
851
951
 
852
952
  ```typescript
853
953
  import { uuidV1 } from 'bguard/string/uuidV1';
@@ -865,7 +965,7 @@ import { uuidV1 } from 'bguard/string/uuidV1';
865
965
  * _See_ Error Translation Key = 's:uuidV1'
866
966
 
867
967
 
868
- ##### uuidV2 (string) {#assert_uuidV2_string}
968
+ ##### <a id="assert_uuidV2_string"> uuidV2 </a>
869
969
 
870
970
  ```typescript
871
971
  import { uuidV2 } from 'bguard/string/uuidV2';
@@ -883,7 +983,7 @@ import { uuidV2 } from 'bguard/string/uuidV2';
883
983
  * _See_ Error Translation Key = 's:uuidV2'
884
984
 
885
985
 
886
- ##### uuidV3 (string) {#assert_uuidV3_string}
986
+ ##### <a id="assert_uuidV3_string"> uuidV3 </a>
887
987
 
888
988
  ```typescript
889
989
  import { uuidV3 } from 'bguard/string/uuidV3';
@@ -901,7 +1001,7 @@ import { uuidV3 } from 'bguard/string/uuidV3';
901
1001
  * _See_ Error Translation Key = 's:uuidV3'
902
1002
 
903
1003
 
904
- ##### uuidV4 (string) {#assert_uuidV4_string}
1004
+ ##### <a id="assert_uuidV4_string"> uuidV4 </a>
905
1005
 
906
1006
  ```typescript
907
1007
  import { uuidV4 } from 'bguard/string/uuidV4';
@@ -921,7 +1021,7 @@ import { uuidV4 } from 'bguard/string/uuidV4';
921
1021
  * _See_ Error Translation Key = 's:uuidV4'
922
1022
 
923
1023
 
924
- ##### uuidV5 (string) {#assert_uuidV5_string}
1024
+ ##### <a id="assert_uuidV5_string"> uuidV5 </a>
925
1025
 
926
1026
  ```typescript
927
1027
  import { uuidV5 } from 'bguard/string/uuidV5';
@@ -939,7 +1039,7 @@ import { uuidV5 } from 'bguard/string/uuidV5';
939
1039
  * _See_ Error Translation Key = 's:uuidV5'
940
1040
 
941
1041
 
942
- ##### validUrl (string) {#assert_validUrl_string}
1042
+ ##### <a id="assert_validUrl_string"> validUrl </a>
943
1043
 
944
1044
  ```typescript
945
1045
  import { validUrl } from 'bguard/string/validUrl';
@@ -958,7 +1058,7 @@ import { validUrl } from 'bguard/string/validUrl';
958
1058
  ```
959
1059
  * _See_ Error Translation Key = 's:url'
960
1060
 
961
- #### number {#assertdir_number}
1061
+ #### <a id="assertdir_number"> number </a>
962
1062
 
963
1063
  <b>Prerequisites</b>
964
1064
 
@@ -975,7 +1075,7 @@ import { number } from 'bguard/number';
975
1075
  ```
976
1076
 
977
1077
 
978
- ##### max (number) {#assert_max_number}
1078
+ ##### <a id="assert_max_number"> max </a>
979
1079
 
980
1080
  ```typescript
981
1081
  import { max } from 'bguard/number/max';
@@ -994,7 +1094,7 @@ import { max } from 'bguard/number/max';
994
1094
  * _See_ Error Translation Key = 'n:max'
995
1095
 
996
1096
 
997
- ##### maxExcluded (number) {#assert_maxExcluded_number}
1097
+ ##### <a id="assert_maxExcluded_number"> maxExcluded </a>
998
1098
 
999
1099
  ```typescript
1000
1100
  import { maxExcluded } from 'bguard/number/maxExcluded';
@@ -1013,7 +1113,7 @@ import { maxExcluded } from 'bguard/number/maxExcluded';
1013
1113
  * _See_ Error Translation Key = 'n:maxExcluded'
1014
1114
 
1015
1115
 
1016
- ##### min (number) {#assert_min_number}
1116
+ ##### <a id="assert_min_number"> min </a>
1017
1117
 
1018
1118
  ```typescript
1019
1119
  import { min } from 'bguard/number/min';
@@ -1032,7 +1132,7 @@ import { min } from 'bguard/number/min';
1032
1132
  * _See_ Error Translation Key = 'n:min'
1033
1133
 
1034
1134
 
1035
- ##### minExcluded (number) {#assert_minExcluded_number}
1135
+ ##### <a id="assert_minExcluded_number"> minExcluded </a>
1036
1136
 
1037
1137
  ```typescript
1038
1138
  import { minExcluded } from 'bguard/number/minExcluded';
@@ -1051,7 +1151,7 @@ import { minExcluded } from 'bguard/number/minExcluded';
1051
1151
  * _See_ Error Translation Key = 'n:minExcluded'
1052
1152
 
1053
1153
 
1054
- ##### negative (number) {#assert_negative_number}
1154
+ ##### <a id="assert_negative_number"> negative </a>
1055
1155
 
1056
1156
  ```typescript
1057
1157
  import { negative } from 'bguard/number/negative';
@@ -1069,7 +1169,7 @@ import { negative } from 'bguard/number/negative';
1069
1169
  * _See_ - Error Translation Key = 'n:negative'
1070
1170
 
1071
1171
 
1072
- ##### positive (number) {#assert_positive_number}
1172
+ ##### <a id="assert_positive_number"> positive </a>
1073
1173
 
1074
1174
  ```typescript
1075
1175
  import { positive } from 'bguard/number/positive';
@@ -1086,7 +1186,7 @@ import { positive } from 'bguard/number/positive';
1086
1186
  ```
1087
1187
  * _See_ Error Translation Key = 'n:positive'
1088
1188
 
1089
- #### array {#assertdir_array}
1189
+ #### <a id="assertdir_array"> array </a>
1090
1190
 
1091
1191
  <b>Prerequisites</b>
1092
1192
 
@@ -1105,7 +1205,7 @@ import { array } from 'bguard/array';
1105
1205
  ```
1106
1206
 
1107
1207
 
1108
- ##### maxArrayLength (array) {#assert_maxArrayLength_array}
1208
+ ##### <a id="assert_maxArrayLength_array"> maxArrayLength </a>
1109
1209
 
1110
1210
  ```typescript
1111
1211
  import { maxArrayLength } from 'bguard/array/maxArrayLength';
@@ -1124,7 +1224,7 @@ import { maxArrayLength } from 'bguard/array/maxArrayLength';
1124
1224
  * _See_ Error Translation Key = 'a:maxArrayLength'
1125
1225
 
1126
1226
 
1127
- ##### minArrayLength (array) {#assert_minArrayLength_array}
1227
+ ##### <a id="assert_minArrayLength_array"> minArrayLength </a>
1128
1228
 
1129
1229
  ```typescript
1130
1230
  import { minArrayLength } from 'bguard/array/minArrayLength';
@@ -1142,7 +1242,7 @@ import { minArrayLength } from 'bguard/array/minArrayLength';
1142
1242
  ```
1143
1243
  * _See_ Error Translation Key = 'a:minArrayLength'
1144
1244
 
1145
- #### bigint {#assertdir_bigint}
1245
+ #### <a id="assertdir_bigint"> bigint </a>
1146
1246
 
1147
1247
  <b>Prerequisites</b>
1148
1248
 
@@ -1160,7 +1260,7 @@ import { bigint } from 'bguard/bigint';
1160
1260
  ```
1161
1261
 
1162
1262
 
1163
- ##### bigintMax (bigint) {#assert_bigintMax_bigint}
1263
+ ##### <a id="assert_bigintMax_bigint"> bigintMax </a>
1164
1264
 
1165
1265
  ```typescript
1166
1266
  import { bigintMax } from 'bguard/bigint/bigintMax';
@@ -1179,7 +1279,7 @@ import { bigintMax } from 'bguard/bigint/bigintMax';
1179
1279
  * _See_ Error Translation Key = 'bi:max'
1180
1280
 
1181
1281
 
1182
- ##### bigintMaxExcluded (bigint) {#assert_bigintMaxExcluded_bigint}
1282
+ ##### <a id="assert_bigintMaxExcluded_bigint"> bigintMaxExcluded </a>
1183
1283
 
1184
1284
  ```typescript
1185
1285
  import { bigintMaxExcluded } from 'bguard/bigint/bigintMaxExcluded';
@@ -1198,7 +1298,7 @@ import { bigintMaxExcluded } from 'bguard/bigint/bigintMaxExcluded';
1198
1298
  * _See_ Error Translation Key = 'bi:maxExcluded'
1199
1299
 
1200
1300
 
1201
- ##### bigintMin (bigint) {#assert_bigintMin_bigint}
1301
+ ##### <a id="assert_bigintMin_bigint"> bigintMin </a>
1202
1302
 
1203
1303
  ```typescript
1204
1304
  import { bigintMin } from 'bguard/bigint/bigintMin';
@@ -1217,7 +1317,7 @@ import { bigintMin } from 'bguard/bigint/bigintMin';
1217
1317
  * _See_ Error Translation Key = 'bi:min'
1218
1318
 
1219
1319
 
1220
- ##### bigintMinExcluded (bigint) {#assert_bigintMinExcluded_bigint}
1320
+ ##### <a id="assert_bigintMinExcluded_bigint"> bigintMinExcluded </a>
1221
1321
 
1222
1322
  ```typescript
1223
1323
  import { bigintMinExcluded } from 'bguard/bigint/bigintMinExcluded';
@@ -1235,7 +1335,7 @@ import { bigintMinExcluded } from 'bguard/bigint/bigintMinExcluded';
1235
1335
  ```
1236
1336
  * _See_ Error Translation Key = 'bi:minExcluded'
1237
1337
 
1238
- #### date {#assertdir_date}
1338
+ #### <a id="assertdir_date"> date </a>
1239
1339
 
1240
1340
  <b>Prerequisites</b>
1241
1341
 
@@ -1252,7 +1352,7 @@ import { date } from 'bguard/date';
1252
1352
  ```
1253
1353
 
1254
1354
 
1255
- ##### dateMax (date) {#assert_dateMax_date}
1355
+ ##### <a id="assert_dateMax_date"> dateMax </a>
1256
1356
 
1257
1357
  ```typescript
1258
1358
  import { dateMax } from 'bguard/date/dateMax';
@@ -1271,7 +1371,7 @@ import { dateMax } from 'bguard/date/dateMax';
1271
1371
  * _See_ Error Translation Key = 'dt:max'
1272
1372
 
1273
1373
 
1274
- ##### dateMin (date) {#assert_dateMin_date}
1374
+ ##### <a id="assert_dateMin_date"> dateMin </a>
1275
1375
 
1276
1376
  ```typescript
1277
1377
  import { dateMin } from 'bguard/date/dateMin';
@@ -1289,7 +1389,7 @@ import { dateMin } from 'bguard/date/dateMin';
1289
1389
  ```
1290
1390
  * _See_ Error Translation Key = 'dt:min'
1291
1391
 
1292
- #### mix {#assertdir_mix}
1392
+ #### <a id="assertdir_mix"> mix </a>
1293
1393
 
1294
1394
  <b>Prerequisites</b>
1295
1395
 
@@ -1310,7 +1410,7 @@ import { oneOfTypes } from 'bguard/mix';
1310
1410
  ```
1311
1411
 
1312
1412
 
1313
- ##### equalTo (mix) {#assert_equalTo_mix}
1413
+ ##### <a id="assert_equalTo_mix"> equalTo </a>
1314
1414
 
1315
1415
  ```typescript
1316
1416
  import { equalTo } from 'bguard/mix/equalTo';
@@ -1329,7 +1429,7 @@ import { equalTo } from 'bguard/mix/equalTo';
1329
1429
  * _See_ Error Translation Key = 'm:equalTo'
1330
1430
 
1331
1431
 
1332
- ##### oneOfValues (mix) {#assert_oneOfValues_mix}
1432
+ ##### <a id="assert_oneOfValues_mix"> oneOfValues </a>
1333
1433
 
1334
1434
  ```typescript
1335
1435
  import { oneOfValues } from 'bguard/mix/oneOfValues';
@@ -1348,5 +1448,53 @@ import { oneOfValues } from 'bguard/mix/oneOfValues';
1348
1448
  ```
1349
1449
  * _See_ Error Translation Key = 'm:oneOfValues'
1350
1450
 
1451
+ #### <a id="assertdir_object"> object </a>
1452
+
1453
+ <b>Prerequisites</b>
1454
+
1455
+ ```typescript
1456
+ import { object } from 'bguard/object';
1457
+ ```
1458
+
1459
+ * _Description_ Creates a new schema for validating objects where each property must match the specified schema.
1460
+
1461
+ * _Param_ {T} shapeSchema - The schema that each property of the object must match.
1462
+ * _Example_
1463
+ ```typescript
1464
+ const schema = object({
1465
+ name: string(),
1466
+ age: number()
1467
+ });
1468
+ parseOrFail(schema, { name: 'John', age: 30 }); // Validates successfully
1469
+ parseOrFail(schema, { name: 'John', age: '30' }); // Throws a validation error
1470
+ ```
1471
+
1472
+
1473
+ ##### <a id="assert_maxKeys_object"> maxKeys </a>
1474
+
1475
+ ```typescript
1476
+ import { maxKeys } from 'bguard/object/maxKeys';
1477
+ ```
1478
+
1479
+ * _Description_ Ensures that the object has no more than the specified number of keys.
1480
+ * _Param_ {number} expected - The maximum number of keys allowed in the object.
1481
+ * _Throws_ {ValidationError} if the number of the received keys is greater than the expected value.
1482
+ * _Example_
1483
+ ```typescript
1484
+ const schema = object({
1485
+ name: string(),
1486
+ email: string(),
1487
+ })
1488
+ .allowUnrecognized()
1489
+ .custom(maxKeys(2));
1490
+
1491
+ // This will pass
1492
+ parseOrFail(schema, { name: 'John', email: 'john@example.com' });
1493
+
1494
+ // This will throw an error because there are 3 keys
1495
+ parseOrFail(schema, { name: 'John', email: 'john@example.com', address: '123 Main St' });
1496
+ ```
1497
+ * _See_ Error Translation Key = 'o:maxKeys'
1498
+
1351
1499
  ### Contributing
1352
- Contributions are welcome! Please open an issue or submit a pull request for any bugs or feature requests.
1500
+ Contributions are welcome! Please open an issue or submit a pull request for any bugs or feature requests.