@regle/rules 1.1.0-beta.4 → 1.1.0-beta.6

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,4 +1,4 @@
1
- import { RegleRuleMetadataDefinition, RegleRuleWithParamsDefinition, RegleRuleDefinitionWithMetadataProcessor, RegleRuleMetadataConsumer, RegleRuleDefinition, InlineRuleDeclaration, UnwrapRegleUniversalParams, Maybe, FormRuleDeclaration, CommonComparationOptions } from '@regle/core';
1
+ import { RegleRuleMetadataDefinition, RegleRuleWithParamsDefinition, RegleRuleDefinitionWithMetadataProcessor, RegleRuleMetadataConsumer, RegleRuleDefinition, InlineRuleDeclaration, UnwrapRegleUniversalParams, Maybe, FormRuleDeclaration, CommonComparisonOptions, CommonAlphaOptions } from '@regle/core';
2
2
  import { Ref, MaybeRefOrGetter, MaybeRef } from 'vue';
3
3
 
4
4
  /**
@@ -206,10 +206,11 @@ declare const required: RegleRuleDefinition<unknown, [], false, boolean, unknown
206
206
  * Requires the input value to have a maximum specified length, inclusive. Works with arrays, objects and strings.
207
207
  *
208
208
  * @param max - the maximum length
209
+ * @param options - comparision options
209
210
  */
210
211
  declare const maxLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [
211
212
  count: number,
212
- options?: CommonComparationOptions
213
+ options?: CommonComparisonOptions
213
214
  ], false, boolean>;
214
215
 
215
216
  /**
@@ -221,16 +222,20 @@ declare const requiredIf: RegleRuleWithParamsDefinition<unknown, [condition: boo
221
222
 
222
223
  /**
223
224
  * Allows only alphabetic characters.
225
+ *
226
+ * @param [options] - Alpha rules options
224
227
  * */
225
228
  declare const alpha: RegleRuleWithParamsDefinition<string, [
226
- allowSymbols?: boolean | undefined
229
+ options?: CommonAlphaOptions | undefined
227
230
  ], false, boolean, string>;
228
231
 
229
232
  /**
230
233
  * Allows only alphanumeric characters.
234
+ *
235
+ * @param [options] - Alpha rules options
231
236
  */
232
237
  declare const alphaNum: RegleRuleWithParamsDefinition<string | number, [
233
- allowSymbols?: boolean | undefined
238
+ options?: CommonAlphaOptions | undefined
234
239
  ], false, boolean, string | number>;
235
240
 
236
241
  /**
@@ -242,7 +247,7 @@ declare const alphaNum: RegleRuleWithParamsDefinition<string | number, [
242
247
  declare const between: RegleRuleWithParamsDefinition<number, [
243
248
  min: number,
244
249
  max: number,
245
- options?: CommonComparationOptions
250
+ options?: CommonComparisonOptions
246
251
  ], false, boolean>;
247
252
 
248
253
  /**
@@ -264,32 +269,38 @@ declare const integer: RegleRuleDefinition<string | number, [], false, boolean,
264
269
  * Requires a field to have a specified maximum numeric value.
265
270
  *
266
271
  * @param max - the maximum value
272
+ * @param options - comparision options
267
273
  */
268
274
  declare const maxValue: RegleRuleWithParamsDefinition<number, [
269
275
  count: number,
270
- options?: CommonComparationOptions
276
+ options?: CommonComparisonOptions
271
277
  ], false, boolean>;
272
278
 
273
279
  /**
274
280
  * Requires the input value to have a minimum specified length, inclusive. Works with arrays, objects and strings.
275
281
  *
276
282
  * @param min - the minimum value
283
+ * @param options - comparision options
277
284
  */
278
285
  declare const minLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [
279
286
  count: number,
280
- options?: CommonComparationOptions
287
+ options?: CommonComparisonOptions
281
288
  ], false, boolean>;
282
289
 
283
290
  /**
284
291
  * Requires a field to have a specified minimum numeric value.
285
292
  *
286
293
  * @param count - the minimum count
294
+ * @param options - comparision options
287
295
  */
288
296
  declare const minValue: RegleRuleWithParamsDefinition<number, [
289
297
  count: number,
290
- options?: CommonComparationOptions
298
+ options?: CommonComparisonOptions
291
299
  ], false, boolean>;
292
300
 
301
+ /**
302
+ * Requires a field to have a strict numeric value.
303
+ */
293
304
  declare const exactValue: RegleRuleWithParamsDefinition<number, [count: number], false, boolean>;
294
305
 
295
306
  /**
@@ -1 +1 @@
1
- import {createRule,InternalRuleType,unwrapRuleParameters}from'@regle/core';import {unref,computed,toValue}from'vue';function M(e,t){let r,n,s,R;typeof e=="function"&&!("_validator"in e)?(r=InternalRuleType.Inline,n=e):{_type:r,validator:n,_active:s,_params:R}=e;let l=createRule({type:r,validator:n,active:s,message:t}),u=[...R??[]];if(l._params=u,l._message_patched=true,typeof l=="function"){let a=l(...u);return a._message_patched=true,a}else return l}function _(e,t){let r,n,s,R,l;typeof e=="function"&&!("_validator"in e)?(r=InternalRuleType.Inline,n=e):{_type:r,validator:n,_active:s,_params:R,_message:l}=e;let u=createRule({type:r,validator:n,active:s,message:l,tooltip:t}),a=[...R??[]];if(u._params=a,u._tooltip_patched=true,typeof u=="function"){let m=u(...a);return u._tooltip_patched=true,m}else return u}function E(e,t){let r,n,s=[],R="";typeof e=="function"?(r=InternalRuleType.Inline,n=async(u,...a)=>e(u,...a),s=[t]):({_type:r,_message:R}=e,s=s=e._params?.concat(t),n=async(...u)=>e.validator(u));let l=createRule({type:InternalRuleType.Async,validator:n,message:R});return l._params=l._params?.concat(s),l(...t??[])}function P(e,t){let r,n,s=[],R="";typeof e=="function"?(r=InternalRuleType.Inline,n=(u,...a)=>e(u,...a),s=[t]):({_type:r,validator:n,_message:R}=e,s=s=e._params?.concat(t));let l=createRule({type:InternalRuleType.Inline,validator:n,message:R});return l._params=l._params?.concat(s),l(...t)}function S(e,t){let r,n,s=[],R="";typeof t=="function"?(r=InternalRuleType.Inline,n=t,s=[e]):({_type:r,validator:n,_message:R}=t,s=t._params?.concat([e]));function l(o,...y){let[b]=unwrapRuleParameters([e]);return b?n(o,...y):true}function u(o){let[y]=unwrapRuleParameters([e]);return y}let a=createRule({type:r,validator:l,active:u,message:R}),m=[...s??[]];return a._params=m,typeof a=="function"?a(...m):a}function f(e,t=true){return e==null?true:e instanceof Date?isNaN(e.getTime()):e.constructor.name=="File"||e.constructor.name=="FileList"?e.size<=0:Array.isArray(e)?t?e.length===0:false:typeof e=="object"&&e!=null?Object.keys(e).length===0:!String(e).length}function x(e){if(f(e))return false;try{let t=null;if(e instanceof Date)t=e;else if(typeof e=="string"){let r=new Date(e);if(r.toString()==="Invalid Date")return !1;t=r;}return !!t}catch{return false}}function T(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]"?new Date(e):typeof e=="string"||t==="[object String]"?new Date(e):new Date(NaN)}function i(e,t=true){return !f(typeof e=="string"?e.trim():e,t)}function c(e){return e==null||typeof e!="number"?false:!isNaN(e)}function p(e,...t){if(f(e))return true;let r=typeof e=="number"?e.toString():e;return t.every(n=>(n.lastIndex=0,n.test(r)))}function h(e){let t=unref(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 g(e){return typeof e=="number"?e:e!=null?typeof e=="string"?e.trim()!==e?NaN:+e:NaN:NaN}function q(...e){let t=e.some(a=>typeof a=="function"?a.constructor.name==="AsyncFunction":a._async),r=e.map(a=>{if(typeof a=="function")return null;{let m=a._params;return m?.length?m:[]}}).flat().filter(a=>!!a);function n(a,m,...o){let y=[],b=0;for(let d of a)if(typeof d=="function")y.push(d(m)),b++;else {let D=d._params?.length??0;y.push(d.validator(m,...o.slice(b,D))),D&&(b+=D);}return y}function s(a){return a?.some(o=>typeof o!="boolean")?{$valid:a.every(o=>typeof o=="boolean"?!!o:o.$valid),...a.reduce((o,y)=>{if(typeof y=="boolean")return o;let{$valid:b,...d}=y;return {...o,...d}},{})}:a.every(o=>!!o)}let R;e.length?R=t?async(a,...m)=>{let o=await Promise.all(n(e,a,...m));return s(o)}:(a,...m)=>{let o=n(e,a,...m);return s(o)}:R=a=>false;let l=createRule({type:"and",validator:R,message:"The value does not match all of the provided validators"}),u=[...r??[]];return l._params=u,typeof l=="function"?l(...u):l}function G(...e){let t=e.some(a=>typeof a=="function"?a.constructor.name==="AsyncFunction":a._async),r=e.map(a=>typeof a=="function"?null:a._params).flat().filter(a=>!!a);function n(a,m,...o){let y=[],b=0;for(let d of a)if(typeof d=="function")y.push(d(m)),b++;else {let D=d._params?.length??0;y.push(d.validator(m,...o.slice(b,D))),D&&(b+=D);}return y}function s(a){return a.some(o=>typeof o!="boolean")?{$valid:a.some(o=>typeof o=="boolean"?!!o:o.$valid),...a.reduce((o,y)=>{if(typeof y=="boolean")return o;let{$valid:b,...d}=y;return {...o,...d}},{})}:a.some(o=>!!o)}let l=createRule({type:"or",validator:t?async(a,...m)=>{let o=await Promise.all(n(e,a,...m));return s(o)}:(a,...m)=>{let o=n(e,a,...m);return s(o)},message:"The value does not match any of the provided validators"}),u=[...r??[]];return l._params=u,typeof l=="function"?l(...u):l}function B(e,t){let r,n,s,R,l;typeof e=="function"?(n=e,l=e.constructor.name==="AsyncFunction"):({_type:r,validator:n,_params:R}=e,l=e._async),l?s=async(m,...o)=>i(m)?!await n(m,...o):true:s=(m,...o)=>i(m)?!n(m,...o):true;let u=createRule({type:"not",validator:s,message:t??"Error"}),a=[...R??[]];return u._params=a,typeof u=="function"?u(...a):u}var Qt=createRule({type:"required",validator:e=>i(e),message:"This field is required"});var er=createRule({type:"maxLength",validator:(e,t,r)=>{let{allowEqual:n=true}=r??{};return i(e,false)&&i(t)?c(t)?n?h(e)<=t:h(e)<t:(console.warn(`[maxLength] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),false):true},message:({$value:e,$params:[t]})=>Array.isArray(e)?`This list should have maximum ${t} items`:`The value length should not exceed ${t}`});var ar=createRule({type:"required",validator(e,t){return t?i(e):true},message:"This field is required",active({$params:[e]}){return e}});var X=/^[a-zA-Z]*$/,Y=/^[\w.]+$/,lr=createRule({type:"alpha",validator(e,t){return f(e)?true:t?p(e,Y):p(e,X)},message:"The value is not alphabetical"});var ee=/^[a-zA-Z0-9]*$/,te=/^[a-zA-Z0-9_]*$/,Rr=createRule({type:"alphaNum",validator(e,t){return f(e)?true:t?p(e,te):p(e,ee)},message:"The value must be alpha-numeric"});var gr=createRule({type:"between",validator:(e,t,r,n)=>{let{allowEqual:s=true}=n??{};if(i(e)&&i(t)&&i(r)){let R=g(e),l=g(t),u=g(r);return c(R)&&c(l)&&c(u)?s?R>=l&&R<=u:R>l&&R<u:(console.warn(`[between] Value or parameters aren't numbers, got value: ${e}, min: ${t}, max: ${r}`),false)}return true},message:({$params:[e,t]})=>`The value must be between ${e} and ${t}`});var ae=/^[-]?\d*(\.\d+)?$/,br=createRule({type:"decimal",validator(e){return f(e)?true:p(e,ae)},message:"The value must be decimal"});var oe=/^(?:[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,Pr=createRule({type:"email",validator(e){return f(e)?true:p(e,oe)},message:"The value must be an valid email address"});var le=/(^[0-9]*$)|(^-[0-9]+$)/,Vr=createRule({type:"integer",validator(e){return f(e)?true:p(e,le)},message:"The value must be an integer"});var Cr=createRule({type:"maxValue",validator:(e,t,r)=>{let{allowEqual:n=true}=r??{};return i(e)&&i(t)?c(t)&&!isNaN(g(e))?n?g(e)<=t:g(e)<t:(console.warn(`[maxValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),true):true},message:({$params:[e,t]})=>{let{allowEqual:r=true}=t??{};return r?`The value must be less than or equal to ${e}`:`The value must be less than ${e}`}});var Ir=createRule({type:"minLength",validator:(e,t,r)=>{let{allowEqual:n=true}=r??{};return i(e,false)&&i(t)?c(t)?n?h(e)>=t:h(e)>t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),false):true},message:({$value:e,$params:[t]})=>Array.isArray(e)?`The list should have at least ${t} items`:`The value length should be at least ${t}`});var zr=createRule({type:"minValue",validator:(e,t,r)=>{let{allowEqual:n=true}=r??{};return i(e)&&i(t)?c(t)&&!isNaN(g(e))?n?g(e)>=t:g(e)>t:(console.warn(`[minValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),true):true},message:({$params:[e,t]})=>{let{allowEqual:r=true}=t??{};return r?`The value must be greater than or equal to ${e}`:`The value must be greater than ${e}`}});var Gr=createRule({type:"exactValue",validator:(e,t)=>i(e)&&i(t)?c(t)&&!isNaN(g(e))?g(e)===t:(console.warn(`[exactValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),true):true,message:({$params:[e]})=>`The value must be equal to ${e}`});var Jr=createRule({type:"exactLength",validator:(e,t)=>i(e,false)&&i(t)?c(t)?h(e)===t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),false):true,message:({$params:[e]})=>`The value should be exactly ${e} characters long`});var ce=/^\d*(\.\d+)?$/,Yr=createRule({type:"numeric",validator(e){return f(e)?true:p(e,ce)},message:"The value must be numeric"});var rn=createRule({type:"required",validator(e,t){return t?true:i(e)},message:"This field is required",active({$params:[e]}){return !e}});var sn=createRule({type:"sameAs",validator(e,t,r="other"){return f(e)?true:e===t},message({$params:[e,t]}){return `The value must be equal to the ${t} value`}});var xe=/^(?:(?:(?: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,fn=createRule({type:"url",validator(e){return f(e)?true:p(e,xe)},message:"The value is not a valid URL address"});function be(){return navigator.languages!=null?navigator.languages[0]:navigator.language}function w(e){return e?new Intl.DateTimeFormat(be(),{dateStyle:"short"}).format(new Date(e)):"?"}var dn=createRule({type:"dateAfter",validator:(e,t)=>i(e)&&i(t)?x(e)&&x(t)?T(e).getTime()>T(t).getTime()?true:{$valid:false,error:"date-not-after"}:{$valid:false,error:"value-or-paramater-not-a-date"}:true,message:({$params:[e],error:t})=>t==="value-or-paramater-not-a-date"?"The values must be dates":`The date must be after ${w(e)}`});var Dn=createRule({type:"dateBefore",validator:(e,t)=>i(e)&&i(t)?x(e)&&x(t)?T(e).getTime()<T(t).getTime()?true:{$valid:false,error:"date-not-before"}:{$valid:false,error:"value-or-paramater-not-a-date"}:true,message:({$params:[e],error:t})=>t==="value-or-paramater-not-a-date"?"The fields must be dates":`The date must be before ${w(e)}`});var vn=createRule({type:"dateBetween",validator:(e,t,r)=>x(e)&&x(t)&&x(r)?T(e).getTime()>T(t).getTime()&&T(e).getTime()<T(r).getTime():true,message:({$params:[e,t]})=>`The date must be between ${w(e)} and ${w(t)}`});function we(e){if(e.length>3||e.length===0||e[0]==="0"&&e!=="0"||!e.match(/^\d+$/))return false;let t=+e|0;return t>=0&&t<=255}var Fn=createRule({type:"ipv4Address",validator(e){if(f(e))return true;if(typeof e!="string")return false;let t=e.split(".");return t.length===4&&t.every(we)},message:"The value is not a valid IPv4 address"});var En=createRule({type:"macAddress",validator(e,t=":"){if(f(e))return true;if(typeof e!="string")return false;let r=typeof t=="string"&&t!==""?e.split(t):e.length===12||e.length===16?e.match(/.{2}/g):null;return r!==null&&(r.length===6||r.length===8)&&r.every(ve)},message:"The value is not a valid MAC Address"}),ve=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/);var Sn=createRule({type:"checked",validator:e=>i(e)?e===true:true,message:"The value must be checked"});var Un=createRule({type:"contains",validator(e,t){return i(e)&&i(t)?e.includes(t):true},message({$params:[e]}){return `The value must contain ${e}`}});var Zn=createRule({type:"startsWith",validator(e,t){return i(e)&&i(t)?e.startsWith(t):true},message({$params:[e]}){return `The value must end with ${e}`}});var Xn=createRule({type:"endsWith",validator(e,t){return i(e)&&i(t)?e.endsWith(t):true},message({$params:[e]}){return `The value must end with ${e}`}});var ta=createRule({type:"regex",validator(e,t){if(i(e)){let r=Array.isArray(t)?t:[t];return p(e,...r)}return true},message:"The value does not match the required pattern"});function ia(e){let t=computed(()=>toValue(e));return M(P((n,s)=>i(n)&&i(s,false)?s.includes(n):true,[t]),({$params:[n]})=>`The value should be one of those options: ${n.join(", ")}.`)}function Oe(e){let t=Object.keys(e).filter(n=>typeof e[e[n]]!="number"),r={};for(let n of t)r[n]=e[n];return Object.values(r)}function ua(e){let t=computed(()=>toValue(e));return M(P((n,s)=>i(n)&&!f(s)?Oe(s).includes(n):true,[t]),({$params:[n]})=>`The value should be one of those options: ${Object.values(n).join(", ")}.`)}function ya(e){let t=computed(()=>toValue(e));return M(P((n,s)=>s===n,[t]),({$params:[n]})=>`Value should be ${n}.`)}export{lr as alpha,Rr as alphaNum,q as and,S as applyIf,gr as between,Sn as checked,Un as contains,dn as dateAfter,Dn as dateBefore,vn as dateBetween,br as decimal,Pr as email,Xn as endsWith,Jr as exactLength,Gr as exactValue,h as getSize,Vr as integer,Fn as ipv4Address,x as isDate,f as isEmpty,i as isFilled,c as isNumber,ya as literal,En as macAddress,p as matchRegex,er as maxLength,Cr as maxValue,Ir as minLength,zr as minValue,ua as nativeEnum,B as not,Yr as numeric,ia as oneOf,G as or,ta as regex,Qt as required,ar as requiredIf,rn as requiredUnless,sn as sameAs,Zn as startsWith,T as toDate,g as toNumber,fn as url,E as withAsync,M as withMessage,P as withParams,_ as withTooltip};
1
+ import {createRule,InternalRuleType,unwrapRuleParameters}from'@regle/core';import {unref,computed,toValue}from'vue';function M(e,t){let r,n,s,R;typeof e=="function"&&!("_validator"in e)?(r=InternalRuleType.Inline,n=e):{_type:r,validator:n,_active:s,_params:R}=e;let l=createRule({type:r,validator:n,active:s,message:t}),u=[...R??[]];if(l._params=u,l._message_patched=true,typeof l=="function"){let a=l(...u);return a._message_patched=true,a}else return l}function _(e,t){let r,n,s,R,l;typeof e=="function"&&!("_validator"in e)?(r=InternalRuleType.Inline,n=e):{_type:r,validator:n,_active:s,_params:R,_message:l}=e;let u=createRule({type:r,validator:n,active:s,message:l,tooltip:t}),a=[...R??[]];if(u._params=a,u._tooltip_patched=true,typeof u=="function"){let m=u(...a);return u._tooltip_patched=true,m}else return u}function E(e,t){let r,n,s=[],R="";typeof e=="function"?(r=InternalRuleType.Inline,n=async(u,...a)=>e(u,...a),s=[t]):({_type:r,_message:R}=e,s=s=e._params?.concat(t),n=async(...u)=>e.validator(u));let l=createRule({type:InternalRuleType.Async,validator:n,message:R});return l._params=l._params?.concat(s),l(...t??[])}function P(e,t){let r,n,s=[],R="";typeof e=="function"?(r=InternalRuleType.Inline,n=(u,...a)=>e(u,...a),s=[t]):({_type:r,validator:n,_message:R}=e,s=s=e._params?.concat(t));let l=createRule({type:InternalRuleType.Inline,validator:n,message:R});return l._params=l._params?.concat(s),l(...t)}function S(e,t){let r,n,s=[],R="";typeof t=="function"?(r=InternalRuleType.Inline,n=t,s=[e]):({_type:r,validator:n,_message:R}=t,s=t._params?.concat([e]));function l(o,...y){let[b]=unwrapRuleParameters([e]);return b?n(o,...y):true}function u(o){let[y]=unwrapRuleParameters([e]);return y}let a=createRule({type:r,validator:l,active:u,message:R}),m=[...s??[]];return a._params=m,typeof a=="function"?a(...m):a}function f(e,t=true){return e==null?true:e instanceof Date?isNaN(e.getTime()):e.constructor.name=="File"||e.constructor.name=="FileList"?e.size<=0:Array.isArray(e)?t?e.length===0:false:typeof e=="object"&&e!=null?Object.keys(e).length===0:!String(e).length}function x(e){if(f(e))return false;try{let t=null;if(e instanceof Date)t=e;else if(typeof e=="string"){let r=new Date(e);if(r.toString()==="Invalid Date")return !1;t=r;}return !!t}catch{return false}}function T(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]"?new Date(e):typeof e=="string"||t==="[object String]"?new Date(e):new Date(NaN)}function i(e,t=true){return !f(typeof e=="string"?e.trim():e,t)}function c(e){return e==null||typeof e!="number"?false:!isNaN(e)}function p(e,...t){if(f(e))return true;let r=typeof e=="number"?e.toString():e;return t.every(n=>(n.lastIndex=0,n.test(r)))}function h(e){let t=unref(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 g(e){return typeof e=="number"?e:e!=null?typeof e=="string"?e.trim()!==e?NaN:+e:NaN:NaN}function q(...e){let t=e.some(a=>typeof a=="function"?a.constructor.name==="AsyncFunction":a._async),r=e.map(a=>{if(typeof a=="function")return null;{let m=a._params;return m?.length?m:[]}}).flat().filter(a=>!!a);function n(a,m,...o){let y=[],b=0;for(let d of a)if(typeof d=="function")y.push(d(m)),b++;else {let D=d._params?.length??0;y.push(d.validator(m,...o.slice(b,D))),D&&(b+=D);}return y}function s(a){return a?.some(o=>typeof o!="boolean")?{$valid:a.every(o=>typeof o=="boolean"?!!o:o.$valid),...a.reduce((o,y)=>{if(typeof y=="boolean")return o;let{$valid:b,...d}=y;return {...o,...d}},{})}:a.every(o=>!!o)}let R;e.length?R=t?async(a,...m)=>{let o=await Promise.all(n(e,a,...m));return s(o)}:(a,...m)=>{let o=n(e,a,...m);return s(o)}:R=a=>false;let l=createRule({type:"and",validator:R,message:"The value does not match all of the provided validators"}),u=[...r??[]];return l._params=u,typeof l=="function"?l(...u):l}function G(...e){let t=e.some(a=>typeof a=="function"?a.constructor.name==="AsyncFunction":a._async),r=e.map(a=>typeof a=="function"?null:a._params).flat().filter(a=>!!a);function n(a,m,...o){let y=[],b=0;for(let d of a)if(typeof d=="function")y.push(d(m)),b++;else {let D=d._params?.length??0;y.push(d.validator(m,...o.slice(b,D))),D&&(b+=D);}return y}function s(a){return a.some(o=>typeof o!="boolean")?{$valid:a.some(o=>typeof o=="boolean"?!!o:o.$valid),...a.reduce((o,y)=>{if(typeof y=="boolean")return o;let{$valid:b,...d}=y;return {...o,...d}},{})}:a.some(o=>!!o)}let l=createRule({type:"or",validator:t?async(a,...m)=>{let o=await Promise.all(n(e,a,...m));return s(o)}:(a,...m)=>{let o=n(e,a,...m);return s(o)},message:"The value does not match any of the provided validators"}),u=[...r??[]];return l._params=u,typeof l=="function"?l(...u):l}function B(e,t){let r,n,s,R,l;typeof e=="function"?(n=e,l=e.constructor.name==="AsyncFunction"):({_type:r,validator:n,_params:R}=e,l=e._async),l?s=async(m,...o)=>i(m)?!await n(m,...o):true:s=(m,...o)=>i(m)?!n(m,...o):true;let u=createRule({type:"not",validator:s,message:t??"Error"}),a=[...R??[]];return u._params=a,typeof u=="function"?u(...a):u}var Qt=createRule({type:"required",validator:e=>i(e),message:"This field is required"});var er=createRule({type:"maxLength",validator:(e,t,r)=>{let{allowEqual:n=true}=r??{};return i(e,false)&&i(t)?c(t)?n?h(e)<=t:h(e)<t:(console.warn(`[maxLength] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),false):true},message:({$value:e,$params:[t]})=>Array.isArray(e)?`This list should have maximum ${t} items`:`The value length should not exceed ${t}`});var ar=createRule({type:"required",validator(e,t){return t?i(e):true},message:"This field is required",active({$params:[e]}){return e}});var X=/^[a-zA-Z]*$/,Y=/^[\w.]+$/,lr=createRule({type:"alpha",validator(e,t){return f(e)?true:t?.allowSymbols?p(e,Y):p(e,X)},message:"The value is not alphabetical"});var ee=/^[a-zA-Z0-9]*$/,te=/^[a-zA-Z0-9_]*$/,Rr=createRule({type:"alphaNum",validator(e,t){return f(e)?true:t?.allowSymbols?p(e,te):p(e,ee)},message:"The value must be alpha-numeric"});var gr=createRule({type:"between",validator:(e,t,r,n)=>{let{allowEqual:s=true}=n??{};if(i(e)&&i(t)&&i(r)){let R=g(e),l=g(t),u=g(r);return c(R)&&c(l)&&c(u)?s?R>=l&&R<=u:R>l&&R<u:(console.warn(`[between] Value or parameters aren't numbers, got value: ${e}, min: ${t}, max: ${r}`),false)}return true},message:({$params:[e,t]})=>`The value must be between ${e} and ${t}`});var ae=/^[-]?\d*(\.\d+)?$/,br=createRule({type:"decimal",validator(e){return f(e)?true:p(e,ae)},message:"The value must be decimal"});var oe=/^(?:[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,Pr=createRule({type:"email",validator(e){return f(e)?true:p(e,oe)},message:"The value must be an valid email address"});var le=/(^[0-9]*$)|(^-[0-9]+$)/,Vr=createRule({type:"integer",validator(e){return f(e)?true:p(e,le)},message:"The value must be an integer"});var Fr=createRule({type:"maxValue",validator:(e,t,r)=>{let{allowEqual:n=true}=r??{};return i(e)&&i(t)?c(t)&&!isNaN(g(e))?n?g(e)<=t:g(e)<t:(console.warn(`[maxValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),true):true},message:({$params:[e,t]})=>{let{allowEqual:r=true}=t??{};return r?`The value must be less than or equal to ${e}`:`The value must be less than ${e}`}});var Or=createRule({type:"minLength",validator:(e,t,r)=>{let{allowEqual:n=true}=r??{};return i(e,false)&&i(t)?c(t)?n?h(e)>=t:h(e)>t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),false):true},message:({$value:e,$params:[t]})=>Array.isArray(e)?`The list should have at least ${t} items`:`The value length should be at least ${t}`});var zr=createRule({type:"minValue",validator:(e,t,r)=>{let{allowEqual:n=true}=r??{};return i(e)&&i(t)?c(t)&&!isNaN(g(e))?n?g(e)>=t:g(e)>t:(console.warn(`[minValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),true):true},message:({$params:[e,t]})=>{let{allowEqual:r=true}=t??{};return r?`The value must be greater than or equal to ${e}`:`The value must be greater than ${e}`}});var Gr=createRule({type:"exactValue",validator:(e,t)=>i(e)&&i(t)?c(t)&&!isNaN(g(e))?g(e)===t:(console.warn(`[exactValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),true):true,message:({$params:[e]})=>`The value must be equal to ${e}`});var Jr=createRule({type:"exactLength",validator:(e,t)=>i(e,false)&&i(t)?c(t)?h(e)===t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),false):true,message:({$params:[e]})=>`The value should be exactly ${e} characters long`});var ce=/^\d*(\.\d+)?$/,Yr=createRule({type:"numeric",validator(e){return f(e)?true:p(e,ce)},message:"The value must be numeric"});var rn=createRule({type:"required",validator(e,t){return t?true:i(e)},message:"This field is required",active({$params:[e]}){return !e}});var sn=createRule({type:"sameAs",validator(e,t,r="other"){return f(e)?true:e===t},message({$params:[e,t]}){return `The value must be equal to the ${t} value`}});var xe=/^(?:(?:(?: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,fn=createRule({type:"url",validator(e){return f(e)?true:p(e,xe)},message:"The value is not a valid URL address"});function be(){return navigator.languages!=null?navigator.languages[0]:navigator.language}function w(e){return e?new Intl.DateTimeFormat(be(),{dateStyle:"short"}).format(new Date(e)):"?"}var dn=createRule({type:"dateAfter",validator:(e,t)=>i(e)&&i(t)?x(e)&&x(t)?T(e).getTime()>T(t).getTime()?true:{$valid:false,error:"date-not-after"}:{$valid:false,error:"value-or-paramater-not-a-date"}:true,message:({$params:[e],error:t})=>t==="value-or-paramater-not-a-date"?"The values must be dates":`The date must be after ${w(e)}`});var Dn=createRule({type:"dateBefore",validator:(e,t)=>i(e)&&i(t)?x(e)&&x(t)?T(e).getTime()<T(t).getTime()?true:{$valid:false,error:"date-not-before"}:{$valid:false,error:"value-or-paramater-not-a-date"}:true,message:({$params:[e],error:t})=>t==="value-or-paramater-not-a-date"?"The fields must be dates":`The date must be before ${w(e)}`});var vn=createRule({type:"dateBetween",validator:(e,t,r)=>x(e)&&x(t)&&x(r)?T(e).getTime()>T(t).getTime()&&T(e).getTime()<T(r).getTime():true,message:({$params:[e,t]})=>`The date must be between ${w(e)} and ${w(t)}`});function we(e){if(e.length>3||e.length===0||e[0]==="0"&&e!=="0"||!e.match(/^\d+$/))return false;let t=+e|0;return t>=0&&t<=255}var Cn=createRule({type:"ipv4Address",validator(e){if(f(e))return true;if(typeof e!="string")return false;let t=e.split(".");return t.length===4&&t.every(we)},message:"The value is not a valid IPv4 address"});var En=createRule({type:"macAddress",validator(e,t=":"){if(f(e))return true;if(typeof e!="string")return false;let r=typeof t=="string"&&t!==""?e.split(t):e.length===12||e.length===16?e.match(/.{2}/g):null;return r!==null&&(r.length===6||r.length===8)&&r.every(ve)},message:"The value is not a valid MAC Address"}),ve=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/);var Sn=createRule({type:"checked",validator:e=>i(e)?e===true:true,message:"The field must be checked"});var Un=createRule({type:"contains",validator(e,t){return i(e)&&i(t)?e.includes(t):true},message({$params:[e]}){return `The value must contain ${e}`}});var Zn=createRule({type:"startsWith",validator(e,t){return i(e)&&i(t)?e.startsWith(t):true},message({$params:[e]}){return `The value must end with ${e}`}});var Xn=createRule({type:"endsWith",validator(e,t){return i(e)&&i(t)?e.endsWith(t):true},message({$params:[e]}){return `The value must end with ${e}`}});var ta=createRule({type:"regex",validator(e,t){if(i(e)){let r=Array.isArray(t)?t:[t];return p(e,...r)}return true},message:"The value does not match the required pattern"});function ia(e){let t=computed(()=>toValue(e));return M(P((n,s)=>i(n)&&i(s,false)?s.includes(n):true,[t]),({$params:[n]})=>`The value should be one of those options: ${n.join(", ")}.`)}function Ie(e){let t=Object.keys(e).filter(n=>typeof e[e[n]]!="number"),r={};for(let n of t)r[n]=e[n];return Object.values(r)}function ua(e){let t=computed(()=>toValue(e));return M(P((n,s)=>i(n)&&!f(s)?Ie(s).includes(n):true,[t]),({$params:[n]})=>`The value should be one of those options: ${Object.values(n).join(", ")}.`)}function ya(e){let t=computed(()=>toValue(e));return M(P((n,s)=>s===n,[t]),({$params:[n]})=>`Value should be ${n}.`)}export{lr as alpha,Rr as alphaNum,q as and,S as applyIf,gr as between,Sn as checked,Un as contains,dn as dateAfter,Dn as dateBefore,vn as dateBetween,br as decimal,Pr as email,Xn as endsWith,Jr as exactLength,Gr as exactValue,h as getSize,Vr as integer,Cn as ipv4Address,x as isDate,f as isEmpty,i as isFilled,c as isNumber,ya as literal,En as macAddress,p as matchRegex,er as maxLength,Fr as maxValue,Or as minLength,zr as minValue,ua as nativeEnum,B as not,Yr as numeric,ia as oneOf,G as or,ta as regex,Qt as required,ar as requiredIf,rn as requiredUnless,sn as sameAs,Zn as startsWith,T as toDate,g as toNumber,fn as url,E as withAsync,M as withMessage,P as withParams,_ as withTooltip};
@@ -517,11 +517,11 @@ var alphaRegex = /^[a-zA-Z]*$/;
517
517
  var alphaSymbolRegex = /^[\w.]+$/;
518
518
  var alpha = createRule({
519
519
  type: "alpha",
520
- validator(value, allowSymbols) {
520
+ validator(value, options) {
521
521
  if (isEmpty(value)) {
522
522
  return true;
523
523
  }
524
- if (allowSymbols) {
524
+ if (options?.allowSymbols) {
525
525
  return matchRegex(value, alphaSymbolRegex);
526
526
  }
527
527
  return matchRegex(value, alphaRegex);
@@ -532,11 +532,11 @@ var alphaNumRegex = /^[a-zA-Z0-9]*$/;
532
532
  var alphaNumSymbolRegex = /^[a-zA-Z0-9_]*$/;
533
533
  var alphaNum = createRule({
534
534
  type: "alphaNum",
535
- validator(value, allowSymbols) {
535
+ validator(value, options) {
536
536
  if (isEmpty(value)) {
537
537
  return true;
538
538
  }
539
- if (allowSymbols) {
539
+ if (options?.allowSymbols) {
540
540
  return matchRegex(value, alphaNumSymbolRegex);
541
541
  }
542
542
  return matchRegex(value, alphaNumRegex);
@@ -875,7 +875,7 @@ var checked = createRule({
875
875
  }
876
876
  return true;
877
877
  },
878
- message: "The value must be checked"
878
+ message: "The field must be checked"
879
879
  });
880
880
  var contains = createRule({
881
881
  type: "contains",
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@regle/rules",
3
- "version": "1.1.0-beta.4",
3
+ "version": "1.1.0-beta.6",
4
4
  "description": "Collection of rules and helpers for Regle",
5
5
  "dependencies": {
6
- "@regle/core": "1.1.0-beta.4"
6
+ "@regle/core": "1.1.0-beta.6"
7
7
  },
8
8
  "devDependencies": {
9
9
  "@typescript-eslint/eslint-plugin": "8.28.0",