@regle/rules 1.19.13 → 1.19.15-beta.1

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.19.13
2
+ * @regle/rules v1.19.15-beta.1
3
3
  * (c) 2026 Victor Garcia
4
4
  * @license MIT
5
5
  */
@@ -691,6 +691,52 @@ declare const checked: RegleRuleDefinition<'checked', boolean, [], false, boolea
691
691
  * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#contains Documentation}
692
692
  */
693
693
  declare const contains: RegleRuleWithParamsDefinition<'contains', string, [part: MaybeInput<string>], false, boolean, MaybeInput<string>>;
694
+ /**
695
+ * Requires a string field to contain at least a given number of special characters.
696
+ *
697
+ * @example
698
+ * ```ts
699
+ * import { useRegle, containsSpecialCharacter } from '@regle/rules';
700
+ *
701
+ * const { r$ } = useRegle({ password: '' }, {
702
+ * password: {
703
+ * containsSpecialCharacter,
704
+ * // or with a minimum number of special characters
705
+ * containsSpecialCharacter: containsSpecialCharacter(2)
706
+ * }
707
+ * })
708
+ * ```
709
+ * @param minCharactersCount - The minimum number of special characters to contain.
710
+ * @returns A rule that validates the string field.
711
+ *
712
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#containsSpecialCharacter Documentation}
713
+ */
714
+ declare const containsSpecialCharacter: RegleRuleWithParamsDefinition<'containsSpecialCharacter', string, [minCharactersCount?: number | undefined], false, {
715
+ $valid: boolean;
716
+ minCharactersCount: number;
717
+ }, string, string, false>;
718
+ /**
719
+ * Requires a string field to contain at least a given number of uppercase letters.
720
+ *
721
+ * @example
722
+ * ```ts
723
+ * import { useRegle, containsUppercase } from '@regle/rules';
724
+ *
725
+ * const { r$ } = useRegle({ password: '' }, {
726
+ * password: { containsUppercase },
727
+ * // or with a minimum number of uppercase letters
728
+ * password: { containsUppercase: containsUppercase(2) }
729
+ * })
730
+ * ```
731
+ * @param minUppercaseCount - The minimum number of uppercase letters to contain.
732
+ * @returns A rule that validates the string field.
733
+ *
734
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#containsUppercase Documentation}
735
+ */
736
+ declare const containsUppercase: RegleRuleWithParamsDefinition<'containsUppercase', string, [minUppercaseCount?: number | undefined], false, {
737
+ $valid: boolean;
738
+ minUppercaseCount: number;
739
+ }, string, string, false>;
694
740
  /**
695
741
  * Requires a value to be a native `Date` constructor.
696
742
  *
@@ -1554,4 +1600,4 @@ declare function type<T>(): RegleRuleDefinition<'type', unknown, [], false, bool
1554
1600
  * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#uppercase Documentation}
1555
1601
  */
1556
1602
  declare const uppercase: RegleRuleDefinition<'uppercase', string, [], false, boolean, unknown, string>;
1557
- export { alpha, alphaNum, and, applyIf, assignIf, atLeastOne, between, boolean, checked, contains, 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 };
1603
+ 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 };
@@ -1,11 +1,12 @@
1
1
  /**
2
- * @regle/rules v1.19.13
2
+ * @regle/rules v1.19.15-beta.1
3
3
  * (c) 2026 Victor Garcia
4
4
  * @license MIT
5
5
  */
6
6
 
7
7
  import { InternalRuleType, createRule, unwrapRuleParameters } from "@regle/core";
8
8
  import { capitalize, computed, effectScope, onScopeDispose, ref, toValue } from "vue";
9
+ import { isFilled as isFilled$1, regex as regex$1 } from "@regle/rules";
9
10
 
10
11
  /**
11
12
  * Server side friendly way of checking for a File
@@ -1160,6 +1161,80 @@ const contains = createStringOperationRule({
1160
1161
  operation: "contains"
1161
1162
  });
1162
1163
 
1164
+ /**
1165
+ * Requires a string field to contain at least a given number of special characters.
1166
+ *
1167
+ * @example
1168
+ * ```ts
1169
+ * import { useRegle, containsSpecialCharacter } from '@regle/rules';
1170
+ *
1171
+ * const { r$ } = useRegle({ password: '' }, {
1172
+ * password: {
1173
+ * containsSpecialCharacter,
1174
+ * // or with a minimum number of special characters
1175
+ * containsSpecialCharacter: containsSpecialCharacter(2)
1176
+ * }
1177
+ * })
1178
+ * ```
1179
+ * @param minCharactersCount - The minimum number of special characters to contain.
1180
+ * @returns A rule that validates the string field.
1181
+ *
1182
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#containsSpecialCharacter Documentation}
1183
+ */
1184
+ const containsSpecialCharacter = createRule({
1185
+ type: "containsSpecialCharacter",
1186
+ validator(value, minCharactersCount = 1) {
1187
+ const minOccurrences = Number.isFinite(minCharactersCount) ? Math.max(1, Math.floor(minCharactersCount)) : 1;
1188
+ if (isFilled$1(value)) return {
1189
+ $valid: regex$1(new RegExp(`^(?:.*[!@~\`#£€\$%^&*()_+\\-=[\\]{};':"\\\\|,.<>/?]){${minOccurrences},}.*$`)).exec(value),
1190
+ minCharactersCount: minOccurrences
1191
+ };
1192
+ return {
1193
+ $valid: true,
1194
+ minCharactersCount: minOccurrences
1195
+ };
1196
+ },
1197
+ message({ minCharactersCount }) {
1198
+ return `This field must contain at least ${minCharactersCount} special character${minCharactersCount > 1 ? "s" : ""}`;
1199
+ }
1200
+ });
1201
+
1202
+ /**
1203
+ * Requires a string field to contain at least a given number of uppercase letters.
1204
+ *
1205
+ * @example
1206
+ * ```ts
1207
+ * import { useRegle, containsUppercase } from '@regle/rules';
1208
+ *
1209
+ * const { r$ } = useRegle({ password: '' }, {
1210
+ * password: { containsUppercase },
1211
+ * // or with a minimum number of uppercase letters
1212
+ * password: { containsUppercase: containsUppercase(2) }
1213
+ * })
1214
+ * ```
1215
+ * @param minUppercaseCount - The minimum number of uppercase letters to contain.
1216
+ * @returns A rule that validates the string field.
1217
+ *
1218
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#containsUppercase Documentation}
1219
+ */
1220
+ const containsUppercase = createRule({
1221
+ type: "containsUppercase",
1222
+ validator(value, minUppercaseCount = 1) {
1223
+ const minOccurrences = Number.isFinite(minUppercaseCount) ? Math.max(1, Math.floor(minUppercaseCount)) : 1;
1224
+ if (isFilled$1(value)) return {
1225
+ $valid: regex$1(new RegExp(`^(?:.*[A-Z]){${minOccurrences},}.*$`)).exec(value),
1226
+ minUppercaseCount: minOccurrences
1227
+ };
1228
+ return {
1229
+ $valid: true,
1230
+ minUppercaseCount: minOccurrences
1231
+ };
1232
+ },
1233
+ message: ({ minUppercaseCount }) => {
1234
+ return `This field must contain at least ${minUppercaseCount} uppercase letter${minUppercaseCount > 1 ? "s" : ""}`;
1235
+ }
1236
+ });
1237
+
1163
1238
  /**
1164
1239
  * Requires a value to be a native `Date` constructor.
1165
1240
  *
@@ -2467,4 +2542,4 @@ const uppercase = createRule({
2467
2542
  message: "The value must be uppercase"
2468
2543
  });
2469
2544
 
2470
- export { alpha, alphaNum, and, applyIf, assignIf, atLeastOne, between, boolean, checked, contains, 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 };
2545
+ 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 };
@@ -1,7 +1,7 @@
1
1
  /**
2
- * @regle/rules v1.19.13
2
+ * @regle/rules v1.19.15-beta.1
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 F({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 I(...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:F({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 L=/^https?$/,R=/^(?=.{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])?)*\.?$/,z=/^(?:(?:(?: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 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]*$/,q=/^[a-zA-Z0-9_]*$/,se=/^[-]?\d*(\.\d+)?$/,ce=/^(?:[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,le=/(^[0-9]*$)|(^-[0-9]+$)/,ue=/^\d*(\.\d+)?$/,de=t({type:`alpha`,validator(e,t){return u(e)?!0:t?.allowSymbols?T(e,G):T(e,W)},message:`The value must be alphabetical`}),fe=t({type:`alphaNum`,validator(e,t){return u(e)?!0:t?.allowSymbols?T(e,q):T(e,K)},message:`The value must be alpha-numeric`}),pe=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`}),me=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}`}),he=t({type:`boolean`,validator:e=>C(e)?typeof e==`boolean`:!0,message:`The value must be a native boolean`}),ge=t({type:`checked`,validator:e=>e===!0,message:`The field must be checked`,required:!0});function J({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 _e=J({type:`contains`,operation:`contains`}),ve=t({type:`date`,validator:e=>C(e)?e instanceof Date:!0,message:`The value must be a native Date`});function ye(){return navigator.languages==null?navigator.language??`en-US`:navigator.languages[0]}function Y(e){return e?new Intl.DateTimeFormat(ye(),{dateStyle:`short`}).format(new Date(e)):`?`}const be=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)}`}),xe=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)}`}),Se=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)}`}),Ce=t({type:`decimal`,validator(e){return u(e)?!0:T(e,se)},message:`The value must be decimal`}),we=t({type:`email`,validator(e){return u(e)?!0:T(e,ce)},message:`The value must be a valid email address`}),Te=t({type:`emoji`,validator(e){return u(e)?!0:B().test(e)},message:`The value should be a valid emoji`}),Ee=J({type:`endsWith`,operation:`endsWith`}),De=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`}),Oe=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`}),ke=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}`}),Ae=t({type:`file`,validator:e=>C(e)?l(e):!0,message:`The value must be a native File`}),je=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(`, `)}.`}}),Me=t({type:`hexadecimal`,validator(e){return u(e)?!0:T(e,U)},message:`The value must be hexadecimal`}),Ne=t({type:`hostname`,validator(e){return u(e)?!0:T(e,R)},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!R.test(r.hostname)||n&&!n.test(r.protocol.endsWith(`:`)?r.protocol.slice(0,-1):r.protocol)?!1:T(e,z)}catch{return!1}},message:`The value must be a valid URL`}),Pe=t({type:`httpUrl`,validator(e,t={}){if(u(e))return!0;let{protocol:n=L}=t||{};return X({protocol:n}).exec(e)},message:`The value is not a valid http URL address`}),Fe=t({type:`integer`,validator(e){return u(e)?!0:T(e,le)},message:`The value must be an integer`});function Ie(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 Le=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(Ie)},message:`The value is not a valid IPv4 address`});function Re(e){return m(_((e,t)=>C(e)&&C(t)?t===e:!0,[i(()=>c(e))]),({$params:[e]})=>`Value should be ${e}.`)}const ze=t({type:`lowercase`,validator(e){return u(e)?!0:T(e,V)},message:`The value must be lowercase`}),Be=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(Ve)},message:`The value is not a valid MAC Address`}),Ve=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/),He=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 Ue=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 We=Q({type:`maxValue`,direction:`max`}),Ge=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)}`}}),Ke=Z({type:`minLength`,direction:`min`}),qe=Q({type:`minValue`,direction:`min`});function Je(e){let t=Object.keys(e).filter(t=>typeof e[e[t]]!=`number`),n={};for(let r of t)n[r]=e[r];return Object.values(n)}function $(e){return m(_((e,t)=>C(e)&&!u(t)?Je(t).includes(e):!0,[i(()=>c(e))]),({$params:[e]})=>`The value must be one of the following: ${Object.values(e).join(`, `)}`)}const Ye=t({type:`number`,validator:e=>C(e)?w(e):!0,message:`The value must be a native number`}),Xe=t({type:`numeric`,validator(e){return u(e)?!0:T(e,ue)},message:`The value must be numeric`}),Ze=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(`, `)}`}),Qe=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`}),$e=t({type:`required`,validator:e=>C(e,!0,!1),message:`This field is required`,required:!0}),et=t({type:`required`,validator(e,t){return t?C(e):!0},message:`This field is required`,active({$params:[e]}){return e}}),tt=t({type:`required`,validator(e,t){return t?!0:C(e)},message:`This field is required`,active({$params:[e]}){return!e}}),nt=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`}}),rt=J({type:`startsWith`,operation:`startsWith`}),it=t({type:`string`,validator:e=>C(e)?typeof e==`string`:!0,message:`The value must be a string`});function at(){return(()=>!0)}const ot=t({type:`uppercase`,validator(e){return u(e)?!0:T(e,H)},message:`The value must be uppercase`});export{de as alpha,fe as alphaNum,te as and,v as applyIf,ae as assignIf,pe as atLeastOne,me as between,he as boolean,ge as checked,_e as contains,ve as date,be as dateAfter,xe as dateBefore,Se as dateBetween,Ce as decimal,we as email,Te as emoji,Ee as endsWith,De as exactDigits,Oe as exactLength,ke as exactValue,Ae as file,je as fileType,E as getSize,Me as hexadecimal,Ne as hostname,Pe as httpUrl,Fe as integer,Le as ipv4Address,y as isDate,u as isEmpty,C as isFilled,w as isNumber,Re as literal,ze as lowercase,Be as macAddress,T as matchRegex,He as maxFileSize,Ue as maxLength,We as maxValue,Ge as minFileSize,Ke as minLength,qe as minValue,$ as nativeEnum,ie as not,Ye as number,Xe as numeric,Ze as oneOf,ne as or,I as pipe,Qe as regex,$e as required,et as requiredIf,tt as requiredUnless,nt as sameAs,rt as startsWith,it as string,b as toDate,D as toNumber,at as type,ot 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";import{isFilled as l,regex as u}from"@regle/rules";function d(e){return e?.constructor?.name==`File`}function f(e,t=!0,n=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):d(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:p(e)?e==null?!0:n?Object.keys(e).length===0:!1:!String(e).length}function p(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function m(e){return(p(e)||typeof e==`function`)&&`_validator`in e}function h(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(m(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 g(e,n){let{_type:r,validator:i,_active:a,_params:o,_async:s}=h(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 _(e,n){let{_type:r,validator:i,_active:a,_params:o,_message:s,_async:c}=h(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 v(n,r){let i,{_type:a,_params:o,_message:s,_active:c}=h(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 y(n,r){let i,{_type:a,_params:o,_message:s,_active:c,_async:l}=h(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 b(e,r,i){let{_type:a,validator:o,_params:s,_message:c,_async:l,_active:u}=h(r),d=(s??[]).concat(i?.hideParams?[]:[e]);function f(t,...r){let[i]=n([e]);return i?o(t,...r):!0}function p(t){let[r]=n([e]);return r?typeof u==`function`?u(t):u??!0:!1}let m=t({type:a,validator:f,active:p,message:c,async:l});return m._params=d,typeof m==`function`?m(...d):m}function x(e){if(f(e))return!1;let t=null;if(e instanceof Date)t=e;else if(typeof e==`string`){let n=new Date(e);if(n.toString()===`Invalid Date`)return!1;t=n}return!!t}function S(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 ee(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 C(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 w(e,t=!0,n=!0){return!f(typeof e==`string`?e.trim():e,t,n)}function T(e){return e==null?!1:typeof e==`number`?!isNaN(e):!1}function E(e,...t){if(f(e))return!0;let n=typeof e==`number`?e.toString():e;return t.every(e=>(e.lastIndex=0,e.test(n)))}function D(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 O(e){return typeof e==`number`?e:e==null?NaN:typeof e==`string`&&e.trim()===e?+e:NaN}function k(e){return e==null?!1:typeof e==`string`}function te(e){return e.some(e=>typeof e==`function`?e.constructor.name===`AsyncFunction`:e._async)}function A(e){return e.map(e=>{if(typeof e==`function`)return null;{let t=e._params;return t?.length?t:[]}}).flat().filter(e=>!!e)}function j(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 M(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 N(e,t,n){return t.some(e=>typeof e!=`boolean`)?{$valid:M(e,t,n),...t.reduce((e,t)=>{if(typeof t==`boolean`)return e;let{$valid:n,...r}=t;return{...e,...r}},{})}:M(e,t,n)}function P(e,n){let{mode:r,message:i}=n,a=te(e),o=A(e),s;s=e.length?a?async(t,...n)=>N(t,await Promise.all(j(e,t,...n)),r):(t,...n)=>N(t,j(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 ne(...e){return P(e,{mode:`and`,message:`The value does not match all of the provided validators`})}function re(...e){return P(e,{mode:`or`,message:`The value does not match any of the provided validators`})}function ie(...e){return P(e,{mode:`xor`,message:`The value does not match exactly one of the provided validators`})}function ae(e,n){let i,{_type:a,validator:o,_params:s,_async:c,_active:l}=h(e);i=c?async(e,...t)=>{if(w(e))try{return!await o(e,...t)}catch{return!0}return!0}:(e,...t)=>w(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 F(e,t,n){return Object.entries(c(t)).map(([t,r])=>typeof r==`function`||p(r)&&`_validator`in r?[t,b(n?e:()=>!c(e),r)]:[t,r])}function oe(e,t,n){let r=F(e,t,!0),i=n?F(e,n,!1):[];return Object.fromEntries([...r,...i])}function I(e,t,n){return e.run(()=>i(()=>n===0?!0:Array.from(t.value.entries()).slice(0,n).every(([,e])=>e===!0)))}function L({validator:e,index:t,isAsync:n,mappedResults:r,options:i}){return n?ee(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 R(...n){let r=[],i=s(new Map),c=[],l=n[0],u=Array.isArray(l)?l:n,d=Array.isArray(l)&&p(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:f,_async:p,_active:m}=h(n),g=t({type:s,validator:L({validator:l,mappedResults:i,index:e,isAsync:p,options:d}),active:m,async:p,message:f});g._params=u;let _;_=typeof g==`function`?g(...u??[]):g;let v=I(o,i,e),y=e>0&&r[e-1]._async,x=b(v,_,{hideParams:!y});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 z=/^https?$/,B=/^(?=.{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])?)*\.?$/,V=/^(?:(?:(?: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 H(){return RegExp(`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`,`u`)}const U=/^[^A-Z]*$/,W=/^[^a-z]*$/,G=/^[0-9a-fA-F]*$/,K=/^[a-zA-Z]*$/,q=/^[\w.]+$/,se=/^[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 f(e)?!0:t?.allowSymbols?E(e,q):E(e,K)},message:`The value must be alphabetical`}),me=t({type:`alphaNum`,validator(e,t){return f(e)?!0:t?.allowSymbols?E(e,ce):E(e,se)},message:`The value must be alpha-numeric`}),he=t({type:`atLeastOne`,validator:(e,t)=>w(e,!0,!1)&&p(e)?t?.length?t.some(t=>w(e[t])):D(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(w(e)&&w(t)&&w(n)){let r=O(e),a=O(t),o=O(n);return T(r)&&T(a)&&T(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=>w(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 J({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 w(e)&&w(t)&&k(e)&&k(t)?r(e,t):!0},message({$params:[e]}){return i(e)}})}const ye=J({type:`contains`,operation:`contains`}),be=t({type:`containsSpecialCharacter`,validator(e,t=1){let n=Number.isFinite(t)?Math.max(1,Math.floor(t)):1;return l(e)?{$valid:u(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 l(e)?{$valid:u(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=>w(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 w(e)&&w(t)?x(e)&&x(t)?(r?S(e).getTime()>=S(t).getTime():S(e).getTime()>S(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 w(e)&&w(t)?x(e)&&x(t)?(r?S(e).getTime()<=S(t).getTime():S(e).getTime()<S(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 x(e)&&x(t)&&x(n)?i?S(e).getTime()>=S(t).getTime()&&S(e).getTime()<=S(n).getTime():S(e).getTime()>S(t).getTime()&&S(e).getTime()<S(n).getTime():!0},message:({$params:[e,t]})=>`The date must be between ${Y(e)} and ${Y(t)}`}),De=t({type:`decimal`,validator(e){return f(e)?!0:E(e,le)},message:`The value must be decimal`}),Oe=t({type:`email`,validator(e){return f(e)?!0:E(e,ue)},message:`The value must be a valid email address`}),ke=t({type:`emoji`,validator(e){return f(e)?!0:H().test(e)},message:`The value should be a valid emoji`}),Ae=J({type:`endsWith`,operation:`endsWith`}),je=t({type:`exactDigits`,validator:(e,t)=>{if(w(e,!1)&&w(t)){if(T(t)){let n=RegExp(`^\\d{${t}}$`);return E(e.toString(),n)}return!0}return!0},message:({$params:[e]})=>`The value should have exactly ${e} digits`}),Me=t({type:`exactLength`,validator:(e,t)=>w(e,!1)&&w(t)?T(t)?D(e)===t:!1:!0,message:({$params:[e]})=>`The value must be exactly ${e} characters long`}),Ne=t({type:`exactValue`,validator:(e,t)=>w(e)&&w(t)&&T(t)&&!isNaN(O(e))?O(e)===t:!0,message:({$params:[e]})=>`The value must be equal to ${e}`}),Pe=t({type:`file`,validator:e=>w(e)?d(e):!0,message:`The value must be a native File`}),Fe=t({type:`fileType`,validator:(e,t)=>w(e)&&d(e)?t.includes(e.type):!0,message({$params:[e]}){return`File type is not allowed. Allowed types are: ${e.map(e=>e.split(`/`)[1]).join(`, `)}.`}}),Ie=t({type:`hexadecimal`,validator(e){return f(e)?!0:E(e,G)},message:`The value must be hexadecimal`}),Le=t({type:`hostname`,validator(e){return f(e)?!0:E(e,B)},message:`The value is not a valid hostname`}),X=t({type:`url`,validator(e,t={}){try{if(f(e))return!0;let{protocol:n}=t||{},r=new URL(e);return!B.test(r.hostname)||n&&!n.test(r.protocol.endsWith(`:`)?r.protocol.slice(0,-1):r.protocol)?!1:E(e,V)}catch{return!1}},message:`The value must be a valid URL`}),Re=t({type:`httpUrl`,validator(e,t={}){if(f(e))return!0;let{protocol:n=z}=t||{};return X({protocol:n}).exec(e)},message:`The value is not a valid http URL address`}),ze=t({type:`integer`,validator(e){return f(e)?!0:E(e,de)},message:`The value must be an integer`});function Be(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 Ve=t({type:`ipv4Address`,validator(e){if(f(e))return!0;if(typeof e!=`string`)return!1;let t=e.split(`.`);return t.length===4&&t.every(Be)},message:`The value is not a valid IPv4 address`});function He(e){return g(y((e,t)=>w(e)&&w(t)?t===e:!0,[i(()=>c(e))]),({$params:[e]})=>`Value should be ${e}.`)}const Ue=t({type:`lowercase`,validator(e){return f(e)?!0:E(e,U)},message:`The value must be lowercase`}),We=t({type:`macAddress`,validator(e,t=`:`){if(f(e))return!0;if(typeof e!=`string`)return!1;let n=typeof t==`string`&&t!==``?e.split(t):e.length===12||e.length===16?e.match(/.{2}/g):null;return n!==null&&(n.length===6||n.length===8)&&n.every(Ge)},message:`The value is not a valid MAC Address`}),Ge=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/),Ke=t({type:`maxFileSize`,validator:(e,t)=>w(e)&&d(e)?{$valid:e.size<=t,fileSize:e.size}:!0,message({$params:[e],fileSize:t}){return`File size (${C(t)}) cannot exceed ${C(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 w(e,!1)&&w(t)&&T(t)?r(D(e),t,i):!0},message:({$value:e,$params:[t]})=>i(e,t)})}const qe=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 w(e)&&w(t)&&!isNaN(O(e))&&!isNaN(O(t))?r(O(e),O(t),i):!0},message:({$params:[e,t]})=>{let{allowEqual:n=!0}=t??{};return i(e,n)}})}const Je=Q({type:`maxValue`,direction:`max`}),Ye=t({type:`minFileSize`,validator:(e,t)=>w(e)&&d(e)?{$valid:e.size>=t,fileSize:e.size}:!0,message({$params:[e],fileSize:t}){return`File size (${C(t)}) must be at least ${C(e)}`}}),Xe=Z({type:`minLength`,direction:`min`}),Ze=Q({type:`minValue`,direction:`min`});function $(e){let t=Object.keys(e).filter(t=>typeof e[e[t]]!=`number`),n={};for(let r of t)n[r]=e[r];return Object.values(n)}function Qe(e){return g(y((e,t)=>w(e)&&!f(t)?$(t).includes(e):!0,[i(()=>c(e))]),({$params:[e]})=>`The value must be one of the following: ${Object.values(e).join(`, `)}`)}const $e=t({type:`number`,validator:e=>w(e)?T(e):!0,message:`The value must be a native number`}),et=t({type:`numeric`,validator(e){return f(e)?!0:E(e,fe)},message:`The value must be numeric`}),tt=t({type:`oneOf`,validator(e,t){return w(e)&&w(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(`, `)}`}),nt=t({type:`regex`,validator(e,t){return w(e)?E(e,...Array.isArray(t)?t:[t]):!0},message:`The value must match the required pattern`}),rt=t({type:`required`,validator:e=>w(e,!0,!1),message:`This field is required`,required:!0}),it=t({type:`required`,validator(e,t){return t?w(e):!0},message:`This field is required`,active({$params:[e]}){return e}}),at=t({type:`required`,validator(e,t){return t?!0:w(e)},message:`This field is required`,active({$params:[e]}){return!e}}),ot=t({type:`sameAs`,validator(e,t,n){return f(e)?!0:e===t},message({$params:[e,t=`other`]}){return`The value must be equal to the ${t} value`}}),st=J({type:`startsWith`,operation:`startsWith`}),ct=t({type:`string`,validator:e=>w(e)?typeof e==`string`:!0,message:`The value must be a string`});function lt(){return(()=>!0)}const ut=t({type:`uppercase`,validator(e){return f(e)?!0:E(e,W)},message:`The value must be uppercase`});export{pe as alpha,me as alphaNum,ne as and,b as applyIf,oe 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 email,ke as emoji,Ae as endsWith,je as exactDigits,Me as exactLength,Ne as exactValue,Pe as file,Fe as fileType,D as getSize,Ie as hexadecimal,Le as hostname,Re as httpUrl,ze as integer,Ve as ipv4Address,x as isDate,f as isEmpty,w as isFilled,T as isNumber,He as literal,Ue as lowercase,We as macAddress,E as matchRegex,Ke as maxFileSize,qe as maxLength,Je as maxValue,Ye as minFileSize,Xe as minLength,Ze as minValue,Qe as nativeEnum,ae as not,$e as number,et as numeric,tt as oneOf,re as or,R as pipe,nt as regex,rt as required,it as requiredIf,at as requiredUnless,ot as sameAs,st as startsWith,ct as string,S as toDate,O as toNumber,lt as type,ut as uppercase,X as url,v as withAsync,g as withMessage,y as withParams,_ as withTooltip,ie as xor};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@regle/rules",
3
- "version": "1.19.13",
3
+ "version": "1.19.15-beta.1",
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.19.13"
39
+ "@regle/core": "1.19.15-beta.1"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/node": "24.10.13",