@regle/rules 1.16.2 → 1.17.0
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.d.ts +1 -1
- package/dist/regle-rules.js +24 -13
- package/dist/regle-rules.min.js +2 -2
- package/package.json +2 -2
package/dist/regle-rules.d.ts
CHANGED
package/dist/regle-rules.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @regle/rules v1.
|
|
2
|
+
* @regle/rules v1.17.0
|
|
3
3
|
* (c) 2026 Victor Garcia
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -143,12 +143,13 @@ function applyIf(_condition, rule) {
|
|
|
143
143
|
let validator;
|
|
144
144
|
let _params = [];
|
|
145
145
|
let _message = "";
|
|
146
|
+
let _async = false;
|
|
146
147
|
if (typeof rule === "function") {
|
|
147
148
|
_type = InternalRuleType.Inline;
|
|
148
149
|
validator = rule;
|
|
149
150
|
_params = [_condition];
|
|
150
151
|
} else {
|
|
151
|
-
({_type, validator, _message} = rule);
|
|
152
|
+
({_type, validator, _message, _async} = rule);
|
|
152
153
|
_params = rule._params?.concat([_condition]);
|
|
153
154
|
}
|
|
154
155
|
function newValidator(value, ...args) {
|
|
@@ -164,7 +165,8 @@ function applyIf(_condition, rule) {
|
|
|
164
165
|
type: _type,
|
|
165
166
|
validator: newValidator,
|
|
166
167
|
active: newActive,
|
|
167
|
-
message: _message
|
|
168
|
+
message: _message,
|
|
169
|
+
async: _async
|
|
168
170
|
});
|
|
169
171
|
const newParams = [..._params ?? []];
|
|
170
172
|
newRule._params = newParams;
|
|
@@ -470,6 +472,15 @@ function toNumber(argument) {
|
|
|
470
472
|
return NaN;
|
|
471
473
|
}
|
|
472
474
|
|
|
475
|
+
/**
|
|
476
|
+
* Type guard that checks if the passed value is a real `String`.
|
|
477
|
+
*/
|
|
478
|
+
function isString(value) {
|
|
479
|
+
if (value == null) return false;
|
|
480
|
+
else if (typeof value !== "string") return false;
|
|
481
|
+
return true;
|
|
482
|
+
}
|
|
483
|
+
|
|
473
484
|
/**
|
|
474
485
|
* The `and` operator combines multiple rules and validates successfully only if **all** provided rules are valid.
|
|
475
486
|
*
|
|
@@ -874,7 +885,7 @@ const between = createRule({
|
|
|
874
885
|
if (isNumber(tValue) && isNumber(tMin) && isNumber(tMax)) if (allowEqual) return tValue >= tMin && tValue <= tMax;
|
|
875
886
|
else return tValue > tMin && tValue < tMax;
|
|
876
887
|
console.warn(`[between] Value or parameters aren't numbers, got value: ${value}, min: ${min}, max: ${max}`);
|
|
877
|
-
return
|
|
888
|
+
return true;
|
|
878
889
|
}
|
|
879
890
|
return true;
|
|
880
891
|
},
|
|
@@ -955,7 +966,7 @@ const checked = createRule({
|
|
|
955
966
|
const contains = createRule({
|
|
956
967
|
type: "contains",
|
|
957
968
|
validator(value, part) {
|
|
958
|
-
if (isFilled(value) && isFilled(part)) return value.includes(part);
|
|
969
|
+
if (isFilled(value) && isFilled(part) && isString(value) && isString(part)) return value.includes(part);
|
|
959
970
|
return true;
|
|
960
971
|
},
|
|
961
972
|
message({ $params: [part] }) {
|
|
@@ -1218,7 +1229,7 @@ const emoji = createRule({
|
|
|
1218
1229
|
const endsWith = createRule({
|
|
1219
1230
|
type: "endsWith",
|
|
1220
1231
|
validator(value, part) {
|
|
1221
|
-
if (isFilled(value) && isFilled(part)) return value.endsWith(part);
|
|
1232
|
+
if (isFilled(value) && isFilled(part) && isString(value) && isString(part)) return value.endsWith(part);
|
|
1222
1233
|
return true;
|
|
1223
1234
|
},
|
|
1224
1235
|
message({ $params: [part] }) {
|
|
@@ -1259,7 +1270,7 @@ const exactDigits = createRule({
|
|
|
1259
1270
|
return matchRegex(value.toString(), digitsRegex);
|
|
1260
1271
|
}
|
|
1261
1272
|
console.warn(`[exactDigits] Parameter isn't a number, got parameter: ${count}`);
|
|
1262
|
-
return
|
|
1273
|
+
return true;
|
|
1263
1274
|
}
|
|
1264
1275
|
return true;
|
|
1265
1276
|
},
|
|
@@ -1397,7 +1408,7 @@ const fileType = createRule({
|
|
|
1397
1408
|
validator: (value, accept) => {
|
|
1398
1409
|
if (isFilled(value)) {
|
|
1399
1410
|
if (isFile(value)) return accept.includes(value.type);
|
|
1400
|
-
return
|
|
1411
|
+
return true;
|
|
1401
1412
|
}
|
|
1402
1413
|
return true;
|
|
1403
1414
|
},
|
|
@@ -1721,7 +1732,7 @@ const maxLength = createRule({
|
|
|
1721
1732
|
if (isNumber(max)) if (allowEqual) return getSize(value) <= max;
|
|
1722
1733
|
else return getSize(value) < max;
|
|
1723
1734
|
console.warn(`[maxLength] Value or parameter isn't a number, got value: ${value}, parameter: ${max}`);
|
|
1724
|
-
return
|
|
1735
|
+
return true;
|
|
1725
1736
|
}
|
|
1726
1737
|
return true;
|
|
1727
1738
|
},
|
|
@@ -1765,7 +1776,7 @@ const maxValue = createRule({
|
|
|
1765
1776
|
if (!isNaN(toNumber(value)) && !isNaN(toNumber(max))) if (allowEqual) return toNumber(value) <= toNumber(max);
|
|
1766
1777
|
else return toNumber(value) < toNumber(max);
|
|
1767
1778
|
console.warn(`[maxValue] Value or parameter isn't a number, got value: ${value}, parameter: ${max}`);
|
|
1768
|
-
return
|
|
1779
|
+
return true;
|
|
1769
1780
|
}
|
|
1770
1781
|
return true;
|
|
1771
1782
|
},
|
|
@@ -1845,7 +1856,7 @@ const minLength = createRule({
|
|
|
1845
1856
|
if (isNumber(min)) if (allowEqual) return getSize(value) >= min;
|
|
1846
1857
|
else return getSize(value) > min;
|
|
1847
1858
|
console.warn(`[minLength] Parameter isn't a number, got parameter: ${min}`);
|
|
1848
|
-
return
|
|
1859
|
+
return true;
|
|
1849
1860
|
}
|
|
1850
1861
|
return true;
|
|
1851
1862
|
},
|
|
@@ -1889,7 +1900,7 @@ const minValue = createRule({
|
|
|
1889
1900
|
if (!isNaN(toNumber(value)) && !isNaN(toNumber(min))) if (allowEqual) return toNumber(value) >= toNumber(min);
|
|
1890
1901
|
else return toNumber(value) > toNumber(min);
|
|
1891
1902
|
console.warn(`[minValue] Value or parameter isn't a number, got value: ${value}, parameter: ${min}`);
|
|
1892
|
-
return
|
|
1903
|
+
return true;
|
|
1893
1904
|
}
|
|
1894
1905
|
return true;
|
|
1895
1906
|
},
|
|
@@ -2188,7 +2199,7 @@ const sameAs = createRule({
|
|
|
2188
2199
|
const startsWith = createRule({
|
|
2189
2200
|
type: "startsWith",
|
|
2190
2201
|
validator(value, part) {
|
|
2191
|
-
if (isFilled(value) && isFilled(part)) return value.startsWith(part);
|
|
2202
|
+
if (isFilled(value) && isFilled(part) && isString(value) && isString(part)) return value.startsWith(part);
|
|
2192
2203
|
return true;
|
|
2193
2204
|
},
|
|
2194
2205
|
message({ $params: [part] }) {
|
package/dist/regle-rules.min.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @regle/rules v1.
|
|
2
|
+
* @regle/rules v1.17.0
|
|
3
3
|
* (c) 2026 Victor Garcia
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import{InternalRuleType as e,createRule as t,unwrapRuleParameters as n}from"@regle/core";import{computed as r,toValue as i,unref as a}from"vue";function o(n,r){let i,a,o,s,c=!1;typeof n==`function`&&!(`_validator`in n)?(i=e.Inline,a=n):{_type:i,validator:a,_active:o,_params:s,_async:c}=n;let l=t({type:i,validator:a,active:o,message:r,async:c}),u=[...s??[]];if(l._params=u,l._message_patched=!0,typeof l==`function`){if(s!=null){let e=l(...u);return e._message_patched=!0,e}return l}else return l}function s(n,r){let i,a,o,s,c,l=!1;typeof n==`function`&&!(`_validator`in n)?(i=e.Inline,a=n):{_type:i,validator:a,_active:o,_params:s,_message:c,_async:l}=n;let u=t({type:i,validator:a,active:o,message:c,tooltip:r,async:l}),d=[...s??[]];if(u._params=d,u._tooltip_patched=!0,typeof u==`function`){let e=u(...d);return u._tooltip_patched=!0,e}else return u}function c(n,r){let i,a,o=[],s=``;typeof n==`function`?(a=async(e,...t)=>n(e,...t),o=[r]):({_type:i,_message:s}=n,o=o=n._params?.concat(r),a=async(...e)=>n.validator(e));let c=t({type:i??e.Async,validator:a,message:s,async:!0});return c._params=c._params?.concat(o),c(...r??[])}function l(n,r){let i,a,o=[],s=``;typeof n==`function`?(e.Inline,a=(e,...t)=>n(e,...t),o=[r]):({_type:i,validator:a,_message:s}=n,o=o=n._params?.concat(r));let c=t({type:e.Inline,validator:a,message:s});return c._params=c._params?.concat(o),c(...r)}function u(r,i){let a,o,s=[],c=``;typeof i==`function`?(a=e.Inline,o=i,s=[r]):({_type:a,validator:o,_message:c}=i,s=i._params?.concat([r]));function l(e,...t){let[i]=n([r]);return i?o(e,...t):!0}function u(){let[e]=n([r]);return e}let d=t({type:a,validator:l,active:u,message:c}),f=[...s??[]];return d._params=f,typeof d==`function`?d(...f):d}function d(e){return e?.constructor?.name==`File`}function f(e,t=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):d(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:typeof e==`object`&&e?Object.keys(e).length===0:!String(e).length}function ee(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function p(e){if(f(e))return!1;let t=null;if(e instanceof Date)t=e;else if(typeof e==`string`){let n=new Date(e);if(n.toString()===`Invalid Date`)return!1;t=n}return!!t}function m(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]`||typeof e==`string`||t===`[object String]`?new Date(e):new Date(NaN)}function h(e){return e===void 0?`0 bytes`:e<1024?`${e} bytes`:e<1024*1024?`${(e/1024).toFixed(2)} kb`:e<1024*1024*1024?`${(e/1024/1024).toFixed(2)} mb`:`${(e/1024/1024/1024).toFixed(2)} gb`}function g(e,t=!0){return!f(typeof e==`string`?e.trim():e,t)}function _(e){return e==null?!1:typeof e==`number`?!isNaN(e):!1}function v(e,...t){if(f(e))return!0;let n=typeof e==`number`?e.toString():e;return t.every(e=>(e.lastIndex=0,e.test(n)))}function y(e){let t=a(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 b(e){return typeof e==`number`?e:e==null?NaN:typeof e==`string`&&e.trim()===e?+e:NaN}function x(...e){let n=e.some(e=>typeof e==`function`?e.constructor.name===`AsyncFunction`:e._async),r=e.map(e=>{if(typeof e==`function`)return null;{let t=e._params;return t?.length?t:[]}}).flat().filter(e=>!!e);function i(e,t,...n){let r=[],i=0;for(let a of e)if(typeof a==`function`)r.push(a(t)),i++;else{let e=a._params?.length??0;r.push(a.validator(t,...n.slice(i,e))),e&&(i+=e)}return r}function a(e){return e?.some(e=>typeof e!=`boolean`)?{$valid:e.every(e=>typeof e==`boolean`?!!e:e.$valid),...e.reduce((e,t)=>{if(typeof t==`boolean`)return e;let{$valid:n,...r}=t;return{...e,...r}},{})}:e.every(e=>!!e)}let o;o=e.length?n?async(t,...n)=>a(await Promise.all(i(e,t,...n))):(t,...n)=>a(i(e,t,...n)):e=>!1;let s=t({type:`and`,validator:o,message:`The value does not match all of the provided validators`}),c=[...r??[]];return s._params=c,typeof s==`function`?s(...c):s}function S(...e){let n=e.some(e=>typeof e==`function`?e.constructor.name===`AsyncFunction`:e._async),r=e.map(e=>typeof e==`function`?null:e._params).flat().filter(e=>!!e);function i(e,t,...n){let r=[],i=0;for(let a of e)if(typeof a==`function`)r.push(a(t)),i++;else{let e=a._params?.length??0;r.push(a.validator(t,...n.slice(i,e))),e&&(i+=e)}return r}function a(e){return e.some(e=>typeof e!=`boolean`)?{$valid:e.some(e=>typeof e==`boolean`?!!e:e.$valid),...e.reduce((e,t)=>{if(typeof t==`boolean`)return e;let{$valid:n,...r}=t;return{...e,...r}},{})}:e.some(e=>!!e)}let o=t({type:`or`,validator:n?async(t,...n)=>a(await Promise.all(i(e,t,...n))):(t,...n)=>a(i(e,t,...n)),message:`The value does not match any of the provided validators`}),s=[...r??[]];return o._params=s,typeof o==`function`?o(...s):o}function te(e,n){let r,i,a,o,s;typeof e==`function`?(i=e,s=e.constructor.name===`AsyncFunction`):({_type:r,validator:i,_params:o}=e,s=e._async),a=s?async(e,...t)=>g(e)?!await i(e,...t):!0:(e,...t)=>g(e)?!i(e,...t):!0;let c=t({type:`not`,validator:a,message:n??`Error`}),l=[...o??[]];return c._params=l,typeof c==`function`?c(...l):c}function C(e,t,n){return Object.entries(i(t)).map(([t,r])=>typeof r==`function`||ee(r)&&`_validator`in r?[t,u(n?e:()=>!i(e),r)]:[t,r])}function ne(e,t,n){return r(()=>{let r=C(e,t,!0),i=n?C(e,n,!1):[];return Object.fromEntries([...r,...i])})}const w=/^https?$/,T=/^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/,E=/^(?:(?:(?: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;function D(){return RegExp(`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`,`u`)}const O=/^[^A-Z]*$/,k=/^[^a-z]*$/,A=/^[0-9a-fA-F]*$/,j=/^[a-zA-Z]*$/,M=/^[\w.]+$/,N=/^[a-zA-Z0-9]*$/,P=/^[a-zA-Z0-9_]*$/,F=/^[-]?\d*(\.\d+)?$/,I=/^(?:[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,L=/(^[0-9]*$)|(^-[0-9]+$)/,R=/^\d*(\.\d+)?$/,z=t({type:`alpha`,validator(e,t){return f(e)?!0:t?.allowSymbols?v(e,M):v(e,j)},message:`The value is not alphabetical`}),B=t({type:`alphaNum`,validator(e,t){return f(e)?!0:t?.allowSymbols?v(e,P):v(e,N)},message:`The value must be alpha-numeric`}),V=t({type:`between`,validator:(e,t,n,r)=>{let{allowEqual:i=!0}=r??{};if(g(e)&&g(t)&&g(n)){let r=b(e),a=b(t),o=b(n);return _(r)&&_(a)&&_(o)?i?r>=a&&r<=o:r>a&&r<o:!1}return!0},message:({$params:[e,t]})=>`The value must be between ${e} and ${t}`}),H=t({type:`boolean`,validator:e=>g(e)?typeof e==`boolean`:!0,message:`The value must be a native boolean`}),U=t({type:`checked`,validator:e=>g(e)?e===!0:!0,message:`The field must be checked`}),W=t({type:`contains`,validator(e,t){return g(e)&&g(t)?e.includes(t):!0},message({$params:[e]}){return`The value must contain ${e}`}}),G=t({type:`date`,validator:e=>g(e)?e instanceof Date:!0,message:`The value must be a native Date`});function K(){return navigator.languages==null?navigator.language:navigator.languages[0]}function q(e){return e?new Intl.DateTimeFormat(K(),{dateStyle:`short`}).format(new Date(e)):`?`}const J=t({type:`dateAfter`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return g(e)&&g(t)?p(e)&&p(t)?(r?m(e).getTime()>=m(t).getTime():m(e).getTime()>m(t).getTime())?!0:{$valid:!1,error:`date-not-after`}:{$valid:!1,error:`value-or-parameter-not-a-date`}:!0},message:({$params:[e],error:t})=>t===`value-or-parameter-not-a-date`?`The values must be dates`:`The date must be after ${q(e)}`}),Y=t({type:`dateBefore`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return g(e)&&g(t)?p(e)&&p(t)?(r?m(e).getTime()<=m(t).getTime():m(e).getTime()<m(t).getTime())?!0:{$valid:!1,error:`date-not-before`}:{$valid:!1,error:`value-or-parameter-not-a-date`}:!0},message:({$params:[e],error:t})=>t===`value-or-parameter-not-a-date`?`The values must be dates`:`The date must be before ${q(e)}`}),X=t({type:`dateBetween`,validator:(e,t,n,r)=>{let{allowEqual:i=!0}=r??{};return p(e)&&p(t)&&p(n)?i?m(e).getTime()>=m(t).getTime()&&m(e).getTime()<=m(n).getTime():m(e).getTime()>m(t).getTime()&&m(e).getTime()<m(n).getTime():!0},message:({$params:[e,t]})=>`The date must be between ${q(e)} and ${q(t)}`}),Z=t({type:`decimal`,validator(e){return f(e)?!0:v(e,F)},message:`The value must be decimal`}),re=t({type:`email`,validator(e){return f(e)?!0:v(e,I)},message:`The value must be an valid email address`}),ie=t({type:`emoji`,validator(e){return f(e)?!0:D().test(e)},message:`The value should be a valid emoji`}),ae=t({type:`endsWith`,validator(e,t){return g(e)&&g(t)?e.endsWith(t):!0},message({$params:[e]}){return`The value must end with ${e}`}}),oe=t({type:`exactDigits`,validator:(e,t)=>{if(g(e,!1)&&g(t)){if(_(t)){let n=RegExp(`^\\d{${t}}$`);return v(e.toString(),n)}return!1}return!0},message:({$params:[e]})=>`The value should have exactly ${e} digits`}),se=t({type:`exactLength`,validator:(e,t)=>g(e,!1)&&g(t)?_(t)?y(e)===t:!1:!0,message:({$params:[e]})=>`The value should be exactly ${e} characters long`}),ce=t({type:`exactValue`,validator:(e,t)=>g(e)&&g(t)&&_(t)&&!isNaN(b(e))?b(e)===t:!0,message:({$params:[e]})=>`The value must be equal to ${e}`}),le=t({type:`file`,validator:e=>g(e)?d(e):!0,message:`The value must be a native File`}),ue=t({type:`fileType`,validator:(e,t)=>g(e)?d(e)?t.includes(e.type):!1:!0,message({$params:[e]}){return`File type is not allowed. Allowed types are: ${e.map(e=>e.split(`/`)[1]).join(`, `)}.`}}),de=t({type:`hexadecimal`,validator(e){return f(e)?!0:v(e,A)},message:`The value must be hexadecimal`}),fe=t({type:`hostname`,validator(e){return f(e)?!0:v(e,T)},message:`The value is not a valid hostname`}),Q=t({type:`url`,validator(e,t={}){try{if(f(e))return!0;let{protocol:n}=t||{},r=new URL(e);return!T.test(r.hostname)||n&&!n.test(r.protocol.endsWith(`:`)?r.protocol.slice(0,-1):r.protocol)?!1:v(e,E)}catch{return!1}},message:`The value is not a valid URL address`}),pe=t({type:`httpUrl`,validator(e,t={}){if(f(e))return!0;let{protocol:n=w}=t||{};return Q({protocol:n}).exec(e)},message:`The value is not a valid http URL address`}),me=t({type:`integer`,validator(e){return f(e)?!0:v(e,L)},message:`The value must be an integer`});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}const ge=t({type:`ipv4Address`,validator(e){if(f(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 IPv4 address`});function _e(e){return o(l((e,t)=>g(e)&&g(t)?t===e:!0,[r(()=>i(e))]),({$params:[e]})=>`Value should be ${e}.`)}const ve=t({type:`lowercase`,validator(e){return f(e)?!0:v(e,O)},message:`The value is not a valid lowercase string`}),ye=t({type:`macAddress`,validator(e,t=`:`){if(f(e))return!0;if(typeof e!=`string`)return!1;let n=typeof t==`string`&&t!==``?e.split(t):e.length===12||e.length===16?e.match(/.{2}/g):null;return n!==null&&(n.length===6||n.length===8)&&n.every(be)},message:`The value is not a valid MAC Address`}),be=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/),xe=t({type:`maxFileSize`,validator:(e,t)=>g(e)&&d(e)?{$valid:e.size<=t,fileSize:e.size}:!0,message({$params:[e],fileSize:t}){return`File size (${h(t)}) cannot exceed ${h(e)}`}}),Se=t({type:`maxLength`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return g(e,!1)&&g(t)?_(t)?r?y(e)<=t:y(e)<t:!1:!0},message:({$value:e,$params:[t]})=>Array.isArray(e)?`This list should have maximum ${t} items`:`The value length should not exceed ${t}`}),Ce=t({type:`maxValue`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return g(e)&&g(t)?!isNaN(b(e))&&!isNaN(b(t))?r?b(e)<=b(t):b(e)<b(t):!1:!0},message:({$params:[e,t]})=>{let{allowEqual:n=!0}=t??{};return n?`The value must be less than or equal to ${e}`:`The value must be less than ${e}`}}),we=t({type:`minFileSize`,validator:(e,t)=>g(e)&&d(e)?{$valid:e.size>=t,fileSize:e.size}:!0,message({$params:[e],fileSize:t}){return`File size (${h(t)}) must be at least ${h(e)}`}}),Te=t({type:`minLength`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return g(e,!1)&&g(t)?_(t)?r?y(e)>=t:y(e)>t:!1:!0},message:({$value:e,$params:[t]})=>Array.isArray(e)?`The list should have at least ${t} items`:`The value length should be at least ${t}`}),Ee=t({type:`minValue`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return g(e)&&g(t)?!isNaN(b(e))&&!isNaN(b(t))?r?b(e)>=b(t):b(e)>b(t):!1:!0},message:({$params:[e,t]})=>{let{allowEqual:n=!0}=t??{};return n?`The value must be greater than or equal to ${e}`:`The value must be greater than ${e}`}});function De(e){let t=Object.keys(e).filter(t=>typeof e[e[t]]!=`number`),n={};for(let r of t)n[r]=e[r];return Object.values(n)}function $(e){return o(l((e,t)=>g(e)&&!f(t)?De(t).includes(e):!0,[r(()=>i(e))]),({$params:[e]})=>`The value should be one of those options: ${Object.values(e).join(`, `)}.`)}const Oe=t({type:`number`,validator:e=>g(e)?_(e):!0,message:`The value must be a native number`}),ke=t({type:`numeric`,validator(e){return f(e)?!0:v(e,R)},message:`The value must be numeric`}),Ae=t({type:`oneOf`,validator(e,t){return g(e)&&g(t,!1)?t.includes(e):!0},message:({$params:[e]})=>`The value should be one of those options: ${e.join(`, `)}.`}),je=t({type:`regex`,validator(e,t){return g(e)?v(e,...Array.isArray(t)?t:[t]):!0},message:`The value does not match the required pattern`}),Me=t({type:`required`,validator:e=>g(e),message:`This field is required`}),Ne=t({type:`required`,validator(e,t){return t?g(e):!0},message:`This field is required`,active({$params:[e]}){return e}}),Pe=t({type:`required`,validator(e,t){return t?!0:g(e)},message:`This field is required`,active({$params:[e]}){return!e}}),Fe=t({type:`sameAs`,validator(e,t,n){return f(e)?!0:e===t},message({$params:[e,t=`other`]}){return`The value must be equal to the ${t} value`}}),Ie=t({type:`startsWith`,validator(e,t){return g(e)&&g(t)?e.startsWith(t):!0},message({$params:[e]}){return`The value must start with ${e}`}}),Le=t({type:`string`,validator:e=>g(e)?typeof e==`string`:!0,message:`The value must be a string`});function Re(){return(()=>!0)}const ze=t({type:`uppercase`,validator(e){return f(e)?!0:v(e,k)},message:`The value is not a valid uppercase string`});export{z as alpha,B as alphaNum,x as and,u as applyIf,ne as assignIf,V as between,H as boolean,U as checked,W as contains,G as date,J as dateAfter,Y as dateBefore,X as dateBetween,Z as decimal,re as email,ie as emoji,ae as endsWith,oe as exactDigits,se as exactLength,ce as exactValue,le as file,ue as fileType,y as getSize,de as hexadecimal,fe as hostname,pe as httpUrl,me as integer,ge as ipv4Address,p as isDate,f as isEmpty,g as isFilled,_ as isNumber,_e as literal,ve as lowercase,ye as macAddress,v as matchRegex,xe as maxFileSize,Se as maxLength,Ce as maxValue,we as minFileSize,Te as minLength,Ee as minValue,$ as nativeEnum,te as not,Oe as number,ke as numeric,Ae as oneOf,S as or,je as regex,Me as required,Ne as requiredIf,Pe as requiredUnless,Fe as sameAs,Ie as startsWith,Le as string,m as toDate,b as toNumber,Re as type,ze as uppercase,Q as url,c as withAsync,o as withMessage,l as withParams,s as withTooltip};
|
|
7
|
+
import{InternalRuleType as e,createRule as t,unwrapRuleParameters as n}from"@regle/core";import{computed as r,toValue as i,unref as a}from"vue";function o(n,r){let i,a,o,s,c=!1;typeof n==`function`&&!(`_validator`in n)?(i=e.Inline,a=n):{_type:i,validator:a,_active:o,_params:s,_async:c}=n;let l=t({type:i,validator:a,active:o,message:r,async:c}),u=[...s??[]];if(l._params=u,l._message_patched=!0,typeof l==`function`){if(s!=null){let e=l(...u);return e._message_patched=!0,e}return l}else return l}function s(n,r){let i,a,o,s,c,l=!1;typeof n==`function`&&!(`_validator`in n)?(i=e.Inline,a=n):{_type:i,validator:a,_active:o,_params:s,_message:c,_async:l}=n;let u=t({type:i,validator:a,active:o,message:c,tooltip:r,async:l}),d=[...s??[]];if(u._params=d,u._tooltip_patched=!0,typeof u==`function`){let e=u(...d);return u._tooltip_patched=!0,e}else return u}function c(n,r){let i,a,o=[],s=``;typeof n==`function`?(a=async(e,...t)=>n(e,...t),o=[r]):({_type:i,_message:s}=n,o=o=n._params?.concat(r),a=async(...e)=>n.validator(e));let c=t({type:i??e.Async,validator:a,message:s,async:!0});return c._params=c._params?.concat(o),c(...r??[])}function l(n,r){let i,a,o=[],s=``;typeof n==`function`?(e.Inline,a=(e,...t)=>n(e,...t),o=[r]):({_type:i,validator:a,_message:s}=n,o=o=n._params?.concat(r));let c=t({type:e.Inline,validator:a,message:s});return c._params=c._params?.concat(o),c(...r)}function u(r,i){let a,o,s=[],c=``,l=!1;typeof i==`function`?(a=e.Inline,o=i,s=[r]):({_type:a,validator:o,_message:c,_async:l}=i,s=i._params?.concat([r]));function u(e,...t){let[i]=n([r]);return i?o(e,...t):!0}function d(){let[e]=n([r]);return e}let f=t({type:a,validator:u,active:d,message:c,async:l}),p=[...s??[]];return f._params=p,typeof f==`function`?f(...p):f}function d(e){return e?.constructor?.name==`File`}function f(e,t=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):d(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:typeof e==`object`&&e?Object.keys(e).length===0:!String(e).length}function p(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function m(e){if(f(e))return!1;let t=null;if(e instanceof Date)t=e;else if(typeof e==`string`){let n=new Date(e);if(n.toString()===`Invalid Date`)return!1;t=n}return!!t}function h(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]`||typeof e==`string`||t===`[object String]`?new Date(e):new Date(NaN)}function g(e){return e===void 0?`0 bytes`:e<1024?`${e} bytes`:e<1024*1024?`${(e/1024).toFixed(2)} kb`:e<1024*1024*1024?`${(e/1024/1024).toFixed(2)} mb`:`${(e/1024/1024/1024).toFixed(2)} gb`}function _(e,t=!0){return!f(typeof e==`string`?e.trim():e,t)}function v(e){return e==null?!1:typeof e==`number`?!isNaN(e):!1}function y(e,...t){if(f(e))return!0;let n=typeof e==`number`?e.toString():e;return t.every(e=>(e.lastIndex=0,e.test(n)))}function b(e){let t=a(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){return typeof e==`number`?e:e==null?NaN:typeof e==`string`&&e.trim()===e?+e:NaN}function S(e){return e==null?!1:typeof e==`string`}function ee(...e){let n=e.some(e=>typeof e==`function`?e.constructor.name===`AsyncFunction`:e._async),r=e.map(e=>{if(typeof e==`function`)return null;{let t=e._params;return t?.length?t:[]}}).flat().filter(e=>!!e);function i(e,t,...n){let r=[],i=0;for(let a of e)if(typeof a==`function`)r.push(a(t)),i++;else{let e=a._params?.length??0;r.push(a.validator(t,...n.slice(i,e))),e&&(i+=e)}return r}function a(e){return e?.some(e=>typeof e!=`boolean`)?{$valid:e.every(e=>typeof e==`boolean`?!!e:e.$valid),...e.reduce((e,t)=>{if(typeof t==`boolean`)return e;let{$valid:n,...r}=t;return{...e,...r}},{})}:e.every(e=>!!e)}let o;o=e.length?n?async(t,...n)=>a(await Promise.all(i(e,t,...n))):(t,...n)=>a(i(e,t,...n)):e=>!1;let s=t({type:`and`,validator:o,message:`The value does not match all of the provided validators`}),c=[...r??[]];return s._params=c,typeof s==`function`?s(...c):s}function C(...e){let n=e.some(e=>typeof e==`function`?e.constructor.name===`AsyncFunction`:e._async),r=e.map(e=>typeof e==`function`?null:e._params).flat().filter(e=>!!e);function i(e,t,...n){let r=[],i=0;for(let a of e)if(typeof a==`function`)r.push(a(t)),i++;else{let e=a._params?.length??0;r.push(a.validator(t,...n.slice(i,e))),e&&(i+=e)}return r}function a(e){return e.some(e=>typeof e!=`boolean`)?{$valid:e.some(e=>typeof e==`boolean`?!!e:e.$valid),...e.reduce((e,t)=>{if(typeof t==`boolean`)return e;let{$valid:n,...r}=t;return{...e,...r}},{})}:e.some(e=>!!e)}let o=t({type:`or`,validator:n?async(t,...n)=>a(await Promise.all(i(e,t,...n))):(t,...n)=>a(i(e,t,...n)),message:`The value does not match any of the provided validators`}),s=[...r??[]];return o._params=s,typeof o==`function`?o(...s):o}function w(e,n){let r,i,a,o,s;typeof e==`function`?(i=e,s=e.constructor.name===`AsyncFunction`):({_type:r,validator:i,_params:o}=e,s=e._async),a=s?async(e,...t)=>_(e)?!await i(e,...t):!0:(e,...t)=>_(e)?!i(e,...t):!0;let c=t({type:`not`,validator:a,message:n??`Error`}),l=[...o??[]];return c._params=l,typeof c==`function`?c(...l):c}function T(e,t,n){return Object.entries(i(t)).map(([t,r])=>typeof r==`function`||p(r)&&`_validator`in r?[t,u(n?e:()=>!i(e),r)]:[t,r])}function te(e,t,n){return r(()=>{let r=T(e,t,!0),i=n?T(e,n,!1):[];return Object.fromEntries([...r,...i])})}const ne=/^https?$/,E=/^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/,D=/^(?:(?:(?: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;function O(){return RegExp(`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`,`u`)}const k=/^[^A-Z]*$/,A=/^[^a-z]*$/,j=/^[0-9a-fA-F]*$/,M=/^[a-zA-Z]*$/,N=/^[\w.]+$/,P=/^[a-zA-Z0-9]*$/,F=/^[a-zA-Z0-9_]*$/,I=/^[-]?\d*(\.\d+)?$/,L=/^(?:[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,R=/(^[0-9]*$)|(^-[0-9]+$)/,z=/^\d*(\.\d+)?$/,B=t({type:`alpha`,validator(e,t){return f(e)?!0:t?.allowSymbols?y(e,N):y(e,M)},message:`The value is not alphabetical`}),V=t({type:`alphaNum`,validator(e,t){return f(e)?!0:t?.allowSymbols?y(e,F):y(e,P)},message:`The value must be alpha-numeric`}),H=t({type:`between`,validator:(e,t,n,r)=>{let{allowEqual:i=!0}=r??{};if(_(e)&&_(t)&&_(n)){let r=x(e),a=x(t),o=x(n);return v(r)&&v(a)&&v(o)?i?r>=a&&r<=o:r>a&&r<o:!0}return!0},message:({$params:[e,t]})=>`The value must be between ${e} and ${t}`}),U=t({type:`boolean`,validator:e=>_(e)?typeof e==`boolean`:!0,message:`The value must be a native boolean`}),W=t({type:`checked`,validator:e=>_(e)?e===!0:!0,message:`The field must be checked`}),G=t({type:`contains`,validator(e,t){return _(e)&&_(t)&&S(e)&&S(t)?e.includes(t):!0},message({$params:[e]}){return`The value must contain ${e}`}}),K=t({type:`date`,validator:e=>_(e)?e instanceof Date:!0,message:`The value must be a native Date`});function q(){return navigator.languages==null?navigator.language:navigator.languages[0]}function J(e){return e?new Intl.DateTimeFormat(q(),{dateStyle:`short`}).format(new Date(e)):`?`}const Y=t({type:`dateAfter`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return _(e)&&_(t)?m(e)&&m(t)?(r?h(e).getTime()>=h(t).getTime():h(e).getTime()>h(t).getTime())?!0:{$valid:!1,error:`date-not-after`}:{$valid:!1,error:`value-or-parameter-not-a-date`}:!0},message:({$params:[e],error:t})=>t===`value-or-parameter-not-a-date`?`The values must be dates`:`The date must be after ${J(e)}`}),X=t({type:`dateBefore`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return _(e)&&_(t)?m(e)&&m(t)?(r?h(e).getTime()<=h(t).getTime():h(e).getTime()<h(t).getTime())?!0:{$valid:!1,error:`date-not-before`}:{$valid:!1,error:`value-or-parameter-not-a-date`}:!0},message:({$params:[e],error:t})=>t===`value-or-parameter-not-a-date`?`The values must be dates`:`The date must be before ${J(e)}`}),Z=t({type:`dateBetween`,validator:(e,t,n,r)=>{let{allowEqual:i=!0}=r??{};return m(e)&&m(t)&&m(n)?i?h(e).getTime()>=h(t).getTime()&&h(e).getTime()<=h(n).getTime():h(e).getTime()>h(t).getTime()&&h(e).getTime()<h(n).getTime():!0},message:({$params:[e,t]})=>`The date must be between ${J(e)} and ${J(t)}`}),re=t({type:`decimal`,validator(e){return f(e)?!0:y(e,I)},message:`The value must be decimal`}),ie=t({type:`email`,validator(e){return f(e)?!0:y(e,L)},message:`The value must be an valid email address`}),ae=t({type:`emoji`,validator(e){return f(e)?!0:O().test(e)},message:`The value should be a valid emoji`}),oe=t({type:`endsWith`,validator(e,t){return _(e)&&_(t)&&S(e)&&S(t)?e.endsWith(t):!0},message({$params:[e]}){return`The value must end with ${e}`}}),se=t({type:`exactDigits`,validator:(e,t)=>{if(_(e,!1)&&_(t)){if(v(t)){let n=RegExp(`^\\d{${t}}$`);return y(e.toString(),n)}return!0}return!0},message:({$params:[e]})=>`The value should have exactly ${e} digits`}),ce=t({type:`exactLength`,validator:(e,t)=>_(e,!1)&&_(t)?v(t)?b(e)===t:!1:!0,message:({$params:[e]})=>`The value should be exactly ${e} characters long`}),le=t({type:`exactValue`,validator:(e,t)=>_(e)&&_(t)&&v(t)&&!isNaN(x(e))?x(e)===t:!0,message:({$params:[e]})=>`The value must be equal to ${e}`}),ue=t({type:`file`,validator:e=>_(e)?d(e):!0,message:`The value must be a native File`}),de=t({type:`fileType`,validator:(e,t)=>_(e)&&d(e)?t.includes(e.type):!0,message({$params:[e]}){return`File type is not allowed. Allowed types are: ${e.map(e=>e.split(`/`)[1]).join(`, `)}.`}}),fe=t({type:`hexadecimal`,validator(e){return f(e)?!0:y(e,j)},message:`The value must be hexadecimal`}),pe=t({type:`hostname`,validator(e){return f(e)?!0:y(e,E)},message:`The value is not a valid hostname`}),Q=t({type:`url`,validator(e,t={}){try{if(f(e))return!0;let{protocol:n}=t||{},r=new URL(e);return!E.test(r.hostname)||n&&!n.test(r.protocol.endsWith(`:`)?r.protocol.slice(0,-1):r.protocol)?!1:y(e,D)}catch{return!1}},message:`The value is not a valid URL address`}),me=t({type:`httpUrl`,validator(e,t={}){if(f(e))return!0;let{protocol:n=ne}=t||{};return Q({protocol:n}).exec(e)},message:`The value is not a valid http URL address`}),he=t({type:`integer`,validator(e){return f(e)?!0:y(e,R)},message:`The value must be an integer`});function ge(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}const _e=t({type:`ipv4Address`,validator(e){if(f(e))return!0;if(typeof e!=`string`)return!1;let t=e.split(`.`);return t.length===4&&t.every(ge)},message:`The value is not a valid IPv4 address`});function ve(e){return o(l((e,t)=>_(e)&&_(t)?t===e:!0,[r(()=>i(e))]),({$params:[e]})=>`Value should be ${e}.`)}const ye=t({type:`lowercase`,validator(e){return f(e)?!0:y(e,k)},message:`The value is not a valid lowercase string`}),be=t({type:`macAddress`,validator(e,t=`:`){if(f(e))return!0;if(typeof e!=`string`)return!1;let n=typeof t==`string`&&t!==``?e.split(t):e.length===12||e.length===16?e.match(/.{2}/g):null;return n!==null&&(n.length===6||n.length===8)&&n.every(xe)},message:`The value is not a valid MAC Address`}),xe=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/),Se=t({type:`maxFileSize`,validator:(e,t)=>_(e)&&d(e)?{$valid:e.size<=t,fileSize:e.size}:!0,message({$params:[e],fileSize:t}){return`File size (${g(t)}) cannot exceed ${g(e)}`}}),Ce=t({type:`maxLength`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return _(e,!1)&&_(t)&&v(t)?r?b(e)<=t:b(e)<t:!0},message:({$value:e,$params:[t]})=>Array.isArray(e)?`This list should have maximum ${t} items`:`The value length should not exceed ${t}`}),we=t({type:`maxValue`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return _(e)&&_(t)&&!isNaN(x(e))&&!isNaN(x(t))?r?x(e)<=x(t):x(e)<x(t):!0},message:({$params:[e,t]})=>{let{allowEqual:n=!0}=t??{};return n?`The value must be less than or equal to ${e}`:`The value must be less than ${e}`}}),Te=t({type:`minFileSize`,validator:(e,t)=>_(e)&&d(e)?{$valid:e.size>=t,fileSize:e.size}:!0,message({$params:[e],fileSize:t}){return`File size (${g(t)}) must be at least ${g(e)}`}}),Ee=t({type:`minLength`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return _(e,!1)&&_(t)&&v(t)?r?b(e)>=t:b(e)>t:!0},message:({$value:e,$params:[t]})=>Array.isArray(e)?`The list should have at least ${t} items`:`The value length should be at least ${t}`}),De=t({type:`minValue`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return _(e)&&_(t)&&!isNaN(x(e))&&!isNaN(x(t))?r?x(e)>=x(t):x(e)>x(t):!0},message:({$params:[e,t]})=>{let{allowEqual:n=!0}=t??{};return n?`The value must be greater than or equal to ${e}`:`The value must be greater than ${e}`}});function $(e){let t=Object.keys(e).filter(t=>typeof e[e[t]]!=`number`),n={};for(let r of t)n[r]=e[r];return Object.values(n)}function Oe(e){return o(l((e,t)=>_(e)&&!f(t)?$(t).includes(e):!0,[r(()=>i(e))]),({$params:[e]})=>`The value should be one of those options: ${Object.values(e).join(`, `)}.`)}const ke=t({type:`number`,validator:e=>_(e)?v(e):!0,message:`The value must be a native number`}),Ae=t({type:`numeric`,validator(e){return f(e)?!0:y(e,z)},message:`The value must be numeric`}),je=t({type:`oneOf`,validator(e,t){return _(e)&&_(t,!1)?t.includes(e):!0},message:({$params:[e]})=>`The value should be one of those options: ${e.join(`, `)}.`}),Me=t({type:`regex`,validator(e,t){return _(e)?y(e,...Array.isArray(t)?t:[t]):!0},message:`The value does not match the required pattern`}),Ne=t({type:`required`,validator:e=>_(e),message:`This field is required`}),Pe=t({type:`required`,validator(e,t){return t?_(e):!0},message:`This field is required`,active({$params:[e]}){return e}}),Fe=t({type:`required`,validator(e,t){return t?!0:_(e)},message:`This field is required`,active({$params:[e]}){return!e}}),Ie=t({type:`sameAs`,validator(e,t,n){return f(e)?!0:e===t},message({$params:[e,t=`other`]}){return`The value must be equal to the ${t} value`}}),Le=t({type:`startsWith`,validator(e,t){return _(e)&&_(t)&&S(e)&&S(t)?e.startsWith(t):!0},message({$params:[e]}){return`The value must start with ${e}`}}),Re=t({type:`string`,validator:e=>_(e)?typeof e==`string`:!0,message:`The value must be a string`});function ze(){return(()=>!0)}const Be=t({type:`uppercase`,validator(e){return f(e)?!0:y(e,A)},message:`The value is not a valid uppercase string`});export{B as alpha,V as alphaNum,ee as and,u as applyIf,te as assignIf,H as between,U as boolean,W as checked,G as contains,K as date,Y as dateAfter,X as dateBefore,Z as dateBetween,re as decimal,ie as email,ae as emoji,oe as endsWith,se as exactDigits,ce as exactLength,le as exactValue,ue as file,de as fileType,b as getSize,fe as hexadecimal,pe as hostname,me as httpUrl,he as integer,_e as ipv4Address,m as isDate,f as isEmpty,_ as isFilled,v as isNumber,ve as literal,ye as lowercase,be as macAddress,y as matchRegex,Se as maxFileSize,Ce as maxLength,we as maxValue,Te as minFileSize,Ee as minLength,De as minValue,Oe as nativeEnum,w as not,ke as number,Ae as numeric,je as oneOf,C as or,Me as regex,Ne as required,Pe as requiredIf,Fe as requiredUnless,Ie as sameAs,Le as startsWith,Re as string,h as toDate,x as toNumber,ze as type,Be as uppercase,Q as url,c as withAsync,o as withMessage,l as withParams,s as withTooltip};
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regle/rules",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.0",
|
|
4
4
|
"description": "Collection of rules and helpers for Regle",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"type-fest": "5.3.1",
|
|
7
|
-
"@regle/core": "1.
|
|
7
|
+
"@regle/core": "1.17.0"
|
|
8
8
|
},
|
|
9
9
|
"devDependencies": {
|
|
10
10
|
"@types/node": "22.19.3",
|