@oxog/vld 2.0.2 → 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 (450) hide show
  1. package/CHANGELOG.md +75 -1
  2. package/LICENSE +20 -20
  3. package/README.md +101 -37
  4. package/dist/chunks/errors-core-BeiFUtZM.js +81 -0
  5. package/dist/chunks/{index-CETyGkrv.js → index-0R2ntSud.js} +16 -402
  6. package/dist/chunks/index-BvH403Yy.js +88 -0
  7. package/dist/chunks/security-B0Pd_vSY.js +35 -0
  8. package/dist/chunks/string-BJRQod3t.js +530 -0
  9. package/dist/cjs/chunks/errors-core-DWxLFs2f.cjs +83 -0
  10. package/dist/cjs/chunks/index-BkI37108.cjs +538 -0
  11. package/dist/cjs/chunks/index-Cc3bjUMX.cjs +91 -0
  12. package/dist/cjs/chunks/security-Dc3Jh13T.cjs +37 -0
  13. package/dist/cjs/chunks/string-BKZrc4hs.cjs +533 -0
  14. package/dist/cjs/cli/bin.cjs +506 -0
  15. package/dist/cjs/cli/index.cjs +209 -0
  16. package/dist/cjs/codecs/index.cjs +45 -0
  17. package/dist/{chunks/date-ODue_rtq.js → cjs/coercion/index.cjs} +185 -103
  18. package/dist/cjs/compat/emitter.cjs +184 -0
  19. package/dist/cjs/compat/result.cjs +189 -0
  20. package/dist/cjs/errors.cjs +6 -213
  21. package/dist/cjs/index.cjs +1558 -9647
  22. package/dist/cjs/kernel.cjs +415 -0
  23. package/dist/cjs/locales/af.cjs +108 -0
  24. package/dist/cjs/locales/ar.cjs +108 -0
  25. package/dist/cjs/locales/bn.cjs +108 -0
  26. package/dist/cjs/locales/da.cjs +108 -0
  27. package/dist/cjs/locales/de.cjs +108 -0
  28. package/dist/cjs/locales/en.cjs +108 -0
  29. package/dist/cjs/locales/es-MX.cjs +107 -0
  30. package/dist/cjs/locales/es.cjs +96 -0
  31. package/dist/cjs/locales/fi.cjs +108 -0
  32. package/dist/cjs/locales/fr.cjs +96 -0
  33. package/dist/cjs/locales/hi.cjs +108 -0
  34. package/dist/cjs/locales/id.cjs +108 -0
  35. package/dist/cjs/locales/index.cjs +41 -2875
  36. package/dist/cjs/locales/it.cjs +108 -0
  37. package/dist/cjs/locales/ja.cjs +108 -0
  38. package/dist/cjs/locales/ko.cjs +108 -0
  39. package/dist/cjs/locales/lazy.cjs +42 -3023
  40. package/dist/cjs/locales/nl.cjs +108 -0
  41. package/dist/cjs/locales/no.cjs +108 -0
  42. package/dist/cjs/locales/pl.cjs +108 -0
  43. package/dist/cjs/locales/pt-BR.cjs +108 -0
  44. package/dist/cjs/locales/pt.cjs +108 -0
  45. package/dist/cjs/locales/ru.cjs +108 -0
  46. package/dist/cjs/locales/runtime.cjs +51 -0
  47. package/dist/cjs/locales/sv.cjs +108 -0
  48. package/dist/cjs/locales/sw.cjs +108 -0
  49. package/dist/cjs/locales/th.cjs +108 -0
  50. package/dist/cjs/locales/tr.cjs +108 -0
  51. package/dist/cjs/locales/vi.cjs +108 -0
  52. package/dist/cjs/locales/zh.cjs +108 -0
  53. package/dist/cjs/mini.cjs +121 -7208
  54. package/dist/cjs/pigment.cjs +207 -0
  55. package/dist/cjs/plugins/index.cjs +12 -0
  56. package/dist/cjs/registry.cjs +37 -0
  57. package/dist/cjs/v3/index.cjs +425 -0
  58. package/dist/cjs/v4/core/index.cjs +894 -0
  59. package/dist/cjs/v4/index.cjs +425 -0
  60. package/dist/cjs/v4/locales/index.cjs +130 -0
  61. package/dist/cjs/v4/mini/index.cjs +509 -0
  62. package/dist/cjs/v4-mini/index.cjs +532 -0
  63. package/dist/cjs/validators/any.cjs +40 -0
  64. package/dist/cjs/validators/array.cjs +283 -0
  65. package/dist/cjs/validators/base.cjs +887 -0
  66. package/dist/cjs/validators/base64.cjs +73 -0
  67. package/dist/cjs/validators/bigint.cjs +232 -0
  68. package/dist/cjs/validators/boolean.cjs +146 -0
  69. package/dist/cjs/validators/codec.cjs +205 -0
  70. package/dist/cjs/validators/custom.cjs +71 -0
  71. package/dist/cjs/validators/date.cjs +278 -0
  72. package/dist/cjs/validators/discriminated-union.cjs +130 -0
  73. package/dist/cjs/validators/enum.cjs +154 -0
  74. package/dist/cjs/validators/file.cjs +130 -0
  75. package/dist/cjs/validators/function.cjs +63 -0
  76. package/dist/cjs/validators/hex.cjs +70 -0
  77. package/dist/cjs/validators/index.cjs +123 -0
  78. package/dist/cjs/validators/intersection.cjs +120 -0
  79. package/dist/cjs/validators/json.cjs +70 -0
  80. package/dist/cjs/validators/lazy.cjs +53 -0
  81. package/dist/cjs/validators/literal.cjs +64 -0
  82. package/dist/cjs/validators/map.cjs +218 -0
  83. package/dist/cjs/validators/nan.cjs +41 -0
  84. package/dist/cjs/validators/never.cjs +36 -0
  85. package/dist/cjs/validators/null.cjs +43 -0
  86. package/dist/cjs/validators/number.cjs +427 -0
  87. package/dist/cjs/validators/object.cjs +868 -0
  88. package/dist/cjs/validators/promise.cjs +115 -0
  89. package/dist/cjs/validators/record.cjs +262 -0
  90. package/dist/cjs/validators/set.cjs +203 -0
  91. package/dist/cjs/validators/string-bool.cjs +124 -0
  92. package/dist/cjs/validators/string-formats.cjs +168 -0
  93. package/dist/cjs/validators/string.cjs +12 -0
  94. package/dist/cjs/validators/symbol.cjs +62 -0
  95. package/dist/cjs/validators/template-literal.cjs +108 -0
  96. package/dist/cjs/validators/tuple.cjs +187 -0
  97. package/dist/cjs/validators/uint8array.cjs +106 -0
  98. package/dist/cjs/validators/undefined.cjs +43 -0
  99. package/dist/cjs/validators/union.cjs +191 -0
  100. package/dist/cjs/validators/unknown.cjs +40 -0
  101. package/dist/cjs/validators/void.cjs +48 -0
  102. package/dist/cjs/validators/xor.cjs +69 -0
  103. package/dist/cli/bin.d.ts +0 -1
  104. package/dist/cli/bin.js +407 -0
  105. package/dist/cli/commands/benchmark.d.ts +1 -2
  106. package/dist/cli/commands/validate.d.ts +1 -2
  107. package/dist/cli/index.d.ts +0 -1
  108. package/dist/cli/index.js +205 -0
  109. package/dist/codecs/index.d.ts +21 -4
  110. package/dist/codecs/index.js +11 -4
  111. package/dist/coercion/bigint.d.ts +2 -3
  112. package/dist/coercion/boolean.d.ts +3 -3
  113. package/dist/coercion/date.d.ts +3 -3
  114. package/dist/coercion/index.d.ts +5 -6
  115. package/dist/coercion/index.js +473 -5
  116. package/dist/coercion/number.d.ts +2 -3
  117. package/dist/coercion/string.d.ts +2 -3
  118. package/dist/compat/emitter.d.ts +0 -1
  119. package/dist/compat/emitter.js +0 -1
  120. package/dist/compat/index.d.ts +4 -5
  121. package/dist/compat/result.d.ts +1 -2
  122. package/dist/compat/result.js +0 -1
  123. package/dist/errors-core.d.ts +39 -0
  124. package/dist/errors.d.ts +4 -54
  125. package/dist/errors.js +4 -68
  126. package/dist/events.d.ts +3 -4
  127. package/dist/index.d.ts +1195 -600
  128. package/dist/index.js +1262 -44
  129. package/dist/kernel.d.ts +2 -3
  130. package/dist/kernel.js +10 -6
  131. package/dist/locales/af.d.ts +1 -2
  132. package/dist/locales/af.js +0 -1
  133. package/dist/locales/ar.d.ts +1 -2
  134. package/dist/locales/ar.js +0 -1
  135. package/dist/locales/bn.d.ts +1 -2
  136. package/dist/locales/bn.js +0 -1
  137. package/dist/locales/da.d.ts +1 -2
  138. package/dist/locales/da.js +0 -1
  139. package/dist/locales/de.d.ts +1 -2
  140. package/dist/locales/de.js +0 -1
  141. package/dist/locales/en.d.ts +1 -2
  142. package/dist/locales/en.js +0 -1
  143. package/dist/locales/es-MX.d.ts +1 -2
  144. package/dist/locales/es-MX.js +0 -1
  145. package/dist/locales/es.d.ts +1 -2
  146. package/dist/locales/es.js +0 -1
  147. package/dist/locales/fi.d.ts +1 -2
  148. package/dist/locales/fi.js +0 -1
  149. package/dist/locales/fr.d.ts +1 -2
  150. package/dist/locales/fr.js +0 -1
  151. package/dist/locales/hi.d.ts +1 -2
  152. package/dist/locales/hi.js +0 -1
  153. package/dist/locales/id.d.ts +1 -2
  154. package/dist/locales/id.js +0 -1
  155. package/dist/locales/index.d.ts +10 -15
  156. package/dist/locales/index.js +28 -2
  157. package/dist/locales/it.d.ts +1 -2
  158. package/dist/locales/it.js +0 -1
  159. package/dist/locales/ja.d.ts +1 -2
  160. package/dist/locales/ja.js +0 -1
  161. package/dist/locales/ko.d.ts +1 -2
  162. package/dist/locales/ko.js +0 -1
  163. package/dist/locales/lazy.d.ts +4 -26
  164. package/dist/locales/lazy.js +12 -55
  165. package/dist/locales/nl.d.ts +1 -2
  166. package/dist/locales/nl.js +0 -1
  167. package/dist/locales/no.d.ts +1 -2
  168. package/dist/locales/no.js +0 -1
  169. package/dist/locales/pl.d.ts +1 -2
  170. package/dist/locales/pl.js +0 -1
  171. package/dist/locales/pt-BR.d.ts +1 -2
  172. package/dist/locales/pt-BR.js +0 -1
  173. package/dist/locales/pt.d.ts +1 -2
  174. package/dist/locales/pt.js +0 -1
  175. package/dist/locales/ru.d.ts +1 -2
  176. package/dist/locales/ru.js +0 -1
  177. package/dist/locales/runtime.d.ts +10 -0
  178. package/dist/locales/runtime.js +41 -0
  179. package/dist/locales/sv.d.ts +1 -2
  180. package/dist/locales/sv.js +0 -1
  181. package/dist/locales/sw.d.ts +1 -2
  182. package/dist/locales/sw.js +0 -1
  183. package/dist/locales/th.d.ts +1 -2
  184. package/dist/locales/th.js +0 -1
  185. package/dist/locales/tr.d.ts +1 -2
  186. package/dist/locales/tr.js +0 -1
  187. package/dist/locales/types.d.ts +0 -1
  188. package/dist/locales/vi.d.ts +1 -2
  189. package/dist/locales/vi.js +0 -1
  190. package/dist/locales/zh.d.ts +1 -2
  191. package/dist/locales/zh.js +0 -1
  192. package/dist/logger.d.ts +0 -1
  193. package/dist/mini.d.ts +64 -65
  194. package/dist/mini.js +31 -7
  195. package/dist/pigment.d.ts +0 -1
  196. package/dist/pigment.js +6 -4
  197. package/dist/plugins/index.d.ts +2 -3
  198. package/dist/plugins/index.js +1 -0
  199. package/dist/plugins/types.d.ts +4 -5
  200. package/dist/registry.d.ts +23 -0
  201. package/dist/registry.js +34 -0
  202. package/dist/utils/codec-utils.d.ts +0 -1
  203. package/dist/utils/deep-merge.d.ts +0 -1
  204. package/dist/utils/ip-validation.d.ts +0 -1
  205. package/dist/utils/json-schema.d.ts +77 -0
  206. package/dist/utils/security.d.ts +2 -6
  207. package/dist/v3/index.d.ts +2 -0
  208. package/dist/v3/index.js +46 -0
  209. package/dist/v4/core/index.d.ts +260 -0
  210. package/dist/v4/core/index.js +277 -0
  211. package/dist/v4/index.d.ts +4 -0
  212. package/dist/v4/index.js +50 -0
  213. package/dist/v4/locales/index.d.ts +53 -0
  214. package/dist/v4/locales/index.js +77 -0
  215. package/dist/v4/mini/index.d.ts +2 -0
  216. package/dist/v4/mini/index.js +47 -0
  217. package/dist/v4-mini/index.d.ts +22 -0
  218. package/dist/v4-mini/index.js +75 -0
  219. package/dist/validators/any.d.ts +7 -2
  220. package/dist/validators/any.js +37 -0
  221. package/dist/validators/array.d.ts +9 -2
  222. package/dist/validators/array.js +279 -0
  223. package/dist/validators/base.d.ts +228 -5
  224. package/dist/validators/base.js +868 -0
  225. package/dist/validators/base64.d.ts +1 -2
  226. package/dist/validators/base64.js +68 -0
  227. package/dist/validators/bigint.d.ts +21 -3
  228. package/dist/validators/bigint.js +228 -0
  229. package/dist/validators/boolean.d.ts +13 -4
  230. package/dist/validators/boolean.js +142 -0
  231. package/dist/validators/codec.d.ts +9 -2
  232. package/dist/validators/codec.js +200 -0
  233. package/dist/validators/custom.d.ts +15 -2
  234. package/dist/validators/custom.js +67 -0
  235. package/dist/validators/date.d.ts +19 -3
  236. package/dist/validators/date.js +274 -0
  237. package/dist/validators/discriminated-union.d.ts +4 -3
  238. package/dist/validators/discriminated-union.js +123 -0
  239. package/dist/validators/enum.d.ts +10 -7
  240. package/dist/validators/enum.js +150 -0
  241. package/dist/validators/file.d.ts +7 -2
  242. package/dist/validators/file.js +125 -0
  243. package/dist/validators/function.d.ts +11 -5
  244. package/dist/validators/function.js +58 -0
  245. package/dist/validators/hex.d.ts +1 -2
  246. package/dist/validators/hex.js +65 -0
  247. package/dist/validators/index.d.ts +38 -38
  248. package/dist/validators/index.js +35 -5
  249. package/dist/validators/intersection.d.ts +1 -2
  250. package/dist/validators/intersection.js +116 -0
  251. package/dist/validators/json.d.ts +1 -2
  252. package/dist/validators/json.js +66 -0
  253. package/dist/validators/lazy.d.ts +5 -9
  254. package/dist/validators/lazy.js +50 -0
  255. package/dist/validators/literal.d.ts +2 -2
  256. package/dist/validators/literal.js +60 -0
  257. package/dist/validators/map.d.ts +15 -2
  258. package/dist/validators/map.js +214 -0
  259. package/dist/validators/nan.d.ts +2 -3
  260. package/dist/validators/nan.js +38 -0
  261. package/dist/validators/never.d.ts +1 -2
  262. package/dist/validators/never.js +32 -0
  263. package/dist/validators/null.d.ts +3 -3
  264. package/dist/validators/null.js +40 -0
  265. package/dist/validators/number.d.ts +80 -21
  266. package/dist/validators/number.js +423 -0
  267. package/dist/validators/object.d.ts +30 -9
  268. package/dist/validators/object.js +864 -0
  269. package/dist/validators/promise.d.ts +58 -0
  270. package/dist/validators/promise.js +111 -0
  271. package/dist/validators/record.d.ts +11 -2
  272. package/dist/validators/record.js +258 -0
  273. package/dist/validators/set.d.ts +11 -2
  274. package/dist/validators/set.js +199 -0
  275. package/dist/validators/string-bool.d.ts +7 -10
  276. package/dist/validators/string-bool.js +120 -0
  277. package/dist/validators/string-formats.d.ts +13 -4
  278. package/dist/validators/string-formats.js +135 -0
  279. package/dist/validators/string.d.ts +39 -18
  280. package/dist/validators/string.js +4 -0
  281. package/dist/validators/symbol.d.ts +8 -3
  282. package/dist/validators/symbol.js +58 -0
  283. package/dist/validators/template-literal.d.ts +1 -2
  284. package/dist/validators/template-literal.js +103 -0
  285. package/dist/validators/tuple.d.ts +15 -2
  286. package/dist/validators/tuple.js +183 -0
  287. package/dist/validators/uint8array.d.ts +3 -4
  288. package/dist/validators/uint8array.js +101 -0
  289. package/dist/validators/undefined.d.ts +3 -3
  290. package/dist/validators/undefined.js +40 -0
  291. package/dist/validators/union.d.ts +7 -4
  292. package/dist/validators/union.js +187 -0
  293. package/dist/validators/unknown.d.ts +7 -2
  294. package/dist/{chunks/unknown-SLIH1VCf.js → validators/unknown.js} +12 -3
  295. package/dist/validators/void.d.ts +3 -2
  296. package/dist/validators/void.js +44 -0
  297. package/dist/validators/xor.d.ts +2 -3
  298. package/dist/validators/xor.js +66 -0
  299. package/package.json +116 -31
  300. package/dist/chunks/bigint-DgsCr2dC.js +0 -1709
  301. package/dist/chunks/bigint-DgsCr2dC.js.map +0 -1
  302. package/dist/chunks/date-ODue_rtq.js.map +0 -1
  303. package/dist/chunks/index-BZqWZvVe.js +0 -426
  304. package/dist/chunks/index-BZqWZvVe.js.map +0 -1
  305. package/dist/chunks/index-CETyGkrv.js.map +0 -1
  306. package/dist/chunks/json-o20GFhTh.js +0 -2021
  307. package/dist/chunks/json-o20GFhTh.js.map +0 -1
  308. package/dist/chunks/unknown-SLIH1VCf.js.map +0 -1
  309. package/dist/cjs/errors.cjs.map +0 -1
  310. package/dist/cjs/index.cjs.map +0 -1
  311. package/dist/cjs/locales/index.cjs.map +0 -1
  312. package/dist/cjs/locales/lazy.cjs.map +0 -1
  313. package/dist/cjs/mini.cjs.map +0 -1
  314. package/dist/cli/bin.d.ts.map +0 -1
  315. package/dist/cli/commands/benchmark.d.ts.map +0 -1
  316. package/dist/cli/commands/validate.d.ts.map +0 -1
  317. package/dist/cli/index.d.ts.map +0 -1
  318. package/dist/codecs/index.d.ts.map +0 -1
  319. package/dist/codecs/index.js.map +0 -1
  320. package/dist/coercion/bigint.d.ts.map +0 -1
  321. package/dist/coercion/boolean.d.ts.map +0 -1
  322. package/dist/coercion/date.d.ts.map +0 -1
  323. package/dist/coercion/index.d.ts.map +0 -1
  324. package/dist/coercion/index.js.map +0 -1
  325. package/dist/coercion/number.d.ts.map +0 -1
  326. package/dist/coercion/string.d.ts.map +0 -1
  327. package/dist/compat/emitter.d.ts.map +0 -1
  328. package/dist/compat/emitter.js.map +0 -1
  329. package/dist/compat/index.d.ts.map +0 -1
  330. package/dist/compat/result.d.ts.map +0 -1
  331. package/dist/compat/result.js.map +0 -1
  332. package/dist/errors.d.ts.map +0 -1
  333. package/dist/errors.js.map +0 -1
  334. package/dist/events.d.ts.map +0 -1
  335. package/dist/index.d.ts.map +0 -1
  336. package/dist/index.js.map +0 -1
  337. package/dist/kernel.d.ts.map +0 -1
  338. package/dist/kernel.js.map +0 -1
  339. package/dist/locales/af.d.ts.map +0 -1
  340. package/dist/locales/af.js.map +0 -1
  341. package/dist/locales/ar.d.ts.map +0 -1
  342. package/dist/locales/ar.js.map +0 -1
  343. package/dist/locales/backup-en.d.ts +0 -3
  344. package/dist/locales/backup-en.d.ts.map +0 -1
  345. package/dist/locales/bn.d.ts.map +0 -1
  346. package/dist/locales/bn.js.map +0 -1
  347. package/dist/locales/da.d.ts.map +0 -1
  348. package/dist/locales/da.js.map +0 -1
  349. package/dist/locales/de.d.ts.map +0 -1
  350. package/dist/locales/de.js.map +0 -1
  351. package/dist/locales/en.d.ts.map +0 -1
  352. package/dist/locales/en.js.map +0 -1
  353. package/dist/locales/es-MX.d.ts.map +0 -1
  354. package/dist/locales/es-MX.js.map +0 -1
  355. package/dist/locales/es.d.ts.map +0 -1
  356. package/dist/locales/es.js.map +0 -1
  357. package/dist/locales/fi.d.ts.map +0 -1
  358. package/dist/locales/fi.js.map +0 -1
  359. package/dist/locales/fr.d.ts.map +0 -1
  360. package/dist/locales/fr.js.map +0 -1
  361. package/dist/locales/hi.d.ts.map +0 -1
  362. package/dist/locales/hi.js.map +0 -1
  363. package/dist/locales/id.d.ts.map +0 -1
  364. package/dist/locales/id.js.map +0 -1
  365. package/dist/locales/index.d.ts.map +0 -1
  366. package/dist/locales/index.js.map +0 -1
  367. package/dist/locales/it.d.ts.map +0 -1
  368. package/dist/locales/it.js.map +0 -1
  369. package/dist/locales/ja.d.ts.map +0 -1
  370. package/dist/locales/ja.js.map +0 -1
  371. package/dist/locales/ko.d.ts.map +0 -1
  372. package/dist/locales/ko.js.map +0 -1
  373. package/dist/locales/lazy.d.ts.map +0 -1
  374. package/dist/locales/lazy.js.map +0 -1
  375. package/dist/locales/nl.d.ts.map +0 -1
  376. package/dist/locales/nl.js.map +0 -1
  377. package/dist/locales/no.d.ts.map +0 -1
  378. package/dist/locales/no.js.map +0 -1
  379. package/dist/locales/pl.d.ts.map +0 -1
  380. package/dist/locales/pl.js.map +0 -1
  381. package/dist/locales/pt-BR.d.ts.map +0 -1
  382. package/dist/locales/pt-BR.js.map +0 -1
  383. package/dist/locales/pt.d.ts.map +0 -1
  384. package/dist/locales/pt.js.map +0 -1
  385. package/dist/locales/ru.d.ts.map +0 -1
  386. package/dist/locales/ru.js.map +0 -1
  387. package/dist/locales/sv.d.ts.map +0 -1
  388. package/dist/locales/sv.js.map +0 -1
  389. package/dist/locales/sw.d.ts.map +0 -1
  390. package/dist/locales/sw.js.map +0 -1
  391. package/dist/locales/th.d.ts.map +0 -1
  392. package/dist/locales/th.js.map +0 -1
  393. package/dist/locales/tr.d.ts.map +0 -1
  394. package/dist/locales/tr.js.map +0 -1
  395. package/dist/locales/types.d.ts.map +0 -1
  396. package/dist/locales/vi.d.ts.map +0 -1
  397. package/dist/locales/vi.js.map +0 -1
  398. package/dist/locales/zh.d.ts.map +0 -1
  399. package/dist/locales/zh.js.map +0 -1
  400. package/dist/logger.d.ts.map +0 -1
  401. package/dist/mini.d.ts.map +0 -1
  402. package/dist/mini.js.map +0 -1
  403. package/dist/pigment.d.ts.map +0 -1
  404. package/dist/pigment.js.map +0 -1
  405. package/dist/plugins/index.d.ts.map +0 -1
  406. package/dist/plugins/types.d.ts.map +0 -1
  407. package/dist/utils/codec-utils.d.ts.map +0 -1
  408. package/dist/utils/deep-merge.d.ts.map +0 -1
  409. package/dist/utils/ip-validation.d.ts.map +0 -1
  410. package/dist/utils/security.d.ts.map +0 -1
  411. package/dist/validators/any.d.ts.map +0 -1
  412. package/dist/validators/array.d.ts.map +0 -1
  413. package/dist/validators/base.d.ts.map +0 -1
  414. package/dist/validators/base64.d.ts.map +0 -1
  415. package/dist/validators/bigint.d.ts.map +0 -1
  416. package/dist/validators/boolean.d.ts.map +0 -1
  417. package/dist/validators/codec.d.ts.map +0 -1
  418. package/dist/validators/custom.d.ts.map +0 -1
  419. package/dist/validators/date.d.ts.map +0 -1
  420. package/dist/validators/discriminated-union.d.ts.map +0 -1
  421. package/dist/validators/enum.d.ts.map +0 -1
  422. package/dist/validators/file.d.ts.map +0 -1
  423. package/dist/validators/function.d.ts.map +0 -1
  424. package/dist/validators/hex.d.ts.map +0 -1
  425. package/dist/validators/index.d.ts.map +0 -1
  426. package/dist/validators/index.js.map +0 -1
  427. package/dist/validators/intersection.d.ts.map +0 -1
  428. package/dist/validators/json.d.ts.map +0 -1
  429. package/dist/validators/lazy.d.ts.map +0 -1
  430. package/dist/validators/literal.d.ts.map +0 -1
  431. package/dist/validators/map.d.ts.map +0 -1
  432. package/dist/validators/nan.d.ts.map +0 -1
  433. package/dist/validators/never.d.ts.map +0 -1
  434. package/dist/validators/null.d.ts.map +0 -1
  435. package/dist/validators/number.d.ts.map +0 -1
  436. package/dist/validators/object.d.ts.map +0 -1
  437. package/dist/validators/record.d.ts.map +0 -1
  438. package/dist/validators/set.d.ts.map +0 -1
  439. package/dist/validators/string-bool.d.ts.map +0 -1
  440. package/dist/validators/string-formats.d.ts.map +0 -1
  441. package/dist/validators/string.d.ts.map +0 -1
  442. package/dist/validators/symbol.d.ts.map +0 -1
  443. package/dist/validators/template-literal.d.ts.map +0 -1
  444. package/dist/validators/tuple.d.ts.map +0 -1
  445. package/dist/validators/uint8array.d.ts.map +0 -1
  446. package/dist/validators/undefined.d.ts.map +0 -1
  447. package/dist/validators/union.d.ts.map +0 -1
  448. package/dist/validators/unknown.d.ts.map +0 -1
  449. package/dist/validators/void.d.ts.map +0 -1
  450. package/dist/validators/xor.d.ts.map +0 -1
package/CHANGELOG.md CHANGED
@@ -5,6 +5,80 @@ All notable changes to VLD will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [2.1.0] - 2026-06-16
9
+
10
+ ### Added
11
+
12
+ - Added first-class Zod drop-in package subpaths:
13
+ - `@oxog/vld/v3`
14
+ - `@oxog/vld/v4`
15
+ - `@oxog/vld/v4-mini`
16
+ - `@oxog/vld/v4/mini`
17
+ - `@oxog/vld/v4/core`
18
+ - `@oxog/vld/v4/locales`
19
+ - `@oxog/vld/v4/locales/*`
20
+ - Added Zod-style mini aliases and helpers for `v4-mini` and `v4/mini`, including `ZodMini*` class aliases, `pick`, `omit`, `partial`, `required`, `extend`, `safeExtend`, `merge`, `catchall`, `minimum`, `maximum`, and `_default`.
21
+ - Added Zod-style `v4/locales` named locale functions.
22
+ - Added `v4/core` compatibility exports for the full Zod core export-name/type surface, plus common Zod core factory calling conventions.
23
+ - Added `verify:drop-in`, a real TypeScript fixture app that compiles and runs once with `zod` and once with built VLD, then compares normalized runtime output.
24
+ - Added release guards for Zod latest parity, package exports, published types, install smoke tests, package budgets, bundle budgets, drop-in fixture behavior, runtime performance, startup, and memory.
25
+
26
+ ### Changed
27
+
28
+ - Strengthened `release:check` to include `verify:drop-in`.
29
+ - Updated package metadata and budgets for the broader drop-in compatibility surface.
30
+ - Kept validator `safeParse` failures aligned with public `VldError` formatting helpers across primitive, collection, scalar, and special validators.
31
+
32
+ ### Verified
33
+
34
+ - Tested against npm latest `zod@4.4.3`.
35
+ - 82 test suites and 2160 tests passing.
36
+ - 100% statement, branch, and line coverage.
37
+ - Zod subpath export parity has zero missing exports and zero type mismatches for `zod/v4`, `zod/v4-mini`, `zod/v4/mini`, `zod/v4/core`, and `zod/v4/locales`.
38
+ - Latest release gate snapshot: runtime guard average 11.81x faster than Zod, startup total 1.50x faster, and 4.77x less retained heap.
39
+
40
+ ## [2.0.3] - 2026-05-08
41
+
42
+ ### 🐛 Bug Fixes
43
+
44
+ #### **VldPromise - Thenable Check Before Promise.resolve**
45
+ - **File**: `src/validators/promise.ts`
46
+ - **Fix**: `_isThenable()` check now happens BEFORE `Promise.resolve()` wrapping
47
+ - **Issue**: Everything becomes thenable after Promise.resolve wrapping
48
+ - **Impact**: Correctly rejects non-Promise, non-thenable inputs
49
+
50
+ ### ✨ New Features
51
+
52
+ #### **Number Bit-Width Validators**
53
+ - **Files**: `src/validators/number.ts`
54
+ - **Added**: `uint32()`, `uint64()`, `int32()`, `int64()`, `float32()`, `float64()`
55
+ - **Use case**: Validate integers/floats within specific bit ranges
56
+
57
+ #### **VldMeta - Metadata Support**
58
+ - **File**: `src/validators/base.ts`
59
+ - **Added**: `VldMeta` class and `SchemaMetadata` interface
60
+ - **Methods**: `describe()`, `meta()` for attaching documentation
61
+
62
+ #### **exactOptional() Validator**
63
+ - **File**: `src/validators/base.ts`
64
+ - **Added**: `VldExactOptional` for strict optional handling
65
+ - **Use case**: When `undefined` should only appear if explicitly set
66
+
67
+ ### 📝 Documentation
68
+
69
+ #### **README Updates**
70
+ - Coverage badge: 98.34% (was 98.99%)
71
+ - Test count: 1914 tests (was 1858)
72
+ - Note: Increased test suite size slightly reduced percentage but improved coverage
73
+
74
+ ### ✅ Testing
75
+
76
+ #### **Coverage Test Suite Expansion**
77
+ - Added `tests/validators/promise-coverage.test.ts` - 19 tests for Promise validator
78
+ - Added `tests/validators/base-coverage.test.ts` - VldMeta, exactOptional, describe tests
79
+ - Added `tests/validators/string-formats-coverage.test.ts` - xid, guid, httpUrl, hash tests
80
+ - Total: 76 test suites, 1914 tests passing
81
+
8
82
  ## [2.0.2] - 2026-02-27
9
83
 
10
84
  ### ⚡ Performance Optimizations
@@ -499,4 +573,4 @@ VLD continues to outperform Zod across all benchmarks:
499
573
 
500
574
  ---
501
575
 
502
- For more details, see the [GitHub Releases](https://github.com/ersinkoc/vld/releases)
576
+ For more details, see the [GitHub Releases](https://github.com/ersinkoc/vld/releases)
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Ersin Koc
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ersin Koc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # VLD - Fast & Lightweight TypeScript Validation Library
2
2
 
3
- [![NPM Version](https://img.shields.io/npm/v/@oxog/vld.svg)](https://www.npmjs.com/package/@oxog/vld) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/) [![Zero Dependencies](https://img.shields.io/badge/Dependencies-0-green.svg)](package.json) [![Test Coverage](https://img.shields.io/badge/Coverage-98.99%25-brightgreen.svg)](package.json)
3
+ [![NPM Version](https://img.shields.io/npm/v/@oxog/vld.svg)](https://www.npmjs.com/package/@oxog/vld) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/) [![Zero Dependencies](https://img.shields.io/badge/Dependencies-0-green.svg)](package.json) [![Test Coverage](https://img.shields.io/badge/Coverage-100%25-brightgreen.svg)](package.json)
4
4
 
5
- VLD is a blazing-fast, type-safe validation library for TypeScript and JavaScript with **full Zod feature parity**. Built with performance in mind, it provides a simple and intuitive API while maintaining excellent type inference and 27+ language internationalization support.
5
+ VLD is a blazing-fast, type-safe validation library for TypeScript and JavaScript with **Zod-compatible root and subpath APIs**. Built with performance in mind, it provides a simple and intuitive API while maintaining excellent type inference and 27+ language internationalization support.
6
6
 
7
7
  ## Table of Contents
8
8
 
@@ -34,8 +34,9 @@ VLD is a blazing-fast, type-safe validation library for TypeScript and JavaScrip
34
34
  - **Composable**: Chain validations for complex schemas
35
35
  - **Advanced Error Formatting**: Tree, pretty, and flatten error utilities
36
36
  - **Multi-language**: Built-in support for 27+ languages
37
- - **98.99% Test Coverage**: Rigorously tested with 1858 passing tests
38
- - **Industry Leading Performance**: 1.98x faster than Zod on average
37
+ - **100% Statement / Branch / Line Coverage**: Rigorously tested with 2160 passing tests
38
+ - **Release-Gated Performance**: CI guards require VLD to stay faster than the latest stable Zod across runtime, startup, and memory benchmarks
39
+ - **Drop-in App Verification**: A real TypeScript fixture is compiled and run once with `zod` and once with built VLD, then normalized runtime output is compared
39
40
 
40
41
  ### Advanced Zod-Compatible Features
41
42
  - **Type Coercion**: `v.coerce.string()`, `v.coerce.number()`, `v.coerce.boolean()`, etc.
@@ -149,14 +150,18 @@ await setLocaleAsync('tr'); // Loads Turkish on demand
149
150
 
150
151
  VLD is designed for speed and efficiency with recent optimizations delivering exceptional performance:
151
152
 
152
- ### Speed Benchmarks (v1.5.0)
153
- - **3.25x faster** for email validation
154
- - **3.23x faster** for number validation
155
- - **3.16x faster** for optional validation
156
- - **2.73x faster** for safeParse operations
157
- - **2.08x faster** for enum validation
158
- - **2.03x faster** for simple string validation
159
- - **1.98x faster** overall average performance
153
+ ### Release-Gated Speed Benchmarks (v2.1.0 vs Zod 4.4.3)
154
+ - Runtime guard: VLD must stay at least 1.2x faster on every guarded hot path and keep at least a 3x average ratio
155
+ - Startup guard: VLD must keep at least 1.1x faster import, 1.25x faster total startup, and 1.25x faster warm parse ratios than Zod
156
+ - Memory guard: VLD must keep at least 2x lower total retained heap, 1.5x higher aggregate throughput, and no guarded case below 1.1x speed
157
+
158
+ ### Recent Local Benchmark Snapshot
159
+ - **52.92x faster** for nullish validation
160
+ - **46.58x faster** for catch validation
161
+ - **27.62x faster** for number validation
162
+ - **14.88x faster** for bigint validation
163
+ - **10.71x faster** for nullable validation
164
+ - **Over 10x faster** average guarded runtime ratio in recent release checks
160
165
 
161
166
  ### Optimizations
162
167
  - **110x improvement** in union type validation
@@ -167,10 +172,10 @@ VLD is designed for speed and efficiency with recent optimizations delivering ex
167
172
  - **Pre-computed keys** with Set for O(1) lookups
168
173
 
169
174
  ### Memory Efficiency
170
- - **98% less memory** for validator creation
171
- - **51% less memory** for data parsing
172
- - **86% less memory** for error handling
173
- - **78% less memory** overall average
175
+ - **18.13x less memory** for schema creation
176
+ - **6.20x less memory** for union validation
177
+ - **2.81x less memory** for simple string validation
178
+ - **4.85x less memory** overall
174
179
 
175
180
  ### A Note on Real-World Benchmarking
176
181
 
@@ -527,7 +532,8 @@ v.function()
527
532
  ### Type Inference
528
533
 
529
534
  ```typescript
530
- import { v, Infer } from '@oxog/vld';
535
+ import { v } from '@oxog/vld';
536
+ import type { Infer } from '@oxog/vld';
531
537
 
532
538
  const schema = v.object({
533
539
  name: v.string(),
@@ -542,8 +548,8 @@ type User = Infer<typeof schema>;
542
548
  ### Error Formatting Types
543
549
 
544
550
  ```typescript
545
- import {
546
- VldError, // Main error class
551
+ import { VldError } from '@oxog/vld';
552
+ import type {
547
553
  VldIssue, // Individual validation issue
548
554
  VldErrorTree, // Nested error structure
549
555
  VldFlattenedError // Flattened error structure
@@ -1095,8 +1101,8 @@ VLD is designed as a compelling alternative to Zod, offering full feature parity
1095
1101
 
1096
1102
  | Feature | VLD | Zod |
1097
1103
  | ----------------------- | ---------------------------------- | ------------------------------------ |
1098
- | **Performance** | **~1.98x faster** (average) | Baseline |
1099
- | **Memory Usage** | **~78% less** overall | Baseline |
1104
+ | **Performance** | **Release-gated faster runtime, startup, and memory paths** | Baseline |
1105
+ | **Memory Usage** | **~4.85x less** overall | Baseline |
1100
1106
  | **Internationalization**| **Built-in (27+ languages)** | Requires third-party library |
1101
1107
  | **Dependencies** | **Zero** | `zod-i18n` for locales |
1102
1108
  | **Bundle Size** | Smaller | Larger |
@@ -1104,7 +1110,7 @@ VLD is designed as a compelling alternative to Zod, offering full feature parity
1104
1110
  | **Plugin System** | **Built-in** | Not available |
1105
1111
  | **Result Pattern** | **Built-in** | Not available |
1106
1112
  | **CLI Tools** | **Built-in** | Not available |
1107
- | **Codecs** | Built-in, bidirectional | Via external `zod-codecs` |
1113
+ | **Codecs** | Built-in, bidirectional | Built-in |
1108
1114
  | **Type Inference** | Excellent | Excellent |
1109
1115
 
1110
1116
  ### Seamless Migration from Zod
@@ -1119,26 +1125,75 @@ import { v } from '@oxog/vld';
1119
1125
  const schema = v.string().email();
1120
1126
  ```
1121
1127
 
1128
+ ### Drop-in Package Subpaths
1129
+
1130
+ VLD also exposes Zod-compatible package subpaths so applications that import Zod 4 entry points can migrate by changing the package name:
1131
+
1132
+ ```typescript
1133
+ // Before
1134
+ import { z } from 'zod';
1135
+ import * as core from 'zod/v4/core';
1136
+ import * as mini from 'zod/v4-mini';
1137
+ import * as locales from 'zod/v4/locales';
1138
+
1139
+ // After
1140
+ import { z } from '@oxog/vld';
1141
+ import * as core from '@oxog/vld/v4/core';
1142
+ import * as mini from '@oxog/vld/v4-mini';
1143
+ import * as locales from '@oxog/vld/v4/locales';
1144
+ ```
1145
+
1146
+ Release checks enforce zero missing exports and zero `typeof` mismatches for `zod/v4`, `zod/v4-mini`, `zod/v4/mini`, `zod/v4/core`, and `zod/v4/locales` against the installed latest Zod.
1147
+
1148
+ ### Real App Drop-in Verification
1149
+
1150
+ `npm run verify:drop-in` creates two temporary TypeScript applications from the same fixture:
1151
+
1152
+ - One imports and runs against real `zod`.
1153
+ - One imports and runs against the locally built `@oxog/vld` package.
1154
+ - The fixture exercises root APIs, `v4`, `v4-mini`, `v4/core`, `v4/locales`, parsing, error formatting, JSON Schema output, mini helpers, and core factories.
1155
+ - The normalized runtime outputs must match exactly.
1156
+
1122
1157
  ## Benchmarks
1123
1158
 
1124
1159
  ### Performance Results
1125
1160
 
1126
- | Test Case | VLD Performance | Improvement |
1161
+ Median of 11 samples per case against Zod 4.4.3, the latest stable release at the time of measurement. The release gate also runs focused runtime, startup, memory, package, install, security, Zod parity, and real drop-in app checks before publishing.
1162
+
1163
+ | Test Case | VLD Median Performance | Improvement |
1127
1164
  |-----------|----------------|-------------|
1128
- | Simple String | 73.0M ops/sec | **2.03x faster** |
1129
- | Email Validation | 21.8M ops/sec | **3.25x faster** |
1130
- | Number Validation | 36.3M ops/sec | **3.23x faster** |
1131
- | Simple Object | 7.1M ops/sec | **1.02x faster** |
1132
- | Complex Object | 1.9M ops/sec | **1.34x faster** |
1133
- | Array Validation | 7.5M ops/sec | **1.35x faster** |
1134
- | Union Types | 7.1M ops/sec | **1.29x faster** |
1135
- | Optional Values | 36.1M ops/sec | **3.16x faster** |
1136
- | SafeParse | 60.0M ops/sec | **2.73x faster** |
1137
- | Type Coercion | 20.4M ops/sec | **1.01x faster** |
1138
- | Enum Validation | 60.3M ops/sec | **2.08x faster** |
1139
- | Discriminated Union | 3.6M ops/sec | Zod 1.27x faster |
1140
-
1141
- **VLD won 11/12 tests | Average: 1.98x faster than Zod**
1165
+ | Simple String | 719.2M ops/sec | **3.40x faster** |
1166
+ | Email Validation | 22.1M ops/sec | **2.87x faster** |
1167
+ | Top-level Email Format | 22.8M ops/sec | **3.66x faster** |
1168
+ | StringBool Validation | 32.7M ops/sec | **3.44x faster** |
1169
+ | Number Validation | 226.2M ops/sec | **27.62x faster** |
1170
+ | Simple Object | 37.7M ops/sec | **1.40x faster** |
1171
+ | Complex Object | 2.3M ops/sec | **1.02x faster** |
1172
+ | Array Validation | 39.8M ops/sec | **6.74x faster** |
1173
+ | Union Types | 38.1M ops/sec | **4.10x faster** |
1174
+ | Optional Values | 236.9M ops/sec | **7.57x faster** |
1175
+ | Nullable Values | 224.7M ops/sec | **10.71x faster** |
1176
+ | Nullish Values | 228.4M ops/sec | **52.92x faster** |
1177
+ | Default Values | 207.8M ops/sec | **9.71x faster** |
1178
+ | Catch Values | 232.1M ops/sec | **46.58x faster** |
1179
+ | SafeParse | 162.0M ops/sec | **1.80x faster** |
1180
+ | Type Coercion | 204.5M ops/sec | **8.72x faster** |
1181
+ | Enum Validation | 180.3M ops/sec | **1.32x faster** |
1182
+ | Discriminated Union | 19.2M ops/sec | **1.79x faster** |
1183
+ | Tuple Validation | 50.0M ops/sec | **7.99x faster** |
1184
+ | Record Validation | 10.7M ops/sec | **5.63x faster** |
1185
+ | Set Validation | 18.9M ops/sec | **1.84x faster** |
1186
+ | Map Validation | 14.8M ops/sec | **2.37x faster** |
1187
+ | BigInt Validation | 164.8M ops/sec | **14.88x faster** |
1188
+ | Date Validation | 227.2M ops/sec | **2.57x faster** |
1189
+ | Symbol Validation | 230.0M ops/sec | **1.01x faster** |
1190
+ | Any Validation | 232.5M ops/sec | **1.01x faster** |
1191
+ | Unknown Validation | 234.9M ops/sec | **1.04x faster** |
1192
+ | Function Validation | 233.6M ops/sec | **3.52x faster** |
1193
+ | Template Literal Validation | 39.3M ops/sec | **1.15x faster** |
1194
+ | Promise Async Validation | 6.3M ops/sec | **1.38x faster** |
1195
+
1196
+ **VLD won 30/30 snapshot tests. Release checks additionally enforce runtime, startup, memory, Zod subpath parity, and real drop-in app guard thresholds against Zod.**
1142
1197
 
1143
1198
  ### Run Benchmarks
1144
1199
 
@@ -1146,6 +1201,15 @@ const schema = v.string().email();
1146
1201
  # Quick performance comparison
1147
1202
  npm run benchmark
1148
1203
 
1204
+ # Median-based stable comparison
1205
+ npm run benchmark:stable
1206
+
1207
+ # Fast CI-friendly performance regression guard
1208
+ npm run benchmark:guard
1209
+
1210
+ # Full release gate: lint, source and published types, tests, exports, package and install checks, security audit, Zod parity, real drop-in app verification, and performance guards
1211
+ npm run release:check
1212
+
1149
1213
  # Memory usage comparison
1150
1214
  npm run benchmark:memory
1151
1215
 
@@ -0,0 +1,81 @@
1
+ function serializeIssue(issue) {
2
+ const result = {
3
+ code: issue.code,
4
+ path: issue.path,
5
+ message: issue.message
6
+ };
7
+ if (issue.expected !== undefined)
8
+ result.expected = issue.expected;
9
+ if (issue.received !== undefined)
10
+ result.received = issue.received;
11
+ if (issue.keys !== undefined)
12
+ result.keys = issue.keys;
13
+ if (issue.minimum !== undefined)
14
+ result.minimum = issue.minimum;
15
+ if (issue.maximum !== undefined)
16
+ result.maximum = issue.maximum;
17
+ if (issue.exact !== undefined)
18
+ result.exact = issue.exact;
19
+ if (issue.inclusive !== undefined)
20
+ result.inclusive = issue.inclusive;
21
+ return result;
22
+ }
23
+ function deserializeIssue(issue) {
24
+ const result = {
25
+ code: issue.code,
26
+ path: issue.path,
27
+ message: issue.message
28
+ };
29
+ if (issue.expected !== undefined)
30
+ result.expected = issue.expected;
31
+ if (issue.received !== undefined)
32
+ result.received = issue.received;
33
+ if (issue.keys !== undefined)
34
+ result.keys = issue.keys;
35
+ if (issue.minimum !== undefined)
36
+ result.minimum = issue.minimum;
37
+ if (issue.maximum !== undefined)
38
+ result.maximum = issue.maximum;
39
+ if (issue.exact !== undefined)
40
+ result.exact = issue.exact;
41
+ if (issue.inclusive !== undefined)
42
+ result.inclusive = issue.inclusive;
43
+ return result;
44
+ }
45
+ class VldError extends Error {
46
+ constructor(issues) {
47
+ const firstIssue = issues[0];
48
+ const message = issues.length === 1 && firstIssue !== undefined
49
+ ? firstIssue.message
50
+ : `${issues.length} validation errors`;
51
+ super(message);
52
+ this.name = 'VldError';
53
+ this.issues = issues;
54
+ if (Error.captureStackTrace) {
55
+ Error.captureStackTrace(this, VldError);
56
+ }
57
+ }
58
+ get firstError() {
59
+ return this.issues[0];
60
+ }
61
+ get formattedErrors() {
62
+ return this.issues.map((issue) => issue.message);
63
+ }
64
+ toJSON() {
65
+ return {
66
+ name: this.name,
67
+ message: this.message,
68
+ code: 'VLD_VALIDATION_ERROR',
69
+ issues: this.issues.map(serializeIssue)
70
+ };
71
+ }
72
+ static fromJSON(json) {
73
+ const issues = json.issues.map(deserializeIssue);
74
+ return new VldError(issues);
75
+ }
76
+ static isVldError(value) {
77
+ return value instanceof VldError;
78
+ }
79
+ }
80
+
81
+ export { VldError as V };