@regle/rules 0.5.9 → 0.5.10
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/dist/regle-rules.min.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var core=require('@regle/core'),vue=require('vue');function V(e,t){let i,o,u,f;typeof e=="function"&&!("_validator"in e)?(i=core.InternalRuleType.Inline,o=e):{_type:i,validator:o,_active:u,_params:f}=e;let m=core.createRule({type:i,validator:o,active:u,message:t}),R=[...f??[]];if(m._params=R,m._message_patched=!0,typeof m=="function"){let r=m(...R);return r._message_patched=!0,r}else return m}function v(e,t){let i,o,u,f,m;typeof e=="function"&&!("_validator"in e)?(i=core.InternalRuleType.Inline,o=e):{_type:i,validator:o,_active:u,_params:f,_message:m}=e;let R=core.createRule({type:i,validator:o,active:u,message:m,tooltip:t}),r=[...f??[]];if(R._params=r,R._tooltip_patched=!0,typeof R=="function"){let s=R(...r);return R._tooltip_patched=!0,s}else return R}function N(e,t){let i=async(u,...f)=>e(u,...f),o=core.createRule({type:core.InternalRuleType.Async,validator:i,message:""});return o._params=o._params?.concat(t),o(...t??[])}function k(e,t){let i=(u,...f)=>e(u,...f),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=[],f="";typeof t=="function"?(i=core.InternalRuleType.Inline,o=t,u=[e]):({_type:i,validator:o,_message:f}=t,u=t._params?.concat([e]));function m(n,...p){let[b]=core.unwrapRuleParameters([e]);return b?o(n,...p):!0}function R(n){let[p]=core.unwrapRuleParameters([e]);return p}let r=core.createRule({type:i,validator:m,active:R,message:f}),s=[...u??[]];if(r._params=s,typeof r=="function"){let n=r(...s);return n._message_patched=!0,n}else return r}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 g(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 D(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 x(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 T(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 d(e){return typeof e=="number"?e:e!=null?typeof e=="string"?e.trim()!==e?NaN:+e:NaN:NaN}function q(...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:[]}}).flat().filter(r=>!!r);function o(r,s,...n){let p=[],b=0;for(let c of r)if(typeof c=="function")p.push(c(s)),b++;else {let M=c._params?.length??0;p.push(c.validator(s,...n.slice(b,M))),M&&(b+=M);}return p}function u(r){return r?.some(n=>typeof n!="boolean")?{$valid:r.every(n=>typeof n=="boolean"?!!n:n.$valid),...r.reduce((n,p)=>{if(typeof p=="boolean")return n;let{$valid:b,...c}=p;return {...n,...c}},{})}:r.every(n=>!!n)}let f;e.length?f=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)}:f=r=>!1;let m=core.createRule({type:"and",validator:f,message:"The value does not match all of the provided validators"}),R=[...i??[]];if(m._params=R,typeof m=="function"){let r=m(...R);return r._message_patched=!0,r}else return m}function O(...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 p=[],b=0;for(let c of r)if(typeof c=="function")p.push(c(s)),b++;else {let M=c._params?.length??0;p.push(c.validator(s,...n.slice(b,M))),M&&(b+=M);}return p}function u(r){return r.some(n=>typeof n!="boolean")?{$valid:r.some(n=>typeof n=="boolean"?!!n:n.$valid),...r.reduce((n,p)=>{if(typeof p=="boolean")return n;let{$valid:b,...c}=p;return {...n,...c}},{})}:r.some(n=>!!n)}let m=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"}),R=[...i??[]];if(m._params=R,typeof m=="function"){let r=m(...R);return r._message_patched=!0,r}else return m}function j(e,t){let i,o,u,f,m;typeof e=="function"?(o=e,m=e.constructor.name==="AsyncFunction"):({_type:i,validator:o,_params:f}=e,m=e._async),m?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"}),r=[...f??[]];if(R._params=r,typeof R=="function"){let s=R(...r);return s._message_patched=!0,s}else return R}var zt=core.createRule({type:"required",validator:e=>a(e),message:"This field is required"});var Ut=core.createRule({type:"maxLength",validator:(e,t)=>a(e)&&a(t)?y(t)?D(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 Kt=core.createRule({type:"required",validator(e,t){return t?a(e):!0},message:"This field is required",active({$params:[e]}){return e}});var Q=/^[a-zA-Z]*$/,Ht=core.createRule({type:"alpha",validator(e){return l(e)?!0:g(e,Q)},message:"The value is not alphabetical"});var Y=/^[a-zA-Z0-9]*$/,Yt=core.createRule({type:"alpha",validator(e){return l(e)?!0:g(e,Y)},message:"The value must be alpha-numeric"});var ar=core.createRule({type:"between",validator:(e,t,i)=>{if(a(e)&&a(t)&&a(i)){let o=d(e),u=d(t),f=d(i);return y(o)&&y(u)&&y(f)?o>=u&&o<=f:(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 re=/^[-]?\d*(\.\d+)?$/,sr=core.createRule({type:"decimal",validator(e){return l(e)?!0:g(e,re)},message:"Value must be decimal"});var ne=/^(?:[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,fr=core.createRule({type:"email",validator(e){return l(e)?!0:g(e,ne)},message:"Value must be an valid email address"});var oe=/(^[0-9]*$)|(^-[0-9]+$)/,gr=core.createRule({type:"integer",validator(e){return l(e)?!0:g(e,oe)},message:"Value must be an integer"});var xr=core.createRule({type:"maxValue",validator:(e,t)=>a(e)&&a(t)?y(t)&&!isNaN(d(e))?d(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 hr=core.createRule({type:"minLength",validator:(e,t)=>a(e)&&a(t)?y(t)?D(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 Vr=core.createRule({type:"minValue",validator:(e,t)=>a(e)&&a(t)?y(t)&&!isNaN(d(e))?d(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 _r=core.createRule({type:"exactValue",validator:(e,t)=>a(e)&&a(t)?y(t)&&!isNaN(d(e))?d(e)===t:(console.warn(`[exactValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!0):!0,message:({$params:[e]})=>`The value must be equal to ${e}`});var Er=core.createRule({type:"exactLength",validator:(e,t)=>a(e)&&a(t)?y(t)?D(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 pe=/^\d*(\.\d+)?$/,Cr=core.createRule({type:"numeric",validator(e){return l(e)?!0:g(e,pe)},message:"This field must be numeric"});var Gr=core.createRule({type:"required",validator(e,t){return t?!0:a(e)},message:"This field is required",active({$params:[e]}){return !e}});var Br=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 ce=/^(?:(?:(?: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:g(e,ce)},message:"The value is not a valid URL address"});function Te(){return navigator.languages!=null?navigator.languages[0]:navigator.language}function h(e){return e?new Intl.DateTimeFormat(Te(),{dateStyle:"short"}).format(new Date(e)):"?"}var aa=core.createRule({type:"dateAfter",validator:(e,t)=>a(e)&&a(t)?x(e)&&x(t)?T(e).getTime()>T(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 ${h(e)}`});var la=core.createRule({type:"dateBefore",validator:(e,t)=>a(e)&&a(t)?x(e)&&x(t)?T(e).getTime()<T(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 ${h(e)}`});var pa=core.createRule({type:"dateBetween",validator:(e,t,i)=>x(e)&&x(t)&&x(i)?T(e).getTime()>T(t).getTime()&&T(e).getTime()<T(i).getTime():!0,message:({$params:[e,t]})=>`The date must be between ${h(e)} and ${h(t)}`});function he(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 ca=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(he)},message:"The value is not a valid IP address"});var Da=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(we)},message:"The value is not a valid MAC Address"}),we=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/);var wa=core.createRule({type:"checked",validator:e=>a(e)?e===!0:!0,message:"This field must be checked"});var Wa=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 Na=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 za=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 Ua=core.createRule({type:"regex",validator(e,...t){return a(e)?g(e,...t):!0},message:"This field does not match the required pattern"});exports.alpha=Ht;exports.alphaNum=Yt;exports.and=q;exports.applyIf=C;exports.between=ar;exports.checked=wa;exports.contains=Wa;exports.dateAfter=aa;exports.dateBefore=la;exports.dateBetween=pa;exports.decimal=sr;exports.email=fr;exports.endsWith=za;exports.exactLength=Er;exports.exactValue=_r;exports.getSize=D;exports.integer=gr;exports.ipAddress=ca;exports.isDate=x;exports.isEmpty=l;exports.isFilled=a;exports.isNumber=y;exports.macAddress=Da;exports.matchRegex=g;exports.maxLength=Ut;exports.maxValue=xr;exports.minLength=hr;exports.minValue=Vr;exports.not=j;exports.numeric=Cr;exports.or=O;exports.regex=Ua;exports.required=zt;exports.requiredIf=Kt;exports.requiredUnless=Gr;exports.sameAs=Br;exports.startsWith=Na;exports.toDate=T;exports.toNumber=d;exports.url=Qr;exports.withAsync=N;exports.withMessage=V;exports.withParams=k;exports.withTooltip=v;
|
|
1
|
+
'use strict';var core=require('@regle/core'),vue=require('vue');function V(e,t){let i,o,u,f;typeof e=="function"&&!("_validator"in e)?(i=core.InternalRuleType.Inline,o=e):{_type:i,validator:o,_active:u,_params:f}=e;let m=core.createRule({type:i,validator:o,active:u,message:t}),R=[...f??[]];if(m._params=R,m._message_patched=!0,typeof m=="function"){let r=m(...R);return r._message_patched=!0,r}else return m}function v(e,t){let i,o,u,f,m;typeof e=="function"&&!("_validator"in e)?(i=core.InternalRuleType.Inline,o=e):{_type:i,validator:o,_active:u,_params:f,_message:m}=e;let R=core.createRule({type:i,validator:o,active:u,message:m,tooltip:t}),r=[...f??[]];if(R._params=r,R._tooltip_patched=!0,typeof R=="function"){let s=R(...r);return R._tooltip_patched=!0,s}else return R}function N(e,t){let i=async(u,...f)=>e(u,...f),o=core.createRule({type:core.InternalRuleType.Async,validator:i,message:""});return o._params=o._params?.concat(t),o(...t??[])}function k(e,t){let i=(u,...f)=>e(u,...f),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=[],f="";typeof t=="function"?(i=core.InternalRuleType.Inline,o=t,u=[e]):({_type:i,validator:o,_message:f}=t,u=t._params?.concat([e]));function m(n,...p){let[b]=core.unwrapRuleParameters([e]);return b?o(n,...p):!0}function R(n){let[p]=core.unwrapRuleParameters([e]);return p}let r=core.createRule({type:i,validator:m,active:R,message:f}),s=[...u??[]];if(r._params=s,typeof r=="function"){let n=r(...s);return n._message_patched=!0,n}else return r}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 g(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 D(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 x(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 T(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 d(e){return typeof e=="number"?e:e!=null?typeof e=="string"?e.trim()!==e?NaN:+e:NaN:NaN}function q(...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:[]}}).flat().filter(r=>!!r);function o(r,s,...n){let p=[],b=0;for(let c of r)if(typeof c=="function")p.push(c(s)),b++;else {let M=c._params?.length??0;p.push(c.validator(s,...n.slice(b,M))),M&&(b+=M);}return p}function u(r){return r?.some(n=>typeof n!="boolean")?{$valid:r.every(n=>typeof n=="boolean"?!!n:n.$valid),...r.reduce((n,p)=>{if(typeof p=="boolean")return n;let{$valid:b,...c}=p;return {...n,...c}},{})}:r.every(n=>!!n)}let f;e.length?f=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)}:f=r=>!1;let m=core.createRule({type:"and",validator:f,message:"The value does not match all of the provided validators"}),R=[...i??[]];if(m._params=R,typeof m=="function"){let r=m(...R);return r._message_patched=!0,r}else return m}function O(...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 p=[],b=0;for(let c of r)if(typeof c=="function")p.push(c(s)),b++;else {let M=c._params?.length??0;p.push(c.validator(s,...n.slice(b,M))),M&&(b+=M);}return p}function u(r){return r.some(n=>typeof n!="boolean")?{$valid:r.some(n=>typeof n=="boolean"?!!n:n.$valid),...r.reduce((n,p)=>{if(typeof p=="boolean")return n;let{$valid:b,...c}=p;return {...n,...c}},{})}:r.some(n=>!!n)}let m=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"}),R=[...i??[]];if(m._params=R,typeof m=="function"){let r=m(...R);return r._message_patched=!0,r}else return m}function B(e,t){let i,o,u,f,m;typeof e=="function"?(o=e,m=e.constructor.name==="AsyncFunction"):({_type:i,validator:o,_params:f}=e,m=e._async),m?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"}),r=[...f??[]];if(R._params=r,typeof R=="function"){let s=R(...r);return s._message_patched=!0,s}else return R}var Ct=core.createRule({type:"required",validator:e=>a(e),message:"This field is required"});var Gt=core.createRule({type:"maxLength",validator:(e,t)=>a(e)&&a(t)?y(t)?D(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 jt=core.createRule({type:"required",validator(e,t){return t?a(e):!0},message:"This field is required",active({$params:[e]}){return e}});var Q=/^[a-zA-Z]*$/,Qt=core.createRule({type:"alpha",validator(e){return l(e)?!0:g(e,Q)},message:"The value is not alphabetical"});var Y=/^[a-zA-Z0-9]*$/,tr=core.createRule({type:"alpha",validator(e){return l(e)?!0:g(e,Y)},message:"The value must be alpha-numeric"});var ir=core.createRule({type:"between",validator:(e,t,i)=>{if(a(e)&&a(t)&&a(i)){let o=d(e),u=d(t),f=d(i);return y(o)&&y(u)&&y(f)?o>=u&&o<=f:(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 re=/^[-]?\d*(\.\d+)?$/,ur=core.createRule({type:"decimal",validator(e){return l(e)?!0:g(e,re)},message:"Value must be decimal"});var ne=/^(?:[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,pr=core.createRule({type:"email",validator(e){return l(e)?!0:g(e,ne)},message:"Value must be an valid email address"});var oe=/(^[0-9]*$)|(^-[0-9]+$)/,cr=core.createRule({type:"integer",validator(e){return l(e)?!0:g(e,oe)},message:"Value must be an integer"});var Dr=core.createRule({type:"maxValue",validator:(e,t)=>a(e)&&a(t)?y(t)&&!isNaN(d(e))?d(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 wr=core.createRule({type:"minLength",validator:(e,t)=>a(e)&&a(t)?y(t)?D(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(d(e))?d(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 Nr=core.createRule({type:"exactValue",validator:(e,t)=>a(e)&&a(t)?y(t)&&!isNaN(d(e))?d(e)===t:(console.warn(`[exactValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!0):!0,message:({$params:[e]})=>`The value must be equal to ${e}`});var zr=core.createRule({type:"exactLength",validator:(e,t)=>a(e)&&a(t)?y(t)?D(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 pe=/^\d*(\.\d+)?$/,Ur=core.createRule({type:"numeric",validator(e){return l(e)?!0:g(e,pe)},message:"This field must be numeric"});var Kr=core.createRule({type:"required",validator(e,t){return t?!0:a(e)},message:"This field is required",active({$params:[e]}){return !e}});var Hr=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 ce=/^(?:(?:(?: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,Yr=core.createRule({type:"url",validator(e){return l(e)?!0:g(e,ce)},message:"The value is not a valid URL address"});function Te(){return navigator.languages!=null?navigator.languages[0]:navigator.language}function h(e){return e?new Intl.DateTimeFormat(Te(),{dateStyle:"short"}).format(new Date(e)):"?"}var ia=core.createRule({type:"dateAfter",validator:(e,t)=>a(e)&&a(t)?x(e)&&x(t)?T(e).getTime()>T(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 ${h(e)}`});var ma=core.createRule({type:"dateBefore",validator:(e,t)=>a(e)&&a(t)?x(e)&&x(t)?T(e).getTime()<T(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 ${h(e)}`});var ga=core.createRule({type:"dateBetween",validator:(e,t,i)=>x(e)&&x(t)&&x(i)?T(e).getTime()>T(t).getTime()&&T(e).getTime()<T(i).getTime():!0,message:({$params:[e,t]})=>`The date must be between ${h(e)} and ${h(t)}`});function he(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 xa=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(he)},message:"The value is not a valid IP address"});var ha=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(we)},message:"The value is not a valid MAC Address"}),we=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/);var Va=core.createRule({type:"checked",validator:e=>a(e)?e===!0:!0,message:"This field must be checked"});var Fa=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 Ea=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 Ca=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 Ga=core.createRule({type:"regex",validator(e,...t){return a(e)?g(e,...t):!0},message:"This field does not match the required pattern"});exports.alpha=Qt;exports.alphaNum=tr;exports.and=q;exports.applyIf=C;exports.between=ir;exports.checked=Va;exports.contains=Fa;exports.dateAfter=ia;exports.dateBefore=ma;exports.dateBetween=ga;exports.decimal=ur;exports.email=pr;exports.endsWith=Ca;exports.exactLength=zr;exports.exactValue=Nr;exports.getSize=D;exports.integer=cr;exports.ipAddress=xa;exports.isDate=x;exports.isEmpty=l;exports.isFilled=a;exports.isNumber=y;exports.macAddress=ha;exports.matchRegex=g;exports.maxLength=Gt;exports.maxValue=Dr;exports.minLength=wr;exports.minValue=Wr;exports.not=B;exports.numeric=Ur;exports.or=O;exports.regex=Ga;exports.required=Ct;exports.requiredIf=jt;exports.requiredUnless=Kr;exports.sameAs=Hr;exports.startsWith=Ea;exports.toDate=T;exports.toNumber=d;exports.url=Yr;exports.withAsync=N;exports.withMessage=V;exports.withParams=k;exports.withTooltip=v;
|
package/dist/regle-rules.min.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {createRule,InternalRuleType,unwrapRuleParameters}from'@regle/core';import {unref}from'vue';function V(e,t){let i,o,u,f;typeof e=="function"&&!("_validator"in e)?(i=InternalRuleType.Inline,o=e):{_type:i,validator:o,_active:u,_params:f}=e;let m=createRule({type:i,validator:o,active:u,message:t}),R=[...f??[]];if(m._params=R,m._message_patched=!0,typeof m=="function"){let r=m(...R);return r._message_patched=!0,r}else return m}function v(e,t){let i,o,u,f,m;typeof e=="function"&&!("_validator"in e)?(i=InternalRuleType.Inline,o=e):{_type:i,validator:o,_active:u,_params:f,_message:m}=e;let R=createRule({type:i,validator:o,active:u,message:m,tooltip:t}),r=[...f??[]];if(R._params=r,R._tooltip_patched=!0,typeof R=="function"){let s=R(...r);return R._tooltip_patched=!0,s}else return R}function N(e,t){let i=async(u,...f)=>e(u,...f),o=createRule({type:InternalRuleType.Async,validator:i,message:""});return o._params=o._params?.concat(t),o(...t??[])}function k(e,t){let i=(u,...f)=>e(u,...f),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=[],f="";typeof t=="function"?(i=InternalRuleType.Inline,o=t,u=[e]):({_type:i,validator:o,_message:f}=t,u=t._params?.concat([e]));function m(n,...p){let[b]=unwrapRuleParameters([e]);return b?o(n,...p):!0}function R(n){let[p]=unwrapRuleParameters([e]);return p}let r=createRule({type:i,validator:m,active:R,message:f}),s=[...u??[]];if(r._params=s,typeof r=="function"){let n=r(...s);return n._message_patched=!0,n}else return r}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 g(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 D(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 x(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 T(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 d(e){return typeof e=="number"?e:e!=null?typeof e=="string"?e.trim()!==e?NaN:+e:NaN:NaN}function q(...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:[]}}).flat().filter(r=>!!r);function o(r,s,...n){let p=[],b=0;for(let c of r)if(typeof c=="function")p.push(c(s)),b++;else {let M=c._params?.length??0;p.push(c.validator(s,...n.slice(b,M))),M&&(b+=M);}return p}function u(r){return r?.some(n=>typeof n!="boolean")?{$valid:r.every(n=>typeof n=="boolean"?!!n:n.$valid),...r.reduce((n,p)=>{if(typeof p=="boolean")return n;let{$valid:b,...c}=p;return {...n,...c}},{})}:r.every(n=>!!n)}let f;e.length?f=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)}:f=r=>!1;let m=createRule({type:"and",validator:f,message:"The value does not match all of the provided validators"}),R=[...i??[]];if(m._params=R,typeof m=="function"){let r=m(...R);return r._message_patched=!0,r}else return m}function O(...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 p=[],b=0;for(let c of r)if(typeof c=="function")p.push(c(s)),b++;else {let M=c._params?.length??0;p.push(c.validator(s,...n.slice(b,M))),M&&(b+=M);}return p}function u(r){return r.some(n=>typeof n!="boolean")?{$valid:r.some(n=>typeof n=="boolean"?!!n:n.$valid),...r.reduce((n,p)=>{if(typeof p=="boolean")return n;let{$valid:b,...c}=p;return {...n,...c}},{})}:r.some(n=>!!n)}let m=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"}),R=[...i??[]];if(m._params=R,typeof m=="function"){let r=m(...R);return r._message_patched=!0,r}else return m}function j(e,t){let i,o,u,f,m;typeof e=="function"?(o=e,m=e.constructor.name==="AsyncFunction"):({_type:i,validator:o,_params:f}=e,m=e._async),m?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"}),r=[...f??[]];if(R._params=r,typeof R=="function"){let s=R(...r);return s._message_patched=!0,s}else return R}var zt=createRule({type:"required",validator:e=>a(e),message:"This field is required"});var Ut=createRule({type:"maxLength",validator:(e,t)=>a(e)&&a(t)?y(t)?D(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 Kt=createRule({type:"required",validator(e,t){return t?a(e):!0},message:"This field is required",active({$params:[e]}){return e}});var Q=/^[a-zA-Z]*$/,Ht=createRule({type:"alpha",validator(e){return l(e)?!0:g(e,Q)},message:"The value is not alphabetical"});var Y=/^[a-zA-Z0-9]*$/,Yt=createRule({type:"alpha",validator(e){return l(e)?!0:g(e,Y)},message:"The value must be alpha-numeric"});var ar=createRule({type:"between",validator:(e,t,i)=>{if(a(e)&&a(t)&&a(i)){let o=d(e),u=d(t),f=d(i);return y(o)&&y(u)&&y(f)?o>=u&&o<=f:(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 re=/^[-]?\d*(\.\d+)?$/,sr=createRule({type:"decimal",validator(e){return l(e)?!0:g(e,re)},message:"Value must be decimal"});var ne=/^(?:[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,fr=createRule({type:"email",validator(e){return l(e)?!0:g(e,ne)},message:"Value must be an valid email address"});var oe=/(^[0-9]*$)|(^-[0-9]+$)/,gr=createRule({type:"integer",validator(e){return l(e)?!0:g(e,oe)},message:"Value must be an integer"});var xr=createRule({type:"maxValue",validator:(e,t)=>a(e)&&a(t)?y(t)&&!isNaN(d(e))?d(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 hr=createRule({type:"minLength",validator:(e,t)=>a(e)&&a(t)?y(t)?D(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 Vr=createRule({type:"minValue",validator:(e,t)=>a(e)&&a(t)?y(t)&&!isNaN(d(e))?d(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 _r=createRule({type:"exactValue",validator:(e,t)=>a(e)&&a(t)?y(t)&&!isNaN(d(e))?d(e)===t:(console.warn(`[exactValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!0):!0,message:({$params:[e]})=>`The value must be equal to ${e}`});var Er=createRule({type:"exactLength",validator:(e,t)=>a(e)&&a(t)?y(t)?D(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 pe=/^\d*(\.\d+)?$/,Cr=createRule({type:"numeric",validator(e){return l(e)?!0:g(e,pe)},message:"This field must be numeric"});var Gr=createRule({type:"required",validator(e,t){return t?!0:a(e)},message:"This field is required",active({$params:[e]}){return !e}});var Br=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 ce=/^(?:(?:(?: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:g(e,ce)},message:"The value is not a valid URL address"});function Te(){return navigator.languages!=null?navigator.languages[0]:navigator.language}function h(e){return e?new Intl.DateTimeFormat(Te(),{dateStyle:"short"}).format(new Date(e)):"?"}var aa=createRule({type:"dateAfter",validator:(e,t)=>a(e)&&a(t)?x(e)&&x(t)?T(e).getTime()>T(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 ${h(e)}`});var la=createRule({type:"dateBefore",validator:(e,t)=>a(e)&&a(t)?x(e)&&x(t)?T(e).getTime()<T(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 ${h(e)}`});var pa=createRule({type:"dateBetween",validator:(e,t,i)=>x(e)&&x(t)&&x(i)?T(e).getTime()>T(t).getTime()&&T(e).getTime()<T(i).getTime():!0,message:({$params:[e,t]})=>`The date must be between ${h(e)} and ${h(t)}`});function he(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 ca=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(he)},message:"The value is not a valid IP address"});var Da=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(we)},message:"The value is not a valid MAC Address"}),we=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/);var wa=createRule({type:"checked",validator:e=>a(e)?e===!0:!0,message:"This field must be checked"});var Wa=createRule({type:"contains",validator(e,t){return a(e)&&a(t)?e.includes(t):!0},message({$params:[e]}){return `Field must contain ${e}`}});var Na=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 za=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 Ua=createRule({type:"regex",validator(e,...t){return a(e)?g(e,...t):!0},message:"This field does not match the required pattern"});export{Ht as alpha,Yt as alphaNum,q as and,C as applyIf,ar as between,wa as checked,Wa as contains,aa as dateAfter,la as dateBefore,pa as dateBetween,sr as decimal,fr as email,za as endsWith,Er as exactLength,_r as exactValue,D as getSize,gr as integer,ca as ipAddress,x as isDate,l as isEmpty,a as isFilled,y as isNumber,Da as macAddress,g as matchRegex,Ut as maxLength,xr as maxValue,hr as minLength,Vr as minValue,j as not,Cr as numeric,O as or,Ua as regex,zt as required,Kt as requiredIf,Gr as requiredUnless,Br as sameAs,Na as startsWith,T as toDate,d as toNumber,Qr as url,N as withAsync,V as withMessage,k as withParams,v as withTooltip};
|
|
1
|
+
import {createRule,InternalRuleType,unwrapRuleParameters}from'@regle/core';import {unref}from'vue';function V(e,t){let i,o,u,f;typeof e=="function"&&!("_validator"in e)?(i=InternalRuleType.Inline,o=e):{_type:i,validator:o,_active:u,_params:f}=e;let m=createRule({type:i,validator:o,active:u,message:t}),R=[...f??[]];if(m._params=R,m._message_patched=!0,typeof m=="function"){let r=m(...R);return r._message_patched=!0,r}else return m}function v(e,t){let i,o,u,f,m;typeof e=="function"&&!("_validator"in e)?(i=InternalRuleType.Inline,o=e):{_type:i,validator:o,_active:u,_params:f,_message:m}=e;let R=createRule({type:i,validator:o,active:u,message:m,tooltip:t}),r=[...f??[]];if(R._params=r,R._tooltip_patched=!0,typeof R=="function"){let s=R(...r);return R._tooltip_patched=!0,s}else return R}function N(e,t){let i=async(u,...f)=>e(u,...f),o=createRule({type:InternalRuleType.Async,validator:i,message:""});return o._params=o._params?.concat(t),o(...t??[])}function k(e,t){let i=(u,...f)=>e(u,...f),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=[],f="";typeof t=="function"?(i=InternalRuleType.Inline,o=t,u=[e]):({_type:i,validator:o,_message:f}=t,u=t._params?.concat([e]));function m(n,...p){let[b]=unwrapRuleParameters([e]);return b?o(n,...p):!0}function R(n){let[p]=unwrapRuleParameters([e]);return p}let r=createRule({type:i,validator:m,active:R,message:f}),s=[...u??[]];if(r._params=s,typeof r=="function"){let n=r(...s);return n._message_patched=!0,n}else return r}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 g(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 D(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 x(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 T(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 d(e){return typeof e=="number"?e:e!=null?typeof e=="string"?e.trim()!==e?NaN:+e:NaN:NaN}function q(...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:[]}}).flat().filter(r=>!!r);function o(r,s,...n){let p=[],b=0;for(let c of r)if(typeof c=="function")p.push(c(s)),b++;else {let M=c._params?.length??0;p.push(c.validator(s,...n.slice(b,M))),M&&(b+=M);}return p}function u(r){return r?.some(n=>typeof n!="boolean")?{$valid:r.every(n=>typeof n=="boolean"?!!n:n.$valid),...r.reduce((n,p)=>{if(typeof p=="boolean")return n;let{$valid:b,...c}=p;return {...n,...c}},{})}:r.every(n=>!!n)}let f;e.length?f=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)}:f=r=>!1;let m=createRule({type:"and",validator:f,message:"The value does not match all of the provided validators"}),R=[...i??[]];if(m._params=R,typeof m=="function"){let r=m(...R);return r._message_patched=!0,r}else return m}function O(...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 p=[],b=0;for(let c of r)if(typeof c=="function")p.push(c(s)),b++;else {let M=c._params?.length??0;p.push(c.validator(s,...n.slice(b,M))),M&&(b+=M);}return p}function u(r){return r.some(n=>typeof n!="boolean")?{$valid:r.some(n=>typeof n=="boolean"?!!n:n.$valid),...r.reduce((n,p)=>{if(typeof p=="boolean")return n;let{$valid:b,...c}=p;return {...n,...c}},{})}:r.some(n=>!!n)}let m=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"}),R=[...i??[]];if(m._params=R,typeof m=="function"){let r=m(...R);return r._message_patched=!0,r}else return m}function B(e,t){let i,o,u,f,m;typeof e=="function"?(o=e,m=e.constructor.name==="AsyncFunction"):({_type:i,validator:o,_params:f}=e,m=e._async),m?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"}),r=[...f??[]];if(R._params=r,typeof R=="function"){let s=R(...r);return s._message_patched=!0,s}else return R}var Ct=createRule({type:"required",validator:e=>a(e),message:"This field is required"});var Gt=createRule({type:"maxLength",validator:(e,t)=>a(e)&&a(t)?y(t)?D(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 jt=createRule({type:"required",validator(e,t){return t?a(e):!0},message:"This field is required",active({$params:[e]}){return e}});var Q=/^[a-zA-Z]*$/,Qt=createRule({type:"alpha",validator(e){return l(e)?!0:g(e,Q)},message:"The value is not alphabetical"});var Y=/^[a-zA-Z0-9]*$/,tr=createRule({type:"alpha",validator(e){return l(e)?!0:g(e,Y)},message:"The value must be alpha-numeric"});var ir=createRule({type:"between",validator:(e,t,i)=>{if(a(e)&&a(t)&&a(i)){let o=d(e),u=d(t),f=d(i);return y(o)&&y(u)&&y(f)?o>=u&&o<=f:(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 re=/^[-]?\d*(\.\d+)?$/,ur=createRule({type:"decimal",validator(e){return l(e)?!0:g(e,re)},message:"Value must be decimal"});var ne=/^(?:[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,pr=createRule({type:"email",validator(e){return l(e)?!0:g(e,ne)},message:"Value must be an valid email address"});var oe=/(^[0-9]*$)|(^-[0-9]+$)/,cr=createRule({type:"integer",validator(e){return l(e)?!0:g(e,oe)},message:"Value must be an integer"});var Dr=createRule({type:"maxValue",validator:(e,t)=>a(e)&&a(t)?y(t)&&!isNaN(d(e))?d(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 wr=createRule({type:"minLength",validator:(e,t)=>a(e)&&a(t)?y(t)?D(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(d(e))?d(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 Nr=createRule({type:"exactValue",validator:(e,t)=>a(e)&&a(t)?y(t)&&!isNaN(d(e))?d(e)===t:(console.warn(`[exactValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!0):!0,message:({$params:[e]})=>`The value must be equal to ${e}`});var zr=createRule({type:"exactLength",validator:(e,t)=>a(e)&&a(t)?y(t)?D(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 pe=/^\d*(\.\d+)?$/,Ur=createRule({type:"numeric",validator(e){return l(e)?!0:g(e,pe)},message:"This field must be numeric"});var Kr=createRule({type:"required",validator(e,t){return t?!0:a(e)},message:"This field is required",active({$params:[e]}){return !e}});var Hr=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 ce=/^(?:(?:(?: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,Yr=createRule({type:"url",validator(e){return l(e)?!0:g(e,ce)},message:"The value is not a valid URL address"});function Te(){return navigator.languages!=null?navigator.languages[0]:navigator.language}function h(e){return e?new Intl.DateTimeFormat(Te(),{dateStyle:"short"}).format(new Date(e)):"?"}var ia=createRule({type:"dateAfter",validator:(e,t)=>a(e)&&a(t)?x(e)&&x(t)?T(e).getTime()>T(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 ${h(e)}`});var ma=createRule({type:"dateBefore",validator:(e,t)=>a(e)&&a(t)?x(e)&&x(t)?T(e).getTime()<T(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 ${h(e)}`});var ga=createRule({type:"dateBetween",validator:(e,t,i)=>x(e)&&x(t)&&x(i)?T(e).getTime()>T(t).getTime()&&T(e).getTime()<T(i).getTime():!0,message:({$params:[e,t]})=>`The date must be between ${h(e)} and ${h(t)}`});function he(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 xa=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(he)},message:"The value is not a valid IP address"});var ha=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(we)},message:"The value is not a valid MAC Address"}),we=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/);var Va=createRule({type:"checked",validator:e=>a(e)?e===!0:!0,message:"This field must be checked"});var Fa=createRule({type:"contains",validator(e,t){return a(e)&&a(t)?e.includes(t):!0},message({$params:[e]}){return `Field must contain ${e}`}});var Ea=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 Ca=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 Ga=createRule({type:"regex",validator(e,...t){return a(e)?g(e,...t):!0},message:"This field does not match the required pattern"});export{Qt as alpha,tr as alphaNum,q as and,C as applyIf,ir as between,Va as checked,Fa as contains,ia as dateAfter,ma as dateBefore,ga as dateBetween,ur as decimal,pr as email,Ca as endsWith,zr as exactLength,Nr as exactValue,D as getSize,cr as integer,xa as ipAddress,x as isDate,l as isEmpty,a as isFilled,y as isNumber,ha as macAddress,g as matchRegex,Gt as maxLength,Dr as maxValue,wr as minLength,Wr as minValue,B as not,Ur as numeric,O as or,Ga as regex,Ct as required,jt as requiredIf,Kr as requiredUnless,Hr as sameAs,Ea as startsWith,T as toDate,d as toNumber,Yr as url,N as withAsync,V as withMessage,k as withParams,v as withTooltip};
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regle/rules",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.10",
|
|
4
4
|
"description": "Collection of rules and helpers for Regle",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@regle/core": "0.5.
|
|
6
|
+
"@regle/core": "0.5.10"
|
|
7
7
|
},
|
|
8
8
|
"devDependencies": {
|
|
9
|
-
"@typescript-eslint/eslint-plugin": "8.19.
|
|
10
|
-
"@typescript-eslint/parser": "8.19.
|
|
9
|
+
"@typescript-eslint/eslint-plugin": "8.19.1",
|
|
10
|
+
"@typescript-eslint/parser": "8.19.1",
|
|
11
11
|
"@vue/reactivity": "3.5.13",
|
|
12
12
|
"@vue/test-utils": "2.4.6",
|
|
13
|
-
"bumpp": "9.
|
|
13
|
+
"bumpp": "9.10.0",
|
|
14
14
|
"changelogithub": "0.13.11",
|
|
15
15
|
"cross-env": "7.0.3",
|
|
16
16
|
"eslint": "9.15.0",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"eslint-plugin-vue": "9.31.0",
|
|
19
19
|
"prettier": "3.3.3",
|
|
20
20
|
"tsup": "8.3.5",
|
|
21
|
-
"type-fest": "4.
|
|
21
|
+
"type-fest": "4.32.0",
|
|
22
22
|
"typescript": "5.6.3",
|
|
23
23
|
"vitest": "2.1.8",
|
|
24
24
|
"vue": "3.5.13",
|