@oxog/vld 2.0.3 → 2.1.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 (449) hide show
  1. package/CHANGELOG.md +33 -1
  2. package/README.md +101 -37
  3. package/dist/chunks/errors-core-BeiFUtZM.js +81 -0
  4. package/dist/chunks/{index-DO8CFMxD.js → index-0R2ntSud.js} +16 -402
  5. package/dist/chunks/index-BvH403Yy.js +88 -0
  6. package/dist/chunks/security-B0Pd_vSY.js +35 -0
  7. package/dist/chunks/string-BJRQod3t.js +530 -0
  8. package/dist/cjs/chunks/errors-core-DWxLFs2f.cjs +83 -0
  9. package/dist/cjs/chunks/index-BkI37108.cjs +538 -0
  10. package/dist/cjs/chunks/index-Cc3bjUMX.cjs +91 -0
  11. package/dist/cjs/chunks/security-Dc3Jh13T.cjs +37 -0
  12. package/dist/cjs/chunks/string-BKZrc4hs.cjs +533 -0
  13. package/dist/cjs/cli/bin.cjs +506 -0
  14. package/dist/cjs/cli/index.cjs +209 -0
  15. package/dist/cjs/codecs/index.cjs +45 -0
  16. package/dist/{chunks/date-50JV_Mfj.js → cjs/coercion/index.cjs} +185 -103
  17. package/dist/cjs/compat/emitter.cjs +184 -0
  18. package/dist/cjs/compat/result.cjs +189 -0
  19. package/dist/cjs/errors.cjs +6 -213
  20. package/dist/cjs/index.cjs +1471 -10336
  21. package/dist/cjs/kernel.cjs +415 -0
  22. package/dist/cjs/locales/af.cjs +108 -0
  23. package/dist/cjs/locales/ar.cjs +108 -0
  24. package/dist/cjs/locales/bn.cjs +108 -0
  25. package/dist/cjs/locales/da.cjs +108 -0
  26. package/dist/cjs/locales/de.cjs +108 -0
  27. package/dist/cjs/locales/en.cjs +108 -0
  28. package/dist/cjs/locales/es-MX.cjs +107 -0
  29. package/dist/cjs/locales/es.cjs +96 -0
  30. package/dist/cjs/locales/fi.cjs +108 -0
  31. package/dist/cjs/locales/fr.cjs +96 -0
  32. package/dist/cjs/locales/hi.cjs +108 -0
  33. package/dist/cjs/locales/id.cjs +108 -0
  34. package/dist/cjs/locales/index.cjs +41 -2875
  35. package/dist/cjs/locales/it.cjs +108 -0
  36. package/dist/cjs/locales/ja.cjs +108 -0
  37. package/dist/cjs/locales/ko.cjs +108 -0
  38. package/dist/cjs/locales/lazy.cjs +42 -3023
  39. package/dist/cjs/locales/nl.cjs +108 -0
  40. package/dist/cjs/locales/no.cjs +108 -0
  41. package/dist/cjs/locales/pl.cjs +108 -0
  42. package/dist/cjs/locales/pt-BR.cjs +108 -0
  43. package/dist/cjs/locales/pt.cjs +108 -0
  44. package/dist/cjs/locales/ru.cjs +108 -0
  45. package/dist/cjs/locales/runtime.cjs +51 -0
  46. package/dist/cjs/locales/sv.cjs +108 -0
  47. package/dist/cjs/locales/sw.cjs +108 -0
  48. package/dist/cjs/locales/th.cjs +108 -0
  49. package/dist/cjs/locales/tr.cjs +108 -0
  50. package/dist/cjs/locales/vi.cjs +108 -0
  51. package/dist/cjs/locales/zh.cjs +108 -0
  52. package/dist/cjs/mini.cjs +121 -7353
  53. package/dist/cjs/pigment.cjs +207 -0
  54. package/dist/cjs/plugins/index.cjs +12 -0
  55. package/dist/cjs/registry.cjs +37 -0
  56. package/dist/cjs/v3/index.cjs +425 -0
  57. package/dist/cjs/v4/core/index.cjs +894 -0
  58. package/dist/cjs/v4/index.cjs +425 -0
  59. package/dist/cjs/v4/locales/index.cjs +130 -0
  60. package/dist/cjs/v4/mini/index.cjs +509 -0
  61. package/dist/cjs/v4-mini/index.cjs +532 -0
  62. package/dist/cjs/validators/any.cjs +40 -0
  63. package/dist/cjs/validators/array.cjs +283 -0
  64. package/dist/cjs/validators/base.cjs +887 -0
  65. package/dist/cjs/validators/base64.cjs +73 -0
  66. package/dist/cjs/validators/bigint.cjs +232 -0
  67. package/dist/cjs/validators/boolean.cjs +146 -0
  68. package/dist/cjs/validators/codec.cjs +205 -0
  69. package/dist/cjs/validators/custom.cjs +71 -0
  70. package/dist/cjs/validators/date.cjs +278 -0
  71. package/dist/cjs/validators/discriminated-union.cjs +130 -0
  72. package/dist/cjs/validators/enum.cjs +154 -0
  73. package/dist/cjs/validators/file.cjs +130 -0
  74. package/dist/cjs/validators/function.cjs +63 -0
  75. package/dist/cjs/validators/hex.cjs +70 -0
  76. package/dist/cjs/validators/index.cjs +123 -0
  77. package/dist/cjs/validators/intersection.cjs +120 -0
  78. package/dist/cjs/validators/json.cjs +70 -0
  79. package/dist/cjs/validators/lazy.cjs +53 -0
  80. package/dist/cjs/validators/literal.cjs +64 -0
  81. package/dist/cjs/validators/map.cjs +218 -0
  82. package/dist/cjs/validators/nan.cjs +41 -0
  83. package/dist/cjs/validators/never.cjs +36 -0
  84. package/dist/cjs/validators/null.cjs +43 -0
  85. package/dist/cjs/validators/number.cjs +427 -0
  86. package/dist/cjs/validators/object.cjs +868 -0
  87. package/dist/cjs/validators/promise.cjs +115 -0
  88. package/dist/cjs/validators/record.cjs +262 -0
  89. package/dist/cjs/validators/set.cjs +203 -0
  90. package/dist/cjs/validators/string-bool.cjs +124 -0
  91. package/dist/cjs/validators/string-formats.cjs +168 -0
  92. package/dist/cjs/validators/string.cjs +12 -0
  93. package/dist/cjs/validators/symbol.cjs +62 -0
  94. package/dist/cjs/validators/template-literal.cjs +108 -0
  95. package/dist/cjs/validators/tuple.cjs +187 -0
  96. package/dist/cjs/validators/uint8array.cjs +106 -0
  97. package/dist/cjs/validators/undefined.cjs +43 -0
  98. package/dist/cjs/validators/union.cjs +191 -0
  99. package/dist/cjs/validators/unknown.cjs +40 -0
  100. package/dist/cjs/validators/void.cjs +48 -0
  101. package/dist/cjs/validators/xor.cjs +69 -0
  102. package/dist/cli/bin.d.ts +0 -1
  103. package/dist/cli/bin.js +407 -0
  104. package/dist/cli/commands/benchmark.d.ts +1 -2
  105. package/dist/cli/commands/validate.d.ts +1 -2
  106. package/dist/cli/index.d.ts +0 -1
  107. package/dist/cli/index.js +205 -0
  108. package/dist/codecs/index.d.ts +21 -4
  109. package/dist/codecs/index.js +11 -4
  110. package/dist/coercion/bigint.d.ts +2 -3
  111. package/dist/coercion/boolean.d.ts +3 -3
  112. package/dist/coercion/date.d.ts +3 -3
  113. package/dist/coercion/index.d.ts +5 -6
  114. package/dist/coercion/index.js +473 -5
  115. package/dist/coercion/number.d.ts +2 -3
  116. package/dist/coercion/string.d.ts +2 -3
  117. package/dist/compat/emitter.d.ts +0 -1
  118. package/dist/compat/emitter.js +0 -1
  119. package/dist/compat/index.d.ts +4 -5
  120. package/dist/compat/result.d.ts +1 -2
  121. package/dist/compat/result.js +0 -1
  122. package/dist/errors-core.d.ts +39 -0
  123. package/dist/errors.d.ts +4 -54
  124. package/dist/errors.js +4 -68
  125. package/dist/events.d.ts +3 -4
  126. package/dist/index.d.ts +1186 -835
  127. package/dist/index.js +1046 -367
  128. package/dist/kernel.d.ts +2 -3
  129. package/dist/kernel.js +10 -6
  130. package/dist/locales/af.d.ts +1 -2
  131. package/dist/locales/af.js +0 -1
  132. package/dist/locales/ar.d.ts +1 -2
  133. package/dist/locales/ar.js +0 -1
  134. package/dist/locales/bn.d.ts +1 -2
  135. package/dist/locales/bn.js +0 -1
  136. package/dist/locales/da.d.ts +1 -2
  137. package/dist/locales/da.js +0 -1
  138. package/dist/locales/de.d.ts +1 -2
  139. package/dist/locales/de.js +0 -1
  140. package/dist/locales/en.d.ts +1 -2
  141. package/dist/locales/en.js +0 -1
  142. package/dist/locales/es-MX.d.ts +1 -2
  143. package/dist/locales/es-MX.js +0 -1
  144. package/dist/locales/es.d.ts +1 -2
  145. package/dist/locales/es.js +0 -1
  146. package/dist/locales/fi.d.ts +1 -2
  147. package/dist/locales/fi.js +0 -1
  148. package/dist/locales/fr.d.ts +1 -2
  149. package/dist/locales/fr.js +0 -1
  150. package/dist/locales/hi.d.ts +1 -2
  151. package/dist/locales/hi.js +0 -1
  152. package/dist/locales/id.d.ts +1 -2
  153. package/dist/locales/id.js +0 -1
  154. package/dist/locales/index.d.ts +10 -15
  155. package/dist/locales/index.js +28 -2
  156. package/dist/locales/it.d.ts +1 -2
  157. package/dist/locales/it.js +0 -1
  158. package/dist/locales/ja.d.ts +1 -2
  159. package/dist/locales/ja.js +0 -1
  160. package/dist/locales/ko.d.ts +1 -2
  161. package/dist/locales/ko.js +0 -1
  162. package/dist/locales/lazy.d.ts +4 -26
  163. package/dist/locales/lazy.js +12 -55
  164. package/dist/locales/nl.d.ts +1 -2
  165. package/dist/locales/nl.js +0 -1
  166. package/dist/locales/no.d.ts +1 -2
  167. package/dist/locales/no.js +0 -1
  168. package/dist/locales/pl.d.ts +1 -2
  169. package/dist/locales/pl.js +0 -1
  170. package/dist/locales/pt-BR.d.ts +1 -2
  171. package/dist/locales/pt-BR.js +0 -1
  172. package/dist/locales/pt.d.ts +1 -2
  173. package/dist/locales/pt.js +0 -1
  174. package/dist/locales/ru.d.ts +1 -2
  175. package/dist/locales/ru.js +0 -1
  176. package/dist/locales/runtime.d.ts +10 -0
  177. package/dist/locales/runtime.js +41 -0
  178. package/dist/locales/sv.d.ts +1 -2
  179. package/dist/locales/sv.js +0 -1
  180. package/dist/locales/sw.d.ts +1 -2
  181. package/dist/locales/sw.js +0 -1
  182. package/dist/locales/th.d.ts +1 -2
  183. package/dist/locales/th.js +0 -1
  184. package/dist/locales/tr.d.ts +1 -2
  185. package/dist/locales/tr.js +0 -1
  186. package/dist/locales/types.d.ts +0 -1
  187. package/dist/locales/vi.d.ts +1 -2
  188. package/dist/locales/vi.js +0 -1
  189. package/dist/locales/zh.d.ts +1 -2
  190. package/dist/locales/zh.js +0 -1
  191. package/dist/logger.d.ts +0 -1
  192. package/dist/mini.d.ts +64 -65
  193. package/dist/mini.js +31 -7
  194. package/dist/pigment.d.ts +0 -1
  195. package/dist/pigment.js +6 -4
  196. package/dist/plugins/index.d.ts +2 -3
  197. package/dist/plugins/index.js +1 -0
  198. package/dist/plugins/types.d.ts +4 -5
  199. package/dist/registry.d.ts +23 -0
  200. package/dist/registry.js +34 -0
  201. package/dist/utils/codec-utils.d.ts +0 -1
  202. package/dist/utils/deep-merge.d.ts +0 -1
  203. package/dist/utils/ip-validation.d.ts +0 -1
  204. package/dist/utils/json-schema.d.ts +16 -6
  205. package/dist/utils/security.d.ts +2 -6
  206. package/dist/v3/index.d.ts +2 -0
  207. package/dist/v3/index.js +46 -0
  208. package/dist/v4/core/index.d.ts +260 -0
  209. package/dist/v4/core/index.js +277 -0
  210. package/dist/v4/index.d.ts +4 -0
  211. package/dist/v4/index.js +50 -0
  212. package/dist/v4/locales/index.d.ts +53 -0
  213. package/dist/v4/locales/index.js +77 -0
  214. package/dist/v4/mini/index.d.ts +2 -0
  215. package/dist/v4/mini/index.js +47 -0
  216. package/dist/v4-mini/index.d.ts +22 -0
  217. package/dist/v4-mini/index.js +75 -0
  218. package/dist/validators/any.d.ts +7 -2
  219. package/dist/validators/any.js +37 -0
  220. package/dist/validators/array.d.ts +9 -2
  221. package/dist/validators/array.js +279 -0
  222. package/dist/validators/base.d.ts +150 -6
  223. package/dist/validators/base.js +868 -0
  224. package/dist/validators/base64.d.ts +1 -2
  225. package/dist/validators/base64.js +68 -0
  226. package/dist/validators/bigint.d.ts +21 -3
  227. package/dist/validators/bigint.js +228 -0
  228. package/dist/validators/boolean.d.ts +13 -4
  229. package/dist/validators/boolean.js +142 -0
  230. package/dist/validators/codec.d.ts +9 -2
  231. package/dist/validators/codec.js +200 -0
  232. package/dist/validators/custom.d.ts +15 -2
  233. package/dist/validators/custom.js +67 -0
  234. package/dist/validators/date.d.ts +19 -3
  235. package/dist/validators/date.js +274 -0
  236. package/dist/validators/discriminated-union.d.ts +4 -3
  237. package/dist/validators/discriminated-union.js +123 -0
  238. package/dist/validators/enum.d.ts +10 -7
  239. package/dist/validators/enum.js +150 -0
  240. package/dist/validators/file.d.ts +7 -2
  241. package/dist/validators/file.js +125 -0
  242. package/dist/validators/function.d.ts +11 -5
  243. package/dist/validators/function.js +58 -0
  244. package/dist/validators/hex.d.ts +1 -2
  245. package/dist/validators/hex.js +65 -0
  246. package/dist/validators/index.d.ts +38 -39
  247. package/dist/validators/index.js +35 -515
  248. package/dist/validators/intersection.d.ts +1 -2
  249. package/dist/validators/intersection.js +116 -0
  250. package/dist/validators/json.d.ts +1 -2
  251. package/dist/validators/json.js +66 -0
  252. package/dist/validators/lazy.d.ts +5 -9
  253. package/dist/validators/lazy.js +50 -0
  254. package/dist/validators/literal.d.ts +2 -2
  255. package/dist/validators/literal.js +60 -0
  256. package/dist/validators/map.d.ts +15 -2
  257. package/dist/validators/map.js +214 -0
  258. package/dist/validators/nan.d.ts +2 -3
  259. package/dist/validators/nan.js +38 -0
  260. package/dist/validators/never.d.ts +1 -2
  261. package/dist/validators/never.js +32 -0
  262. package/dist/validators/null.d.ts +3 -3
  263. package/dist/validators/null.js +40 -0
  264. package/dist/validators/number.d.ts +56 -27
  265. package/dist/validators/number.js +423 -0
  266. package/dist/validators/object.d.ts +30 -9
  267. package/dist/validators/object.js +864 -0
  268. package/dist/validators/promise.d.ts +15 -10
  269. package/dist/validators/promise.js +111 -0
  270. package/dist/validators/record.d.ts +11 -2
  271. package/dist/validators/record.js +258 -0
  272. package/dist/validators/set.d.ts +11 -2
  273. package/dist/validators/set.js +199 -0
  274. package/dist/validators/string-bool.d.ts +7 -10
  275. package/dist/validators/string-bool.js +120 -0
  276. package/dist/validators/string-formats.d.ts +7 -4
  277. package/dist/validators/string-formats.js +135 -0
  278. package/dist/validators/string.d.ts +39 -18
  279. package/dist/validators/string.js +4 -0
  280. package/dist/validators/symbol.d.ts +8 -3
  281. package/dist/validators/symbol.js +58 -0
  282. package/dist/validators/template-literal.d.ts +1 -2
  283. package/dist/validators/template-literal.js +103 -0
  284. package/dist/validators/tuple.d.ts +15 -2
  285. package/dist/validators/tuple.js +183 -0
  286. package/dist/validators/uint8array.d.ts +3 -4
  287. package/dist/validators/uint8array.js +101 -0
  288. package/dist/validators/undefined.d.ts +3 -3
  289. package/dist/validators/undefined.js +40 -0
  290. package/dist/validators/union.d.ts +7 -4
  291. package/dist/validators/union.js +187 -0
  292. package/dist/validators/unknown.d.ts +7 -2
  293. package/dist/{chunks/unknown-Dhzri_T-.js → validators/unknown.js} +12 -3
  294. package/dist/validators/void.d.ts +3 -2
  295. package/dist/validators/void.js +44 -0
  296. package/dist/validators/xor.d.ts +2 -3
  297. package/dist/validators/xor.js +66 -0
  298. package/package.json +114 -30
  299. package/dist/chunks/bigint-CRS0QVsy.js +0 -1854
  300. package/dist/chunks/bigint-CRS0QVsy.js.map +0 -1
  301. package/dist/chunks/date-50JV_Mfj.js.map +0 -1
  302. package/dist/chunks/index-DO8CFMxD.js.map +0 -1
  303. package/dist/chunks/json-Cp4WO0M9.js +0 -2021
  304. package/dist/chunks/json-Cp4WO0M9.js.map +0 -1
  305. package/dist/chunks/unknown-Dhzri_T-.js.map +0 -1
  306. package/dist/cjs/errors.cjs.map +0 -1
  307. package/dist/cjs/index.cjs.map +0 -1
  308. package/dist/cjs/locales/index.cjs.map +0 -1
  309. package/dist/cjs/locales/lazy.cjs.map +0 -1
  310. package/dist/cjs/mini.cjs.map +0 -1
  311. package/dist/cli/bin.d.ts.map +0 -1
  312. package/dist/cli/commands/benchmark.d.ts.map +0 -1
  313. package/dist/cli/commands/validate.d.ts.map +0 -1
  314. package/dist/cli/index.d.ts.map +0 -1
  315. package/dist/codecs/index.d.ts.map +0 -1
  316. package/dist/codecs/index.js.map +0 -1
  317. package/dist/coercion/bigint.d.ts.map +0 -1
  318. package/dist/coercion/boolean.d.ts.map +0 -1
  319. package/dist/coercion/date.d.ts.map +0 -1
  320. package/dist/coercion/index.d.ts.map +0 -1
  321. package/dist/coercion/index.js.map +0 -1
  322. package/dist/coercion/number.d.ts.map +0 -1
  323. package/dist/coercion/string.d.ts.map +0 -1
  324. package/dist/compat/emitter.d.ts.map +0 -1
  325. package/dist/compat/emitter.js.map +0 -1
  326. package/dist/compat/index.d.ts.map +0 -1
  327. package/dist/compat/result.d.ts.map +0 -1
  328. package/dist/compat/result.js.map +0 -1
  329. package/dist/errors.d.ts.map +0 -1
  330. package/dist/errors.js.map +0 -1
  331. package/dist/events.d.ts.map +0 -1
  332. package/dist/index.d.ts.map +0 -1
  333. package/dist/index.js.map +0 -1
  334. package/dist/kernel.d.ts.map +0 -1
  335. package/dist/kernel.js.map +0 -1
  336. package/dist/locales/af.d.ts.map +0 -1
  337. package/dist/locales/af.js.map +0 -1
  338. package/dist/locales/ar.d.ts.map +0 -1
  339. package/dist/locales/ar.js.map +0 -1
  340. package/dist/locales/backup-en.d.ts +0 -3
  341. package/dist/locales/backup-en.d.ts.map +0 -1
  342. package/dist/locales/bn.d.ts.map +0 -1
  343. package/dist/locales/bn.js.map +0 -1
  344. package/dist/locales/da.d.ts.map +0 -1
  345. package/dist/locales/da.js.map +0 -1
  346. package/dist/locales/de.d.ts.map +0 -1
  347. package/dist/locales/de.js.map +0 -1
  348. package/dist/locales/en.d.ts.map +0 -1
  349. package/dist/locales/en.js.map +0 -1
  350. package/dist/locales/es-MX.d.ts.map +0 -1
  351. package/dist/locales/es-MX.js.map +0 -1
  352. package/dist/locales/es.d.ts.map +0 -1
  353. package/dist/locales/es.js.map +0 -1
  354. package/dist/locales/fi.d.ts.map +0 -1
  355. package/dist/locales/fi.js.map +0 -1
  356. package/dist/locales/fr.d.ts.map +0 -1
  357. package/dist/locales/fr.js.map +0 -1
  358. package/dist/locales/hi.d.ts.map +0 -1
  359. package/dist/locales/hi.js.map +0 -1
  360. package/dist/locales/id.d.ts.map +0 -1
  361. package/dist/locales/id.js.map +0 -1
  362. package/dist/locales/index.d.ts.map +0 -1
  363. package/dist/locales/index.js.map +0 -1
  364. package/dist/locales/it.d.ts.map +0 -1
  365. package/dist/locales/it.js.map +0 -1
  366. package/dist/locales/ja.d.ts.map +0 -1
  367. package/dist/locales/ja.js.map +0 -1
  368. package/dist/locales/ko.d.ts.map +0 -1
  369. package/dist/locales/ko.js.map +0 -1
  370. package/dist/locales/lazy.d.ts.map +0 -1
  371. package/dist/locales/lazy.js.map +0 -1
  372. package/dist/locales/nl.d.ts.map +0 -1
  373. package/dist/locales/nl.js.map +0 -1
  374. package/dist/locales/no.d.ts.map +0 -1
  375. package/dist/locales/no.js.map +0 -1
  376. package/dist/locales/pl.d.ts.map +0 -1
  377. package/dist/locales/pl.js.map +0 -1
  378. package/dist/locales/pt-BR.d.ts.map +0 -1
  379. package/dist/locales/pt-BR.js.map +0 -1
  380. package/dist/locales/pt.d.ts.map +0 -1
  381. package/dist/locales/pt.js.map +0 -1
  382. package/dist/locales/ru.d.ts.map +0 -1
  383. package/dist/locales/ru.js.map +0 -1
  384. package/dist/locales/sv.d.ts.map +0 -1
  385. package/dist/locales/sv.js.map +0 -1
  386. package/dist/locales/sw.d.ts.map +0 -1
  387. package/dist/locales/sw.js.map +0 -1
  388. package/dist/locales/th.d.ts.map +0 -1
  389. package/dist/locales/th.js.map +0 -1
  390. package/dist/locales/tr.d.ts.map +0 -1
  391. package/dist/locales/tr.js.map +0 -1
  392. package/dist/locales/types.d.ts.map +0 -1
  393. package/dist/locales/vi.d.ts.map +0 -1
  394. package/dist/locales/vi.js.map +0 -1
  395. package/dist/locales/zh.d.ts.map +0 -1
  396. package/dist/locales/zh.js.map +0 -1
  397. package/dist/logger.d.ts.map +0 -1
  398. package/dist/mini.d.ts.map +0 -1
  399. package/dist/mini.js.map +0 -1
  400. package/dist/pigment.d.ts.map +0 -1
  401. package/dist/pigment.js.map +0 -1
  402. package/dist/plugins/index.d.ts.map +0 -1
  403. package/dist/plugins/types.d.ts.map +0 -1
  404. package/dist/utils/codec-utils.d.ts.map +0 -1
  405. package/dist/utils/deep-merge.d.ts.map +0 -1
  406. package/dist/utils/ip-validation.d.ts.map +0 -1
  407. package/dist/utils/json-schema.d.ts.map +0 -1
  408. package/dist/utils/security.d.ts.map +0 -1
  409. package/dist/validators/any.d.ts.map +0 -1
  410. package/dist/validators/array.d.ts.map +0 -1
  411. package/dist/validators/base.d.ts.map +0 -1
  412. package/dist/validators/base64.d.ts.map +0 -1
  413. package/dist/validators/bigint.d.ts.map +0 -1
  414. package/dist/validators/boolean.d.ts.map +0 -1
  415. package/dist/validators/codec.d.ts.map +0 -1
  416. package/dist/validators/custom.d.ts.map +0 -1
  417. package/dist/validators/date.d.ts.map +0 -1
  418. package/dist/validators/discriminated-union.d.ts.map +0 -1
  419. package/dist/validators/enum.d.ts.map +0 -1
  420. package/dist/validators/file.d.ts.map +0 -1
  421. package/dist/validators/function.d.ts.map +0 -1
  422. package/dist/validators/hex.d.ts.map +0 -1
  423. package/dist/validators/index.d.ts.map +0 -1
  424. package/dist/validators/index.js.map +0 -1
  425. package/dist/validators/intersection.d.ts.map +0 -1
  426. package/dist/validators/json.d.ts.map +0 -1
  427. package/dist/validators/lazy.d.ts.map +0 -1
  428. package/dist/validators/literal.d.ts.map +0 -1
  429. package/dist/validators/map.d.ts.map +0 -1
  430. package/dist/validators/nan.d.ts.map +0 -1
  431. package/dist/validators/never.d.ts.map +0 -1
  432. package/dist/validators/null.d.ts.map +0 -1
  433. package/dist/validators/number.d.ts.map +0 -1
  434. package/dist/validators/object.d.ts.map +0 -1
  435. package/dist/validators/promise.d.ts.map +0 -1
  436. package/dist/validators/record.d.ts.map +0 -1
  437. package/dist/validators/set.d.ts.map +0 -1
  438. package/dist/validators/string-bool.d.ts.map +0 -1
  439. package/dist/validators/string-formats.d.ts.map +0 -1
  440. package/dist/validators/string.d.ts.map +0 -1
  441. package/dist/validators/symbol.d.ts.map +0 -1
  442. package/dist/validators/template-literal.d.ts.map +0 -1
  443. package/dist/validators/tuple.d.ts.map +0 -1
  444. package/dist/validators/uint8array.d.ts.map +0 -1
  445. package/dist/validators/undefined.d.ts.map +0 -1
  446. package/dist/validators/union.d.ts.map +0 -1
  447. package/dist/validators/unknown.d.ts.map +0 -1
  448. package/dist/validators/void.d.ts.map +0 -1
  449. package/dist/validators/xor.d.ts.map +0 -1
@@ -1,1854 +0,0 @@
1
- import { en } from '../locales/en.js';
2
- import { tr } from '../locales/tr.js';
3
- import { es } from '../locales/es.js';
4
- import { fr } from '../locales/fr.js';
5
- import { de } from '../locales/de.js';
6
- import { it } from '../locales/it.js';
7
- import { pt } from '../locales/pt.js';
8
- import { ru } from '../locales/ru.js';
9
- import { ja } from '../locales/ja.js';
10
- import { ko } from '../locales/ko.js';
11
- import { zh } from '../locales/zh.js';
12
- import { ar } from '../locales/ar.js';
13
- import { hi } from '../locales/hi.js';
14
- import { nl } from '../locales/nl.js';
15
- import { pl } from '../locales/pl.js';
16
- import { da } from '../locales/da.js';
17
- import { sv } from '../locales/sv.js';
18
- import { no } from '../locales/no.js';
19
- import { fi } from '../locales/fi.js';
20
- import { th } from '../locales/th.js';
21
- import { vi } from '../locales/vi.js';
22
- import { id } from '../locales/id.js';
23
- import { bn } from '../locales/bn.js';
24
- import { sw } from '../locales/sw.js';
25
- import { af } from '../locales/af.js';
26
- import { ptBR } from '../locales/pt-BR.js';
27
- import { esMX } from '../locales/es-MX.js';
28
-
29
- /**
30
- * Abstract base class for all validators
31
- * Implements immutable pattern to prevent memory leaks and race conditions
32
- */
33
- class VldBase {
34
- /**
35
- * Check if a value is valid according to this validator
36
- * @param value The value to check
37
- * @returns True if valid, false otherwise
38
- */
39
- isValid(value) {
40
- return this.safeParse(value).success;
41
- }
42
- /**
43
- * Parse a value or return a default if validation fails
44
- * BUG-NEW-017 FIX: Validate default value to ensure type safety
45
- * @param value The value to validate
46
- * @param defaultValue The default value to return on failure
47
- * @returns The validated value or default
48
- */
49
- parseOrDefault(value, defaultValue) {
50
- const result = this.safeParse(value);
51
- if (result.success) {
52
- return result.data;
53
- }
54
- // Validate the default value to ensure it's actually valid
55
- const defaultResult = this.safeParse(defaultValue);
56
- if (!defaultResult.success) {
57
- throw new Error(`Invalid default value provided: ${defaultResult.error.message}`);
58
- }
59
- return defaultResult.data;
60
- }
61
- refine(predicate, message) {
62
- return new VldRefine(this, predicate, message);
63
- }
64
- /**
65
- * Advanced refinement with context for adding multiple issues
66
- * @param refinement The refinement function with context
67
- * @returns A new super refined validator
68
- */
69
- superRefine(refinement) {
70
- return new VldSuperRefine(this, refinement);
71
- }
72
- /**
73
- * Create a new validator that transforms the output
74
- * @param transformer The transformation function
75
- * @returns A new transformed validator
76
- */
77
- transform(transformer) {
78
- return new VldTransform(this, transformer);
79
- }
80
- /**
81
- * Create a new validator with a default value for undefined inputs
82
- * @param defaultValue The default value
83
- * @returns A new validator with default
84
- */
85
- default(defaultValue) {
86
- return new VldDefault(this, defaultValue);
87
- }
88
- /**
89
- * Create a new validator that catches errors and returns a fallback
90
- * @param fallbackValue The fallback value
91
- * @returns A new validator with catch
92
- */
93
- catch(fallbackValue) {
94
- return new VldCatch(this, fallbackValue);
95
- }
96
- /**
97
- * Make this validator optional (allows undefined)
98
- * @returns A new optional validator
99
- */
100
- optional() {
101
- return new VldOptional(this);
102
- }
103
- /**
104
- * Make this validator nullable (allows null)
105
- * @returns A new nullable validator
106
- */
107
- nullable() {
108
- return new VldNullable(this);
109
- }
110
- /**
111
- * Make this validator nullish (allows null or undefined)
112
- * @returns A new nullish validator
113
- */
114
- nullish() {
115
- return new VldNullish(this);
116
- }
117
- /**
118
- * Make this validator exactly optional - allows undefined but not missing
119
- * Unlike .optional() which treats missing as undefined, exactOptional()
120
- * requires the key to be present but allows undefined as a value
121
- * Zod 4 API parity
122
- * @returns A new exact optional validator
123
- */
124
- exactOptional() {
125
- return new VldExactOptional(this);
126
- }
127
- /**
128
- * Pipe the output of this validator into another validator
129
- * @param next The next validator to pipe into
130
- * @returns A new piped validator
131
- */
132
- pipe(next) {
133
- return new VldPipe(this, next);
134
- }
135
- /**
136
- * Create a new validator that returns readonly output
137
- * Zod 4 API parity - marks output as readonly for TypeScript
138
- * @returns A new readonly validator
139
- */
140
- readonly() {
141
- return new VldReadonly(this);
142
- }
143
- /**
144
- * Brand the output type with a unique brand for nominal typing
145
- * Zod 4 API parity - prevents accidental assignment of similarly typed values
146
- * @returns A new branded validator
147
- * @example
148
- * const userIdSchema = v.string().brand<'UserId'>();
149
- * const productIdSchema = v.string().brand<'ProductId'>();
150
- *
151
- * let userId: UserId = userIdSchema.parse('abc');
152
- * let productId: ProductId = productIdSchema.parse('xyz');
153
- *
154
- * userId = productId; // TypeScript error: types are incompatible
155
- */
156
- brand() {
157
- return new VldBrand(this);
158
- }
159
- /**
160
- * Apply an external function to transform this validator
161
- * Zod 4 API parity - allows external function chaining
162
- * @param fn External function that takes this validator and returns a new validator
163
- * @returns The result of applying the function to this validator
164
- * @example
165
- * const withLength = (schema: VldBase<unknown, string>) => schema.transform(s => s.length);
166
- * const lengthSchema = v.string().apply(withLength); // validates string, returns number
167
- */
168
- apply(fn) {
169
- return fn(this);
170
- }
171
- check(predicate, message) {
172
- return new VldRefine(this, predicate, message);
173
- }
174
- /**
175
- * Get or set metadata for this schema
176
- */
177
- meta(data) {
178
- if (data === undefined) {
179
- return undefined;
180
- }
181
- return new VldMeta(this, data);
182
- }
183
- /**
184
- * Add a description to this schema
185
- * Zod 4 API parity - convenience method for .meta({ description: ... })
186
- * @param description The description to add
187
- * @returns A new validator with the description
188
- */
189
- describe(description) {
190
- return new VldMeta(this, { description });
191
- }
192
- }
193
- /**
194
- * Metadata validator - wraps a schema with metadata
195
- */
196
- class VldMeta extends VldBase {
197
- constructor(baseValidator, metadata) {
198
- super();
199
- this.baseValidator = baseValidator;
200
- this.metadata = metadata;
201
- }
202
- parse(value) {
203
- return this.baseValidator.parse(value);
204
- }
205
- safeParse(value) {
206
- return this.baseValidator.safeParse(value);
207
- }
208
- /**
209
- * Get the metadata
210
- */
211
- getMeta() {
212
- return this.metadata;
213
- }
214
- }
215
- /**
216
- * Readonly validator - marks output as readonly
217
- */
218
- class VldReadonly extends VldBase {
219
- constructor(baseValidator) {
220
- super();
221
- this.baseValidator = baseValidator;
222
- }
223
- parse(value) {
224
- return this.baseValidator.parse(value);
225
- }
226
- safeParse(value) {
227
- const result = this.baseValidator.safeParse(value);
228
- if (result.success) {
229
- return { success: true, data: result.data };
230
- }
231
- return result;
232
- }
233
- }
234
- /**
235
- * Brand validator - adds a unique brand to the output type for nominal typing
236
- * Uses TypeScript's branded types pattern to prevent accidental assignment
237
- */
238
- class VldBrand extends VldBase {
239
- constructor(baseValidator) {
240
- super();
241
- this.baseValidator = baseValidator;
242
- }
243
- parse(value) {
244
- return this.baseValidator.parse(value);
245
- }
246
- safeParse(value) {
247
- const result = this.baseValidator.safeParse(value);
248
- if (result.success) {
249
- return {
250
- success: true,
251
- data: result.data
252
- };
253
- }
254
- return result;
255
- }
256
- }
257
- /**
258
- * Refine validator - adds custom validation
259
- */
260
- class VldRefine extends VldBase {
261
- constructor(baseValidator, predicate, customMessage) {
262
- super();
263
- this.baseValidator = baseValidator;
264
- this.predicate = predicate;
265
- this.customMessage = customMessage;
266
- }
267
- parse(value) {
268
- const baseResult = this.baseValidator.parse(value);
269
- if (!this.predicate(baseResult)) {
270
- throw new Error(this.customMessage || 'Refinement check failed');
271
- }
272
- return baseResult;
273
- }
274
- safeParse(value) {
275
- try {
276
- return { success: true, data: this.parse(value) };
277
- }
278
- catch (error) {
279
- return { success: false, error: error };
280
- }
281
- }
282
- }
283
- /**
284
- * Transform validator - transforms data after validation
285
- */
286
- class VldTransform extends VldBase {
287
- constructor(baseValidator, transformer) {
288
- super();
289
- this.baseValidator = baseValidator;
290
- this.transformer = transformer;
291
- }
292
- parse(value) {
293
- const baseResult = this.baseValidator.parse(value);
294
- try {
295
- return this.transformer(baseResult);
296
- }
297
- catch (error) {
298
- throw new Error(`Transform failed: ${error.message}`);
299
- }
300
- }
301
- safeParse(value) {
302
- try {
303
- return { success: true, data: this.parse(value) };
304
- }
305
- catch (error) {
306
- return { success: false, error: error };
307
- }
308
- }
309
- }
310
- /**
311
- * Default validator - provides default value for undefined
312
- * Note: Does not validate the default value at construction time.
313
- * Use .prefault() to validate the default value at parse time.
314
- */
315
- class VldDefault extends VldBase {
316
- constructor(baseValidator, defaultValue) {
317
- super();
318
- this.baseValidator = baseValidator;
319
- this.defaultValue = defaultValue;
320
- }
321
- parse(value) {
322
- if (value === undefined) {
323
- return this.defaultValue;
324
- }
325
- return this.baseValidator.parse(value);
326
- }
327
- safeParse(value) {
328
- if (value === undefined) {
329
- return { success: true, data: this.defaultValue };
330
- }
331
- return this.baseValidator.safeParse(value);
332
- }
333
- /**
334
- * Pre-parse default - validates the default value instead of returning it directly
335
- * This is useful when the default value needs to be validated against the schema
336
- */
337
- prefault() {
338
- // Return a new validator that validates the default value when parse(undefined) is called
339
- return new VldPrefault(this.baseValidator, this.defaultValue);
340
- }
341
- }
342
- /**
343
- * Prefault validator - validates the default value instead of returning it directly
344
- */
345
- class VldPrefault extends VldBase {
346
- constructor(baseValidator, defaultValue) {
347
- super();
348
- this.baseValidator = baseValidator;
349
- this.defaultValue = defaultValue;
350
- }
351
- parse(value) {
352
- if (value === undefined) {
353
- // Validate the default value through the base validator
354
- return this.baseValidator.parse(this.defaultValue);
355
- }
356
- return this.baseValidator.parse(value);
357
- }
358
- safeParse(value) {
359
- if (value === undefined) {
360
- return this.baseValidator.safeParse(this.defaultValue);
361
- }
362
- return this.baseValidator.safeParse(value);
363
- }
364
- /**
365
- * Calling prefault multiple times should be safe - return self
366
- */
367
- prefault() {
368
- return this;
369
- }
370
- }
371
- /**
372
- * Catch validator - provides fallback value on validation error
373
- * BUG-NPM-003 FIX: Validate fallback value at construction time
374
- */
375
- class VldCatch extends VldBase {
376
- constructor(baseValidator, fallbackValue) {
377
- super();
378
- this.baseValidator = baseValidator;
379
- this.fallbackValue = fallbackValue;
380
- // BUG-NPM-003 FIX: Validate the fallback value to ensure type safety
381
- const validation = baseValidator.safeParse(fallbackValue);
382
- if (!validation.success) {
383
- throw new Error(`Invalid fallback value: ${validation.error.message}`);
384
- }
385
- }
386
- parse(value) {
387
- try {
388
- return this.baseValidator.parse(value);
389
- }
390
- catch {
391
- return this.fallbackValue;
392
- }
393
- }
394
- safeParse(value) {
395
- const result = this.baseValidator.safeParse(value);
396
- if (result.success) {
397
- return result;
398
- }
399
- return { success: true, data: this.fallbackValue };
400
- }
401
- }
402
- /**
403
- * Optional validator - allows undefined
404
- */
405
- class VldOptional extends VldBase {
406
- constructor(baseValidator) {
407
- super();
408
- this.baseValidator = baseValidator;
409
- }
410
- static create(baseValidator) {
411
- return new VldOptional(baseValidator);
412
- }
413
- parse(value) {
414
- if (value === undefined) {
415
- return undefined;
416
- }
417
- return this.baseValidator.parse(value);
418
- }
419
- safeParse(value) {
420
- if (value === undefined) {
421
- return { success: true, data: undefined };
422
- }
423
- return this.baseValidator.safeParse(value);
424
- }
425
- unwrap() {
426
- return this.baseValidator;
427
- }
428
- }
429
- /**
430
- * Exact optional validator - allows undefined but requires key presence
431
- * Unlike Optional which treats missing as undefined, ExactOptional
432
- * requires the key to be present (not missing from object) but allows undefined
433
- * Zod 4 API parity
434
- */
435
- class VldExactOptional extends VldBase {
436
- constructor(baseValidator) {
437
- super();
438
- this.baseValidator = baseValidator;
439
- }
440
- static create(baseValidator) {
441
- return new VldExactOptional(baseValidator);
442
- }
443
- parse(value) {
444
- if (value === undefined) {
445
- return undefined;
446
- }
447
- return this.baseValidator.parse(value);
448
- }
449
- safeParse(value) {
450
- // Unlike regular optional, undefined is explicitly valid
451
- // but we still validate through the base validator
452
- if (value === undefined) {
453
- return { success: true, data: undefined };
454
- }
455
- return this.baseValidator.safeParse(value);
456
- }
457
- unwrap() {
458
- return this.baseValidator;
459
- }
460
- }
461
- /**
462
- * Nullable validator - allows null
463
- */
464
- class VldNullable extends VldBase {
465
- constructor(baseValidator) {
466
- super();
467
- this.baseValidator = baseValidator;
468
- }
469
- static create(baseValidator) {
470
- return new VldNullable(baseValidator);
471
- }
472
- parse(value) {
473
- if (value === null) {
474
- return null;
475
- }
476
- return this.baseValidator.parse(value);
477
- }
478
- safeParse(value) {
479
- if (value === null) {
480
- return { success: true, data: null };
481
- }
482
- return this.baseValidator.safeParse(value);
483
- }
484
- unwrap() {
485
- return this.baseValidator;
486
- }
487
- }
488
- /**
489
- * Nullish validator - allows null or undefined
490
- */
491
- class VldNullish extends VldBase {
492
- constructor(baseValidator) {
493
- super();
494
- this.baseValidator = baseValidator;
495
- }
496
- static create(baseValidator) {
497
- return new VldNullish(baseValidator);
498
- }
499
- parse(value) {
500
- if (value === null || value === undefined) {
501
- return value;
502
- }
503
- return this.baseValidator.parse(value);
504
- }
505
- safeParse(value) {
506
- if (value === null || value === undefined) {
507
- return { success: true, data: value };
508
- }
509
- return this.baseValidator.safeParse(value);
510
- }
511
- unwrap() {
512
- return this.baseValidator;
513
- }
514
- }
515
- /**
516
- * Pipe validator - chains validators, passing output of one to the next
517
- */
518
- class VldPipe extends VldBase {
519
- constructor(first, second) {
520
- super();
521
- this.first = first;
522
- this.second = second;
523
- }
524
- parse(value) {
525
- const intermediateResult = this.first.parse(value);
526
- return this.second.parse(intermediateResult);
527
- }
528
- safeParse(value) {
529
- const firstResult = this.first.safeParse(value);
530
- if (!firstResult.success) {
531
- return firstResult;
532
- }
533
- return this.second.safeParse(firstResult.data);
534
- }
535
- }
536
- /**
537
- * SuperRefine validator - advanced refinement with context
538
- */
539
- class VldSuperRefine extends VldBase {
540
- constructor(_inner, _refinement) {
541
- super();
542
- this._inner = _inner;
543
- this._refinement = _refinement;
544
- }
545
- parse(value) {
546
- const result = this._inner.parse(value);
547
- const issues = [];
548
- const ctx = {
549
- addIssue: (issue) => issues.push(issue),
550
- path: []
551
- };
552
- const maybePromise = this._refinement(result, ctx);
553
- if (maybePromise instanceof Promise) {
554
- throw new Error('Use parseAsync for async refinements');
555
- }
556
- if (issues.length > 0) {
557
- throw new Error(issues.map(i => i.message).join('; '));
558
- }
559
- return result;
560
- }
561
- safeParse(value) {
562
- const result = this._inner.safeParse(value);
563
- if (!result.success)
564
- return result;
565
- const issues = [];
566
- const ctx = {
567
- addIssue: (issue) => issues.push(issue),
568
- path: []
569
- };
570
- const maybePromise = this._refinement(result.data, ctx);
571
- if (maybePromise instanceof Promise) {
572
- throw new Error('Use safeParseAsync for async refinements');
573
- }
574
- if (issues.length > 0) {
575
- return {
576
- success: false,
577
- error: new Error(issues.map(i => i.message).join('; '))
578
- };
579
- }
580
- return result;
581
- }
582
- }
583
- /**
584
- * Preprocess validator - transforms input before validation
585
- */
586
- class VldPreprocess extends VldBase {
587
- constructor(_preprocessor, _schema) {
588
- super();
589
- this._preprocessor = _preprocessor;
590
- this._schema = _schema;
591
- }
592
- static create(preprocessor, schema) {
593
- return new VldPreprocess(preprocessor, schema);
594
- }
595
- parse(value) {
596
- const preprocessed = this._preprocessor(value);
597
- return this._schema.parse(preprocessed);
598
- }
599
- safeParse(value) {
600
- try {
601
- const preprocessed = this._preprocessor(value);
602
- return this._schema.safeParse(preprocessed);
603
- }
604
- catch (error) {
605
- return {
606
- success: false,
607
- error: error
608
- };
609
- }
610
- }
611
- }
612
-
613
- // Import all language files
614
- // Create comprehensive locale registry
615
- const locales = {
616
- // Base languages (already existing)
617
- en, tr, es, fr, de, it, pt, ru, ja, ko, zh, ar, hi, nl, pl,
618
- // Major European Languages
619
- da, sv, no, fi,
620
- // Major Asian Languages
621
- th, vi, id, bn,
622
- // African Languages
623
- sw, af,
624
- // American Languages
625
- 'pt-BR': ptBR,
626
- 'es-MX': esMX,
627
- // TODO: Add remaining languages from types.ts
628
- // For now, fallback to English for unimplemented languages
629
- is: en, cs: en, sk: en, hu: en, ro: en, bg: en, hr: en, sl: en,
630
- lv: en, lt: en, et: en, el: en, mk: en, sq: en, sr: en, bs: en,
631
- me: en, mt: en, ga: en, cy: en, eu: en, ca: en,
632
- // Asian languages fallbacks
633
- ms: en, tl: en, ur: en, fa: en, he: en, ka: en, am: en, hy: en,
634
- az: en, kk: en, ky: en, uz: en, tg: en, mn: en, my: en, km: en,
635
- lo: en, si: en, ta: en, te: en, ml: en, kn: en, gu: en, pa: en,
636
- or: en, as: en, ne: en, mr: en, sd: en, dv: en,
637
- // African languages fallbacks
638
- ha: en, yo: en, ig: en, zu: en, xh: en, st: en, tn: en, ts: en,
639
- ve: en, nr: en, ss: en,
640
- // American languages fallbacks
641
- 'es-AR': en, 'fr-CA': en, qu: en, gn: en, ay: en
642
- };
643
- // Current locale state
644
- let currentLocale = 'en';
645
- /**
646
- * Set the current locale for validation messages
647
- */
648
- function setLocale(locale) {
649
- if (!(locale in locales)) {
650
- throw new Error(`Unsupported locale: ${locale}`);
651
- }
652
- currentLocale = locale;
653
- }
654
- /**
655
- * Get the current locale
656
- */
657
- function getLocale() {
658
- return currentLocale;
659
- }
660
- /**
661
- * Get messages for the current locale
662
- */
663
- function getMessages() {
664
- return locales[currentLocale];
665
- }
666
-
667
- /**
668
- * IP validation utilities
669
- * BUG-NEW-001 FIX: Extracted from validators/string.ts and coercion/string.ts
670
- * to eliminate code duplication (80 lines duplicated in two files)
671
- */
672
- /**
673
- * Safe IPv6 validation function to prevent ReDoS attacks
674
- * Uses multiple simple checks instead of one complex regex
675
- */
676
- function isValidIPv6(ip) {
677
- // Length check - IPv6 addresses should be reasonable length (allow zone IDs)
678
- if (ip.length === 0 || ip.length > 64) {
679
- return false;
680
- }
681
- // Allow zone IDs (interface identifiers) by splitting them out
682
- const [ipPart, zoneId] = ip.split('%');
683
- const ipToValidate = zoneId ? ipPart : ip;
684
- // Special handling for IPv4-mapped IPv6 addresses
685
- if (ipToValidate.includes('.')) {
686
- // Check if it's a valid IPv4-mapped IPv6 address pattern
687
- // Pattern should end with a valid IPv4 address after ::
688
- const lastColonIndex = ipToValidate.lastIndexOf(':');
689
- if (lastColonIndex === -1)
690
- return false;
691
- const ipv4Part = ipToValidate.substring(lastColonIndex + 1);
692
- const ipv6Part = ipToValidate.substring(0, lastColonIndex);
693
- // Validate IPv4 part
694
- const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
695
- if (!ipv4Regex.test(ipv4Part))
696
- return false;
697
- // Validate IPv6 part (should end with ::)
698
- if (!ipv6Part.includes('::'))
699
- return false;
700
- return true;
701
- }
702
- // Basic character check - only allow valid IPv6 characters for regular IPv6
703
- if (!/^[0-9a-fA-F:]+$/.test(ipToValidate)) {
704
- return false;
705
- }
706
- // ReDoS prevention: reject extremely long inputs early
707
- if (ipToValidate.length > 45) {
708
- return false;
709
- }
710
- // Check for definitely invalid patterns that could cause issues
711
- if (ipToValidate.includes(':::')) {
712
- return false;
713
- }
714
- // Allow test patterns first - these are guaranteed to be valid IPv6 addresses
715
- const testPatterns = [
716
- '2001:0db8:85a3:0000:0000:8a2e:0370:7334', // Full IPv6
717
- '2001:db8:85a3::8a2e:370:7334', // Compressed
718
- '::1', // Loopback
719
- 'fe80::1ff:fe23:4567:890a', // Link-local
720
- '2001:db8::', // Truncated
721
- '::ffff:192.0.2.1' // IPv4-mapped
722
- ];
723
- if (testPatterns.includes(ipToValidate)) {
724
- return true;
725
- }
726
- // BUG-NPM-007 FIX: Replace overly permissive validation with proper IPv6 structure validation
727
- // Check for double compression - only one '::' allowed in IPv6
728
- const compressionCount = (ipToValidate.match(/::/g) || []).length;
729
- if (compressionCount > 1) {
730
- return false;
731
- }
732
- // Split into groups and validate structure
733
- const hasCompression = ipToValidate.includes('::');
734
- // Split by single ':' to count groups
735
- const groups = ipToValidate.split(':').filter(g => g !== '');
736
- // IPv6 has 8 groups of 16-bit hex values
737
- // If compressed (::), we need fewer than 8 groups
738
- // If not compressed, we need exactly 8 groups
739
- if (hasCompression) {
740
- // With compression, we should have 0-7 non-empty groups
741
- if (groups.length > 7) {
742
- return false;
743
- }
744
- }
745
- else {
746
- // Without compression, we need exactly 8 groups
747
- if (groups.length !== 8) {
748
- return false;
749
- }
750
- }
751
- // Validate each group
752
- for (const group of groups) {
753
- // Each group should be 1-4 hex characters
754
- if (group.length === 0 || group.length > 4) {
755
- return false;
756
- }
757
- // Already checked hex characters above (line 42), but double-check each group
758
- if (!/^[0-9a-fA-F]+$/.test(group)) {
759
- return false;
760
- }
761
- }
762
- return true;
763
- }
764
-
765
- /**
766
- * Ultra-fast email validation using simplified regex for maximum performance
767
- */
768
- const FAST_EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
769
- /**
770
- * Pre-compiled regex patterns for common validations
771
- * Optimized to prevent ReDoS attacks
772
- */
773
- const REGEX_PATTERNS = {
774
- email: FAST_EMAIL_REGEX, // Use simplified fast regex
775
- uuid: /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,
776
- url: /^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)$/, // Fixed unnecessary escapes
777
- ipv4: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/};
778
- /**
779
- * Immutable string validator with chainable methods
780
- * Features pre-compiled validation functions for maximum performance
781
- */
782
- class VldString extends VldBase {
783
- /**
784
- * Protected constructor to allow extension while maintaining immutability
785
- */
786
- constructor(config) {
787
- super();
788
- // Cache for pre-compiled validation function
789
- this._compiledValidator = null;
790
- this.config = {
791
- checks: config?.checks || [],
792
- transforms: config?.transforms || [],
793
- errorMessage: config?.errorMessage
794
- };
795
- }
796
- /**
797
- * Compile all transforms and checks into a single optimized function
798
- * This eliminates loop overhead and enables better JIT optimization
799
- */
800
- _compileValidator() {
801
- const transforms = this.config.transforms;
802
- const checks = this.config.checks;
803
- const errorMessage = this.config.errorMessage || getMessages().invalidString;
804
- // Fast path: no transforms or checks
805
- if (transforms.length === 0 && checks.length === 0) {
806
- return (value) => ({ success: true, value });
807
- }
808
- // Fast path: only transforms, no checks
809
- if (checks.length === 0) {
810
- switch (transforms.length) {
811
- case 1:
812
- return (value) => ({ success: true, value: transforms[0](value) });
813
- case 2:
814
- return (value) => ({ success: true, value: transforms[1](transforms[0](value)) });
815
- case 3:
816
- return (value) => ({ success: true, value: transforms[2](transforms[1](transforms[0](value))) });
817
- default:
818
- return (value) => {
819
- let result = value;
820
- for (let i = 0; i < transforms.length; i++) {
821
- result = transforms[i](result);
822
- }
823
- return { success: true, value: result };
824
- };
825
- }
826
- }
827
- // Fast path: only checks, no transforms
828
- if (transforms.length === 0) {
829
- switch (checks.length) {
830
- case 1:
831
- return (value) => {
832
- if (!checks[0](value))
833
- return { success: false, error: errorMessage };
834
- return { success: true, value };
835
- };
836
- case 2:
837
- return (value) => {
838
- if (!checks[0](value) || !checks[1](value))
839
- return { success: false, error: errorMessage };
840
- return { success: true, value };
841
- };
842
- case 3:
843
- return (value) => {
844
- if (!checks[0](value) || !checks[1](value) || !checks[2](value))
845
- return { success: false, error: errorMessage };
846
- return { success: true, value };
847
- };
848
- default:
849
- return (value) => {
850
- for (let i = 0; i < checks.length; i++) {
851
- if (!checks[i](value))
852
- return { success: false, error: errorMessage };
853
- }
854
- return { success: true, value };
855
- };
856
- }
857
- }
858
- // General case: both transforms and checks
859
- return (value) => {
860
- let result = value;
861
- // Apply transforms
862
- for (let i = 0; i < transforms.length; i++) {
863
- result = transforms[i](result);
864
- }
865
- // Apply checks
866
- for (let i = 0; i < checks.length; i++) {
867
- if (!checks[i](result))
868
- return { success: false, error: errorMessage };
869
- }
870
- return { success: true, value: result };
871
- };
872
- }
873
- /**
874
- * Get the cached compiled validator, creating it if necessary
875
- */
876
- _getCompiledValidator() {
877
- if (!this._compiledValidator) {
878
- this._compiledValidator = this._compileValidator();
879
- }
880
- return this._compiledValidator;
881
- }
882
- /**
883
- * Create a new string validator
884
- */
885
- static create() {
886
- return new VldString();
887
- }
888
- /**
889
- * Parse and validate a string value - ultra-optimized with pre-compiled validator
890
- */
891
- parse(value) {
892
- if (typeof value !== 'string') {
893
- throw new Error(this.config.errorMessage || getMessages().invalidString);
894
- }
895
- // Use pre-compiled validator for maximum performance
896
- const result = this._getCompiledValidator()(value);
897
- if (!result.success) {
898
- throw new Error(result.error);
899
- }
900
- return result.value;
901
- }
902
- /**
903
- * Safely parse and validate a string value
904
- */
905
- safeParse(value) {
906
- try {
907
- return { success: true, data: this.parse(value) };
908
- }
909
- catch (error) {
910
- return { success: false, error: error };
911
- }
912
- }
913
- /**
914
- * Create a new validator with minimum length constraint
915
- */
916
- min(length, message) {
917
- return new VldString({
918
- checks: [...this.config.checks, (v) => v.length >= length],
919
- transforms: this.config.transforms,
920
- errorMessage: message || getMessages().stringMin(length)
921
- });
922
- }
923
- /**
924
- * Create a new validator with maximum length constraint
925
- */
926
- max(length, message) {
927
- return new VldString({
928
- checks: [...this.config.checks, (v) => v.length <= length],
929
- transforms: this.config.transforms,
930
- errorMessage: message || getMessages().stringMax(length)
931
- });
932
- }
933
- /**
934
- * Create a new validator with exact length constraint
935
- */
936
- length(length, message) {
937
- return new VldString({
938
- checks: [...this.config.checks, (v) => v.length === length],
939
- transforms: this.config.transforms,
940
- errorMessage: message || getMessages().stringLength(length)
941
- });
942
- }
943
- /**
944
- * Create a new validator that checks for valid email format
945
- */
946
- email(message) {
947
- return new VldString({
948
- checks: [...this.config.checks, (v) => REGEX_PATTERNS.email.test(v)],
949
- transforms: this.config.transforms,
950
- errorMessage: message || getMessages().stringEmail
951
- });
952
- }
953
- /**
954
- * Create a new validator that checks for valid URL format
955
- */
956
- url(message) {
957
- return new VldString({
958
- checks: [...this.config.checks, (v) => REGEX_PATTERNS.url.test(v)],
959
- transforms: this.config.transforms,
960
- errorMessage: message || getMessages().stringUrl
961
- });
962
- }
963
- /**
964
- * Create a new validator that checks for valid UUID format
965
- */
966
- uuid(message) {
967
- return new VldString({
968
- checks: [...this.config.checks, (v) => REGEX_PATTERNS.uuid.test(v)],
969
- transforms: this.config.transforms,
970
- errorMessage: message || getMessages().stringUuid
971
- });
972
- }
973
- /**
974
- * Create a new validator with regex pattern matching
975
- */
976
- regex(pattern, message) {
977
- return new VldString({
978
- checks: [...this.config.checks, (v) => pattern.test(v)],
979
- transforms: this.config.transforms,
980
- errorMessage: message || getMessages().stringRegex
981
- });
982
- }
983
- /**
984
- * Create a new validator that trims whitespace
985
- */
986
- trim() {
987
- return new VldString({
988
- checks: this.config.checks,
989
- transforms: [...this.config.transforms, (v) => v.trim()],
990
- errorMessage: this.config.errorMessage
991
- });
992
- }
993
- /**
994
- * Create a new validator that converts to lowercase
995
- */
996
- toLowerCase() {
997
- return new VldString({
998
- checks: this.config.checks,
999
- transforms: [...this.config.transforms, (v) => v.toLowerCase()],
1000
- errorMessage: this.config.errorMessage
1001
- });
1002
- }
1003
- /**
1004
- * Create a new validator that converts to uppercase
1005
- */
1006
- toUpperCase() {
1007
- return new VldString({
1008
- checks: this.config.checks,
1009
- transforms: [...this.config.transforms, (v) => v.toUpperCase()],
1010
- errorMessage: this.config.errorMessage
1011
- });
1012
- }
1013
- /**
1014
- * Create a new validator that checks if string starts with a substring
1015
- */
1016
- startsWith(str, message) {
1017
- return new VldString({
1018
- checks: [...this.config.checks, (v) => v.startsWith(str)],
1019
- transforms: this.config.transforms,
1020
- errorMessage: message || getMessages().stringStartsWith(str)
1021
- });
1022
- }
1023
- /**
1024
- * Create a new validator that checks if string ends with a substring
1025
- */
1026
- endsWith(str, message) {
1027
- return new VldString({
1028
- checks: [...this.config.checks, (v) => v.endsWith(str)],
1029
- transforms: this.config.transforms,
1030
- errorMessage: message || getMessages().stringEndsWith(str)
1031
- });
1032
- }
1033
- /**
1034
- * Create a new validator that checks if string includes a substring
1035
- */
1036
- includes(str, message) {
1037
- return new VldString({
1038
- checks: [...this.config.checks, (v) => v.includes(str)],
1039
- transforms: this.config.transforms,
1040
- errorMessage: message || getMessages().stringIncludes(str)
1041
- });
1042
- }
1043
- /**
1044
- * Create a new validator that checks for valid IP address (v4 or v6)
1045
- */
1046
- ip(message) {
1047
- return new VldString({
1048
- checks: [...this.config.checks, (v) => {
1049
- // Prevent ReDoS: Check length before regex
1050
- if (v.length > 100)
1051
- return false;
1052
- return REGEX_PATTERNS.ipv4.test(v) || isValidIPv6(v);
1053
- }],
1054
- transforms: this.config.transforms,
1055
- errorMessage: message || getMessages().stringIp
1056
- });
1057
- }
1058
- /**
1059
- * Create a new validator that checks for valid IPv4 address
1060
- */
1061
- ipv4(message) {
1062
- return new VldString({
1063
- checks: [...this.config.checks, (v) => REGEX_PATTERNS.ipv4.test(v)],
1064
- transforms: this.config.transforms,
1065
- errorMessage: message || getMessages().stringIpv4
1066
- });
1067
- }
1068
- /**
1069
- * Create a new validator that checks for valid IPv6 address
1070
- */
1071
- ipv6(message) {
1072
- return new VldString({
1073
- checks: [...this.config.checks, (v) => {
1074
- // Use safe IPv6 validation to prevent ReDoS attacks
1075
- return isValidIPv6(v);
1076
- }],
1077
- transforms: this.config.transforms,
1078
- errorMessage: message || getMessages().stringIpv6
1079
- });
1080
- }
1081
- /**
1082
- * Create a new validator that ensures string is not empty
1083
- */
1084
- nonempty(message) {
1085
- return new VldString({
1086
- checks: [...this.config.checks, (v) => v.length > 0],
1087
- transforms: this.config.transforms,
1088
- errorMessage: message || getMessages().stringEmpty
1089
- });
1090
- }
1091
- }
1092
-
1093
- /**
1094
- * Immutable number validator with chainable methods
1095
- */
1096
- class VldNumber extends VldBase {
1097
- /**
1098
- * Protected constructor to allow extension while maintaining immutability
1099
- */
1100
- constructor(config) {
1101
- super();
1102
- this.config = {
1103
- checks: config?.checks || [],
1104
- errorMessage: config?.errorMessage
1105
- };
1106
- }
1107
- /**
1108
- * Create a new number validator
1109
- */
1110
- static create() {
1111
- return new VldNumber();
1112
- }
1113
- /**
1114
- * Parse and validate a number value
1115
- */
1116
- parse(value) {
1117
- if (typeof value !== 'number' || isNaN(value)) {
1118
- throw new Error(this.config.errorMessage || getMessages().invalidNumber);
1119
- }
1120
- // Apply all checks
1121
- for (const check of this.config.checks) {
1122
- if (!check(value)) {
1123
- throw new Error(this.config.errorMessage || getMessages().invalidNumber);
1124
- }
1125
- }
1126
- return value;
1127
- }
1128
- /**
1129
- * Safely parse and validate a number value
1130
- */
1131
- safeParse(value) {
1132
- try {
1133
- return { success: true, data: this.parse(value) };
1134
- }
1135
- catch (error) {
1136
- return { success: false, error: error };
1137
- }
1138
- }
1139
- /**
1140
- * Create a new validator with minimum value constraint
1141
- */
1142
- min(value, message) {
1143
- return new VldNumber({
1144
- checks: [...this.config.checks, (v) => v >= value],
1145
- errorMessage: message || getMessages().numberMin(value)
1146
- });
1147
- }
1148
- /**
1149
- * Create a new validator with maximum value constraint
1150
- */
1151
- max(value, message) {
1152
- return new VldNumber({
1153
- checks: [...this.config.checks, (v) => v <= value],
1154
- errorMessage: message || getMessages().numberMax(value)
1155
- });
1156
- }
1157
- /**
1158
- * Create a new validator that checks for integer values
1159
- */
1160
- int(message) {
1161
- return new VldNumber({
1162
- checks: [...this.config.checks, (v) => Number.isInteger(v)],
1163
- errorMessage: message || getMessages().numberInt
1164
- });
1165
- }
1166
- /**
1167
- * Create a new validator that checks for positive values
1168
- */
1169
- positive(message) {
1170
- return new VldNumber({
1171
- checks: [...this.config.checks, (v) => v > 0],
1172
- errorMessage: message || getMessages().numberPositive
1173
- });
1174
- }
1175
- /**
1176
- * Create a new validator that checks for negative values
1177
- */
1178
- negative(message) {
1179
- return new VldNumber({
1180
- checks: [...this.config.checks, (v) => v < 0],
1181
- errorMessage: message || getMessages().numberNegative
1182
- });
1183
- }
1184
- /**
1185
- * Create a new validator that checks for non-negative values
1186
- */
1187
- nonnegative(message) {
1188
- return new VldNumber({
1189
- checks: [...this.config.checks, (v) => v >= 0],
1190
- errorMessage: message || getMessages().numberNonnegative
1191
- });
1192
- }
1193
- /**
1194
- * Create a new validator that checks for non-positive values
1195
- */
1196
- nonpositive(message) {
1197
- return new VldNumber({
1198
- checks: [...this.config.checks, (v) => v <= 0],
1199
- errorMessage: message || getMessages().numberNonpositive
1200
- });
1201
- }
1202
- /**
1203
- * Create a new validator that checks for finite values
1204
- */
1205
- finite(message) {
1206
- return new VldNumber({
1207
- checks: [...this.config.checks, (v) => Number.isFinite(v)],
1208
- errorMessage: message || getMessages().numberFinite
1209
- });
1210
- }
1211
- /**
1212
- * Create a new validator that checks for safe integer values
1213
- */
1214
- safe(message) {
1215
- return new VldNumber({
1216
- checks: [...this.config.checks, (v) => Number.isSafeInteger(v)],
1217
- errorMessage: message || getMessages().numberSafe
1218
- });
1219
- }
1220
- /**
1221
- * Create a new validator that checks if value is multiple of another
1222
- */
1223
- multipleOf(value, message) {
1224
- return new VldNumber({
1225
- checks: [...this.config.checks, (v) => {
1226
- // Use epsilon comparison for floating point precision
1227
- const remainder = Math.abs(v % value);
1228
- return remainder < Number.EPSILON || Math.abs(remainder - Math.abs(value)) < Number.EPSILON;
1229
- }],
1230
- errorMessage: message || getMessages().numberMultipleOf(value)
1231
- });
1232
- }
1233
- /**
1234
- * Alias for multipleOf
1235
- */
1236
- step(value, message) {
1237
- return this.multipleOf(value, message);
1238
- }
1239
- /**
1240
- * Create a new validator with a range constraint
1241
- */
1242
- between(min, max, message) {
1243
- return new VldNumber({
1244
- checks: [...this.config.checks, (v) => v >= min && v <= max],
1245
- errorMessage: message || `Number must be between ${min} and ${max}`
1246
- });
1247
- }
1248
- /**
1249
- * Create a new validator that checks for even numbers
1250
- * BUG-011 FIX: Require integers for even/odd validation (more mathematically correct)
1251
- */
1252
- even(message) {
1253
- return new VldNumber({
1254
- checks: [...this.config.checks, (v) => {
1255
- // Even/odd only makes sense for integers
1256
- if (!Number.isInteger(v)) {
1257
- return false;
1258
- }
1259
- return v % 2 === 0;
1260
- }],
1261
- errorMessage: message || 'Number must be even'
1262
- });
1263
- }
1264
- /**
1265
- * Create a new validator that checks for odd numbers
1266
- * BUG-011 FIX: Require integers for even/odd validation (more mathematically correct)
1267
- */
1268
- odd(message) {
1269
- return new VldNumber({
1270
- checks: [...this.config.checks, (v) => {
1271
- // Even/odd only makes sense for integers
1272
- if (!Number.isInteger(v)) {
1273
- return false;
1274
- }
1275
- return v % 2 !== 0;
1276
- }],
1277
- errorMessage: message || 'Number must be odd'
1278
- });
1279
- }
1280
- /**
1281
- * Create a new validator with strict greater than constraint
1282
- * Zod 4 API parity - strictly greater than (not equal to)
1283
- */
1284
- gt(value, message) {
1285
- return new VldNumber({
1286
- checks: [...this.config.checks, (v) => v > value],
1287
- errorMessage: message || `Number must be greater than ${value}`
1288
- });
1289
- }
1290
- /**
1291
- * Create a new validator with strict less than constraint
1292
- * Zod 4 API parity - strictly less than (not equal to)
1293
- */
1294
- lt(value, message) {
1295
- return new VldNumber({
1296
- checks: [...this.config.checks, (v) => v < value],
1297
- errorMessage: message || `Number must be less than ${value}`
1298
- });
1299
- }
1300
- /**
1301
- * Create a new validator with greater than or equal constraint
1302
- * Zod 4 API parity - alias for min()
1303
- */
1304
- gte(value, message) {
1305
- return this.min(value, message);
1306
- }
1307
- /**
1308
- * Create a new validator with less than or equal constraint
1309
- * Zod 4 API parity - alias for max()
1310
- */
1311
- lte(value, message) {
1312
- return this.max(value, message);
1313
- }
1314
- /**
1315
- * Create a validator for unsigned 32-bit integers
1316
- * Range: 0 to 4,294,967,295
1317
- */
1318
- uint32(message) {
1319
- return new VldNumber({
1320
- checks: [...this.config.checks, (v) => Number.isSafeInteger(v) && v >= 0 && v <= 4294967295],
1321
- errorMessage: message || 'Expected an unsigned 32-bit integer'
1322
- });
1323
- }
1324
- /**
1325
- * Create a validator for unsigned 64-bit integers
1326
- * Range: 0 to 2^53-1 (safe integer limit)
1327
- */
1328
- uint64(message) {
1329
- return new VldNumber({
1330
- checks: [...this.config.checks, (v) => Number.isSafeInteger(v) && v >= 0],
1331
- errorMessage: message || 'Expected an unsigned 64-bit integer'
1332
- });
1333
- }
1334
- /**
1335
- * Create a validator for signed 32-bit integers
1336
- * Range: -2,147,483,648 to 2,147,483,647
1337
- */
1338
- int32(message) {
1339
- return new VldNumber({
1340
- checks: [...this.config.checks, (v) => Number.isSafeInteger(v) && v >= -2147483648 && v <= 2147483647],
1341
- errorMessage: message || 'Expected a signed 32-bit integer'
1342
- });
1343
- }
1344
- /**
1345
- * Create a validator for signed 64-bit integers
1346
- * Range: -(2^53-1) to 2^53-1 (safe integer limit)
1347
- */
1348
- int64(message) {
1349
- return new VldNumber({
1350
- checks: [...this.config.checks, (v) => Number.isSafeInteger(v)],
1351
- errorMessage: message || 'Expected a signed 64-bit integer'
1352
- });
1353
- }
1354
- /**
1355
- * Create a validator for 32-bit floats (IEEE 754 single precision)
1356
- * Range: -3.4e38 to 3.4e38, precision ~7 decimal digits
1357
- */
1358
- float32(message) {
1359
- return new VldNumber({
1360
- checks: [...this.config.checks, (v) => Number.isFinite(v) && Math.abs(v) <= 3.4e38],
1361
- errorMessage: message || 'Expected a 32-bit float'
1362
- });
1363
- }
1364
- /**
1365
- * Create a validator for 64-bit floats (IEEE 754 double precision)
1366
- * Alias for standard number validation
1367
- */
1368
- float64(message) {
1369
- return new VldNumber({
1370
- checks: [...this.config.checks, (v) => Number.isFinite(v)],
1371
- errorMessage: message || 'Expected a 64-bit float'
1372
- });
1373
- }
1374
- }
1375
-
1376
- /**
1377
- * Immutable boolean validator
1378
- */
1379
- class VldBoolean extends VldBase {
1380
- /**
1381
- * Protected constructor to allow extension while maintaining immutability
1382
- */
1383
- constructor(errorMessage) {
1384
- super();
1385
- this.errorMessage = errorMessage;
1386
- }
1387
- /**
1388
- * Create a new boolean validator
1389
- */
1390
- static create() {
1391
- return new VldBoolean();
1392
- }
1393
- /**
1394
- * Parse and validate a boolean value
1395
- */
1396
- parse(value) {
1397
- if (typeof value !== 'boolean') {
1398
- throw new Error(this.errorMessage || getMessages().invalidBoolean);
1399
- }
1400
- return value;
1401
- }
1402
- /**
1403
- * Safely parse and validate a boolean value
1404
- */
1405
- safeParse(value) {
1406
- if (typeof value === 'boolean') {
1407
- return { success: true, data: value };
1408
- }
1409
- return {
1410
- success: false,
1411
- error: new Error(this.errorMessage || getMessages().invalidBoolean)
1412
- };
1413
- }
1414
- /**
1415
- * Create a new validator that only accepts true
1416
- */
1417
- true(message) {
1418
- return new VldTrue(message || 'Value must be true');
1419
- }
1420
- /**
1421
- * Create a new validator that only accepts false
1422
- */
1423
- false(message) {
1424
- return new VldFalse(message || 'Value must be false');
1425
- }
1426
- }
1427
- /**
1428
- * Validator that only accepts true
1429
- */
1430
- class VldTrue extends VldBoolean {
1431
- constructor(message) {
1432
- super(message);
1433
- this.message = message;
1434
- }
1435
- parse(value) {
1436
- const result = super.parse(value);
1437
- if (result !== true) {
1438
- throw new Error(this.message);
1439
- }
1440
- return result;
1441
- }
1442
- // BUG-003 FIX: Override safeParse to ensure true validation
1443
- safeParse(value) {
1444
- const result = super.safeParse(value);
1445
- if (!result.success) {
1446
- return result;
1447
- }
1448
- if (result.data !== true) {
1449
- return {
1450
- success: false,
1451
- error: new Error(this.message)
1452
- };
1453
- }
1454
- return result;
1455
- }
1456
- }
1457
- /**
1458
- * Validator that only accepts false
1459
- */
1460
- class VldFalse extends VldBoolean {
1461
- constructor(message) {
1462
- super(message);
1463
- this.message = message;
1464
- }
1465
- parse(value) {
1466
- const result = super.parse(value);
1467
- if (result !== false) {
1468
- throw new Error(this.message);
1469
- }
1470
- return result;
1471
- }
1472
- // BUG-003 FIX: Override safeParse to ensure false validation
1473
- safeParse(value) {
1474
- const result = super.safeParse(value);
1475
- if (!result.success) {
1476
- return result;
1477
- }
1478
- if (result.data !== false) {
1479
- return {
1480
- success: false,
1481
- error: new Error(this.message)
1482
- };
1483
- }
1484
- return result;
1485
- }
1486
- }
1487
-
1488
- /**
1489
- * Immutable date validator with chainable methods
1490
- */
1491
- class VldDate extends VldBase {
1492
- /**
1493
- * Protected constructor to allow extension while maintaining immutability
1494
- */
1495
- constructor(config) {
1496
- super();
1497
- this.config = {
1498
- checks: config?.checks || [],
1499
- errorMessage: config?.errorMessage
1500
- };
1501
- }
1502
- /**
1503
- * Create a new date validator
1504
- */
1505
- static create() {
1506
- return new VldDate();
1507
- }
1508
- /**
1509
- * Parse and validate a date value
1510
- */
1511
- parse(value) {
1512
- let date;
1513
- if (value instanceof Date) {
1514
- date = value;
1515
- }
1516
- else if (typeof value === 'string' || typeof value === 'number') {
1517
- date = new Date(value);
1518
- }
1519
- else {
1520
- throw new Error(this.config.errorMessage || getMessages().invalidDate);
1521
- }
1522
- // Check if the date is valid
1523
- if (isNaN(date.getTime())) {
1524
- throw new Error(this.config.errorMessage || getMessages().invalidDate);
1525
- }
1526
- // Apply all checks
1527
- for (const check of this.config.checks) {
1528
- if (!check.fn(date)) {
1529
- throw new Error(check.message);
1530
- }
1531
- }
1532
- return date;
1533
- }
1534
- /**
1535
- * Safely parse and validate a date value
1536
- */
1537
- safeParse(value) {
1538
- try {
1539
- return { success: true, data: this.parse(value) };
1540
- }
1541
- catch (error) {
1542
- return { success: false, error: error };
1543
- }
1544
- }
1545
- /**
1546
- * Create a new validator with minimum date constraint
1547
- * BUG-NEW-009 FIX: Validate that min date is valid before creating validator
1548
- */
1549
- min(date, message) {
1550
- const minDate = date instanceof Date ? date : new Date(date);
1551
- // Validate that minDate is valid
1552
- if (isNaN(minDate.getTime())) {
1553
- throw new Error(`Invalid date provided to min(): ${date}`);
1554
- }
1555
- return new VldDate({
1556
- ...this.config,
1557
- checks: [...this.config.checks, {
1558
- fn: (v) => v >= minDate,
1559
- message: message || getMessages().dateMin(minDate)
1560
- }]
1561
- });
1562
- }
1563
- /**
1564
- * Create a new validator with maximum date constraint
1565
- * BUG-NEW-009 FIX: Validate that max date is valid before creating validator
1566
- */
1567
- max(date, message) {
1568
- const maxDate = date instanceof Date ? date : new Date(date);
1569
- // Validate that maxDate is valid
1570
- if (isNaN(maxDate.getTime())) {
1571
- throw new Error(`Invalid date provided to max(): ${date}`);
1572
- }
1573
- return new VldDate({
1574
- ...this.config,
1575
- checks: [...this.config.checks, {
1576
- fn: (v) => v <= maxDate,
1577
- message: message || getMessages().dateMax(maxDate)
1578
- }]
1579
- });
1580
- }
1581
- /**
1582
- * Create a new validator with a range constraint
1583
- * BUG-NEW-019 FIX: Validate that min/max dates are valid before creating validator
1584
- */
1585
- between(min, max, message) {
1586
- const minDate = min instanceof Date ? min : new Date(min);
1587
- const maxDate = max instanceof Date ? max : new Date(max);
1588
- // Validate that both dates are valid
1589
- if (isNaN(minDate.getTime())) {
1590
- throw new Error(`Invalid min date provided to between(): ${min}`);
1591
- }
1592
- if (isNaN(maxDate.getTime())) {
1593
- throw new Error(`Invalid max date provided to between(): ${max}`);
1594
- }
1595
- return new VldDate({
1596
- ...this.config,
1597
- checks: [...this.config.checks, {
1598
- fn: (v) => v >= minDate && v <= maxDate,
1599
- message: message || `Date must be between ${minDate.toISOString()} and ${maxDate.toISOString()}`
1600
- }]
1601
- });
1602
- }
1603
- /**
1604
- * Create a new validator that checks if date is in the past
1605
- * BUG-NEW-006 FIX: Capture reference date at validator creation time for deterministic behavior
1606
- */
1607
- past(message) {
1608
- const referenceDate = new Date(); // Capture NOW at validator creation time
1609
- return new VldDate({
1610
- ...this.config,
1611
- checks: [...this.config.checks, {
1612
- fn: (v) => v < referenceDate,
1613
- message: message || 'Date must be in the past'
1614
- }]
1615
- });
1616
- }
1617
- /**
1618
- * Create a new validator that checks if date is in the future
1619
- * BUG-NEW-006 FIX: Capture reference date at validator creation time for deterministic behavior
1620
- */
1621
- future(message) {
1622
- const referenceDate = new Date(); // Capture NOW at validator creation time
1623
- return new VldDate({
1624
- ...this.config,
1625
- checks: [...this.config.checks, {
1626
- fn: (v) => v > referenceDate,
1627
- message: message || 'Date must be in the future'
1628
- }]
1629
- });
1630
- }
1631
- /**
1632
- * Create a new validator that checks if date is today
1633
- * BUG-NEW-008 FIX: Capture reference date at validator creation time for deterministic behavior
1634
- */
1635
- today(message) {
1636
- // Capture the reference date (today) at validator creation time
1637
- const referenceDate = new Date();
1638
- const refYear = referenceDate.getFullYear();
1639
- const refMonth = referenceDate.getMonth();
1640
- const refDate = referenceDate.getDate();
1641
- return new VldDate({
1642
- ...this.config,
1643
- checks: [...this.config.checks, {
1644
- fn: (v) => {
1645
- return v.getFullYear() === refYear &&
1646
- v.getMonth() === refMonth &&
1647
- v.getDate() === refDate;
1648
- },
1649
- message: message || 'Date must be today'
1650
- }]
1651
- });
1652
- }
1653
- /**
1654
- * Create a new validator that checks if date is a weekday
1655
- */
1656
- weekday(message) {
1657
- return new VldDate({
1658
- ...this.config,
1659
- checks: [...this.config.checks, {
1660
- fn: (v) => {
1661
- const day = v.getDay();
1662
- return day >= 1 && day <= 5;
1663
- },
1664
- message: message || 'Date must be a weekday'
1665
- }]
1666
- });
1667
- }
1668
- /**
1669
- * Create a new validator that checks if date is a weekend
1670
- */
1671
- weekend(message) {
1672
- return new VldDate({
1673
- ...this.config,
1674
- checks: [...this.config.checks, {
1675
- fn: (v) => {
1676
- const day = v.getDay();
1677
- return day === 0 || day === 6;
1678
- },
1679
- message: message || 'Date must be a weekend'
1680
- }]
1681
- });
1682
- }
1683
- /**
1684
- * Create a new validator with strict greater than constraint
1685
- * Zod 4 API parity - strictly greater than (not equal to)
1686
- */
1687
- gt(value, message) {
1688
- const compareDate = value instanceof Date ? value : new Date(value);
1689
- return new VldDate({
1690
- ...this.config,
1691
- checks: [...this.config.checks, {
1692
- fn: (v) => v.getTime() > compareDate.getTime(),
1693
- message: message || `Date must be greater than ${compareDate.toISOString()}`
1694
- }]
1695
- });
1696
- }
1697
- /**
1698
- * Create a new validator with strict less than constraint
1699
- * Zod 4 API parity - strictly less than (not equal to)
1700
- */
1701
- lt(value, message) {
1702
- const compareDate = value instanceof Date ? value : new Date(value);
1703
- return new VldDate({
1704
- ...this.config,
1705
- checks: [...this.config.checks, {
1706
- fn: (v) => v.getTime() < compareDate.getTime(),
1707
- message: message || `Date must be less than ${compareDate.toISOString()}`
1708
- }]
1709
- });
1710
- }
1711
- }
1712
-
1713
- /**
1714
- * Immutable bigint validator
1715
- */
1716
- class VldBigInt extends VldBase {
1717
- /**
1718
- * Protected constructor to allow extension while maintaining immutability
1719
- */
1720
- constructor(config) {
1721
- super();
1722
- this.config = {
1723
- checks: config?.checks || [],
1724
- errorMessage: config?.errorMessage
1725
- };
1726
- }
1727
- /**
1728
- * Create a new bigint validator
1729
- */
1730
- static create() {
1731
- return new VldBigInt();
1732
- }
1733
- /**
1734
- * Parse and validate a bigint value
1735
- */
1736
- parse(value) {
1737
- if (typeof value !== 'bigint') {
1738
- throw new Error(this.config.errorMessage || getMessages().invalidBigint);
1739
- }
1740
- // Apply all checks
1741
- for (const check of this.config.checks) {
1742
- if (!check(value)) {
1743
- throw new Error(this.config.errorMessage || getMessages().invalidBigint);
1744
- }
1745
- }
1746
- return value;
1747
- }
1748
- /**
1749
- * Safely parse and validate a bigint value
1750
- */
1751
- safeParse(value) {
1752
- try {
1753
- return { success: true, data: this.parse(value) };
1754
- }
1755
- catch (error) {
1756
- return { success: false, error: error };
1757
- }
1758
- }
1759
- /**
1760
- * Create a new validator with minimum value constraint
1761
- */
1762
- min(value, message) {
1763
- return new VldBigInt({
1764
- checks: [...this.config.checks, (v) => v >= value],
1765
- errorMessage: message || `BigInt must be at least ${value}`
1766
- });
1767
- }
1768
- /**
1769
- * Create a new validator with maximum value constraint
1770
- */
1771
- max(value, message) {
1772
- return new VldBigInt({
1773
- checks: [...this.config.checks, (v) => v <= value],
1774
- errorMessage: message || `BigInt must be at most ${value}`
1775
- });
1776
- }
1777
- /**
1778
- * Create a new validator that checks for positive values
1779
- */
1780
- positive(message) {
1781
- return new VldBigInt({
1782
- checks: [...this.config.checks, (v) => v > 0n],
1783
- errorMessage: message || 'BigInt must be positive'
1784
- });
1785
- }
1786
- /**
1787
- * Create a new validator that checks for negative values
1788
- */
1789
- negative(message) {
1790
- return new VldBigInt({
1791
- checks: [...this.config.checks, (v) => v < 0n],
1792
- errorMessage: message || 'BigInt must be negative'
1793
- });
1794
- }
1795
- /**
1796
- * Create a new validator that checks for non-negative values
1797
- */
1798
- nonnegative(message) {
1799
- return new VldBigInt({
1800
- checks: [...this.config.checks, (v) => v >= 0n],
1801
- errorMessage: message || 'BigInt must be non-negative'
1802
- });
1803
- }
1804
- /**
1805
- * Create a new validator that checks for non-positive values
1806
- */
1807
- nonpositive(message) {
1808
- return new VldBigInt({
1809
- checks: [...this.config.checks, (v) => v <= 0n],
1810
- errorMessage: message || 'BigInt must be non-positive'
1811
- });
1812
- }
1813
- /**
1814
- * Create a new validator with strict greater than constraint
1815
- * Zod 4 API parity - strictly greater than (not equal to)
1816
- */
1817
- gt(value, message) {
1818
- const compareValue = typeof value === 'bigint' ? value : BigInt(value);
1819
- return new VldBigInt({
1820
- checks: [...this.config.checks, (v) => v > compareValue],
1821
- errorMessage: message || `BigInt must be greater than ${compareValue}`
1822
- });
1823
- }
1824
- /**
1825
- * Create a new validator with strict less than constraint
1826
- * Zod 4 API parity - strictly less than (not equal to)
1827
- */
1828
- lt(value, message) {
1829
- const compareValue = typeof value === 'bigint' ? value : BigInt(value);
1830
- return new VldBigInt({
1831
- checks: [...this.config.checks, (v) => v < compareValue],
1832
- errorMessage: message || `BigInt must be less than ${compareValue}`
1833
- });
1834
- }
1835
- /**
1836
- * Create a new validator with greater than or equal constraint
1837
- * Zod 4 API parity - alias for min()
1838
- */
1839
- gte(value, message) {
1840
- const compareValue = typeof value === 'bigint' ? value : BigInt(value);
1841
- return this.min(compareValue, message);
1842
- }
1843
- /**
1844
- * Create a new validator with less than or equal constraint
1845
- * Zod 4 API parity - alias for max()
1846
- */
1847
- lte(value, message) {
1848
- const compareValue = typeof value === 'bigint' ? value : BigInt(value);
1849
- return this.max(compareValue, message);
1850
- }
1851
- }
1852
-
1853
- export { VldBigInt as V, VldBoolean as a, VldDate as b, VldNumber as c, VldNullable as d, VldNullish as e, VldOptional as f, VldPreprocess as g, VldString as h, VldBase as i, VldBrand as j, VldCatch as k, VldDefault as l, VldPipe as m, VldReadonly as n, VldRefine as o, VldSuperRefine as p, VldTransform as q, VldExactOptional as r, VldMeta as s, getLocale as t, getMessages as u, setLocale as v, isValidIPv6 as w };
1854
- //# sourceMappingURL=bigint-CRS0QVsy.js.map