@regle/rules 1.19.16 → 1.20.0-preview.2

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.16
2
+ * @regle/rules v1.20.0-preview.2
3
3
  * (c) 2026 Victor Garcia
4
4
  * @license MIT
5
5
  */
@@ -149,7 +149,10 @@ interface ApplyIfOptions {
149
149
  *
150
150
  * @see {@link https://reglejs.dev/core-concepts/rules/rules-operators#applyif Documentation}
151
151
  */
152
- declare function applyIf<TRule extends FormRuleDeclaration<any>>(_condition: MaybeRefOrGetter<Maybe<boolean>>, rule: TRule, options?: ApplyIfOptions): TRule extends InlineRuleDeclaration<infer TValue, infer TParams, infer TReturn> ? RegleRuleDefinition<'applyIf', TValue, ParamsToLooseParams<TParams, [condition: boolean]>, TReturn extends Promise<any> ? true : false, TReturn extends Promise<infer M> ? M : TReturn> : TRule extends RegleRuleDefinition<infer TType, infer TValue, infer TParams, infer TAsync, infer TMetadata, any, any, any> ? RegleRuleDefinition<TType, TValue, ParamsToLooseParams<[...TParams], [condition: boolean]>, TAsync, TMetadata> : TRule extends RegleRuleWithParamsDefinitionInput<infer TType, infer TValue, infer TParams, infer TAsync, infer TMetadata, any> ? RegleRuleDefinition<TType, TValue, ParamsToLooseParams<[...TParams], [condition: boolean]>, TAsync, TMetadata> : TRule;
152
+ declare function applyIf<TType extends string | unknown, TValue, TParams extends [param?: any, ...any[]], TAsync extends boolean, TMetadata extends RegleRuleMetadataDefinition>(_condition: MaybeRefOrGetter<Maybe<boolean>>, rule: RegleRuleWithParamsDefinitionInput<TType, TValue, TParams, TAsync, TMetadata, any>, options?: ApplyIfOptions): RegleRuleDefinition<TType, TValue, ParamsToLooseParams<[...TParams]>, TAsync, TMetadata, MaybeInput<TValue>, TValue, false>;
153
+ declare function applyIf<TType extends string | unknown, TValue, TParams extends any[], TAsync extends boolean, TMetadata extends RegleRuleMetadataDefinition>(_condition: MaybeRefOrGetter<Maybe<boolean>>, rule: RegleRuleWithParamsDefinitionInput<TType, TValue, TParams, TAsync, TMetadata, any>, options?: ApplyIfOptions): RegleRuleDefinition<TType, TValue, ParamsToLooseParams<[...TParams]>, TAsync, TMetadata, MaybeInput<TValue>, TValue, false>;
154
+ declare function applyIf<TValue, TParams extends any[], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>>(_condition: MaybeRefOrGetter<Maybe<boolean>>, rule: InlineRuleDeclaration<TValue, TParams, TReturn>, options?: ApplyIfOptions): RegleRuleDefinition<'applyIf', TValue, ParamsToLooseParams<TParams>, TReturn extends Promise<any> ? true : false, TReturn extends Promise<infer M> ? M : TReturn, MaybeInput<TValue>, TValue, false>;
155
+ declare function applyIf<TType extends string | unknown, TValue, TParams extends any[], TAsync extends boolean, TMetadata extends RegleRuleMetadataDefinition>(_condition: MaybeRefOrGetter<Maybe<boolean>>, rule: RegleRuleDefinition<TType, TValue, TParams, TAsync, TMetadata, any, any, any>, options?: ApplyIfOptions): RegleRuleDefinition<TType, TValue, ParamsToLooseParams<[...TParams]>, TAsync, TMetadata, MaybeInput<TValue>, TValue, false>;
153
156
  /**
154
157
  * Checks if any value you provide is defined (including arrays and objects).
155
158
  * This is almost a must-have for optional fields when writing custom rules.
@@ -1,12 +1,11 @@
1
1
  /**
2
- * @regle/rules v1.19.16
2
+ * @regle/rules v1.20.0-preview.2
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";
10
9
 
11
10
  /**
12
11
  * Server side friendly way of checking for a File
@@ -172,29 +171,6 @@ function withParams(rule, depsArray) {
172
171
  return newRule(...depsArray);
173
172
  }
174
173
 
175
- /**
176
- * The `applyIf` operator is similar to `requiredIf`, but it can be used with **any rule**.
177
- * It simplifies conditional rule declarations.
178
- *
179
- * @param _condition - The condition to check (ref, getter, or value)
180
- * @param rule - The rule to apply conditionally
181
- * @returns A rule that only applies when the condition is truthy
182
- *
183
- * @example
184
- * ```ts
185
- * import { minLength, applyIf } from '@regle/rules';
186
- *
187
- * const condition = ref(false);
188
- *
189
- * const { r$ } = useRegle({ name: '' }, {
190
- * name: {
191
- * minLength: applyIf(condition, minLength(6))
192
- * },
193
- * });
194
- * ```
195
- *
196
- * @see {@link https://reglejs.dev/core-concepts/rules/rules-operators#applyif Documentation}
197
- */
198
174
  function applyIf(_condition, rule, options) {
199
175
  const { _type, validator, _params, _message, _async, _active } = extractValidator(rule);
200
176
  const augmentedParams = (_params ?? []).concat(options?.hideParams ? [] : [_condition]);
@@ -1161,6 +1137,35 @@ const contains = createStringOperationRule({
1161
1137
  operation: "contains"
1162
1138
  });
1163
1139
 
1140
+ /**
1141
+ * Checks if the value matches one or more regular expressions.
1142
+ *
1143
+ * @param regexp - A single RegExp or an array of RegExp patterns
1144
+ *
1145
+ * @example
1146
+ * ```ts
1147
+ * import { regex } from '@regle/rules';
1148
+ *
1149
+ * const { r$ } = useRegle({ name: '' }, {
1150
+ * name: {
1151
+ * regex: regex(/^foo/),
1152
+ * // or with multiple patterns
1153
+ * regex: regex([/^bar/, /baz$/]),
1154
+ * },
1155
+ * })
1156
+ * ```
1157
+ *
1158
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#regex Documentation}
1159
+ */
1160
+ const regex = createRule({
1161
+ type: "regex",
1162
+ validator(value, regexp) {
1163
+ if (isFilled(value)) return matchRegex(value, ...Array.isArray(regexp) ? regexp : [regexp]);
1164
+ return true;
1165
+ },
1166
+ message: "The value must match the required pattern"
1167
+ });
1168
+
1164
1169
  /**
1165
1170
  * Requires a string field to contain at least a given number of special characters.
1166
1171
  *
@@ -1185,8 +1190,8 @@ const containsSpecialCharacter = createRule({
1185
1190
  type: "containsSpecialCharacter",
1186
1191
  validator(value, minCharactersCount = 1) {
1187
1192
  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),
1193
+ if (isFilled(value)) return {
1194
+ $valid: regex(new RegExp(`^(?:.*[!@~\`#£€\$%^&*()_+\\-=[\\]{};':"\\\\|,.<>/?]){${minOccurrences},}.*$`)).exec(value),
1190
1195
  minCharactersCount: minOccurrences
1191
1196
  };
1192
1197
  return {
@@ -1221,8 +1226,8 @@ const containsUppercase = createRule({
1221
1226
  type: "containsUppercase",
1222
1227
  validator(value, minUppercaseCount = 1) {
1223
1228
  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),
1229
+ if (isFilled(value)) return {
1230
+ $valid: regex(new RegExp(`^(?:.*[A-Z]){${minOccurrences},}.*$`)).exec(value),
1226
1231
  minUppercaseCount: minOccurrences
1227
1232
  };
1228
1233
  return {
@@ -2287,35 +2292,6 @@ const oneOf = createRule({
2287
2292
  }
2288
2293
  });
2289
2294
 
2290
- /**
2291
- * Checks if the value matches one or more regular expressions.
2292
- *
2293
- * @param regexp - A single RegExp or an array of RegExp patterns
2294
- *
2295
- * @example
2296
- * ```ts
2297
- * import { regex } from '@regle/rules';
2298
- *
2299
- * const { r$ } = useRegle({ name: '' }, {
2300
- * name: {
2301
- * regex: regex(/^foo/),
2302
- * // or with multiple patterns
2303
- * regex: regex([/^bar/, /baz$/]),
2304
- * },
2305
- * })
2306
- * ```
2307
- *
2308
- * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#regex Documentation}
2309
- */
2310
- const regex = createRule({
2311
- type: "regex",
2312
- validator(value, regexp) {
2313
- if (isFilled(value)) return matchRegex(value, ...Array.isArray(regexp) ? regexp : [regexp]);
2314
- return true;
2315
- },
2316
- message: "The value must match the required pattern"
2317
- });
2318
-
2319
2295
  /**
2320
2296
  * Requires non-empty data. Checks for empty arrays and strings containing only whitespaces.
2321
2297
  *
@@ -1,7 +1,7 @@
1
1
  /**
2
- * @regle/rules v1.19.16
2
+ * @regle/rules v1.20.0-preview.2
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";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};
7
+ import{InternalRuleType as e,createRule as t,unwrapRuleParameters as n}from"@regle/core";import{capitalize as r,computed as i,effectScope as a,onScopeDispose as o,ref as s,toValue as c}from"vue";function l(e){return e?.constructor?.name==`File`}function u(e,t=!0,n=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):l(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:d(e)?e==null?!0:n?Object.keys(e).length===0:!1:!String(e).length}function d(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function f(e){return(d(e)||typeof e==`function`)&&`_validator`in e}function p(t){let n,r,i=[],a=``,o=!1,s;if(typeof t==`function`&&!(`_validator`in t))n=e.Inline,r=t,o=t.constructor.name===`AsyncFunction`;else if(f(t))({_type:n,validator:r,_message:a,_async:o,_params:i,_active:s}=t);else throw Error(`Cannot extract validator from invalid rule`);return{_type:n,validator:r,_params:i,_message:a,_async:o,_active:s}}function m(e,n){let{_type:r,validator:i,_active:a,_params:o,_async:s}=p(e),c=t({type:r,validator:i,active:a,message:n,async:s}),l=o??[];if(c._params=l,c._message_patched=!0,typeof c==`function`){if(o!=null){let e=c(...l);return e._message_patched=!0,e}return c}else return c}function h(e,n){let{_type:r,validator:i,_active:a,_params:o,_message:s,_async:c}=p(e),l=t({type:r,validator:i,active:a,message:s,tooltip:n,async:c}),u=o??[];if(l._params=u,l._tooltip_patched=!0,typeof l==`function`){let e=l(...u);return l._tooltip_patched=!0,e}else return l}function g(n,r){let i,{_type:a,_params:o,_message:s,_active:c}=p(n);i=typeof n==`function`?async(e,...t)=>n(e,...t):async(...e)=>n.validator(e);let l=(o??[])?.concat(r),u=t({type:a??e.Async,validator:i,message:s,async:!0,active:c});return u._params=l,u(...r??[])}function _(n,r){let i,{_type:a,_params:o,_message:s,_active:c,_async:l}=p(n);i=typeof n==`function`?(e,...t)=>n(e,...t):n.validator;let u=(o??[])?.concat(r),d=t({type:a??e.Inline,validator:i,message:s,active:c,async:l});return d._params=u,d(...r)}function v(e,r,i){let{_type:a,validator:o,_params:s,_message:c,_async:l,_active:u}=p(r),d=(s??[]).concat(i?.hideParams?[]:[e]);function f(t,...r){let[i]=n([e]);return i?o(t,...r):!0}function m(t){let[r]=n([e]);return r?typeof u==`function`?u(t):u??!0:!1}let h=t({type:a,validator:f,active:m,message:c,async:l});return h._params=d,typeof h==`function`?h(...d):h}function y(e){if(u(e))return!1;let t=null;if(e instanceof Date)t=e;else if(typeof e==`string`){let n=new Date(e);if(n.toString()===`Invalid Date`)return!1;t=n}return!!t}function b(e){let t=Object.prototype.toString.call(e);return e==null?new Date(NaN):e instanceof Date||typeof e==`object`&&t===`[object Date]`?new Date(e.getTime()):typeof e==`number`||t===`[object Number]`||typeof e==`string`||t===`[object String]`?new Date(e):new Date(NaN)}function x(e,t,{immediate:n=!1,trackDebounceRef:r}={}){let i,a=(...a)=>{r&&(r.value=!0);function o(){r&&(r.value=!1)}return new Promise((r,s)=>{function c(e){r(e),o()}if(clearTimeout(i),i=setTimeout(()=>{if(o(),i=void 0,!n)try{Promise.resolve(e.apply(this,[...a])).then(c).catch(e=>s(e)).finally(o)}catch(e){s(e)}},t),n){o();try{Promise.resolve(e.apply(this,[...a])).then(c).catch(e=>s(e)).finally(o)}catch(e){s(e)}}})};return a.cancel=()=>{clearTimeout(i),i=void 0,r&&(r.value=!1)},a}function S(e){return e===void 0?`0 bytes`:e<1024?`${e} bytes`:e<1024*1024?`${(e/1024).toFixed(2)} kb`:e<1024*1024*1024?`${(e/1024/1024).toFixed(2)} mb`:`${(e/1024/1024/1024).toFixed(2)} gb`}function C(e,t=!0,n=!0){return!u(typeof e==`string`?e.trim():e,t,n)}function w(e){return e==null?!1:typeof e==`number`?!isNaN(e):!1}function T(e,...t){if(u(e))return!0;let n=typeof e==`number`?e.toString():e;return t.every(e=>(e.lastIndex=0,e.test(n)))}function E(e){let t=c(e);return Array.isArray(t)?t.length:typeof t==`object`?Object.keys(t).length:typeof t==`number`?isNaN(t)?0:t:String(t).length}function D(e){return typeof e==`number`?e:e==null?NaN:typeof e==`string`&&e.trim()===e?+e:NaN}function O(e){return e==null?!1:typeof e==`string`}function ee(e){return e.some(e=>typeof e==`function`?e.constructor.name===`AsyncFunction`:e._async)}function k(e){return e.map(e=>{if(typeof e==`function`)return null;{let t=e._params;return t?.length?t:[]}}).flat().filter(e=>!!e)}function A(e,t,...n){let r=[],i=0;for(let a of e)if(typeof a==`function`)r.push(a(t)),i++;else{let e=a._params?.length??0;r.push(a.validator(t,...n.slice(i,i+e))),e&&(i+=e)}return r}function j(e,t,n){let r=e=>typeof e==`boolean`?!!e:e.$valid;return n===`xor`?t.length>1?t.filter(r).length===1:t.every(r):t[n===`and`?`every`:`some`](r)}function M(e,t,n){return t.some(e=>typeof e!=`boolean`)?{$valid:j(e,t,n),...t.reduce((e,t)=>{if(typeof t==`boolean`)return e;let{$valid:n,...r}=t;return{...e,...r}},{})}:j(e,t,n)}function N(e,n){let{mode:r,message:i}=n,a=ee(e),o=k(e),s;s=e.length?a?async(t,...n)=>M(t,await Promise.all(A(e,t,...n)),r):(t,...n)=>M(t,A(e,t,...n),r):e=>!1;let c=t({type:r,validator:s,message:i}),l=[...o??[]];return c._params=l,typeof c==`function`?c(...l):c}function te(...e){return N(e,{mode:`and`,message:`The value does not match all of the provided validators`})}function ne(...e){return N(e,{mode:`or`,message:`The value does not match any of the provided validators`})}function re(...e){return N(e,{mode:`xor`,message:`The value does not match exactly one of the provided validators`})}function ie(e,n){let i,{_type:a,validator:o,_params:s,_async:c,_active:l}=p(e);i=c?async(e,...t)=>{if(C(e))try{return!await o(e,...t)}catch{return!0}return!0}:(e,...t)=>C(e)?!o(e,...t):!0;let u=t({type:a?`not(${r(a)})`:void 0,validator:i,message:n??`Error`,active:l,async:c}),d=[...s??[]];return u._params=d,typeof u==`function`?u(...d):u}function P(e,t,n){return Object.entries(c(t)).map(([t,r])=>typeof r==`function`||d(r)&&`_validator`in r?[t,v(n?e:()=>!c(e),r)]:[t,r])}function ae(e,t,n){let r=P(e,t,!0),i=n?P(e,n,!1):[];return Object.fromEntries([...r,...i])}function oe(e,t,n){return e.run(()=>i(()=>n===0?!0:Array.from(t.value.entries()).slice(0,n).every(([,e])=>e===!0)))}function se({validator:e,index:t,isAsync:n,mappedResults:r,options:i}){return n?x(async(n,...i)=>{r.value.set(t,!1);let a=await e(n,...i),o=typeof a==`boolean`?a:a?.$valid??!1;return r.value.set(t,o),a},i?.debounce??200):(n,...i)=>{r.value.set(t,!1);let a=e(n,...i);if(a instanceof Promise)return!1;let o=typeof a==`boolean`?a:a?.$valid??!1;return r.value.set(t,o),a}}function F(...n){let r=[],i=s(new Map),c=[],l=n[0],u=Array.isArray(l)?l:n,f=Array.isArray(l)&&d(n[1])?n[1]:void 0;for(let[e,n]of u.entries()){let o=a();c.push(o);let{_type:s,validator:l,_params:u,_message:d,_async:m,_active:h}=p(n),g=t({type:s,validator:se({validator:l,mappedResults:i,index:e,isAsync:m,options:f}),active:h,async:m,message:d});g._params=u;let _;_=typeof g==`function`?g(...u??[]):g;let y=oe(o,i,e),b=e>0&&r[e-1]._async,x=v(y,_,{hideParams:!b});r.push(x)}return o(()=>{c.forEach(e=>e.stop()),c=[]}),{...Object.fromEntries(r.map((t,n)=>[t.type&&t.type!==e.Inline?t.type:`anonymous${n}`,t])),$debounce:0}}const I=/^https?$/,L=/^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/,R=/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?$/i;function z(){return RegExp(`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`,`u`)}const B=/^[^A-Z]*$/,V=/^[^a-z]*$/,H=/^[0-9a-fA-F]*$/,U=/^[a-zA-Z]*$/,W=/^[\w.]+$/,G=/^[a-zA-Z0-9]*$/,K=/^[a-zA-Z0-9_]*$/,ce=/^[-]?\d*(\.\d+)?$/,le=/^(?:[A-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]{2,}(?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i,ue=/(^[0-9]*$)|(^-[0-9]+$)/,de=/^\d*(\.\d+)?$/,fe=t({type:`alpha`,validator(e,t){return u(e)?!0:t?.allowSymbols?T(e,W):T(e,U)},message:`The value must be alphabetical`}),pe=t({type:`alphaNum`,validator(e,t){return u(e)?!0:t?.allowSymbols?T(e,K):T(e,G)},message:`The value must be alpha-numeric`}),me=t({type:`atLeastOne`,validator:(e,t)=>C(e,!0,!1)&&d(e)?t?.length?t.some(t=>C(e[t])):E(e)>0:!0,message:`At least one item is required`}),he=t({type:`between`,validator:(e,t,n,r)=>{let{allowEqual:i=!0}=r??{};if(C(e)&&C(t)&&C(n)){let r=D(e),a=D(t),o=D(n);return w(r)&&w(a)&&w(o)?i?r>=a&&r<=o:r>a&&r<o:!0}return!0},message:({$params:[e,t]})=>`The value must be between ${e} and ${t}`}),ge=t({type:`boolean`,validator:e=>C(e)?typeof e==`boolean`:!0,message:`The value must be a native boolean`}),_e=t({type:`checked`,validator:e=>e===!0,message:`The field must be checked`,required:!0});function q({type:e,operation:n}){let r=(e,t)=>{switch(n){case`contains`:return e.includes(t);case`startsWith`:return e.startsWith(t);case`endsWith`:return e.endsWith(t)}},i=e=>{switch(n){case`contains`:return`The value must contain ${e}`;case`startsWith`:return`The value must start with ${e}`;case`endsWith`:return`The value must end with ${e}`}};return t({type:e,validator(e,t){return C(e)&&C(t)&&O(e)&&O(t)?r(e,t):!0},message({$params:[e]}){return i(e)}})}const ve=q({type:`contains`,operation:`contains`}),J=t({type:`regex`,validator(e,t){return C(e)?T(e,...Array.isArray(t)?t:[t]):!0},message:`The value must match the required pattern`}),ye=t({type:`containsSpecialCharacter`,validator(e,t=1){let n=Number.isFinite(t)?Math.max(1,Math.floor(t)):1;return C(e)?{$valid:J(RegExp(`^(?:.*[!@~\`#£€\$%^&*()_+\\-=[\\]{};':"\\\\|,.<>/?]){${n},}.*$`)).exec(e),minCharactersCount:n}:{$valid:!0,minCharactersCount:n}},message({minCharactersCount:e}){return`This field must contain at least ${e} special character${e>1?`s`:``}`}}),be=t({type:`containsUppercase`,validator(e,t=1){let n=Number.isFinite(t)?Math.max(1,Math.floor(t)):1;return C(e)?{$valid:J(RegExp(`^(?:.*[A-Z]){${n},}.*$`)).exec(e),minUppercaseCount:n}:{$valid:!0,minUppercaseCount:n}},message:({minUppercaseCount:e})=>`This field must contain at least ${e} uppercase letter${e>1?`s`:``}`}),xe=t({type:`date`,validator:e=>C(e)?e instanceof Date:!0,message:`The value must be a native Date`});function Se(){return navigator.languages==null?navigator.language??`en-US`:navigator.languages[0]}function Y(e){return e?new Intl.DateTimeFormat(Se(),{dateStyle:`short`}).format(new Date(e)):`?`}const Ce=t({type:`dateAfter`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return C(e)&&C(t)?y(e)&&y(t)?(r?b(e).getTime()>=b(t).getTime():b(e).getTime()>b(t).getTime())?!0:{$valid:!1,error:`date-not-after`}:{$valid:!1,error:`value-or-parameter-not-a-date`}:!0},message:({$params:[e],error:t})=>t===`value-or-parameter-not-a-date`?`The values must be dates`:`The date must be after ${Y(e)}`}),we=t({type:`dateBefore`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return C(e)&&C(t)?y(e)&&y(t)?(r?b(e).getTime()<=b(t).getTime():b(e).getTime()<b(t).getTime())?!0:{$valid:!1,error:`date-not-before`}:{$valid:!1,error:`value-or-parameter-not-a-date`}:!0},message:({$params:[e],error:t})=>t===`value-or-parameter-not-a-date`?`The values must be dates`:`The date must be before ${Y(e)}`}),Te=t({type:`dateBetween`,validator:(e,t,n,r)=>{let{allowEqual:i=!0}=r??{};return y(e)&&y(t)&&y(n)?i?b(e).getTime()>=b(t).getTime()&&b(e).getTime()<=b(n).getTime():b(e).getTime()>b(t).getTime()&&b(e).getTime()<b(n).getTime():!0},message:({$params:[e,t]})=>`The date must be between ${Y(e)} and ${Y(t)}`}),Ee=t({type:`decimal`,validator(e){return u(e)?!0:T(e,ce)},message:`The value must be decimal`}),De=t({type:`email`,validator(e){return u(e)?!0:T(e,le)},message:`The value must be a valid email address`}),Oe=t({type:`emoji`,validator(e){return u(e)?!0:z().test(e)},message:`The value should be a valid emoji`}),ke=q({type:`endsWith`,operation:`endsWith`}),Ae=t({type:`exactDigits`,validator:(e,t)=>{if(C(e,!1)&&C(t)){if(w(t)){let n=RegExp(`^\\d{${t}}$`);return T(e.toString(),n)}return!0}return!0},message:({$params:[e]})=>`The value should have exactly ${e} digits`}),je=t({type:`exactLength`,validator:(e,t)=>C(e,!1)&&C(t)?w(t)?E(e)===t:!1:!0,message:({$params:[e]})=>`The value must be exactly ${e} characters long`}),Me=t({type:`exactValue`,validator:(e,t)=>C(e)&&C(t)&&w(t)&&!isNaN(D(e))?D(e)===t:!0,message:({$params:[e]})=>`The value must be equal to ${e}`}),Ne=t({type:`file`,validator:e=>C(e)?l(e):!0,message:`The value must be a native File`}),Pe=t({type:`fileType`,validator:(e,t)=>C(e)&&l(e)?t.includes(e.type):!0,message({$params:[e]}){return`File type is not allowed. Allowed types are: ${e.map(e=>e.split(`/`)[1]).join(`, `)}.`}}),Fe=t({type:`hexadecimal`,validator(e){return u(e)?!0:T(e,H)},message:`The value must be hexadecimal`}),Ie=t({type:`hostname`,validator(e){return u(e)?!0:T(e,L)},message:`The value is not a valid hostname`}),X=t({type:`url`,validator(e,t={}){try{if(u(e))return!0;let{protocol:n}=t||{},r=new URL(e);return!L.test(r.hostname)||n&&!n.test(r.protocol.endsWith(`:`)?r.protocol.slice(0,-1):r.protocol)?!1:T(e,R)}catch{return!1}},message:`The value must be a valid URL`}),Le=t({type:`httpUrl`,validator(e,t={}){if(u(e))return!0;let{protocol:n=I}=t||{};return X({protocol:n}).exec(e)},message:`The value is not a valid http URL address`}),Re=t({type:`integer`,validator(e){return u(e)?!0:T(e,ue)},message:`The value must be an integer`});function ze(e){if(e.length>3||e.length===0||e[0]===`0`&&e!==`0`||!e.match(/^\d+$/))return!1;let t=e|0;return t>=0&&t<=255}const Be=t({type:`ipv4Address`,validator(e){if(u(e))return!0;if(typeof e!=`string`)return!1;let t=e.split(`.`);return t.length===4&&t.every(ze)},message:`The value is not a valid IPv4 address`});function Ve(e){return m(_((e,t)=>C(e)&&C(t)?t===e:!0,[i(()=>c(e))]),({$params:[e]})=>`Value should be ${e}.`)}const He=t({type:`lowercase`,validator(e){return u(e)?!0:T(e,B)},message:`The value must be lowercase`}),Ue=t({type:`macAddress`,validator(e,t=`:`){if(u(e))return!0;if(typeof e!=`string`)return!1;let n=typeof t==`string`&&t!==``?e.split(t):e.length===12||e.length===16?e.match(/.{2}/g):null;return n!==null&&(n.length===6||n.length===8)&&n.every(We)},message:`The value is not a valid MAC Address`}),We=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/),Ge=t({type:`maxFileSize`,validator:(e,t)=>C(e)&&l(e)?{$valid:e.size<=t,fileSize:e.size}:!0,message({$params:[e],fileSize:t}){return`File size (${S(t)}) cannot exceed ${S(e)}`}});function Z({type:e,direction:n}){let r=(e,t,r)=>n===`min`?r?e>=t:e>t:r?e<=t:e<t,i=(e,t)=>Array.isArray(e)?n===`min`?`The list must have at least ${t} items`:`The list must have at most ${t} items`:n===`min`?`The value must be at least ${t} characters long`:`The value must be at most ${t} characters long`;return t({type:e,validator:(e,t,n)=>{let{allowEqual:i=!0}=n??{};return C(e,!1)&&C(t)&&w(t)?r(E(e),t,i):!0},message:({$value:e,$params:[t]})=>i(e,t)})}const Ke=Z({type:`maxLength`,direction:`max`});function Q({type:e,direction:n}){let r=(e,t,r)=>n===`min`?r?e>=t:e>t:r?e<=t:e<t,i=(e,t)=>n===`min`?t?`The value must be greater than or equal to ${e}`:`The value must be greater than ${e}`:t?`The value must be less than or equal to ${e}`:`The value must be less than ${e}`;return t({type:e,validator:(e,t,n)=>{let{allowEqual:i=!0}=n??{};return C(e)&&C(t)&&!isNaN(D(e))&&!isNaN(D(t))?r(D(e),D(t),i):!0},message:({$params:[e,t]})=>{let{allowEqual:n=!0}=t??{};return i(e,n)}})}const qe=Q({type:`maxValue`,direction:`max`}),Je=t({type:`minFileSize`,validator:(e,t)=>C(e)&&l(e)?{$valid:e.size>=t,fileSize:e.size}:!0,message({$params:[e],fileSize:t}){return`File size (${S(t)}) must be at least ${S(e)}`}}),$=Z({type:`minLength`,direction:`min`}),Ye=Q({type:`minValue`,direction:`min`});function Xe(e){let t=Object.keys(e).filter(t=>typeof e[e[t]]!=`number`),n={};for(let r of t)n[r]=e[r];return Object.values(n)}function Ze(e){return m(_((e,t)=>C(e)&&!u(t)?Xe(t).includes(e):!0,[i(()=>c(e))]),({$params:[e]})=>`The value must be one of the following: ${Object.values(e).join(`, `)}`)}const Qe=t({type:`number`,validator:e=>C(e)?w(e):!0,message:`The value must be a native number`}),$e=t({type:`numeric`,validator(e){return u(e)?!0:T(e,de)},message:`The value must be numeric`}),et=t({type:`oneOf`,validator(e,t){return C(e)&&C(t,!1)?Array.isArray(t)?t.includes(e):Object.values(t).includes(e):!0},message:({$params:[e]})=>`The value must be one of the following: ${(Array.isArray(e)?e:Object.values(e)).join(`, `)}`}),tt=t({type:`required`,validator:e=>C(e,!0,!1),message:`This field is required`,required:!0}),nt=t({type:`required`,validator(e,t){return t?C(e):!0},message:`This field is required`,active({$params:[e]}){return e}}),rt=t({type:`required`,validator(e,t){return t?!0:C(e)},message:`This field is required`,active({$params:[e]}){return!e}}),it=t({type:`sameAs`,validator(e,t,n){return u(e)?!0:e===t},message({$params:[e,t=`other`]}){return`The value must be equal to the ${t} value`}}),at=q({type:`startsWith`,operation:`startsWith`}),ot=t({type:`string`,validator:e=>C(e)?typeof e==`string`:!0,message:`The value must be a string`});function st(){return(()=>!0)}const ct=t({type:`uppercase`,validator(e){return u(e)?!0:T(e,V)},message:`The value must be uppercase`});export{fe as alpha,pe as alphaNum,te as and,v as applyIf,ae as assignIf,me as atLeastOne,he as between,ge as boolean,_e as checked,ve as contains,ye as containsSpecialCharacter,be as containsUppercase,xe as date,Ce as dateAfter,we as dateBefore,Te as dateBetween,Ee as decimal,De as email,Oe as emoji,ke as endsWith,Ae as exactDigits,je as exactLength,Me as exactValue,Ne as file,Pe as fileType,E as getSize,Fe as hexadecimal,Ie as hostname,Le as httpUrl,Re as integer,Be as ipv4Address,y as isDate,u as isEmpty,C as isFilled,w as isNumber,Ve as literal,He as lowercase,Ue as macAddress,T as matchRegex,Ge as maxFileSize,Ke as maxLength,qe as maxValue,Je as minFileSize,$ as minLength,Ye as minValue,Ze as nativeEnum,ie as not,Qe as number,$e as numeric,et as oneOf,ne as or,F as pipe,J as regex,tt as required,nt as requiredIf,rt as requiredUnless,it as sameAs,at as startsWith,ot as string,b as toDate,D as toNumber,st as type,ct as uppercase,X as url,g as withAsync,m as withMessage,_ as withParams,h as withTooltip,re as xor};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@regle/rules",
3
- "version": "1.19.16",
3
+ "version": "1.20.0-preview.2",
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.16"
39
+ "@regle/core": "1.20.0-preview.2"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/node": "24.10.13",
@@ -45,12 +45,13 @@
45
45
  "tsdown": "0.20.3",
46
46
  "type-fest": "5.4.4",
47
47
  "typescript": "5.9.3",
48
+ "@typescript/native-preview": "7.0.0-dev.20260303.1",
48
49
  "vitest": "4.0.18",
49
50
  "vue": "3.5.28",
50
51
  "vue-tsc": "3.2.5"
51
52
  },
52
53
  "scripts": {
53
- "typecheck": "tsc --noEmit",
54
+ "typecheck": "tsgo --noEmit",
54
55
  "build": "tsdown",
55
56
  "build:sourcemaps": "tsdown --config=tsdown.sourcemap.ts",
56
57
  "dev": "tsdown --config=tsdown.dev.ts --watch",