@regle/rules 0.5.1 → 0.5.2

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/README.md CHANGED
@@ -9,10 +9,6 @@ Regle \ʁɛɡl\ (French word for 'rule' ) is a Typescript-first model-based vali
9
9
  It's heavily inspired by Vuelidate.
10
10
 
11
11
 
12
- # 📚 Documentation
13
-
14
- [![Documentation](https://raw.githubusercontent.com/victorgarciaesgi/regle/refs/heads/main/.github/images/redirectDoc.svg)](https://regle.vercel.app/)
15
-
16
12
  ## 📚 Documentation
17
13
 
18
14
  [![Documentation](https://raw.githubusercontent.com/victorgarciaesgi/regle/refs/heads/main/.github/images/redirectDoc.svg)](https://regle.vercel.app/)
@@ -1 +1 @@
1
- 'use strict';var core=require('@regle/core'),vue=require('vue');function $(e,t){let i,o,u,m;typeof e=="function"&&!("_validator"in e)?(i=core.InternalRuleType.Inline,o=e):{_type:i,validator:o,_active:u,_params:m}=e;let f=core.createRule({type:i,validator:o,active:u,message:t}),r=[...m??[]];if(f._params=r,f._message_patched=!0,typeof f=="function"){let s=f(...r);return s._message_patched=!0,s}else return f}function v(e,t){let i,o,u,m,f;typeof e=="function"&&!("_validator"in e)?(i=core.InternalRuleType.Inline,o=e):{_type:i,validator:o,_active:u,_params:m,_message:f}=e;let r=core.createRule({type:i,validator:o,active:u,message:f,tooltip:t}),s=[...m??[]];if(r._params=s,r._tooltip_patched=!0,typeof r=="function"){let n=r(...s);return r._tooltip_patched=!0,n}else return r}function N(e,t){let i=async(u,...m)=>e(u,...m),o=core.createRule({type:core.InternalRuleType.Async,validator:i,message:""});return o._params=o._params?.concat(t),o(...t??[])}function E(e,t){let i=(u,...m)=>e(u,...m),o=core.createRule({type:core.InternalRuleType.Inline,validator:i,message:""});return o._params=o._params?.concat(t),o(...t)}function C(e,t){let i,o,u=[],m="";typeof t=="function"?(i=core.InternalRuleType.Inline,o=t,u=[e]):({_type:i,validator:o,_message:m}=t,u=t._params?.concat([e]));function f(R,...d){let[y]=core.unwrapRuleParameters([e]);return y?o(R,...d):!0}function r(R){let[d]=core.unwrapRuleParameters([e]);return d}let s=core.createRule({type:i,validator:f,active:r,message:m}),n=[...u??[]];if(s._params=n,typeof s=="function"){let R=s(...n);return R._message_patched=!0,R}else return s}function l(e){return e==null?!0:e instanceof Date?isNaN(e.getTime()):Array.isArray(e)?!1:typeof e=="object"&&e!=null?Object.keys(e).length===0:!String(e).length}function a(e){return !l(typeof e=="string"?e.trim():e)}function g(e){return e==null||typeof e!="number"?!1:!isNaN(e)}function p(e,...t){if(l(e))return !0;let i=typeof e=="number"?e.toString():e;return t.every(o=>(o.lastIndex=0,o.test(i)))}function b(e){let t=vue.unref(e);return Array.isArray(t)?t.length:typeof t=="object"?Object.keys(t).length:typeof t=="number"?isNaN(t)?0:t:String(t).length}function T(e){if(l(e))return !1;try{let t=null;if(e instanceof Date)t=e;else if(typeof e=="number"&&!isNaN(e))t=new Date(e);else if(typeof e=="string"){let i=new Date(e);if(i.toString()==="Invalid Date")return !1;t=i;}return !!t}catch{return !1}}function c(e){let t=Object.prototype.toString.call(e);return e==null?new Date(NaN):e instanceof Date||typeof e=="object"&&t==="[object Date]"?new Date(e.getTime()):typeof e=="number"||t==="[object Number]"?new Date(e):typeof e=="string"||t==="[object String]"?new Date(e):new Date(NaN)}function x(e){return typeof e=="number"?e:e!=null?typeof e=="string"?e.trim()!==e?NaN:+e:NaN:NaN}function U(...e){let t=e.some(r=>typeof r=="function"?r.constructor.name==="AsyncFunction":r._async),i=e.map(r=>{if(typeof r=="function")return null;{let s=r._params;return s?.length?s:[null]}}).flat().filter(r=>!!r);function o(r,s,...n){let R=[],d=0;for(let y of r)if(typeof y=="function")R.push(y(s)),d++;else {let D=y._params?.length??0;R.push(y.validator(s,...n.slice(d,D))),D&&(d+=D);}return R}function u(r){return r?.some(n=>typeof n!="boolean")?{$valid:r.every(n=>typeof n=="boolean"?!!n:n.$valid),...r.reduce((n,R)=>{if(typeof R=="boolean")return n;let{$valid:d,...y}=R;return {...n,...y}},{})}:r.every(n=>!!n)}let m;e.length?m=t?async(r,...s)=>{let n=await Promise.all(o(e,r,...s));return u(n)}:(r,...s)=>{let n=o(e,r,...s);return u(n)}:m=r=>!1;let f=core.createRule({type:"and",validator:m,message:"The value does not match all of the provided validators"});return f._params=i,f}function q(...e){let t=e.some(r=>typeof r=="function"?r.constructor.name==="AsyncFunction":r._async),i=e.map(r=>typeof r=="function"?null:r._params).flat().filter(r=>!!r);function o(r,s,...n){let R=[],d=0;for(let y of r)if(typeof y=="function")R.push(y(s)),d++;else {let D=y._params?.length??0;R.push(y.validator(s,...n.slice(d,D))),D&&(d+=D);}return R}function u(r){return r.some(n=>typeof n!="boolean")?{$valid:r.some(n=>typeof n=="boolean"?!!n:n.$valid),...r.reduce((n,R)=>{if(typeof R=="boolean")return n;let{$valid:d,...y}=R;return {...n,...y}},{})}:r.some(n=>!!n)}let f=core.createRule({type:"or",validator:t?async(r,...s)=>{let n=await Promise.all(o(e,r,...s));return u(n)}:(r,...s)=>{let n=o(e,r,...s);return u(n)},message:"The value does not match any of the provided validators"});return f._params=i,f}function K(e,t){let i,o,u,m,f;typeof e=="function"?(o=e,f=e.constructor.name==="AsyncFunction"):({_type:i,validator:o,_params:m}=e,f=e._async),f?u=async(s,...n)=>a(s)?!await o(s,...n):!0:u=(s,...n)=>a(s)?!o(s,...n):!0;let r=core.createRule({type:"not",validator:u,message:t??"Error"});return r._params=m,r}var _t=core.createRule({type:"required",validator:e=>a(e),message:"This field is required"});var zt=core.createRule({type:"maxLength",validator:(e,t)=>a(e)&&a(t)?g(t)?b(e)<=t:(console.warn(`[maxLength] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!1):!0,message:({$value:e,$params:[t]})=>Array.isArray(e)?`This list should have maximum ${t} items`:`The maximum length allowed is ${t}`});var Ut=core.createRule({type:"required",validator(e,t){return t?a(e):!0},message:"This field is required",active({$params:[e]}){return e}});var J=/^[a-zA-Z]*$/,Kt=core.createRule({type:"alpha",validator(e){return l(e)?!0:p(e,J)},message:"The value is not alphabetical"});var X=/^[a-zA-Z0-9]*$/,Ht=core.createRule({type:"alpha",validator(e){return l(e)?!0:p(e,X)},message:"The value must be alpha-numeric"});var Yt=core.createRule({type:"between",validator:(e,t,i)=>{if(a(e)&&a(t)&&a(i)){let o=x(e),u=x(t),m=x(i);return g(o)&&g(u)&&g(m)?o>=u&&o<=m:(console.warn(`[between] Value or parameters aren't numbers, got value: ${e}, min: ${t}, max: ${i}`),!1)}return !0},message:({$params:[e,t]})=>`The value must be between ${e} and ${t}`});var te=/^[-]?\d*(\.\d+)?$/,ar=core.createRule({type:"decimal",validator(e){return l(e)?!0:p(e,te)},message:"Value must be decimal"});var ae=/^(?:[A-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]{2,}(?:[a-z0-9-]*[a-z0-9])?|\[(?:(?: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]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i,sr=core.createRule({type:"email",validator(e){return l(e)?!0:p(e,ae)},message:"Value must be an valid email address"});var ie=/(^[0-9]*$)|(^-[0-9]+$)/,fr=core.createRule({type:"integer",validator(e){return l(e)?!0:p(e,ie)},message:"Value must be an integer"});var yr=core.createRule({type:"maxValue",validator:(e,t)=>a(e)&&a(t)?g(t)&&!isNaN(x(e))?x(e)<=t:(console.warn(`[maxValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!0):!0,message:({$params:[e]})=>`The maximum value allowed is ${e}`});var xr=core.createRule({type:"minLength",validator:(e,t)=>a(e)&&a(t)?g(t)?b(e)>=t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),!1):!0,message:({$value:e,$params:[t]})=>Array.isArray(e)?`This list should have at least ${t} items`:`This field should be at least ${t} characters long`});var hr=core.createRule({type:"minValue",validator:(e,t)=>a(e)&&a(t)?g(t)&&!isNaN(x(e))?x(e)>=t:(console.warn(`[minValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!0):!0,message:({$params:[e]})=>`The minimum value allowed is ${e}`});var Vr=core.createRule({type:"exactLength",validator:(e,t)=>a(e)&&a(t)?g(t)?b(e)===t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),!1):!0,message:({$params:[e]})=>`This field should be exactly ${e} characters long`});var fe=/^\d*(\.\d+)?$/,Fr=core.createRule({type:"numeric",validator(e){return l(e)?!0:p(e,fe)},message:"This field must be numeric"});var Er=core.createRule({type:"required",validator(e,t){return t?!0:a(e)},message:"This field is required",active({$params:[e]}){return !e}});var Sr=core.createRule({type:"sameAs",validator(e,t,i="other"){return l(e)?!0:e===t},message({$params:[e,t]}){return `Value must be equal to the ${t} value`}});var ye=/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?$/i,qr=core.createRule({type:"url",validator(e){return l(e)?!0:p(e,ye)},message:"The value is not a valid URL address"});function de(){return navigator.languages!=null?navigator.languages[0]:navigator.language}function M(e){return e?new Intl.DateTimeFormat(de(),{dateStyle:"short"}).format(new Date(e)):"?"}var Hr=core.createRule({type:"dateAfter",validator:(e,t)=>a(e)&&a(t)?T(e)&&T(t)?c(e).getTime()>c(t).getTime()?!0:{$valid:!1,error:"date-not-after"}:{$valid:!1,error:"value-or-paramater-not-a-date"}:!0,message:({$params:[e],error:t})=>t==="value-or-paramater-not-a-date"?"The inputs must be Dates":`The date must be after ${M(e)}`});var ea=core.createRule({type:"dateBefore",validator:(e,t)=>a(e)&&a(t)?T(e)&&T(t)?c(e).getTime()<c(t).getTime()?!0:{$valid:!1,error:"date-not-before"}:{$valid:!1,error:"value-or-paramater-not-a-date"}:!0,message:({$params:[e],error:t})=>t==="value-or-paramater-not-a-date"?"The fields must be Dates":`The date must be before ${M(e)}`});var ia=core.createRule({type:"dateBetween",validator:(e,t,i)=>T(e)&&T(t)&&T(i)?c(e).getTime()>c(t).getTime()&&c(e).getTime()<c(i).getTime():!0,message:({$params:[e,t]})=>`The date must be between ${M(e)} and ${M(t)}`});function De(e){if(e.length>3||e.length===0||e[0]==="0"&&e!=="0"||!e.match(/^\d+$/))return !1;let t=+e|0;return t>=0&&t<=255}var ua=core.createRule({type:"ipAddress",validator(e){if(l(e))return !0;if(typeof e!="string")return !1;let t=e.split(".");return t.length===4&&t.every(De)},message:"The value is not a valid IP address"});var pa=core.createRule({type:"macAddress",validator(e,t=":"){if(l(e))return !0;if(typeof e!="string")return !1;let i=typeof t=="string"&&t!==""?e.split(t):e.length===12||e.length===16?e.match(/.{2}/g):null;return i!==null&&(i.length===6||i.length===8)&&i.every(he)},message:"The value is not a valid MAC Address"}),he=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/);var ca=core.createRule({type:"checked",validator:e=>a(e)?e===!0:!0,message:"This field must be checked"});var Da=core.createRule({type:"contains",validator(e,t){return a(e)&&a(t)?e.includes(t):!0},message({$params:[e]}){return `Field must contain ${e}`}});var wa=core.createRule({type:"startsWith",validator(e,t){return a(e)&&a(t)?e.startsWith(t):!0},message({$params:[e]}){return `Field must end with ${e}`}});var va=core.createRule({type:"endsWith",validator(e,t){return a(e)&&a(t)?e.endsWith(t):!0},message({$params:[e]}){return `Field must end with ${e}`}});var _a=core.createRule({type:"regex",validator(e,...t){return a(e)?p(e,...t):!0},message:"This field does not match the required pattern"});exports.alpha=Kt;exports.alphaNum=Ht;exports.and=U;exports.applyIf=C;exports.between=Yt;exports.checked=ca;exports.contains=Da;exports.dateAfter=Hr;exports.dateBefore=ea;exports.dateBetween=ia;exports.decimal=ar;exports.email=sr;exports.endsWith=va;exports.exactLength=Vr;exports.getSize=b;exports.integer=fr;exports.ipAddress=ua;exports.isDate=T;exports.isEmpty=l;exports.isFilled=a;exports.isNumber=g;exports.macAddress=pa;exports.matchRegex=p;exports.maxLength=zt;exports.maxValue=yr;exports.minLength=xr;exports.minValue=hr;exports.not=K;exports.numeric=Fr;exports.or=q;exports.regex=_a;exports.required=_t;exports.requiredIf=Ut;exports.requiredUnless=Er;exports.sameAs=Sr;exports.startsWith=wa;exports.toDate=c;exports.toNumber=x;exports.url=qr;exports.withAsync=N;exports.withMessage=$;exports.withParams=E;exports.withTooltip=v;
1
+ 'use strict';var core=require('@regle/core'),vue=require('vue');function $(e,t){let i,o,u,m;typeof e=="function"&&!("_validator"in e)?(i=core.InternalRuleType.Inline,o=e):{_type:i,validator:o,_active:u,_params:m}=e;let f=core.createRule({type:i,validator:o,active:u,message:t}),r=[...m??[]];if(f._params=r,f._message_patched=!0,typeof f=="function"){let s=f(...r);return s._message_patched=!0,s}else return f}function W(e,t){let i,o,u,m,f;typeof e=="function"&&!("_validator"in e)?(i=core.InternalRuleType.Inline,o=e):{_type:i,validator:o,_active:u,_params:m,_message:f}=e;let r=core.createRule({type:i,validator:o,active:u,message:f,tooltip:t}),s=[...m??[]];if(r._params=s,r._tooltip_patched=!0,typeof r=="function"){let n=r(...s);return r._tooltip_patched=!0,n}else return r}function N(e,t){let i=async(u,...m)=>e(u,...m),o=core.createRule({type:core.InternalRuleType.Async,validator:i,message:""});return o._params=o._params?.concat(t),o(...t??[])}function E(e,t){let i=(u,...m)=>e(u,...m),o=core.createRule({type:core.InternalRuleType.Inline,validator:i,message:""});return o._params=o._params?.concat(t),o(...t)}function S(e,t){let i,o,u=[],m="";typeof t=="function"?(i=core.InternalRuleType.Inline,o=t,u=[e]):({_type:i,validator:o,_message:m}=t,u=t._params?.concat([e]));function f(R,...d){let[g]=core.unwrapRuleParameters([e]);return g?o(R,...d):!0}function r(R){let[d]=core.unwrapRuleParameters([e]);return d}let s=core.createRule({type:i,validator:f,active:r,message:m}),n=[...u??[]];if(s._params=n,typeof s=="function"){let R=s(...n);return R._message_patched=!0,R}else return s}function l(e){return e==null?!0:e instanceof Date?isNaN(e.getTime()):Array.isArray(e)?!1:typeof e=="object"&&e!=null?Object.keys(e).length===0:!String(e).length}function a(e){return !l(typeof e=="string"?e.trim():e)}function y(e){return e==null||typeof e!="number"?!1:!isNaN(e)}function p(e,...t){if(l(e))return !0;let i=typeof e=="number"?e.toString():e;return t.every(o=>(o.lastIndex=0,o.test(i)))}function b(e){let t=vue.unref(e);return Array.isArray(t)?t.length:typeof t=="object"?Object.keys(t).length:typeof t=="number"?isNaN(t)?0:t:String(t).length}function T(e){if(l(e))return !1;try{let t=null;if(e instanceof Date)t=e;else if(typeof e=="number"&&!isNaN(e))t=new Date(e);else if(typeof e=="string"){let i=new Date(e);if(i.toString()==="Invalid Date")return !1;t=i;}return !!t}catch{return !1}}function c(e){let t=Object.prototype.toString.call(e);return e==null?new Date(NaN):e instanceof Date||typeof e=="object"&&t==="[object Date]"?new Date(e.getTime()):typeof e=="number"||t==="[object Number]"?new Date(e):typeof e=="string"||t==="[object String]"?new Date(e):new Date(NaN)}function x(e){return typeof e=="number"?e:e!=null?typeof e=="string"?e.trim()!==e?NaN:+e:NaN:NaN}function U(...e){let t=e.some(r=>typeof r=="function"?r.constructor.name==="AsyncFunction":r._async),i=e.map(r=>{if(typeof r=="function")return null;{let s=r._params;return s?.length?s:[null]}}).flat().filter(r=>!!r);function o(r,s,...n){let R=[],d=0;for(let g of r)if(typeof g=="function")R.push(g(s)),d++;else {let D=g._params?.length??0;R.push(g.validator(s,...n.slice(d,D))),D&&(d+=D);}return R}function u(r){return r?.some(n=>typeof n!="boolean")?{$valid:r.every(n=>typeof n=="boolean"?!!n:n.$valid),...r.reduce((n,R)=>{if(typeof R=="boolean")return n;let{$valid:d,...g}=R;return {...n,...g}},{})}:r.every(n=>!!n)}let m;e.length?m=t?async(r,...s)=>{let n=await Promise.all(o(e,r,...s));return u(n)}:(r,...s)=>{let n=o(e,r,...s);return u(n)}:m=r=>!1;let f=core.createRule({type:"and",validator:m,message:"The value does not match all of the provided validators"});return f._params=i,f}function G(...e){let t=e.some(r=>typeof r=="function"?r.constructor.name==="AsyncFunction":r._async),i=e.map(r=>typeof r=="function"?null:r._params).flat().filter(r=>!!r);function o(r,s,...n){let R=[],d=0;for(let g of r)if(typeof g=="function")R.push(g(s)),d++;else {let D=g._params?.length??0;R.push(g.validator(s,...n.slice(d,D))),D&&(d+=D);}return R}function u(r){return r.some(n=>typeof n!="boolean")?{$valid:r.some(n=>typeof n=="boolean"?!!n:n.$valid),...r.reduce((n,R)=>{if(typeof R=="boolean")return n;let{$valid:d,...g}=R;return {...n,...g}},{})}:r.some(n=>!!n)}let f=core.createRule({type:"or",validator:t?async(r,...s)=>{let n=await Promise.all(o(e,r,...s));return u(n)}:(r,...s)=>{let n=o(e,r,...s);return u(n)},message:"The value does not match any of the provided validators"});return f._params=i,f}function O(e,t){let i,o,u,m,f;typeof e=="function"?(o=e,f=e.constructor.name==="AsyncFunction"):({_type:i,validator:o,_params:m}=e,f=e._async),f?u=async(s,...n)=>a(s)?!await o(s,...n):!0:u=(s,...n)=>a(s)?!o(s,...n):!0;let r=core.createRule({type:"not",validator:u,message:t??"Error"});return r._params=m,r}var Et=core.createRule({type:"required",validator:e=>a(e),message:"This field is required"});var Ct=core.createRule({type:"maxLength",validator:(e,t)=>a(e)&&a(t)?y(t)?b(e)<=t:(console.warn(`[maxLength] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!1):!0,message:({$value:e,$params:[t]})=>Array.isArray(e)?`This list should have maximum ${t} items`:`The maximum length allowed is ${t}`});var Gt=core.createRule({type:"required",validator(e,t){return t?a(e):!0},message:"This field is required",active({$params:[e]}){return e}});var J=/^[a-zA-Z]*$/,Bt=core.createRule({type:"alpha",validator(e){return l(e)?!0:p(e,J)},message:"The value is not alphabetical"});var X=/^[a-zA-Z0-9]*$/,Qt=core.createRule({type:"alpha",validator(e){return l(e)?!0:p(e,X)},message:"The value must be alpha-numeric"});var tr=core.createRule({type:"between",validator:(e,t,i)=>{if(a(e)&&a(t)&&a(i)){let o=x(e),u=x(t),m=x(i);return y(o)&&y(u)&&y(m)?o>=u&&o<=m:(console.warn(`[between] Value or parameters aren't numbers, got value: ${e}, min: ${t}, max: ${i}`),!1)}return !0},message:({$params:[e,t]})=>`The value must be between ${e} and ${t}`});var te=/^[-]?\d*(\.\d+)?$/,ir=core.createRule({type:"decimal",validator(e){return l(e)?!0:p(e,te)},message:"Value must be decimal"});var ae=/^(?:[A-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]{2,}(?:[a-z0-9-]*[a-z0-9])?|\[(?:(?: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]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i,ur=core.createRule({type:"email",validator(e){return l(e)?!0:p(e,ae)},message:"Value must be an valid email address"});var ie=/(^[0-9]*$)|(^-[0-9]+$)/,pr=core.createRule({type:"integer",validator(e){return l(e)?!0:p(e,ie)},message:"Value must be an integer"});var cr=core.createRule({type:"maxValue",validator:(e,t)=>a(e)&&a(t)?y(t)&&!isNaN(x(e))?x(e)<=t:(console.warn(`[maxValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!0):!0,message:({$params:[e]})=>`The maximum value allowed is ${e}`});var Dr=core.createRule({type:"minLength",validator:(e,t)=>a(e)&&a(t)?y(t)?b(e)>=t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),!1):!0,message:({$value:e,$params:[t]})=>Array.isArray(e)?`This list should have at least ${t} items`:`This field should be at least ${t} characters long`});var wr=core.createRule({type:"minValue",validator:(e,t)=>a(e)&&a(t)?y(t)&&!isNaN(x(e))?x(e)>=t:(console.warn(`[minValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!0):!0,message:({$params:[e]})=>`The minimum value allowed is ${e}`});var Wr=core.createRule({type:"exactLength",validator:(e,t)=>a(e)&&a(t)?y(t)?b(e)===t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),!1):!0,message:({$params:[e]})=>`This field should be exactly ${e} characters long`});var fe=/^\d*(\.\d+)?$/,_r=core.createRule({type:"numeric",validator(e){return l(e)?!0:p(e,fe)},message:"This field must be numeric"});var zr=core.createRule({type:"required",validator(e,t){return t?!0:a(e)},message:"This field is required",active({$params:[e]}){return !e}});var Ur=core.createRule({type:"sameAs",validator(e,t,i="other"){return l(e)?!0:e===t},message({$params:[e,t]}){return `Value must be equal to the ${t} value`}});var ge=/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?$/i,Or=core.createRule({type:"url",validator(e){return l(e)?!0:p(e,ge)},message:"The value is not a valid URL address"});function de(){return navigator.languages!=null?navigator.languages[0]:navigator.language}function M(e){return e?new Intl.DateTimeFormat(de(),{dateStyle:"short"}).format(new Date(e)):"?"}var Qr=core.createRule({type:"dateAfter",validator:(e,t)=>a(e)&&a(t)?T(e)&&T(t)?c(e).getTime()>c(t).getTime()?!0:{$valid:!1,error:"date-not-after"}:{$valid:!1,error:"value-or-paramater-not-a-date"}:!0,message:({$params:[e],error:t})=>t==="value-or-paramater-not-a-date"?"The inputs must be Dates":`The date must be after ${M(e)}`});var ra=core.createRule({type:"dateBefore",validator:(e,t)=>a(e)&&a(t)?T(e)&&T(t)?c(e).getTime()<c(t).getTime()?!0:{$valid:!1,error:"date-not-before"}:{$valid:!1,error:"value-or-paramater-not-a-date"}:!0,message:({$params:[e],error:t})=>t==="value-or-paramater-not-a-date"?"The fields must be Dates":`The date must be before ${M(e)}`});var sa=core.createRule({type:"dateBetween",validator:(e,t,i)=>T(e)&&T(t)&&T(i)?c(e).getTime()>c(t).getTime()&&c(e).getTime()<c(i).getTime():!0,message:({$params:[e,t]})=>`The date must be between ${M(e)} and ${M(t)}`});function De(e){if(e.length>3||e.length===0||e[0]==="0"&&e!=="0"||!e.match(/^\d+$/))return !1;let t=+e|0;return t>=0&&t<=255}var fa=core.createRule({type:"ipAddress",validator(e){if(l(e))return !0;if(typeof e!="string")return !1;let t=e.split(".");return t.length===4&&t.every(De)},message:"The value is not a valid IP address"});var ga=core.createRule({type:"macAddress",validator(e,t=":"){if(l(e))return !0;if(typeof e!="string")return !1;let i=typeof t=="string"&&t!==""?e.split(t):e.length===12||e.length===16?e.match(/.{2}/g):null;return i!==null&&(i.length===6||i.length===8)&&i.every(he)},message:"The value is not a valid MAC Address"}),he=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/);var xa=core.createRule({type:"checked",validator:e=>a(e)?e===!0:!0,message:"This field must be checked"});var ha=core.createRule({type:"contains",validator(e,t){return a(e)&&a(t)?e.includes(t):!0},message({$params:[e]}){return `Field must contain ${e}`}});var Va=core.createRule({type:"startsWith",validator(e,t){return a(e)&&a(t)?e.startsWith(t):!0},message({$params:[e]}){return `Field must end with ${e}`}});var Fa=core.createRule({type:"endsWith",validator(e,t){return a(e)&&a(t)?e.endsWith(t):!0},message({$params:[e]}){return `Field must end with ${e}`}});var Ea=core.createRule({type:"regex",validator(e,...t){return a(e)?p(e,...t):!0},message:"This field does not match the required pattern"});exports.alpha=Bt;exports.alphaNum=Qt;exports.and=U;exports.applyIf=S;exports.between=tr;exports.checked=xa;exports.contains=ha;exports.dateAfter=Qr;exports.dateBefore=ra;exports.dateBetween=sa;exports.decimal=ir;exports.email=ur;exports.endsWith=Fa;exports.exactLength=Wr;exports.getSize=b;exports.integer=pr;exports.ipAddress=fa;exports.isDate=T;exports.isEmpty=l;exports.isFilled=a;exports.isNumber=y;exports.macAddress=ga;exports.matchRegex=p;exports.maxLength=Ct;exports.maxValue=cr;exports.minLength=Dr;exports.minValue=wr;exports.not=O;exports.numeric=_r;exports.or=G;exports.regex=Ea;exports.required=Et;exports.requiredIf=Gt;exports.requiredUnless=zr;exports.sameAs=Ur;exports.startsWith=Va;exports.toDate=c;exports.toNumber=x;exports.url=Or;exports.withAsync=N;exports.withMessage=$;exports.withParams=E;exports.withTooltip=W;
@@ -1 +1 @@
1
- import {createRule,InternalRuleType,unwrapRuleParameters}from'@regle/core';import {unref}from'vue';function $(e,t){let i,o,u,m;typeof e=="function"&&!("_validator"in e)?(i=InternalRuleType.Inline,o=e):{_type:i,validator:o,_active:u,_params:m}=e;let f=createRule({type:i,validator:o,active:u,message:t}),r=[...m??[]];if(f._params=r,f._message_patched=!0,typeof f=="function"){let s=f(...r);return s._message_patched=!0,s}else return f}function v(e,t){let i,o,u,m,f;typeof e=="function"&&!("_validator"in e)?(i=InternalRuleType.Inline,o=e):{_type:i,validator:o,_active:u,_params:m,_message:f}=e;let r=createRule({type:i,validator:o,active:u,message:f,tooltip:t}),s=[...m??[]];if(r._params=s,r._tooltip_patched=!0,typeof r=="function"){let n=r(...s);return r._tooltip_patched=!0,n}else return r}function N(e,t){let i=async(u,...m)=>e(u,...m),o=createRule({type:InternalRuleType.Async,validator:i,message:""});return o._params=o._params?.concat(t),o(...t??[])}function E(e,t){let i=(u,...m)=>e(u,...m),o=createRule({type:InternalRuleType.Inline,validator:i,message:""});return o._params=o._params?.concat(t),o(...t)}function C(e,t){let i,o,u=[],m="";typeof t=="function"?(i=InternalRuleType.Inline,o=t,u=[e]):({_type:i,validator:o,_message:m}=t,u=t._params?.concat([e]));function f(R,...d){let[y]=unwrapRuleParameters([e]);return y?o(R,...d):!0}function r(R){let[d]=unwrapRuleParameters([e]);return d}let s=createRule({type:i,validator:f,active:r,message:m}),n=[...u??[]];if(s._params=n,typeof s=="function"){let R=s(...n);return R._message_patched=!0,R}else return s}function l(e){return e==null?!0:e instanceof Date?isNaN(e.getTime()):Array.isArray(e)?!1:typeof e=="object"&&e!=null?Object.keys(e).length===0:!String(e).length}function a(e){return !l(typeof e=="string"?e.trim():e)}function g(e){return e==null||typeof e!="number"?!1:!isNaN(e)}function p(e,...t){if(l(e))return !0;let i=typeof e=="number"?e.toString():e;return t.every(o=>(o.lastIndex=0,o.test(i)))}function b(e){let t=unref(e);return Array.isArray(t)?t.length:typeof t=="object"?Object.keys(t).length:typeof t=="number"?isNaN(t)?0:t:String(t).length}function T(e){if(l(e))return !1;try{let t=null;if(e instanceof Date)t=e;else if(typeof e=="number"&&!isNaN(e))t=new Date(e);else if(typeof e=="string"){let i=new Date(e);if(i.toString()==="Invalid Date")return !1;t=i;}return !!t}catch{return !1}}function c(e){let t=Object.prototype.toString.call(e);return e==null?new Date(NaN):e instanceof Date||typeof e=="object"&&t==="[object Date]"?new Date(e.getTime()):typeof e=="number"||t==="[object Number]"?new Date(e):typeof e=="string"||t==="[object String]"?new Date(e):new Date(NaN)}function x(e){return typeof e=="number"?e:e!=null?typeof e=="string"?e.trim()!==e?NaN:+e:NaN:NaN}function U(...e){let t=e.some(r=>typeof r=="function"?r.constructor.name==="AsyncFunction":r._async),i=e.map(r=>{if(typeof r=="function")return null;{let s=r._params;return s?.length?s:[null]}}).flat().filter(r=>!!r);function o(r,s,...n){let R=[],d=0;for(let y of r)if(typeof y=="function")R.push(y(s)),d++;else {let D=y._params?.length??0;R.push(y.validator(s,...n.slice(d,D))),D&&(d+=D);}return R}function u(r){return r?.some(n=>typeof n!="boolean")?{$valid:r.every(n=>typeof n=="boolean"?!!n:n.$valid),...r.reduce((n,R)=>{if(typeof R=="boolean")return n;let{$valid:d,...y}=R;return {...n,...y}},{})}:r.every(n=>!!n)}let m;e.length?m=t?async(r,...s)=>{let n=await Promise.all(o(e,r,...s));return u(n)}:(r,...s)=>{let n=o(e,r,...s);return u(n)}:m=r=>!1;let f=createRule({type:"and",validator:m,message:"The value does not match all of the provided validators"});return f._params=i,f}function q(...e){let t=e.some(r=>typeof r=="function"?r.constructor.name==="AsyncFunction":r._async),i=e.map(r=>typeof r=="function"?null:r._params).flat().filter(r=>!!r);function o(r,s,...n){let R=[],d=0;for(let y of r)if(typeof y=="function")R.push(y(s)),d++;else {let D=y._params?.length??0;R.push(y.validator(s,...n.slice(d,D))),D&&(d+=D);}return R}function u(r){return r.some(n=>typeof n!="boolean")?{$valid:r.some(n=>typeof n=="boolean"?!!n:n.$valid),...r.reduce((n,R)=>{if(typeof R=="boolean")return n;let{$valid:d,...y}=R;return {...n,...y}},{})}:r.some(n=>!!n)}let f=createRule({type:"or",validator:t?async(r,...s)=>{let n=await Promise.all(o(e,r,...s));return u(n)}:(r,...s)=>{let n=o(e,r,...s);return u(n)},message:"The value does not match any of the provided validators"});return f._params=i,f}function K(e,t){let i,o,u,m,f;typeof e=="function"?(o=e,f=e.constructor.name==="AsyncFunction"):({_type:i,validator:o,_params:m}=e,f=e._async),f?u=async(s,...n)=>a(s)?!await o(s,...n):!0:u=(s,...n)=>a(s)?!o(s,...n):!0;let r=createRule({type:"not",validator:u,message:t??"Error"});return r._params=m,r}var _t=createRule({type:"required",validator:e=>a(e),message:"This field is required"});var zt=createRule({type:"maxLength",validator:(e,t)=>a(e)&&a(t)?g(t)?b(e)<=t:(console.warn(`[maxLength] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!1):!0,message:({$value:e,$params:[t]})=>Array.isArray(e)?`This list should have maximum ${t} items`:`The maximum length allowed is ${t}`});var Ut=createRule({type:"required",validator(e,t){return t?a(e):!0},message:"This field is required",active({$params:[e]}){return e}});var J=/^[a-zA-Z]*$/,Kt=createRule({type:"alpha",validator(e){return l(e)?!0:p(e,J)},message:"The value is not alphabetical"});var X=/^[a-zA-Z0-9]*$/,Ht=createRule({type:"alpha",validator(e){return l(e)?!0:p(e,X)},message:"The value must be alpha-numeric"});var Yt=createRule({type:"between",validator:(e,t,i)=>{if(a(e)&&a(t)&&a(i)){let o=x(e),u=x(t),m=x(i);return g(o)&&g(u)&&g(m)?o>=u&&o<=m:(console.warn(`[between] Value or parameters aren't numbers, got value: ${e}, min: ${t}, max: ${i}`),!1)}return !0},message:({$params:[e,t]})=>`The value must be between ${e} and ${t}`});var te=/^[-]?\d*(\.\d+)?$/,ar=createRule({type:"decimal",validator(e){return l(e)?!0:p(e,te)},message:"Value must be decimal"});var ae=/^(?:[A-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]{2,}(?:[a-z0-9-]*[a-z0-9])?|\[(?:(?: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]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i,sr=createRule({type:"email",validator(e){return l(e)?!0:p(e,ae)},message:"Value must be an valid email address"});var ie=/(^[0-9]*$)|(^-[0-9]+$)/,fr=createRule({type:"integer",validator(e){return l(e)?!0:p(e,ie)},message:"Value must be an integer"});var yr=createRule({type:"maxValue",validator:(e,t)=>a(e)&&a(t)?g(t)&&!isNaN(x(e))?x(e)<=t:(console.warn(`[maxValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!0):!0,message:({$params:[e]})=>`The maximum value allowed is ${e}`});var xr=createRule({type:"minLength",validator:(e,t)=>a(e)&&a(t)?g(t)?b(e)>=t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),!1):!0,message:({$value:e,$params:[t]})=>Array.isArray(e)?`This list should have at least ${t} items`:`This field should be at least ${t} characters long`});var hr=createRule({type:"minValue",validator:(e,t)=>a(e)&&a(t)?g(t)&&!isNaN(x(e))?x(e)>=t:(console.warn(`[minValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!0):!0,message:({$params:[e]})=>`The minimum value allowed is ${e}`});var Vr=createRule({type:"exactLength",validator:(e,t)=>a(e)&&a(t)?g(t)?b(e)===t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),!1):!0,message:({$params:[e]})=>`This field should be exactly ${e} characters long`});var fe=/^\d*(\.\d+)?$/,Fr=createRule({type:"numeric",validator(e){return l(e)?!0:p(e,fe)},message:"This field must be numeric"});var Er=createRule({type:"required",validator(e,t){return t?!0:a(e)},message:"This field is required",active({$params:[e]}){return !e}});var Sr=createRule({type:"sameAs",validator(e,t,i="other"){return l(e)?!0:e===t},message({$params:[e,t]}){return `Value must be equal to the ${t} value`}});var ye=/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?$/i,qr=createRule({type:"url",validator(e){return l(e)?!0:p(e,ye)},message:"The value is not a valid URL address"});function de(){return navigator.languages!=null?navigator.languages[0]:navigator.language}function M(e){return e?new Intl.DateTimeFormat(de(),{dateStyle:"short"}).format(new Date(e)):"?"}var Hr=createRule({type:"dateAfter",validator:(e,t)=>a(e)&&a(t)?T(e)&&T(t)?c(e).getTime()>c(t).getTime()?!0:{$valid:!1,error:"date-not-after"}:{$valid:!1,error:"value-or-paramater-not-a-date"}:!0,message:({$params:[e],error:t})=>t==="value-or-paramater-not-a-date"?"The inputs must be Dates":`The date must be after ${M(e)}`});var ea=createRule({type:"dateBefore",validator:(e,t)=>a(e)&&a(t)?T(e)&&T(t)?c(e).getTime()<c(t).getTime()?!0:{$valid:!1,error:"date-not-before"}:{$valid:!1,error:"value-or-paramater-not-a-date"}:!0,message:({$params:[e],error:t})=>t==="value-or-paramater-not-a-date"?"The fields must be Dates":`The date must be before ${M(e)}`});var ia=createRule({type:"dateBetween",validator:(e,t,i)=>T(e)&&T(t)&&T(i)?c(e).getTime()>c(t).getTime()&&c(e).getTime()<c(i).getTime():!0,message:({$params:[e,t]})=>`The date must be between ${M(e)} and ${M(t)}`});function De(e){if(e.length>3||e.length===0||e[0]==="0"&&e!=="0"||!e.match(/^\d+$/))return !1;let t=+e|0;return t>=0&&t<=255}var ua=createRule({type:"ipAddress",validator(e){if(l(e))return !0;if(typeof e!="string")return !1;let t=e.split(".");return t.length===4&&t.every(De)},message:"The value is not a valid IP address"});var pa=createRule({type:"macAddress",validator(e,t=":"){if(l(e))return !0;if(typeof e!="string")return !1;let i=typeof t=="string"&&t!==""?e.split(t):e.length===12||e.length===16?e.match(/.{2}/g):null;return i!==null&&(i.length===6||i.length===8)&&i.every(he)},message:"The value is not a valid MAC Address"}),he=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/);var ca=createRule({type:"checked",validator:e=>a(e)?e===!0:!0,message:"This field must be checked"});var Da=createRule({type:"contains",validator(e,t){return a(e)&&a(t)?e.includes(t):!0},message({$params:[e]}){return `Field must contain ${e}`}});var wa=createRule({type:"startsWith",validator(e,t){return a(e)&&a(t)?e.startsWith(t):!0},message({$params:[e]}){return `Field must end with ${e}`}});var va=createRule({type:"endsWith",validator(e,t){return a(e)&&a(t)?e.endsWith(t):!0},message({$params:[e]}){return `Field must end with ${e}`}});var _a=createRule({type:"regex",validator(e,...t){return a(e)?p(e,...t):!0},message:"This field does not match the required pattern"});export{Kt as alpha,Ht as alphaNum,U as and,C as applyIf,Yt as between,ca as checked,Da as contains,Hr as dateAfter,ea as dateBefore,ia as dateBetween,ar as decimal,sr as email,va as endsWith,Vr as exactLength,b as getSize,fr as integer,ua as ipAddress,T as isDate,l as isEmpty,a as isFilled,g as isNumber,pa as macAddress,p as matchRegex,zt as maxLength,yr as maxValue,xr as minLength,hr as minValue,K as not,Fr as numeric,q as or,_a as regex,_t as required,Ut as requiredIf,Er as requiredUnless,Sr as sameAs,wa as startsWith,c as toDate,x as toNumber,qr as url,N as withAsync,$ as withMessage,E as withParams,v as withTooltip};
1
+ import {createRule,InternalRuleType,unwrapRuleParameters}from'@regle/core';import {unref}from'vue';function $(e,t){let i,o,u,m;typeof e=="function"&&!("_validator"in e)?(i=InternalRuleType.Inline,o=e):{_type:i,validator:o,_active:u,_params:m}=e;let f=createRule({type:i,validator:o,active:u,message:t}),r=[...m??[]];if(f._params=r,f._message_patched=!0,typeof f=="function"){let s=f(...r);return s._message_patched=!0,s}else return f}function W(e,t){let i,o,u,m,f;typeof e=="function"&&!("_validator"in e)?(i=InternalRuleType.Inline,o=e):{_type:i,validator:o,_active:u,_params:m,_message:f}=e;let r=createRule({type:i,validator:o,active:u,message:f,tooltip:t}),s=[...m??[]];if(r._params=s,r._tooltip_patched=!0,typeof r=="function"){let n=r(...s);return r._tooltip_patched=!0,n}else return r}function N(e,t){let i=async(u,...m)=>e(u,...m),o=createRule({type:InternalRuleType.Async,validator:i,message:""});return o._params=o._params?.concat(t),o(...t??[])}function E(e,t){let i=(u,...m)=>e(u,...m),o=createRule({type:InternalRuleType.Inline,validator:i,message:""});return o._params=o._params?.concat(t),o(...t)}function S(e,t){let i,o,u=[],m="";typeof t=="function"?(i=InternalRuleType.Inline,o=t,u=[e]):({_type:i,validator:o,_message:m}=t,u=t._params?.concat([e]));function f(R,...d){let[g]=unwrapRuleParameters([e]);return g?o(R,...d):!0}function r(R){let[d]=unwrapRuleParameters([e]);return d}let s=createRule({type:i,validator:f,active:r,message:m}),n=[...u??[]];if(s._params=n,typeof s=="function"){let R=s(...n);return R._message_patched=!0,R}else return s}function l(e){return e==null?!0:e instanceof Date?isNaN(e.getTime()):Array.isArray(e)?!1:typeof e=="object"&&e!=null?Object.keys(e).length===0:!String(e).length}function a(e){return !l(typeof e=="string"?e.trim():e)}function y(e){return e==null||typeof e!="number"?!1:!isNaN(e)}function p(e,...t){if(l(e))return !0;let i=typeof e=="number"?e.toString():e;return t.every(o=>(o.lastIndex=0,o.test(i)))}function b(e){let t=unref(e);return Array.isArray(t)?t.length:typeof t=="object"?Object.keys(t).length:typeof t=="number"?isNaN(t)?0:t:String(t).length}function T(e){if(l(e))return !1;try{let t=null;if(e instanceof Date)t=e;else if(typeof e=="number"&&!isNaN(e))t=new Date(e);else if(typeof e=="string"){let i=new Date(e);if(i.toString()==="Invalid Date")return !1;t=i;}return !!t}catch{return !1}}function c(e){let t=Object.prototype.toString.call(e);return e==null?new Date(NaN):e instanceof Date||typeof e=="object"&&t==="[object Date]"?new Date(e.getTime()):typeof e=="number"||t==="[object Number]"?new Date(e):typeof e=="string"||t==="[object String]"?new Date(e):new Date(NaN)}function x(e){return typeof e=="number"?e:e!=null?typeof e=="string"?e.trim()!==e?NaN:+e:NaN:NaN}function U(...e){let t=e.some(r=>typeof r=="function"?r.constructor.name==="AsyncFunction":r._async),i=e.map(r=>{if(typeof r=="function")return null;{let s=r._params;return s?.length?s:[null]}}).flat().filter(r=>!!r);function o(r,s,...n){let R=[],d=0;for(let g of r)if(typeof g=="function")R.push(g(s)),d++;else {let D=g._params?.length??0;R.push(g.validator(s,...n.slice(d,D))),D&&(d+=D);}return R}function u(r){return r?.some(n=>typeof n!="boolean")?{$valid:r.every(n=>typeof n=="boolean"?!!n:n.$valid),...r.reduce((n,R)=>{if(typeof R=="boolean")return n;let{$valid:d,...g}=R;return {...n,...g}},{})}:r.every(n=>!!n)}let m;e.length?m=t?async(r,...s)=>{let n=await Promise.all(o(e,r,...s));return u(n)}:(r,...s)=>{let n=o(e,r,...s);return u(n)}:m=r=>!1;let f=createRule({type:"and",validator:m,message:"The value does not match all of the provided validators"});return f._params=i,f}function G(...e){let t=e.some(r=>typeof r=="function"?r.constructor.name==="AsyncFunction":r._async),i=e.map(r=>typeof r=="function"?null:r._params).flat().filter(r=>!!r);function o(r,s,...n){let R=[],d=0;for(let g of r)if(typeof g=="function")R.push(g(s)),d++;else {let D=g._params?.length??0;R.push(g.validator(s,...n.slice(d,D))),D&&(d+=D);}return R}function u(r){return r.some(n=>typeof n!="boolean")?{$valid:r.some(n=>typeof n=="boolean"?!!n:n.$valid),...r.reduce((n,R)=>{if(typeof R=="boolean")return n;let{$valid:d,...g}=R;return {...n,...g}},{})}:r.some(n=>!!n)}let f=createRule({type:"or",validator:t?async(r,...s)=>{let n=await Promise.all(o(e,r,...s));return u(n)}:(r,...s)=>{let n=o(e,r,...s);return u(n)},message:"The value does not match any of the provided validators"});return f._params=i,f}function O(e,t){let i,o,u,m,f;typeof e=="function"?(o=e,f=e.constructor.name==="AsyncFunction"):({_type:i,validator:o,_params:m}=e,f=e._async),f?u=async(s,...n)=>a(s)?!await o(s,...n):!0:u=(s,...n)=>a(s)?!o(s,...n):!0;let r=createRule({type:"not",validator:u,message:t??"Error"});return r._params=m,r}var Et=createRule({type:"required",validator:e=>a(e),message:"This field is required"});var Ct=createRule({type:"maxLength",validator:(e,t)=>a(e)&&a(t)?y(t)?b(e)<=t:(console.warn(`[maxLength] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!1):!0,message:({$value:e,$params:[t]})=>Array.isArray(e)?`This list should have maximum ${t} items`:`The maximum length allowed is ${t}`});var Gt=createRule({type:"required",validator(e,t){return t?a(e):!0},message:"This field is required",active({$params:[e]}){return e}});var J=/^[a-zA-Z]*$/,Bt=createRule({type:"alpha",validator(e){return l(e)?!0:p(e,J)},message:"The value is not alphabetical"});var X=/^[a-zA-Z0-9]*$/,Qt=createRule({type:"alpha",validator(e){return l(e)?!0:p(e,X)},message:"The value must be alpha-numeric"});var tr=createRule({type:"between",validator:(e,t,i)=>{if(a(e)&&a(t)&&a(i)){let o=x(e),u=x(t),m=x(i);return y(o)&&y(u)&&y(m)?o>=u&&o<=m:(console.warn(`[between] Value or parameters aren't numbers, got value: ${e}, min: ${t}, max: ${i}`),!1)}return !0},message:({$params:[e,t]})=>`The value must be between ${e} and ${t}`});var te=/^[-]?\d*(\.\d+)?$/,ir=createRule({type:"decimal",validator(e){return l(e)?!0:p(e,te)},message:"Value must be decimal"});var ae=/^(?:[A-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]{2,}(?:[a-z0-9-]*[a-z0-9])?|\[(?:(?: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]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i,ur=createRule({type:"email",validator(e){return l(e)?!0:p(e,ae)},message:"Value must be an valid email address"});var ie=/(^[0-9]*$)|(^-[0-9]+$)/,pr=createRule({type:"integer",validator(e){return l(e)?!0:p(e,ie)},message:"Value must be an integer"});var cr=createRule({type:"maxValue",validator:(e,t)=>a(e)&&a(t)?y(t)&&!isNaN(x(e))?x(e)<=t:(console.warn(`[maxValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!0):!0,message:({$params:[e]})=>`The maximum value allowed is ${e}`});var Dr=createRule({type:"minLength",validator:(e,t)=>a(e)&&a(t)?y(t)?b(e)>=t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),!1):!0,message:({$value:e,$params:[t]})=>Array.isArray(e)?`This list should have at least ${t} items`:`This field should be at least ${t} characters long`});var wr=createRule({type:"minValue",validator:(e,t)=>a(e)&&a(t)?y(t)&&!isNaN(x(e))?x(e)>=t:(console.warn(`[minValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!0):!0,message:({$params:[e]})=>`The minimum value allowed is ${e}`});var Wr=createRule({type:"exactLength",validator:(e,t)=>a(e)&&a(t)?y(t)?b(e)===t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),!1):!0,message:({$params:[e]})=>`This field should be exactly ${e} characters long`});var fe=/^\d*(\.\d+)?$/,_r=createRule({type:"numeric",validator(e){return l(e)?!0:p(e,fe)},message:"This field must be numeric"});var zr=createRule({type:"required",validator(e,t){return t?!0:a(e)},message:"This field is required",active({$params:[e]}){return !e}});var Ur=createRule({type:"sameAs",validator(e,t,i="other"){return l(e)?!0:e===t},message({$params:[e,t]}){return `Value must be equal to the ${t} value`}});var ge=/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?$/i,Or=createRule({type:"url",validator(e){return l(e)?!0:p(e,ge)},message:"The value is not a valid URL address"});function de(){return navigator.languages!=null?navigator.languages[0]:navigator.language}function M(e){return e?new Intl.DateTimeFormat(de(),{dateStyle:"short"}).format(new Date(e)):"?"}var Qr=createRule({type:"dateAfter",validator:(e,t)=>a(e)&&a(t)?T(e)&&T(t)?c(e).getTime()>c(t).getTime()?!0:{$valid:!1,error:"date-not-after"}:{$valid:!1,error:"value-or-paramater-not-a-date"}:!0,message:({$params:[e],error:t})=>t==="value-or-paramater-not-a-date"?"The inputs must be Dates":`The date must be after ${M(e)}`});var ra=createRule({type:"dateBefore",validator:(e,t)=>a(e)&&a(t)?T(e)&&T(t)?c(e).getTime()<c(t).getTime()?!0:{$valid:!1,error:"date-not-before"}:{$valid:!1,error:"value-or-paramater-not-a-date"}:!0,message:({$params:[e],error:t})=>t==="value-or-paramater-not-a-date"?"The fields must be Dates":`The date must be before ${M(e)}`});var sa=createRule({type:"dateBetween",validator:(e,t,i)=>T(e)&&T(t)&&T(i)?c(e).getTime()>c(t).getTime()&&c(e).getTime()<c(i).getTime():!0,message:({$params:[e,t]})=>`The date must be between ${M(e)} and ${M(t)}`});function De(e){if(e.length>3||e.length===0||e[0]==="0"&&e!=="0"||!e.match(/^\d+$/))return !1;let t=+e|0;return t>=0&&t<=255}var fa=createRule({type:"ipAddress",validator(e){if(l(e))return !0;if(typeof e!="string")return !1;let t=e.split(".");return t.length===4&&t.every(De)},message:"The value is not a valid IP address"});var ga=createRule({type:"macAddress",validator(e,t=":"){if(l(e))return !0;if(typeof e!="string")return !1;let i=typeof t=="string"&&t!==""?e.split(t):e.length===12||e.length===16?e.match(/.{2}/g):null;return i!==null&&(i.length===6||i.length===8)&&i.every(he)},message:"The value is not a valid MAC Address"}),he=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/);var xa=createRule({type:"checked",validator:e=>a(e)?e===!0:!0,message:"This field must be checked"});var ha=createRule({type:"contains",validator(e,t){return a(e)&&a(t)?e.includes(t):!0},message({$params:[e]}){return `Field must contain ${e}`}});var Va=createRule({type:"startsWith",validator(e,t){return a(e)&&a(t)?e.startsWith(t):!0},message({$params:[e]}){return `Field must end with ${e}`}});var Fa=createRule({type:"endsWith",validator(e,t){return a(e)&&a(t)?e.endsWith(t):!0},message({$params:[e]}){return `Field must end with ${e}`}});var Ea=createRule({type:"regex",validator(e,...t){return a(e)?p(e,...t):!0},message:"This field does not match the required pattern"});export{Bt as alpha,Qt as alphaNum,U as and,S as applyIf,tr as between,xa as checked,ha as contains,Qr as dateAfter,ra as dateBefore,sa as dateBetween,ir as decimal,ur as email,Fa as endsWith,Wr as exactLength,b as getSize,pr as integer,fa as ipAddress,T as isDate,l as isEmpty,a as isFilled,y as isNumber,ga as macAddress,p as matchRegex,Ct as maxLength,cr as maxValue,Dr as minLength,wr as minValue,O as not,_r as numeric,G as or,Ea as regex,Et as required,Gt as requiredIf,zr as requiredUnless,Ur as sameAs,Va as startsWith,c as toDate,x as toNumber,Or as url,N as withAsync,$ as withMessage,E as withParams,W as withTooltip};
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@regle/rules",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Collection of rules and helpers for Regle",
5
5
  "dependencies": {
6
- "@regle/core": "0.5.1"
6
+ "@regle/core": "0.5.2"
7
7
  },
8
8
  "devDependencies": {
9
9
  "@typescript-eslint/eslint-plugin": "8.18.1",