@regle/rules 1.23.2 → 1.24.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.
@@ -1,10 +1,10 @@
1
1
  /**
2
- * @regle/rules v1.23.2
2
+ * @regle/rules v1.24.0
3
3
  * (c) 2026 Victor Garcia
4
4
  * @license MIT
5
5
  */
6
6
 
7
- import { CommonAlphaOptions, CommonComparisonOptions, ExtendedRulesDeclarations, FormRuleDeclaration, InlineRuleDeclaration, Maybe, MaybeInput, MaybeReadonly, NonEmptyTuple, ParamsToLooseParams, Prettify, RegleRuleDecl, RegleRuleDefinition, RegleRuleDefinitionWithMetadataProcessor, RegleRuleMetadataConsumer, RegleRuleMetadataDefinition, RegleRuleWithParamsDefinition, RegleRuleWithParamsDefinitionInput, UnwrapRegleUniversalParams } from "@regle/core";
7
+ import { CommonAlphaOptions, CommonComparisonOptions, ExtendedRulesDeclarations, FormRuleDeclaration, InlineRuleDeclaration, Maybe, MaybeInput, MaybeReadonly, MeasurableValue, NonEmptyTuple, ParamsToLooseParams, Prettify, RegleRuleDecl, RegleRuleDefinition, RegleRuleDefinitionWithMetadataProcessor, RegleRuleMetadataConsumer, RegleRuleMetadataDefinition, RegleRuleWithParamsDefinition, RegleRuleWithParamsDefinitionInput, UnwrapRegleUniversalParams } from "@regle/core";
8
8
  import { MaybeRefOrGetter, Ref } from "vue";
9
9
  import { EmptyObject, IsTuple, IsUnknown } from "type-fest";
10
10
  /**
@@ -238,10 +238,10 @@ declare function isNumber(value: unknown): value is number;
238
238
  */
239
239
  declare function matchRegex(_value: string | number | null | undefined, ...expr: RegExp[]): boolean;
240
240
  /**
241
- * Returns the length/size of any data type. Works with strings, arrays, objects and numbers.
241
+ * Returns the length of strings, numbers, arrays, or number of keys for objects.
242
242
  *
243
243
  * @param value - The value to get the size of
244
- * @returns The length of strings/arrays, number of keys for objects, or the number itself
244
+ * @returns The length of strings, numbers, arrays, and number of keys for objects
245
245
  *
246
246
  * @example
247
247
  * ```ts
@@ -261,7 +261,7 @@ declare function matchRegex(_value: string | number | null | undefined, ...expr:
261
261
  *
262
262
  * @see {@link https://reglejs.dev/core-concepts/rules/validations-helpers#getsize Documentation}
263
263
  */
264
- declare function getSize(value: MaybeRefOrGetter<string | any[] | Record<string, any> | number>): number;
264
+ declare function getSize(value: MaybeRefOrGetter<MeasurableValue>): number;
265
265
  /**
266
266
  * Converts any string (or number) into a number using the `Number` constructor.
267
267
  *
@@ -920,7 +920,7 @@ declare const emoji: RegleRuleDefinition<'emoji', string, [], false, boolean, un
920
920
  */
921
921
  declare const endsWith: RegleRuleWithParamsDefinition<'endsWith', string, [part: MaybeInput<string>], false, boolean, MaybeInput<string>>;
922
922
  /**
923
- * Requires the input value to have a strict specified length. Works with arrays, objects and strings.
923
+ * Requires the input value to have a strict specified number of digits. Works with strings and numbers.
924
924
  *
925
925
  * @param count - The exact required length
926
926
  *
@@ -945,7 +945,7 @@ declare const endsWith: RegleRuleWithParamsDefinition<'endsWith', string, [part:
945
945
  */
946
946
  declare const exactDigits: RegleRuleWithParamsDefinition<'exactDigits', string | number, [count: number], false, boolean>;
947
947
  /**
948
- * Requires the input value to have a strict specified length. Works with arrays, objects and strings.
948
+ * Requires the input value to have a strict specified length. Works with arrays, objects, numbers, and strings.
949
949
  *
950
950
  * @param count - The exact required length
951
951
  *
@@ -968,7 +968,7 @@ declare const exactDigits: RegleRuleWithParamsDefinition<'exactDigits', string |
968
968
  *
969
969
  * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#exactlength Documentation}
970
970
  */
971
- declare const exactLength: RegleRuleWithParamsDefinition<'exactLength', string | any[] | Record<PropertyKey, any>, [count: number], false, boolean>;
971
+ declare const exactLength: RegleRuleWithParamsDefinition<'exactLength', MeasurableValue, [count: number], false, boolean>;
972
972
  /**
973
973
  * Requires a field to have a strict numeric value.
974
974
  *
@@ -1212,7 +1212,7 @@ declare const maxFileSize: RegleRuleWithParamsDefinition<'maxFileSize', File, [m
1212
1212
  fileSize: number;
1213
1213
  }, unknown, File>;
1214
1214
  /**
1215
- * Requires the input value to have a maximum specified length, inclusive. Works with arrays, objects and strings.
1215
+ * Requires the input value to have a maximum specified length, inclusive. Works with arrays, objects, numbers, and strings.
1216
1216
  *
1217
1217
  * @param max - The maximum length
1218
1218
  * @param options - Optional configuration (e.g., `{ allowEqual: false }`)
@@ -1237,7 +1237,7 @@ declare const maxFileSize: RegleRuleWithParamsDefinition<'maxFileSize', File, [m
1237
1237
  *
1238
1238
  * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#maxlength Documentation}
1239
1239
  */
1240
- declare const maxLength: RegleRuleWithParamsDefinition<'maxLength', string | any[] | Record<PropertyKey, any>, [max: number, options?: CommonComparisonOptions], false, boolean>;
1240
+ declare const maxLength: RegleRuleWithParamsDefinition<'maxLength', MeasurableValue, [max: number, options?: CommonComparisonOptions], false, boolean>;
1241
1241
  /**
1242
1242
  * Requires a field to have a specified maximum numeric value.
1243
1243
  *
@@ -1288,7 +1288,7 @@ declare const minFileSize: RegleRuleWithParamsDefinition<'minFileSize', File, [m
1288
1288
  fileSize: number;
1289
1289
  }, MaybeInput<File>, File>;
1290
1290
  /**
1291
- * Requires the input value to have a minimum specified length, inclusive. Works with arrays, objects and strings.
1291
+ * Requires the input value to have a minimum specified length, inclusive. Works with arrays, objects, numbers, and strings.
1292
1292
  *
1293
1293
  * @param min - The minimum length
1294
1294
  * @param options - Optional configuration (e.g., `{ allowEqual: false }`)
@@ -1313,7 +1313,7 @@ declare const minFileSize: RegleRuleWithParamsDefinition<'minFileSize', File, [m
1313
1313
  *
1314
1314
  * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#minlength Documentation}
1315
1315
  */
1316
- declare const minLength: RegleRuleWithParamsDefinition<'minLength', string | any[] | Record<PropertyKey, any>, [min: number, options?: CommonComparisonOptions], false, boolean, MaybeInput<string | any[] | Record<PropertyKey, any>>>;
1316
+ declare const minLength: RegleRuleWithParamsDefinition<'minLength', MeasurableValue, [min: number, options?: CommonComparisonOptions], false, boolean>;
1317
1317
  /**
1318
1318
  * Requires a field to have a specified minimum numeric value.
1319
1319
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @regle/rules v1.23.2
2
+ * @regle/rules v1.24.0
3
3
  * (c) 2026 Victor Garcia
4
4
  * @license MIT
5
5
  */
@@ -397,10 +397,10 @@ function matchRegex(_value, ...expr) {
397
397
  });
398
398
  }
399
399
  /**
400
- * Returns the length/size of any data type. Works with strings, arrays, objects and numbers.
400
+ * Returns the length of strings, numbers, arrays, or number of keys for objects.
401
401
  *
402
402
  * @param value - The value to get the size of
403
- * @returns The length of strings/arrays, number of keys for objects, or the number itself
403
+ * @returns The length of strings, numbers, arrays, and number of keys for objects
404
404
  *
405
405
  * @example
406
406
  * ```ts
@@ -422,12 +422,10 @@ function matchRegex(_value, ...expr) {
422
422
  */
423
423
  function getSize(value) {
424
424
  const _value = toValue(value);
425
+ if (_value instanceof Set || _value instanceof Map) return _value.size;
425
426
  if (Array.isArray(_value)) return _value.length;
426
427
  if (typeof _value === "object") return Object.keys(_value).length;
427
- if (typeof _value === "number") {
428
- if (isNaN(_value)) return 0;
429
- return _value;
430
- }
428
+ if (Number.isNaN(_value)) return 0;
431
429
  return String(_value).length;
432
430
  }
433
431
  /**
@@ -1473,7 +1471,7 @@ const endsWith = createStringOperationRule({
1473
1471
  operation: "endsWith"
1474
1472
  });
1475
1473
  /**
1476
- * Requires the input value to have a strict specified length. Works with arrays, objects and strings.
1474
+ * Requires the input value to have a strict specified number of digits. Works with strings and numbers.
1477
1475
  *
1478
1476
  * @param count - The exact required length
1479
1477
  *
@@ -1514,7 +1512,7 @@ const exactDigits = createRule({
1514
1512
  }
1515
1513
  });
1516
1514
  /**
1517
- * Requires the input value to have a strict specified length. Works with arrays, objects and strings.
1515
+ * Requires the input value to have a strict specified length. Works with arrays, objects, numbers, and strings.
1518
1516
  *
1519
1517
  * @param count - The exact required length
1520
1518
  *
@@ -1948,7 +1946,7 @@ function createLengthRule({ type, direction }) {
1948
1946
  });
1949
1947
  }
1950
1948
  /**
1951
- * Requires the input value to have a maximum specified length, inclusive. Works with arrays, objects and strings.
1949
+ * Requires the input value to have a maximum specified length, inclusive. Works with arrays, objects, numbers, and strings.
1952
1950
  *
1953
1951
  * @param max - The maximum length
1954
1952
  * @param options - Optional configuration (e.g., `{ allowEqual: false }`)
@@ -2072,7 +2070,7 @@ const minFileSize = createRule({
2072
2070
  }
2073
2071
  });
2074
2072
  /**
2075
- * Requires the input value to have a minimum specified length, inclusive. Works with arrays, objects and strings.
2073
+ * Requires the input value to have a minimum specified length, inclusive. Works with arrays, objects, numbers, and strings.
2076
2074
  *
2077
2075
  * @param min - The minimum length
2078
2076
  * @param options - Optional configuration (e.g., `{ allowEqual: false }`)
@@ -1,7 +1,7 @@
1
1
  /**
2
- * @regle/rules v1.23.2
2
+ * @regle/rules v1.24.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{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])):Object.values(e).some(e=>C(e)):!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};
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 t instanceof Set||t instanceof Map?t.size:Array.isArray(t)?t.length:typeof t==`object`?Object.keys(t).length:Number.isNaN(t)?0: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])):Object.values(e).some(e=>C(e)):!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.23.2",
3
+ "version": "1.24.0",
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.6.0",
39
- "@regle/core": "1.23.2"
39
+ "@regle/core": "1.24.0"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/node": "24.12.2",