@regle/rules 1.2.0-beta.1 → 1.2.0-beta.3

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 CHANGED
@@ -5,7 +5,7 @@
5
5
  # Regle
6
6
 
7
7
 
8
- Regle \ʁɛɡl\ (French word for 'rule' ) is a Typescript-first model-based validation library for Vue 3.
8
+ Regle \ʁɛɡl\ (French word for 'rule') is a Typescript-first model-based validation library for Vue 3.
9
9
  It's heavily inspired by Vuelidate.
10
10
 
11
11
 
@@ -15,15 +15,20 @@ It's heavily inspired by Vuelidate.
15
15
 
16
16
  ## 🎮 Play with it
17
17
 
18
- | Simple demo | Advanced Demo |
19
- | ------------- | ------------- |
20
- | [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/~/github.com/victorgarciaesgi/regle-examples/tree/main/examples/simple-example?file=examples/simple-example/src/App.vue&configPath=examples/simple-example) | [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/~/github.com/victorgarciaesgi/regle-examples/tree/main/examples/advanced-example?file=examples/advanced-example/src/App.vue&configPath=examples/advanced-example) |
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> | [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/~/github.com/victorgarciaesgi/regle-examples/tree/main/examples/simple-example?file=examples/simple-example/src/App.vue&configPath=examples/simple-example) | [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/~/github.com/victorgarciaesgi/regle-examples/tree/main/examples/advanced-example?file=examples/advanced-example/src/App.vue&configPath=examples/advanced-example) |
21
21
 
22
22
  ## 🧰 Features
23
- - ✅ 100% type inference
24
- - 📖 Model based validation
25
- - 🛒 Collection validation
26
- - 💀 Headless
27
- - 🪗 Extensible
28
- - 🦸‍♂️ [Zod](https://zod.dev/) support
29
- - 🤖 [Valibot](https://valibot.dev/) support
23
+
24
+ - ☁️ Headless
25
+ - Type safety
26
+ - 🧮 Model based
27
+ - 🧰 Modular
28
+ - 🔄 Async validation
29
+ - 🌐 Plug any i18n library
30
+ - 📗 Vuelidate compatible API
31
+ - Standard Schemas spec support
32
+ - 🦸‍♂️ [Zod](https://zod.dev/)
33
+ - 🤖 [Valibot](https://valibot.dev/)
34
+ - 🚢 [ArkType](https://arktype.io) 🚧
@@ -1,4 +1,4 @@
1
- import { RegleRuleMetadataDefinition, RegleRuleWithParamsDefinition, RegleRuleDefinitionWithMetadataProcessor, RegleRuleMetadataConsumer, RegleRuleDefinition, InlineRuleDeclaration, UnwrapRegleUniversalParams, Maybe, FormRuleDeclaration, CommonComparisonOptions, CommonAlphaOptions, MaybeInput } from '@regle/core';
1
+ import { RegleRuleMetadataDefinition, RegleRuleWithParamsDefinition, RegleRuleDefinitionWithMetadataProcessor, RegleRuleMetadataConsumer, RegleRuleDefinition, InlineRuleDeclaration, UnwrapRegleUniversalParams, Maybe, FormRuleDeclaration, CommonAlphaOptions, MaybeInput, CommonComparisonOptions } from '@regle/core';
2
2
  import { Ref, MaybeRefOrGetter, MaybeRef } from 'vue';
3
3
 
4
4
  /**
@@ -197,29 +197,6 @@ declare function or<TRules extends [FormRuleDeclaration<any, any>, ...FormRuleDe
197
197
  */
198
198
  declare function not<TValue, TParams extends any[] = [], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition> = RegleRuleMetadataDefinition, TMetadata extends RegleRuleMetadataDefinition = TReturn extends Promise<infer M> ? M : TReturn, TAsync extends boolean = TReturn extends Promise<any> ? true : false>(rule: RegleRuleDefinition<TValue, TParams, TAsync, TMetadata> | InlineRuleDeclaration<TValue, TParams, TReturn>, message?: RegleRuleDefinitionWithMetadataProcessor<TValue, RegleRuleMetadataConsumer<TValue, TParams, TMetadata>, string | string[]>): RegleRuleDefinition<TValue, TParams, TAsync, TMetadata>;
199
199
 
200
- /**
201
- * Requires non-empty data. Checks for empty arrays and strings containing only whitespaces.
202
- */
203
- declare const required: RegleRuleDefinition<unknown, [], false, boolean, unknown>;
204
-
205
- /**
206
- * Requires the input value to have a maximum specified length, inclusive. Works with arrays, objects and strings.
207
- *
208
- * @param max - the maximum length
209
- * @param options - comparision options
210
- */
211
- declare const maxLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [
212
- count: number,
213
- options?: CommonComparisonOptions
214
- ], false, boolean>;
215
-
216
- /**
217
- * Requires non-empty data, only if provided data property, ref, or a function resolves to true.
218
- *
219
- * @param condition - the condition to enable the required rule
220
- */
221
- declare const requiredIf: RegleRuleWithParamsDefinition<unknown, [condition: boolean], false, boolean>;
222
-
223
200
  /**
224
201
  * Allows only alphabetic characters.
225
202
  *
@@ -251,121 +228,65 @@ declare const between: RegleRuleWithParamsDefinition<number, [
251
228
  ], false, boolean, MaybeInput<number>>;
252
229
 
253
230
  /**
254
- * Allows positive and negative decimal numbers.
255
- */
256
- declare const decimal: RegleRuleDefinition<string | number, [
257
- ], false, boolean, MaybeInput<number | undefined>>;
258
-
259
- /**
260
- * Validates email addresses. Always verify on the server to ensure the address is real and not already in use.
261
- */
262
- declare const email: RegleRuleDefinition<string, [], false, boolean, MaybeInput<string>>;
263
-
264
- /**
265
- * Allows only integers (positive and negative).
266
- */
267
- declare const integer: RegleRuleDefinition<string | number, [], false, boolean, MaybeInput<number>>;
268
-
269
- /**
270
- * Requires a field to have a specified maximum numeric value.
271
- *
272
- * @param max - the maximum value
273
- * @param options - comparision options
274
- */
275
- declare const maxValue: RegleRuleWithParamsDefinition<number, [
276
- count: number,
277
- options?: CommonComparisonOptions
278
- ], false, boolean, MaybeInput<number>>;
279
-
280
- /**
281
- * Requires the input value to have a minimum specified length, inclusive. Works with arrays, objects and strings.
231
+ * Requires a value to be a native boolean type
282
232
  *
283
- * @param min - the minimum value
284
- * @param options - comparision options
285
- */
286
- declare const minLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [
287
- count: number,
288
- options?: CommonComparisonOptions
289
- ], false, boolean>;
290
-
291
- /**
292
- * Requires a field to have a specified minimum numeric value.
293
- *
294
- * @param count - the minimum count
295
- * @param options - comparision options
233
+ * Mainly used for typing
296
234
  */
297
- declare const minValue: RegleRuleWithParamsDefinition<number, [
298
- count: number,
299
- options?: CommonComparisonOptions
300
- ], false, boolean, MaybeInput<number>>;
235
+ declare const boolean: RegleRuleDefinition<unknown, [], false, boolean, MaybeInput<boolean>, unknown>;
301
236
 
302
237
  /**
303
- * Requires a field to have a strict numeric value.
238
+ * Requires a boolean value to be true. This is useful for checkbox inputs.
304
239
  */
305
- declare const exactValue: RegleRuleWithParamsDefinition<number, [
306
- count: number
307
- ], false, boolean, MaybeInput<number>>;
240
+ declare const checked: RegleRuleDefinition<boolean, [], false, boolean, MaybeInput<boolean>>;
308
241
 
309
242
  /**
310
- * Requires the input value to have a strict specified length, inclusive. Works with arrays, objects and strings.
243
+ * Checks if the string contains the specified substring.
311
244
  *
312
- * @param count - the required length
313
- */
314
- declare const exactLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [
315
- count: number
316
- ], false, boolean>;
317
-
318
- /**
319
- * Allows only numeric values (including numeric strings).
245
+ * @param part - the part the value needs to contain
320
246
  */
321
- declare const numeric: RegleRuleDefinition<string | number, [
322
- ], false, boolean, MaybeInput<string | number>>;
247
+ declare const contains: RegleRuleWithParamsDefinition<string, [
248
+ part: MaybeInput<string>
249
+ ], false, boolean, MaybeInput<string>>;
323
250
 
324
251
  /**
325
- * Requires non-empty data, only if provided data property, ref, or a function resolves to false.
252
+ * Requires a value to be a native Date constructor
326
253
  *
327
- * @param condition - the condition to disable the required rule
328
- */
329
- declare const requiredUnless: RegleRuleWithParamsDefinition<unknown, [condition: boolean], false, boolean>;
330
-
331
- /**
332
- * Checks if the value matches the specified property or ref.
333
- */
334
- declare const sameAs: RegleRuleWithParamsDefinition<unknown, [target: unknown, otherName?: string], false, boolean>;
335
-
336
- /**
337
- * Validates URLs.
254
+ * Mainly used for typing
338
255
  */
339
- declare const url: RegleRuleDefinition<string, [], false, boolean, MaybeInput<string>>;
256
+ declare const date: RegleRuleDefinition<unknown, [], false, boolean, MaybeInput<Date>, unknown>;
340
257
 
341
258
  /**
342
259
  * Checks if the date is after the given parameter.
343
260
  *
344
261
  * @param after - the date to compare to
262
+ * @param options - comparison options
345
263
  */
346
264
  declare const dateAfter: RegleRuleWithParamsDefinition<string | Date, [
347
- after: MaybeInput<string | Date>
265
+ after: MaybeInput<string | Date>,
266
+ options?: CommonComparisonOptions
348
267
  ], false, true | {
349
268
  $valid: false;
350
269
  error: 'date-not-after';
351
270
  } | {
352
271
  $valid: false;
353
- error: 'value-or-paramater-not-a-date';
272
+ error: 'value-or-parameter-not-a-date';
354
273
  }, MaybeInput<string | Date>>;
355
274
 
356
275
  /**
357
276
  * Checks if the date is before the given parameter.
358
277
  *
359
278
  * @param before - the date to compare to
279
+ * @param options - comparison options
360
280
  */
361
281
  declare const dateBefore: RegleRuleWithParamsDefinition<string | Date, [
362
- before: MaybeInput<string | Date>
282
+ before: MaybeInput<string | Date>,
283
+ options?: CommonComparisonOptions
363
284
  ], false, true | {
364
285
  $valid: false;
365
286
  error: 'date-not-before';
366
287
  } | {
367
288
  $valid: false;
368
- error: 'value-or-paramater-not-a-date';
289
+ error: 'value-or-parameter-not-a-date';
369
290
  }, MaybeInput<string | Date>>;
370
291
 
371
292
  /**
@@ -373,17 +294,70 @@ declare const dateBefore: RegleRuleWithParamsDefinition<string | Date, [
373
294
  *
374
295
  * @param before - the minimum limit
375
296
  * @param after - the maximum limit
297
+ * @param options - comparison options
376
298
  */
377
299
  declare const dateBetween: RegleRuleWithParamsDefinition<string | Date, [
378
300
  before: MaybeInput<string | Date>,
379
- after: MaybeInput<string | Date>
301
+ after: MaybeInput<string | Date>,
302
+ options?: CommonComparisonOptions
380
303
  ], false, boolean, MaybeInput<string | Date>>;
381
304
 
305
+ /**
306
+ * Allows positive and negative decimal numbers.
307
+ */
308
+ declare const decimal: RegleRuleDefinition<string | number, [
309
+ ], false, boolean, MaybeInput<number | undefined>>;
310
+
311
+ /**
312
+ * Validates email addresses. Always verify on the server to ensure the address is real and not already in use.
313
+ */
314
+ declare const email: RegleRuleDefinition<string, [], false, boolean, MaybeInput<string>>;
315
+
316
+ /**
317
+ * Checks if the string ends with the specified substring.
318
+ *
319
+ * @param part - the value the field must end with
320
+ */
321
+ declare const endsWith: RegleRuleWithParamsDefinition<string, [
322
+ part: MaybeInput<string>
323
+ ], false, boolean, MaybeInput<string>>;
324
+
325
+ /**
326
+ * Requires the input value to have a strict specified length, inclusive. Works with arrays, objects and strings.
327
+ *
328
+ * @param count - the required length
329
+ */
330
+ declare const exactLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [
331
+ count: number
332
+ ], false, boolean>;
333
+
334
+ /**
335
+ * Requires a field to have a strict numeric value.
336
+ */
337
+ declare const exactValue: RegleRuleWithParamsDefinition<number, [
338
+ count: number
339
+ ], false, boolean, MaybeInput<number>>;
340
+
341
+ /**
342
+ * Allows only hexadecimal values.
343
+ */
344
+ declare const hexadecimal: RegleRuleDefinition<string, [], false, boolean, MaybeInput<string>>;
345
+
346
+ /**
347
+ * Allows only integers (positive and negative).
348
+ */
349
+ declare const integer: RegleRuleDefinition<string | number, [], false, boolean, MaybeInput<number>>;
350
+
382
351
  /**
383
352
  * Validates IPv4 addresses in dotted decimal notation 127.0.0.1.
384
353
  */
385
354
  declare const ipv4Address: RegleRuleDefinition<string, [], false, boolean, MaybeInput<string>>;
386
355
 
356
+ /**
357
+ * Allow only one possible literal value
358
+ */
359
+ declare function literal<const TValue extends string | number>(literal: MaybeRefOrGetter<TValue>): RegleRuleDefinition<TValue, [literal: TValue], false, boolean, MaybeInput<TValue>, string | number>;
360
+
387
361
  /**
388
362
  * Validates MAC addresses. Call as a function to specify a custom separator (e.g., ':' or an empty string for 00ff1122334455).
389
363
  *
@@ -394,42 +368,69 @@ declare const macAddress: RegleRuleWithParamsDefinition<string, [
394
368
  ], false, boolean, MaybeInput<string>>;
395
369
 
396
370
  /**
397
- * Requires a boolean value to be true. This is useful for checkbox inputs.
371
+ * Requires the input value to have a maximum specified length, inclusive. Works with arrays, objects and strings.
372
+ *
373
+ * @param max - the maximum length
374
+ * @param options - comparison options
398
375
  */
399
- declare const checked: RegleRuleDefinition<boolean, [], false, boolean, MaybeInput<boolean>>;
376
+ declare const maxLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [
377
+ count: number,
378
+ options?: CommonComparisonOptions
379
+ ], false, boolean>;
400
380
 
401
381
  /**
402
- * Checks if the string contains the specified substring.
382
+ * Requires a field to have a specified maximum numeric value.
403
383
  *
404
- * @param part - the part the value needs to contain
384
+ * @param max - the maximum value
385
+ * @param options - comparison options
405
386
  */
406
- declare const contains: RegleRuleWithParamsDefinition<string, [
407
- part: MaybeInput<string>
408
- ], false, boolean, MaybeInput<string>>;
387
+ declare const maxValue: RegleRuleWithParamsDefinition<number, [
388
+ count: number,
389
+ options?: CommonComparisonOptions
390
+ ], false, boolean, MaybeInput<number>>;
409
391
 
410
392
  /**
411
- * Checks if the string starts with the specified substring.
393
+ * Requires the input value to have a minimum specified length, inclusive. Works with arrays, objects and strings.
412
394
  *
413
- * @private part - the vlaue the field must start with
395
+ * @param min - the minimum value
396
+ * @param options - comparison options
414
397
  */
415
- declare const startsWith: RegleRuleWithParamsDefinition<string, [
416
- part: MaybeInput<string>
417
- ], false, boolean, MaybeInput<string>>;
398
+ declare const minLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [
399
+ count: number,
400
+ options?: CommonComparisonOptions
401
+ ], false, boolean>;
418
402
 
419
403
  /**
420
- * Checks if the string ends with the specified substring.
404
+ * Requires a field to have a specified minimum numeric value.
421
405
  *
422
- * @param part - the value the field must end with
406
+ * @param count - the minimum count
407
+ * @param options - comparison options
423
408
  */
424
- declare const endsWith: RegleRuleWithParamsDefinition<string, [
425
- part: MaybeInput<string>
426
- ], false, boolean, MaybeInput<string>>;
409
+ declare const minValue: RegleRuleWithParamsDefinition<number, [
410
+ count: number,
411
+ options?: CommonComparisonOptions
412
+ ], false, boolean, MaybeInput<number>>;
427
413
 
414
+ type EnumLike = {
415
+ [k: string]: string | number;
416
+ [nu: number]: string;
417
+ };
428
418
  /**
429
- * Checks if the value matches one or more regular expressions.
419
+ * Validate against a native Typescript enum value.
430
420
  */
431
- declare const regex: RegleRuleWithParamsDefinition<string | number, [
432
- regexp: RegExp | RegExp[]
421
+ declare function nativeEnum<T extends EnumLike>(enumLike: T): RegleRuleDefinition<MaybeInput<T[keyof T]>, [enumLike: T], false, boolean, MaybeInput<T[keyof T]>, string | number>;
422
+
423
+ /**
424
+ * Requires a value to be a native number type
425
+ *
426
+ * Mainly used for typing
427
+ */
428
+ declare const number: RegleRuleDefinition<unknown, [], false, boolean, MaybeInput<number>, unknown>;
429
+
430
+ /**
431
+ * Allows only numeric values (including numeric strings).
432
+ */
433
+ declare const numeric: RegleRuleDefinition<string | number, [
433
434
  ], false, boolean, MaybeInput<string | number>>;
434
435
 
435
436
  /**
@@ -439,25 +440,66 @@ declare function oneOf<const TValues extends [string | number, ...(string | numb
439
440
  options: TValues
440
441
  ], false, boolean, MaybeInput<TValues[number]>, string | number>;
441
442
 
442
- type EnumLike = {
443
- [k: string]: string | number;
444
- [nu: number]: string;
445
- };
446
443
  /**
447
- * Validate against a native Typescript enum value.
444
+ * Checks if the value matches one or more regular expressions.
448
445
  */
449
- declare function nativeEnum<T extends EnumLike>(enumLike: T): RegleRuleDefinition<MaybeInput<T[keyof T]>, [enumLike: T], false, boolean, MaybeInput<T[keyof T]>, string | number>;
446
+ declare const regex: RegleRuleWithParamsDefinition<string | number, [
447
+ regexp: RegExp | RegExp[]
448
+ ], false, boolean, MaybeInput<string | number>>;
450
449
 
451
450
  /**
452
- * Allow only one possible literal value
451
+ * Requires non-empty data. Checks for empty arrays and strings containing only whitespaces.
453
452
  */
454
- declare function literal<const TValue extends string | number>(literal: MaybeRefOrGetter<TValue>): RegleRuleDefinition<TValue, [literal: TValue], false, boolean, MaybeInput<TValue>, string | number>;
453
+ declare const required: RegleRuleDefinition<unknown, [], false, boolean, unknown>;
454
+
455
+ /**
456
+ * Requires non-empty data, only if provided data property, ref, or a function resolves to true.
457
+ *
458
+ * @param condition - the condition to enable the required rule
459
+ */
460
+ declare const requiredIf: RegleRuleWithParamsDefinition<unknown, [condition: boolean], false, boolean>;
461
+
462
+ /**
463
+ * Requires non-empty data, only if provided data property, ref, or a function resolves to false.
464
+ *
465
+ * @param condition - the condition to disable the required rule
466
+ */
467
+ declare const requiredUnless: RegleRuleWithParamsDefinition<unknown, [condition: boolean], false, boolean>;
468
+
469
+ /**
470
+ * Checks if the value matches the specified property or ref.
471
+ */
472
+ declare const sameAs: <const TTarget extends unknown>(target: MaybeRefOrGetter<TTarget>, otherName?: MaybeRefOrGetter<string>) => RegleRuleDefinition<unknown, [
473
+ target: TTarget,
474
+ otherName?: string
475
+ ], false, boolean, TTarget extends MaybeInput<infer M> ? M : MaybeInput<TTarget>>;
476
+
477
+ /**
478
+ * Checks if the string starts with the specified substring.
479
+ *
480
+ * @private part - the value the field must start with
481
+ */
482
+ declare const startsWith: RegleRuleWithParamsDefinition<string, [
483
+ part: MaybeInput<string>
484
+ ], false, boolean, MaybeInput<string>>;
485
+
486
+ /**
487
+ * Requires a value to be a native string type
488
+ *
489
+ * Mainly used for typing
490
+ */
491
+ declare const string: RegleRuleDefinition<unknown, [], false, boolean, MaybeInput<string>, unknown>;
455
492
 
456
493
  /**
457
- * Define the input type of a rule
494
+ * Define the input type of a rule. No runtime validation.
458
495
  *
459
- * Necessary for using `InferState`
496
+ * Override any input type set by other rules.
460
497
  */
461
498
  declare function type<T>(): RegleRuleDefinition<unknown, [], false, boolean, MaybeInput<T>>;
462
499
 
463
- export { type EnumLike, alpha, alphaNum, and, applyIf, between, checked, contains, dateAfter, dateBefore, dateBetween, decimal, email, endsWith, exactLength, exactValue, getSize, integer, ipv4Address, isDate, isEmpty, isFilled, isNumber, literal, macAddress, matchRegex, maxLength, maxValue, minLength, minValue, nativeEnum, not, numeric, oneOf, or, regex, required, requiredIf, requiredUnless, sameAs, startsWith, toDate, toNumber, type, url, withAsync, withMessage, withParams, withTooltip };
500
+ /**
501
+ * Validates URLs.
502
+ */
503
+ declare const url: RegleRuleDefinition<string, [], false, boolean, MaybeInput<string>>;
504
+
505
+ export { type EnumLike, alpha, alphaNum, and, applyIf, between, boolean, checked, contains, date, dateAfter, dateBefore, dateBetween, decimal, email, endsWith, exactLength, exactValue, getSize, hexadecimal, integer, ipv4Address, isDate, isEmpty, isFilled, isNumber, literal, macAddress, matchRegex, maxLength, maxValue, minLength, minValue, nativeEnum, not, number, numeric, oneOf, or, regex, required, requiredIf, requiredUnless, sameAs, startsWith, string, toDate, toNumber, type, url, withAsync, withMessage, withParams, withTooltip };
@@ -1 +1 @@
1
- import {createRule,InternalRuleType,unwrapRuleParameters}from'@regle/core';import {unref,computed,toValue}from'vue';function D(e,t){let n,r,s,p;typeof e=="function"&&!("_validator"in e)?(n=InternalRuleType.Inline,r=e):{_type:n,validator:r,_active:s,_params:p}=e;let l=createRule({type:n,validator:r,active:s,message:t}),u=[...p??[]];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 F(e,t){let n,r,s,p,l;typeof e=="function"&&!("_validator"in e)?(n=InternalRuleType.Inline,r=e):{_type:n,validator:r,_active:s,_params:p,_message:l}=e;let u=createRule({type:n,validator:r,active:s,message:l,tooltip:t}),a=[...p??[]];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 N(e,t){let n,r,s=[],p="";typeof e=="function"?(n=InternalRuleType.Inline,r=async(u,...a)=>e(u,...a),s=[t]):({_type:n,_message:p}=e,s=s=e._params?.concat(t),r=async(...u)=>e.validator(u));let l=createRule({type:InternalRuleType.Async,validator:r,message:p});return l._params=l._params?.concat(s),l(...t??[])}function P(e,t){let n,r,s=[],p="";typeof e=="function"?(n=InternalRuleType.Inline,r=(u,...a)=>e(u,...a),s=[t]):({_type:n,validator:r,_message:p}=e,s=s=e._params?.concat(t));let l=createRule({type:InternalRuleType.Inline,validator:r,message:p});return l._params=l._params?.concat(s),l(...t)}function S(e,t){let n,r,s=[],p="";typeof t=="function"?(n=InternalRuleType.Inline,r=t,s=[e]):({_type:n,validator:r,_message:p}=t,s=t._params?.concat([e]));function l(o,...y){let[x]=unwrapRuleParameters([e]);return x?r(o,...y):true}function u(o){let[y]=unwrapRuleParameters([e]);return y}let a=createRule({type:n,validator:l,active:u,message:p}),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 b(e){if(f(e))return false;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 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 g(e){return e==null||typeof e!="number"?false:!isNaN(e)}function R(e,...t){if(f(e))return true;let n=typeof e=="number"?e.toString():e;return t.every(r=>(r.lastIndex=0,r.test(n)))}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 c(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),n=e.map(a=>{if(typeof a=="function")return null;{let m=a._params;return m?.length?m:[]}}).flat().filter(a=>!!a);function r(a,m,...o){let y=[],x=0;for(let d of a)if(typeof d=="function")y.push(d(m)),x++;else {let M=d._params?.length??0;y.push(d.validator(m,...o.slice(x,M))),M&&(x+=M);}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:x,...d}=y;return {...o,...d}},{})}:a.every(o=>!!o)}let p;e.length?p=t?async(a,...m)=>{let o=await Promise.all(r(e,a,...m));return s(o)}:(a,...m)=>{let o=r(e,a,...m);return s(o)}:p=a=>false;let l=createRule({type:"and",validator:p,message:"The value does not match all of the provided validators"}),u=[...n??[]];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),n=e.map(a=>typeof a=="function"?null:a._params).flat().filter(a=>!!a);function r(a,m,...o){let y=[],x=0;for(let d of a)if(typeof d=="function")y.push(d(m)),x++;else {let M=d._params?.length??0;y.push(d.validator(m,...o.slice(x,M))),M&&(x+=M);}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:x,...d}=y;return {...o,...d}},{})}:a.some(o=>!!o)}let l=createRule({type:"or",validator:t?async(a,...m)=>{let o=await Promise.all(r(e,a,...m));return s(o)}:(a,...m)=>{let o=r(e,a,...m);return s(o)},message:"The value does not match any of the provided validators"}),u=[...n??[]];return l._params=u,typeof l=="function"?l(...u):l}function B(e,t){let n,r,s,p,l;typeof e=="function"?(r=e,l=e.constructor.name==="AsyncFunction"):({_type:n,validator:r,_params:p}=e,l=e._async),l?s=async(m,...o)=>i(m)?!await r(m,...o):true:s=(m,...o)=>i(m)?!r(m,...o):true;let u=createRule({type:"not",validator:s,message:t??"Error"}),a=[...p??[]];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 en=createRule({type:"maxLength",validator:(e,t,n)=>{let{allowEqual:r=true}=n??{};return i(e,false)&&i(t)?g(t)?r?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 an=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.]+$/,un=createRule({type:"alpha",validator(e,t){return f(e)?true:t?.allowSymbols?R(e,Y):R(e,X)},message:"The value is not alphabetical"});var ee=/^[a-zA-Z0-9]*$/,te=/^[a-zA-Z0-9_]*$/,Rn=createRule({type:"alphaNum",validator(e,t){return f(e)?true:t?.allowSymbols?R(e,te):R(e,ee)},message:"The value must be alpha-numeric"});var dn=createRule({type:"between",validator:(e,t,n,r)=>{let{allowEqual:s=true}=r??{};if(i(e)&&i(t)&&i(n)){let p=c(e),l=c(t),u=c(n);return g(p)&&g(l)&&g(u)?s?p>=l&&p<=u:p>l&&p<u:(console.warn(`[between] Value or parameters aren't numbers, got value: ${e}, min: ${t}, max: ${n}`),false)}return true},message:({$params:[e,t]})=>`The value must be between ${e} and ${t}`});var ae=/^[-]?\d*(\.\d+)?$/,hn=createRule({type:"decimal",validator(e){return f(e)?true:R(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,wn=createRule({type:"email",validator(e){return f(e)?true:R(e,oe)},message:"The value must be an valid email address"});var le=/(^[0-9]*$)|(^-[0-9]+$)/,Vn=createRule({type:"integer",validator(e){return f(e)?true:R(e,le)},message:"The value must be an integer"});var Fn=createRule({type:"maxValue",validator:(e,t,n)=>{let{allowEqual:r=true}=n??{};return i(e)&&i(t)?g(t)&&!isNaN(c(e))?r?c(e)<=t:c(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:n=true}=t??{};return n?`The value must be less than or equal to ${e}`:`The value must be less than ${e}`}});var On=createRule({type:"minLength",validator:(e,t,n)=>{let{allowEqual:r=true}=n??{};return i(e,false)&&i(t)?g(t)?r?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 Ln=createRule({type:"minValue",validator:(e,t,n)=>{let{allowEqual:r=true}=n??{};return i(e)&&i(t)?g(t)&&!isNaN(c(e))?r?c(e)>=t:c(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:n=true}=t??{};return n?`The value must be greater than or equal to ${e}`:`The value must be greater than ${e}`}});var Kn=createRule({type:"exactValue",validator:(e,t)=>i(e)&&i(t)?g(t)&&!isNaN(c(e))?c(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 Hn=createRule({type:"exactLength",validator:(e,t)=>i(e,false)&&i(t)?g(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 ge=/^\d*(\.\d+)?$/,jn=createRule({type:"numeric",validator(e){return f(e)?true:R(e,ge)},message:"The value must be numeric"});var rr=createRule({type:"required",validator(e,t){return t?true:i(e)},message:"This field is required",active({$params:[e]}){return !e}});var sr=createRule({type:"sameAs",validator(e,t,n){return f(e)?true:e===t},message({$params:[e,t="other"]}){return `The value must be equal to the ${t} value`}});var 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,fr=createRule({type:"url",validator(e){return f(e)?true:R(e,be)},message:"The value is not a valid URL address"});function xe(){return navigator.languages!=null?navigator.languages[0]:navigator.language}function w(e){return e?new Intl.DateTimeFormat(xe(),{dateStyle:"short"}).format(new Date(e)):"?"}var dr=createRule({type:"dateAfter",validator:(e,t)=>i(e)&&i(t)?b(e)&&b(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 Mr=createRule({type:"dateBefore",validator:(e,t)=>i(e)&&i(t)?b(e)&&b(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 values must be dates":`The date must be before ${w(e)}`});var $r=createRule({type:"dateBetween",validator:(e,t,n)=>b(e)&&b(t)&&b(n)?T(e).getTime()>T(t).getTime()&&T(e).getTime()<T(n).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 Wr=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 Nr=createRule({type:"macAddress",validator(e,t=":"){if(f(e))return true;if(typeof e!="string")return false;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($e)},message:"The value is not a valid MAC Address"}),$e=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/);var Sr=createRule({type:"checked",validator:e=>i(e)?e===true:true,message:"The field must be checked"});var Ur=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 Zr=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 Xr=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 n=Array.isArray(t)?t:[t];return R(e,...n)}return true},message:"The value does not match the required pattern"});function ia(e){let t=computed(()=>toValue(e));return D(P((r,s)=>i(r)&&i(s,false)?s.includes(r):true,[t]),({$params:[r]})=>`The value should be one of those options: ${r.join(", ")}.`)}function Oe(e){let t=Object.keys(e).filter(r=>typeof e[e[r]]!="number"),n={};for(let r of t)n[r]=e[r];return Object.values(n)}function ua(e){let t=computed(()=>toValue(e));return D(P((r,s)=>i(r)&&!f(s)?Oe(s).includes(r):true,[t]),({$params:[r]})=>`The value should be one of those options: ${Object.values(r).join(", ")}.`)}function Ra(e){let t=computed(()=>toValue(e));return D(P((r,s)=>s===r,[t]),({$params:[r]})=>`Value should be ${r}.`)}function ga(){return ()=>true}export{un as alpha,Rn as alphaNum,q as and,S as applyIf,dn as between,Sr as checked,Ur as contains,dr as dateAfter,Mr as dateBefore,$r as dateBetween,hn as decimal,wn as email,Xr as endsWith,Hn as exactLength,Kn as exactValue,h as getSize,Vn as integer,Wr as ipv4Address,b as isDate,f as isEmpty,i as isFilled,g as isNumber,Ra as literal,Nr as macAddress,R as matchRegex,en as maxLength,Fn as maxValue,On as minLength,Ln as minValue,ua as nativeEnum,B as not,jn as numeric,ia as oneOf,G as or,ta as regex,Qt as required,an as requiredIf,rr as requiredUnless,sr as sameAs,Zr as startsWith,T as toDate,c as toNumber,ga as type,fr as url,N as withAsync,D as withMessage,P as withParams,F as withTooltip};
1
+ import {createRule,InternalRuleType,unwrapRuleParameters}from'@regle/core';import {unref,computed,toValue}from'vue';function D(e,t){let a,n,o,f;typeof e=="function"&&!("_validator"in e)?(a=InternalRuleType.Inline,n=e):{_type:a,validator:n,_active:o,_params:f}=e;let l=createRule({type:a,validator:n,active:o,message:t}),u=[...f??[]];if(l._params=u,l._message_patched=true,typeof l=="function"){if(f!=null){let i=l(...u);return i._message_patched=true,i}return l}else return l}function F(e,t){let a,n,o,f,l;typeof e=="function"&&!("_validator"in e)?(a=InternalRuleType.Inline,n=e):{_type:a,validator:n,_active:o,_params:f,_message:l}=e;let u=createRule({type:a,validator:n,active:o,message:l,tooltip:t}),i=[...f??[]];if(u._params=i,u._tooltip_patched=true,typeof u=="function"){let p=u(...i);return u._tooltip_patched=true,p}else return u}function N(e,t){let a,n,o=[],f="";typeof e=="function"?(a=InternalRuleType.Inline,n=async(u,...i)=>e(u,...i),o=[t]):({_type:a,_message:f}=e,o=o=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(o),l(...t??[])}function P(e,t){let a,n,o=[],f="";typeof e=="function"?(a=InternalRuleType.Inline,n=(u,...i)=>e(u,...i),o=[t]):({_type:a,validator:n,_message:f}=e,o=o=e._params?.concat(t));let l=createRule({type:InternalRuleType.Inline,validator:n,message:f});return l._params=l._params?.concat(o),l(...t)}function S(e,t){let a,n,o=[],f="";typeof t=="function"?(a=InternalRuleType.Inline,n=t,o=[e]):({_type:a,validator:n,_message:f}=t,o=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 i=createRule({type:a,validator:l,active:u,message:f}),p=[...o??[]];return i._params=p,typeof i=="function"?i(...p):i}function m(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 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 L(...e){let t=e.some(i=>typeof i=="function"?i.constructor.name==="AsyncFunction":i._async),a=e.map(i=>{if(typeof i=="function")return null;{let p=i._params;return p?.length?p:[]}}).flat().filter(i=>!!i);function n(i,p,...s){let c=[],x=0;for(let T of i)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 o(i){return i?.some(s=>typeof s!="boolean")?{$valid:i.every(s=>typeof s=="boolean"?!!s:s.$valid),...i.reduce((s,c)=>{if(typeof c=="boolean")return s;let{$valid:x,...T}=c;return {...s,...T}},{})}:i.every(s=>!!s)}let f;e.length?f=t?async(i,...p)=>{let s=await Promise.all(n(e,i,...p));return o(s)}:(i,...p)=>{let s=n(e,i,...p);return o(s)}:f=i=>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 U(...e){let t=e.some(i=>typeof i=="function"?i.constructor.name==="AsyncFunction":i._async),a=e.map(i=>typeof i=="function"?null:i._params).flat().filter(i=>!!i);function n(i,p,...s){let c=[],x=0;for(let T of i)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 o(i){return i.some(s=>typeof s!="boolean")?{$valid:i.some(s=>typeof s=="boolean"?!!s:s.$valid),...i.reduce((s,c)=>{if(typeof c=="boolean")return s;let{$valid:x,...T}=c;return {...s,...T}},{})}:i.some(s=>!!s)}let l=createRule({type:"or",validator:t?async(i,...p)=>{let s=await Promise.all(n(e,i,...p));return o(s)}:(i,...p)=>{let s=n(e,i,...p);return o(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,o,f,l;typeof e=="function"?(n=e,l=e.constructor.name==="AsyncFunction"):({_type:a,validator:n,_params:f}=e,l=e._async),l?o=async(p,...s)=>r(p)?!await n(p,...s):true:o=(p,...s)=>r(p)?!n(p,...s):true;let u=createRule({type:"not",validator:o,message:t??"Error"}),i=[...f??[]];return u._params=i,typeof u=="function"?u(...i):u}var J=/^[a-zA-Z]*$/,H=/^[\w.]+$/,nn=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_]*$/,sn=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 fn=createRule({type:"between",validator:(e,t,a,n)=>{let{allowEqual:o=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)?o?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 cn=createRule({type:"boolean",validator:e=>r(e)?typeof e=="boolean":true,message:"The value must be a native boolean"});var xn=createRule({type:"checked",validator:e=>r(e)?e===true:true,message:"The field must be checked"});var Pn=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 Vn=createRule({type:"date",validator:e=>r(e)?e instanceof Date:true,message:"The value must be a native Date constructor"});function ae(){return navigator.languages!=null?navigator.languages[0]:navigator.language}function w(e){return e?new Intl.DateTimeFormat(ae(),{dateStyle:"short"}).format(new Date(e)):"?"}var Nn=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 qn=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 Kn=createRule({type:"dateBetween",validator:(e,t,a,n)=>{let{allowEqual:o=true}=n??{};return b(e)&&b(t)&&b(a)?o?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 ue=/^[-]?\d*(\.\d+)?$/,Hn=createRule({type:"decimal",validator(e){return m(e)?true:R(e,ue)},message:"The value must be decimal"});var fe=/^(?:[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,jn=createRule({type:"email",validator(e){return m(e)?true:R(e,fe)},message:"The value must be an valid email address"});var rr=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 sr=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 fr=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 ce=/^[a-fA-F0-9]*$/,gr=createRule({type:"hexadecimal",validator(e){return m(e)?true:R(e,ce)},message:"The value must be hexadecimal"});var Te=/(^[0-9]*$)|(^-[0-9]+$)/,br=createRule({type:"integer",validator(e){return m(e)?true:R(e,Te)},message:"The value must be an integer"});function xe(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 Dr=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(xe)},message:"The value is not a valid IPv4 address"});function vr(e){let t=computed(()=>toValue(e));return D(P((n,o)=>r(n)&&r(o)?o===n:true,[t]),({$params:[n]})=>`Value should be ${n}.`)}var Wr=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(Pe)},message:"The value is not a valid MAC Address"}),Pe=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/);var Nr=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 Sr=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 Gr=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 Zr=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 We(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 Xr(e){let t=computed(()=>toValue(e));return D(P((n,o)=>r(n)&&!m(o)?We(o).includes(n):true,[t]),({$params:[n]})=>`The value should be one of those options: ${Object.values(n).join(", ")}.`)}var ta=createRule({type:"number",validator:e=>r(e)?g(e):true,message:"The value must be a native number"});var Oe=/^\d*(\.\d+)?$/,ia=createRule({type:"numeric",validator(e){return m(e)?true:R(e,Oe)},message:"The value must be numeric"});function ua(e){let t=computed(()=>toValue(e));return D(P((n,o)=>r(n)&&r(o,false)?o.includes(n):true,[t]),({$params:[n]})=>`The value should be one of those options: ${n.join(", ")}.`)}var Ra=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 da=createRule({type:"required",validator:e=>r(e),message:"This field is required"});var Ma=createRule({type:"required",validator(e,t){return t?r(e):true},message:"This field is required",active({$params:[e]}){return e}});var wa=createRule({type:"required",validator(e,t){return t?true:r(e)},message:"This field is required",active({$params:[e]}){return !e}});var Va=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 Fa=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 Ea=createRule({type:"string",validator:e=>r(e)?typeof e=="string":true,message:"The value must be a string"});function Sa(){return ()=>true}var Ke=/^(?:(?:(?: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,Ga=createRule({type:"url",validator(e){return m(e)?true:R(e,Ke)},message:"The value is not a valid URL address"});export{nn as alpha,sn as alphaNum,L as and,S as applyIf,fn as between,cn as boolean,xn as checked,Pn as contains,Vn as date,Nn as dateAfter,qn as dateBefore,Kn as dateBetween,Hn as decimal,jn as email,rr as endsWith,sr as exactLength,fr as exactValue,M as getSize,gr as hexadecimal,br as integer,Dr as ipv4Address,b as isDate,m as isEmpty,r as isFilled,g as isNumber,vr as literal,Wr as macAddress,R as matchRegex,Nr as maxLength,Sr as maxValue,Gr as minLength,Zr as minValue,Xr as nativeEnum,B as not,ta as number,ia as numeric,ua as oneOf,U as or,Ra as regex,da as required,Ma as requiredIf,wa as requiredUnless,Va as sameAs,Fa as startsWith,Ea as string,y as toDate,d as toNumber,Sa as type,Ga as url,N as withAsync,D as withMessage,P as withParams,F as withTooltip};