@regle/rules 1.20.0-preview.2 → 1.20.0-preview.4

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @regle/rules v1.20.0-preview.2
2
+ * @regle/rules v1.20.0-preview.4
3
3
  * (c) 2026 Victor Garcia
4
4
  * @license MIT
5
5
  */
@@ -857,6 +857,21 @@ declare const dateBetween: RegleRuleWithParamsDefinition<'dateBetween', string |
857
857
  * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#decimal Documentation}
858
858
  */
859
859
  declare const decimal: RegleRuleDefinition<'decimal', string | number, [], false, boolean, MaybeInput<number | undefined>>;
860
+ /**
861
+ * Validates domain names.
862
+ *
863
+ * @example
864
+ * ```ts
865
+ * import { domain } from '@regle/rules';
866
+ *
867
+ * const { r$ } = useRegle({ siteDomain: '' }, {
868
+ * siteDomain: { domain },
869
+ * })
870
+ * ```
871
+ *
872
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#domain Documentation}
873
+ */
874
+ declare const domain: RegleRuleDefinition<'domain', string, [], false, boolean, unknown, string>;
860
875
  /**
861
876
  * Validates email addresses. Always verify on the server to ensure the address is real and not already in use.
862
877
  *
@@ -1603,4 +1618,4 @@ declare function type<T>(): RegleRuleDefinition<'type', unknown, [], false, bool
1603
1618
  * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#uppercase Documentation}
1604
1619
  */
1605
1620
  declare const uppercase: RegleRuleDefinition<'uppercase', string, [], false, boolean, unknown, string>;
1606
- export { alpha, alphaNum, and, applyIf, assignIf, atLeastOne, between, boolean, checked, contains, containsSpecialCharacter, containsUppercase, date, dateAfter, dateBefore, dateBetween, decimal, email, emoji, endsWith, exactDigits, exactLength, exactValue, file, fileType, getSize, hexadecimal, hostname, httpUrl, integer, ipv4Address, isDate, isEmpty, isFilled, isNumber, literal, lowercase, macAddress, matchRegex, maxFileSize, maxLength, maxValue, minFileSize, minLength, minValue, nativeEnum, not, number, numeric, oneOf, or, pipe, regex, required, requiredIf, requiredUnless, sameAs, startsWith, string, toDate, toNumber, type, uppercase, url, withAsync, withMessage, withParams, withTooltip, xor };
1621
+ export { alpha, alphaNum, and, applyIf, assignIf, atLeastOne, between, boolean, checked, contains, containsSpecialCharacter, containsUppercase, date, dateAfter, dateBefore, dateBetween, decimal, domain, email, emoji, endsWith, exactDigits, exactLength, exactValue, file, fileType, getSize, hexadecimal, hostname, httpUrl, integer, ipv4Address, isDate, isEmpty, isFilled, isNumber, literal, lowercase, macAddress, matchRegex, maxFileSize, maxLength, maxValue, minFileSize, minLength, minValue, nativeEnum, not, number, numeric, oneOf, or, pipe, regex, required, requiredIf, requiredUnless, sameAs, startsWith, string, toDate, toNumber, type, uppercase, url, withAsync, withMessage, withParams, withTooltip, xor };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @regle/rules v1.20.0-preview.2
2
+ * @regle/rules v1.20.0-preview.4
3
3
  * (c) 2026 Victor Garcia
4
4
  * @license MIT
5
5
  */
@@ -863,6 +863,8 @@ const HOSTNAME_REGEX = /^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z
863
863
  * Regex taken from {@link https://gist.github.com/dperini/729294}
864
864
  */
865
865
  const URL_REGEX = /^(?:(?:(?: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;
866
+ /** Regex for validating url domains */
867
+ const DOMAIN_REGEX = /^([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/;
866
868
  /** Regex for validating emoji */
867
869
  const _EMOJI_REGEX = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
868
870
  function EMOJI_REGEX() {
@@ -1430,6 +1432,29 @@ const decimal = createRule({
1430
1432
  message: "The value must be decimal"
1431
1433
  });
1432
1434
 
1435
+ /**
1436
+ * Validates domain names.
1437
+ *
1438
+ * @example
1439
+ * ```ts
1440
+ * import { domain } from '@regle/rules';
1441
+ *
1442
+ * const { r$ } = useRegle({ siteDomain: '' }, {
1443
+ * siteDomain: { domain },
1444
+ * })
1445
+ * ```
1446
+ *
1447
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#domain Documentation}
1448
+ */
1449
+ const domain = createRule({
1450
+ type: "domain",
1451
+ validator(value) {
1452
+ if (isEmpty(value)) return true;
1453
+ return matchRegex(value, DOMAIN_REGEX);
1454
+ },
1455
+ message: "The value is not a valid domain"
1456
+ });
1457
+
1433
1458
  /**
1434
1459
  * Validates email addresses. Always verify on the server to ensure the address is real and not already in use.
1435
1460
  *
@@ -2518,4 +2543,4 @@ const uppercase = createRule({
2518
2543
  message: "The value must be uppercase"
2519
2544
  });
2520
2545
 
2521
- export { alpha, alphaNum, and, applyIf, assignIf, atLeastOne, between, boolean, checked, contains, containsSpecialCharacter, containsUppercase, date, dateAfter, dateBefore, dateBetween, decimal, email, emoji, endsWith, exactDigits, exactLength, exactValue, file, fileType, getSize, hexadecimal, hostname, httpUrl, integer, ipv4Address, isDate, isEmpty, isFilled, isNumber, literal, lowercase, macAddress, matchRegex, maxFileSize, maxLength, maxValue, minFileSize, minLength, minValue, nativeEnum, not, number, numeric, oneOf, or, pipe, regex, required, requiredIf, requiredUnless, sameAs, startsWith, string, toDate, toNumber, type, uppercase, url, withAsync, withMessage, withParams, withTooltip, xor };
2546
+ export { alpha, alphaNum, and, applyIf, assignIf, atLeastOne, between, boolean, checked, contains, containsSpecialCharacter, containsUppercase, date, dateAfter, dateBefore, dateBetween, decimal, domain, email, emoji, endsWith, exactDigits, exactLength, exactValue, file, fileType, getSize, hexadecimal, hostname, httpUrl, integer, ipv4Address, isDate, isEmpty, isFilled, isNumber, literal, lowercase, macAddress, matchRegex, maxFileSize, maxLength, maxValue, minFileSize, minLength, minValue, nativeEnum, not, number, numeric, oneOf, or, pipe, regex, required, requiredIf, requiredUnless, sameAs, startsWith, string, toDate, toNumber, type, uppercase, url, withAsync, withMessage, withParams, withTooltip, xor };
@@ -1,7 +1,7 @@
1
1
  /**
2
- * @regle/rules v1.20.0-preview.2
2
+ * @regle/rules v1.20.0-preview.4
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{capitalize as r,computed as i,effectScope as a,onScopeDispose as o,ref as s,toValue as c}from"vue";function l(e){return e?.constructor?.name==`File`}function u(e,t=!0,n=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):l(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:d(e)?e==null?!0:n?Object.keys(e).length===0:!1:!String(e).length}function d(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function f(e){return(d(e)||typeof e==`function`)&&`_validator`in e}function p(t){let n,r,i=[],a=``,o=!1,s;if(typeof t==`function`&&!(`_validator`in t))n=e.Inline,r=t,o=t.constructor.name===`AsyncFunction`;else if(f(t))({_type:n,validator:r,_message:a,_async:o,_params:i,_active:s}=t);else throw Error(`Cannot extract validator from invalid rule`);return{_type:n,validator:r,_params:i,_message:a,_async:o,_active:s}}function m(e,n){let{_type:r,validator:i,_active:a,_params:o,_async:s}=p(e),c=t({type:r,validator:i,active:a,message:n,async:s}),l=o??[];if(c._params=l,c._message_patched=!0,typeof c==`function`){if(o!=null){let e=c(...l);return e._message_patched=!0,e}return c}else return c}function h(e,n){let{_type:r,validator:i,_active:a,_params:o,_message:s,_async:c}=p(e),l=t({type:r,validator:i,active:a,message:s,tooltip:n,async:c}),u=o??[];if(l._params=u,l._tooltip_patched=!0,typeof l==`function`){let e=l(...u);return l._tooltip_patched=!0,e}else return l}function g(n,r){let i,{_type:a,_params:o,_message:s,_active:c}=p(n);i=typeof n==`function`?async(e,...t)=>n(e,...t):async(...e)=>n.validator(e);let l=(o??[])?.concat(r),u=t({type:a??e.Async,validator:i,message:s,async:!0,active:c});return u._params=l,u(...r??[])}function _(n,r){let i,{_type:a,_params:o,_message:s,_active:c,_async:l}=p(n);i=typeof n==`function`?(e,...t)=>n(e,...t):n.validator;let u=(o??[])?.concat(r),d=t({type:a??e.Inline,validator:i,message:s,active:c,async:l});return d._params=u,d(...r)}function v(e,r,i){let{_type:a,validator:o,_params:s,_message:c,_async:l,_active:u}=p(r),d=(s??[]).concat(i?.hideParams?[]:[e]);function f(t,...r){let[i]=n([e]);return i?o(t,...r):!0}function m(t){let[r]=n([e]);return r?typeof u==`function`?u(t):u??!0:!1}let h=t({type:a,validator:f,active:m,message:c,async:l});return h._params=d,typeof h==`function`?h(...d):h}function y(e){if(u(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 b(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 x(e,t,{immediate:n=!1,trackDebounceRef:r}={}){let i,a=(...a)=>{r&&(r.value=!0);function o(){r&&(r.value=!1)}return new Promise((r,s)=>{function c(e){r(e),o()}if(clearTimeout(i),i=setTimeout(()=>{if(o(),i=void 0,!n)try{Promise.resolve(e.apply(this,[...a])).then(c).catch(e=>s(e)).finally(o)}catch(e){s(e)}},t),n){o();try{Promise.resolve(e.apply(this,[...a])).then(c).catch(e=>s(e)).finally(o)}catch(e){s(e)}}})};return a.cancel=()=>{clearTimeout(i),i=void 0,r&&(r.value=!1)},a}function S(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 C(e,t=!0,n=!0){return!u(typeof e==`string`?e.trim():e,t,n)}function w(e){return e==null?!1:typeof e==`number`?!isNaN(e):!1}function T(e,...t){if(u(e))return!0;let n=typeof e==`number`?e.toString():e;return t.every(e=>(e.lastIndex=0,e.test(n)))}function E(e){let t=c(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 D(e){return typeof e==`number`?e:e==null?NaN:typeof e==`string`&&e.trim()===e?+e:NaN}function O(e){return e==null?!1:typeof e==`string`}function ee(e){return e.some(e=>typeof e==`function`?e.constructor.name===`AsyncFunction`:e._async)}function k(e){return e.map(e=>{if(typeof e==`function`)return null;{let t=e._params;return t?.length?t:[]}}).flat().filter(e=>!!e)}function A(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,i+e))),e&&(i+=e)}return r}function j(e,t,n){let r=e=>typeof e==`boolean`?!!e:e.$valid;return n===`xor`?t.length>1?t.filter(r).length===1:t.every(r):t[n===`and`?`every`:`some`](r)}function M(e,t,n){return t.some(e=>typeof e!=`boolean`)?{$valid:j(e,t,n),...t.reduce((e,t)=>{if(typeof t==`boolean`)return e;let{$valid:n,...r}=t;return{...e,...r}},{})}:j(e,t,n)}function N(e,n){let{mode:r,message:i}=n,a=ee(e),o=k(e),s;s=e.length?a?async(t,...n)=>M(t,await Promise.all(A(e,t,...n)),r):(t,...n)=>M(t,A(e,t,...n),r):e=>!1;let c=t({type:r,validator:s,message:i}),l=[...o??[]];return c._params=l,typeof c==`function`?c(...l):c}function te(...e){return N(e,{mode:`and`,message:`The value does not match all of the provided validators`})}function ne(...e){return N(e,{mode:`or`,message:`The value does not match any of the provided validators`})}function re(...e){return N(e,{mode:`xor`,message:`The value does not match exactly one of the provided validators`})}function ie(e,n){let i,{_type:a,validator:o,_params:s,_async:c,_active:l}=p(e);i=c?async(e,...t)=>{if(C(e))try{return!await o(e,...t)}catch{return!0}return!0}:(e,...t)=>C(e)?!o(e,...t):!0;let u=t({type:a?`not(${r(a)})`:void 0,validator:i,message:n??`Error`,active:l,async:c}),d=[...s??[]];return u._params=d,typeof u==`function`?u(...d):u}function P(e,t,n){return Object.entries(c(t)).map(([t,r])=>typeof r==`function`||d(r)&&`_validator`in r?[t,v(n?e:()=>!c(e),r)]:[t,r])}function ae(e,t,n){let r=P(e,t,!0),i=n?P(e,n,!1):[];return Object.fromEntries([...r,...i])}function oe(e,t,n){return e.run(()=>i(()=>n===0?!0:Array.from(t.value.entries()).slice(0,n).every(([,e])=>e===!0)))}function se({validator:e,index:t,isAsync:n,mappedResults:r,options:i}){return n?x(async(n,...i)=>{r.value.set(t,!1);let a=await e(n,...i),o=typeof a==`boolean`?a:a?.$valid??!1;return r.value.set(t,o),a},i?.debounce??200):(n,...i)=>{r.value.set(t,!1);let a=e(n,...i);if(a instanceof Promise)return!1;let o=typeof a==`boolean`?a:a?.$valid??!1;return r.value.set(t,o),a}}function F(...n){let r=[],i=s(new Map),c=[],l=n[0],u=Array.isArray(l)?l:n,f=Array.isArray(l)&&d(n[1])?n[1]:void 0;for(let[e,n]of u.entries()){let o=a();c.push(o);let{_type:s,validator:l,_params:u,_message:d,_async:m,_active:h}=p(n),g=t({type:s,validator:se({validator:l,mappedResults:i,index:e,isAsync:m,options:f}),active:h,async:m,message:d});g._params=u;let _;_=typeof g==`function`?g(...u??[]):g;let y=oe(o,i,e),b=e>0&&r[e-1]._async,x=v(y,_,{hideParams:!b});r.push(x)}return o(()=>{c.forEach(e=>e.stop()),c=[]}),{...Object.fromEntries(r.map((t,n)=>[t.type&&t.type!==e.Inline?t.type:`anonymous${n}`,t])),$debounce:0}}const I=/^https?$/,L=/^(?=.{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])?)*\.?$/,R=/^(?:(?:(?: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 z(){return RegExp(`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`,`u`)}const B=/^[^A-Z]*$/,V=/^[^a-z]*$/,H=/^[0-9a-fA-F]*$/,U=/^[a-zA-Z]*$/,W=/^[\w.]+$/,G=/^[a-zA-Z0-9]*$/,K=/^[a-zA-Z0-9_]*$/,ce=/^[-]?\d*(\.\d+)?$/,le=/^(?:[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,ue=/(^[0-9]*$)|(^-[0-9]+$)/,de=/^\d*(\.\d+)?$/,fe=t({type:`alpha`,validator(e,t){return u(e)?!0:t?.allowSymbols?T(e,W):T(e,U)},message:`The value must be alphabetical`}),pe=t({type:`alphaNum`,validator(e,t){return u(e)?!0:t?.allowSymbols?T(e,K):T(e,G)},message:`The value must be alpha-numeric`}),me=t({type:`atLeastOne`,validator:(e,t)=>C(e,!0,!1)&&d(e)?t?.length?t.some(t=>C(e[t])):E(e)>0:!0,message:`At least one item is required`}),he=t({type:`between`,validator:(e,t,n,r)=>{let{allowEqual:i=!0}=r??{};if(C(e)&&C(t)&&C(n)){let r=D(e),a=D(t),o=D(n);return w(r)&&w(a)&&w(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}`}),ge=t({type:`boolean`,validator:e=>C(e)?typeof e==`boolean`:!0,message:`The value must be a native boolean`}),_e=t({type:`checked`,validator:e=>e===!0,message:`The field must be checked`,required:!0});function q({type:e,operation:n}){let r=(e,t)=>{switch(n){case`contains`:return e.includes(t);case`startsWith`:return e.startsWith(t);case`endsWith`:return e.endsWith(t)}},i=e=>{switch(n){case`contains`:return`The value must contain ${e}`;case`startsWith`:return`The value must start with ${e}`;case`endsWith`:return`The value must end with ${e}`}};return t({type:e,validator(e,t){return C(e)&&C(t)&&O(e)&&O(t)?r(e,t):!0},message({$params:[e]}){return i(e)}})}const ve=q({type:`contains`,operation:`contains`}),J=t({type:`regex`,validator(e,t){return C(e)?T(e,...Array.isArray(t)?t:[t]):!0},message:`The value must match the required pattern`}),ye=t({type:`containsSpecialCharacter`,validator(e,t=1){let n=Number.isFinite(t)?Math.max(1,Math.floor(t)):1;return C(e)?{$valid:J(RegExp(`^(?:.*[!@~\`#£€\$%^&*()_+\\-=[\\]{};':"\\\\|,.<>/?]){${n},}.*$`)).exec(e),minCharactersCount:n}:{$valid:!0,minCharactersCount:n}},message({minCharactersCount:e}){return`This field must contain at least ${e} special character${e>1?`s`:``}`}}),be=t({type:`containsUppercase`,validator(e,t=1){let n=Number.isFinite(t)?Math.max(1,Math.floor(t)):1;return C(e)?{$valid:J(RegExp(`^(?:.*[A-Z]){${n},}.*$`)).exec(e),minUppercaseCount:n}:{$valid:!0,minUppercaseCount:n}},message:({minUppercaseCount:e})=>`This field must contain at least ${e} uppercase letter${e>1?`s`:``}`}),xe=t({type:`date`,validator:e=>C(e)?e instanceof Date:!0,message:`The value must be a native Date`});function Se(){return navigator.languages==null?navigator.language??`en-US`:navigator.languages[0]}function Y(e){return e?new Intl.DateTimeFormat(Se(),{dateStyle:`short`}).format(new Date(e)):`?`}const Ce=t({type:`dateAfter`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return C(e)&&C(t)?y(e)&&y(t)?(r?b(e).getTime()>=b(t).getTime():b(e).getTime()>b(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 ${Y(e)}`}),we=t({type:`dateBefore`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return C(e)&&C(t)?y(e)&&y(t)?(r?b(e).getTime()<=b(t).getTime():b(e).getTime()<b(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 ${Y(e)}`}),Te=t({type:`dateBetween`,validator:(e,t,n,r)=>{let{allowEqual:i=!0}=r??{};return y(e)&&y(t)&&y(n)?i?b(e).getTime()>=b(t).getTime()&&b(e).getTime()<=b(n).getTime():b(e).getTime()>b(t).getTime()&&b(e).getTime()<b(n).getTime():!0},message:({$params:[e,t]})=>`The date must be between ${Y(e)} and ${Y(t)}`}),Ee=t({type:`decimal`,validator(e){return u(e)?!0:T(e,ce)},message:`The value must be decimal`}),De=t({type:`email`,validator(e){return u(e)?!0:T(e,le)},message:`The value must be a valid email address`}),Oe=t({type:`emoji`,validator(e){return u(e)?!0:z().test(e)},message:`The value should be a valid emoji`}),ke=q({type:`endsWith`,operation:`endsWith`}),Ae=t({type:`exactDigits`,validator:(e,t)=>{if(C(e,!1)&&C(t)){if(w(t)){let n=RegExp(`^\\d{${t}}$`);return T(e.toString(),n)}return!0}return!0},message:({$params:[e]})=>`The value should have exactly ${e} digits`}),je=t({type:`exactLength`,validator:(e,t)=>C(e,!1)&&C(t)?w(t)?E(e)===t:!1:!0,message:({$params:[e]})=>`The value must be exactly ${e} characters long`}),Me=t({type:`exactValue`,validator:(e,t)=>C(e)&&C(t)&&w(t)&&!isNaN(D(e))?D(e)===t:!0,message:({$params:[e]})=>`The value must be equal to ${e}`}),Ne=t({type:`file`,validator:e=>C(e)?l(e):!0,message:`The value must be a native File`}),Pe=t({type:`fileType`,validator:(e,t)=>C(e)&&l(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 u(e)?!0:T(e,H)},message:`The value must be hexadecimal`}),Ie=t({type:`hostname`,validator(e){return u(e)?!0:T(e,L)},message:`The value is not a valid hostname`}),X=t({type:`url`,validator(e,t={}){try{if(u(e))return!0;let{protocol:n}=t||{},r=new URL(e);return!L.test(r.hostname)||n&&!n.test(r.protocol.endsWith(`:`)?r.protocol.slice(0,-1):r.protocol)?!1:T(e,R)}catch{return!1}},message:`The value must be a valid URL`}),Le=t({type:`httpUrl`,validator(e,t={}){if(u(e))return!0;let{protocol:n=I}=t||{};return X({protocol:n}).exec(e)},message:`The value is not a valid http URL address`}),Re=t({type:`integer`,validator(e){return u(e)?!0:T(e,ue)},message:`The value must be an integer`});function ze(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 Be=t({type:`ipv4Address`,validator(e){if(u(e))return!0;if(typeof e!=`string`)return!1;let t=e.split(`.`);return t.length===4&&t.every(ze)},message:`The value is not a valid IPv4 address`});function Ve(e){return m(_((e,t)=>C(e)&&C(t)?t===e:!0,[i(()=>c(e))]),({$params:[e]})=>`Value should be ${e}.`)}const He=t({type:`lowercase`,validator(e){return u(e)?!0:T(e,B)},message:`The value must be lowercase`}),Ue=t({type:`macAddress`,validator(e,t=`:`){if(u(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(We)},message:`The value is not a valid MAC Address`}),We=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/),Ge=t({type:`maxFileSize`,validator:(e,t)=>C(e)&&l(e)?{$valid:e.size<=t,fileSize:e.size}:!0,message({$params:[e],fileSize:t}){return`File size (${S(t)}) cannot exceed ${S(e)}`}});function Z({type:e,direction:n}){let r=(e,t,r)=>n===`min`?r?e>=t:e>t:r?e<=t:e<t,i=(e,t)=>Array.isArray(e)?n===`min`?`The list must have at least ${t} items`:`The list must have at most ${t} items`:n===`min`?`The value must be at least ${t} characters long`:`The value must be at most ${t} characters long`;return t({type:e,validator:(e,t,n)=>{let{allowEqual:i=!0}=n??{};return C(e,!1)&&C(t)&&w(t)?r(E(e),t,i):!0},message:({$value:e,$params:[t]})=>i(e,t)})}const Ke=Z({type:`maxLength`,direction:`max`});function Q({type:e,direction:n}){let r=(e,t,r)=>n===`min`?r?e>=t:e>t:r?e<=t:e<t,i=(e,t)=>n===`min`?t?`The value must be greater than or equal to ${e}`:`The value must be greater than ${e}`:t?`The value must be less than or equal to ${e}`:`The value must be less than ${e}`;return t({type:e,validator:(e,t,n)=>{let{allowEqual:i=!0}=n??{};return C(e)&&C(t)&&!isNaN(D(e))&&!isNaN(D(t))?r(D(e),D(t),i):!0},message:({$params:[e,t]})=>{let{allowEqual:n=!0}=t??{};return i(e,n)}})}const qe=Q({type:`maxValue`,direction:`max`}),Je=t({type:`minFileSize`,validator:(e,t)=>C(e)&&l(e)?{$valid:e.size>=t,fileSize:e.size}:!0,message({$params:[e],fileSize:t}){return`File size (${S(t)}) must be at least ${S(e)}`}}),$=Z({type:`minLength`,direction:`min`}),Ye=Q({type:`minValue`,direction:`min`});function Xe(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 Ze(e){return m(_((e,t)=>C(e)&&!u(t)?Xe(t).includes(e):!0,[i(()=>c(e))]),({$params:[e]})=>`The value must be one of the following: ${Object.values(e).join(`, `)}`)}const Qe=t({type:`number`,validator:e=>C(e)?w(e):!0,message:`The value must be a native number`}),$e=t({type:`numeric`,validator(e){return u(e)?!0:T(e,de)},message:`The value must be numeric`}),et=t({type:`oneOf`,validator(e,t){return C(e)&&C(t,!1)?Array.isArray(t)?t.includes(e):Object.values(t).includes(e):!0},message:({$params:[e]})=>`The value must be one of the following: ${(Array.isArray(e)?e:Object.values(e)).join(`, `)}`}),tt=t({type:`required`,validator:e=>C(e,!0,!1),message:`This field is required`,required:!0}),nt=t({type:`required`,validator(e,t){return t?C(e):!0},message:`This field is required`,active({$params:[e]}){return e}}),rt=t({type:`required`,validator(e,t){return t?!0:C(e)},message:`This field is required`,active({$params:[e]}){return!e}}),it=t({type:`sameAs`,validator(e,t,n){return u(e)?!0:e===t},message({$params:[e,t=`other`]}){return`The value must be equal to the ${t} value`}}),at=q({type:`startsWith`,operation:`startsWith`}),ot=t({type:`string`,validator:e=>C(e)?typeof e==`string`:!0,message:`The value must be a string`});function st(){return(()=>!0)}const ct=t({type:`uppercase`,validator(e){return u(e)?!0:T(e,V)},message:`The value must be uppercase`});export{fe as alpha,pe as alphaNum,te as and,v as applyIf,ae as assignIf,me as atLeastOne,he as between,ge as boolean,_e as checked,ve as contains,ye as containsSpecialCharacter,be as containsUppercase,xe as date,Ce as dateAfter,we as dateBefore,Te as dateBetween,Ee as decimal,De as email,Oe as emoji,ke as endsWith,Ae as exactDigits,je as exactLength,Me as exactValue,Ne as file,Pe as fileType,E as getSize,Fe as hexadecimal,Ie as hostname,Le as httpUrl,Re as integer,Be as ipv4Address,y as isDate,u as isEmpty,C as isFilled,w as isNumber,Ve as literal,He as lowercase,Ue as macAddress,T as matchRegex,Ge as maxFileSize,Ke as maxLength,qe as maxValue,Je as minFileSize,$ as minLength,Ye as minValue,Ze as nativeEnum,ie as not,Qe as number,$e as numeric,et as oneOf,ne as or,F as pipe,J as regex,tt as required,nt as requiredIf,rt as requiredUnless,it as sameAs,at as startsWith,ot as string,b as toDate,D as toNumber,st as type,ct as uppercase,X as url,g as withAsync,m as withMessage,_ as withParams,h as withTooltip,re as xor};
7
+ import{InternalRuleType as e,createRule as t,unwrapRuleParameters as n}from"@regle/core";import{capitalize as r,computed as i,effectScope as a,onScopeDispose as o,ref as s,toValue as c}from"vue";function l(e){return e?.constructor?.name==`File`}function u(e,t=!0,n=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):l(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:d(e)?e==null?!0:n?Object.keys(e).length===0:!1:!String(e).length}function d(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function f(e){return(d(e)||typeof e==`function`)&&`_validator`in e}function p(t){let n,r,i=[],a=``,o=!1,s;if(typeof t==`function`&&!(`_validator`in t))n=e.Inline,r=t,o=t.constructor.name===`AsyncFunction`;else if(f(t))({_type:n,validator:r,_message:a,_async:o,_params:i,_active:s}=t);else throw Error(`Cannot extract validator from invalid rule`);return{_type:n,validator:r,_params:i,_message:a,_async:o,_active:s}}function m(e,n){let{_type:r,validator:i,_active:a,_params:o,_async:s}=p(e),c=t({type:r,validator:i,active:a,message:n,async:s}),l=o??[];if(c._params=l,c._message_patched=!0,typeof c==`function`){if(o!=null){let e=c(...l);return e._message_patched=!0,e}return c}else return c}function h(e,n){let{_type:r,validator:i,_active:a,_params:o,_message:s,_async:c}=p(e),l=t({type:r,validator:i,active:a,message:s,tooltip:n,async:c}),u=o??[];if(l._params=u,l._tooltip_patched=!0,typeof l==`function`){let e=l(...u);return l._tooltip_patched=!0,e}else return l}function g(n,r){let i,{_type:a,_params:o,_message:s,_active:c}=p(n);i=typeof n==`function`?async(e,...t)=>n(e,...t):async(...e)=>n.validator(e);let l=(o??[])?.concat(r),u=t({type:a??e.Async,validator:i,message:s,async:!0,active:c});return u._params=l,u(...r??[])}function _(n,r){let i,{_type:a,_params:o,_message:s,_active:c,_async:l}=p(n);i=typeof n==`function`?(e,...t)=>n(e,...t):n.validator;let u=(o??[])?.concat(r),d=t({type:a??e.Inline,validator:i,message:s,active:c,async:l});return d._params=u,d(...r)}function v(e,r,i){let{_type:a,validator:o,_params:s,_message:c,_async:l,_active:u}=p(r),d=(s??[]).concat(i?.hideParams?[]:[e]);function f(t,...r){let[i]=n([e]);return i?o(t,...r):!0}function m(t){let[r]=n([e]);return r?typeof u==`function`?u(t):u??!0:!1}let h=t({type:a,validator:f,active:m,message:c,async:l});return h._params=d,typeof h==`function`?h(...d):h}function y(e){if(u(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 b(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 x(e,t,{immediate:n=!1,trackDebounceRef:r}={}){let i,a=(...a)=>{r&&(r.value=!0);function o(){r&&(r.value=!1)}return new Promise((r,s)=>{function c(e){r(e),o()}if(clearTimeout(i),i=setTimeout(()=>{if(o(),i=void 0,!n)try{Promise.resolve(e.apply(this,[...a])).then(c).catch(e=>s(e)).finally(o)}catch(e){s(e)}},t),n){o();try{Promise.resolve(e.apply(this,[...a])).then(c).catch(e=>s(e)).finally(o)}catch(e){s(e)}}})};return a.cancel=()=>{clearTimeout(i),i=void 0,r&&(r.value=!1)},a}function S(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 C(e,t=!0,n=!0){return!u(typeof e==`string`?e.trim():e,t,n)}function w(e){return e==null?!1:typeof e==`number`?!isNaN(e):!1}function T(e,...t){if(u(e))return!0;let n=typeof e==`number`?e.toString():e;return t.every(e=>(e.lastIndex=0,e.test(n)))}function E(e){let t=c(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 D(e){return typeof e==`number`?e:e==null?NaN:typeof e==`string`&&e.trim()===e?+e:NaN}function O(e){return e==null?!1:typeof e==`string`}function ee(e){return e.some(e=>typeof e==`function`?e.constructor.name===`AsyncFunction`:e._async)}function k(e){return e.map(e=>{if(typeof e==`function`)return null;{let t=e._params;return t?.length?t:[]}}).flat().filter(e=>!!e)}function A(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,i+e))),e&&(i+=e)}return r}function j(e,t,n){let r=e=>typeof e==`boolean`?!!e:e.$valid;return n===`xor`?t.length>1?t.filter(r).length===1:t.every(r):t[n===`and`?`every`:`some`](r)}function M(e,t,n){return t.some(e=>typeof e!=`boolean`)?{$valid:j(e,t,n),...t.reduce((e,t)=>{if(typeof t==`boolean`)return e;let{$valid:n,...r}=t;return{...e,...r}},{})}:j(e,t,n)}function N(e,n){let{mode:r,message:i}=n,a=ee(e),o=k(e),s;s=e.length?a?async(t,...n)=>M(t,await Promise.all(A(e,t,...n)),r):(t,...n)=>M(t,A(e,t,...n),r):e=>!1;let c=t({type:r,validator:s,message:i}),l=[...o??[]];return c._params=l,typeof c==`function`?c(...l):c}function te(...e){return N(e,{mode:`and`,message:`The value does not match all of the provided validators`})}function ne(...e){return N(e,{mode:`or`,message:`The value does not match any of the provided validators`})}function re(...e){return N(e,{mode:`xor`,message:`The value does not match exactly one of the provided validators`})}function ie(e,n){let i,{_type:a,validator:o,_params:s,_async:c,_active:l}=p(e);i=c?async(e,...t)=>{if(C(e))try{return!await o(e,...t)}catch{return!0}return!0}:(e,...t)=>C(e)?!o(e,...t):!0;let u=t({type:a?`not(${r(a)})`:void 0,validator:i,message:n??`Error`,active:l,async:c}),d=[...s??[]];return u._params=d,typeof u==`function`?u(...d):u}function P(e,t,n){return Object.entries(c(t)).map(([t,r])=>typeof r==`function`||d(r)&&`_validator`in r?[t,v(n?e:()=>!c(e),r)]:[t,r])}function ae(e,t,n){let r=P(e,t,!0),i=n?P(e,n,!1):[];return Object.fromEntries([...r,...i])}function oe(e,t,n){return e.run(()=>i(()=>n===0?!0:Array.from(t.value.entries()).slice(0,n).every(([,e])=>e===!0)))}function se({validator:e,index:t,isAsync:n,mappedResults:r,options:i}){return n?x(async(n,...i)=>{r.value.set(t,!1);let a=await e(n,...i),o=typeof a==`boolean`?a:a?.$valid??!1;return r.value.set(t,o),a},i?.debounce??200):(n,...i)=>{r.value.set(t,!1);let a=e(n,...i);if(a instanceof Promise)return!1;let o=typeof a==`boolean`?a:a?.$valid??!1;return r.value.set(t,o),a}}function F(...n){let r=[],i=s(new Map),c=[],l=n[0],u=Array.isArray(l)?l:n,f=Array.isArray(l)&&d(n[1])?n[1]:void 0;for(let[e,n]of u.entries()){let o=a();c.push(o);let{_type:s,validator:l,_params:u,_message:d,_async:m,_active:h}=p(n),g=t({type:s,validator:se({validator:l,mappedResults:i,index:e,isAsync:m,options:f}),active:h,async:m,message:d});g._params=u;let _;_=typeof g==`function`?g(...u??[]):g;let y=oe(o,i,e),b=e>0&&r[e-1]._async,x=v(y,_,{hideParams:!b});r.push(x)}return o(()=>{c.forEach(e=>e.stop()),c=[]}),{...Object.fromEntries(r.map((t,n)=>[t.type&&t.type!==e.Inline?t.type:`anonymous${n}`,t])),$debounce:0}}const I=/^https?$/,L=/^(?=.{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])?)*\.?$/,R=/^(?:(?:(?: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,z=/^([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/;function B(){return RegExp(`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`,`u`)}const V=/^[^A-Z]*$/,H=/^[^a-z]*$/,U=/^[0-9a-fA-F]*$/,W=/^[a-zA-Z]*$/,G=/^[\w.]+$/,K=/^[a-zA-Z0-9]*$/,ce=/^[a-zA-Z0-9_]*$/,le=/^[-]?\d*(\.\d+)?$/,ue=/^(?:[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,de=/(^[0-9]*$)|(^-[0-9]+$)/,fe=/^\d*(\.\d+)?$/,pe=t({type:`alpha`,validator(e,t){return u(e)?!0:t?.allowSymbols?T(e,G):T(e,W)},message:`The value must be alphabetical`}),me=t({type:`alphaNum`,validator(e,t){return u(e)?!0:t?.allowSymbols?T(e,ce):T(e,K)},message:`The value must be alpha-numeric`}),he=t({type:`atLeastOne`,validator:(e,t)=>C(e,!0,!1)&&d(e)?t?.length?t.some(t=>C(e[t])):E(e)>0:!0,message:`At least one item is required`}),ge=t({type:`between`,validator:(e,t,n,r)=>{let{allowEqual:i=!0}=r??{};if(C(e)&&C(t)&&C(n)){let r=D(e),a=D(t),o=D(n);return w(r)&&w(a)&&w(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}`}),_e=t({type:`boolean`,validator:e=>C(e)?typeof e==`boolean`:!0,message:`The value must be a native boolean`}),ve=t({type:`checked`,validator:e=>e===!0,message:`The field must be checked`,required:!0});function q({type:e,operation:n}){let r=(e,t)=>{switch(n){case`contains`:return e.includes(t);case`startsWith`:return e.startsWith(t);case`endsWith`:return e.endsWith(t)}},i=e=>{switch(n){case`contains`:return`The value must contain ${e}`;case`startsWith`:return`The value must start with ${e}`;case`endsWith`:return`The value must end with ${e}`}};return t({type:e,validator(e,t){return C(e)&&C(t)&&O(e)&&O(t)?r(e,t):!0},message({$params:[e]}){return i(e)}})}const ye=q({type:`contains`,operation:`contains`}),J=t({type:`regex`,validator(e,t){return C(e)?T(e,...Array.isArray(t)?t:[t]):!0},message:`The value must match the required pattern`}),be=t({type:`containsSpecialCharacter`,validator(e,t=1){let n=Number.isFinite(t)?Math.max(1,Math.floor(t)):1;return C(e)?{$valid:J(RegExp(`^(?:.*[!@~\`#£€\$%^&*()_+\\-=[\\]{};':"\\\\|,.<>/?]){${n},}.*$`)).exec(e),minCharactersCount:n}:{$valid:!0,minCharactersCount:n}},message({minCharactersCount:e}){return`This field must contain at least ${e} special character${e>1?`s`:``}`}}),xe=t({type:`containsUppercase`,validator(e,t=1){let n=Number.isFinite(t)?Math.max(1,Math.floor(t)):1;return C(e)?{$valid:J(RegExp(`^(?:.*[A-Z]){${n},}.*$`)).exec(e),minUppercaseCount:n}:{$valid:!0,minUppercaseCount:n}},message:({minUppercaseCount:e})=>`This field must contain at least ${e} uppercase letter${e>1?`s`:``}`}),Se=t({type:`date`,validator:e=>C(e)?e instanceof Date:!0,message:`The value must be a native Date`});function Ce(){return navigator.languages==null?navigator.language??`en-US`:navigator.languages[0]}function Y(e){return e?new Intl.DateTimeFormat(Ce(),{dateStyle:`short`}).format(new Date(e)):`?`}const we=t({type:`dateAfter`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return C(e)&&C(t)?y(e)&&y(t)?(r?b(e).getTime()>=b(t).getTime():b(e).getTime()>b(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 ${Y(e)}`}),Te=t({type:`dateBefore`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return C(e)&&C(t)?y(e)&&y(t)?(r?b(e).getTime()<=b(t).getTime():b(e).getTime()<b(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 ${Y(e)}`}),Ee=t({type:`dateBetween`,validator:(e,t,n,r)=>{let{allowEqual:i=!0}=r??{};return y(e)&&y(t)&&y(n)?i?b(e).getTime()>=b(t).getTime()&&b(e).getTime()<=b(n).getTime():b(e).getTime()>b(t).getTime()&&b(e).getTime()<b(n).getTime():!0},message:({$params:[e,t]})=>`The date must be between ${Y(e)} and ${Y(t)}`}),De=t({type:`decimal`,validator(e){return u(e)?!0:T(e,le)},message:`The value must be decimal`}),Oe=t({type:`domain`,validator(e){return u(e)?!0:T(e,z)},message:`The value is not a valid domain`}),ke=t({type:`email`,validator(e){return u(e)?!0:T(e,ue)},message:`The value must be a valid email address`}),Ae=t({type:`emoji`,validator(e){return u(e)?!0:B().test(e)},message:`The value should be a valid emoji`}),je=q({type:`endsWith`,operation:`endsWith`}),Me=t({type:`exactDigits`,validator:(e,t)=>{if(C(e,!1)&&C(t)){if(w(t)){let n=RegExp(`^\\d{${t}}$`);return T(e.toString(),n)}return!0}return!0},message:({$params:[e]})=>`The value should have exactly ${e} digits`}),Ne=t({type:`exactLength`,validator:(e,t)=>C(e,!1)&&C(t)?w(t)?E(e)===t:!1:!0,message:({$params:[e]})=>`The value must be exactly ${e} characters long`}),Pe=t({type:`exactValue`,validator:(e,t)=>C(e)&&C(t)&&w(t)&&!isNaN(D(e))?D(e)===t:!0,message:({$params:[e]})=>`The value must be equal to ${e}`}),Fe=t({type:`file`,validator:e=>C(e)?l(e):!0,message:`The value must be a native File`}),Ie=t({type:`fileType`,validator:(e,t)=>C(e)&&l(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(`, `)}.`}}),Le=t({type:`hexadecimal`,validator(e){return u(e)?!0:T(e,U)},message:`The value must be hexadecimal`}),Re=t({type:`hostname`,validator(e){return u(e)?!0:T(e,L)},message:`The value is not a valid hostname`}),X=t({type:`url`,validator(e,t={}){try{if(u(e))return!0;let{protocol:n}=t||{},r=new URL(e);return!L.test(r.hostname)||n&&!n.test(r.protocol.endsWith(`:`)?r.protocol.slice(0,-1):r.protocol)?!1:T(e,R)}catch{return!1}},message:`The value must be a valid URL`}),ze=t({type:`httpUrl`,validator(e,t={}){if(u(e))return!0;let{protocol:n=I}=t||{};return X({protocol:n}).exec(e)},message:`The value is not a valid http URL address`}),Be=t({type:`integer`,validator(e){return u(e)?!0:T(e,de)},message:`The value must be an integer`});function Ve(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 He=t({type:`ipv4Address`,validator(e){if(u(e))return!0;if(typeof e!=`string`)return!1;let t=e.split(`.`);return t.length===4&&t.every(Ve)},message:`The value is not a valid IPv4 address`});function Ue(e){return m(_((e,t)=>C(e)&&C(t)?t===e:!0,[i(()=>c(e))]),({$params:[e]})=>`Value should be ${e}.`)}const We=t({type:`lowercase`,validator(e){return u(e)?!0:T(e,V)},message:`The value must be lowercase`}),Ge=t({type:`macAddress`,validator(e,t=`:`){if(u(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(Ke)},message:`The value is not a valid MAC Address`}),Ke=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/),qe=t({type:`maxFileSize`,validator:(e,t)=>C(e)&&l(e)?{$valid:e.size<=t,fileSize:e.size}:!0,message({$params:[e],fileSize:t}){return`File size (${S(t)}) cannot exceed ${S(e)}`}});function Z({type:e,direction:n}){let r=(e,t,r)=>n===`min`?r?e>=t:e>t:r?e<=t:e<t,i=(e,t)=>Array.isArray(e)?n===`min`?`The list must have at least ${t} items`:`The list must have at most ${t} items`:n===`min`?`The value must be at least ${t} characters long`:`The value must be at most ${t} characters long`;return t({type:e,validator:(e,t,n)=>{let{allowEqual:i=!0}=n??{};return C(e,!1)&&C(t)&&w(t)?r(E(e),t,i):!0},message:({$value:e,$params:[t]})=>i(e,t)})}const Je=Z({type:`maxLength`,direction:`max`});function Q({type:e,direction:n}){let r=(e,t,r)=>n===`min`?r?e>=t:e>t:r?e<=t:e<t,i=(e,t)=>n===`min`?t?`The value must be greater than or equal to ${e}`:`The value must be greater than ${e}`:t?`The value must be less than or equal to ${e}`:`The value must be less than ${e}`;return t({type:e,validator:(e,t,n)=>{let{allowEqual:i=!0}=n??{};return C(e)&&C(t)&&!isNaN(D(e))&&!isNaN(D(t))?r(D(e),D(t),i):!0},message:({$params:[e,t]})=>{let{allowEqual:n=!0}=t??{};return i(e,n)}})}const $=Q({type:`maxValue`,direction:`max`}),Ye=t({type:`minFileSize`,validator:(e,t)=>C(e)&&l(e)?{$valid:e.size>=t,fileSize:e.size}:!0,message({$params:[e],fileSize:t}){return`File size (${S(t)}) must be at least ${S(e)}`}}),Xe=Z({type:`minLength`,direction:`min`}),Ze=Q({type:`minValue`,direction:`min`});function Qe(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(e){return m(_((e,t)=>C(e)&&!u(t)?Qe(t).includes(e):!0,[i(()=>c(e))]),({$params:[e]})=>`The value must be one of the following: ${Object.values(e).join(`, `)}`)}const et=t({type:`number`,validator:e=>C(e)?w(e):!0,message:`The value must be a native number`}),tt=t({type:`numeric`,validator(e){return u(e)?!0:T(e,fe)},message:`The value must be numeric`}),nt=t({type:`oneOf`,validator(e,t){return C(e)&&C(t,!1)?Array.isArray(t)?t.includes(e):Object.values(t).includes(e):!0},message:({$params:[e]})=>`The value must be one of the following: ${(Array.isArray(e)?e:Object.values(e)).join(`, `)}`}),rt=t({type:`required`,validator:e=>C(e,!0,!1),message:`This field is required`,required:!0}),it=t({type:`required`,validator(e,t){return t?C(e):!0},message:`This field is required`,active({$params:[e]}){return e}}),at=t({type:`required`,validator(e,t){return t?!0:C(e)},message:`This field is required`,active({$params:[e]}){return!e}}),ot=t({type:`sameAs`,validator(e,t,n){return u(e)?!0:e===t},message({$params:[e,t=`other`]}){return`The value must be equal to the ${t} value`}}),st=q({type:`startsWith`,operation:`startsWith`}),ct=t({type:`string`,validator:e=>C(e)?typeof e==`string`:!0,message:`The value must be a string`});function lt(){return(()=>!0)}const ut=t({type:`uppercase`,validator(e){return u(e)?!0:T(e,H)},message:`The value must be uppercase`});export{pe as alpha,me as alphaNum,te as and,v as applyIf,ae as assignIf,he as atLeastOne,ge as between,_e as boolean,ve as checked,ye as contains,be as containsSpecialCharacter,xe as containsUppercase,Se as date,we as dateAfter,Te as dateBefore,Ee as dateBetween,De as decimal,Oe as domain,ke as email,Ae as emoji,je as endsWith,Me as exactDigits,Ne as exactLength,Pe as exactValue,Fe as file,Ie as fileType,E as getSize,Le as hexadecimal,Re as hostname,ze as httpUrl,Be as integer,He as ipv4Address,y as isDate,u as isEmpty,C as isFilled,w as isNumber,Ue as literal,We as lowercase,Ge as macAddress,T as matchRegex,qe as maxFileSize,Je as maxLength,$ as maxValue,Ye as minFileSize,Xe as minLength,Ze as minValue,$e as nativeEnum,ie as not,et as number,tt as numeric,nt as oneOf,ne as or,F as pipe,J as regex,rt as required,it as requiredIf,at as requiredUnless,ot as sameAs,st as startsWith,ct as string,b as toDate,D as toNumber,lt as type,ut as uppercase,X as url,g as withAsync,m as withMessage,_ as withParams,h as withTooltip,re as xor};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@regle/rules",
3
- "version": "1.20.0-preview.2",
3
+ "version": "1.20.0-preview.4",
4
4
  "description": "Collection of rules and helpers for Regle",
5
5
  "homepage": "https://reglejs.dev/",
6
6
  "license": "MIT",
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "type-fest": "5.4.4",
39
- "@regle/core": "1.20.0-preview.2"
39
+ "@regle/core": "1.20.0-preview.4"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/node": "24.10.13",