@oxog/vld 3.0.1 → 3.0.5

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 (127) hide show
  1. package/CHANGELOG.md +985 -781
  2. package/README.md +28 -11
  3. package/dist/chunks/index-Bn85LHAC.js +1 -0
  4. package/dist/cjs/chunks/index-DJwZFerZ.cjs +1 -0
  5. package/dist/cjs/cli/bin.cjs +1 -1
  6. package/dist/cjs/compile.cjs +1 -1
  7. package/dist/cjs/index.cjs +1 -1
  8. package/dist/cjs/locales/af.cjs +1 -1
  9. package/dist/cjs/locales/ar.cjs +1 -1
  10. package/dist/cjs/locales/bn.cjs +1 -1
  11. package/dist/cjs/locales/da.cjs +1 -1
  12. package/dist/cjs/locales/de.cjs +1 -1
  13. package/dist/cjs/locales/en.cjs +1 -1
  14. package/dist/cjs/locales/es-MX.cjs +1 -1
  15. package/dist/cjs/locales/es.cjs +1 -1
  16. package/dist/cjs/locales/fi.cjs +1 -1
  17. package/dist/cjs/locales/fr.cjs +1 -1
  18. package/dist/cjs/locales/gu.cjs +1 -1
  19. package/dist/cjs/locales/hi.cjs +1 -1
  20. package/dist/cjs/locales/id.cjs +1 -1
  21. package/dist/cjs/locales/index.cjs +1 -1
  22. package/dist/cjs/locales/it.cjs +1 -1
  23. package/dist/cjs/locales/ja.cjs +1 -1
  24. package/dist/cjs/locales/kn.cjs +1 -1
  25. package/dist/cjs/locales/ko.cjs +1 -1
  26. package/dist/cjs/locales/ne.cjs +1 -1
  27. package/dist/cjs/locales/nl.cjs +1 -1
  28. package/dist/cjs/locales/no.cjs +1 -1
  29. package/dist/cjs/locales/pl.cjs +1 -1
  30. package/dist/cjs/locales/pt-BR-v4.cjs +1 -1
  31. package/dist/cjs/locales/pt-BR.cjs +1 -1
  32. package/dist/cjs/locales/pt.cjs +1 -1
  33. package/dist/cjs/locales/ru.cjs +1 -1
  34. package/dist/cjs/locales/sk.cjs +1 -1
  35. package/dist/cjs/locales/sv.cjs +1 -1
  36. package/dist/cjs/locales/sw.cjs +1 -1
  37. package/dist/cjs/locales/tg.cjs +1 -0
  38. package/dist/cjs/locales/th.cjs +1 -1
  39. package/dist/cjs/locales/tr.cjs +1 -1
  40. package/dist/cjs/locales/vi.cjs +1 -1
  41. package/dist/cjs/locales/zh.cjs +1 -1
  42. package/dist/cjs/v3/index.cjs +1 -1
  43. package/dist/cjs/v4/core/index.cjs +1 -1
  44. package/dist/cjs/v4/index.cjs +1 -1
  45. package/dist/cjs/v4/locales/index.cjs +1 -1
  46. package/dist/cjs/v4/mini/index.cjs +1 -1
  47. package/dist/cjs/v4-mini/index.cjs +1 -1
  48. package/dist/cjs/validators/base.cjs +1 -1
  49. package/dist/cjs/validators/custom.cjs +1 -1
  50. package/dist/cjs/validators/number-v2.cjs +1 -1
  51. package/dist/cjs/validators/object.cjs +1 -1
  52. package/dist/cjs/validators/promise.cjs +1 -1
  53. package/dist/cjs/validators/string-formats.cjs +1 -1
  54. package/dist/cjs/validators/string.cjs +1 -1
  55. package/dist/cli/bin.js +1 -1
  56. package/dist/compile.d.ts +15 -0
  57. package/dist/compile.js +1 -1
  58. package/dist/index.d.ts +50 -17
  59. package/dist/index.js +1 -1
  60. package/dist/locales/af.js +1 -1
  61. package/dist/locales/ar.js +1 -1
  62. package/dist/locales/bn.js +1 -1
  63. package/dist/locales/da.js +1 -1
  64. package/dist/locales/de.js +1 -1
  65. package/dist/locales/en.js +1 -1
  66. package/dist/locales/es-MX.js +1 -1
  67. package/dist/locales/es.js +1 -1
  68. package/dist/locales/fi.js +1 -1
  69. package/dist/locales/fr.js +1 -1
  70. package/dist/locales/gu.js +1 -1
  71. package/dist/locales/hi.js +1 -1
  72. package/dist/locales/id.js +1 -1
  73. package/dist/locales/index.js +1 -1
  74. package/dist/locales/it.js +1 -1
  75. package/dist/locales/ja.js +1 -1
  76. package/dist/locales/kn.js +1 -1
  77. package/dist/locales/ko.js +1 -1
  78. package/dist/locales/ne.js +1 -1
  79. package/dist/locales/nl.js +1 -1
  80. package/dist/locales/no.js +1 -1
  81. package/dist/locales/pl.js +1 -1
  82. package/dist/locales/pt-BR-v4.js +1 -1
  83. package/dist/locales/pt-BR.js +1 -1
  84. package/dist/locales/pt.js +1 -1
  85. package/dist/locales/ru.js +1 -1
  86. package/dist/locales/sk.js +1 -1
  87. package/dist/locales/sv.js +1 -1
  88. package/dist/locales/sw.js +1 -1
  89. package/dist/locales/tg.d.ts +2 -0
  90. package/dist/locales/tg.js +1 -0
  91. package/dist/locales/th.js +1 -1
  92. package/dist/locales/tr.js +1 -1
  93. package/dist/locales/types.d.ts +1 -0
  94. package/dist/locales/vi.js +1 -1
  95. package/dist/locales/zh.js +1 -1
  96. package/dist/utils/json-schema.d.ts +4 -0
  97. package/dist/v3/index.js +1 -1
  98. package/dist/v4/core/index.d.ts +12 -2
  99. package/dist/v4/core/index.js +1 -1
  100. package/dist/v4/index.js +1 -1
  101. package/dist/v4/locales/index.d.ts +1 -0
  102. package/dist/v4/locales/index.js +1 -1
  103. package/dist/v4/mini/index.js +1 -1
  104. package/dist/v4-mini/index.d.ts +1 -1
  105. package/dist/v4-mini/index.js +1 -1
  106. package/dist/validators/array-v2.d.ts +1 -1
  107. package/dist/validators/base.d.ts +29 -0
  108. package/dist/validators/base.js +1 -1
  109. package/dist/validators/bigint-v2.d.ts +1 -1
  110. package/dist/validators/custom.d.ts +21 -1
  111. package/dist/validators/custom.js +1 -1
  112. package/dist/validators/date-v2.d.ts +1 -1
  113. package/dist/validators/number-v2.d.ts +1 -1
  114. package/dist/validators/number-v2.js +1 -1
  115. package/dist/validators/object-v2.d.ts +5 -5
  116. package/dist/validators/object.js +1 -1
  117. package/dist/validators/promise.d.ts +7 -0
  118. package/dist/validators/promise.js +1 -1
  119. package/dist/validators/string-formats.d.ts +14 -1
  120. package/dist/validators/string-formats.js +1 -1
  121. package/dist/validators/string-v2.d.ts +2 -2
  122. package/dist/validators/string.d.ts +10 -0
  123. package/dist/validators/string.js +1 -1
  124. package/dist/validators/union-v2.d.ts +1 -1
  125. package/package.json +246 -245
  126. package/dist/chunks/index-CKPStM3V.js +0 -1
  127. package/dist/cjs/chunks/index-lejEpLfv.cjs +0 -1
@@ -1 +1 @@
1
- "use strict";var e=require("./base.cjs"),s=require("../locales/runtime.cjs"),r=require("../chunks/ip-validation-BZqPamPC.cjs"),t=require("../chunks/errors-core-C0mA6tfa.cjs");require("../registry.cjs"),require("../locales/en.cjs");const i={email:/^[^\s@]+@[^\s@]+\.[^\s@]+$/,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,url:/^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)$/,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]?)$/,uuidv4:/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,uuidv6:/^[0-9a-f]{8}-[0-9a-f]{4}-6[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,uuidv7:/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,emoji:/^(?:\p{Emoji_Presentation}|\p{Emoji}\uFE0F)(?:\u200D(?:\p{Emoji_Presentation}|\p{Emoji}\uFE0F))*$/u,base64:/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,base64url:/^[A-Za-z0-9_-]*$/,jwt:/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$/,nanoid:/^[A-Za-z0-9_-]{21}$/,cuid:/^c[^\s-]{8,}$/i,cuid2:/^[0-9a-z]+$/,ulid:/^[0-9A-HJKMNP-TV-Z]{26}$/,cidrv4:/^(?:(?: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]?)\/(?:3[0-2]|[12]?[0-9])$/,cidrv6:/^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\/(?:12[0-8]|1[01][0-9]|[1-9]?[0-9])$|^::(?:[0-9a-fA-F]{1,4}:){0,6}[0-9a-fA-F]{1,4}\/(?:12[0-8]|1[01][0-9]|[1-9]?[0-9])$|^(?:[0-9a-fA-F]{1,4}:){1,7}:\/(?:12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,e164:/^\+[1-9]\d{1,14}$/,xid:/^[A-HJKMNP-TV-Z0-9]{20}$/,guid:/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/i,ksuid:/^[0-9A-Za-z]{27}$/,isoDate:/^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/,isoTime:/^(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?$/,isoDateTime:/^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?Z?$/,isoDuration:/^-?P(?!$)(?:\d+(?:\.\d+)?Y)?(?:\d+(?:\.\d+)?M)?(?:\d+(?:\.\d+)?W)?(?:\d+(?:\.\d+)?D)?(?:T(?=\d)(?:\d+(?:\.\d+)?H)?(?:\d+(?:\.\d+)?M)?(?:\d+(?:\.\d+)?S)?)?$/};class VldString extends e.VldBase{constructor(s){super(s?.validatorType||e.VLD_VALIDATOR_TYPES.STRING),this.config={checks:s?.checks||[],transforms:s?.transforms||[],errorMessage:s?.errorMessage,jsonSchema:s?.jsonSchema,checkMetas:s?.checkMetas},this._checks=this.config.checks,this._transforms=this.config.transforms,this._isSimple=0===this._checks.length&&0===this._transforms.length,this._checkMetas=this.config.checkMetas}static create(){return new VldString}get isSimple(){return this._isSimple}get minLength(){return this.config.jsonSchema?.minLength??null}get maxLength(){return this.config.jsonSchema?.maxLength??null}_createCheckIssue(e){switch(e.kind){case"min":return{code:"too_small",path:[],origin:"string",minimum:e.value,inclusive:!0,message:e.message||`Too small: expected string to have >=${e.value} characters`};case"max":return{code:"too_big",path:[],origin:"string",maximum:e.value,inclusive:!0,message:e.message||`Too big: expected string to have <=${e.value} characters`};case"length":return{code:"too_big",path:[],origin:"string",exact:e.value,message:e.message||`Too big: expected string to have exactly ${e.value} characters`};case"format":{const s={code:"invalid_format",path:[],origin:"string",format:e.format,message:e.message||`Invalid ${e.format}`};return void 0!==e.pattern&&(s.pattern=e.pattern),s}case"regex":{const s={code:"invalid_format",path:[],origin:"string",format:"regex",message:e.message||"Invalid string: does not match pattern"};return void 0!==e.pattern&&(s.pattern=e.pattern),s}default:return{code:"custom",path:[],message:e.message||"Invalid string"}}}_runChecks(e){const s=this._checks,r=this._checkMetas;for(let t=0;t<s.length;t++)if(!s[t](e))return r?.[t]??this._fallbackMeta();return null}_fallbackMeta(){return{kind:"other",message:this.config.errorMessage}}parse(e){if("string"!=typeof e)throw new t.VldError([t.createInvalidTypeIssue("string",t.getTypeName(e),this.config.errorMessage)]);return this._isSimple?e:this.parseKnownString(e)}parseKnownString(e){if(this._isSimple)return e;const s=this._transforms;let r=e;switch(s.length){case 0:break;case 1:r=s[0](r);break;case 2:r=s[1](s[0](r));break;case 3:r=s[2](s[1](s[0](r)));break;default:for(let e=0;e<s.length;e++)r=s[e](r)}const i=this._runChecks(r);if(i)throw new t.VldError([this._createCheckIssue(i)]);return r}safeParse(e){if("string"!=typeof e)return{success:!1,error:new t.VldError([t.createInvalidTypeIssue("string",t.getTypeName(e),this.config.errorMessage)])};if(this._isSimple)return{success:!0,data:e};try{return{success:!0,data:this.parseKnownString(e)}}catch(e){return e instanceof t.VldError?{success:!1,error:e}:{success:!1,error:(s=e.message,new t.VldError([{code:"invalid_string",path:[],message:s}]))}}var s}min(r,t){return new VldString({checks:[...this.config.checks,e=>e.length>=r],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringMin(r)),jsonSchema:{...this.config.jsonSchema,minLength:r},checkMetas:[...this.config.checkMetas??[],{kind:"min",value:r,message:e.resolveErrorMessage(t,s.getMessages().stringMin(r))}]})}max(r,t){return new VldString({checks:[...this.config.checks,e=>e.length<=r],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringMax(r)),jsonSchema:{...this.config.jsonSchema,maxLength:r},checkMetas:[...this.config.checkMetas??[],{kind:"max",value:r,message:e.resolveErrorMessage(t,s.getMessages().stringMax(r))}]})}length(r,t){return new VldString({checks:[...this.config.checks,e=>e.length===r],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringLength(r)),jsonSchema:{...this.config.jsonSchema,exactLength:r},checkMetas:[...this.config.checkMetas??[],{kind:"length",value:r,message:e.resolveErrorMessage(t,s.getMessages().stringLength(r))}]})}email(r){return new VldString({checks:[...this.config.checks,e=>i.email.test(e)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(r,s.getMessages().stringEmail),jsonSchema:{...this.config.jsonSchema,format:"email"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"email",message:e.resolveErrorMessage(r,s.getMessages().stringEmail)}]})}url(r){return new VldString({checks:[...this.config.checks,e=>i.url.test(e)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(r,s.getMessages().stringUrl),jsonSchema:{...this.config.jsonSchema,format:"uri"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"url",message:e.resolveErrorMessage(r,s.getMessages().stringUrl)}]})}uuid(r){return new VldString({checks:[...this.config.checks,e=>i.uuid.test(e)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(r,s.getMessages().stringUuid),jsonSchema:{...this.config.jsonSchema,format:"uuid"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"uuid",message:e.resolveErrorMessage(r,s.getMessages().stringUuid)}]})}format(s,r,t){return new VldString({checks:[...this.config.checks,e=>s.test(e)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,`Invalid ${r}`),jsonSchema:{...this.config.jsonSchema,format:r,pattern:s.source},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:r,pattern:s.source,message:e.resolveErrorMessage(t,`Invalid ${r}`)}]})}uuidv4(e){return this.format(i.uuidv4,"uuid",e)}uuidv6(e){return this.format(i.uuidv6,"uuid",e)}uuidv7(e){return this.format(i.uuidv7,"uuid",e)}emoji(e){return this.format(i.emoji,"emoji",e)}base64(e){return this.format(i.base64,"base64",e)}base64url(e){return this.format(i.base64url,"base64url",e)}jwt(e){return this.format(i.jwt,"jwt",e)}nanoid(e){return this.format(i.nanoid,"nanoid",e)}cuid(e){return this.format(i.cuid,"cuid",e)}cuid2(e){return this.format(i.cuid2,"cuid2",e)}ulid(e){return this.format(i.ulid,"ulid",e)}cidrv4(e){return this.format(i.cidrv4,"cidrv4",e)}cidrv6(e){return this.format(i.cidrv6,"cidrv6",e)}e164(e){return this.format(i.e164,"e164",e)}xid(e){return this.format(i.xid,"xid",e)}guid(e){return this.format(i.guid,"guid",e)}ksuid(e){return this.format(i.ksuid,"ksuid",e)}date(e){return this.format(i.isoDate,"date",e)}time(e){return this.format(i.isoTime,"time",e)}datetime(e){return this.format(i.isoDateTime,"datetime",e)}duration(e){return this.format(i.isoDuration,"duration",e)}regex(r,t){return new VldString({checks:[...this.config.checks,e=>r.test(e)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringRegex),jsonSchema:{...this.config.jsonSchema,pattern:r.source},checkMetas:[...this.config.checkMetas??[],{kind:"regex",pattern:r.source,message:e.resolveErrorMessage(t,s.getMessages().stringRegex)}]})}trim(){return new VldString({checks:this.config.checks,transforms:[...this.config.transforms,e=>e.trim()],errorMessage:this.config.errorMessage,jsonSchema:this.config.jsonSchema})}toLowerCase(){return new VldString({checks:this.config.checks,transforms:[...this.config.transforms,e=>e.toLowerCase()],errorMessage:this.config.errorMessage,jsonSchema:this.config.jsonSchema})}lowercase(){return this.toLowerCase()}toUpperCase(){return new VldString({checks:this.config.checks,transforms:[...this.config.transforms,e=>e.toUpperCase()],errorMessage:this.config.errorMessage,jsonSchema:this.config.jsonSchema})}uppercase(){return this.toUpperCase()}normalize(e){return new VldString({checks:this.config.checks,transforms:[...this.config.transforms,s=>s.normalize(e)],errorMessage:this.config.errorMessage,jsonSchema:this.config.jsonSchema})}slugify(){return new VldString({checks:this.config.checks,transforms:[...this.config.transforms,e=>e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")],errorMessage:this.config.errorMessage,jsonSchema:this.config.jsonSchema})}startsWith(r,t){return new VldString({checks:[...this.config.checks,e=>e.startsWith(r)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringStartsWith(r)),jsonSchema:this.config.jsonSchema})}endsWith(r,t){return new VldString({checks:[...this.config.checks,e=>e.endsWith(r)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringEndsWith(r)),jsonSchema:this.config.jsonSchema})}includes(r,t){return new VldString({checks:[...this.config.checks,e=>e.includes(r)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringIncludes(r)),jsonSchema:this.config.jsonSchema})}ip(t){return new VldString({checks:[...this.config.checks,e=>!(e.length>100)&&(i.ipv4.test(e)||r.isValidIPv6(e))],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringIp),jsonSchema:{...this.config.jsonSchema,format:"ip"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"ip",message:e.resolveErrorMessage(t,s.getMessages().stringIp)}]})}ipv4(r){return new VldString({checks:[...this.config.checks,e=>i.ipv4.test(e)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(r,s.getMessages().stringIpv4),jsonSchema:{...this.config.jsonSchema,format:"ipv4"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"ipv4",message:e.resolveErrorMessage(r,s.getMessages().stringIpv4)}]})}ipv6(t){return new VldString({checks:[...this.config.checks,e=>r.isValidIPv6(e)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringIpv6),jsonSchema:{...this.config.jsonSchema,format:"ipv6"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"ipv6",message:e.resolveErrorMessage(t,s.getMessages().stringIpv6)}]})}nonempty(r){return new VldString({checks:[...this.config.checks,e=>e.length>0],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(r,s.getMessages().stringEmpty),jsonSchema:{...this.config.jsonSchema,minLength:Math.max(this.config.jsonSchema?.minLength||0,1)},checkMetas:[...this.config.checkMetas??[],{kind:"min",value:1,message:e.resolveErrorMessage(r,s.getMessages().stringEmpty)}]})}}exports.VldString=VldString;
1
+ "use strict";var e=require("./base.cjs"),s=require("../locales/runtime.cjs"),r=require("../chunks/ip-validation-BZqPamPC.cjs"),t=require("../chunks/errors-core-C0mA6tfa.cjs");require("../registry.cjs"),require("../locales/en.cjs");const i=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,a={email:i,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,url:/^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)$/,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]?)$/,uuidv4:/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,uuidv6:/^[0-9a-f]{8}-[0-9a-f]{4}-6[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,uuidv7:/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,emoji:/^(?=[\s\S]*[\p{Extended_Pictographic}\p{Regional_Indicator}\u20E3])[\p{Extended_Pictographic}\p{Emoji_Component}]+$/u,base64:/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,base64url:/^[A-Za-z0-9_-]*$/,jwt:/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$/,nanoid:/^[A-Za-z0-9_-]{21}$/,cuid:/^c[^\s-]{8,}$/i,cuid2:/^[0-9a-z]+$/,ulid:/^[0-9A-HJKMNP-TV-Z]{26}$/,cidrv4:/^(?:(?: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]?)\/(?:3[0-2]|[12]?[0-9])$/,cidrv6:/^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\/(?:12[0-8]|1[01][0-9]|[1-9]?[0-9])$|^::(?:[0-9a-fA-F]{1,4}:){0,6}[0-9a-fA-F]{1,4}\/(?:12[0-8]|1[01][0-9]|[1-9]?[0-9])$|^(?:[0-9a-fA-F]{1,4}:){1,7}:\/(?:12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,e164:/^\+[1-9]\d{1,14}$/,xid:/^[A-HJKMNP-TV-Z0-9]{20}$/,guid:/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/i,ksuid:/^[0-9A-Za-z]{27}$/,isoDate:/^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/,isoTime:/^(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?$/,isoDateTime:/^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?Z?$/,isoDuration:/^-?P(?!$)(?:\d+(?:\.\d+)?Y)?(?:\d+(?:\.\d+)?M)?(?:\d+(?:\.\d+)?W)?(?:\d+(?:\.\d+)?D)?(?:T(?=\d)(?:\d+(?:\.\d+)?H)?(?:\d+(?:\.\d+)?M)?(?:\d+(?:\.\d+)?S)?)?$/},n={email:{source:i.source,flags:i.flags},url:{source:a.url.source,flags:a.url.flags},uuid:{source:a.uuid.source,flags:a.uuid.flags}};class VldString extends e.VldBase{constructor(s){super(s?.validatorType||e.VLD_VALIDATOR_TYPES.STRING),this.config={checks:s?.checks||[],transforms:s?.transforms||[],errorMessage:s?.errorMessage,jsonSchema:s?.jsonSchema,checkMetas:s?.checkMetas},this._checks=this.config.checks,this._transforms=this.config.transforms,this._isSimple=0===this._checks.length&&0===this._transforms.length,this._checkMetas=this.config.checkMetas}static create(){return new VldString}get isSimple(){return this._isSimple}get minLength(){return this.config.jsonSchema?.minLength??null}get maxLength(){return this.config.jsonSchema?.maxLength??null}_createCheckIssue(e){switch(e.kind){case"min":return{code:"too_small",path:[],origin:"string",minimum:e.value,inclusive:!0,message:e.message||`Too small: expected string to have >=${e.value} characters`};case"max":return{code:"too_big",path:[],origin:"string",maximum:e.value,inclusive:!0,message:e.message||`Too big: expected string to have <=${e.value} characters`};case"length":return{code:"too_big",path:[],origin:"string",exact:e.value,message:e.message||`Too big: expected string to have exactly ${e.value} characters`};case"format":{const s={code:"invalid_format",path:[],origin:"string",format:e.format,message:e.message||`Invalid ${e.format}`};return void 0!==e.pattern&&(s.pattern=e.pattern),s}case"regex":{const s={code:"invalid_format",path:[],origin:"string",format:"regex",message:e.message||"Invalid string: does not match pattern"};return void 0!==e.pattern&&(s.pattern=e.pattern),s}default:return{code:"custom",path:[],message:e.message||"Invalid string"}}}_runChecks(e){const s=this._checks,r=this._checkMetas;for(let t=0;t<s.length;t++)if(!s[t](e))return r?.[t]??this._fallbackMeta();return null}_fallbackMeta(){return{kind:"other",message:this.config.errorMessage}}parse(e){if("string"!=typeof e)throw new t.VldError([t.createInvalidTypeIssue("string",t.getTypeName(e),this.config.errorMessage)]);return this._isSimple?e:this.parseKnownString(e)}parseKnownString(e){if(this._isSimple)return e;const s=this._transforms;let r=e;switch(s.length){case 0:break;case 1:r=s[0](r);break;case 2:r=s[1](s[0](r));break;case 3:r=s[2](s[1](s[0](r)));break;default:for(let e=0;e<s.length;e++)r=s[e](r)}const i=this._runChecks(r);if(i)throw new t.VldError([this._createCheckIssue(i)]);return r}safeParse(e){if("string"!=typeof e)return{success:!1,error:new t.VldError([t.createInvalidTypeIssue("string",t.getTypeName(e),this.config.errorMessage)])};if(this._isSimple)return{success:!0,data:e};try{return{success:!0,data:this.parseKnownString(e)}}catch(e){return e instanceof t.VldError?{success:!1,error:e}:{success:!1,error:(s=e.message,new t.VldError([{code:"invalid_string",path:[],message:s}]))}}var s}min(r,t){return new VldString({checks:[...this.config.checks,e=>e.length>=r],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringMin(r)),jsonSchema:{...this.config.jsonSchema,minLength:r},checkMetas:[...this.config.checkMetas??[],{kind:"min",value:r,message:e.resolveErrorMessage(t,s.getMessages().stringMin(r))}]})}max(r,t){return new VldString({checks:[...this.config.checks,e=>e.length<=r],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringMax(r)),jsonSchema:{...this.config.jsonSchema,maxLength:r},checkMetas:[...this.config.checkMetas??[],{kind:"max",value:r,message:e.resolveErrorMessage(t,s.getMessages().stringMax(r))}]})}length(r,t){return new VldString({checks:[...this.config.checks,e=>e.length===r],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringLength(r)),jsonSchema:{...this.config.jsonSchema,exactLength:r},checkMetas:[...this.config.checkMetas??[],{kind:"length",value:r,message:e.resolveErrorMessage(t,s.getMessages().stringLength(r))}]})}email(r){return new VldString({checks:[...this.config.checks,e=>a.email.test(e)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(r,s.getMessages().stringEmail),jsonSchema:{...this.config.jsonSchema,format:"email"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"email",message:e.resolveErrorMessage(r,s.getMessages().stringEmail)}]})}url(r){return new VldString({checks:[...this.config.checks,e=>a.url.test(e)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(r,s.getMessages().stringUrl),jsonSchema:{...this.config.jsonSchema,format:"uri"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"url",message:e.resolveErrorMessage(r,s.getMessages().stringUrl)}]})}uuid(r){return new VldString({checks:[...this.config.checks,e=>a.uuid.test(e)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(r,s.getMessages().stringUuid),jsonSchema:{...this.config.jsonSchema,format:"uuid"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"uuid",message:e.resolveErrorMessage(r,s.getMessages().stringUuid)}]})}format(s,r,t){return new VldString({checks:[...this.config.checks,e=>s.test(e)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,`Invalid ${r}`),jsonSchema:{...this.config.jsonSchema,format:r,pattern:s.source},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:r,pattern:s.source,flags:s.flags,message:e.resolveErrorMessage(t,`Invalid ${r}`)}]})}uuidv4(e){return this.format(a.uuidv4,"uuid",e)}uuidv6(e){return this.format(a.uuidv6,"uuid",e)}uuidv7(e){return this.format(a.uuidv7,"uuid",e)}emoji(e){return this.format(a.emoji,"emoji",e)}base64(e){return this.format(a.base64,"base64",e)}base64url(e){return this.format(a.base64url,"base64url",e)}jwt(e){return this.format(a.jwt,"jwt",e)}nanoid(e){return this.format(a.nanoid,"nanoid",e)}cuid(e){return this.format(a.cuid,"cuid",e)}cuid2(e){return this.format(a.cuid2,"cuid2",e)}ulid(e){return this.format(a.ulid,"ulid",e)}cidrv4(e){return this.format(a.cidrv4,"cidrv4",e)}cidrv6(e){return this.format(a.cidrv6,"cidrv6",e)}e164(e){return this.format(a.e164,"e164",e)}xid(e){return this.format(a.xid,"xid",e)}guid(e){return this.format(a.guid,"guid",e)}ksuid(e){return this.format(a.ksuid,"ksuid",e)}date(e){return this.format(a.isoDate,"date",e)}time(e){return this.format(a.isoTime,"time",e)}datetime(e){return this.format(a.isoDateTime,"datetime",e)}duration(e){return this.format(a.isoDuration,"duration",e)}regex(r,t){return new VldString({checks:[...this.config.checks,e=>r.test(e)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringRegex),jsonSchema:{...this.config.jsonSchema,pattern:r.source},checkMetas:[...this.config.checkMetas??[],{kind:"regex",pattern:r.source,flags:r.flags,message:e.resolveErrorMessage(t,s.getMessages().stringRegex)}]})}trim(){return new VldString({checks:this.config.checks,transforms:[...this.config.transforms,e=>e.trim()],errorMessage:this.config.errorMessage,jsonSchema:this.config.jsonSchema})}toLowerCase(){return new VldString({checks:this.config.checks,transforms:[...this.config.transforms,e=>e.toLowerCase()],errorMessage:this.config.errorMessage,jsonSchema:this.config.jsonSchema})}lowercase(){return this.toLowerCase()}toUpperCase(){return new VldString({checks:this.config.checks,transforms:[...this.config.transforms,e=>e.toUpperCase()],errorMessage:this.config.errorMessage,jsonSchema:this.config.jsonSchema})}uppercase(){return this.toUpperCase()}normalize(e){return new VldString({checks:this.config.checks,transforms:[...this.config.transforms,s=>s.normalize(e)],errorMessage:this.config.errorMessage,jsonSchema:this.config.jsonSchema})}slugify(){return new VldString({checks:this.config.checks,transforms:[...this.config.transforms,e=>e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")],errorMessage:this.config.errorMessage,jsonSchema:this.config.jsonSchema})}startsWith(r,t){return new VldString({checks:[...this.config.checks,e=>e.startsWith(r)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringStartsWith(r)),jsonSchema:this.config.jsonSchema})}endsWith(r,t){return new VldString({checks:[...this.config.checks,e=>e.endsWith(r)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringEndsWith(r)),jsonSchema:this.config.jsonSchema})}includes(r,t){return new VldString({checks:[...this.config.checks,e=>e.includes(r)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringIncludes(r)),jsonSchema:this.config.jsonSchema})}ip(t){return new VldString({checks:[...this.config.checks,e=>!(e.length>100)&&(a.ipv4.test(e)||r.isValidIPv6(e))],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringIp),jsonSchema:{...this.config.jsonSchema,format:"ip"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"ip",message:e.resolveErrorMessage(t,s.getMessages().stringIp)}]})}ipv4(r){return new VldString({checks:[...this.config.checks,e=>a.ipv4.test(e)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(r,s.getMessages().stringIpv4),jsonSchema:{...this.config.jsonSchema,format:"ipv4"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"ipv4",message:e.resolveErrorMessage(r,s.getMessages().stringIpv4)}]})}ipv6(t){return new VldString({checks:[...this.config.checks,e=>r.isValidIPv6(e)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringIpv6),jsonSchema:{...this.config.jsonSchema,format:"ipv6"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"ipv6",message:e.resolveErrorMessage(t,s.getMessages().stringIpv6)}]})}nonempty(r){return new VldString({checks:[...this.config.checks,e=>e.length>0],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(r,s.getMessages().stringEmpty),jsonSchema:{...this.config.jsonSchema,minLength:Math.max(this.config.jsonSchema?.minLength||0,1)},checkMetas:[...this.config.checkMetas??[],{kind:"min",value:1,message:e.resolveErrorMessage(r,s.getMessages().stringEmpty)}]})}}exports.COMPILABLE_FORMATS=n,exports.VldString=VldString;
package/dist/cli/bin.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{vldCli as e}from"./index.js";import*as o from"fs";import{readFileSync as s}from"fs";import*as r from"path";import a from"../pigment.js";import{prettifyError as t,prettifyErrorColored as n}from"../errors.js";import i from"../index.js";function c(e,o,s){const a=process.cwd();if(!e.startsWith(a+r.sep)&&e!==a)throw new Error(`${o} path escapes allowed directory: ${s}`)}const l={name:"validate",description:"Validate JSON data against a VLD schema",aliases:["v"],arguments:[{name:"schema",description:"Path to schema file (.ts or .js)",required:!0},{name:"data",description:"Path to JSON data file or JSON string",required:!0}],options:[{name:"strict",short:"s",description:"Enable strict mode (no extra keys)",type:"boolean",default:!1},{name:"quiet",short:"q",description:"Only output errors",type:"boolean",default:!1},{name:"json",short:"j",description:"Output as JSON",type:"boolean",default:!1},{name:"no-color",description:"Disable colored output",type:"boolean",default:!1}],action:async(e,s)=>{const i=e.schema,l=e.data,m=s.quiet,p=s.json,d=s["no-color"];let u,f;try{const e=r.resolve(process.cwd(),i);if(c(e,"Schema",i),!o.existsSync(e))throw new Error(`Schema file not found: ${i}`);const s=await(import(e));if(u=s.default||s.schema||s,!u||"function"!=typeof u.parse)throw new Error("Schema must export a VLD validator with parse() method")}catch(e){return p?console.log(JSON.stringify({success:!1,error:e.message})):console.error(a.red("Schema Error:"),e.message),void(process.exitCode=1)}try{if(l.startsWith("{")||l.startsWith("["))f=JSON.parse(l);else{const e=r.resolve(process.cwd(),l);if(c(e,"Data",l),!o.existsSync(e))throw new Error(`Data file not found: ${l}`);const s=o.readFileSync(e,"utf-8");f=JSON.parse(s)}}catch(e){return p?console.log(JSON.stringify({success:!1,error:e.message})):console.error(a.red("Data Error:"),e.message),void(process.exitCode=1)}const g=u.safeParse(f);if(p)if(g.success)console.log(JSON.stringify({success:!0,data:g.data}));else{const e=g.error,o={success:!1,error:e?.message,issues:e?.issues};console.log(JSON.stringify(o))}else if(g.success)m||(console.log(a.green("Validation passed")),console.log(""),console.log(a.dim("Data:")),console.log(JSON.stringify(g.data,null,2)));else{if(console.error(a.red("Validation failed")),console.error(""),g.error&&"issues"in g.error){const e=d?t(g.error,{colored:!1}):n(g.error);console.error(e)}else console.error(g.error?.message||"Unknown error");process.exitCode=1}}};function m(e,o,s){for(let e=0;e<Math.min(100,s/10);e++)o();const r=performance.now();for(let e=0;e<s;e++)o();const a=performance.now()-r,t=a/s;return{name:e,iterations:s,totalMs:a,avgMs:t,opsPerSec:1e3/t}}function p(e){return e.toLocaleString("en-US",{maximumFractionDigits:2})}function d(e,o){return`${o?a.cyan(e.name.padEnd(30)):e.name.padEnd(30)} ${o?a.green(p(e.opsPerSec).padStart(12)):p(e.opsPerSec).padStart(12)} ops/sec ${o?a.yellow(e.avgMs.toFixed(6).padStart(12)):e.avgMs.toFixed(6).padStart(12)} ms/op`}const u={name:"benchmark",description:"Run performance benchmarks",aliases:["bench","b"],options:[{name:"iterations",short:"n",description:"Number of iterations",type:"number",default:1e4},{name:"suite",short:"s",description:"Benchmark suite to run (all, primitives, objects, arrays)",type:"string",default:"all"},{name:"json",short:"j",description:"Output as JSON",type:"boolean",default:!1},{name:"no-color",description:"Disable colored output",type:"boolean",default:!1}],action:async(e,o)=>{const s=o.iterations,r=o.suite,t=o.json,n=!o["no-color"],c=[],l=i.string(),u=i.number(),f=i.boolean(),g=i.date(),h=i.object({name:i.string(),email:i.string(),age:i.number(),active:i.boolean()}),b=i.array(i.number()),S=i.object({user:i.object({name:i.string(),email:i.string()}),items:i.array(i.object({id:i.number(),name:i.string(),price:i.number()}))}),y="hello world",v=new Date,j={name:"John",email:"john@example.com",age:30,active:!0},w=[1,2,3,4,5,6,7,8,9,10],O={user:{name:"John",email:"john@example.com"},items:[{id:1,name:"Item 1",price:10.99},{id:2,name:"Item 2",price:20.99},{id:3,name:"Item 3",price:30.99}]};if(t||(console.log(a.bold("VLD Performance Benchmark")),console.log(a.dim(`Running ${p(s)} iterations per test`)),console.log("")),("all"===r||"primitives"===r)&&(t||console.log(a.bold("Primitives:")),c.push(m("string.parse()",()=>l.parse(y),s)),c.push(m("number.parse()",()=>u.parse(42),s)),c.push(m("boolean.parse()",()=>f.parse(true),s)),c.push(m("date.parse()",()=>g.parse(v),s)),c.push(m("string.safeParse()",()=>l.safeParse(y),s)),!t)){for(const e of c.slice(-5))console.log(" "+d(e,n));console.log("")}if(("all"===r||"objects"===r)&&(t||console.log(a.bold("Objects:")),c.push(m("object.parse()",()=>h.parse(j),s)),c.push(m("object.safeParse()",()=>h.safeParse(j),s)),c.push(m("nested.parse()",()=>S.parse(O),s)),!t)){for(const e of c.slice(-3))console.log(" "+d(e,n));console.log("")}if(("all"===r||"arrays"===r)&&(t||console.log(a.bold("Arrays:")),c.push(m("array.parse()",()=>b.parse(w),s)),c.push(m("array.safeParse()",()=>b.safeParse(w),s)),!t)){for(const e of c.slice(-2))console.log(" "+d(e,n));console.log("")}if(t)console.log(JSON.stringify({iterations:s,suite:r,results:c.map(e=>({name:e.name,iterations:e.iterations,totalMs:e.totalMs,avgMs:e.avgMs,opsPerSec:e.opsPerSec}))}));else{const e=c.reduce((e,o)=>e+o.opsPerSec,0)/c.length;console.log(a.bold("Summary:")),console.log(` Total benchmarks: ${c.length}`),console.log(` Average ops/sec: ${p(e)}`)}}},f=JSON.parse(s(new URL("../../package.json",import.meta.url),"utf-8")).version||"0.0.0";e.version=f,e.command(l),e.command(u),e.command({name:"help",description:"Show help information",aliases:["h"],action:()=>{console.log(e.help())}}),e.command({name:"version",description:"Show version information",action:()=>{console.log(`vld v${f}`)}}),e.run(process.argv.slice(2)).catch(e=>{console.error("Fatal error:",e),process.exitCode=1});
2
+ import{vldCli as e}from"./index.js";import*as o from"fs";import{readFileSync as s}from"fs";import*as r from"path";import a from"../pigment.js";import{prettifyError as t,prettifyErrorColored as n}from"../errors.js";import i from"../index.js";function c(e,o,s){const a=process.cwd();if(!e.startsWith(a+r.sep)&&e!==a)throw new Error(`${o} path escapes allowed directory: ${s}`)}const l={name:"validate",description:"Validate JSON data against a VLD schema",aliases:["v"],arguments:[{name:"schema",description:"Path to schema file (.ts or .js)",required:!0},{name:"data",description:"Path to JSON data file or JSON string",required:!0}],options:[{name:"strict",short:"s",description:"Enable strict mode (no extra keys)",type:"boolean",default:!1},{name:"quiet",short:"q",description:"Only output errors",type:"boolean",default:!1},{name:"json",short:"j",description:"Output as JSON",type:"boolean",default:!1},{name:"no-color",description:"Disable colored output",type:"boolean",default:!1}],action:async(e,s)=>{const i=e.schema,l=e.data,m=s.quiet,p=s.json,d=s["no-color"];let u,f;try{const e=r.resolve(process.cwd(),i);if(c(e,"Schema",i),!o.existsSync(e))throw new Error(`Schema file not found: ${i}`);const s=await import(e);if(u=s.default||s.schema||s,!u||"function"!=typeof u.parse)throw new Error("Schema must export a VLD validator with parse() method")}catch(e){return p?console.log(JSON.stringify({success:!1,error:e.message})):console.error(a.red("Schema Error:"),e.message),void(process.exitCode=1)}try{if(l.startsWith("{")||l.startsWith("["))f=JSON.parse(l);else{const e=r.resolve(process.cwd(),l);if(c(e,"Data",l),!o.existsSync(e))throw new Error(`Data file not found: ${l}`);const s=o.readFileSync(e,"utf-8");f=JSON.parse(s)}}catch(e){return p?console.log(JSON.stringify({success:!1,error:e.message})):console.error(a.red("Data Error:"),e.message),void(process.exitCode=1)}const g=u.safeParse(f);if(p)if(g.success)console.log(JSON.stringify({success:!0,data:g.data}));else{const e=g.error,o={success:!1,error:e?.message,issues:e?.issues};console.log(JSON.stringify(o))}else if(g.success)m||(console.log(a.green("Validation passed")),console.log(""),console.log(a.dim("Data:")),console.log(JSON.stringify(g.data,null,2)));else{if(console.error(a.red("Validation failed")),console.error(""),g.error&&"issues"in g.error){const e=d?t(g.error,{colored:!1}):n(g.error);console.error(e)}else console.error(g.error?.message||"Unknown error");process.exitCode=1}}};function m(e,o,s){for(let e=0;e<Math.min(100,s/10);e++)o();const r=performance.now();for(let e=0;e<s;e++)o();const a=performance.now()-r,t=a/s;return{name:e,iterations:s,totalMs:a,avgMs:t,opsPerSec:1e3/t}}function p(e){return e.toLocaleString("en-US",{maximumFractionDigits:2})}function d(e,o){return`${o?a.cyan(e.name.padEnd(30)):e.name.padEnd(30)} ${o?a.green(p(e.opsPerSec).padStart(12)):p(e.opsPerSec).padStart(12)} ops/sec ${o?a.yellow(e.avgMs.toFixed(6).padStart(12)):e.avgMs.toFixed(6).padStart(12)} ms/op`}const u={name:"benchmark",description:"Run performance benchmarks",aliases:["bench","b"],options:[{name:"iterations",short:"n",description:"Number of iterations",type:"number",default:1e4},{name:"suite",short:"s",description:"Benchmark suite to run (all, primitives, objects, arrays)",type:"string",default:"all"},{name:"json",short:"j",description:"Output as JSON",type:"boolean",default:!1},{name:"no-color",description:"Disable colored output",type:"boolean",default:!1}],action:async(e,o)=>{const s=o.iterations,r=o.suite,t=o.json,n=!o["no-color"],c=[],l=i.string(),u=i.number(),f=i.boolean(),g=i.date(),h=i.object({name:i.string(),email:i.string(),age:i.number(),active:i.boolean()}),b=i.array(i.number()),S=i.object({user:i.object({name:i.string(),email:i.string()}),items:i.array(i.object({id:i.number(),name:i.string(),price:i.number()}))}),y="hello world",v=new Date,j={name:"John",email:"john@example.com",age:30,active:!0},w=[1,2,3,4,5,6,7,8,9,10],O={user:{name:"John",email:"john@example.com"},items:[{id:1,name:"Item 1",price:10.99},{id:2,name:"Item 2",price:20.99},{id:3,name:"Item 3",price:30.99}]};if(t||(console.log(a.bold("VLD Performance Benchmark")),console.log(a.dim(`Running ${p(s)} iterations per test`)),console.log("")),("all"===r||"primitives"===r)&&(t||console.log(a.bold("Primitives:")),c.push(m("string.parse()",()=>l.parse(y),s)),c.push(m("number.parse()",()=>u.parse(42),s)),c.push(m("boolean.parse()",()=>f.parse(true),s)),c.push(m("date.parse()",()=>g.parse(v),s)),c.push(m("string.safeParse()",()=>l.safeParse(y),s)),!t)){for(const e of c.slice(-5))console.log(" "+d(e,n));console.log("")}if(("all"===r||"objects"===r)&&(t||console.log(a.bold("Objects:")),c.push(m("object.parse()",()=>h.parse(j),s)),c.push(m("object.safeParse()",()=>h.safeParse(j),s)),c.push(m("nested.parse()",()=>S.parse(O),s)),!t)){for(const e of c.slice(-3))console.log(" "+d(e,n));console.log("")}if(("all"===r||"arrays"===r)&&(t||console.log(a.bold("Arrays:")),c.push(m("array.parse()",()=>b.parse(w),s)),c.push(m("array.safeParse()",()=>b.safeParse(w),s)),!t)){for(const e of c.slice(-2))console.log(" "+d(e,n));console.log("")}if(t)console.log(JSON.stringify({iterations:s,suite:r,results:c.map(e=>({name:e.name,iterations:e.iterations,totalMs:e.totalMs,avgMs:e.avgMs,opsPerSec:e.opsPerSec}))}));else{const e=c.reduce((e,o)=>e+o.opsPerSec,0)/c.length;console.log(a.bold("Summary:")),console.log(` Total benchmarks: ${c.length}`),console.log(` Average ops/sec: ${p(e)}`)}}},f=JSON.parse(s(new URL("../../package.json",import.meta.url),"utf-8")).version||"0.0.0";e.version=f,e.command(l),e.command(u),e.command({name:"help",description:"Show help information",aliases:["h"],action:()=>{console.log(e.help())}}),e.command({name:"version",description:"Show version information",action:()=>{console.log(`vld v${f}`)}}),e.run(process.argv.slice(2)).catch(e=>{console.error("Fatal error:",e),process.exitCode=1});
package/dist/compile.d.ts CHANGED
@@ -71,6 +71,21 @@ export declare function applyCompiled<T extends VldBase<any, any>>(schema: T, co
71
71
  export declare function compile<T extends VldBase<any, any>>(schema: T, options?: {
72
72
  JITless?: boolean;
73
73
  }): T;
74
+ /**
75
+ * Zod 4.6 `z.withParser()`: install an externally generated parser as a
76
+ * schema's fast path. Returns a clone; the original schema is unchanged.
77
+ *
78
+ * The parser takes the input and returns the parsed value, or `INVALID`
79
+ * (the exported sentinel) to hand the parse to the runtime. It must be
80
+ * synchronous and forward-direction, and it must build fresh output rather
81
+ * than return its input - vld cannot check either, and a wrong *success*
82
+ * is returned to the caller as-is.
83
+ *
84
+ * This is the escape hatch for build-time or native compilers in CSP
85
+ * environments where `new Function` (and therefore `z.compile()`) is
86
+ * unavailable.
87
+ */
88
+ export declare function withParser<T extends VldBase<any, any>>(schema: T, parser: (input: unknown) => unknown): T;
74
89
  export declare function validate(schema: VldBase<any, any>, value: unknown): boolean;
75
90
  export declare function validateAsync(schema: VldBase<any, any>, value: unknown): Promise<boolean>;
76
91
  export declare function properties<T extends Record<string, VldBase<any, any>>>(shape: T): VldObject<Partial<{
package/dist/compile.js CHANGED
@@ -1 +1 @@
1
- import{VldBase as t}from"./validators/base.js";import{VldString as e}from"./validators/string.js";import{VldNumber as i}from"./validators/number.js";import{VldBoolean as r}from"./validators/boolean.js";import{VldBigInt as n}from"./validators/bigint.js";import{VldUndefined as s}from"./validators/undefined.js";import{VldNull as o}from"./validators/null.js";import{VldObject as a}from"./validators/object.js";import{VldArray as u}from"./validators/array.js";import{VldUnknown as l}from"./validators/unknown.js";class h extends Error{constructor(t){super(t),this.name="ZodCompileError"}}class c extends h{constructor(t="Cannot compile async schema"){super(t),this.name="ZodCompileAsyncError"}}class f extends h{constructor(t="Schema node is not supported by the AOT compiler"){super(t),this.name="ZodCompileUnsupportedError"}}const $=Symbol.for("@oxog/vld/compile-invalid");const d=t=>{const e=new WeakMap;return i=>{const r=e.get(i);if(void 0!==r)return r;const n=t(i);return e.set(i,n),n}};function v(t){return t&&t.constructor&&t.constructor.name||""}function p(t,e){return`__${e}${t.scratch++}`}function _(t,e,i){if(!i.failed){if("VldString"===v(t)){const r=t._checks,n=t._checkMetas,s=[];if(n)for(const t of n)switch(t.kind){case"min":s.push(`__v.length >= ${t.value}`);break;case"max":s.push(`__v.length <= ${t.value}`);break;case"length":s.push(`__v.length === ${t.value}`);break;case"regex":{const e=(t.pattern??t.value?.source??String(t.value)).replace(/\\/g,"\\\\").replace(/\//g,"\\/");s.push(`/${e}/.test(__v)`);break}case"startsWith":s.push(`__v.startsWith(${JSON.stringify(t.value)})`);break;case"endsWith":s.push(`__v.endsWith(${JSON.stringify(t.value)})`);break;case"includes":s.push(`__v.includes(${JSON.stringify(t.value)})`);break;case"email":case"url":case"uuid":case"ip":break;default:if(r&&r.length>0)return void(i.failed=!0)}else if(r&&r.length>0)return void(i.failed=!0);return void(0===s.length?i.hoist.push(`if (typeof ${e} !== "string") ${i.throwOnFail?"throw":"return"} ${i.invalid}; ${i.validateOnly?i.outParam+" = true; ":(i.skipOutAssign?"":i.outParam+" = ")+e};`):i.hoist.push(`{ const __v = ${e}; if (typeof __v !== "string" || !(${s.join(" && ")})) ${i.throwOnFail?"throw":"return"} ${i.invalid}; ${i.outParam} = __v; }`))}if("VldNumber"===v(t)){const r=t._checks,n=t._checkMetas,s=[];if(n)for(const t of n)switch(t.kind){case"int":s.push("Number.isInteger(__v)");break;case"finite":s.push("Number.isFinite(__v)");break;case"min":s.push(!1!==t.inclusive?`__v >= ${t.value}`:`__v > ${t.value}`);break;case"max":s.push(!1!==t.inclusive?`__v <= ${t.value}`:`__v < ${t.value}`);break;case"gt":s.push(`__v > ${t.value}`);break;case"gte":s.push(`__v >= ${t.value}`);break;case"lt":s.push(`__v < ${t.value}`);break;case"lte":s.push(`__v <= ${t.value}`);break;case"multipleOf":s.push(`__v % ${t.value} === 0`);break;case"positive":s.push("__v > 0");break;case"negative":s.push("__v < 0");break;case"nonnegative":s.push("__v >= 0");break;case"nonpositive":s.push("__v <= 0");break;case"safe":s.push("Number.isSafeInteger(__v)");break;default:if(r&&r.length>0)return void(i.failed=!0)}else if(r&&r.length>0)return void(i.failed=!0);const o=['typeof __v === "number"',"!Number.isNaN(__v)",...s];return void i.hoist.push(`{ const __v = ${e}; if (!(${o.join(" && ")})) ${i.throwOnFail?"throw":"return"} ${i.invalid}; ${i.outParam} = __v; }`)}if("VldBoolean"!==v(t)){if("VldBigInt"===v(t)){const r=t._checks,n=t._checkMetas,s=[];if(n)for(const t of n)switch(t.kind){case"min":s.push(`__v >= ${t.value}n`);break;case"max":s.push(`__v <= ${t.value}n`);break;case"positive":s.push("__v > 0n");break;case"negative":s.push("__v < 0n");break;case"nonnegative":s.push("__v >= 0n");break;case"nonpositive":s.push("__v <= 0n");break;default:if(r&&r.length>0)return void(i.failed=!0)}else if(r&&r.length>0)return void(i.failed=!0);const o=['typeof __v === "bigint"',...s];return void i.hoist.push(`{ const __v = ${e}; if (!(${o.join(" && ")})) ${i.throwOnFail?"throw":"return"} ${i.invalid}; ${i.outParam} = __v; }`)}if("VldDate"!==v(t))if("VldNull"!==v(t))if("VldUndefined"!==v(t))if("VldAny"!==v(t)&&"VldUnknown"!==v(t)){if("VldLiteral"===v(t)){const r=t._values||[];if(0===r.length)return void i.hoist.push(`${i.throwOnFail?"throw":"return"} ${i.invalid};`);if(1===r.length){const t=r[0],n="number"==typeof t&&Number.isNaN(t)?"NaN":JSON.stringify(t);return void i.hoist.push(`if (!Object.is(${n}, ${e})) ${i.throwOnFail?"throw":"return"} ${i.invalid}; ${i.validateOnly?i.outParam+" = true; ":(i.skipOutAssign?"":i.outParam+" = ")+e};`)}const n=p(i,"set");return i.hoist.push(`const ${n} = new Set([${r.map(t=>"number"==typeof t&&Number.isNaN(t)?"NaN":JSON.stringify(t)).join(",")}]);`),void i.hoist.push(`if (!${n}.has(${e})) ${i.throwOnFail?"throw":"return"} ${i.invalid}; ${i.validateOnly?i.outParam+" = true; ":(i.skipOutAssign?"":i.outParam+" = ")+e};`)}if("VldEnum"===v(t)){const r=t._values||[],n=p(i,"set");return i.hoist.push(`const ${n} = new Set([${r.map(t=>JSON.stringify(t)).join(",")}]);`),void i.hoist.push(`if (!${n}.has(${e})) ${i.throwOnFail?"throw":"return"} ${i.invalid}; ${i.validateOnly?i.outParam+" = true; ":(i.skipOutAssign?"":i.outParam+" = ")+e};`)}if("VldOptional"===v(t)){const r=t.baseValidator;return i.hoist.push(`if (${e} === undefined) { ${i.outParam} = undefined; } else {`),_(r,e,i),void i.hoist.push("}")}if("VldArray"===v(t)){const r=t.config?.itemValidator??t.config?.element;if(!r)return void(i.failed=!0);const n=p(i,"arr"),s=p(i,"i");if("VldObject"===v(r)){if(i.hoist.push(`if (!Array.isArray(${e})) ${i.throwOnFail?"throw":"return"} ${i.invalid};`),i.validateOnly){if(i.hoist.push(`for (let ${s} = 0; ${s} < ${e}.length; ${s}++) {`),_(r,`${e}[${s}]`,i),i.failed)return;return i.hoist.push("}"),void i.hoist.push(`${i.outParam} = true;`)}i.hoist.push(`const ${n} = new Array(${e}.length);`);const t={invalid:i.invalid,outParam:"__slot",scratch:0,hoist:[],failed:!1,skipOutAssign:!0};return t.hoist.push(`for (let ${s} = 0; ${s} < ${e}.length; ${s}++) {`," let __slot;"),_(r,`${e}[${s}]`,t),t.failed?void(i.failed=!0):(t.hoist.push(` ${n}[${s}] = __slot;`,"}"),i.hoist.push(...t.hoist),void i.hoist.push(`${i.outParam} = ${n};`))}const o=p(i,"it");if(i.hoist.push(`if (!Array.isArray(${e})) ${i.throwOnFail?"throw":"return"} ${i.invalid};`),i.validateOnly)return i.hoist.push(`for (let ${s} = 0; ${s} < ${e}.length; ${s}++) {`,` const ${o} = ${e}[${s}];`),_(r,o,i),i.hoist.push("}"),void i.hoist.push(`${i.outParam} = true;`);if(i.hoist.push(`const ${n} = new Array(${e}.length);`,`for (let ${s} = 0; ${s} < ${e}.length; ${s}++) {`),_(r,`${e}[${s}]`,i),i.failed)return;return void i.hoist.push(` ${n}[${s}] = ${e}[${s}];`,"}",`${i.outParam} = ${n};`)}if("VldTuple"===v(t)){const r=t.validators.filter(t=>Boolean(t)),n=t.restValidator,s=p(i,"tup"),o=n?`${e}.length < ${r.length}`:`${e}.length !== ${r.length}`;if(i.hoist.push(`if (!Array.isArray(${e}) || ${o}) ${i.throwOnFail?"throw":"return"} ${i.invalid};`),i.validateOnly){for(let t=0;t<r.length;t++){const n=r[t];if(!n)return void(i.failed=!0);if(_(n,`${e}[${t}]`,i),i.failed)return}if(n){const t=p(i,"i");i.hoist.push(`for (let ${t} = ${r.length}; ${t} < ${e}.length; ${t}++) {`),_(n,`${e}[${t}]`,i),i.hoist.push("}")}return void i.hoist.push(`${i.outParam} = true;`)}i.hoist.push(`const ${s} = new Array(${e}.length);`);for(let t=0;t<r.length;t++){const n=r[t];if(!n)return void(i.failed=!0);const o=p(i,"it");i.hoist.push(`{ const ${o} = ${e}[${t}];`);const a=i.skipOutAssign??!1;i.skipOutAssign=!0,_(n,o,i),i.skipOutAssign=a,i.hoist.push(` ${s}[${t}] = ${o}; }`)}if(n){const t=p(i,"i"),o=p(i,"it");i.hoist.push(`for (let ${t} = ${r.length}; ${t} < ${e}.length; ${t}++) {`,` const ${o} = ${e}[${t}];`);const a=i.skipOutAssign??!1;i.skipOutAssign=!0,_(n,o,i),i.skipOutAssign=a,i.hoist.push(` ${s}[${t}] = ${o}; }`)}return void i.hoist.push(`${i.outParam} = ${s};`)}if("VldObject"===v(t)){const r=t._config?.shape;if(!r)return void(i.failed=!0);const n=p(i,"o");if(i.hoist.push(`if (typeof ${e} !== "object" || ${e} === null || Array.isArray(${e})) ${i.throwOnFail?"throw":"return"} ${i.invalid};`),i.validateOnly){for(const t of Object.keys(r)){const n=r[t];if(!n)return void(i.failed=!0);if(_(n,`${e}${/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)?`.${t}`:`[${JSON.stringify(t)}]`}`,i),i.failed)return}return void i.hoist.push(`${i.outParam} = true;`)}i.hoist.push(`const ${n} = {};`);for(const t of Object.keys(r)){const s=r[t];if(!s)return void(i.failed=!0);const o=/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)?`.${t}`:`[${JSON.stringify(t)}]`,a=p(i,"p");i.hoist.push(`{ const ${a} = ${e}${o};`);const u=i.skipOutAssign??!1;i.skipOutAssign=!0,_(s,a,i),i.skipOutAssign=u,i.hoist.push(` ${n}${o} = ${a}; }`)}return void i.hoist.push(`${i.outParam} = ${n};`)}if("VldRecord"===v(t)){const r=t.keyValidator,n=t.valueValidator,s=p(i,"rec"),o=p(i,"ks"),a=p(i,"i"),u=p(i,"k"),l=p(i,"v");return i.hoist.push(`if (typeof ${e} !== "object" || ${e} === null || Array.isArray(${e})) ${i.throwOnFail?"throw":"return"} ${i.invalid};`,`const ${s} = {};`,`const ${o} = Object.keys(${e});`,`for (let ${a} = 0; ${a} < ${o}.length; ${a}++) {`,` let ${u} = ${o}[${a}];`),_(r,u,i),i.hoist.push(` let ${l} = ${e}[${o}[${a}]];`),_(n,l,i),void i.hoist.push(` ${s}[${u}] = ${l};`,"}",""+(i.validateOnly?i.outParam+" = true; ":i.outParam+" = "+s+";"))}if("VldUnion"===v(t)){const e=t.validators.filter(t=>Boolean(t));if(0===e.length)return void(i.failed=!0);const r=p(i,"u");i.hoist.push(`let ${r} = ${i.invalid};`);for(let t=0;t<e.length;t++){const n=e[t],s=v(n);if("VldString"===s){i.hoist.push(`if (typeof value === "string") { ${r} = value; }`,`else if (${r} === ${i.invalid}) { /* fall through to next option */ }`);continue}if("VldNumber"===s){i.hoist.push(`if (typeof value === "number" && value === value) { ${r} = value; }`,`else if (${r} === ${i.invalid}) { /* fall through */ }`);continue}if("VldBoolean"===s){i.hoist.push(`if (typeof value === "boolean") { ${r} = value; }`,`else if (${r} === ${i.invalid}) { /* fall through */ }`);continue}if("VldNull"===s){i.hoist.push(`if (value === null) { ${r} = value; }`,`else if (${r} === ${i.invalid}) { /* fall through */ }`);continue}if("VldUndefined"===s){i.hoist.push(`if (value === undefined) { ${r} = value; }`,`else if (${r} === ${i.invalid}) { /* fall through */ }`);continue}if("VldLiteral"===s){const t=n._values||[];if(1===t.length){const e=t[0],n="number"==typeof e&&Number.isNaN(e)?"NaN":JSON.stringify(e);i.hoist.push(`if (Object.is(${n}, value)) { ${r} = value; }`,`else if (${r} === ${i.invalid}) { /* fall through */ }`);continue}}const o={invalid:i.invalid,outParam:r,scratch:0,hoist:[],failed:!1,skipOutAssign:!0};if(_(n,"value",o),o.failed)return void(i.failed=!0);i.hoist.push(`${r} = ((value) => {`,...o.hoist.map(t=>" "+t)," return value;","})(value);",`if (${r} !== ${i.invalid}) { /* matched */ }`)}return void i.hoist.push(`if (${r} === ${i.invalid}) ${i.throwOnFail?"throw":"return"} ${i.invalid}; ${i.outParam} = ${r};`)}i.failed=!0}else i.hoist.push((i.validateOnly?i.outParam+" = true; ":(i.skipOutAssign?"":i.outParam+" = ")+e)+";");else i.hoist.push(`if (${e} !== undefined) ${i.throwOnFail?"throw":"return"} ${i.invalid}; ${i.outParam} = undefined;`);else i.hoist.push(`if (${e} !== null) ${i.throwOnFail?"throw":"return"} ${i.invalid}; ${i.outParam} = null;`);else i.hoist.push(`{ const __v = ${e}; if (!(__v instanceof Date) || __v.getTime() !== __v.getTime()) ${i.throwOnFail?"throw":"return"} ${i.invalid}; ${i.outParam} = __v; }`)}else i.hoist.push(`if (typeof ${e} !== "boolean") ${i.throwOnFail?"throw":"return"} ${i.invalid}; ${i.validateOnly?i.outParam+" = true; ":(i.skipOutAssign?"":i.outParam+" = ")+e};`)}}function g(t,e){if(!t||"function"!=typeof t.parse)return null;const i=!!e?.validateOnly,r={invalid:"__INV",outParam:i?"__ok":"__out",scratch:0,hoist:[],failed:!1,validateOnly:i};if(r.hoist.push(i?"let __ok;":"let __out;"),_(t,"value",r),r.failed)return"1"===process.env.VLD_COMPILE_DEBUG&&console.error("[compile] failed to lower schema; partial body:\n"+r.hoist.join("\n")),null;r.hoist.push(i?"return __ok;":"return __out;");const n=r.hoist.join("\n"),s=new Function("value",r.invalid,n),o=t=>s(t,$);return Object.defineProperty(o,"__vld_compiled",{value:!0,enumerable:!1}),o}function m(t){return g(t,{validateOnly:!0})}function b(t,e,i){const r=t.parse.bind(t),n=t.safeParse.bind(t),s=$,o=i??e;return t.parse=t=>o(t)===s?r(t):t,t.safeParse=t=>o(t)===s?n(t):{success:!0,data:t},Object.defineProperty(t,"_zod",{value:{bag:{validator:e,validatorValidate:i}},enumerable:!1,configurable:!0}),t}function y(t,e){const i=t?._zod?.bag?.validator;if(i)return t;const r=function(t){return Object.create(Object.getPrototypeOf(t),Object.getOwnPropertyDescriptors(t))}(t);if(e?.JITless)return Object.defineProperty(r,"_zod",{value:{bag:{}},enumerable:!1,configurable:!0}),r;const n=m(r);return n?b(r,n,n):r}function O(t,e){const i=t?._zod?.bag?.validatorValidate??t?._zod?.bag?.validator;if(i)try{return i(e)!==$}catch{return!1}const r=t.safeParse(e);return Boolean(r?.success)}async function k(t,e){const i=t?._zod?.bag?.validatorValidate??t?._zod?.bag?.validator;if(i)try{return i(e)!==$}catch{return!1}const r=await t.safeParseAsync(e);return Boolean(r?.success)}function w(t){const e={};for(const i of Object.keys(t))e[i]=t[i].optional();return a.create(e)}function A(t,e,i){if(null===i||"object"!=typeof i||Array.isArray(i))return;const r=i[t];for(const i of e){const e=i._config?.shape;if(!e)continue;const n=e[t];if(!n)continue;const s=n._values||[];for(const t of s)if(Object.is(t,r))return i}}function P(h){if(h instanceof t)return h;if(null===h)return o.create();switch(null===h?"null":Array.isArray(h)?"array":typeof h){case"string":return e.create();case"number":return i.create();case"boolean":return r.create();case"bigint":return n.create();case"undefined":return s.create();case"array":return u.create(l.create());case"object":return a.create(h);default:return l.create()}}export{$ as COMPILE_INVALID,c as ZodCompileAsyncError,h as ZodCompileError,f as ZodCompileUnsupportedError,c as _ZodCompileAsyncError,f as _ZodCompileUnsupportedError,b as applyCompiled,y as compile,g as compileFn,m as compileFnValidate,A as getDiscriminatedOption,d as memoizer,w as properties,P as toZod,O as validate,k as validateAsync};
1
+ import{VldBase as t}from"./validators/base.js";import{VldString as e,COMPILABLE_FORMATS as i}from"./validators/string.js";import{VldNumber as r}from"./validators/number.js";import{VldBoolean as n}from"./validators/boolean.js";import{VldBigInt as a}from"./validators/bigint.js";import{VldUndefined as s}from"./validators/undefined.js";import{VldNull as o}from"./validators/null.js";import{VldObject as u}from"./validators/object.js";import{VldArray as l}from"./validators/array.js";import{VldUnknown as h}from"./validators/unknown.js";class f extends Error{constructor(t){super(t),this.name="ZodCompileError"}}class c extends f{constructor(t="Cannot compile async schema"){super(t),this.name="ZodCompileAsyncError"}}class $ extends f{constructor(t="Schema node is not supported by the AOT compiler"){super(t),this.name="ZodCompileUnsupportedError"}}const d=Symbol.for("@oxog/vld/compile-invalid");function v(t){return Object.create(Object.getPrototypeOf(t),Object.getOwnPropertyDescriptors(t))}const p=t=>{const e=new WeakMap;return i=>{const r=e.get(i);if(void 0!==r)return r;const n=t(i);return e.set(i,n),n}};function _(t){return t&&t.constructor&&t.constructor.name||""}function g(t,e,i){const r=`__re${t.regexTable.length}`;return t.regexTable.push({source:e,flags:i}),r}function m(t,e){return`__${e}${t.scratch++}`}function b(t,e,r){if(!r.failed){if("VldString"===_(t)){const n=t._checks,a=t._checkMetas;if(t._transforms?.length)return void(r.failed=!0);const s=[];if(a)for(const t of a)switch(t.kind){case"min":s.push(`__v.length >= ${t.value}`);break;case"max":s.push(`__v.length <= ${t.value}`);break;case"length":s.push(`__v.length === ${t.value}`);break;case"regex":{const e=t.pattern??t.value?.source??String(t.value);s.push(`${g(r,e,t.flags??"")}.test(__v)`);break}case"startsWith":s.push(`__v.startsWith(${JSON.stringify(t.value)})`);break;case"endsWith":s.push(`__v.endsWith(${JSON.stringify(t.value)})`);break;case"includes":s.push(`__v.includes(${JSON.stringify(t.value)})`);break;case"email":case"url":case"uuid":{const e=i[t.kind];s.push(`${g(r,e.source,e.flags)}.test(__v)`);break}case"format":if("email"===t.format||"url"===t.format||"uuid"===t.format){const e=i[t.format];s.push(`${g(r,e.source,e.flags)}.test(__v)`)}else{if(void 0===t.pattern)return void(r.failed=!0);s.push(`${g(r,t.pattern,t.flags??"")}.test(__v)`)}break;default:return void(r.failed=!0)}else if(n&&n.length>0)return void(r.failed=!0);return void(0===s.length?r.hoist.push(`if (typeof ${e} !== "string") ${r.throwOnFail?"throw":"return"} ${r.invalid}; ${r.validateOnly?r.outParam+" = true; ":(r.skipOutAssign?"":r.outParam+" = ")+e};`):r.hoist.push(`{ const __v = ${e}; if (typeof __v !== "string" || !(${s.join(" && ")})) ${r.throwOnFail?"throw":"return"} ${r.invalid}; ${r.outParam} = __v; }`))}if("VldNumber"===_(t)){const i=t._checks,n=t._checkMetas,a=[];if(n)for(const t of n)switch(t.kind){case"int":a.push("Number.isInteger(__v)");break;case"finite":a.push("Number.isFinite(__v)");break;case"min":a.push(!1!==t.inclusive?`__v >= ${t.value}`:`__v > ${t.value}`);break;case"max":a.push(!1!==t.inclusive?`__v <= ${t.value}`:`__v < ${t.value}`);break;case"gt":a.push(`__v > ${t.value}`);break;case"gte":a.push(`__v >= ${t.value}`);break;case"lt":a.push(`__v < ${t.value}`);break;case"lte":a.push(`__v <= ${t.value}`);break;case"multipleOf":a.push(`__v % ${t.value} === 0`);break;case"positive":a.push("__v > 0");break;case"negative":a.push("__v < 0");break;case"nonnegative":a.push("__v >= 0");break;case"nonpositive":a.push("__v <= 0");break;case"safe":a.push("Number.isSafeInteger(__v)");break;default:if(i&&i.length>0)return void(r.failed=!0)}else if(i&&i.length>0)return void(r.failed=!0);const s=['typeof __v === "number"',"!Number.isNaN(__v)",...a];return void r.hoist.push(`{ const __v = ${e}; if (!(${s.join(" && ")})) ${r.throwOnFail?"throw":"return"} ${r.invalid}; ${r.outParam} = __v; }`)}if("VldBoolean"!==_(t)){if("VldBigInt"===_(t)){const i=t._checks,n=t._checkMetas,a=[];if(n)for(const t of n)switch(t.kind){case"min":a.push(`__v >= ${t.value}n`);break;case"max":a.push(`__v <= ${t.value}n`);break;case"positive":a.push("__v > 0n");break;case"negative":a.push("__v < 0n");break;case"nonnegative":a.push("__v >= 0n");break;case"nonpositive":a.push("__v <= 0n");break;default:if(i&&i.length>0)return void(r.failed=!0)}else if(i&&i.length>0)return void(r.failed=!0);const s=['typeof __v === "bigint"',...a];return void r.hoist.push(`{ const __v = ${e}; if (!(${s.join(" && ")})) ${r.throwOnFail?"throw":"return"} ${r.invalid}; ${r.outParam} = __v; }`)}if("VldDate"!==_(t))if("VldNull"!==_(t))if("VldUndefined"!==_(t))if("VldAny"!==_(t)&&"VldUnknown"!==_(t)){if("VldLiteral"===_(t)){const i=t._values||[];if(0===i.length)return void r.hoist.push(`${r.throwOnFail?"throw":"return"} ${r.invalid};`);if(1===i.length){const t=i[0],n="number"==typeof t&&Number.isNaN(t)?"NaN":JSON.stringify(t);return void r.hoist.push(`if (!Object.is(${n}, ${e})) ${r.throwOnFail?"throw":"return"} ${r.invalid}; ${r.validateOnly?r.outParam+" = true; ":(r.skipOutAssign?"":r.outParam+" = ")+e};`)}const n=m(r,"set");return r.hoist.push(`const ${n} = new Set([${i.map(t=>"number"==typeof t&&Number.isNaN(t)?"NaN":JSON.stringify(t)).join(",")}]);`),void r.hoist.push(`if (!${n}.has(${e})) ${r.throwOnFail?"throw":"return"} ${r.invalid}; ${r.validateOnly?r.outParam+" = true; ":(r.skipOutAssign?"":r.outParam+" = ")+e};`)}if("VldEnum"===_(t)){const i=t._values||[],n=m(r,"set");return r.hoist.push(`const ${n} = new Set([${i.map(t=>JSON.stringify(t)).join(",")}]);`),void r.hoist.push(`if (!${n}.has(${e})) ${r.throwOnFail?"throw":"return"} ${r.invalid}; ${r.validateOnly?r.outParam+" = true; ":(r.skipOutAssign?"":r.outParam+" = ")+e};`)}if("VldOptional"===_(t)){const i=t.baseValidator;return r.hoist.push(`if (${e} === undefined) { ${r.outParam} = undefined; } else {`),b(i,e,r),void r.hoist.push("}")}if("VldDefault"===_(t)){if(!r.validateOnly)return void(r.failed=!0);const i=t.baseValidator;return r.hoist.push(`if (${e} === undefined) { ${r.outParam} = true; } else {`),b(i,e,r),void r.hoist.push("}")}if("VldArray"===_(t)){const i=t.config;if(i?.unique)return void(r.failed=!0);const n=i?.itemValidator??t.config?.element;if(!n)return void(r.failed=!0);const a=[];"number"==typeof i?.exactLength?a.push(`if (${e}.length !== ${i.exactLength}) ${r.throwOnFail?"throw":"return"} ${r.invalid};`):("number"==typeof i?.minLength&&a.push(`if (${e}.length < ${i.minLength}) ${r.throwOnFail?"throw":"return"} ${r.invalid};`),"number"==typeof i?.maxLength&&a.push(`if (${e}.length > ${i.maxLength}) ${r.throwOnFail?"throw":"return"} ${r.invalid};`));const s=m(r,"arr"),o=m(r,"i");if("VldObject"===_(n)){if(r.hoist.push(`if (!Array.isArray(${e})) ${r.throwOnFail?"throw":"return"} ${r.invalid};`,...a),r.validateOnly){if(r.hoist.push(`for (let ${o} = 0; ${o} < ${e}.length; ${o}++) {`),b(n,`${e}[${o}]`,r),r.failed)return;return r.hoist.push("}"),void r.hoist.push(`${r.outParam} = true;`)}r.hoist.push(`const ${s} = new Array(${e}.length);`);const t={invalid:r.invalid,outParam:"__slot",scratch:0,hoist:[],failed:!1,skipOutAssign:!0,regexTable:r.regexTable};return t.hoist.push(`for (let ${o} = 0; ${o} < ${e}.length; ${o}++) {`," let __slot;"),b(n,`${e}[${o}]`,t),t.failed?void(r.failed=!0):(t.hoist.push(` ${s}[${o}] = __slot;`,"}"),r.hoist.push(...t.hoist),void r.hoist.push(`${r.outParam} = ${s};`))}const u=m(r,"it");if(r.hoist.push(`if (!Array.isArray(${e})) ${r.throwOnFail?"throw":"return"} ${r.invalid};`,...a),r.validateOnly)return r.hoist.push(`for (let ${o} = 0; ${o} < ${e}.length; ${o}++) {`,` const ${u} = ${e}[${o}];`),b(n,u,r),r.hoist.push("}"),void r.hoist.push(`${r.outParam} = true;`);if(r.hoist.push(`const ${s} = new Array(${e}.length);`,`for (let ${o} = 0; ${o} < ${e}.length; ${o}++) {`),b(n,`${e}[${o}]`,r),r.failed)return;return void r.hoist.push(` ${s}[${o}] = ${e}[${o}];`,"}",`${r.outParam} = ${s};`)}if("VldTuple"===_(t)){const i=t.validators.filter(t=>Boolean(t)),n=t.restValidator,a=m(r,"tup"),s=n?`${e}.length < ${i.length}`:`${e}.length !== ${i.length}`;if(r.hoist.push(`if (!Array.isArray(${e}) || ${s}) ${r.throwOnFail?"throw":"return"} ${r.invalid};`),r.validateOnly){for(let t=0;t<i.length;t++){const n=i[t];if(!n)return void(r.failed=!0);if(b(n,`${e}[${t}]`,r),r.failed)return}if(n){const t=m(r,"i");r.hoist.push(`for (let ${t} = ${i.length}; ${t} < ${e}.length; ${t}++) {`),b(n,`${e}[${t}]`,r),r.hoist.push("}")}return void r.hoist.push(`${r.outParam} = true;`)}r.hoist.push(`const ${a} = new Array(${e}.length);`);for(let t=0;t<i.length;t++){const n=i[t];if(!n)return void(r.failed=!0);const s=m(r,"it");r.hoist.push(`{ const ${s} = ${e}[${t}];`);const o=r.skipOutAssign??!1;r.skipOutAssign=!0,b(n,s,r),r.skipOutAssign=o,r.hoist.push(` ${a}[${t}] = ${s}; }`)}if(n){const t=m(r,"i"),s=m(r,"it");r.hoist.push(`for (let ${t} = ${i.length}; ${t} < ${e}.length; ${t}++) {`,` const ${s} = ${e}[${t}];`);const o=r.skipOutAssign??!1;r.skipOutAssign=!0,b(n,s,r),r.skipOutAssign=o,r.hoist.push(` ${a}[${t}] = ${s}; }`)}return void r.hoist.push(`${r.outParam} = ${a};`)}if("VldObject"===_(t)){const i=t._config?.shape;if(!i)return void(r.failed=!0);const n=t._config;if(n?.strict||n?.passthrough||n?.catchall)return void(r.failed=!0);const a=m(r,"o");if(r.hoist.push(`if (typeof ${e} !== "object" || ${e} === null || Array.isArray(${e})) ${r.throwOnFail?"throw":"return"} ${r.invalid};`),r.validateOnly){for(const t of Object.keys(i)){const n=i[t];if(!n)return void(r.failed=!0);if(b(n,`${e}${/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)?`.${t}`:`[${JSON.stringify(t)}]`}`,r),r.failed)return}return void r.hoist.push(`${r.outParam} = true;`)}r.hoist.push(`const ${a} = {};`);for(const t of Object.keys(i)){const n=i[t];if(!n)return void(r.failed=!0);const s=/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)?`.${t}`:`[${JSON.stringify(t)}]`,o=m(r,"p");r.hoist.push(`{ const ${o} = ${e}${s};`);const u=r.skipOutAssign??!1;r.skipOutAssign=!0,b(n,o,r),r.skipOutAssign=u,r.hoist.push(` ${a}${s} = ${o}; }`)}return void r.hoist.push(`${r.outParam} = ${a};`)}if("VldRecord"===_(t)){const i=t.keyValidator,n=t.valueValidator,a=m(r,"rec"),s=m(r,"ks"),o=m(r,"i"),u=m(r,"k"),l=m(r,"v");return r.hoist.push(`if (typeof ${e} !== "object" || ${e} === null || Array.isArray(${e})) ${r.throwOnFail?"throw":"return"} ${r.invalid};`,`const ${a} = {};`,`const ${s} = Object.keys(${e});`,`for (let ${o} = 0; ${o} < ${s}.length; ${o}++) {`,` let ${u} = ${s}[${o}];`),b(i,u,r),r.hoist.push(` let ${l} = ${e}[${s}[${o}]];`),b(n,l,r),void r.hoist.push(` ${a}[${u}] = ${l};`,"}",""+(r.validateOnly?r.outParam+" = true; ":r.outParam+" = "+a+";"))}if("VldUnion"===_(t)){const e=t.validators.filter(t=>Boolean(t));if(0===e.length)return void(r.failed=!0);const i=m(r,"u");r.hoist.push(`let ${i} = ${r.invalid};`);for(let t=0;t<e.length;t++){const n=e[t],a=_(n);if("VldString"===a){r.hoist.push(`if (typeof value === "string") { ${i} = value; }`,`else if (${i} === ${r.invalid}) { /* fall through to next option */ }`);continue}if("VldNumber"===a){r.hoist.push(`if (typeof value === "number" && value === value) { ${i} = value; }`,`else if (${i} === ${r.invalid}) { /* fall through */ }`);continue}if("VldBoolean"===a){r.hoist.push(`if (typeof value === "boolean") { ${i} = value; }`,`else if (${i} === ${r.invalid}) { /* fall through */ }`);continue}if("VldNull"===a){r.hoist.push(`if (value === null) { ${i} = value; }`,`else if (${i} === ${r.invalid}) { /* fall through */ }`);continue}if("VldUndefined"===a){r.hoist.push(`if (value === undefined) { ${i} = value; }`,`else if (${i} === ${r.invalid}) { /* fall through */ }`);continue}if("VldLiteral"===a){const t=n._values||[];if(1===t.length){const e=t[0],n="number"==typeof e&&Number.isNaN(e)?"NaN":JSON.stringify(e);r.hoist.push(`if (Object.is(${n}, value)) { ${i} = value; }`,`else if (${i} === ${r.invalid}) { /* fall through */ }`);continue}}const s={invalid:r.invalid,outParam:i,scratch:0,hoist:[],failed:!1,skipOutAssign:!0,regexTable:r.regexTable};if(b(n,"value",s),s.failed)return void(r.failed=!0);r.hoist.push(`${i} = ((value) => {`,...s.hoist.map(t=>" "+t)," return value;","})(value);",`if (${i} !== ${r.invalid}) { /* matched */ }`)}return void r.hoist.push(`if (${i} === ${r.invalid}) ${r.throwOnFail?"throw":"return"} ${r.invalid}; ${r.outParam} = ${i};`)}r.failed=!0}else r.hoist.push((r.validateOnly?r.outParam+" = true; ":(r.skipOutAssign?"":r.outParam+" = ")+e)+";");else r.hoist.push(`if (${e} !== undefined) ${r.throwOnFail?"throw":"return"} ${r.invalid}; ${r.outParam} = undefined;`);else r.hoist.push(`if (${e} !== null) ${r.throwOnFail?"throw":"return"} ${r.invalid}; ${r.outParam} = null;`);else r.hoist.push(`{ const __v = ${e}; if (!(__v instanceof Date) || __v.getTime() !== __v.getTime()) ${r.throwOnFail?"throw":"return"} ${r.invalid}; ${r.outParam} = __v; }`)}else r.hoist.push(`if (typeof ${e} !== "boolean") ${r.throwOnFail?"throw":"return"} ${r.invalid}; ${r.validateOnly?r.outParam+" = true; ":(r.skipOutAssign?"":r.outParam+" = ")+e};`)}}function y(t,e){if(!t||"function"!=typeof t.parse)return null;const i=!!e?.validateOnly,r={invalid:"__INV",outParam:i?"__ok":"__out",scratch:0,hoist:[],failed:!1,validateOnly:i,regexTable:[]};if(r.hoist.push(i?"let __ok;":"let __out;"),b(t,"value",r),r.failed)return"1"===process.env.VLD_COMPILE_DEBUG&&console.error("[compile] failed to lower schema; partial body:\n"+r.hoist.join("\n")),null;r.hoist.push(i?"return __ok;":"return __out;");const n=[...r.regexTable.map((t,e)=>`const __re${e} = __re[${e}];`),...r.hoist].join("\n"),a=new Function("value",r.invalid,"__re",n),s=r.regexTable.map(t=>new RegExp(t.source,t.flags)),o=t=>a(t,d,s);return Object.defineProperty(o,"__vld_compiled",{value:!0,enumerable:!1}),o}function O(t){return y(t,{validateOnly:!0})}function k(t,e,i){const r=t.parse.bind(t),n=t.safeParse.bind(t),a=d,s=i??e;return t.parse=t=>s(t)===a?r(t):t,t.safeParse=t=>s(t)===a?n(t):{success:!0,data:t},Object.defineProperty(t,"_zod",{value:{bag:{validator:e,validatorValidate:i}},enumerable:!1,configurable:!0}),t}function w(t,e){const i=t?._zod?.bag?.validator;if(i)return t;const r=v(t);if(e?.JITless)return Object.defineProperty(r,"_zod",{value:{bag:{}},enumerable:!1,configurable:!0}),r;const n=O(r);return n?k(r,n,n):r}function P(t,e){const i=v(t),r=i.parse.bind(i),n=i.safeParse.bind(i);return i.parse=t=>{const i=e(t);return i===d?r(t):i},i.safeParse=t=>{const i=e(t);return i===d?n(t):{success:!0,data:i}},Object.defineProperty(i,"_zod",{value:{bag:{validator:e}},enumerable:!1,configurable:!0}),i}function A(t,e){const i=t?._zod?.bag?.validatorValidate??t?._zod?.bag?.validator;if(i)try{return i(e)!==d}catch{return!1}const r=t.safeParse(e);return Boolean(r?.success)}async function j(t,e){const i=t?._zod?.bag?.validatorValidate??t?._zod?.bag?.validator;if(i)try{return i(e)!==d}catch{return!1}const r=await t.safeParseAsync(e);return Boolean(r?.success)}function V(t){const e={};for(const i of Object.keys(t))e[i]=t[i].optional();return u.create(e)}function N(t,e,i){if(null===i||"object"!=typeof i||Array.isArray(i))return;const r=i[t];for(const i of e){const e=i._config?.shape;if(!e)continue;const n=e[t];if(!n)continue;const a=n._values||[];for(const t of a)if(Object.is(t,r))return i}}function x(i){if(i instanceof t)return i;if(null===i)return o.create();switch(null===i?"null":Array.isArray(i)?"array":typeof i){case"string":return e.create();case"number":return r.create();case"boolean":return n.create();case"bigint":return a.create();case"undefined":return s.create();case"array":return l.create(h.create());case"object":return u.create(i);default:return h.create()}}globalThis["@oxog/vld/lazy-validate-compiler"]=t=>O(t);export{d as COMPILE_INVALID,c as ZodCompileAsyncError,f as ZodCompileError,$ as ZodCompileUnsupportedError,c as _ZodCompileAsyncError,$ as _ZodCompileUnsupportedError,k as applyCompiled,w as compile,y as compileFn,O as compileFnValidate,N as getDiscriminatedOption,p as memoizer,V as properties,x as toZod,A as validate,j as validateAsync,P as withParser};
package/dist/index.d.ts CHANGED
@@ -55,7 +55,7 @@ import { VldDiscriminatedUnion } from './validators/discriminated-union.js';
55
55
  import { VldXor } from './validators/xor.js';
56
56
  import { VldJson } from './validators/json.js';
57
57
  import { VldTemplateLiteral } from './validators/template-literal.js';
58
- import { VldCustom, custom as customFn } from './validators/custom.js';
58
+ import { VldCustom, VldInstance, custom as customFn } from './validators/custom.js';
59
59
  import { VldFile } from './validators/file.js';
60
60
  import { VldFunction } from './validators/function.js';
61
61
  import { VldBrand, VldCatch, VldDefault, VldExactOptional, VldMeta, VldNullable, VldNullish, VldOptional, VldPipe, VldPrefault, VldPreprocess, VldReadonly, VldRefine, VldTransform } from './validators/base.js';
@@ -73,7 +73,7 @@ import { VldCoerceDate } from './coercion/date.js';
73
73
  import { VldCoerceBigInt } from './coercion/bigint.js';
74
74
  import { flattenError as flattenErrorFn, prettifyError as prettifyErrorFn, treeifyError as treeifyErrorFn } from './errors.js';
75
75
  import { fromJSONSchema as fromJSONSchemaFn, toJSONSchema as toJSONSchemaFn } from './utils/json-schema.js';
76
- import { validate as validateFn, validateAsync as validateAsyncFn, properties as propertiesFn, getDiscriminatedOption as getDiscriminatedOptionFn, toZod as toZodFn, ZodCompileError as ZodCompileErrorClass, ZodCompileAsyncError as ZodCompileAsyncErrorClass, ZodCompileUnsupportedError as ZodCompileUnsupportedErrorClass } from './compile.js';
76
+ import { validate as validateFn, validateAsync as validateAsyncFn, properties as propertiesFn, getDiscriminatedOption as getDiscriminatedOptionFn, toZod as toZodFn, withParser as withParserFn, COMPILE_INVALID, ZodCompileError as ZodCompileErrorClass, ZodCompileAsyncError as ZodCompileAsyncErrorClass, ZodCompileUnsupportedError as ZodCompileUnsupportedErrorClass } from './compile.js';
77
77
  import * as stringFormats from './validators/string-formats.js';
78
78
  type NativeEnumLike = Record<string, string | number>;
79
79
  type Constructor<T = unknown> = abstract new (...args: any[]) => T;
@@ -145,7 +145,7 @@ export declare const core: {
145
145
  readonly nullish: (value: unknown) => value is null | undefined;
146
146
  readonly cached: <T>(getter: () => T) => (() => T);
147
147
  };
148
- readonly regexes: Readonly<Record<"number" | "bigint" | "boolean" | "undefined" | "integer" | "date" | "null" | "hex" | "base64" | "email" | "base64url" | "jwt" | "nanoid" | "cuid" | "cuid2" | "ulid" | "cidrv4" | "cidrv6" | "e164" | "xid" | "guid" | "ksuid" | "duration" | "ipv4" | "ipv6" | "browserEmail" | "creditCard" | "domain" | "extendedDuration" | "hostname" | "html5Email" | "httpProtocol" | "httpUrl" | "idnEmail" | "lowercase" | "md5" | "md5_base64" | "md5_base64url" | "md5_hex" | "rfc5322Email" | "sha1" | "sha1_base64" | "sha1_base64url" | "sha1_hex" | "sha256" | "sha256_base64" | "sha256_base64url" | "sha256_hex" | "sha384" | "sha384_base64" | "sha384_base64url" | "sha384_hex" | "sha512" | "sha512_base64" | "sha512_base64url" | "sha512_hex" | "unicodeEmail" | "uppercase" | "uuid4" | "uuid6" | "uuid7", RegExp> & {
148
+ readonly regexes: Readonly<Record<"number" | "bigint" | "boolean" | "undefined" | "integer" | "date" | "null" | "hex" | "base64" | "email" | "base64url" | "jwt" | "nanoid" | "cuid" | "cuid2" | "ulid" | "cidrv4" | "cidrv6" | "e164" | "xid" | "guid" | "ksuid" | "duration" | "ipv4" | "ipv6" | "anyString" | "browserEmail" | "creditCard" | "currencyCode" | "domain" | "extendedDuration" | "hostname" | "html5Email" | "httpProtocol" | "httpUrl" | "iban" | "idnEmail" | "lowercase" | "md5" | "md5_base64" | "md5_base64url" | "md5_hex" | "rfc5322Email" | "sha1" | "sha1_base64" | "sha1_base64url" | "sha1_hex" | "sha256" | "sha256_base64" | "sha256_base64url" | "sha256_hex" | "sha384" | "sha384_base64" | "sha384_base64url" | "sha384_hex" | "sha512" | "sha512_base64" | "sha512_base64url" | "sha512_hex" | "unicodeEmail" | "uppercase" | "uuid4" | "uuid6" | "uuid7", RegExp> & {
149
149
  nanoidOfLength: (length: number) => RegExp;
150
150
  datetime: (options?: stringFormats.ISODateTimeOptions) => RegExp;
151
151
  emoji: () => RegExp;
@@ -193,8 +193,8 @@ export type { Infer, Input, Output } from './validators/index.js';
193
193
  export { VldBase } from './validators/base.js';
194
194
  export { VldIntersection } from './validators/intersection.js';
195
195
  export { VldMeta, type SchemaMetadata } from './validators/base.js';
196
- export { VldBase as ZodType, VldAny as ZodAny, VldArray as ZodArray, VldBigInt as ZodBigInt, VldBigInt as ZodBigIntFormat, VldBoolean as ZodBoolean, VldBrand as ZodBranded, VldCatch as ZodCatch, VldCodec as ZodCodec, VldCustom as ZodCustom, VldCustom as ZodSuccess, VldDate as ZodDate, VldDefault as ZodDefault, VldDiscriminatedUnion as ZodDiscriminatedUnion, VldEnum as ZodEnum, VldExactOptional as ZodExactOptional, VldFile as ZodFile, VldFunction as ZodFunction, VldIntersection as ZodIntersection, VldJson as ZodJSON, VldLazy as ZodLazy, VldLiteral as ZodLiteral, VldMap as ZodMap, VldMeta as ZodMeta, VldNan as ZodNaN, VldNever as ZodNever, VldNull as ZodNull, VldNullable as ZodNullable, VldNumber as ZodNumber, VldNumber as ZodNumberFormat, VldObject as ZodObject, VldOptional as ZodOptional, VldPipe as ZodPipe, VldPrefault as ZodPrefault, VldPreprocess as ZodPreprocess, VldPromise as ZodPromise, VldReadonly as ZodReadonly, VldRecord as ZodRecord, VldRefine as ZodNonOptional, VldSet as ZodSet, VldString as ZodString, VldSymbol as ZodSymbol, VldTemplateLiteral as ZodTemplateLiteral, VldTuple as ZodTuple, VldTransform as ZodTransform, VldUndefined as ZodUndefined, VldUnion as ZodUnion, VldUnknown as ZodUnknown, VldVoid as ZodVoid, VldXor as ZodXor };
197
- export { VldStringFormat as ZodBase64, VldStringFormat as ZodBase64URL, VldStringFormat as ZodCIDRv4, VldStringFormat as ZodCIDRv6, VldStringFormat as ZodCUID, VldStringFormat as ZodCUID2, VldStringFormat as ZodCreditCard, VldStringFormat as ZodCustomStringFormat, VldStringFormat as ZodE164, VldStringFormat as ZodEmail, VldStringFormat as ZodEmoji, VldStringFormat as ZodGUID, VldStringFormat as ZodIPv4, VldStringFormat as ZodIPv6, VldStringFormat as ZodISODate, VldStringFormat as ZodISODateTime, VldStringFormat as ZodISODuration, VldStringFormat as ZodISOTime, VldStringFormat as ZodJWT, VldStringFormat as ZodKSUID, VldStringFormat as ZodMAC, VldStringFormat as ZodNanoID, VldStringFormat as ZodStringFormat, VldStringFormat as ZodULID, VldStringFormat as ZodURL, VldStringFormat as ZodUUID, VldStringFormat as ZodXID } from './validators/string-formats.js';
196
+ export { VldBase as ZodType, VldAny as ZodAny, VldArray as ZodArray, VldBigInt as ZodBigInt, VldBigInt as ZodBigIntFormat, VldBoolean as ZodBoolean, VldBrand as ZodBranded, VldCatch as ZodCatch, VldCodec as ZodCodec, VldCustom as ZodCustom, VldCustom as ZodSuccess, VldDate as ZodDate, VldDefault as ZodDefault, VldDiscriminatedUnion as ZodDiscriminatedUnion, VldEnum as ZodEnum, VldExactOptional as ZodExactOptional, VldFile as ZodFile, VldFunction as ZodFunction, VldIntersection as ZodIntersection, VldInstance as ZodInstanceOf, VldJson as ZodJSON, VldLazy as ZodLazy, VldLiteral as ZodLiteral, VldMap as ZodMap, VldMeta as ZodMeta, VldNan as ZodNaN, VldNever as ZodNever, VldNull as ZodNull, VldNullable as ZodNullable, VldNumber as ZodNumber, VldNumber as ZodNumberFormat, VldObject as ZodObject, VldOptional as ZodOptional, VldPipe as ZodPipe, VldPrefault as ZodPrefault, VldPreprocess as ZodPreprocess, VldPromise as ZodPromise, VldReadonly as ZodReadonly, VldRecord as ZodRecord, VldRefine as ZodNonOptional, VldSet as ZodSet, VldString as ZodString, VldSymbol as ZodSymbol, VldTemplateLiteral as ZodTemplateLiteral, VldTuple as ZodTuple, VldTransform as ZodTransform, VldUndefined as ZodUndefined, VldUnion as ZodUnion, VldUnknown as ZodUnknown, VldVoid as ZodVoid, VldXor as ZodXor };
197
+ export { VldStringFormat as ZodBase64, VldStringFormat as ZodBase64URL, VldStringFormat as ZodCIDRv4, VldStringFormat as ZodCIDRv6, VldStringFormat as ZodCUID, VldStringFormat as ZodCUID2, VldStringFormat as ZodCreditCard, VldStringFormat as ZodCustomStringFormat, VldStringFormat as ZodE164, VldStringFormat as ZodEmail, VldStringFormat as ZodEmoji, VldStringFormat as ZodGUID, VldStringFormat as ZodIBAN, VldStringFormat as ZodIPv4, VldStringFormat as ZodIPv6, VldStringFormat as ZodISODate, VldStringFormat as ZodISODateTime, VldStringFormat as ZodISODuration, VldStringFormat as ZodISOTime, VldStringFormat as ZodJWT, VldStringFormat as ZodKSUID, VldStringFormat as ZodMAC, VldStringFormat as ZodNanoID, VldStringFormat as ZodStringFormat, VldStringFormat as ZodULID, VldStringFormat as ZodURL, VldStringFormat as ZodUUID, VldStringFormat as ZodXID } from './validators/string-formats.js';
198
198
  export { VldError as ZodError, VldError as ZodRealError } from './errors.js';
199
199
  export { registry, globalRegistry, type SchemaRegistry } from './registry.js';
200
200
  export { setLocale, setLocaleAsync, registerLocale, getLocale, getMessages, isLocaleLoaded, getSupportedLocales, isLocaleSupported, type Locale } from './locales/index.js';
@@ -356,7 +356,7 @@ export declare const v: {
356
356
  check: <T = unknown>(schemaOrPredicate: VldBase<unknown, T> | ((value: T) => boolean | Promise<boolean>), predicateOrMessage?: ((value: T) => boolean | Promise<boolean>) | RefinementMessage, message?: RefinementMessage) => VldBase<unknown, T>;
357
357
  superRefine: <T = unknown>(schemaOrRefinement: VldBase<unknown, T> | ((value: T, ctx: SuperRefineContext) => void | Promise<void>), refinement?: (value: T, ctx: SuperRefineContext) => void | Promise<void>) => VldBase<unknown, T>;
358
358
  property: typeof propertyCheck;
359
- instanceof: <T>(constructor: Constructor<T>, message?: RefinementMessage) => VldCustom<T>;
359
+ instanceof: <T>(constructor: Constructor<T>, message?: RefinementMessage) => VldInstance<T>;
360
360
  config: typeof configure;
361
361
  setErrorMap: typeof setGlobalErrorMap;
362
362
  getErrorMap: typeof getGlobalErrorMap;
@@ -372,7 +372,7 @@ export declare const v: {
372
372
  readonly nullish: (value: unknown) => value is null | undefined;
373
373
  readonly cached: <T>(getter: () => T) => (() => T);
374
374
  };
375
- readonly regexes: Readonly<Record<"number" | "bigint" | "boolean" | "undefined" | "integer" | "date" | "null" | "hex" | "base64" | "email" | "base64url" | "jwt" | "nanoid" | "cuid" | "cuid2" | "ulid" | "cidrv4" | "cidrv6" | "e164" | "xid" | "guid" | "ksuid" | "duration" | "ipv4" | "ipv6" | "browserEmail" | "creditCard" | "domain" | "extendedDuration" | "hostname" | "html5Email" | "httpProtocol" | "httpUrl" | "idnEmail" | "lowercase" | "md5" | "md5_base64" | "md5_base64url" | "md5_hex" | "rfc5322Email" | "sha1" | "sha1_base64" | "sha1_base64url" | "sha1_hex" | "sha256" | "sha256_base64" | "sha256_base64url" | "sha256_hex" | "sha384" | "sha384_base64" | "sha384_base64url" | "sha384_hex" | "sha512" | "sha512_base64" | "sha512_base64url" | "sha512_hex" | "unicodeEmail" | "uppercase" | "uuid4" | "uuid6" | "uuid7", RegExp> & {
375
+ readonly regexes: Readonly<Record<"number" | "bigint" | "boolean" | "undefined" | "integer" | "date" | "null" | "hex" | "base64" | "email" | "base64url" | "jwt" | "nanoid" | "cuid" | "cuid2" | "ulid" | "cidrv4" | "cidrv6" | "e164" | "xid" | "guid" | "ksuid" | "duration" | "ipv4" | "ipv6" | "anyString" | "browserEmail" | "creditCard" | "currencyCode" | "domain" | "extendedDuration" | "hostname" | "html5Email" | "httpProtocol" | "httpUrl" | "iban" | "idnEmail" | "lowercase" | "md5" | "md5_base64" | "md5_base64url" | "md5_hex" | "rfc5322Email" | "sha1" | "sha1_base64" | "sha1_base64url" | "sha1_hex" | "sha256" | "sha256_base64" | "sha256_base64url" | "sha256_hex" | "sha384" | "sha384_base64" | "sha384_base64url" | "sha384_hex" | "sha512" | "sha512_base64" | "sha512_base64url" | "sha512_hex" | "unicodeEmail" | "uppercase" | "uuid4" | "uuid6" | "uuid7", RegExp> & {
376
376
  nanoidOfLength: (length: number) => RegExp;
377
377
  datetime: (options?: stringFormats.ISODateTimeOptions) => RegExp;
378
378
  emoji: () => RegExp;
@@ -474,6 +474,12 @@ export declare const v: {
474
474
  creditCard: (params?: {
475
475
  message?: string;
476
476
  }) => stringFormats.VldStringFormat;
477
+ iban: (params?: {
478
+ message?: string;
479
+ }) => stringFormats.VldStringFormat;
480
+ currencyCode: (params?: {
481
+ message?: string;
482
+ }) => stringFormats.VldStringFormat;
477
483
  e164: () => stringFormats.VldStringFormat;
478
484
  hash: (algorithm: "md5" | "sha1" | "sha256" | "sha384" | "sha512") => stringFormats.VldStringFormat;
479
485
  iso: {
@@ -519,7 +525,7 @@ export declare const v: {
519
525
  guid: () => stringFormats.VldStringFormat;
520
526
  httpUrl: () => stringFormats.VldStringFormat;
521
527
  ksuid: () => stringFormats.VldStringFormat;
522
- regexes: Readonly<Record<"number" | "bigint" | "boolean" | "undefined" | "integer" | "date" | "null" | "hex" | "base64" | "email" | "base64url" | "jwt" | "nanoid" | "cuid" | "cuid2" | "ulid" | "cidrv4" | "cidrv6" | "e164" | "xid" | "guid" | "ksuid" | "duration" | "ipv4" | "ipv6" | "browserEmail" | "creditCard" | "domain" | "extendedDuration" | "hostname" | "html5Email" | "httpProtocol" | "httpUrl" | "idnEmail" | "lowercase" | "md5" | "md5_base64" | "md5_base64url" | "md5_hex" | "rfc5322Email" | "sha1" | "sha1_base64" | "sha1_base64url" | "sha1_hex" | "sha256" | "sha256_base64" | "sha256_base64url" | "sha256_hex" | "sha384" | "sha384_base64" | "sha384_base64url" | "sha384_hex" | "sha512" | "sha512_base64" | "sha512_base64url" | "sha512_hex" | "unicodeEmail" | "uppercase" | "uuid4" | "uuid6" | "uuid7", RegExp> & {
528
+ regexes: Readonly<Record<"number" | "bigint" | "boolean" | "undefined" | "integer" | "date" | "null" | "hex" | "base64" | "email" | "base64url" | "jwt" | "nanoid" | "cuid" | "cuid2" | "ulid" | "cidrv4" | "cidrv6" | "e164" | "xid" | "guid" | "ksuid" | "duration" | "ipv4" | "ipv6" | "anyString" | "browserEmail" | "creditCard" | "currencyCode" | "domain" | "extendedDuration" | "hostname" | "html5Email" | "httpProtocol" | "httpUrl" | "iban" | "idnEmail" | "lowercase" | "md5" | "md5_base64" | "md5_base64url" | "md5_hex" | "rfc5322Email" | "sha1" | "sha1_base64" | "sha1_base64url" | "sha1_hex" | "sha256" | "sha256_base64" | "sha256_base64url" | "sha256_hex" | "sha384" | "sha384_base64" | "sha384_base64url" | "sha384_hex" | "sha512" | "sha512_base64" | "sha512_base64url" | "sha512_hex" | "unicodeEmail" | "uppercase" | "uuid4" | "uuid6" | "uuid7", RegExp> & {
523
529
  nanoidOfLength: (length: number) => RegExp;
524
530
  datetime: (options?: stringFormats.ISODateTimeOptions) => RegExp;
525
531
  emoji: () => RegExp;
@@ -534,6 +540,8 @@ export declare const v: {
534
540
  compile: <T extends VldBase<any, any>>(schema: T, options?: {
535
541
  JITless?: boolean;
536
542
  }) => T;
543
+ withParser: <T extends VldBase<any, any>>(schema: T, parser: (input: unknown) => unknown) => T;
544
+ INVALID: symbol;
537
545
  validate: typeof validateFn;
538
546
  validateAsync: typeof validateAsyncFn;
539
547
  properties: typeof propertiesFn;
@@ -659,7 +667,7 @@ export declare const v: {
659
667
  $input: symbol;
660
668
  };
661
669
  /**
662
- * v3.0: vV2 drop-in factory that uses V2 validators everywhere.
670
+ * v3.0: vV2 - drop-in factory that uses V2 validators everywhere.
663
671
  * Recommended for new code and migrations from Zod 4.5.
664
672
  *
665
673
  * import { vV2 as v } from '@oxog/vld';
@@ -890,7 +898,7 @@ export declare const z: {
890
898
  check: <T = unknown>(schemaOrPredicate: VldBase<unknown, T> | ((value: T) => boolean | Promise<boolean>), predicateOrMessage?: ((value: T) => boolean | Promise<boolean>) | RefinementMessage, message?: RefinementMessage) => VldBase<unknown, T>;
891
899
  superRefine: <T = unknown>(schemaOrRefinement: VldBase<unknown, T> | ((value: T, ctx: SuperRefineContext) => void | Promise<void>), refinement?: (value: T, ctx: SuperRefineContext) => void | Promise<void>) => VldBase<unknown, T>;
892
900
  property: typeof propertyCheck;
893
- instanceof: <T>(constructor: Constructor<T>, message?: RefinementMessage) => VldCustom<T>;
901
+ instanceof: <T>(constructor: Constructor<T>, message?: RefinementMessage) => VldInstance<T>;
894
902
  config: typeof configure;
895
903
  setErrorMap: typeof setGlobalErrorMap;
896
904
  getErrorMap: typeof getGlobalErrorMap;
@@ -906,7 +914,7 @@ export declare const z: {
906
914
  readonly nullish: (value: unknown) => value is null | undefined;
907
915
  readonly cached: <T>(getter: () => T) => (() => T);
908
916
  };
909
- readonly regexes: Readonly<Record<"number" | "bigint" | "boolean" | "undefined" | "integer" | "date" | "null" | "hex" | "base64" | "email" | "base64url" | "jwt" | "nanoid" | "cuid" | "cuid2" | "ulid" | "cidrv4" | "cidrv6" | "e164" | "xid" | "guid" | "ksuid" | "duration" | "ipv4" | "ipv6" | "browserEmail" | "creditCard" | "domain" | "extendedDuration" | "hostname" | "html5Email" | "httpProtocol" | "httpUrl" | "idnEmail" | "lowercase" | "md5" | "md5_base64" | "md5_base64url" | "md5_hex" | "rfc5322Email" | "sha1" | "sha1_base64" | "sha1_base64url" | "sha1_hex" | "sha256" | "sha256_base64" | "sha256_base64url" | "sha256_hex" | "sha384" | "sha384_base64" | "sha384_base64url" | "sha384_hex" | "sha512" | "sha512_base64" | "sha512_base64url" | "sha512_hex" | "unicodeEmail" | "uppercase" | "uuid4" | "uuid6" | "uuid7", RegExp> & {
917
+ readonly regexes: Readonly<Record<"number" | "bigint" | "boolean" | "undefined" | "integer" | "date" | "null" | "hex" | "base64" | "email" | "base64url" | "jwt" | "nanoid" | "cuid" | "cuid2" | "ulid" | "cidrv4" | "cidrv6" | "e164" | "xid" | "guid" | "ksuid" | "duration" | "ipv4" | "ipv6" | "anyString" | "browserEmail" | "creditCard" | "currencyCode" | "domain" | "extendedDuration" | "hostname" | "html5Email" | "httpProtocol" | "httpUrl" | "iban" | "idnEmail" | "lowercase" | "md5" | "md5_base64" | "md5_base64url" | "md5_hex" | "rfc5322Email" | "sha1" | "sha1_base64" | "sha1_base64url" | "sha1_hex" | "sha256" | "sha256_base64" | "sha256_base64url" | "sha256_hex" | "sha384" | "sha384_base64" | "sha384_base64url" | "sha384_hex" | "sha512" | "sha512_base64" | "sha512_base64url" | "sha512_hex" | "unicodeEmail" | "uppercase" | "uuid4" | "uuid6" | "uuid7", RegExp> & {
910
918
  nanoidOfLength: (length: number) => RegExp;
911
919
  datetime: (options?: stringFormats.ISODateTimeOptions) => RegExp;
912
920
  emoji: () => RegExp;
@@ -1008,6 +1016,12 @@ export declare const z: {
1008
1016
  creditCard: (params?: {
1009
1017
  message?: string;
1010
1018
  }) => stringFormats.VldStringFormat;
1019
+ iban: (params?: {
1020
+ message?: string;
1021
+ }) => stringFormats.VldStringFormat;
1022
+ currencyCode: (params?: {
1023
+ message?: string;
1024
+ }) => stringFormats.VldStringFormat;
1011
1025
  e164: () => stringFormats.VldStringFormat;
1012
1026
  hash: (algorithm: "md5" | "sha1" | "sha256" | "sha384" | "sha512") => stringFormats.VldStringFormat;
1013
1027
  iso: {
@@ -1053,7 +1067,7 @@ export declare const z: {
1053
1067
  guid: () => stringFormats.VldStringFormat;
1054
1068
  httpUrl: () => stringFormats.VldStringFormat;
1055
1069
  ksuid: () => stringFormats.VldStringFormat;
1056
- regexes: Readonly<Record<"number" | "bigint" | "boolean" | "undefined" | "integer" | "date" | "null" | "hex" | "base64" | "email" | "base64url" | "jwt" | "nanoid" | "cuid" | "cuid2" | "ulid" | "cidrv4" | "cidrv6" | "e164" | "xid" | "guid" | "ksuid" | "duration" | "ipv4" | "ipv6" | "browserEmail" | "creditCard" | "domain" | "extendedDuration" | "hostname" | "html5Email" | "httpProtocol" | "httpUrl" | "idnEmail" | "lowercase" | "md5" | "md5_base64" | "md5_base64url" | "md5_hex" | "rfc5322Email" | "sha1" | "sha1_base64" | "sha1_base64url" | "sha1_hex" | "sha256" | "sha256_base64" | "sha256_base64url" | "sha256_hex" | "sha384" | "sha384_base64" | "sha384_base64url" | "sha384_hex" | "sha512" | "sha512_base64" | "sha512_base64url" | "sha512_hex" | "unicodeEmail" | "uppercase" | "uuid4" | "uuid6" | "uuid7", RegExp> & {
1070
+ regexes: Readonly<Record<"number" | "bigint" | "boolean" | "undefined" | "integer" | "date" | "null" | "hex" | "base64" | "email" | "base64url" | "jwt" | "nanoid" | "cuid" | "cuid2" | "ulid" | "cidrv4" | "cidrv6" | "e164" | "xid" | "guid" | "ksuid" | "duration" | "ipv4" | "ipv6" | "anyString" | "browserEmail" | "creditCard" | "currencyCode" | "domain" | "extendedDuration" | "hostname" | "html5Email" | "httpProtocol" | "httpUrl" | "iban" | "idnEmail" | "lowercase" | "md5" | "md5_base64" | "md5_base64url" | "md5_hex" | "rfc5322Email" | "sha1" | "sha1_base64" | "sha1_base64url" | "sha1_hex" | "sha256" | "sha256_base64" | "sha256_base64url" | "sha256_hex" | "sha384" | "sha384_base64" | "sha384_base64url" | "sha384_hex" | "sha512" | "sha512_base64" | "sha512_base64url" | "sha512_hex" | "unicodeEmail" | "uppercase" | "uuid4" | "uuid6" | "uuid7", RegExp> & {
1057
1071
  nanoidOfLength: (length: number) => RegExp;
1058
1072
  datetime: (options?: stringFormats.ISODateTimeOptions) => RegExp;
1059
1073
  emoji: () => RegExp;
@@ -1068,6 +1082,8 @@ export declare const z: {
1068
1082
  compile: <T extends VldBase<any, any>>(schema: T, options?: {
1069
1083
  JITless?: boolean;
1070
1084
  }) => T;
1085
+ withParser: <T extends VldBase<any, any>>(schema: T, parser: (input: unknown) => unknown) => T;
1086
+ INVALID: symbol;
1071
1087
  validate: typeof validateFn;
1072
1088
  validateAsync: typeof validateAsyncFn;
1073
1089
  properties: typeof propertiesFn;
@@ -1231,7 +1247,7 @@ export declare const string: () => VldString, number: () => VldNumber, int: () =
1231
1247
  datetime: (options?: stringFormats.ISODateTimeOptions) => stringFormats.VldStringFormat;
1232
1248
  dateTime: (options?: stringFormats.ISODateTimeOptions) => stringFormats.VldStringFormat;
1233
1249
  duration: () => stringFormats.VldStringFormat;
1234
- }, stringFormat: (name: string, validator: ((val: string) => boolean) | RegExp) => stringFormats.VldStringFormat, normalize: (form?: "NFC" | "NFD" | "NFKC" | "NFKD" | (string & {})) => VldTransform<string, string, string>, slugify: () => VldTransform<string, string, string>, mime: (types: string | string[], message?: string) => VldFile, xid: () => stringFormats.VldStringFormat, guid: () => stringFormats.VldStringFormat, httpUrl: () => stringFormats.VldStringFormat, ksuid: () => stringFormats.VldStringFormat, regexes: Readonly<Record<"number" | "bigint" | "boolean" | "undefined" | "integer" | "date" | "null" | "hex" | "base64" | "email" | "base64url" | "jwt" | "nanoid" | "cuid" | "cuid2" | "ulid" | "cidrv4" | "cidrv6" | "e164" | "xid" | "guid" | "ksuid" | "duration" | "ipv4" | "ipv6" | "browserEmail" | "creditCard" | "domain" | "extendedDuration" | "hostname" | "html5Email" | "httpProtocol" | "httpUrl" | "idnEmail" | "lowercase" | "md5" | "md5_base64" | "md5_base64url" | "md5_hex" | "rfc5322Email" | "sha1" | "sha1_base64" | "sha1_base64url" | "sha1_hex" | "sha256" | "sha256_base64" | "sha256_base64url" | "sha256_hex" | "sha384" | "sha384_base64" | "sha384_base64url" | "sha384_hex" | "sha512" | "sha512_base64" | "sha512_base64url" | "sha512_hex" | "unicodeEmail" | "uppercase" | "uuid4" | "uuid6" | "uuid7", RegExp> & {
1250
+ }, stringFormat: (name: string, validator: ((val: string) => boolean) | RegExp) => stringFormats.VldStringFormat, normalize: (form?: "NFC" | "NFD" | "NFKC" | "NFKD" | (string & {})) => VldTransform<string, string, string>, slugify: () => VldTransform<string, string, string>, mime: (types: string | string[], message?: string) => VldFile, xid: () => stringFormats.VldStringFormat, guid: () => stringFormats.VldStringFormat, httpUrl: () => stringFormats.VldStringFormat, ksuid: () => stringFormats.VldStringFormat, regexes: Readonly<Record<"number" | "bigint" | "boolean" | "undefined" | "integer" | "date" | "null" | "hex" | "base64" | "email" | "base64url" | "jwt" | "nanoid" | "cuid" | "cuid2" | "ulid" | "cidrv4" | "cidrv6" | "e164" | "xid" | "guid" | "ksuid" | "duration" | "ipv4" | "ipv6" | "anyString" | "browserEmail" | "creditCard" | "currencyCode" | "domain" | "extendedDuration" | "hostname" | "html5Email" | "httpProtocol" | "httpUrl" | "iban" | "idnEmail" | "lowercase" | "md5" | "md5_base64" | "md5_base64url" | "md5_hex" | "rfc5322Email" | "sha1" | "sha1_base64" | "sha1_base64url" | "sha1_hex" | "sha256" | "sha256_base64" | "sha256_base64url" | "sha256_hex" | "sha384" | "sha384_base64" | "sha384_base64url" | "sha384_hex" | "sha512" | "sha512_base64" | "sha512_base64url" | "sha512_hex" | "unicodeEmail" | "uppercase" | "uuid4" | "uuid6" | "uuid7", RegExp> & {
1235
1251
  nanoidOfLength: (length: number) => RegExp;
1236
1252
  datetime: (options?: stringFormats.ISODateTimeOptions) => RegExp;
1237
1253
  emoji: () => RegExp;
@@ -1248,10 +1264,19 @@ export declare const string: () => VldString, number: () => VldNumber, int: () =
1248
1264
  }) => VldCodec<TInput, TOutput>, promise: <T>(inner: VldBase<unknown, T>) => VldPromise<T>, prefault: <TInput, TOutput>(validator: VldBase<TInput, TOutput>, defaultValue: TInput | (() => TInput)) => VldPrefault<TInput, TOutput>, parse: <T>(schema: VldBase<unknown, T>, value: unknown) => T, safeParse: <T>(schema: VldBase<unknown, T>, value: unknown) => ParseResult<T>, parseAsync: <T>(schema: VldBase<unknown, T>, value: unknown) => Promise<T>, safeParseAsync: <T>(schema: VldBase<unknown, T>, value: unknown) => Promise<ParseResult<T>>, decode: <T>(schema: VldBase<unknown, T>, value: unknown) => T, safeDecode: <T>(schema: VldBase<unknown, T>, value: unknown) => ParseResult<T>, decodeAsync: <T>(schema: VldBase<unknown, T>, value: unknown) => Promise<T>, safeDecodeAsync: <T>(schema: VldBase<unknown, T>, value: unknown) => Promise<ParseResult<T>>, encode: <TInput, TOutput>(schema: VldBase<TInput, TOutput>, value: TOutput) => TInput, safeEncode: <TInput, TOutput>(schema: VldBase<TInput, TOutput>, value: TOutput) => ParseResult<TInput>, encodeAsync: <TInput, TOutput>(schema: VldBase<TInput, TOutput>, value: TOutput) => Promise<TInput>, safeEncodeAsync: <TInput, TOutput>(schema: VldBase<TInput, TOutput>, value: TOutput) => Promise<ParseResult<TInput>>, formatError: (error: Error) => FormattedError, NEVER: VldNever, compile: <T extends VldBase<any, any>>(schema: T, options?: {
1249
1265
  JITless?: boolean;
1250
1266
  }) => T, validate: typeof validateFn, validateAsync: typeof validateAsyncFn, properties: typeof propertiesFn, getDiscriminatedOption: typeof getDiscriminatedOptionFn, memoizer: <K extends object, V>(compute: (key: K) => V) => ((key: K) => V), toZod: typeof toZodFn;
1267
+ export { withParserFn as withParser };
1268
+ export { COMPILE_INVALID, COMPILE_INVALID as INVALID };
1269
+ export declare const iban: (params?: {
1270
+ message?: string;
1271
+ }) => stringFormats.VldStringFormat;
1272
+ export declare const currencyCode: (params?: {
1273
+ message?: string;
1274
+ }) => stringFormats.VldStringFormat;
1275
+ export { isValidIBAN } from './validators/string-formats.js';
1251
1276
  declare const catchFactory: <T>(validator: VldBase<unknown, T>, fallbackValue: T) => VldCatch<unknown, T>;
1252
1277
  declare const enumFactory: typeof enumFactoryCompat;
1253
1278
  declare const functionFactory: () => VldFunction;
1254
- declare const instanceOfFactory: <T>(constructor: Constructor<T>, message?: RefinementMessage) => VldCustom<T>;
1279
+ declare const instanceOfFactory: <T>(constructor: Constructor<T>, message?: RefinementMessage) => VldInstance<T>;
1255
1280
  declare const mapFactory: <K, V>(key: VldBase<unknown, K>, value: VldBase<unknown, V>) => VldMap<K, V>;
1256
1281
  declare const neverFactory: () => VldNever;
1257
1282
  declare const nullFactory: () => VldNull;
@@ -1368,7 +1393,7 @@ declare const defaultFactory: {
1368
1393
  check: <T = unknown>(schemaOrPredicate: VldBase<unknown, T> | ((value: T) => boolean | Promise<boolean>), predicateOrMessage?: ((value: T) => boolean | Promise<boolean>) | RefinementMessage, message?: RefinementMessage) => VldBase<unknown, T>;
1369
1394
  superRefine: <T = unknown>(schemaOrRefinement: VldBase<unknown, T> | ((value: T, ctx: SuperRefineContext) => void | Promise<void>), refinement?: (value: T, ctx: SuperRefineContext) => void | Promise<void>) => VldBase<unknown, T>;
1370
1395
  property: typeof propertyCheck;
1371
- instanceof: <T>(constructor: Constructor<T>, message?: RefinementMessage) => VldCustom<T>;
1396
+ instanceof: <T>(constructor: Constructor<T>, message?: RefinementMessage) => VldInstance<T>;
1372
1397
  config: typeof configure;
1373
1398
  setErrorMap: typeof setGlobalErrorMap;
1374
1399
  getErrorMap: typeof getGlobalErrorMap;
@@ -1384,7 +1409,7 @@ declare const defaultFactory: {
1384
1409
  readonly nullish: (value: unknown) => value is null | undefined;
1385
1410
  readonly cached: <T>(getter: () => T) => (() => T);
1386
1411
  };
1387
- readonly regexes: Readonly<Record<"number" | "bigint" | "boolean" | "undefined" | "integer" | "date" | "null" | "hex" | "base64" | "email" | "base64url" | "jwt" | "nanoid" | "cuid" | "cuid2" | "ulid" | "cidrv4" | "cidrv6" | "e164" | "xid" | "guid" | "ksuid" | "duration" | "ipv4" | "ipv6" | "browserEmail" | "creditCard" | "domain" | "extendedDuration" | "hostname" | "html5Email" | "httpProtocol" | "httpUrl" | "idnEmail" | "lowercase" | "md5" | "md5_base64" | "md5_base64url" | "md5_hex" | "rfc5322Email" | "sha1" | "sha1_base64" | "sha1_base64url" | "sha1_hex" | "sha256" | "sha256_base64" | "sha256_base64url" | "sha256_hex" | "sha384" | "sha384_base64" | "sha384_base64url" | "sha384_hex" | "sha512" | "sha512_base64" | "sha512_base64url" | "sha512_hex" | "unicodeEmail" | "uppercase" | "uuid4" | "uuid6" | "uuid7", RegExp> & {
1412
+ readonly regexes: Readonly<Record<"number" | "bigint" | "boolean" | "undefined" | "integer" | "date" | "null" | "hex" | "base64" | "email" | "base64url" | "jwt" | "nanoid" | "cuid" | "cuid2" | "ulid" | "cidrv4" | "cidrv6" | "e164" | "xid" | "guid" | "ksuid" | "duration" | "ipv4" | "ipv6" | "anyString" | "browserEmail" | "creditCard" | "currencyCode" | "domain" | "extendedDuration" | "hostname" | "html5Email" | "httpProtocol" | "httpUrl" | "iban" | "idnEmail" | "lowercase" | "md5" | "md5_base64" | "md5_base64url" | "md5_hex" | "rfc5322Email" | "sha1" | "sha1_base64" | "sha1_base64url" | "sha1_hex" | "sha256" | "sha256_base64" | "sha256_base64url" | "sha256_hex" | "sha384" | "sha384_base64" | "sha384_base64url" | "sha384_hex" | "sha512" | "sha512_base64" | "sha512_base64url" | "sha512_hex" | "unicodeEmail" | "uppercase" | "uuid4" | "uuid6" | "uuid7", RegExp> & {
1388
1413
  nanoidOfLength: (length: number) => RegExp;
1389
1414
  datetime: (options?: stringFormats.ISODateTimeOptions) => RegExp;
1390
1415
  emoji: () => RegExp;
@@ -1486,6 +1511,12 @@ declare const defaultFactory: {
1486
1511
  creditCard: (params?: {
1487
1512
  message?: string;
1488
1513
  }) => stringFormats.VldStringFormat;
1514
+ iban: (params?: {
1515
+ message?: string;
1516
+ }) => stringFormats.VldStringFormat;
1517
+ currencyCode: (params?: {
1518
+ message?: string;
1519
+ }) => stringFormats.VldStringFormat;
1489
1520
  e164: () => stringFormats.VldStringFormat;
1490
1521
  hash: (algorithm: "md5" | "sha1" | "sha256" | "sha384" | "sha512") => stringFormats.VldStringFormat;
1491
1522
  iso: {
@@ -1531,7 +1562,7 @@ declare const defaultFactory: {
1531
1562
  guid: () => stringFormats.VldStringFormat;
1532
1563
  httpUrl: () => stringFormats.VldStringFormat;
1533
1564
  ksuid: () => stringFormats.VldStringFormat;
1534
- regexes: Readonly<Record<"number" | "bigint" | "boolean" | "undefined" | "integer" | "date" | "null" | "hex" | "base64" | "email" | "base64url" | "jwt" | "nanoid" | "cuid" | "cuid2" | "ulid" | "cidrv4" | "cidrv6" | "e164" | "xid" | "guid" | "ksuid" | "duration" | "ipv4" | "ipv6" | "browserEmail" | "creditCard" | "domain" | "extendedDuration" | "hostname" | "html5Email" | "httpProtocol" | "httpUrl" | "idnEmail" | "lowercase" | "md5" | "md5_base64" | "md5_base64url" | "md5_hex" | "rfc5322Email" | "sha1" | "sha1_base64" | "sha1_base64url" | "sha1_hex" | "sha256" | "sha256_base64" | "sha256_base64url" | "sha256_hex" | "sha384" | "sha384_base64" | "sha384_base64url" | "sha384_hex" | "sha512" | "sha512_base64" | "sha512_base64url" | "sha512_hex" | "unicodeEmail" | "uppercase" | "uuid4" | "uuid6" | "uuid7", RegExp> & {
1565
+ regexes: Readonly<Record<"number" | "bigint" | "boolean" | "undefined" | "integer" | "date" | "null" | "hex" | "base64" | "email" | "base64url" | "jwt" | "nanoid" | "cuid" | "cuid2" | "ulid" | "cidrv4" | "cidrv6" | "e164" | "xid" | "guid" | "ksuid" | "duration" | "ipv4" | "ipv6" | "anyString" | "browserEmail" | "creditCard" | "currencyCode" | "domain" | "extendedDuration" | "hostname" | "html5Email" | "httpProtocol" | "httpUrl" | "iban" | "idnEmail" | "lowercase" | "md5" | "md5_base64" | "md5_base64url" | "md5_hex" | "rfc5322Email" | "sha1" | "sha1_base64" | "sha1_base64url" | "sha1_hex" | "sha256" | "sha256_base64" | "sha256_base64url" | "sha256_hex" | "sha384" | "sha384_base64" | "sha384_base64url" | "sha384_hex" | "sha512" | "sha512_base64" | "sha512_base64url" | "sha512_hex" | "unicodeEmail" | "uppercase" | "uuid4" | "uuid6" | "uuid7", RegExp> & {
1535
1566
  nanoidOfLength: (length: number) => RegExp;
1536
1567
  datetime: (options?: stringFormats.ISODateTimeOptions) => RegExp;
1537
1568
  emoji: () => RegExp;
@@ -1546,6 +1577,8 @@ declare const defaultFactory: {
1546
1577
  compile: <T extends VldBase<any, any>>(schema: T, options?: {
1547
1578
  JITless?: boolean;
1548
1579
  }) => T;
1580
+ withParser: <T extends VldBase<any, any>>(schema: T, parser: (input: unknown) => unknown) => T;
1581
+ INVALID: symbol;
1549
1582
  validate: typeof validateFn;
1550
1583
  validateAsync: typeof validateAsyncFn;
1551
1584
  properties: typeof propertiesFn;