1import{r as f,w as u}from"./vue-81e4d5b9.js";class l{constructor(t={},e={},s={},r={}){this.data=t,this.rules=this.parseRules(e),this.attributes=this.prepareAttributes(r),this.messages=this.prepareMessages(s),this.validators=this.prepareValidators(),this.errors=f({}),this.watchTargets()}countErrors(){return Object.values(this.errors).flat().length}passes(){return this.countErrors()===0}fails(){return!this.passes()}getErrors(t=null){return t?this.errors[t]:this.errors}getMessageBag(){return Object.values(this.errors).flat()}hasError(t){return!!this.errors[t]}firstError(t){return(this.errors[t]||[])[0]||""}watchTargets(){Object.entries(this.rules).forEach(([t,e])=>{u(()=>this.dataGet(this.data,t),s=>{t in this.errors&&delete this.errors[t];const r=this.validate(t,s,e);r.length&&(this.errors[t]=r)})})}execute(){return Object.entries(this.rules).forEach(([t,e])=>{t in this.errors&&delete this.errors[t];const s=this.dataGet(this.data,t),r=this.validate(t,s,e);r.length&&(this.errors[t]=r)}),this}validate(t,e,s){const r=[];for(let n=0;n<s.length;n++){const i=s[n];if(i==="nullable"){if(this.dataGet(this.data,t))continue;break}if(typeof i=="string"){if(!(i in this.validators))return;const a=this.validators[i];if(typeof a!="function")return;const o=a(t,e);r.push(o)}else if(typeof i=="function"){const a=i(e,t);r.push(a)}else if(typeof i=="object"){if(!(i.name in this.validators))return;const a=this.validators[i.name];if(typeof a!="function")return;const o=a(t,e,...i.params);r.push(o)}}return r.filter(Boolean)}parseRules(t){const e={};return Object.entries(t).forEach(([s,r])=>{typeof r=="string"?(e[s]=[],r.split("|").forEach((i,a)=>{if(i.includes(":")){const[o,c]=i.split(":"),g=c.split(",");e[s][a]={name:o,params:g}}else e[s][a]=i})):Array.isArray(r)&&(e[s]=r)}),Object.freeze(e)}dataGet(t,e){return String(e).split(".").reduce((s,r)=>{if(typeof s=="object")return s[r]},t)}prepareAttributes(t){return Object.keys(this.rules).forEach(e=>{e in t||(t[e]=String(e).split(".").at(-1).replace(/([_-])|(?=[A-Z])/g," ").toLowerCase().trim())}),t}prepareMessages(t){const e=this.getDefaultMessages();return Object.entries(this.rules).forEach(([s,r])=>{r.forEach(n=>{const i=typeof n=="object"?n.name:n,a=s+"."+i;if(a in t)t[a]=this.customMessage(t[a]);else{const o=e[i];typeof o=="function"&&(typeof n=="object"?t[a]=o(this.attributes[s],...n.params):t[a]=o(this.attributes[s]))}})}),t}prepareValidators(){return Object.freeze({required:(t,e)=>{if(!e)return this.getMessage(t,"required")},email:(t,e)=>{if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e))return this.getMessage(t,"email")},min:(t,e,s)=>{const r=typeof e=="number"&&e<s,n=typeof e=="string"&&e.length<s,i=Array.isArray(e)&&e.length<s;if(r||n||i)return this.getMessage(t,"min")},max:(t,e,s)=>{const r=typeof e=="number"&&e>s,n=typeof e=="string"&&e.length>s,i=Array.isArray(e)&&e.length>s;if(r||n||i)return this.getMessage(t,"max")},between:(t,e,s,r)=>{const n=typeof e=="number"&&(e<s||e>r),i=typeof e=="string"&&(e.length<s||e.length>r),a=Array.isArray(e)&&(e.length<s||e.length>r);if(n||i||a)return this.getMessage(t,"between")},numeric:(t,e)=>{if(typeof e!="number")return this.getMessage(t,"numeric")},digits:(t,e)=>{if(!String(e).split("").every(r=>!isNaN(r)))return this.getMessage(t,"digits")},bn_mobile:(t,e)=>{const s=["013","014","015","016","017","018","019"],r=e.substring(0,3);if(!s.includes(r))return this.getMessage(t,"bn_mobile")},start_with:(t,e,...s)=>{if(Object.keys(s).length==0)return"";const r=e.substring(0,3);if(!s.includes(r))return this.getMessage(t,"start_with")}})}getMessage(t,e){return this.messages[t+"."+e]||""}getDefaultMessages(){return Object.freeze({required:t=>`The ${t} field is required.`,email:t=>`The ${t} must be a valid email address.`,max:(t,e)=>`The ${t} must not be greater than ${e}.`,min:(t,e)=>`The ${t} must be at least ${e}.`,between:(t,e,s)=>`The ${t} must be between ${e} and ${s}.`,numeric:t=>`The ${t} must be a number.`,digits:t=>`The ${t} must be digits.`,bn_mobile:t=>`The ${t} must be start with 013, 014, 015, 016, 017, 018, 019.`,start_with:(t,...e)=>`The ${t} must start with one of the following: ${e.join(", ")}`})}customMessage(t,e,s={}){let r=String(t).replace(":attr",e);
1return Object.keys(s).forEach(n=>{r=r.replace(":"+n,s[n])}),r}}function b(h={},t={},e={},s={}){return new l(h,t,e,s)}export{b as u};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.