@regle/rules 1.17.0 → 1.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -5
- package/dist/regle-rules.d.ts +3 -3
- package/dist/regle-rules.js +62 -58
- package/dist/regle-rules.min.js +2 -2
- package/package.json +30 -31
package/README.md
CHANGED
|
@@ -6,20 +6,18 @@
|
|
|
6
6
|
|
|
7
7
|
# Regle
|
|
8
8
|
|
|
9
|
-
|
|
10
9
|
Regle \ʁɛɡl\ (French word for 'rule') is a Typescript-first model-based validation library for Vue 3.
|
|
11
10
|
It's heavily inspired by Vuelidate.
|
|
12
11
|
|
|
13
|
-
|
|
14
12
|
## 📚 Documentation
|
|
15
13
|
|
|
16
14
|
[](https://reglejs.dev/)
|
|
17
15
|
|
|
18
16
|
## 🎮 Play with it
|
|
19
17
|
|
|
20
|
-
| Playground
|
|
21
|
-
|
|
|
22
|
-
| <a target='_blank' href="https://play.reglejs.dev"><img width="180" src="https://raw.githubusercontent.com/victorgarciaesgi/regle/refs/heads/main/.github/images/regle-playground-button.svg" /></a> |
|
|
18
|
+
| Playground | Simple demo | Advanced Demo |
|
|
19
|
+
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
20
|
+
| <a target='_blank' href="https://play.reglejs.dev"><img width="180" src="https://raw.githubusercontent.com/victorgarciaesgi/regle/refs/heads/main/.github/images/regle-playground-button.svg" /></a> | [](https://stackblitz.com/~/github.com/victorgarciaesgi/regle-examples/tree/main/examples/simple-example?file=examples/simple-example/src/App.vue&configPath=examples/simple-example) | [](https://stackblitz.com/~/github.com/victorgarciaesgi/regle-examples/tree/main/examples/advanced-example?file=examples/advanced-example/src/App.vue&configPath=examples/advanced-example) |
|
|
23
21
|
|
|
24
22
|
## ✨ Features
|
|
25
23
|
|
package/dist/regle-rules.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @regle/rules v1.17.
|
|
2
|
+
* @regle/rules v1.17.1
|
|
3
3
|
* (c) 2026 Victor Garcia
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { CommonAlphaOptions, CommonComparisonOptions, ExtendedRulesDeclarations, FormRuleDeclaration, InlineRuleDeclaration, Maybe, MaybeInput, MaybeReadonly, NonEmptyTuple, RegleRuleDecl, RegleRuleDefinition, RegleRuleDefinitionWithMetadataProcessor, RegleRuleMetadataConsumer, RegleRuleMetadataDefinition, RegleRuleWithParamsDefinition, UnwrapRegleUniversalParams } from "@regle/core";
|
|
7
|
+
import { CommonAlphaOptions, CommonComparisonOptions, ExtendedRulesDeclarations, FormRuleDeclaration, InlineRuleDeclaration, Maybe, MaybeInput, MaybeReadonly, NonEmptyTuple, RegleRuleDecl, RegleRuleDefinition, RegleRuleDefinitionWithMetadataProcessor, RegleRuleMetadataConsumer, RegleRuleMetadataDefinition, RegleRuleWithParamsDefinition, RegleRuleWithParamsDefinitionInput, UnwrapRegleUniversalParams } from "@regle/core";
|
|
8
8
|
import { ComputedRef, MaybeRef, MaybeRefOrGetter, Ref } from "vue";
|
|
9
9
|
import { EmptyObject } from "type-fest";
|
|
10
10
|
/**
|
|
@@ -143,7 +143,7 @@ declare function withParams<TValue$1 extends any, TParams$1 extends any[], TRetu
|
|
|
143
143
|
*
|
|
144
144
|
* @see {@link https://reglejs.dev/core-concepts/rules/rules-operators#applyif Documentation}
|
|
145
145
|
*/
|
|
146
|
-
declare function applyIf<TRule extends FormRuleDeclaration<any>>(_condition: MaybeRefOrGetter<Maybe<boolean>>, rule: TRule): TRule extends InlineRuleDeclaration<infer TValue, infer TParams, infer TReturn> ? RegleRuleDefinition<TValue, [...TParams, condition: boolean], TReturn extends Promise<any> ? true : false, TReturn extends Promise<infer M> ? M : TReturn> : TRule extends
|
|
146
|
+
declare function applyIf<TRule extends FormRuleDeclaration<any>>(_condition: MaybeRefOrGetter<Maybe<boolean>>, rule: TRule): TRule extends InlineRuleDeclaration<infer TValue, infer TParams, infer TReturn> ? RegleRuleDefinition<TValue, [...TParams, condition: boolean], TReturn extends Promise<any> ? true : false, TReturn extends Promise<infer M> ? M : TReturn> : TRule extends RegleRuleWithParamsDefinitionInput<infer TValue, infer TParams, infer TAsync, infer TMetadata> ? RegleRuleDefinition<TValue, [...TParams, condition: boolean], TAsync, TMetadata> : TRule extends RegleRuleDefinition<infer TValue, any[], infer TAsync, infer TMetadata> ? RegleRuleDefinition<TValue, [condition: boolean], TAsync, TMetadata> : TRule;
|
|
147
147
|
/**
|
|
148
148
|
* Checks if any value you provide is defined (including arrays and objects).
|
|
149
149
|
* This is almost a must-have for optional fields when writing custom rules.
|
package/dist/regle-rules.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @regle/rules v1.17.
|
|
2
|
+
* @regle/rules v1.17.1
|
|
3
3
|
* (c) 2026 Victor Garcia
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -115,6 +115,63 @@ function withParams(rule, depsArray) {
|
|
|
115
115
|
return newRule(...depsArray);
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
+
/**
|
|
119
|
+
* Server side friendly way of checking for a File
|
|
120
|
+
*/
|
|
121
|
+
function isFile(value) {
|
|
122
|
+
return value?.constructor?.name == "File";
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Checks if a value is empty in any way (including arrays and objects).
|
|
127
|
+
* This is the inverse of `isFilled`.
|
|
128
|
+
*
|
|
129
|
+
* `isEmpty` also acts as a type guard.
|
|
130
|
+
*
|
|
131
|
+
* By default, it considers an empty array as `true`. You can override this behavior with `considerEmptyArrayInvalid`.
|
|
132
|
+
*
|
|
133
|
+
* @param value - The target value to check
|
|
134
|
+
* @param considerEmptyArrayInvalid - When `false`, empty arrays are not considered empty (default: `true`)
|
|
135
|
+
* @returns `true` if the value is empty, `false` otherwise
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* import { createRule, type Maybe } from '@regle/core';
|
|
140
|
+
* import { isEmpty } from '@regle/rules';
|
|
141
|
+
*
|
|
142
|
+
* const rule = createRule({
|
|
143
|
+
* validator(value: Maybe<string>) {
|
|
144
|
+
* if (isEmpty(value)) {
|
|
145
|
+
* return true;
|
|
146
|
+
* }
|
|
147
|
+
* return check(value);
|
|
148
|
+
* },
|
|
149
|
+
* message: 'Error'
|
|
150
|
+
* })
|
|
151
|
+
* ```
|
|
152
|
+
*
|
|
153
|
+
* @see {@link https://reglejs.dev/core-concepts/rules/validations-helpers#isempty Documentation}
|
|
154
|
+
*/
|
|
155
|
+
function isEmpty(value, considerEmptyArrayInvalid = true) {
|
|
156
|
+
if (value === void 0 || value === null) return true;
|
|
157
|
+
if (value instanceof Date) return isNaN(value.getTime());
|
|
158
|
+
else if (isFile(value)) return value.size <= 0;
|
|
159
|
+
else if (Array.isArray(value)) {
|
|
160
|
+
if (considerEmptyArrayInvalid) return value.length === 0;
|
|
161
|
+
return false;
|
|
162
|
+
} else if (typeof value === "object" && value != null) return Object.keys(value).length === 0;
|
|
163
|
+
return !String(value).length;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function isObject(obj) {
|
|
167
|
+
if (obj && (obj instanceof Date || obj.constructor.name == "File" || obj.constructor.name == "FileList")) return false;
|
|
168
|
+
return typeof obj === "object" && obj !== null && !Array.isArray(obj);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function isRuleDef(rule) {
|
|
172
|
+
return (isObject(rule) || typeof rule === "function") && "_validator" in rule;
|
|
173
|
+
}
|
|
174
|
+
|
|
118
175
|
/**
|
|
119
176
|
* The `applyIf` operator is similar to `requiredIf`, but it can be used with **any rule**.
|
|
120
177
|
* It simplifies conditional rule declarations.
|
|
@@ -144,13 +201,13 @@ function applyIf(_condition, rule) {
|
|
|
144
201
|
let _params = [];
|
|
145
202
|
let _message = "";
|
|
146
203
|
let _async = false;
|
|
147
|
-
if (typeof rule === "function") {
|
|
204
|
+
if (typeof rule === "function" && !("_validator" in rule)) {
|
|
148
205
|
_type = InternalRuleType.Inline;
|
|
149
206
|
validator = rule;
|
|
150
207
|
_params = [_condition];
|
|
151
|
-
} else {
|
|
152
|
-
({_type, validator, _message, _async} = rule);
|
|
153
|
-
_params =
|
|
208
|
+
} else if (isRuleDef(rule)) {
|
|
209
|
+
({_type, validator, _message, _async, _params} = rule);
|
|
210
|
+
_params = (_params ?? [])?.concat([_condition]);
|
|
154
211
|
}
|
|
155
212
|
function newValidator(value, ...args) {
|
|
156
213
|
const [condition] = unwrapRuleParameters([_condition]);
|
|
@@ -174,59 +231,6 @@ function applyIf(_condition, rule) {
|
|
|
174
231
|
else return newRule;
|
|
175
232
|
}
|
|
176
233
|
|
|
177
|
-
/**
|
|
178
|
-
* Server side friendly way of checking for a File
|
|
179
|
-
*/
|
|
180
|
-
function isFile(value) {
|
|
181
|
-
return value?.constructor?.name == "File";
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Checks if a value is empty in any way (including arrays and objects).
|
|
186
|
-
* This is the inverse of `isFilled`.
|
|
187
|
-
*
|
|
188
|
-
* `isEmpty` also acts as a type guard.
|
|
189
|
-
*
|
|
190
|
-
* By default, it considers an empty array as `true`. You can override this behavior with `considerEmptyArrayInvalid`.
|
|
191
|
-
*
|
|
192
|
-
* @param value - The target value to check
|
|
193
|
-
* @param considerEmptyArrayInvalid - When `false`, empty arrays are not considered empty (default: `true`)
|
|
194
|
-
* @returns `true` if the value is empty, `false` otherwise
|
|
195
|
-
*
|
|
196
|
-
* @example
|
|
197
|
-
* ```ts
|
|
198
|
-
* import { createRule, type Maybe } from '@regle/core';
|
|
199
|
-
* import { isEmpty } from '@regle/rules';
|
|
200
|
-
*
|
|
201
|
-
* const rule = createRule({
|
|
202
|
-
* validator(value: Maybe<string>) {
|
|
203
|
-
* if (isEmpty(value)) {
|
|
204
|
-
* return true;
|
|
205
|
-
* }
|
|
206
|
-
* return check(value);
|
|
207
|
-
* },
|
|
208
|
-
* message: 'Error'
|
|
209
|
-
* })
|
|
210
|
-
* ```
|
|
211
|
-
*
|
|
212
|
-
* @see {@link https://reglejs.dev/core-concepts/rules/validations-helpers#isempty Documentation}
|
|
213
|
-
*/
|
|
214
|
-
function isEmpty(value, considerEmptyArrayInvalid = true) {
|
|
215
|
-
if (value === void 0 || value === null) return true;
|
|
216
|
-
if (value instanceof Date) return isNaN(value.getTime());
|
|
217
|
-
else if (isFile(value)) return value.size <= 0;
|
|
218
|
-
else if (Array.isArray(value)) {
|
|
219
|
-
if (considerEmptyArrayInvalid) return value.length === 0;
|
|
220
|
-
return false;
|
|
221
|
-
} else if (typeof value === "object" && value != null) return Object.keys(value).length === 0;
|
|
222
|
-
return !String(value).length;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
function isObject(obj) {
|
|
226
|
-
if (obj && (obj instanceof Date || obj.constructor.name == "File" || obj.constructor.name == "FileList")) return false;
|
|
227
|
-
return typeof obj === "object" && obj !== null && !Array.isArray(obj);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
234
|
/**
|
|
231
235
|
* Checks if the provided value is a valid Date. Used internally for date rules.
|
|
232
236
|
* Can also validate date strings.
|
package/dist/regle-rules.min.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @regle/rules v1.17.
|
|
2
|
+
* @regle/rules v1.17.1
|
|
3
3
|
* (c) 2026 Victor Garcia
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import{InternalRuleType as e,createRule as t,unwrapRuleParameters as n}from"@regle/core";import{computed as r,toValue as i,unref as a}from"vue";function o(n,r){let i,a,o,s,c=!1;typeof n==`function`&&!(`_validator`in n)?(i=e.Inline,a=n):{_type:i,validator:a,_active:o,_params:s,_async:c}=n;let l=t({type:i,validator:a,active:o,message:r,async:c}),u=[...s??[]];if(l._params=u,l._message_patched=!0,typeof l==`function`){if(s!=null){let e=l(...u);return e._message_patched=!0,e}return l}else return l}function s(n,r){let i,a,o,s,c,l=!1;typeof n==`function`&&!(`_validator`in n)?(i=e.Inline,a=n):{_type:i,validator:a,_active:o,_params:s,_message:c,_async:l}=n;let u=t({type:i,validator:a,active:o,message:c,tooltip:r,async:l}),d=[...s??[]];if(u._params=d,u._tooltip_patched=!0,typeof u==`function`){let e=u(...d);return u._tooltip_patched=!0,e}else return u}function c(n,r){let i,a,o=[],s=``;typeof n==`function`?(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:i??e.Async,validator:a,message:s,async:!0});return c._params=c._params?.concat(o),c(...r??[])}function l(n,r){let i,a,o=[],s=``;typeof n==`function`?(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=``,l=!1;typeof i==`function`?(a=e.Inline,o=i,s=[r]):({_type:a,validator:o,_message:c,_async:l}=i,s=i._params?.concat([r]));function u(e,...t){let[i]=n([r]);return i?o(e,...t):!0}function d(){let[e]=n([r]);return e}let f=t({type:a,validator:u,active:d,message:c,async:l}),p=[...s??[]];return f._params=p,typeof f==`function`?f(...p):f}function d(e){return e?.constructor?.name==`File`}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}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){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 h(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 g(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 _(e,t=!0){return!f(typeof e==`string`?e.trim():e,t)}function v(e){return e==null?!1:typeof e==`number`?!isNaN(e):!1}function y(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 b(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 x(e){return typeof e==`number`?e:e==null?NaN:typeof e==`string`&&e.trim()===e?+e:NaN}function S(e){return e==null?!1:typeof e==`string`}function ee(...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){return e?.some(e=>typeof e!=`boolean`)?{$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)=>a(await Promise.all(i(e,t,...n))):(t,...n)=>a(i(e,t,...n)):e=>!1;let s=t({type:`and`,validator:o,message:`The value does not match all of the provided validators`}),c=[...r??[]];return s._params=c,typeof s==`function`?s(...c):s}function C(...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){return e.some(e=>typeof e!=`boolean`)?{$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=t({type:`or`,validator:n?async(t,...n)=>a(await Promise.all(i(e,t,...n))):(t,...n)=>a(i(e,t,...n)),message:`The value does not match any of the provided validators`}),s=[...r??[]];return o._params=s,typeof o==`function`?o(...s):o}function w(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)=>_(e)?!await i(e,...t):!0:(e,...t)=>_(e)?!i(e,...t):!0;let c=t({type:`not`,validator:a,message:n??`Error`}),l=[...o??[]];return c._params=l,typeof c==`function`?c(...l):c}function T(e,t,n){return Object.entries(i(t)).map(([t,r])=>typeof r==`function`||p(r)&&`_validator`in r?[t,u(n?e:()=>!i(e),r)]:[t,r])}function te(e,t,n){return r(()=>{let r=T(e,t,!0),i=n?T(e,n,!1):[];return Object.fromEntries([...r,...i])})}const ne=/^https?$/,E=/^(?=.{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])?)*\.?$/,D=/^(?:(?:(?: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 O(){return RegExp(`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`,`u`)}const k=/^[^A-Z]*$/,A=/^[^a-z]*$/,j=/^[0-9a-fA-F]*$/,M=/^[a-zA-Z]*$/,N=/^[\w.]+$/,P=/^[a-zA-Z0-9]*$/,F=/^[a-zA-Z0-9_]*$/,I=/^[-]?\d*(\.\d+)?$/,L=/^(?:[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,R=/(^[0-9]*$)|(^-[0-9]+$)/,z=/^\d*(\.\d+)?$/,B=t({type:`alpha`,validator(e,t){return f(e)?!0:t?.allowSymbols?y(e,N):y(e,M)},message:`The value is not alphabetical`}),V=t({type:`alphaNum`,validator(e,t){return f(e)?!0:t?.allowSymbols?y(e,F):y(e,P)},message:`The value must be alpha-numeric`}),H=t({type:`between`,validator:(e,t,n,r)=>{let{allowEqual:i=!0}=r??{};if(_(e)&&_(t)&&_(n)){let r=x(e),a=x(t),o=x(n);return v(r)&&v(a)&&v(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}`}),U=t({type:`boolean`,validator:e=>_(e)?typeof e==`boolean`:!0,message:`The value must be a native boolean`}),W=t({type:`checked`,validator:e=>_(e)?e===!0:!0,message:`The field must be checked`}),G=t({type:`contains`,validator(e,t){return _(e)&&_(t)&&S(e)&&S(t)?e.includes(t):!0},message({$params:[e]}){return`The value must contain ${e}`}}),K=t({type:`date`,validator:e=>_(e)?e instanceof Date:!0,message:`The value must be a native Date`});function q(){return navigator.languages==null?navigator.language:navigator.languages[0]}function J(e){return e?new Intl.DateTimeFormat(q(),{dateStyle:`short`}).format(new Date(e)):`?`}const Y=t({type:`dateAfter`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return _(e)&&_(t)?m(e)&&m(t)?(r?h(e).getTime()>=h(t).getTime():h(e).getTime()>h(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 ${J(e)}`}),X=t({type:`dateBefore`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return _(e)&&_(t)?m(e)&&m(t)?(r?h(e).getTime()<=h(t).getTime():h(e).getTime()<h(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 ${J(e)}`}),Z=t({type:`dateBetween`,validator:(e,t,n,r)=>{let{allowEqual:i=!0}=r??{};return m(e)&&m(t)&&m(n)?i?h(e).getTime()>=h(t).getTime()&&h(e).getTime()<=h(n).getTime():h(e).getTime()>h(t).getTime()&&h(e).getTime()<h(n).getTime():!0},message:({$params:[e,t]})=>`The date must be between ${J(e)} and ${J(t)}`}),re=t({type:`decimal`,validator(e){return f(e)?!0:y(e,I)},message:`The value must be decimal`}),ie=t({type:`email`,validator(e){return f(e)?!0:y(e,L)},message:`The value must be an valid email address`}),ae=t({type:`emoji`,validator(e){return f(e)?!0:O().test(e)},message:`The value should be a valid emoji`}),oe=t({type:`endsWith`,validator(e,t){return _(e)&&_(t)&&S(e)&&S(t)?e.endsWith(t):!0},message({$params:[e]}){return`The value must end with ${e}`}}),se=t({type:`exactDigits`,validator:(e,t)=>{if(_(e,!1)&&_(t)){if(v(t)){let n=RegExp(`^\\d{${t}}$`);return y(e.toString(),n)}return!0}return!0},message:({$params:[e]})=>`The value should have exactly ${e} digits`}),ce=t({type:`exactLength`,validator:(e,t)=>_(e,!1)&&_(t)?v(t)?b(e)===t:!1:!0,message:({$params:[e]})=>`The value should be exactly ${e} characters long`}),le=t({type:`exactValue`,validator:(e,t)=>_(e)&&_(t)&&v(t)&&!isNaN(x(e))?x(e)===t:!0,message:({$params:[e]})=>`The value must be equal to ${e}`}),ue=t({type:`file`,validator:e=>_(e)?d(e):!0,message:`The value must be a native File`}),de=t({type:`fileType`,validator:(e,t)=>_(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(`, `)}.`}}),fe=t({type:`hexadecimal`,validator(e){return f(e)?!0:y(e,j)},message:`The value must be hexadecimal`}),pe=t({type:`hostname`,validator(e){return f(e)?!0:y(e,E)},message:`The value is not a valid hostname`}),Q=t({type:`url`,validator(e,t={}){try{if(f(e))return!0;let{protocol:n}=t||{},r=new URL(e);return!E.test(r.hostname)||n&&!n.test(r.protocol.endsWith(`:`)?r.protocol.slice(0,-1):r.protocol)?!1:y(e,D)}catch{return!1}},message:`The value is not a valid URL address`}),me=t({type:`httpUrl`,validator(e,t={}){if(f(e))return!0;let{protocol:n=ne}=t||{};return Q({protocol:n}).exec(e)},message:`The value is not a valid http URL address`}),he=t({type:`integer`,validator(e){return f(e)?!0:y(e,R)},message:`The value must be an integer`});function ge(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 _e=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(ge)},message:`The value is not a valid IPv4 address`});function ve(e){return o(l((e,t)=>_(e)&&_(t)?t===e:!0,[r(()=>i(e))]),({$params:[e]})=>`Value should be ${e}.`)}const ye=t({type:`lowercase`,validator(e){return f(e)?!0:y(e,k)},message:`The value is not a valid lowercase string`}),be=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(xe)},message:`The value is not a valid MAC Address`}),xe=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/),Se=t({type:`maxFileSize`,validator:(e,t)=>_(e)&&d(e)?{$valid:e.size<=t,fileSize:e.size}:!0,message({$params:[e],fileSize:t}){return`File size (${g(t)}) cannot exceed ${g(e)}`}}),Ce=t({type:`maxLength`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return _(e,!1)&&_(t)&&v(t)?r?b(e)<=t:b(e)<t:!0},message:({$value:e,$params:[t]})=>Array.isArray(e)?`This list should have maximum ${t} items`:`The value length should not exceed ${t}`}),we=t({type:`maxValue`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return _(e)&&_(t)&&!isNaN(x(e))&&!isNaN(x(t))?r?x(e)<=x(t):x(e)<x(t):!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}`}}),Te=t({type:`minFileSize`,validator:(e,t)=>_(e)&&d(e)?{$valid:e.size>=t,fileSize:e.size}:!0,message({$params:[e],fileSize:t}){return`File size (${g(t)}) must be at least ${g(e)}`}}),Ee=t({type:`minLength`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return _(e,!1)&&_(t)&&v(t)?r?b(e)>=t:b(e)>t:!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}`}),De=t({type:`minValue`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return _(e)&&_(t)&&!isNaN(x(e))&&!isNaN(x(t))?r?x(e)>=x(t):x(e)>x(t):!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 $(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 Oe(e){return o(l((e,t)=>_(e)&&!f(t)?$(t).includes(e):!0,[r(()=>i(e))]),({$params:[e]})=>`The value should be one of those options: ${Object.values(e).join(`, `)}.`)}const ke=t({type:`number`,validator:e=>_(e)?v(e):!0,message:`The value must be a native number`}),Ae=t({type:`numeric`,validator(e){return f(e)?!0:y(e,z)},message:`The value must be numeric`}),je=t({type:`oneOf`,validator(e,t){return _(e)&&_(t,!1)?t.includes(e):!0},message:({$params:[e]})=>`The value should be one of those options: ${e.join(`, `)}.`}),Me=t({type:`regex`,validator(e,t){return _(e)?y(e,...Array.isArray(t)?t:[t]):!0},message:`The value does not match the required pattern`}),Ne=t({type:`required`,validator:e=>_(e),message:`This field is required`}),Pe=t({type:`required`,validator(e,t){return t?_(e):!0},message:`This field is required`,active({$params:[e]}){return e}}),Fe=t({type:`required`,validator(e,t){return t?!0:_(e)},message:`This field is required`,active({$params:[e]}){return!e}}),Ie=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`}}),Le=t({type:`startsWith`,validator(e,t){return _(e)&&_(t)&&S(e)&&S(t)?e.startsWith(t):!0},message({$params:[e]}){return`The value must start with ${e}`}}),Re=t({type:`string`,validator:e=>_(e)?typeof e==`string`:!0,message:`The value must be a string`});function ze(){return(()=>!0)}const Be=t({type:`uppercase`,validator(e){return f(e)?!0:y(e,A)},message:`The value is not a valid uppercase string`});export{B as alpha,V as alphaNum,ee as and,u as applyIf,te as assignIf,H as between,U as boolean,W as checked,G as contains,K as date,Y as dateAfter,X as dateBefore,Z as dateBetween,re as decimal,ie as email,ae as emoji,oe as endsWith,se as exactDigits,ce as exactLength,le as exactValue,ue as file,de as fileType,b as getSize,fe as hexadecimal,pe as hostname,me as httpUrl,he as integer,_e as ipv4Address,m as isDate,f as isEmpty,_ as isFilled,v as isNumber,ve as literal,ye as lowercase,be as macAddress,y as matchRegex,Se as maxFileSize,Ce as maxLength,we as maxValue,Te as minFileSize,Ee as minLength,De as minValue,Oe as nativeEnum,w as not,ke as number,Ae as numeric,je as oneOf,C as or,Me as regex,Ne as required,Pe as requiredIf,Fe as requiredUnless,Ie as sameAs,Le as startsWith,Re as string,h as toDate,x as toNumber,ze as type,Be as uppercase,Q as url,c as withAsync,o as withMessage,l as withParams,s as withTooltip};
|
|
7
|
+
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,c=!1;typeof n==`function`&&!(`_validator`in n)?(i=e.Inline,a=n):{_type:i,validator:a,_active:o,_params:s,_async:c}=n;let l=t({type:i,validator:a,active:o,message:r,async:c}),u=[...s??[]];if(l._params=u,l._message_patched=!0,typeof l==`function`){if(s!=null){let e=l(...u);return e._message_patched=!0,e}return l}else return l}function s(n,r){let i,a,o,s,c,l=!1;typeof n==`function`&&!(`_validator`in n)?(i=e.Inline,a=n):{_type:i,validator:a,_active:o,_params:s,_message:c,_async:l}=n;let u=t({type:i,validator:a,active:o,message:c,tooltip:r,async:l}),d=[...s??[]];if(u._params=d,u._tooltip_patched=!0,typeof u==`function`){let e=u(...d);return u._tooltip_patched=!0,e}else return u}function c(n,r){let i,a,o=[],s=``;typeof n==`function`?(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:i??e.Async,validator:a,message:s,async:!0});return c._params=c._params?.concat(o),c(...r??[])}function l(n,r){let i,a,o=[],s=``;typeof n==`function`?(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(e){return e?.constructor?.name==`File`}function d(e,t=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):u(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:typeof e==`object`&&e?Object.keys(e).length===0:!String(e).length}function f(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function ee(e){return(f(e)||typeof e==`function`)&&`_validator`in e}function p(r,i){let a,o,s=[],c=``,l=!1;typeof i==`function`&&!(`_validator`in i)?(a=e.Inline,o=i,s=[r]):ee(i)&&({_type:a,validator:o,_message:c,_async:l,_params:s}=i,s=(s??[])?.concat([r]));function u(e,...t){let[i]=n([r]);return i?o(e,...t):!0}function d(){let[e]=n([r]);return e}let f=t({type:a,validator:u,active:d,message:c,async:l}),p=[...s??[]];return f._params=p,typeof f==`function`?f(...p):f}function m(e){if(d(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 h(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 g(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 _(e,t=!0){return!d(typeof e==`string`?e.trim():e,t)}function v(e){return e==null?!1:typeof e==`number`?!isNaN(e):!1}function y(e,...t){if(d(e))return!0;let n=typeof e==`number`?e.toString():e;return t.every(e=>(e.lastIndex=0,e.test(n)))}function b(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 x(e){return typeof e==`number`?e:e==null?NaN:typeof e==`string`&&e.trim()===e?+e:NaN}function S(e){return e==null?!1:typeof e==`string`}function C(...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){return e?.some(e=>typeof e!=`boolean`)?{$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)=>a(await Promise.all(i(e,t,...n))):(t,...n)=>a(i(e,t,...n)):e=>!1;let s=t({type:`and`,validator:o,message:`The value does not match all of the provided validators`}),c=[...r??[]];return s._params=c,typeof s==`function`?s(...c):s}function w(...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){return e.some(e=>typeof e!=`boolean`)?{$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=t({type:`or`,validator:n?async(t,...n)=>a(await Promise.all(i(e,t,...n))):(t,...n)=>a(i(e,t,...n)),message:`The value does not match any of the provided validators`}),s=[...r??[]];return o._params=s,typeof o==`function`?o(...s):o}function te(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)=>_(e)?!await i(e,...t):!0:(e,...t)=>_(e)?!i(e,...t):!0;let c=t({type:`not`,validator:a,message:n??`Error`}),l=[...o??[]];return c._params=l,typeof c==`function`?c(...l):c}function T(e,t,n){return Object.entries(i(t)).map(([t,r])=>typeof r==`function`||f(r)&&`_validator`in r?[t,p(n?e:()=>!i(e),r)]:[t,r])}function ne(e,t,n){return r(()=>{let r=T(e,t,!0),i=n?T(e,n,!1):[];return Object.fromEntries([...r,...i])})}const E=/^https?$/,D=/^(?=.{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])?)*\.?$/,O=/^(?:(?:(?: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 k(){return RegExp(`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`,`u`)}const A=/^[^A-Z]*$/,j=/^[^a-z]*$/,M=/^[0-9a-fA-F]*$/,N=/^[a-zA-Z]*$/,P=/^[\w.]+$/,F=/^[a-zA-Z0-9]*$/,I=/^[a-zA-Z0-9_]*$/,L=/^[-]?\d*(\.\d+)?$/,R=/^(?:[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,z=/(^[0-9]*$)|(^-[0-9]+$)/,B=/^\d*(\.\d+)?$/,V=t({type:`alpha`,validator(e,t){return d(e)?!0:t?.allowSymbols?y(e,P):y(e,N)},message:`The value is not alphabetical`}),H=t({type:`alphaNum`,validator(e,t){return d(e)?!0:t?.allowSymbols?y(e,I):y(e,F)},message:`The value must be alpha-numeric`}),U=t({type:`between`,validator:(e,t,n,r)=>{let{allowEqual:i=!0}=r??{};if(_(e)&&_(t)&&_(n)){let r=x(e),a=x(t),o=x(n);return v(r)&&v(a)&&v(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}`}),W=t({type:`boolean`,validator:e=>_(e)?typeof e==`boolean`:!0,message:`The value must be a native boolean`}),G=t({type:`checked`,validator:e=>_(e)?e===!0:!0,message:`The field must be checked`}),K=t({type:`contains`,validator(e,t){return _(e)&&_(t)&&S(e)&&S(t)?e.includes(t):!0},message({$params:[e]}){return`The value must contain ${e}`}}),q=t({type:`date`,validator:e=>_(e)?e instanceof Date:!0,message:`The value must be a native Date`});function J(){return navigator.languages==null?navigator.language:navigator.languages[0]}function Y(e){return e?new Intl.DateTimeFormat(J(),{dateStyle:`short`}).format(new Date(e)):`?`}const X=t({type:`dateAfter`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return _(e)&&_(t)?m(e)&&m(t)?(r?h(e).getTime()>=h(t).getTime():h(e).getTime()>h(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)}`}),Z=t({type:`dateBefore`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return _(e)&&_(t)?m(e)&&m(t)?(r?h(e).getTime()<=h(t).getTime():h(e).getTime()<h(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)}`}),re=t({type:`dateBetween`,validator:(e,t,n,r)=>{let{allowEqual:i=!0}=r??{};return m(e)&&m(t)&&m(n)?i?h(e).getTime()>=h(t).getTime()&&h(e).getTime()<=h(n).getTime():h(e).getTime()>h(t).getTime()&&h(e).getTime()<h(n).getTime():!0},message:({$params:[e,t]})=>`The date must be between ${Y(e)} and ${Y(t)}`}),ie=t({type:`decimal`,validator(e){return d(e)?!0:y(e,L)},message:`The value must be decimal`}),ae=t({type:`email`,validator(e){return d(e)?!0:y(e,R)},message:`The value must be an valid email address`}),oe=t({type:`emoji`,validator(e){return d(e)?!0:k().test(e)},message:`The value should be a valid emoji`}),se=t({type:`endsWith`,validator(e,t){return _(e)&&_(t)&&S(e)&&S(t)?e.endsWith(t):!0},message({$params:[e]}){return`The value must end with ${e}`}}),ce=t({type:`exactDigits`,validator:(e,t)=>{if(_(e,!1)&&_(t)){if(v(t)){let n=RegExp(`^\\d{${t}}$`);return y(e.toString(),n)}return!0}return!0},message:({$params:[e]})=>`The value should have exactly ${e} digits`}),le=t({type:`exactLength`,validator:(e,t)=>_(e,!1)&&_(t)?v(t)?b(e)===t:!1:!0,message:({$params:[e]})=>`The value should be exactly ${e} characters long`}),ue=t({type:`exactValue`,validator:(e,t)=>_(e)&&_(t)&&v(t)&&!isNaN(x(e))?x(e)===t:!0,message:({$params:[e]})=>`The value must be equal to ${e}`}),de=t({type:`file`,validator:e=>_(e)?u(e):!0,message:`The value must be a native File`}),fe=t({type:`fileType`,validator:(e,t)=>_(e)&&u(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(`, `)}.`}}),pe=t({type:`hexadecimal`,validator(e){return d(e)?!0:y(e,M)},message:`The value must be hexadecimal`}),me=t({type:`hostname`,validator(e){return d(e)?!0:y(e,D)},message:`The value is not a valid hostname`}),Q=t({type:`url`,validator(e,t={}){try{if(d(e))return!0;let{protocol:n}=t||{},r=new URL(e);return!D.test(r.hostname)||n&&!n.test(r.protocol.endsWith(`:`)?r.protocol.slice(0,-1):r.protocol)?!1:y(e,O)}catch{return!1}},message:`The value is not a valid URL address`}),he=t({type:`httpUrl`,validator(e,t={}){if(d(e))return!0;let{protocol:n=E}=t||{};return Q({protocol:n}).exec(e)},message:`The value is not a valid http URL address`}),ge=t({type:`integer`,validator(e){return d(e)?!0:y(e,z)},message:`The value must be an integer`});function _e(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(d(e))return!0;if(typeof e!=`string`)return!1;let t=e.split(`.`);return t.length===4&&t.every(_e)},message:`The value is not a valid IPv4 address`});function ye(e){return o(l((e,t)=>_(e)&&_(t)?t===e:!0,[r(()=>i(e))]),({$params:[e]})=>`Value should be ${e}.`)}const be=t({type:`lowercase`,validator(e){return d(e)?!0:y(e,A)},message:`The value is not a valid lowercase string`}),xe=t({type:`macAddress`,validator(e,t=`:`){if(d(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(Se)},message:`The value is not a valid MAC Address`}),Se=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/),Ce=t({type:`maxFileSize`,validator:(e,t)=>_(e)&&u(e)?{$valid:e.size<=t,fileSize:e.size}:!0,message({$params:[e],fileSize:t}){return`File size (${g(t)}) cannot exceed ${g(e)}`}}),we=t({type:`maxLength`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return _(e,!1)&&_(t)&&v(t)?r?b(e)<=t:b(e)<t:!0},message:({$value:e,$params:[t]})=>Array.isArray(e)?`This list should have maximum ${t} items`:`The value length should not exceed ${t}`}),Te=t({type:`maxValue`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return _(e)&&_(t)&&!isNaN(x(e))&&!isNaN(x(t))?r?x(e)<=x(t):x(e)<x(t):!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}`}}),Ee=t({type:`minFileSize`,validator:(e,t)=>_(e)&&u(e)?{$valid:e.size>=t,fileSize:e.size}:!0,message({$params:[e],fileSize:t}){return`File size (${g(t)}) must be at least ${g(e)}`}}),De=t({type:`minLength`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return _(e,!1)&&_(t)&&v(t)?r?b(e)>=t:b(e)>t:!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 _(e)&&_(t)&&!isNaN(x(e))&&!isNaN(x(t))?r?x(e)>=x(t):x(e)>x(t):!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 ke(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 Ae(e){return o(l((e,t)=>_(e)&&!d(t)?ke(t).includes(e):!0,[r(()=>i(e))]),({$params:[e]})=>`The value should be one of those options: ${Object.values(e).join(`, `)}.`)}const je=t({type:`number`,validator:e=>_(e)?v(e):!0,message:`The value must be a native number`}),Me=t({type:`numeric`,validator(e){return d(e)?!0:y(e,B)},message:`The value must be numeric`}),Ne=t({type:`oneOf`,validator(e,t){return _(e)&&_(t,!1)?t.includes(e):!0},message:({$params:[e]})=>`The value should be one of those options: ${e.join(`, `)}.`}),Pe=t({type:`regex`,validator(e,t){return _(e)?y(e,...Array.isArray(t)?t:[t]):!0},message:`The value does not match the required pattern`}),$=t({type:`required`,validator:e=>_(e),message:`This field is required`}),Fe=t({type:`required`,validator(e,t){return t?_(e):!0},message:`This field is required`,active({$params:[e]}){return e}}),Ie=t({type:`required`,validator(e,t){return t?!0:_(e)},message:`This field is required`,active({$params:[e]}){return!e}}),Le=t({type:`sameAs`,validator(e,t,n){return d(e)?!0:e===t},message({$params:[e,t=`other`]}){return`The value must be equal to the ${t} value`}}),Re=t({type:`startsWith`,validator(e,t){return _(e)&&_(t)&&S(e)&&S(t)?e.startsWith(t):!0},message({$params:[e]}){return`The value must start with ${e}`}}),ze=t({type:`string`,validator:e=>_(e)?typeof e==`string`:!0,message:`The value must be a string`});function Be(){return(()=>!0)}const Ve=t({type:`uppercase`,validator(e){return d(e)?!0:y(e,j)},message:`The value is not a valid uppercase string`});export{V as alpha,H as alphaNum,C as and,p as applyIf,ne as assignIf,U as between,W as boolean,G as checked,K as contains,q as date,X as dateAfter,Z as dateBefore,re as dateBetween,ie as decimal,ae as email,oe as emoji,se as endsWith,ce as exactDigits,le as exactLength,ue as exactValue,de as file,fe as fileType,b as getSize,pe as hexadecimal,me as hostname,he as httpUrl,ge as integer,ve as ipv4Address,m as isDate,d as isEmpty,_ as isFilled,v as isNumber,ye as literal,be as lowercase,xe as macAddress,y as matchRegex,Ce as maxFileSize,we as maxLength,Te as maxValue,Ee as minFileSize,De as minLength,Oe as minValue,Ae as nativeEnum,te as not,je as number,Me as numeric,Ne as oneOf,w as or,Pe as regex,$ as required,Fe as requiredIf,Ie as requiredUnless,Le as sameAs,Re as startsWith,ze as string,h as toDate,x as toNumber,Be as type,Ve as uppercase,Q as url,c as withAsync,o as withMessage,l as withParams,s as withTooltip};
|
package/package.json
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regle/rules",
|
|
3
|
-
"version": "1.17.
|
|
3
|
+
"version": "1.17.1",
|
|
4
4
|
"description": "Collection of rules and helpers for Regle",
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
"homepage": "https://reglejs.dev/",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "Victor Garcia",
|
|
9
|
+
"url": "https://github.com/victorgarciaesgi"
|
|
8
10
|
},
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"@vue/test-utils": "2.4.6",
|
|
13
|
-
"prettier": "3.7.4",
|
|
14
|
-
"tsdown": "0.18.3",
|
|
15
|
-
"type-fest": "5.3.1",
|
|
16
|
-
"typescript": "5.9.3",
|
|
17
|
-
"vitest": "4.0.16",
|
|
18
|
-
"vue": "3.5.26",
|
|
19
|
-
"vue-tsc": "3.2.1"
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/victorgarciaesgi/regle.git"
|
|
20
14
|
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"LICENSE",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
21
20
|
"type": "module",
|
|
21
|
+
"main": "./dist/regle-rules.js",
|
|
22
|
+
"module": "./dist/regle-rules.js",
|
|
23
|
+
"types": "./dist/regle-rules.d.ts",
|
|
22
24
|
"exports": {
|
|
23
25
|
".": {
|
|
24
26
|
"types": "./dist/regle-rules.d.ts",
|
|
@@ -29,27 +31,24 @@
|
|
|
29
31
|
"./package.json": "./package.json",
|
|
30
32
|
"./dist/*": "./dist/*"
|
|
31
33
|
},
|
|
32
|
-
"main": "./dist/regle-rules.js",
|
|
33
|
-
"module": "./dist/regle-rules.js",
|
|
34
|
-
"types": "./dist/regle-rules.d.ts",
|
|
35
|
-
"files": [
|
|
36
|
-
"dist",
|
|
37
|
-
"LICENSE",
|
|
38
|
-
"README.md"
|
|
39
|
-
],
|
|
40
34
|
"publishConfig": {
|
|
41
35
|
"access": "public"
|
|
42
36
|
},
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"type-fest": "5.4.1",
|
|
39
|
+
"@regle/core": "1.17.1"
|
|
46
40
|
},
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
"
|
|
50
|
-
"
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/node": "22.19.7",
|
|
43
|
+
"@vue/reactivity": "3.5.27",
|
|
44
|
+
"@vue/test-utils": "2.4.6",
|
|
45
|
+
"tsdown": "0.18.4",
|
|
46
|
+
"type-fest": "5.4.1",
|
|
47
|
+
"typescript": "5.9.3",
|
|
48
|
+
"vitest": "4.0.17",
|
|
49
|
+
"vue": "3.5.27",
|
|
50
|
+
"vue-tsc": "3.2.2"
|
|
51
51
|
},
|
|
52
|
-
"license": "MIT",
|
|
53
52
|
"scripts": {
|
|
54
53
|
"typecheck": "vue-tsc --noEmit",
|
|
55
54
|
"build": "tsdown",
|