@regle/rules 1.1.2 → 1.2.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -11
- package/dist/regle-rules.d.ts +186 -121
- package/dist/regle-rules.min.mjs +1 -1
- package/dist/regle-rules.mjs +374 -308
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# Regle
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
Regle \ʁɛɡl\ (French word for 'rule'
|
|
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
|
-
| [](https://stackblitz.com/~/github.com/victorgarciaesgi/regle-examples/tree/main/examples/simple-example?file=examples/simple-example/src/App.vue&configPath=examples/simple-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> | [](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) |
|
|
21
21
|
|
|
22
22
|
## 🧰 Features
|
|
23
|
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
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) 🚧
|
package/dist/regle-rules.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RegleRuleMetadataDefinition, RegleRuleWithParamsDefinition, RegleRuleDefinitionWithMetadataProcessor, RegleRuleMetadataConsumer, RegleRuleDefinition, InlineRuleDeclaration, UnwrapRegleUniversalParams, Maybe, FormRuleDeclaration,
|
|
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
|
*
|
|
@@ -227,7 +204,7 @@ declare const requiredIf: RegleRuleWithParamsDefinition<unknown, [condition: boo
|
|
|
227
204
|
* */
|
|
228
205
|
declare const alpha: RegleRuleWithParamsDefinition<string, [
|
|
229
206
|
options?: CommonAlphaOptions | undefined
|
|
230
|
-
], false, boolean, string>;
|
|
207
|
+
], false, boolean, MaybeInput<string>, string>;
|
|
231
208
|
|
|
232
209
|
/**
|
|
233
210
|
* Allows only alphanumeric characters.
|
|
@@ -236,7 +213,7 @@ declare const alpha: RegleRuleWithParamsDefinition<string, [
|
|
|
236
213
|
*/
|
|
237
214
|
declare const alphaNum: RegleRuleWithParamsDefinition<string | number, [
|
|
238
215
|
options?: CommonAlphaOptions | undefined
|
|
239
|
-
], false, boolean, string
|
|
216
|
+
], false, boolean, MaybeInput<string>>;
|
|
240
217
|
|
|
241
218
|
/**
|
|
242
219
|
* Checks if a number is in specified bounds. min and max are both inclusive.
|
|
@@ -248,60 +225,102 @@ declare const between: RegleRuleWithParamsDefinition<number, [
|
|
|
248
225
|
min: number,
|
|
249
226
|
max: number,
|
|
250
227
|
options?: CommonComparisonOptions
|
|
251
|
-
], false, boolean
|
|
228
|
+
], false, boolean, MaybeInput<number>>;
|
|
252
229
|
|
|
253
230
|
/**
|
|
254
|
-
*
|
|
231
|
+
* Requires a value to be a native boolean type
|
|
232
|
+
*
|
|
233
|
+
* Mainly used for typing
|
|
255
234
|
*/
|
|
256
|
-
declare const
|
|
235
|
+
declare const boolean: RegleRuleDefinition<unknown, [], false, boolean, MaybeInput<boolean>, unknown>;
|
|
257
236
|
|
|
258
237
|
/**
|
|
259
|
-
*
|
|
238
|
+
* Requires a boolean value to be true. This is useful for checkbox inputs.
|
|
260
239
|
*/
|
|
261
|
-
declare const
|
|
240
|
+
declare const checked: RegleRuleDefinition<boolean, [], false, boolean, MaybeInput<boolean>>;
|
|
262
241
|
|
|
263
242
|
/**
|
|
264
|
-
*
|
|
243
|
+
* Checks if the string contains the specified substring.
|
|
244
|
+
*
|
|
245
|
+
* @param part - the part the value needs to contain
|
|
265
246
|
*/
|
|
266
|
-
declare const
|
|
247
|
+
declare const contains: RegleRuleWithParamsDefinition<string, [
|
|
248
|
+
part: MaybeInput<string>
|
|
249
|
+
], false, boolean, MaybeInput<string>>;
|
|
267
250
|
|
|
268
251
|
/**
|
|
269
|
-
* Requires a
|
|
252
|
+
* Requires a value to be a native Date constructor
|
|
270
253
|
*
|
|
271
|
-
*
|
|
272
|
-
* @param options - comparision options
|
|
254
|
+
* Mainly used for typing
|
|
273
255
|
*/
|
|
274
|
-
declare const
|
|
275
|
-
|
|
256
|
+
declare const date: RegleRuleDefinition<unknown, [], false, boolean, MaybeInput<Date>, unknown>;
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Checks if the date is after the given parameter.
|
|
260
|
+
*
|
|
261
|
+
* @param after - the date to compare to
|
|
262
|
+
* @param options - comparison options
|
|
263
|
+
*/
|
|
264
|
+
declare const dateAfter: RegleRuleWithParamsDefinition<string | Date, [
|
|
265
|
+
after: MaybeInput<string | Date>,
|
|
276
266
|
options?: CommonComparisonOptions
|
|
277
|
-
], false,
|
|
267
|
+
], false, true | {
|
|
268
|
+
$valid: false;
|
|
269
|
+
error: 'date-not-after';
|
|
270
|
+
} | {
|
|
271
|
+
$valid: false;
|
|
272
|
+
error: 'value-or-parameter-not-a-date';
|
|
273
|
+
}, MaybeInput<string | Date>>;
|
|
278
274
|
|
|
279
275
|
/**
|
|
280
|
-
*
|
|
276
|
+
* Checks if the date is before the given parameter.
|
|
281
277
|
*
|
|
282
|
-
* @param
|
|
283
|
-
* @param options -
|
|
278
|
+
* @param before - the date to compare to
|
|
279
|
+
* @param options - comparison options
|
|
284
280
|
*/
|
|
285
|
-
declare const
|
|
286
|
-
|
|
281
|
+
declare const dateBefore: RegleRuleWithParamsDefinition<string | Date, [
|
|
282
|
+
before: MaybeInput<string | Date>,
|
|
287
283
|
options?: CommonComparisonOptions
|
|
288
|
-
], false,
|
|
284
|
+
], false, true | {
|
|
285
|
+
$valid: false;
|
|
286
|
+
error: 'date-not-before';
|
|
287
|
+
} | {
|
|
288
|
+
$valid: false;
|
|
289
|
+
error: 'value-or-parameter-not-a-date';
|
|
290
|
+
}, MaybeInput<string | Date>>;
|
|
289
291
|
|
|
290
292
|
/**
|
|
291
|
-
*
|
|
293
|
+
* Checks if the date falls between the specified bounds.
|
|
292
294
|
*
|
|
293
|
-
* @param
|
|
294
|
-
* @param
|
|
295
|
+
* @param before - the minimum limit
|
|
296
|
+
* @param after - the maximum limit
|
|
297
|
+
* @param options - comparison options
|
|
295
298
|
*/
|
|
296
|
-
declare const
|
|
297
|
-
|
|
299
|
+
declare const dateBetween: RegleRuleWithParamsDefinition<string | Date, [
|
|
300
|
+
before: MaybeInput<string | Date>,
|
|
301
|
+
after: MaybeInput<string | Date>,
|
|
298
302
|
options?: CommonComparisonOptions
|
|
299
|
-
], false, boolean
|
|
303
|
+
], false, boolean, MaybeInput<string | Date>>;
|
|
300
304
|
|
|
301
305
|
/**
|
|
302
|
-
*
|
|
306
|
+
* Allows positive and negative decimal numbers.
|
|
303
307
|
*/
|
|
304
|
-
declare const
|
|
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>>;
|
|
305
324
|
|
|
306
325
|
/**
|
|
307
326
|
* Requires the input value to have a strict specified length, inclusive. Works with arrays, objects and strings.
|
|
@@ -313,128 +332,174 @@ declare const exactLength: RegleRuleWithParamsDefinition<string | any[] | Record
|
|
|
313
332
|
], false, boolean>;
|
|
314
333
|
|
|
315
334
|
/**
|
|
316
|
-
*
|
|
335
|
+
* Requires a field to have a strict numeric value.
|
|
317
336
|
*/
|
|
318
|
-
declare const
|
|
337
|
+
declare const exactValue: RegleRuleWithParamsDefinition<number, [
|
|
338
|
+
count: number
|
|
339
|
+
], false, boolean, MaybeInput<number>>;
|
|
319
340
|
|
|
320
341
|
/**
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
* @param condition - the condition to disable the required rule
|
|
342
|
+
* Allows only hexadecimal values.
|
|
324
343
|
*/
|
|
325
|
-
declare const
|
|
344
|
+
declare const hexadecimal: RegleRuleDefinition<string, [], false, boolean, MaybeInput<string>>;
|
|
326
345
|
|
|
327
346
|
/**
|
|
328
|
-
*
|
|
347
|
+
* Allows only integers (positive and negative).
|
|
329
348
|
*/
|
|
330
|
-
declare const
|
|
349
|
+
declare const integer: RegleRuleDefinition<string | number, [], false, boolean, MaybeInput<number>>;
|
|
331
350
|
|
|
332
351
|
/**
|
|
333
|
-
* Validates
|
|
352
|
+
* Validates IPv4 addresses in dotted decimal notation 127.0.0.1.
|
|
334
353
|
*/
|
|
335
|
-
declare const
|
|
354
|
+
declare const ipv4Address: RegleRuleDefinition<string, [], false, boolean, MaybeInput<string>>;
|
|
336
355
|
|
|
337
356
|
/**
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
* @param after - the date to compare to
|
|
357
|
+
* Allow only one possible literal value
|
|
341
358
|
*/
|
|
342
|
-
declare const
|
|
343
|
-
after: Maybe<string | Date>
|
|
344
|
-
], false, true | {
|
|
345
|
-
$valid: false;
|
|
346
|
-
error: 'date-not-after';
|
|
347
|
-
} | {
|
|
348
|
-
$valid: false;
|
|
349
|
-
error: 'value-or-paramater-not-a-date';
|
|
350
|
-
}>;
|
|
359
|
+
declare function literal<const TValue extends string | number>(literal: MaybeRefOrGetter<TValue>): RegleRuleDefinition<TValue, [literal: TValue], false, boolean, MaybeInput<TValue>, string | number>;
|
|
351
360
|
|
|
352
361
|
/**
|
|
353
|
-
*
|
|
362
|
+
* Validates MAC addresses. Call as a function to specify a custom separator (e.g., ':' or an empty string for 00ff1122334455).
|
|
354
363
|
*
|
|
355
|
-
* @param
|
|
364
|
+
* @param separator - the custom separator
|
|
356
365
|
*/
|
|
357
|
-
declare const
|
|
358
|
-
|
|
359
|
-
], false,
|
|
360
|
-
$valid: false;
|
|
361
|
-
error: 'date-not-before';
|
|
362
|
-
} | {
|
|
363
|
-
$valid: false;
|
|
364
|
-
error: 'value-or-paramater-not-a-date';
|
|
365
|
-
}>;
|
|
366
|
+
declare const macAddress: RegleRuleWithParamsDefinition<string, [
|
|
367
|
+
separator?: string | undefined
|
|
368
|
+
], false, boolean, MaybeInput<string>>;
|
|
366
369
|
|
|
367
370
|
/**
|
|
368
|
-
*
|
|
371
|
+
* Requires the input value to have a maximum specified length, inclusive. Works with arrays, objects and strings.
|
|
369
372
|
*
|
|
370
|
-
* @param
|
|
371
|
-
* @param
|
|
373
|
+
* @param max - the maximum length
|
|
374
|
+
* @param options - comparison options
|
|
372
375
|
*/
|
|
373
|
-
declare const
|
|
374
|
-
|
|
375
|
-
|
|
376
|
+
declare const maxLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [
|
|
377
|
+
count: number,
|
|
378
|
+
options?: CommonComparisonOptions
|
|
376
379
|
], false, boolean>;
|
|
377
380
|
|
|
378
381
|
/**
|
|
379
|
-
*
|
|
382
|
+
* Requires a field to have a specified maximum numeric value.
|
|
383
|
+
*
|
|
384
|
+
* @param max - the maximum value
|
|
385
|
+
* @param options - comparison options
|
|
380
386
|
*/
|
|
381
|
-
declare const
|
|
387
|
+
declare const maxValue: RegleRuleWithParamsDefinition<number, [
|
|
388
|
+
count: number,
|
|
389
|
+
options?: CommonComparisonOptions
|
|
390
|
+
], false, boolean, MaybeInput<number>>;
|
|
382
391
|
|
|
383
392
|
/**
|
|
384
|
-
*
|
|
393
|
+
* Requires the input value to have a minimum specified length, inclusive. Works with arrays, objects and strings.
|
|
385
394
|
*
|
|
386
|
-
* @param
|
|
395
|
+
* @param min - the minimum value
|
|
396
|
+
* @param options - comparison options
|
|
387
397
|
*/
|
|
388
|
-
declare const
|
|
398
|
+
declare const minLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [
|
|
399
|
+
count: number,
|
|
400
|
+
options?: CommonComparisonOptions
|
|
401
|
+
], false, boolean>;
|
|
389
402
|
|
|
390
403
|
/**
|
|
391
|
-
* Requires a
|
|
404
|
+
* Requires a field to have a specified minimum numeric value.
|
|
405
|
+
*
|
|
406
|
+
* @param count - the minimum count
|
|
407
|
+
* @param options - comparison options
|
|
408
|
+
*/
|
|
409
|
+
declare const minValue: RegleRuleWithParamsDefinition<number, [
|
|
410
|
+
count: number,
|
|
411
|
+
options?: CommonComparisonOptions
|
|
412
|
+
], false, boolean, MaybeInput<number>>;
|
|
413
|
+
|
|
414
|
+
type EnumLike = {
|
|
415
|
+
[k: string]: string | number;
|
|
416
|
+
[nu: number]: string;
|
|
417
|
+
};
|
|
418
|
+
/**
|
|
419
|
+
* Validate against a native Typescript enum value.
|
|
392
420
|
*/
|
|
393
|
-
declare
|
|
421
|
+
declare function nativeEnum<T extends EnumLike>(enumLike: T): RegleRuleDefinition<MaybeInput<T[keyof T]>, [enumLike: T], false, boolean, MaybeInput<T[keyof T]>, string | number>;
|
|
394
422
|
|
|
395
423
|
/**
|
|
396
|
-
*
|
|
424
|
+
* Requires a value to be a native number type
|
|
397
425
|
*
|
|
398
|
-
*
|
|
426
|
+
* Mainly used for typing
|
|
399
427
|
*/
|
|
400
|
-
declare const
|
|
428
|
+
declare const number: RegleRuleDefinition<unknown, [], false, boolean, MaybeInput<number>, unknown>;
|
|
401
429
|
|
|
402
430
|
/**
|
|
403
|
-
*
|
|
431
|
+
* Allows only numeric values (including numeric strings).
|
|
432
|
+
*/
|
|
433
|
+
declare const numeric: RegleRuleDefinition<string | number, [
|
|
434
|
+
], false, boolean, MaybeInput<string | number>>;
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Allow only one of the values from a fixed Array of possible entries.
|
|
438
|
+
*/
|
|
439
|
+
declare function oneOf<const TValues extends [string | number, ...(string | number)[]]>(options: MaybeRefOrGetter<[...TValues]>): RegleRuleDefinition<TValues[number], [
|
|
440
|
+
options: TValues
|
|
441
|
+
], false, boolean, MaybeInput<TValues[number]>, string | number>;
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Checks if the value matches one or more regular expressions.
|
|
445
|
+
*/
|
|
446
|
+
declare const regex: RegleRuleWithParamsDefinition<string | number, [
|
|
447
|
+
regexp: RegExp | RegExp[]
|
|
448
|
+
], false, boolean, MaybeInput<string | number>>;
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Requires non-empty data. Checks for empty arrays and strings containing only whitespaces.
|
|
452
|
+
*/
|
|
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.
|
|
404
457
|
*
|
|
405
|
-
* @
|
|
458
|
+
* @param condition - the condition to enable the required rule
|
|
406
459
|
*/
|
|
407
|
-
declare const
|
|
460
|
+
declare const requiredIf: RegleRuleWithParamsDefinition<unknown, [condition: boolean], false, boolean>;
|
|
408
461
|
|
|
409
462
|
/**
|
|
410
|
-
*
|
|
463
|
+
* Requires non-empty data, only if provided data property, ref, or a function resolves to false.
|
|
411
464
|
*
|
|
412
|
-
* @param
|
|
465
|
+
* @param condition - the condition to disable the required rule
|
|
413
466
|
*/
|
|
414
|
-
declare const
|
|
467
|
+
declare const requiredUnless: RegleRuleWithParamsDefinition<unknown, [condition: boolean], false, boolean>;
|
|
415
468
|
|
|
416
469
|
/**
|
|
417
|
-
* Checks if the value matches
|
|
470
|
+
* Checks if the value matches the specified property or ref.
|
|
418
471
|
*/
|
|
419
|
-
declare const
|
|
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>>;
|
|
420
476
|
|
|
421
477
|
/**
|
|
422
|
-
*
|
|
478
|
+
* Checks if the string starts with the specified substring.
|
|
479
|
+
*
|
|
480
|
+
* @private part - the value the field must start with
|
|
423
481
|
*/
|
|
424
|
-
declare
|
|
482
|
+
declare const startsWith: RegleRuleWithParamsDefinition<string, [
|
|
483
|
+
part: MaybeInput<string>
|
|
484
|
+
], false, boolean, MaybeInput<string>>;
|
|
425
485
|
|
|
426
|
-
type EnumLike = {
|
|
427
|
-
[k: string]: string | number;
|
|
428
|
-
[nu: number]: string;
|
|
429
|
-
};
|
|
430
486
|
/**
|
|
431
|
-
*
|
|
487
|
+
* Requires a value to be a native string type
|
|
488
|
+
*
|
|
489
|
+
* Mainly used for typing
|
|
432
490
|
*/
|
|
433
|
-
declare
|
|
491
|
+
declare const string: RegleRuleDefinition<unknown, [], false, boolean, MaybeInput<string>, unknown>;
|
|
434
492
|
|
|
435
493
|
/**
|
|
436
|
-
*
|
|
494
|
+
* Define the input type of a rule. No runtime validation.
|
|
495
|
+
*
|
|
496
|
+
* Override any input type set by other rules.
|
|
497
|
+
*/
|
|
498
|
+
declare function type<T>(): RegleRuleDefinition<unknown, [], false, boolean, MaybeInput<T>>;
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* Validates URLs.
|
|
437
502
|
*/
|
|
438
|
-
declare
|
|
503
|
+
declare const url: RegleRuleDefinition<string, [], false, boolean, MaybeInput<string>>;
|
|
439
504
|
|
|
440
|
-
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, url, withAsync, withMessage, withParams, withTooltip };
|
|
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 };
|
package/dist/regle-rules.min.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {createRule,InternalRuleType,unwrapRuleParameters}from'@regle/core';import {unref,computed,toValue}from'vue';function M(e,t){let r,n,s,m;typeof e=="function"&&!("_validator"in e)?(r=InternalRuleType.Inline,n=e):{_type:r,validator:n,_active:s,_params:m}=e;let l=createRule({type:r,validator:n,active:s,message:t}),u=[...m??[]];if(l._params=u,l._message_patched=true,typeof l=="function"){if(m!=null){let a=l(...u);return a._message_patched=true,a}return l}else return l}function _(e,t){let r,n,s,m,l;typeof e=="function"&&!("_validator"in e)?(r=InternalRuleType.Inline,n=e):{_type:r,validator:n,_active:s,_params:m,_message:l}=e;let u=createRule({type:r,validator:n,active:s,message:l,tooltip:t}),a=[...m??[]];if(u._params=a,u._tooltip_patched=true,typeof u=="function"){let f=u(...a);return u._tooltip_patched=true,f}else return u}function E(e,t){let r,n,s=[],m="";typeof e=="function"?(r=InternalRuleType.Inline,n=async(u,...a)=>e(u,...a),s=[t]):({_type:r,_message:m}=e,s=s=e._params?.concat(t),n=async(...u)=>e.validator(u));let l=createRule({type:InternalRuleType.Async,validator:n,message:m});return l._params=l._params?.concat(s),l(...t??[])}function P(e,t){let r,n,s=[],m="";typeof e=="function"?(r=InternalRuleType.Inline,n=(u,...a)=>e(u,...a),s=[t]):({_type:r,validator:n,_message:m}=e,s=s=e._params?.concat(t));let l=createRule({type:InternalRuleType.Inline,validator:n,message:m});return l._params=l._params?.concat(s),l(...t)}function S(e,t){let r,n,s=[],m="";typeof t=="function"?(r=InternalRuleType.Inline,n=t,s=[e]):({_type:r,validator:n,_message:m}=t,s=t._params?.concat([e]));function l(o,...y){let[b]=unwrapRuleParameters([e]);return b?n(o,...y):true}function u(o){let[y]=unwrapRuleParameters([e]);return y}let a=createRule({type:r,validator:l,active:u,message:m}),f=[...s??[]];return a._params=f,typeof a=="function"?a(...f):a}function R(e,t=true){return e==null?true:e instanceof Date?isNaN(e.getTime()):e.constructor.name=="File"||e.constructor.name=="FileList"?e.size<=0:Array.isArray(e)?t?e.length===0:false:typeof e=="object"&&e!=null?Object.keys(e).length===0:!String(e).length}function x(e){if(R(e))return false;try{let t=null;if(e instanceof Date)t=e;else if(typeof e=="string"){let r=new Date(e);if(r.toString()==="Invalid Date")return !1;t=r;}return !!t}catch{return false}}function T(e){let t=Object.prototype.toString.call(e);return e==null?new Date(NaN):e instanceof Date||typeof e=="object"&&t==="[object Date]"?new Date(e.getTime()):typeof e=="number"||t==="[object Number]"?new Date(e):typeof e=="string"||t==="[object String]"?new Date(e):new Date(NaN)}function i(e,t=true){return !R(typeof e=="string"?e.trim():e,t)}function g(e){return e==null||typeof e!="number"?false:!isNaN(e)}function p(e,...t){if(R(e))return true;let r=typeof e=="number"?e.toString():e;return t.every(n=>(n.lastIndex=0,n.test(r)))}function h(e){let t=unref(e);return Array.isArray(t)?t.length:typeof t=="object"?Object.keys(t).length:typeof t=="number"?isNaN(t)?0:t:String(t).length}function 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),r=e.map(a=>{if(typeof a=="function")return null;{let f=a._params;return f?.length?f:[]}}).flat().filter(a=>!!a);function n(a,f,...o){let y=[],b=0;for(let d of a)if(typeof d=="function")y.push(d(f)),b++;else {let D=d._params?.length??0;y.push(d.validator(f,...o.slice(b,D))),D&&(b+=D);}return y}function s(a){return a?.some(o=>typeof o!="boolean")?{$valid:a.every(o=>typeof o=="boolean"?!!o:o.$valid),...a.reduce((o,y)=>{if(typeof y=="boolean")return o;let{$valid:b,...d}=y;return {...o,...d}},{})}:a.every(o=>!!o)}let m;e.length?m=t?async(a,...f)=>{let o=await Promise.all(n(e,a,...f));return s(o)}:(a,...f)=>{let o=n(e,a,...f);return s(o)}:m=a=>false;let l=createRule({type:"and",validator:m,message:"The value does not match all of the provided validators"}),u=[...r??[]];return l._params=u,typeof l=="function"?l(...u):l}function G(...e){let t=e.some(a=>typeof a=="function"?a.constructor.name==="AsyncFunction":a._async),r=e.map(a=>typeof a=="function"?null:a._params).flat().filter(a=>!!a);function n(a,f,...o){let y=[],b=0;for(let d of a)if(typeof d=="function")y.push(d(f)),b++;else {let D=d._params?.length??0;y.push(d.validator(f,...o.slice(b,D))),D&&(b+=D);}return y}function s(a){return a.some(o=>typeof o!="boolean")?{$valid:a.some(o=>typeof o=="boolean"?!!o:o.$valid),...a.reduce((o,y)=>{if(typeof y=="boolean")return o;let{$valid:b,...d}=y;return {...o,...d}},{})}:a.some(o=>!!o)}let l=createRule({type:"or",validator:t?async(a,...f)=>{let o=await Promise.all(n(e,a,...f));return s(o)}:(a,...f)=>{let o=n(e,a,...f);return s(o)},message:"The value does not match any of the provided validators"}),u=[...r??[]];return l._params=u,typeof l=="function"?l(...u):l}function B(e,t){let r,n,s,m,l;typeof e=="function"?(n=e,l=e.constructor.name==="AsyncFunction"):({_type:r,validator:n,_params:m}=e,l=e._async),l?s=async(f,...o)=>i(f)?!await n(f,...o):true:s=(f,...o)=>i(f)?!n(f,...o):true;let u=createRule({type:"not",validator:s,message:t??"Error"}),a=[...m??[]];return u._params=a,typeof u=="function"?u(...a):u}var Qt=createRule({type:"required",validator:e=>i(e),message:"This field is required"});var er=createRule({type:"maxLength",validator:(e,t,r)=>{let{allowEqual:n=true}=r??{};return i(e,false)&&i(t)?g(t)?n?h(e)<=t:h(e)<t:(console.warn(`[maxLength] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),false):true},message:({$value:e,$params:[t]})=>Array.isArray(e)?`This list should have maximum ${t} items`:`The value length should not exceed ${t}`});var ar=createRule({type:"required",validator(e,t){return t?i(e):true},message:"This field is required",active({$params:[e]}){return e}});var X=/^[a-zA-Z]*$/,Y=/^[\w.]+$/,lr=createRule({type:"alpha",validator(e,t){return R(e)?true:t?.allowSymbols?p(e,Y):p(e,X)},message:"The value is not alphabetical"});var ee=/^[a-zA-Z0-9]*$/,te=/^[a-zA-Z0-9_]*$/,Rr=createRule({type:"alphaNum",validator(e,t){return R(e)?true:t?.allowSymbols?p(e,te):p(e,ee)},message:"The value must be alpha-numeric"});var cr=createRule({type:"between",validator:(e,t,r,n)=>{let{allowEqual:s=true}=n??{};if(i(e)&&i(t)&&i(r)){let m=c(e),l=c(t),u=c(r);return g(m)&&g(l)&&g(u)?s?m>=l&&m<=u:m>l&&m<u:(console.warn(`[between] Value or parameters aren't numbers, got value: ${e}, min: ${t}, max: ${r}`),false)}return true},message:({$params:[e,t]})=>`The value must be between ${e} and ${t}`});var ae=/^[-]?\d*(\.\d+)?$/,br=createRule({type:"decimal",validator(e){return R(e)?true:p(e,ae)},message:"The value must be decimal"});var oe=/^(?:[A-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]{2,}(?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i,Pr=createRule({type:"email",validator(e){return R(e)?true:p(e,oe)},message:"The value must be an valid email address"});var le=/(^[0-9]*$)|(^-[0-9]+$)/,Vr=createRule({type:"integer",validator(e){return R(e)?true:p(e,le)},message:"The value must be an integer"});var Fr=createRule({type:"maxValue",validator:(e,t,r)=>{let{allowEqual:n=true}=r??{};return i(e)&&i(t)?g(t)&&!isNaN(c(e))?n?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:r=true}=t??{};return r?`The value must be less than or equal to ${e}`:`The value must be less than ${e}`}});var Or=createRule({type:"minLength",validator:(e,t,r)=>{let{allowEqual:n=true}=r??{};return i(e,false)&&i(t)?g(t)?n?h(e)>=t:h(e)>t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),false):true},message:({$value:e,$params:[t]})=>Array.isArray(e)?`The list should have at least ${t} items`:`The value length should be at least ${t}`});var zr=createRule({type:"minValue",validator:(e,t,r)=>{let{allowEqual:n=true}=r??{};return i(e)&&i(t)?g(t)&&!isNaN(c(e))?n?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:r=true}=t??{};return r?`The value must be greater than or equal to ${e}`:`The value must be greater than ${e}`}});var Gr=createRule({type:"exactValue",validator:(e,t)=>i(e)&&i(t)?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 Jr=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+)?$/,Yr=createRule({type:"numeric",validator(e){return R(e)?true:p(e,ge)},message:"The value must be numeric"});var rn=createRule({type:"required",validator(e,t){return t?true:i(e)},message:"This field is required",active({$params:[e]}){return !e}});var sn=createRule({type:"sameAs",validator(e,t,r="other"){return R(e)?true:e===t},message({$params:[e,t]}){return `The value must be equal to the ${t} value`}});var xe=/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?$/i,fn=createRule({type:"url",validator(e){return R(e)?true:p(e,xe)},message:"The value is not a valid URL address"});function be(){return navigator.languages!=null?navigator.languages[0]:navigator.language}function w(e){return e?new Intl.DateTimeFormat(be(),{dateStyle:"short"}).format(new Date(e)):"?"}var dn=createRule({type:"dateAfter",validator:(e,t)=>i(e)&&i(t)?x(e)&&x(t)?T(e).getTime()>T(t).getTime()?true:{$valid:false,error:"date-not-after"}:{$valid:false,error:"value-or-paramater-not-a-date"}:true,message:({$params:[e],error:t})=>t==="value-or-paramater-not-a-date"?"The values must be dates":`The date must be after ${w(e)}`});var Dn=createRule({type:"dateBefore",validator:(e,t)=>i(e)&&i(t)?x(e)&&x(t)?T(e).getTime()<T(t).getTime()?true:{$valid:false,error:"date-not-before"}:{$valid:false,error:"value-or-paramater-not-a-date"}:true,message:({$params:[e],error:t})=>t==="value-or-paramater-not-a-date"?"The values must be dates":`The date must be before ${w(e)}`});var vn=createRule({type:"dateBetween",validator:(e,t,r)=>x(e)&&x(t)&&x(r)?T(e).getTime()>T(t).getTime()&&T(e).getTime()<T(r).getTime():true,message:({$params:[e,t]})=>`The date must be between ${w(e)} and ${w(t)}`});function we(e){if(e.length>3||e.length===0||e[0]==="0"&&e!=="0"||!e.match(/^\d+$/))return false;let t=+e|0;return t>=0&&t<=255}var Cn=createRule({type:"ipv4Address",validator(e){if(R(e))return true;if(typeof e!="string")return false;let t=e.split(".");return t.length===4&&t.every(we)},message:"The value is not a valid IPv4 address"});var En=createRule({type:"macAddress",validator(e,t=":"){if(R(e))return true;if(typeof e!="string")return false;let r=typeof t=="string"&&t!==""?e.split(t):e.length===12||e.length===16?e.match(/.{2}/g):null;return r!==null&&(r.length===6||r.length===8)&&r.every(ve)},message:"The value is not a valid MAC Address"}),ve=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/);var Sn=createRule({type:"checked",validator:e=>i(e)?e===true:true,message:"The field must be checked"});var Un=createRule({type:"contains",validator(e,t){return i(e)&&i(t)?e.includes(t):true},message({$params:[e]}){return `The value must contain ${e}`}});var Zn=createRule({type:"startsWith",validator(e,t){return i(e)&&i(t)?e.startsWith(t):true},message({$params:[e]}){return `The value must end with ${e}`}});var Xn=createRule({type:"endsWith",validator(e,t){return i(e)&&i(t)?e.endsWith(t):true},message({$params:[e]}){return `The value must end with ${e}`}});var ta=createRule({type:"regex",validator(e,t){if(i(e)){let r=Array.isArray(t)?t:[t];return p(e,...r)}return true},message:"The value does not match the required pattern"});function ia(e){let t=computed(()=>toValue(e));return M(P((n,s)=>i(n)&&i(s,false)?s.includes(n):true,[t]),({$params:[n]})=>`The value should be one of those options: ${n.join(", ")}.`)}function Ie(e){let t=Object.keys(e).filter(n=>typeof e[e[n]]!="number"),r={};for(let n of t)r[n]=e[n];return Object.values(r)}function ua(e){let t=computed(()=>toValue(e));return M(P((n,s)=>i(n)&&!R(s)?Ie(s).includes(n):true,[t]),({$params:[n]})=>`The value should be one of those options: ${Object.values(n).join(", ")}.`)}function ya(e){let t=computed(()=>toValue(e));return M(P((n,s)=>s===n,[t]),({$params:[n]})=>`Value should be ${n}.`)}export{lr as alpha,Rr as alphaNum,q as and,S as applyIf,cr as between,Sn as checked,Un as contains,dn as dateAfter,Dn as dateBefore,vn as dateBetween,br as decimal,Pr as email,Xn as endsWith,Jr as exactLength,Gr as exactValue,h as getSize,Vr as integer,Cn as ipv4Address,x as isDate,R as isEmpty,i as isFilled,g as isNumber,ya as literal,En as macAddress,p as matchRegex,er as maxLength,Fr as maxValue,Or as minLength,zr as minValue,ua as nativeEnum,B as not,Yr as numeric,ia as oneOf,G as or,ta as regex,Qt as required,ar as requiredIf,rn as requiredUnless,sn as sameAs,Zn as startsWith,T as toDate,c as toNumber,fn as url,E as withAsync,M as withMessage,P as withParams,_ as withTooltip};
|
|
1
|
+
import {createRule,InternalRuleType,unwrapRuleParameters}from'@regle/core';import {unref,computed,toValue}from'vue';function 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};
|