@regle/rules 1.2.3 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -11
- package/dist/regle-rules.d.ts +209 -104
- package/dist/regle-rules.js +1210 -0
- package/dist/regle-rules.min.js +1 -0
- package/package.json +13 -13
- package/dist/regle-rules.min.mjs +0 -1
- package/dist/regle-rules.mjs +0 -1056
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{InternalRuleType as e,createRule as t,unwrapRuleParameters as n}from"@regle/core";import{computed as r,toValue as i,unref as a}from"vue";function o(n,r){let i,a,o,s;typeof n==`function`&&!(`_validator`in n)?(i=e.Inline,a=n):{_type:i,validator:a,_active:o,_params:s}=n;let c=t({type:i,validator:a,active:o,message:r}),l=[...s??[]];if(c._params=l,c._message_patched=!0,typeof c==`function`){if(s!=null){let e=c(...l);return e._message_patched=!0,e}return c}else return c}function s(n,r){let i,a,o,s,c;typeof n==`function`&&!(`_validator`in n)?(i=e.Inline,a=n):{_type:i,validator:a,_active:o,_params:s,_message:c}=n;let l=t({type:i,validator:a,active:o,message:c,tooltip:r}),u=[...s??[]];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 c(n,r){let i,a,o=[],s=``;typeof n==`function`?(i=e.Inline,a=async(e,...t)=>n(e,...t),o=[r]):({_type:i,_message:s}=n,o=o=n._params?.concat(r),a=async(...e)=>n.validator(e));let c=t({type:e.Async,validator:a,message:s});return c._params=c._params?.concat(o),c(...r??[])}function l(n,r){let i,a,o=[],s=``;typeof n==`function`?(i=e.Inline,a=(e,...t)=>n(e,...t),o=[r]):({_type:i,validator:a,_message:s}=n,o=o=n._params?.concat(r));let c=t({type:e.Inline,validator:a,message:s});return c._params=c._params?.concat(o),c(...r)}function u(r,i){let a,o,s=[],c=``;typeof i==`function`?(a=e.Inline,o=i,s=[r]):({_type:a,validator:o,_message:c}=i,s=i._params?.concat([r]));function l(e,...t){let[i]=n([r]);return i?o(e,...t):!0}function u(e){let[t]=n([r]);return t}let d=t({type:a,validator:l,active:u,message:c}),f=[...s??[]];if(d._params=f,typeof d==`function`){let e=d(...f);return e}else return d}function d(e){return e?.constructor.name==`File`||e?.constructor.name==`FileList`}function f(e,t=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):d(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:typeof e==`object`&&e?Object.keys(e).length===0:!String(e).length}const ee=Symbol(`regle-rule`);function p(e){if(f(e))return!1;try{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}catch{return!1}}function m(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 h(e,t=!0){return!f(typeof e==`string`?e.trim():e,t)}function g(e){return e==null?!1:typeof e==`number`?!isNaN(e):!1}function _(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 v(e){let t=a(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 y(e){if(typeof e==`number`)return e;if(e!=null){if(typeof e==`string`){let t=e.trim()!==e;return t?NaN:+e}return NaN}return NaN}function te(...e){let n=e.some(e=>typeof e==`function`?e.constructor.name===`AsyncFunction`:e._async),r=e.map(e=>{if(typeof e==`function`)return null;{let t=e._params;return t?.length?t:[]}}).flat().filter(e=>!!e);function i(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,e))),e&&(i+=e)}return r}function a(e){let t=e?.some(e=>typeof e!=`boolean`);return t?{$valid:e.every(e=>typeof e==`boolean`?!!e:e.$valid),...e.reduce((e,t)=>{if(typeof t==`boolean`)return e;let{$valid:n,...r}=t;return{...e,...r}},{})}:e.every(e=>!!e)}let o;o=e.length?n?async(t,...n)=>{let r=await Promise.all(i(e,t,...n));return a(r)}:(t,...n)=>{let r=i(e,t,...n);return a(r)}:e=>!1;let s=t({type:`and`,validator:o,message:`The value does not match all of the provided validators`}),c=[...r??[]];if(s._params=c,typeof s==`function`){let e=s(...c);return e}else return s}function b(...e){let n=e.some(e=>typeof e==`function`?e.constructor.name===`AsyncFunction`:e._async),r=e.map(e=>typeof e==`function`?null:e._params).flat().filter(e=>!!e);function i(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,e))),e&&(i+=e)}return r}function a(e){let t=e.some(e=>typeof e!=`boolean`);return t?{$valid:e.some(e=>typeof e==`boolean`?!!e:e.$valid),...e.reduce((e,t)=>{if(typeof t==`boolean`)return e;let{$valid:n,...r}=t;return{...e,...r}},{})}:e.some(e=>!!e)}let o=n?async(t,...n)=>{let r=await Promise.all(i(e,t,...n));return a(r)}:(t,...n)=>{let r=i(e,t,...n);return a(r)},s=t({type:`or`,validator:o,message:`The value does not match any of the provided validators`}),c=[...r??[]];if(s._params=c,typeof s==`function`){let e=s(...c);return e}else return s}function x(e,n){let r,i,a,o,s;typeof e==`function`?(i=e,s=e.constructor.name===`AsyncFunction`):({_type:r,validator:i,_params:o}=e,s=e._async),a=s?async(e,...t)=>{if(h(e)){let n=await i(e,...t);return!n}return!0}:(e,...t)=>h(e)?!i(e,...t):!0;let c=t({type:`not`,validator:a,message:n??`Error`}),l=[...o??[]];if(c._params=l,typeof c==`function`){let e=c(...l);return e}else return c}const S=/^[a-zA-Z]*$/,C=/^[\w.]+$/,w=t({type:`alpha`,validator(e,t){return f(e)?!0:t?.allowSymbols?_(e,C):_(e,S)},message:`The value is not alphabetical`}),T=/^[a-zA-Z0-9]*$/,E=/^[a-zA-Z0-9_]*$/,D=t({type:`alphaNum`,validator(e,t){return f(e)?!0:t?.allowSymbols?_(e,E):_(e,T)},message:`The value must be alpha-numeric`}),O=t({type:`between`,validator:(e,t,n,r)=>{let{allowEqual:i=!0}=r??{};if(h(e)&&h(t)&&h(n)){let r=y(e),a=y(t),o=y(n);return g(r)&&g(a)&&g(o)?i?r>=a&&r<=o:r>a&&r<o:(console.warn(`[between] Value or parameters aren't numbers, got value: ${e}, min: ${t}, max: ${n}`),!1)}return!0},message:({$params:[e,t]})=>`The value must be between ${e} and ${t}`}),k=t({type:`boolean`,validator:e=>h(e)?typeof e==`boolean`:!0,message:`The value must be a native boolean`}),A=t({type:`checked`,validator:e=>h(e)?e===!0:!0,message:`The field must be checked`}),j=t({type:`contains`,validator(e,t){return h(e)&&h(t)?e.includes(t):!0},message({$params:[e]}){return`The value must contain ${e}`}}),M=t({type:`date`,validator:e=>h(e)?e instanceof Date:!0,message:`The value must be a native Date constructor`});function N(){return navigator.languages==null?navigator.language:navigator.languages[0]}function P(e){return e?new Intl.DateTimeFormat(N(),{dateStyle:`short`}).format(new Date(e)):`?`}const F=t({type:`dateAfter`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};if(h(e)&&h(t)){if(p(e)&&p(t)){let n=r?m(e).getTime()>=m(t).getTime():m(e).getTime()>m(t).getTime();return n?!0:{$valid:!1,error:`date-not-after`}}return{$valid:!1,error:`value-or-parameter-not-a-date`}}return!0},message:({$params:[e],error:t})=>t===`value-or-parameter-not-a-date`?`The values must be dates`:`The date must be after ${P(e)}`}),I=t({type:`dateBefore`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};if(h(e)&&h(t)){if(p(e)&&p(t)){let n=r?m(e).getTime()<=m(t).getTime():m(e).getTime()<m(t).getTime();return n?!0:{$valid:!1,error:`date-not-before`}}return{$valid:!1,error:`value-or-parameter-not-a-date`}}return!0},message:({$params:[e],error:t})=>t===`value-or-parameter-not-a-date`?`The values must be dates`:`The date must be before ${P(e)}`}),L=t({type:`dateBetween`,validator:(e,t,n,r)=>{let{allowEqual:i=!0}=r??{};return p(e)&&p(t)&&p(n)?i?m(e).getTime()>=m(t).getTime()&&m(e).getTime()<=m(n).getTime():m(e).getTime()>m(t).getTime()&&m(e).getTime()<m(n).getTime():!0},message:({$params:[e,t]})=>`The date must be between ${P(e)} and ${P(t)}`}),R=/^[-]?\d*(\.\d+)?$/,z=t({type:`decimal`,validator(e){return f(e)?!0:_(e,R)},message:`The value must be decimal`}),B=/^(?:[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,V=t({type:`email`,validator(e){return f(e)?!0:_(e,B)},message:`The value must be an valid email address`}),H=t({type:`endsWith`,validator(e,t){return h(e)&&h(t)?e.endsWith(t):!0},message({$params:[e]}){return`The value must end with ${e}`}}),U=t({type:`exactLength`,validator:(e,t)=>h(e,!1)&&h(t)?g(t)?v(e)===t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),!1):!0,message:({$params:[e]})=>`The value should be exactly ${e} characters long`}),ne=t({type:`exactValue`,validator:(e,t)=>h(e)&&h(t)?g(t)&&!isNaN(y(e))?y(e)===t:(console.warn(`[exactValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!0):!0,message:({$params:[e]})=>`The value must be equal to ${e}`}),W=/^[a-fA-F0-9]*$/,G=t({type:`hexadecimal`,validator(e){return f(e)?!0:_(e,W)},message:`The value must be hexadecimal`}),K=/(^[0-9]*$)|(^-[0-9]+$)/,q=t({type:`integer`,validator(e){return f(e)?!0:_(e,K)},message:`The value must be an integer`});function J(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 Y=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(J)},message:`The value is not a valid IPv4 address`});function X(e){let t=r(()=>i(e)),n=o(l((e,t)=>h(e)&&h(t)?t===e:!0,[t]),({$params:[e]})=>`Value should be ${e}.`);return n}const Z=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(Q)},message:`The value is not a valid MAC Address`}),Q=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/),re=t({type:`maxLength`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return h(e,!1)&&h(t)?g(t)?r?v(e)<=t:v(e)<t:(console.warn(`[maxLength] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!1):!0},message:({$value:e,$params:[t]})=>Array.isArray(e)?`This list should have maximum ${t} items`:`The value length should not exceed ${t}`}),ie=t({type:`maxValue`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return h(e)&&h(t)?g(t)&&!isNaN(y(e))?r?y(e)<=t:y(e)<t:(console.warn(`[maxValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!0):!0},message:({$params:[e,t]})=>{let{allowEqual:n=!0}=t??{};return n?`The value must be less than or equal to ${e}`:`The value must be less than ${e}`}}),ae=t({type:`minLength`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return h(e,!1)&&h(t)?g(t)?r?v(e)>=t:v(e)>t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),!1):!0},message:({$value:e,$params:[t]})=>Array.isArray(e)?`The list should have at least ${t} items`:`The value length should be at least ${t}`}),oe=t({type:`minValue`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return h(e)&&h(t)?g(t)&&!isNaN(y(e))?r?y(e)>=t:y(e)>t:(console.warn(`[minValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!0):!0},message:({$params:[e,t]})=>{let{allowEqual:n=!0}=t??{};return n?`The value must be greater than or equal to ${e}`:`The value must be greater than ${e}`}});function se(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 ce(e){let t=r(()=>i(e)),n=o(l((e,t)=>{if(h(e)&&!f(t)){let n=se(t);return n.includes(e)}return!0},[t]),({$params:[e]})=>`The value should be one of those options: ${Object.values(e).join(`, `)}.`);return n}const le=t({type:`number`,validator:e=>h(e)?g(e):!0,message:`The value must be a native number`}),ue=/^\d*(\.\d+)?$/,de=t({type:`numeric`,validator(e){return f(e)?!0:_(e,ue)},message:`The value must be numeric`});function fe(e){let t=r(()=>i(e)),n=o(l((e,t)=>h(e)&&h(t,!1)?t.includes(e):!0,[t]),({$params:[e]})=>`The value should be one of those options: ${e.join(`, `)}.`);return n}const pe=t({type:`regex`,validator(e,t){if(h(e)){let n=Array.isArray(t)?t:[t];return _(e,...n)}return!0},message:`The value does not match the required pattern`}),$=t({type:`required`,validator:e=>h(e),message:`This field is required`}),me=t({type:`required`,validator(e,t){return t?h(e):!0},message:`This field is required`,active({$params:[e]}){return e}}),he=t({type:`required`,validator(e,t){return t?!0:h(e)},message:`This field is required`,active({$params:[e]}){return!e}}),ge=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`}}),_e=t({type:`startsWith`,validator(e,t){return h(e)&&h(t)?e.startsWith(t):!0},message({$params:[e]}){return`The value must end with ${e}`}}),ve=t({type:`string`,validator:e=>h(e)?typeof e==`string`:!0,message:`The value must be a string`});function ye(){return()=>!0}const be=/^(?:(?:(?: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,xe=t({type:`url`,validator(e){return f(e)?!0:_(e,be)},message:`The value is not a valid URL address`});export{w as alpha,D as alphaNum,te as and,u as applyIf,O as between,k as boolean,A as checked,j as contains,M as date,F as dateAfter,I as dateBefore,L as dateBetween,z as decimal,V as email,H as endsWith,U as exactLength,ne as exactValue,v as getSize,G as hexadecimal,q as integer,Y as ipv4Address,p as isDate,f as isEmpty,h as isFilled,g as isNumber,X as literal,Z as macAddress,_ as matchRegex,re as maxLength,ie as maxValue,ae as minLength,oe as minValue,ce as nativeEnum,x as not,le as number,de as numeric,fe as oneOf,b as or,pe as regex,$ as required,me as requiredIf,he as requiredUnless,ge as sameAs,_e as startsWith,ve as string,m as toDate,y as toNumber,ye as type,xe as url,c as withAsync,o as withMessage,l as withParams,s as withTooltip};
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regle/rules",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Collection of rules and helpers for Regle",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@regle/core": "1.
|
|
6
|
+
"@regle/core": "1.3.0"
|
|
7
7
|
},
|
|
8
8
|
"devDependencies": {
|
|
9
9
|
"@typescript-eslint/eslint-plugin": "8.28.0",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"eslint-config-prettier": "9.1.0",
|
|
16
16
|
"eslint-plugin-vue": "9.33.0",
|
|
17
17
|
"prettier": "3.5.3",
|
|
18
|
-
"
|
|
18
|
+
"tsdown": "0.12.3",
|
|
19
19
|
"type-fest": "4.40.1",
|
|
20
20
|
"typescript": "5.8.3",
|
|
21
21
|
"vitest": "3.1.2",
|
|
@@ -29,18 +29,18 @@
|
|
|
29
29
|
"types": "./dist/regle-rules.d.ts",
|
|
30
30
|
"node": {
|
|
31
31
|
"import": {
|
|
32
|
-
"production": "./dist/regle-rules.min.
|
|
33
|
-
"development": "./dist/regle-rules.
|
|
34
|
-
"default": "./dist/regle-rules.
|
|
32
|
+
"production": "./dist/regle-rules.min.js",
|
|
33
|
+
"development": "./dist/regle-rules.js",
|
|
34
|
+
"default": "./dist/regle-rules.js"
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
|
-
"import": "./dist/regle-rules.
|
|
37
|
+
"import": "./dist/regle-rules.js"
|
|
38
38
|
},
|
|
39
39
|
"./package.json": "./package.json",
|
|
40
40
|
"./dist/*": "./dist/*"
|
|
41
41
|
},
|
|
42
|
-
"main": "./dist/regle-rules.
|
|
43
|
-
"module": "./dist/regle-rules.
|
|
42
|
+
"main": "./dist/regle-rules.js",
|
|
43
|
+
"module": "./dist/regle-rules.js",
|
|
44
44
|
"types": "./dist/regle-rules.d.ts",
|
|
45
45
|
"files": [
|
|
46
46
|
"dist",
|
|
@@ -62,10 +62,10 @@
|
|
|
62
62
|
"license": "MIT",
|
|
63
63
|
"scripts": {
|
|
64
64
|
"typecheck": "vue-tsc --noEmit",
|
|
65
|
-
"build": "
|
|
66
|
-
"build:dev": "
|
|
67
|
-
"build:sourcemaps": "
|
|
68
|
-
"dev": "
|
|
65
|
+
"build": "tsdown",
|
|
66
|
+
"build:dev": "tsdown --config=tsdown.dev.ts",
|
|
67
|
+
"build:sourcemaps": "tsdown --config=tsdown.sourcemap.ts",
|
|
68
|
+
"dev": "tsdown --config=tsdown.dev.ts --watch",
|
|
69
69
|
"test": "vitest run"
|
|
70
70
|
}
|
|
71
71
|
}
|
package/dist/regle-rules.min.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import {createRule,InternalRuleType,unwrapRuleParameters}from'@regle/core';import {unref,computed,toValue}from'vue';function D(e,t){let a,n,i,f;typeof e=="function"&&!("_validator"in e)?(a=InternalRuleType.Inline,n=e):{_type:a,validator:n,_active:i,_params:f}=e;let l=createRule({type:a,validator:n,active:i,message:t}),u=[...f??[]];if(l._params=u,l._message_patched=true,typeof l=="function"){if(f!=null){let o=l(...u);return o._message_patched=true,o}return l}else return l}function F(e,t){let a,n,i,f,l;typeof e=="function"&&!("_validator"in e)?(a=InternalRuleType.Inline,n=e):{_type:a,validator:n,_active:i,_params:f,_message:l}=e;let u=createRule({type:a,validator:n,active:i,message:l,tooltip:t}),o=[...f??[]];if(u._params=o,u._tooltip_patched=true,typeof u=="function"){let p=u(...o);return u._tooltip_patched=true,p}else return u}function _(e,t){let a,n,i=[],f="";typeof e=="function"?(a=InternalRuleType.Inline,n=async(u,...o)=>e(u,...o),i=[t]):({_type:a,_message:f}=e,i=i=e._params?.concat(t),n=async(...u)=>e.validator(u));let l=createRule({type:InternalRuleType.Async,validator:n,message:f});return l._params=l._params?.concat(i),l(...t??[])}function P(e,t){let a,n,i=[],f="";typeof e=="function"?(a=InternalRuleType.Inline,n=(u,...o)=>e(u,...o),i=[t]):({_type:a,validator:n,_message:f}=e,i=i=e._params?.concat(t));let l=createRule({type:InternalRuleType.Inline,validator:n,message:f});return l._params=l._params?.concat(i),l(...t)}function q(e,t){let a,n,i=[],f="";typeof t=="function"?(a=InternalRuleType.Inline,n=t,i=[e]):({_type:a,validator:n,_message:f}=t,i=t._params?.concat([e]));function l(s,...c){let[x]=unwrapRuleParameters([e]);return x?n(s,...c):true}function u(s){let[c]=unwrapRuleParameters([e]);return c}let o=createRule({type:a,validator:l,active:u,message:f}),p=[...i??[]];return o._params=p,typeof o=="function"?o(...p):o}function V(e){return e?.constructor.name=="File"||e?.constructor.name=="FileList"}function m(e,t=true){return e==null?true:e instanceof Date?isNaN(e.getTime()):V(e)?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 b(e){if(m(e))return false;try{let t=null;if(e instanceof Date)t=e;else if(typeof e=="string"){let a=new Date(e);if(a.toString()==="Invalid Date")return !1;t=a;}return !!t}catch{return false}}function y(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 r(e,t=true){return !m(typeof e=="string"?e.trim():e,t)}function g(e){return e==null||typeof e!="number"?false:!isNaN(e)}function R(e,...t){if(m(e))return true;let a=typeof e=="number"?e.toString():e;return t.every(n=>(n.lastIndex=0,n.test(a)))}function M(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 d(e){return typeof e=="number"?e:e!=null?typeof e=="string"?e.trim()!==e?NaN:+e:NaN:NaN}function G(...e){let t=e.some(o=>typeof o=="function"?o.constructor.name==="AsyncFunction":o._async),a=e.map(o=>{if(typeof o=="function")return null;{let p=o._params;return p?.length?p:[]}}).flat().filter(o=>!!o);function n(o,p,...s){let c=[],x=0;for(let T of o)if(typeof T=="function")c.push(T(p)),x++;else {let h=T._params?.length??0;c.push(T.validator(p,...s.slice(x,h))),h&&(x+=h);}return c}function i(o){return o?.some(s=>typeof s!="boolean")?{$valid:o.every(s=>typeof s=="boolean"?!!s:s.$valid),...o.reduce((s,c)=>{if(typeof c=="boolean")return s;let{$valid:x,...T}=c;return {...s,...T}},{})}:o.every(s=>!!s)}let f;e.length?f=t?async(o,...p)=>{let s=await Promise.all(n(e,o,...p));return i(s)}:(o,...p)=>{let s=n(e,o,...p);return i(s)}:f=o=>false;let l=createRule({type:"and",validator:f,message:"The value does not match all of the provided validators"}),u=[...a??[]];return l._params=u,typeof l=="function"?l(...u):l}function K(...e){let t=e.some(o=>typeof o=="function"?o.constructor.name==="AsyncFunction":o._async),a=e.map(o=>typeof o=="function"?null:o._params).flat().filter(o=>!!o);function n(o,p,...s){let c=[],x=0;for(let T of o)if(typeof T=="function")c.push(T(p)),x++;else {let h=T._params?.length??0;c.push(T.validator(p,...s.slice(x,h))),h&&(x+=h);}return c}function i(o){return o.some(s=>typeof s!="boolean")?{$valid:o.some(s=>typeof s=="boolean"?!!s:s.$valid),...o.reduce((s,c)=>{if(typeof c=="boolean")return s;let{$valid:x,...T}=c;return {...s,...T}},{})}:o.some(s=>!!s)}let l=createRule({type:"or",validator:t?async(o,...p)=>{let s=await Promise.all(n(e,o,...p));return i(s)}:(o,...p)=>{let s=n(e,o,...p);return i(s)},message:"The value does not match any of the provided validators"}),u=[...a??[]];return l._params=u,typeof l=="function"?l(...u):l}function B(e,t){let a,n,i,f,l;typeof e=="function"?(n=e,l=e.constructor.name==="AsyncFunction"):({_type:a,validator:n,_params:f}=e,l=e._async),l?i=async(p,...s)=>r(p)?!await n(p,...s):true:i=(p,...s)=>r(p)?!n(p,...s):true;let u=createRule({type:"not",validator:i,message:t??"Error"}),o=[...f??[]];return u._params=o,typeof u=="function"?u(...o):u}var J=/^[a-zA-Z]*$/,H=/^[\w.]+$/,fn=createRule({type:"alpha",validator(e,t){return m(e)?true:t?.allowSymbols?R(e,H):R(e,J)},message:"The value is not alphabetical"});var X=/^[a-zA-Z0-9]*$/,Y=/^[a-zA-Z0-9_]*$/,gn=createRule({type:"alphaNum",validator(e,t){return m(e)?true:t?.allowSymbols?R(e,Y):R(e,X)},message:"The value must be alpha-numeric"});var bn=createRule({type:"between",validator:(e,t,a,n)=>{let{allowEqual:i=true}=n??{};if(r(e)&&r(t)&&r(a)){let f=d(e),l=d(t),u=d(a);return g(f)&&g(l)&&g(u)?i?f>=l&&f<=u:f>l&&f<u:(console.warn(`[between] Value or parameters aren't numbers, got value: ${e}, min: ${t}, max: ${a}`),false)}return true},message:({$params:[e,t]})=>`The value must be between ${e} and ${t}`});var Pn=createRule({type:"boolean",validator:e=>r(e)?typeof e=="boolean":true,message:"The value must be a native boolean"});var $n=createRule({type:"checked",validator:e=>r(e)?e===true:true,message:"The field must be checked"});var Cn=createRule({type:"contains",validator(e,t){return r(e)&&r(t)?e.includes(t):true},message({$params:[e]}){return `The value must contain ${e}`}});var En=createRule({type:"date",validator:e=>r(e)?e instanceof Date:true,message:"The value must be a native Date constructor"});function oe(){return navigator.languages!=null?navigator.languages[0]:navigator.language}function w(e){return e?new Intl.DateTimeFormat(oe(),{dateStyle:"short"}).format(new Date(e)):"?"}var Gn=createRule({type:"dateAfter",validator:(e,t,a)=>{let{allowEqual:n=true}=a??{};return r(e)&&r(t)?b(e)&&b(t)?(n?y(e).getTime()>=y(t).getTime():y(e).getTime()>y(t).getTime())?true:{$valid:false,error:"date-not-after"}:{$valid:false,error:"value-or-parameter-not-a-date"}:true},message:({$params:[e],error:t})=>t==="value-or-parameter-not-a-date"?"The values must be dates":`The date must be after ${w(e)}`});var Zn=createRule({type:"dateBefore",validator:(e,t,a)=>{let{allowEqual:n=true}=a??{};return r(e)&&r(t)?b(e)&&b(t)?(n?y(e).getTime()<=y(t).getTime():y(e).getTime()<y(t).getTime())?true:{$valid:false,error:"date-not-before"}:{$valid:false,error:"value-or-parameter-not-a-date"}:true},message:({$params:[e],error:t})=>t==="value-or-parameter-not-a-date"?"The values must be dates":`The date must be before ${w(e)}`});var Yn=createRule({type:"dateBetween",validator:(e,t,a,n)=>{let{allowEqual:i=true}=n??{};return b(e)&&b(t)&&b(a)?i?y(e).getTime()>=y(t).getTime()&&y(e).getTime()<=y(a).getTime():y(e).getTime()>y(t).getTime()&&y(e).getTime()<y(a).getTime():true},message:({$params:[e,t]})=>`The date must be between ${w(e)} and ${w(t)}`});var me=/^[-]?\d*(\.\d+)?$/,rr=createRule({type:"decimal",validator(e){return m(e)?true:R(e,me)},message:"The value must be decimal"});var pe=/^(?:[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,sr=createRule({type:"email",validator(e){return m(e)?true:R(e,pe)},message:"The value must be an valid email address"});var fr=createRule({type:"endsWith",validator(e,t){return r(e)&&r(t)?e.endsWith(t):true},message({$params:[e]}){return `The value must end with ${e}`}});var gr=createRule({type:"exactLength",validator:(e,t)=>r(e,false)&&r(t)?g(t)?M(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 br=createRule({type:"exactValue",validator:(e,t)=>r(e)&&r(t)?g(t)&&!isNaN(d(e))?d(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 de=/^[a-fA-F0-9]*$/,Dr=createRule({type:"hexadecimal",validator(e){return m(e)?true:R(e,de)},message:"The value must be hexadecimal"});var be=/(^[0-9]*$)|(^-[0-9]+$)/,vr=createRule({type:"integer",validator(e){return m(e)?true:R(e,be)},message:"The value must be an integer"});function Me(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 Wr=createRule({type:"ipv4Address",validator(e){if(m(e))return true;if(typeof e!="string")return false;let t=e.split(".");return t.length===4&&t.every(Me)},message:"The value is not a valid IPv4 address"});function Nr(e){let t=computed(()=>toValue(e));return D(P((n,i)=>r(n)&&r(i)?i===n:true,[t]),({$params:[n]})=>`Value should be ${n}.`)}var Sr=createRule({type:"macAddress",validator(e,t=":"){if(m(e))return true;if(typeof e!="string")return false;let a=typeof t=="string"&&t!==""?e.split(t):e.length===12||e.length===16?e.match(/.{2}/g):null;return a!==null&&(a.length===6||a.length===8)&&a.every(we)},message:"The value is not a valid MAC Address"}),we=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/);var Gr=createRule({type:"maxLength",validator:(e,t,a)=>{let{allowEqual:n=true}=a??{};return r(e,false)&&r(t)?g(t)?n?M(e)<=t:M(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 Br=createRule({type:"maxValue",validator:(e,t,a)=>{let{allowEqual:n=true}=a??{};return r(e)&&r(t)?g(t)&&!isNaN(d(e))?n?d(e)<=t:d(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:a=true}=t??{};return a?`The value must be less than or equal to ${e}`:`The value must be less than ${e}`}});var Qr=createRule({type:"minLength",validator:(e,t,a)=>{let{allowEqual:n=true}=a??{};return r(e,false)&&r(t)?g(t)?n?M(e)>=t:M(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 ta=createRule({type:"minValue",validator:(e,t,a)=>{let{allowEqual:n=true}=a??{};return r(e)&&r(t)?g(t)&&!isNaN(d(e))?n?d(e)>=t:d(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:a=true}=t??{};return a?`The value must be greater than or equal to ${e}`:`The value must be greater than ${e}`}});function Ce(e){let t=Object.keys(e).filter(n=>typeof e[e[n]]!="number"),a={};for(let n of t)a[n]=e[n];return Object.values(a)}function oa(e){let t=computed(()=>toValue(e));return D(P((n,i)=>r(n)&&!m(i)?Ce(i).includes(n):true,[t]),({$params:[n]})=>`The value should be one of those options: ${Object.values(n).join(", ")}.`)}var ua=createRule({type:"number",validator:e=>r(e)?g(e):true,message:"The value must be a native number"});var Ne=/^\d*(\.\d+)?$/,Ra=createRule({type:"numeric",validator(e){return m(e)?true:R(e,Ne)},message:"The value must be numeric"});function da(e){let t=computed(()=>toValue(e));return D(P((n,i)=>r(n)&&r(i,false)?i.includes(n):true,[t]),({$params:[n]})=>`The value should be one of those options: ${n.join(", ")}.`)}var Ma=createRule({type:"regex",validator(e,t){if(r(e)){let a=Array.isArray(t)?t:[t];return R(e,...a)}return true},message:"The value does not match the required pattern"});var wa=createRule({type:"required",validator:e=>r(e),message:"This field is required"});var Va=createRule({type:"required",validator(e,t){return t?r(e):true},message:"This field is required",active({$params:[e]}){return e}});var Oa=createRule({type:"required",validator(e,t){return t?true:r(e)},message:"This field is required",active({$params:[e]}){return !e}});var Ea=createRule({type:"sameAs",validator(e,t,a){return m(e)?true:e===t},message({$params:[e,t="other"]}){return `The value must be equal to the ${t} value`}});var za=createRule({type:"startsWith",validator(e,t){return r(e)&&r(t)?e.startsWith(t):true},message({$params:[e]}){return `The value must end with ${e}`}});var Ka=createRule({type:"string",validator:e=>r(e)?typeof e=="string":true,message:"The value must be a string"});function Ba(){return ()=>true}var je=/^(?:(?:(?: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,Qa=createRule({type:"url",validator(e){return m(e)?true:R(e,je)},message:"The value is not a valid URL address"});export{fn as alpha,gn as alphaNum,G as and,q as applyIf,bn as between,Pn as boolean,$n as checked,Cn as contains,En as date,Gn as dateAfter,Zn as dateBefore,Yn as dateBetween,rr as decimal,sr as email,fr as endsWith,gr as exactLength,br as exactValue,M as getSize,Dr as hexadecimal,vr as integer,Wr as ipv4Address,b as isDate,m as isEmpty,r as isFilled,g as isNumber,Nr as literal,Sr as macAddress,R as matchRegex,Gr as maxLength,Br as maxValue,Qr as minLength,ta as minValue,oa as nativeEnum,B as not,ua as number,Ra as numeric,da as oneOf,K as or,Ma as regex,wa as required,Va as requiredIf,Oa as requiredUnless,Ea as sameAs,za as startsWith,Ka as string,y as toDate,d as toNumber,Ba as type,Qa as url,_ as withAsync,D as withMessage,P as withParams,F as withTooltip};
|