@oxog/vld 3.0.4 → 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.
- package/CHANGELOG.md +985 -878
- package/README.md +28 -11
- package/dist/chunks/index-Bn85LHAC.js +1 -0
- package/dist/cjs/chunks/index-DJwZFerZ.cjs +1 -0
- package/dist/cjs/cli/bin.cjs +1 -1
- package/dist/cjs/compile.cjs +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/locales/index.cjs +1 -1
- package/dist/cjs/locales/tg.cjs +1 -0
- package/dist/cjs/v3/index.cjs +1 -1
- package/dist/cjs/v4/core/index.cjs +1 -1
- package/dist/cjs/v4/index.cjs +1 -1
- package/dist/cjs/v4/locales/index.cjs +1 -1
- package/dist/cjs/v4/mini/index.cjs +1 -1
- package/dist/cjs/v4-mini/index.cjs +1 -1
- package/dist/cjs/validators/base.cjs +1 -1
- package/dist/cjs/validators/custom.cjs +1 -1
- package/dist/cjs/validators/promise.cjs +1 -1
- package/dist/cjs/validators/string-formats.cjs +1 -1
- package/dist/cjs/validators/string.cjs +1 -1
- package/dist/cli/bin.js +1 -1
- package/dist/compile.d.ts +15 -0
- package/dist/compile.js +1 -1
- package/dist/index.d.ts +50 -17
- package/dist/index.js +1 -1
- package/dist/locales/index.js +1 -1
- package/dist/locales/tg.d.ts +2 -0
- package/dist/locales/tg.js +1 -0
- package/dist/utils/json-schema.d.ts +4 -0
- package/dist/v3/index.js +1 -1
- package/dist/v4/core/index.d.ts +12 -2
- package/dist/v4/core/index.js +1 -1
- package/dist/v4/index.js +1 -1
- package/dist/v4/locales/index.d.ts +1 -0
- package/dist/v4/locales/index.js +1 -1
- package/dist/v4/mini/index.js +1 -1
- package/dist/v4-mini/index.d.ts +1 -1
- package/dist/v4-mini/index.js +1 -1
- package/dist/validators/array-v2.d.ts +1 -1
- package/dist/validators/base.d.ts +29 -0
- package/dist/validators/base.js +1 -1
- package/dist/validators/bigint-v2.d.ts +1 -1
- package/dist/validators/custom.d.ts +21 -1
- package/dist/validators/custom.js +1 -1
- package/dist/validators/date-v2.d.ts +1 -1
- package/dist/validators/number-v2.d.ts +1 -1
- package/dist/validators/object-v2.d.ts +5 -5
- package/dist/validators/promise.d.ts +7 -0
- package/dist/validators/promise.js +1 -1
- package/dist/validators/string-formats.d.ts +14 -1
- package/dist/validators/string-formats.js +1 -1
- package/dist/validators/string-v2.d.ts +2 -2
- package/dist/validators/string.d.ts +10 -0
- package/dist/validators/string.js +1 -1
- package/dist/validators/union-v2.d.ts +1 -1
- package/package.json +246 -245
- package/dist/chunks/index-CKPStM3V.js +0 -1
- package/dist/cjs/chunks/index-lejEpLfv.cjs +0 -1
|
@@ -26,7 +26,7 @@ declare function stringRegex(options?: {
|
|
|
26
26
|
maximum?: number;
|
|
27
27
|
}): RegExp;
|
|
28
28
|
declare function macRegex(delimiter?: string): RegExp;
|
|
29
|
-
type StaticRegexName = 'base64' | 'base64url' | 'bigint' | 'boolean' | 'browserEmail' | 'cidrv4' | 'cidrv6' | 'creditCard' | 'cuid' | 'cuid2' | 'date' | 'domain' | 'duration' | 'e164' | 'email' | 'extendedDuration' | 'guid' | 'hex' | 'hostname' | 'html5Email' | 'httpProtocol' | 'httpUrl' | 'idnEmail' | 'integer' | 'ipv4' | 'ipv6' | 'jwt' | 'ksuid' | 'lowercase' | 'md5' | 'md5_base64' | 'md5_base64url' | 'md5_hex' | 'nanoid' | 'null' | 'number' | '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' | 'ulid' | 'undefined' | 'unicodeEmail' | 'uppercase' | 'uuid4' | 'uuid6' | 'uuid7' | 'xid';
|
|
29
|
+
type StaticRegexName = 'anyString' | 'base64' | 'base64url' | 'bigint' | 'boolean' | 'browserEmail' | 'cidrv4' | 'cidrv6' | 'creditCard' | 'currencyCode' | 'cuid' | 'cuid2' | 'date' | 'domain' | 'duration' | 'e164' | 'email' | 'extendedDuration' | 'guid' | 'hex' | 'hostname' | 'html5Email' | 'httpProtocol' | 'httpUrl' | 'iban' | 'idnEmail' | 'integer' | 'ipv4' | 'ipv6' | 'jwt' | 'ksuid' | 'lowercase' | 'md5' | 'md5_base64' | 'md5_base64url' | 'md5_hex' | 'nanoid' | 'null' | 'number' | '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' | 'ulid' | 'undefined' | 'unicodeEmail' | 'uppercase' | 'uuid4' | 'uuid6' | 'uuid7' | 'xid';
|
|
30
30
|
export type RegexNamespace = Readonly<Record<StaticRegexName, RegExp> & {
|
|
31
31
|
nanoidOfLength: (length: number) => RegExp;
|
|
32
32
|
datetime: typeof dateTimeRegex;
|
|
@@ -88,6 +88,19 @@ export declare function isValidCreditCard(input: string): boolean;
|
|
|
88
88
|
export declare const creditCard: (params?: {
|
|
89
89
|
message?: string;
|
|
90
90
|
}) => VldStringFormat;
|
|
91
|
+
export declare function isValidIBAN(input: string): boolean;
|
|
92
|
+
export declare const iban: (params?: {
|
|
93
|
+
message?: string;
|
|
94
|
+
}) => VldStringFormat;
|
|
95
|
+
export declare const currencyCode: (params?: {
|
|
96
|
+
message?: string;
|
|
97
|
+
}) => VldStringFormat;
|
|
98
|
+
/**
|
|
99
|
+
* Zod 4.6 base64 charset regexes: the 4.6 base64 check validates the
|
|
100
|
+
* character set with these patterns and enforces length/padding in code.
|
|
101
|
+
*/
|
|
102
|
+
export declare const base64Charset: RegExp;
|
|
103
|
+
export declare const base64urlCharset: RegExp;
|
|
91
104
|
export declare const iso: {
|
|
92
105
|
readonly ZodISODate: typeof VldStringFormat;
|
|
93
106
|
readonly ZodISODateTime: typeof VldStringFormat;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{VldBase as t,VLD_VALIDATOR_TYPES as a}from"./base.js";import{getMessages as e}from"../locales/runtime.js";import{i as r}from"../chunks/ip-validation-g5LWgy9t.js";import{V as i,c as n,g as d}from"../chunks/errors-core-BU14-Dk8.js";const o="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))";function s(t,a){return t.lastIndex=0,t.test(a)}function c(t,a){return new RegExp(`^[A-Za-z0-9+/]{${t}}${a}$`)}function u(t){return new RegExp(`^[A-Za-z0-9_-]{${t}}$`)}function f(t){const a="(?:[01]\\d|2[0-3]):[0-5]\\d";return"number"!=typeof t.precision?`${a}(?::[0-5]\\d(?:\\.\\d+)?)?`:-1===t.precision?a:0===t.precision?`${a}:[0-5]\\d`:`${a}:[0-5]\\d\\.\\d{${t.precision}}`}function m(t){return void 0===t?/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/:new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${t}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`)}const l={cuid:/^[cC][0-9a-z]{6,}$/,cuid2:/^[0-9a-z]+$/,ulid:/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,xid:/^[0-9a-vA-V]{20}$/,ksuid:/^[A-Za-z0-9]{27}$/,nanoid:/^[a-zA-Z0-9_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/^[^\s@"]{1,64}@[^\s@]{1,255}$/u,browserEmail:/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,emoji:()=>/^(\p{Extended_Pictographic}|\p{Emoji_Component})+$/u,ipv4:/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,ipv6:/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,mac:function(t=":"){const a=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`^(?:[0-9A-F]{2}${a}){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}${a}){5}[0-9a-f]{2}$`)},cidrv4:/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,cidrv6:/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,base64:/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,base64url:/^[A-Za-z0-9_-]*$/,hostname:/^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/,domain:/^([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/,httpProtocol:/^https?$/,e164:/^\+[1-9]\d{6,14}$/,date:new RegExp(`^${o}$`),time:function(t={}){return new RegExp(`^${f(t)}$`)},datetime:function(t={}){const a=["Z"];return t.local&&a.push(""),t.offset&&a.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)"),new RegExp(`^${o}T${f(t)}(?:${a.join("|")})$`)},string:function(t){const a=t?`[\\s\\S]{${t.minimum??0},${t.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${a}$`)},bigint:/^-?\d+n?$/,integer:/^-?\d+$/,number:/^-?\d+(?:\.\d+)?$/,boolean:/^(?:true|false)$/i,null:/^null$/i,undefined:/^undefined$/i,lowercase:/^[^A-Z]*$/,uppercase:/^[^a-z]*$/,hex:/^[0-9a-fA-F]*$/,md5_hex:/^[0-9a-fA-F]{32}$/,md5_base64:c(22,"=="),md5_base64url:u(22),sha1_hex:/^[0-9a-fA-F]{40}$/,sha1_base64:c(27,"="),sha1_base64url:u(27),sha256_hex:/^[0-9a-fA-F]{64}$/,sha256_base64:c(43,"="),sha256_base64url:u(43),sha384_hex:/^[0-9a-fA-F]{96}$/,sha384_base64:c(64,""),sha384_base64url:u(64),sha512_hex:/^[0-9a-fA-F]{128}$/,sha512_base64:c(86,"=="),sha512_base64url:u(86),jwt:/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$/,httpUrl:/^https?:\/\/[^\s/$.?#].[^\s]*$/,md5:/^[a-f0-9]{32}$/i,sha1:/^[a-f0-9]{40}$/i,sha256:/^[a-f0-9]{64}$/i,sha384:/^[a-f0-9]{96}$/i,sha512:/^[a-f0-9]{128}$/i};class VldStringFormat extends t{constructor(t,e,r,i=t=>t,n){super(a.STRING_FORMAT),this._format=t,this._validator=e,this._errorMessage=r,this._normalize=i,this._patternSource=n}static create(t,a,e,r,i){return new VldStringFormat(t,a,e,r,i)}_createFormatIssue(){const t={code:"invalid_format",path:[],origin:"string",format:this._format,message:this._errorMessage||`Invalid ${this._format}`};return this._patternSource&&(t.pattern=this._patternSource),new i([t])}parse(t){if("string"!=typeof t)throw new i([n("string",d(t),e().invalidString)]);if(!this._validator(t))throw this._createFormatIssue();return this._normalize(t)}safeParse(t){return"string"!=typeof t?{success:!1,error:new i([n("string",d(t),e().invalidString)])}:this._validator(t)?{success:!0,data:this._normalize(t)}:{success:!1,error:this._createFormatIssue()}}}const $=t=>{const a=t?.pattern??l.email;return VldStringFormat.create("email",t=>s(a,t),void 0,void 0,a.source)},A=(t={})=>VldStringFormat.create("url",a=>{const e=(t=>{try{return new URL(t)}catch{return}})(a);return void 0!==e&&(!t.hostname||s(t.hostname,e.hostname))&&(!t.protocol||s(t.protocol,e.protocol.slice(0,-1)))},void 0,t.normalize?t=>new URL(t).href:void 0),F=t=>{const a=m(void 0===t?.version?void 0:Number(t.version.slice(1)));return VldStringFormat.create("uuid",t=>s(a,t))},g=()=>VldStringFormat.create("uuid",t=>s(l.uuid4,t)),h=()=>VldStringFormat.create("uuid",t=>s(l.uuid6,t)),p=()=>VldStringFormat.create("uuid",t=>s(l.uuid7,t)),S=()=>VldStringFormat.create("hostname",t=>s(l.hostname,t)),z=()=>VldStringFormat.create("emoji",t=>s(l.emoji(),t)),Z=()=>VldStringFormat.create("base64",t=>s(l.base64,t)),_=()=>VldStringFormat.create("base64url",t=>s(l.base64url,t)),V=()=>VldStringFormat.create("hex",t=>s(l.hex,t)),v=()=>VldStringFormat.create("jwt",t=>s(l.jwt,t)),x=()=>VldStringFormat.create("nanoid",t=>s(l.nanoid,t)),b=()=>VldStringFormat.create("cuid",t=>s(l.cuid,t)),w=()=>VldStringFormat.create("cuid2",t=>s(l.cuid2,t)),E=()=>VldStringFormat.create("ulid",t=>s(l.ulid,t)),R=()=>VldStringFormat.create("ipv4",t=>s(l.ipv4,t)),j=()=>VldStringFormat.create("ipv6",t=>s(l.ipv6,t)),I=t=>{const a=l.mac(t?.delimiter);return VldStringFormat.create("mac",t=>s(a,t))},M=()=>VldStringFormat.create("cidrv4",t=>s(l.cidrv4,t)),T=()=>VldStringFormat.create("cidrv6",t=>{const a=t.lastIndexOf("/");if(a<=0)return!1;const e=Number(t.slice(a+1));return Number.isInteger(e)&&e>=0&&e<=128&&r(t.slice(0,a))}),D=()=>VldStringFormat.create("e164",t=>s(l.e164,t)),O=()=>VldStringFormat.create("xid",t=>s(l.xid,t)),k=()=>VldStringFormat.create("guid",t=>s(l.guid,t)),C=()=>VldStringFormat.create("httpUrl",t=>s(l.httpUrl,t)),P=()=>VldStringFormat.create("ksuid",t=>s(l.ksuid,t)),N=t=>VldStringFormat.create("hash",a=>l[t]?.test(a)??!1,`Invalid ${t} hash`),U=/[ -]/g;function y(t){return!!l.creditCard.test(t)&&function(t){let a=0,e=!1;for(let r=t.length-1;r>=0;r--){let i=t.charCodeAt(r)-48;e&&(i*=2,i>9&&(i-=9)),a+=i,e=!e}return a%10==0}(t.replace(U,""))}const H=t=>VldStringFormat.create("credit_card",y,t?.message,void 0,l.creditCard.source),W={ZodISODate:VldStringFormat,ZodISODateTime:VldStringFormat,ZodISODuration:VldStringFormat,ZodISOTime:VldStringFormat,date:()=>VldStringFormat.create("date",t=>s(l.date,t)),time:(t={})=>{const a=l.time(t);return VldStringFormat.create("time",t=>s(a,t))},datetime:(t={})=>{const a=l.datetime(t);return VldStringFormat.create("datetime",t=>s(a,t))},dateTime:(t={local:!0})=>{const a=l.datetime(t);return VldStringFormat.create("datetime",t=>s(a,t))},duration:()=>VldStringFormat.create("duration",t=>s(l.duration,t))},L=(t,a)=>{const e=a instanceof RegExp?t=>s(a,t):a;return VldStringFormat.create(t,e)};export{VldStringFormat,Z as base64,_ as base64url,M as cidrv4,T as cidrv6,H as creditCard,b as cuid,w as cuid2,D as e164,$ as email,z as emoji,k as guid,N as hash,V as hex,S as hostname,C as httpUrl,R as ipv4,j as ipv6,y as isValidCreditCard,W as iso,v as jwt,P as ksuid,I as mac,x as nanoid,l as regexes,L as stringFormat,E as ulid,A as url,F as uuid,g as uuidv4,h as uuidv6,p as uuidv7,O as xid};
|
|
1
|
+
import{VldBase as t,VLD_VALIDATOR_TYPES as a}from"./base.js";import{getMessages as e}from"../locales/runtime.js";import{i as r}from"../chunks/ip-validation-g5LWgy9t.js";import{V as i,c as n,g as d}from"../chunks/errors-core-BU14-Dk8.js";const o="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))";function s(t,a){return t.lastIndex=0,t.test(a)}function c(t,a){return new RegExp(`^[A-Za-z0-9+/]{${t}}${a}$`)}function u(t){return new RegExp(`^[A-Za-z0-9_-]{${t}}$`)}function A(t){const a="(?:[01]\\d|2[0-3]):[0-5]\\d";return"number"!=typeof t.precision?`${a}(?::[0-5]\\d(?:\\.\\d+)?)?`:-1===t.precision?a:0===t.precision?`${a}:[0-5]\\d`:`${a}:[0-5]\\d\\.\\d{${t.precision}}`}function f(t){return void 0===t?/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-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64}@[^\s@]{1,255}$/u,idnEmail:/^[^\s@"]{1,64}@[^\s@]{1,255}$/u,browserEmail:/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,emoji:()=>/^(?=[\s\S]*[\p{Extended_Pictographic}\p{Regional_Indicator}\u20E3])[\p{Extended_Pictographic}\p{Emoji_Component}]+$/u,ipv4:/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,ipv6:/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,mac:function(t=":"){const a=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`^(?:[0-9A-F]{2}${a}){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}${a}){5}[0-9a-f]{2}$`)},cidrv4:/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,cidrv6:/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,base64:/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,base64url:/^[A-Za-z0-9_-]*$/,hostname:/^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/,domain:/^([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/,httpProtocol:/^https?$/,e164:/^\+[1-9]\d{6,14}$/,date:new RegExp(`^${o}$`),time:function(t={}){return new RegExp(`^${A(t)}$`)},datetime:function(t={}){const a=["Z"];return t.local&&a.push(""),t.offset&&a.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)"),new RegExp(`^${o}T${A(t)}(?:${a.join("|")})$`)},string:function(t){const a=t?`[\\s\\S]{${t.minimum??0},${t.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${a}$`)},bigint:/^-?\d+n?$/,integer:/^-?\d+$/,number:/^-?\d+(?:\.\d+)?$/,boolean:/^(?:true|false)$/i,null:/^null$/i,undefined:/^undefined$/i,lowercase:/^[^A-Z]*$/,uppercase:/^[^a-z]*$/,hex:/^[0-9a-fA-F]*$/,md5_hex:/^[0-9a-fA-F]{32}$/,md5_base64:c(22,"=="),md5_base64url:u(22),sha1_hex:/^[0-9a-fA-F]{40}$/,sha1_base64:c(27,"="),sha1_base64url:u(27),sha256_hex:/^[0-9a-fA-F]{64}$/,sha256_base64:c(43,"="),sha256_base64url:u(43),sha384_hex:/^[0-9a-fA-F]{96}$/,sha384_base64:c(64,""),sha384_base64url:u(64),sha512_hex:/^[0-9a-fA-F]{128}$/,sha512_base64:c(86,"=="),sha512_base64url:u(86),jwt:/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$/,httpUrl:/^https?:\/\/[^\s/$.?#].[^\s]*$/,md5:/^[a-f0-9]{32}$/i,sha1:/^[a-f0-9]{40}$/i,sha256:/^[a-f0-9]{64}$/i,sha384:/^[a-f0-9]{96}$/i,sha512:/^[a-f0-9]{128}$/i};class VldStringFormat extends t{constructor(t,e,r,i=t=>t,n){super(a.STRING_FORMAT),this._format=t,this._validator=e,this._errorMessage=r,this._normalize=i,this._patternSource=n}static create(t,a,e,r,i){return new VldStringFormat(t,a,e,r,i)}_createFormatIssue(){const t={code:"invalid_format",path:[],origin:"string",format:this._format,message:this._errorMessage||`Invalid ${this._format}`};return this._patternSource&&(t.pattern=this._patternSource),new i([t])}parse(t){if("string"!=typeof t)throw new i([n("string",d(t),e().invalidString)]);if(!this._validator(t))throw this._createFormatIssue();return this._normalize(t)}safeParse(t){return"string"!=typeof t?{success:!1,error:new i([n("string",d(t),e().invalidString)])}:this._validator(t)?{success:!0,data:this._normalize(t)}:{success:!1,error:this._createFormatIssue()}}}const l=t=>{const a=t?.pattern??m.email;return VldStringFormat.create("email",t=>s(a,t),void 0,void 0,a.source)},F=(t={})=>VldStringFormat.create("url",a=>{const e=(t=>{try{return new URL(t)}catch{return}})(a);return void 0!==e&&(!t.hostname||s(t.hostname,e.hostname))&&(!t.protocol||s(t.protocol,e.protocol.slice(0,-1)))},void 0,t.normalize?t=>new URL(t).href:void 0),$=t=>{const a=f(void 0===t?.version?void 0:Number(t.version.slice(1)));return VldStringFormat.create("uuid",t=>s(a,t))},S=()=>VldStringFormat.create("uuid",t=>s(m.uuid4,t)),g=()=>VldStringFormat.create("uuid",t=>s(m.uuid6,t)),h=()=>VldStringFormat.create("uuid",t=>s(m.uuid7,t)),Z=()=>VldStringFormat.create("hostname",t=>s(m.hostname,t)),p=()=>VldStringFormat.create("emoji",t=>s(m.emoji(),t)),D=()=>VldStringFormat.create("base64",t=>s(m.base64,t)),V=()=>VldStringFormat.create("base64url",t=>s(m.base64url,t)),z=()=>VldStringFormat.create("hex",t=>s(m.hex,t)),_=()=>VldStringFormat.create("jwt",t=>s(m.jwt,t)),R=()=>VldStringFormat.create("nanoid",t=>s(m.nanoid,t)),P=()=>VldStringFormat.create("cuid",t=>s(m.cuid,t)),v=()=>VldStringFormat.create("cuid2",t=>s(m.cuid2,t)),M=()=>VldStringFormat.create("ulid",t=>s(m.ulid,t)),E=()=>VldStringFormat.create("ipv4",t=>s(m.ipv4,t)),N=()=>VldStringFormat.create("ipv6",t=>s(m.ipv6,t)),T=t=>{const a=m.mac(t?.delimiter);return VldStringFormat.create("mac",t=>s(a,t))},b=()=>VldStringFormat.create("cidrv4",t=>s(m.cidrv4,t)),B=()=>VldStringFormat.create("cidrv6",t=>{const a=t.lastIndexOf("/");if(a<=0)return!1;const e=Number(t.slice(a+1));return Number.isInteger(e)&&e>=0&&e<=128&&r(t.slice(0,a))}),C=()=>VldStringFormat.create("e164",t=>s(m.e164,t)),x=()=>VldStringFormat.create("xid",t=>s(m.xid,t)),U=()=>VldStringFormat.create("guid",t=>s(m.guid,t)),K=()=>VldStringFormat.create("httpUrl",t=>s(m.httpUrl,t)),I=()=>VldStringFormat.create("ksuid",t=>s(m.ksuid,t)),X=t=>VldStringFormat.create("hash",a=>m[t]?.test(a)??!1,`Invalid ${t} hash`),G=/[ -]/g;function w(t){return!!m.creditCard.test(t)&&function(t){let a=0,e=!1;for(let r=t.length-1;r>=0;r--){let i=t.charCodeAt(r)-48;e&&(i*=2,i>9&&(i-=9)),a+=i,e=!e}return a%10==0}(t.replace(G,""))}const L=t=>VldStringFormat.create("credit_card",w,t?.message,void 0,m.creditCard.source);function O(t){return!!m.iban.test(t)&&function(t){let a=0;const e=t.length;for(let r=4;r<e;r++){const e=t.charCodeAt(r);a=(e>=65?100*a+(e-55):10*a+(e-48))%97}for(let e=0;e<4;e++){const r=t.charCodeAt(e);a=(r>=65?100*a+(r-55):10*a+(r-48))%97}return 1===a}(t)}const H=t=>VldStringFormat.create("iban",O,t?.message,void 0,m.iban.source),W=t=>VldStringFormat.create("currency_code",t=>s(m.currencyCode,t),t?.message,void 0,m.currencyCode.source),Y=/^[0-9a-zA-Z+/]*={0,2}$/,j=/^[A-Za-z0-9_-]*$/,y={ZodISODate:VldStringFormat,ZodISODateTime:VldStringFormat,ZodISODuration:VldStringFormat,ZodISOTime:VldStringFormat,date:()=>VldStringFormat.create("date",t=>s(m.date,t)),time:(t={})=>{const a=m.time(t);return VldStringFormat.create("time",t=>s(a,t))},datetime:(t={})=>{const a=m.datetime(t);return VldStringFormat.create("datetime",t=>s(a,t))},dateTime:(t={local:!0})=>{const a=m.datetime(t);return VldStringFormat.create("datetime",t=>s(a,t))},duration:()=>VldStringFormat.create("duration",t=>s(m.duration,t))},J=(t,a)=>{const e=a instanceof RegExp?t=>s(a,t):a;return VldStringFormat.create(t,e)};export{VldStringFormat,D as base64,Y as base64Charset,V as base64url,j as base64urlCharset,b as cidrv4,B as cidrv6,L as creditCard,P as cuid,v as cuid2,W as currencyCode,C as e164,l as email,p as emoji,U as guid,X as hash,z as hex,Z as hostname,K as httpUrl,H as iban,E as ipv4,N as ipv6,w as isValidCreditCard,O as isValidIBAN,y as iso,_ as jwt,I as ksuid,T as mac,R as nanoid,m as regexes,J as stringFormat,M as ulid,F as url,$ as uuid,S as uuidv4,g as uuidv6,h as uuidv7,x as xid};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* VldStringV2
|
|
2
|
+
* VldStringV2 - OPTIMIZED: check classes return Issue | null (no per-call
|
|
3
3
|
* payload allocation), hot path uses early-return, isSimple is precomputed.
|
|
4
4
|
*
|
|
5
5
|
* Same public API as the legacy VldString.
|
|
@@ -217,7 +217,7 @@ export declare class VldStringV2 extends VldBase<string, string> {
|
|
|
217
217
|
get getFormat(): string | null;
|
|
218
218
|
get isCoercion(): boolean;
|
|
219
219
|
parse(value: unknown): string;
|
|
220
|
-
/** Hot path
|
|
220
|
+
/** Hot path - early-return, no payload allocation. */
|
|
221
221
|
parseKnownString(value: string): string;
|
|
222
222
|
safeParse(value: unknown): ParseResult<string>;
|
|
223
223
|
protected withDef(def: Partial<VldStringDef> & {
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import { VldBase, ParseResult, ValidatorType, type ErrorParam } from './base.js';
|
|
2
|
+
/**
|
|
3
|
+
* String formats the AOT compiler (src/compile.ts) can inline as regex
|
|
4
|
+
* checks, with their exact source and flags so compiled validators agree
|
|
5
|
+
* with the runtime parser.
|
|
6
|
+
*/
|
|
7
|
+
export declare const COMPILABLE_FORMATS: Record<'email' | 'url' | 'uuid', {
|
|
8
|
+
source: string;
|
|
9
|
+
flags: string;
|
|
10
|
+
}>;
|
|
2
11
|
/**
|
|
3
12
|
* Type for string validation check functions
|
|
4
13
|
*/
|
|
@@ -22,6 +31,7 @@ interface StringCheckMeta {
|
|
|
22
31
|
readonly value?: number;
|
|
23
32
|
readonly format?: string;
|
|
24
33
|
readonly pattern?: string;
|
|
34
|
+
readonly flags?: string;
|
|
25
35
|
readonly message: string | undefined;
|
|
26
36
|
}
|
|
27
37
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{VldBase as s,VLD_VALIDATOR_TYPES as e,resolveErrorMessage as t}from"./base.js";import{getMessages as r}from"../locales/runtime.js";import{i}from"../chunks/ip-validation-g5LWgy9t.js";import{V as n,c as a,g as c}from"../chunks/errors-core-BU14-Dk8.js";const o={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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}-[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 s{constructor(s){super(s?.validatorType||e.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(s){switch(s.kind){case"min":return{code:"too_small",path:[],origin:"string",minimum:s.value,inclusive:!0,message:s.message||`Too small: expected string to have >=${s.value} characters`};case"max":return{code:"too_big",path:[],origin:"string",maximum:s.value,inclusive:!0,message:s.message||`Too big: expected string to have <=${s.value} characters`};case"length":return{code:"too_big",path:[],origin:"string",exact:s.value,message:s.message||`Too big: expected string to have exactly ${s.value} characters`};case"format":{const e={code:"invalid_format",path:[],origin:"string",format:s.format,message:s.message||`Invalid ${s.format}`};return void 0!==s.pattern&&(e.pattern=s.pattern),e}case"regex":{const e={code:"invalid_format",path:[],origin:"string",format:"regex",message:s.message||"Invalid string: does not match pattern"};return void 0!==s.pattern&&(e.pattern=s.pattern),e}default:return{code:"custom",path:[],message:s.message||"Invalid string"}}}_runChecks(s){const e=this._checks,t=this._checkMetas;for(let r=0;r<e.length;r++)if(!e[r](s))return t?.[r]??this._fallbackMeta();return null}_fallbackMeta(){return{kind:"other",message:this.config.errorMessage}}parse(s){if("string"!=typeof s)throw new n([a("string",c(s),this.config.errorMessage)]);return this._isSimple?s:this.parseKnownString(s)}parseKnownString(s){if(this._isSimple)return s;const e=this._transforms;let t=s;switch(e.length){case 0:break;case 1:t=e[0](t);break;case 2:t=e[1](e[0](t));break;case 3:t=e[2](e[1](e[0](t)));break;default:for(let s=0;s<e.length;s++)t=e[s](t)}const r=this._runChecks(t);if(r)throw new n([this._createCheckIssue(r)]);return t}safeParse(s){if("string"!=typeof s)return{success:!1,error:new n([a("string",c(s),this.config.errorMessage)])};if(this._isSimple)return{success:!0,data:s};try{return{success:!0,data:this.parseKnownString(s)}}catch(s){return s instanceof n?{success:!1,error:s}:{success:!1,error:(e=s.message,new n([{code:"invalid_string",path:[],message:e}]))}}var e}min(s,e){return new VldString({checks:[...this.config.checks,e=>e.length>=s],transforms:this.config.transforms,errorMessage:t(e,r().stringMin(s)),jsonSchema:{...this.config.jsonSchema,minLength:s},checkMetas:[...this.config.checkMetas??[],{kind:"min",value:s,message:t(e,r().stringMin(s))}]})}max(s,e){return new VldString({checks:[...this.config.checks,e=>e.length<=s],transforms:this.config.transforms,errorMessage:t(e,r().stringMax(s)),jsonSchema:{...this.config.jsonSchema,maxLength:s},checkMetas:[...this.config.checkMetas??[],{kind:"max",value:s,message:t(e,r().stringMax(s))}]})}length(s,e){return new VldString({checks:[...this.config.checks,e=>e.length===s],transforms:this.config.transforms,errorMessage:t(e,r().stringLength(s)),jsonSchema:{...this.config.jsonSchema,exactLength:s},checkMetas:[...this.config.checkMetas??[],{kind:"length",value:s,message:t(e,r().stringLength(s))}]})}email(s){return new VldString({checks:[...this.config.checks,s=>o.email.test(s)],transforms:this.config.transforms,errorMessage:t(s,r().stringEmail),jsonSchema:{...this.config.jsonSchema,format:"email"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"email",message:t(s,r().stringEmail)}]})}url(s){return new VldString({checks:[...this.config.checks,s=>o.url.test(s)],transforms:this.config.transforms,errorMessage:t(s,r().stringUrl),jsonSchema:{...this.config.jsonSchema,format:"uri"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"url",message:t(s,r().stringUrl)}]})}uuid(s){return new VldString({checks:[...this.config.checks,s=>o.uuid.test(s)],transforms:this.config.transforms,errorMessage:t(s,r().stringUuid),jsonSchema:{...this.config.jsonSchema,format:"uuid"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"uuid",message:t(s,r().stringUuid)}]})}format(s,e,r){return new VldString({checks:[...this.config.checks,e=>s.test(e)],transforms:this.config.transforms,errorMessage:t(r,`Invalid ${e}`),jsonSchema:{...this.config.jsonSchema,format:e,pattern:s.source},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:e,pattern:s.source,message:t(r,`Invalid ${e}`)}]})}uuidv4(s){return this.format(o.uuidv4,"uuid",s)}uuidv6(s){return this.format(o.uuidv6,"uuid",s)}uuidv7(s){return this.format(o.uuidv7,"uuid",s)}emoji(s){return this.format(o.emoji,"emoji",s)}base64(s){return this.format(o.base64,"base64",s)}base64url(s){return this.format(o.base64url,"base64url",s)}jwt(s){return this.format(o.jwt,"jwt",s)}nanoid(s){return this.format(o.nanoid,"nanoid",s)}cuid(s){return this.format(o.cuid,"cuid",s)}cuid2(s){return this.format(o.cuid2,"cuid2",s)}ulid(s){return this.format(o.ulid,"ulid",s)}cidrv4(s){return this.format(o.cidrv4,"cidrv4",s)}cidrv6(s){return this.format(o.cidrv6,"cidrv6",s)}e164(s){return this.format(o.e164,"e164",s)}xid(s){return this.format(o.xid,"xid",s)}guid(s){return this.format(o.guid,"guid",s)}ksuid(s){return this.format(o.ksuid,"ksuid",s)}date(s){return this.format(o.isoDate,"date",s)}time(s){return this.format(o.isoTime,"time",s)}datetime(s){return this.format(o.isoDateTime,"datetime",s)}duration(s){return this.format(o.isoDuration,"duration",s)}regex(s,e){return new VldString({checks:[...this.config.checks,e=>s.test(e)],transforms:this.config.transforms,errorMessage:t(e,r().stringRegex),jsonSchema:{...this.config.jsonSchema,pattern:s.source},checkMetas:[...this.config.checkMetas??[],{kind:"regex",pattern:s.source,message:t(e,r().stringRegex)}]})}trim(){return new VldString({checks:this.config.checks,transforms:[...this.config.transforms,s=>s.trim()],errorMessage:this.config.errorMessage,jsonSchema:this.config.jsonSchema})}toLowerCase(){return new VldString({checks:this.config.checks,transforms:[...this.config.transforms,s=>s.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,s=>s.toUpperCase()],errorMessage:this.config.errorMessage,jsonSchema:this.config.jsonSchema})}uppercase(){return this.toUpperCase()}normalize(s){return new VldString({checks:this.config.checks,transforms:[...this.config.transforms,e=>e.normalize(s)],errorMessage:this.config.errorMessage,jsonSchema:this.config.jsonSchema})}slugify(){return new VldString({checks:this.config.checks,transforms:[...this.config.transforms,s=>s.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")],errorMessage:this.config.errorMessage,jsonSchema:this.config.jsonSchema})}startsWith(s,e){return new VldString({checks:[...this.config.checks,e=>e.startsWith(s)],transforms:this.config.transforms,errorMessage:t(e,r().stringStartsWith(s)),jsonSchema:this.config.jsonSchema})}endsWith(s,e){return new VldString({checks:[...this.config.checks,e=>e.endsWith(s)],transforms:this.config.transforms,errorMessage:t(e,r().stringEndsWith(s)),jsonSchema:this.config.jsonSchema})}includes(s,e){return new VldString({checks:[...this.config.checks,e=>e.includes(s)],transforms:this.config.transforms,errorMessage:t(e,r().stringIncludes(s)),jsonSchema:this.config.jsonSchema})}ip(s){return new VldString({checks:[...this.config.checks,s=>!(s.length>100)&&(o.ipv4.test(s)||i(s))],transforms:this.config.transforms,errorMessage:t(s,r().stringIp),jsonSchema:{...this.config.jsonSchema,format:"ip"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"ip",message:t(s,r().stringIp)}]})}ipv4(s){return new VldString({checks:[...this.config.checks,s=>o.ipv4.test(s)],transforms:this.config.transforms,errorMessage:t(s,r().stringIpv4),jsonSchema:{...this.config.jsonSchema,format:"ipv4"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"ipv4",message:t(s,r().stringIpv4)}]})}ipv6(s){return new VldString({checks:[...this.config.checks,s=>i(s)],transforms:this.config.transforms,errorMessage:t(s,r().stringIpv6),jsonSchema:{...this.config.jsonSchema,format:"ipv6"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"ipv6",message:t(s,r().stringIpv6)}]})}nonempty(s){return new VldString({checks:[...this.config.checks,s=>s.length>0],transforms:this.config.transforms,errorMessage:t(s,r().stringEmpty),jsonSchema:{...this.config.jsonSchema,minLength:Math.max(this.config.jsonSchema?.minLength||0,1)},checkMetas:[...this.config.checkMetas??[],{kind:"min",value:1,message:t(s,r().stringEmpty)}]})}}export{VldString};
|
|
1
|
+
import{VldBase as s,VLD_VALIDATOR_TYPES as e,resolveErrorMessage as t}from"./base.js";import{getMessages as r}from"../locales/runtime.js";import{i}from"../chunks/ip-validation-g5LWgy9t.js";import{V as n,c as a,g as c}from"../chunks/errors-core-BU14-Dk8.js";const o=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,h={email:o,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)?)?$/},g={email:{source:o.source,flags:o.flags},url:{source:h.url.source,flags:h.url.flags},uuid:{source:h.uuid.source,flags:h.uuid.flags}};class VldString extends s{constructor(s){super(s?.validatorType||e.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(s){switch(s.kind){case"min":return{code:"too_small",path:[],origin:"string",minimum:s.value,inclusive:!0,message:s.message||`Too small: expected string to have >=${s.value} characters`};case"max":return{code:"too_big",path:[],origin:"string",maximum:s.value,inclusive:!0,message:s.message||`Too big: expected string to have <=${s.value} characters`};case"length":return{code:"too_big",path:[],origin:"string",exact:s.value,message:s.message||`Too big: expected string to have exactly ${s.value} characters`};case"format":{const e={code:"invalid_format",path:[],origin:"string",format:s.format,message:s.message||`Invalid ${s.format}`};return void 0!==s.pattern&&(e.pattern=s.pattern),e}case"regex":{const e={code:"invalid_format",path:[],origin:"string",format:"regex",message:s.message||"Invalid string: does not match pattern"};return void 0!==s.pattern&&(e.pattern=s.pattern),e}default:return{code:"custom",path:[],message:s.message||"Invalid string"}}}_runChecks(s){const e=this._checks,t=this._checkMetas;for(let r=0;r<e.length;r++)if(!e[r](s))return t?.[r]??this._fallbackMeta();return null}_fallbackMeta(){return{kind:"other",message:this.config.errorMessage}}parse(s){if("string"!=typeof s)throw new n([a("string",c(s),this.config.errorMessage)]);return this._isSimple?s:this.parseKnownString(s)}parseKnownString(s){if(this._isSimple)return s;const e=this._transforms;let t=s;switch(e.length){case 0:break;case 1:t=e[0](t);break;case 2:t=e[1](e[0](t));break;case 3:t=e[2](e[1](e[0](t)));break;default:for(let s=0;s<e.length;s++)t=e[s](t)}const r=this._runChecks(t);if(r)throw new n([this._createCheckIssue(r)]);return t}safeParse(s){if("string"!=typeof s)return{success:!1,error:new n([a("string",c(s),this.config.errorMessage)])};if(this._isSimple)return{success:!0,data:s};try{return{success:!0,data:this.parseKnownString(s)}}catch(s){return s instanceof n?{success:!1,error:s}:{success:!1,error:(e=s.message,new n([{code:"invalid_string",path:[],message:e}]))}}var e}min(s,e){return new VldString({checks:[...this.config.checks,e=>e.length>=s],transforms:this.config.transforms,errorMessage:t(e,r().stringMin(s)),jsonSchema:{...this.config.jsonSchema,minLength:s},checkMetas:[...this.config.checkMetas??[],{kind:"min",value:s,message:t(e,r().stringMin(s))}]})}max(s,e){return new VldString({checks:[...this.config.checks,e=>e.length<=s],transforms:this.config.transforms,errorMessage:t(e,r().stringMax(s)),jsonSchema:{...this.config.jsonSchema,maxLength:s},checkMetas:[...this.config.checkMetas??[],{kind:"max",value:s,message:t(e,r().stringMax(s))}]})}length(s,e){return new VldString({checks:[...this.config.checks,e=>e.length===s],transforms:this.config.transforms,errorMessage:t(e,r().stringLength(s)),jsonSchema:{...this.config.jsonSchema,exactLength:s},checkMetas:[...this.config.checkMetas??[],{kind:"length",value:s,message:t(e,r().stringLength(s))}]})}email(s){return new VldString({checks:[...this.config.checks,s=>h.email.test(s)],transforms:this.config.transforms,errorMessage:t(s,r().stringEmail),jsonSchema:{...this.config.jsonSchema,format:"email"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"email",message:t(s,r().stringEmail)}]})}url(s){return new VldString({checks:[...this.config.checks,s=>h.url.test(s)],transforms:this.config.transforms,errorMessage:t(s,r().stringUrl),jsonSchema:{...this.config.jsonSchema,format:"uri"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"url",message:t(s,r().stringUrl)}]})}uuid(s){return new VldString({checks:[...this.config.checks,s=>h.uuid.test(s)],transforms:this.config.transforms,errorMessage:t(s,r().stringUuid),jsonSchema:{...this.config.jsonSchema,format:"uuid"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"uuid",message:t(s,r().stringUuid)}]})}format(s,e,r){return new VldString({checks:[...this.config.checks,e=>s.test(e)],transforms:this.config.transforms,errorMessage:t(r,`Invalid ${e}`),jsonSchema:{...this.config.jsonSchema,format:e,pattern:s.source},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:e,pattern:s.source,flags:s.flags,message:t(r,`Invalid ${e}`)}]})}uuidv4(s){return this.format(h.uuidv4,"uuid",s)}uuidv6(s){return this.format(h.uuidv6,"uuid",s)}uuidv7(s){return this.format(h.uuidv7,"uuid",s)}emoji(s){return this.format(h.emoji,"emoji",s)}base64(s){return this.format(h.base64,"base64",s)}base64url(s){return this.format(h.base64url,"base64url",s)}jwt(s){return this.format(h.jwt,"jwt",s)}nanoid(s){return this.format(h.nanoid,"nanoid",s)}cuid(s){return this.format(h.cuid,"cuid",s)}cuid2(s){return this.format(h.cuid2,"cuid2",s)}ulid(s){return this.format(h.ulid,"ulid",s)}cidrv4(s){return this.format(h.cidrv4,"cidrv4",s)}cidrv6(s){return this.format(h.cidrv6,"cidrv6",s)}e164(s){return this.format(h.e164,"e164",s)}xid(s){return this.format(h.xid,"xid",s)}guid(s){return this.format(h.guid,"guid",s)}ksuid(s){return this.format(h.ksuid,"ksuid",s)}date(s){return this.format(h.isoDate,"date",s)}time(s){return this.format(h.isoTime,"time",s)}datetime(s){return this.format(h.isoDateTime,"datetime",s)}duration(s){return this.format(h.isoDuration,"duration",s)}regex(s,e){return new VldString({checks:[...this.config.checks,e=>s.test(e)],transforms:this.config.transforms,errorMessage:t(e,r().stringRegex),jsonSchema:{...this.config.jsonSchema,pattern:s.source},checkMetas:[...this.config.checkMetas??[],{kind:"regex",pattern:s.source,flags:s.flags,message:t(e,r().stringRegex)}]})}trim(){return new VldString({checks:this.config.checks,transforms:[...this.config.transforms,s=>s.trim()],errorMessage:this.config.errorMessage,jsonSchema:this.config.jsonSchema})}toLowerCase(){return new VldString({checks:this.config.checks,transforms:[...this.config.transforms,s=>s.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,s=>s.toUpperCase()],errorMessage:this.config.errorMessage,jsonSchema:this.config.jsonSchema})}uppercase(){return this.toUpperCase()}normalize(s){return new VldString({checks:this.config.checks,transforms:[...this.config.transforms,e=>e.normalize(s)],errorMessage:this.config.errorMessage,jsonSchema:this.config.jsonSchema})}slugify(){return new VldString({checks:this.config.checks,transforms:[...this.config.transforms,s=>s.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")],errorMessage:this.config.errorMessage,jsonSchema:this.config.jsonSchema})}startsWith(s,e){return new VldString({checks:[...this.config.checks,e=>e.startsWith(s)],transforms:this.config.transforms,errorMessage:t(e,r().stringStartsWith(s)),jsonSchema:this.config.jsonSchema})}endsWith(s,e){return new VldString({checks:[...this.config.checks,e=>e.endsWith(s)],transforms:this.config.transforms,errorMessage:t(e,r().stringEndsWith(s)),jsonSchema:this.config.jsonSchema})}includes(s,e){return new VldString({checks:[...this.config.checks,e=>e.includes(s)],transforms:this.config.transforms,errorMessage:t(e,r().stringIncludes(s)),jsonSchema:this.config.jsonSchema})}ip(s){return new VldString({checks:[...this.config.checks,s=>!(s.length>100)&&(h.ipv4.test(s)||i(s))],transforms:this.config.transforms,errorMessage:t(s,r().stringIp),jsonSchema:{...this.config.jsonSchema,format:"ip"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"ip",message:t(s,r().stringIp)}]})}ipv4(s){return new VldString({checks:[...this.config.checks,s=>h.ipv4.test(s)],transforms:this.config.transforms,errorMessage:t(s,r().stringIpv4),jsonSchema:{...this.config.jsonSchema,format:"ipv4"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"ipv4",message:t(s,r().stringIpv4)}]})}ipv6(s){return new VldString({checks:[...this.config.checks,s=>i(s)],transforms:this.config.transforms,errorMessage:t(s,r().stringIpv6),jsonSchema:{...this.config.jsonSchema,format:"ipv6"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"ipv6",message:t(s,r().stringIpv6)}]})}nonempty(s){return new VldString({checks:[...this.config.checks,s=>s.length>0],transforms:this.config.transforms,errorMessage:t(s,r().stringEmpty),jsonSchema:{...this.config.jsonSchema,minLength:Math.max(this.config.jsonSchema?.minLength||0,1)},checkMetas:[...this.config.checkMetas??[],{kind:"min",value:1,message:t(s,r().stringEmpty)}]})}}export{g as COMPILABLE_FORMATS,VldString};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* VldUnionV2
|
|
2
|
+
* VldUnionV2 - single-def union validator.
|
|
3
3
|
* The legacy VldUnion has 5 own properties (validators, errorMessage,
|
|
4
4
|
* typeCheckers, simpleModes, simpleValues). V2 collapses them into a
|
|
5
5
|
* single `__def`, reducing per-instance shape size and letting V8 use
|