"use strict";const b={required:":p is required",required_if:":p is required",string:":p must be of type string",integer:":p must be an integer",float:":p must be a float",boolean:":p must be boolean",array:":p must be an array",file:":p must be a file",number:":p must be of type number",min:":p can not be lower than :p",max:":p can not be bigger than :p",equal:":p must be equal to :p",not_equal:":p must not be equal to :p",regex:":p does not match the pattern",length:":p length must be exactly :p characters",min_length:":p length cannot be less than :p",max_length:":p length cannot be more than :p",in:":p acceptable values are : :p",not_in:":p should not be one of : :p",ends_with:":p must end with :p",starts_with:":p must start with :p"},g={required:":p اجباری است",required_if:":p اجباری است",string:":p باید رشته باشد",integer:":p باید عدد صحیح باشد",float:":p باید عدد اعشاری باشد",boolean:":p باید صحیح/غلط باشد",array:":p باید آرایه باشد",file:":p باید یک فایل باشد",number:":p باید یک عدد باشد",min:":p نباید کمتر از :p باشد",max:":p نباید بیشتر از :p باشد",equal:":p باید برابر :p باشد",not_equal:":p نباید برابر :p باشد",regex:":p از الگوی تعیین شده پیروی نمی کند",length:"طول :p باید :p کاراکتر باشد",min_length:"طول :p نباید کمتر از :p باشد",max_length:"طول :p نباید بیشتر از :p باشد",in:":p باید میان مقادیر : :p باشد",not_in:":p نباید بین مقادیر : :p باشد",ends_with:":p باید با :p پایان یابد",starts_with:":p باید با :p شروع شود"},u=(n,t,o="english")=>{let l;if(o=="english")l=b;else if(o=="persian")l=g;else{console.error("typescript form validator message language undefined");return}const r=l[n];if(!r){console.error("message field not found");return}let i=r;return t.map(a=>{i=i.replace(":p",a)}),i};var s={consider_number_strings:!0,throw_exception:!0,lang:"english"};const y=async(n,t=!0,o=!0,l="english")=>{s.throw_exception=t,s.consider_number_strings=o,s.lang=l;try{n.map(r=>{const i=Object.keys(r)[0];let a=r[i];const h=r.rules,e=r.messages;if(h.indexOf("required")!=-1)_(i,a,e==null?void 0:e.required);else if(h.indexOf(`required_if:${!0}`)!=-1)_(i,a,e==null?void 0:e.required_if);else if(m(a))return;h.map(c=>{c=="string"&&x(i,a,e==null?void 0:e.string),c=="number"&&V(i,a,e==null?void 0:e.number),c=="integer"&&E(i,a,e==null?void 0:e.integer),c=="float"&&q(i,a,e==null?void 0:e.float),c=="boolean"&&I(i,a,e==null?void 0:e.boolean),c=="array"&&W(i,a,e==null?void 0:e.array),c=="file"&&N(i,a,e==null?void 0:e.file),c.startsWith("min:")&&F(i,a,c,e==null?void 0:e.min),c.startsWith("max:")&&A(i,a,c,e==null?void 0:e.max),c.startsWith("length:")&&L(i,a,c,e==null?void 0:e.length),c.startsWith("min_length:")&&R(i,a,c,e==null?void 0:e.min_length),c.startsWith("max_length:")&&B(i,a,c,e==null?void 0:e.max_length),c.startsWith("in:")&&G(i,a,c,e==null?void 0:e.in),c.startsWith("not_in:")&&P(i,a,c,e==null?void 0:e.not_in),c.startsWith("equal:")&&M(i,a,c,e==null?void 0:e.equal),c.startsWith("not_equal:")&&O(i,a,c,e==null?void 0:e.not_equal),c.startsWith("ends_with:")&&j(i,a,c,e==null?void 0:e.ends_with),c.startsWith("starts_with:")&&k(i,a,c,e==null?void 0:e.starts_with),c.startsWith("regex:")&&S(i,a,c,e==null?void 0:e.regex)})})}catch(r){if(s.throw_exception)throw new Error(r.message);return!1}return!0},f=(n,t)=>u(n,t,s.lang),m=n=>{try{n=n.trim()}catch{}return!w(n)&&!n&&n!==0},w=n=>typeof n=="boolean",p=n=>{try{n=n.trim()}catch{}return!w(n)&&!m(n)&&n/Number(n)===1},d=n=>{try{n=n.trim()}catch{}return!w(n)&&!m(n)&&typeof n=="string"},_=(n,t,o)=>{if(m(t))throw new Error(o||f("required",[n]))},x=(n,t,o)=>{if(typeof t!="string")throw new Error(o||f("string",[n]))},E=(n,t,o)=>{if(s.consider_number_strings&&p(t)&&(t=Number(t)),!Number.isInteger(t))throw new Error(o||f("integer",[n]))},q=(n,t,o)=>{if(s.consider_number_strings&&p(t)&&(t=Number(t)),!(Number(t)===t&&t%1!==0)||typeof t!="number")throw new Error(o||f("float",[n]))},I=(n,t,o)=>{if(!w(t))throw new Error(o||f("boolean",[n]))},W=(n,t,o)=>{if(!Array.isArray(t))throw new Error(o||f("array",[n]))},N=(n,t,o)=>{if(!(t instanceof File))throw new Error(o||f("file",[n]))},V=(n,t,o)=>{if(typeof t!="number")throw new Error(o||f("number",[n]))},F=(n,t,o,l)=>{s.consider_number_strings&&p(t)&&(t=Number(t));let r;try{if(r=o.split("min:")[1].trim(),!p(r))throw new Error}catch{console.error('Incorrect format for "min:" ')}if(r&&t{s.consider_number_strings&&p(t)&&(t=Number(t));let r;try{if(r=o.split("max:")[1].trim(),!p(r))throw new Error}catch{console.error('Incorrect format for "max:" ')}if(r&&t>r||!p(t))throw new Error(l||f("max",[n,r]))},M=(n,t,o,l)=>{let r,i;try{const h=o.split("equal:")[1].trim().split(",");h[1]?(i=h[0].trim(),r=h[1].trim()):r=h[0].trim()}catch{console.error('Incorrect format for "equal:" ')}if(r&&t!=r)throw new Error(l||f("equal",[n,i||r]))},O=(n,t,o,l)=>{let r,i;try{const h=o.split("not_equal:")[1].trim().split(",");h[1]?(i=h[0].trim(),r=h[1].trim()):r=h[0].trim()}catch{console.error('Incorrect format for "not_equal:" ')}if(r&&t==r)throw new Error(l||f("not_equal",[n,i||r]))},S=(n,t,o,l)=>{let r;try{r=new RegExp(o.split("regex:")[1].trim())}catch{console.error('Incorrect format for "regex:" ')}if(r&&!r.test(t))throw new Error(l||f("regex",[n]))},L=(n,t,o,l)=>{let r;try{if(r=o.split("length:")[1].trim(),!p(r))throw new Error}catch{console.error('Incorrect format for "length:" ')}if(!d(t)||r&&t.length!=r)throw new Error(l||f("length",[n,r]))},R=(n,t,o,l)=>{let r;try{if(r=o.split("min_length:")[1].trim(),!p(r))throw new Error}catch{console.error('Incorrect format for "min_length:" ')}if(!d(t)||r&&t.length{let r;try{if(r=o.split("max_length:")[1].trim(),!p(r))throw new Error}catch{console.error('Incorrect format for "max_length:" ')}if(!d(t)||r&&t.length>r)throw new Error(l||f("max_length",[n,r]))},G=(n,t,o,l)=>{let r,i;try{if(r=o.split("in:")[1].trim(),i=r.split(","),i=i.map(a=>a.trim()),i.length==0)throw new Error}catch{console.error('Incorrect format for "in:" ')}if(i&&i.indexOf(t)==-1)throw new Error(l||f("in",[n,r]))},P=(n,t,o,l)=>{let r,i;try{if(r=o.split("not_in:")[1].trim(),i=r.split(","),i=i.map(a=>a.trim()),i.length==0)throw new Error}catch{console.error('Incorrect format for "not_in:" ')}if(i&&i.indexOf(t)!=-1)throw new Error(l||f("not_in",[n,r]))},j=(n,t,o,l)=>{let r;try{r=o.split("ends_with:")[1].trim()}catch{console.error('Incorrect format for "ends_with:" ')}if(r&&!t.endsWith(r))throw new Error(l||f("ends_with",[n,r]))},k=(n,t,o,l)=>{let r;try{r=o.split("starts_with:")[1].trim()}catch{console.error('Incorrect format for "starts_with:" ')}if(r&&!t.startsWith(r))throw new Error(l||f("starts_with",[n,r]))};module.exports=y;