@@ -17,8 +17,10 @@ export type ValidationRuleName =
17
17
| "multi"
18
18
| "number"
19
19
| "object"
20
+ | "objectID"
20
21
| "record"
21
22
| "string"
23
+ | "tuple"
22
24
| "url"
23
25
| "uuid"
24
26
| string ;
@@ -39,39 +41,47 @@ export interface RuleAny extends RuleCustom {
39
41
* @see https://github.com/icebob/fastest-validator#array
40
42
*/
41
43
export interface RuleArray < T = any > extends RuleCustom {
42
- /**
43
- * Name of built-in validator
44
- */
45
- type : "array" ;
46
- /**
47
- * If true, the validator accepts an empty array [].
48
- * @default true
49
- */
50
- empty ?: boolean ;
51
- /**
52
- * Minimum count of elements
53
- */
54
- min ?: number ;
55
- /**
56
- * Maximum count of elements
57
- */
58
- max ?: number ;
59
- /**
60
- * Fixed count of elements
61
- */
62
- length ?: number ;
63
- /**
64
- * The array must contain this element too
65
- */
66
- contains ?: T | T [ ] ;
67
- /**
68
- * Every element must be an element of the enum array
69
- */
70
- enum ?: T [ ] ;
71
- /**
72
- * Validation rules that should be applied to each element of array
73
- */
74
- items ?: ValidationRule ;
44
+ /**
45
+ * Name of built-in validator
46
+ */
47
+ type : "array" ;
48
+ /**
49
+ * If true, the validator accepts an empty array [].
50
+ * @default true
51
+ */
52
+ empty ?: boolean ;
53
+ /**
54
+ * Minimum count of elements
55
+ */
56
+ min ?: number ;
57
+ /**
58
+ * Maximum count of elements
59
+ */
60
+ max ?: number ;
61
+ /**
62
+ * Fixed count of elements
63
+ */
64
+ length ?: number ;
65
+ /**
66
+ * The array must contain this element too
67
+ */
68
+ contains ?: T | T [ ] ;
69
+ /**
70
+ * The array must be unique (array of objects is always unique).
71
+ */
72
+ unique ?: boolean ;
73
+ /**
74
+ * Every element must be an element of the enum array
75
+ */
76
+ enum ?: T [ ] ;
77
+ /**
78
+ * Validation rules that should be applied to each element of array
79
+ */
80
+ items ?: ValidationRule ;
81
+ /**
82
+ * Wrap value into array if different type provided
83
+ */
84
+ convert ?: boolean
75
85
}
76
86
77
87
/**
@@ -102,7 +112,7 @@ export interface RuleClass<T = any> extends RuleCustom {
102
112
/**
103
113
* Checked Class
104
114
*/
105
- instanceOf ? : T ;
115
+ instanceOf : T ;
106
116
}
107
117
108
118
/**
@@ -116,7 +126,6 @@ export interface RuleCurrency extends RuleCustom {
116
126
type : "currency" ;
117
127
/**
118
128
* The currency symbol expected in string (as prefix)
119
- * @default null
120
129
*/
121
130
currencySymbol ?: string ;
122
131
/**
@@ -167,13 +176,19 @@ export interface RuleEmail extends RuleCustom {
167
176
type : "email" ;
168
177
/**
169
178
* If true, the validator accepts an empty string ""
170
- * @default true
179
+ * @default false
171
180
*/
172
181
empty ?: boolean ;
173
182
/**
174
183
* Checker method. Can be quick or precise
184
+ * @default quick
175
185
*/
176
186
mode ?: "quick" | "precise" ;
187
+ /**
188
+ * Normalize the e-mail address (trim & lower-case). It's a sanitizer, it will change the value in the original object.
189
+ * @default false
190
+ */
191
+ normalize ?: boolean ;
177
192
/**
178
193
* Minimum value length
179
194
*/
@@ -182,8 +197,6 @@ export interface RuleEmail extends RuleCustom {
182
197
* Maximum value length
183
198
*/
184
199
max ?: number ;
185
-
186
- normalize ?: boolean ;
187
200
}
188
201
189
202
/**
@@ -223,8 +236,7 @@ export interface RuleEqual<T = any> extends RuleCustom {
223
236
/**
224
237
* Strict value checking.
225
238
*
226
- * @type {'boolean' }
227
- * @memberof RuleEqual
239
+ * @default false
228
240
*/
229
241
strict ?: boolean ;
230
242
}
@@ -242,8 +254,7 @@ export interface RuleForbidden extends RuleCustom {
242
254
/**
243
255
* Removes the forbidden value.
244
256
*
245
- * @type {'boolean' }
246
- * @memberof RuleForbidden
257
+ * @default false
247
258
*/
248
259
remove ?: boolean ;
249
260
}
@@ -291,7 +302,7 @@ export interface RuleMulti extends RuleCustom {
291
302
*/
292
303
type : "multi" ;
293
304
294
- rules : RuleCustom [ ] | string [ ] ;
305
+ rules : ( RuleCustom | string ) [ ] ;
295
306
}
296
307
297
308
/**
@@ -371,28 +382,14 @@ export interface RuleObject extends RuleCustom {
371
382
maxProps ?: number ;
372
383
}
373
384
374
- export interface RuleObjectID extends RuleCustom {
375
- /**
376
- * Name of built-in validator
377
- */
378
- type : "objectID" ;
379
- /**
380
- * To inject ObjectID dependency
381
- */
382
- ObjectID ?: any ;
383
- /**
384
- * Convert HexStringObjectID to ObjectID
385
- */
386
- convert ?: boolean | "hexString" ;
387
- }
388
-
389
385
export interface RuleRecord extends RuleCustom {
390
386
/**
391
387
* Name of built-in validator
392
388
*/
393
389
type : "record" ;
394
390
/**
395
391
* Key validation rule
392
+ * @default "string"
396
393
*/
397
394
key ?: RuleString ;
398
395
/**
@@ -439,14 +436,14 @@ export interface RuleString extends RuleCustom {
439
436
* The value must be an element of the enum array
440
437
*/
441
438
enum ?: string [ ] ;
442
- /**
443
- * The value must be a numeric string
444
- */
445
- numeric ?: boolean ;
446
439
/**
447
440
* The value must be an alphabetic string
448
441
*/
449
442
alpha ?: boolean ;
443
+ /**
444
+ * The value must be a numeric string
445
+ */
446
+ numeric ?: boolean ;
450
447
/**
451
448
* The value must be an alphanumeric string
452
449
*/
@@ -457,37 +454,61 @@ export interface RuleString extends RuleCustom {
457
454
alphadash ?: boolean ;
458
455
/**
459
456
* The value must be a hex string
460
- * @default false
461
457
*/
462
458
hex ?: boolean ;
463
459
/**
464
460
* The value must be a singleLine string
465
- * @default false
466
461
*/
467
462
singleLine ?: boolean ;
468
463
/**
469
464
* The value must be a base64 string
470
- * @default false
471
465
*/
472
466
base64 ?: boolean ;
473
467
/**
474
- * if true and the type is not a String, converts with String()
475
- * @default false
468
+ * If true, the value will be trimmed. It's a sanitizer, it will change the value in the original object.
476
469
*/
477
- convert ?: boolean ;
478
-
479
470
trim ?: boolean ;
471
+ /**
472
+ * If true, the value will be left trimmed. It's a sanitizer, it will change the value in the original object.
473
+ */
480
474
trimLeft ?: boolean ;
475
+ /**
476
+ * If true, the value will be right trimmed. It's a sanitizer, it will change the value in the original object.
477
+ */
481
478
trimRight ?: boolean ;
482
-
479
+ /**
480
+ * If it's a number, the value will be left padded. It's a sanitizer, it will change the value in the original object.
481
+ */
483
482
padStart ?: number ;
483
+ /**
484
+ * If it's a number, the value will be right padded. It's a sanitizer, it will change the value in the original object.
485
+ */
484
486
padEnd ?: number ;
487
+ /**
488
+ * The padding character for the padStart and padEnd.
489
+ * @default " "
490
+ */
485
491
padChar ?: string ;
486
-
492
+ /**
493
+ * If true, the value will be lower-cased. It's a sanitizer, it will change the value in the original object.
494
+ */
487
495
lowercase ?: boolean ;
496
+ /**
497
+ * If true, the value will be upper-cased. It's a sanitizer, it will change the value in the original object.
498
+ */
488
499
uppercase ?: boolean ;
500
+ /**
501
+ * If true, the value will be locale lower-cased. It's a sanitizer, it will change the value in the original object.
502
+ */
489
503
localeLowercase ?: boolean ;
504
+ /**
505
+ * If true, the value will be locale upper-cased. It's a sanitizer, it will change the value in the original object.
506
+ */
490
507
localeUppercase ?: boolean ;
508
+ /**
509
+ * if true and the type is not a String, converts with String()
510
+ */
511
+ convert ?: boolean ;
491
512
}
492
513
493
514
/**
@@ -499,6 +520,10 @@ export interface RuleTuple<T = any> extends RuleCustom {
499
520
* Name of built-in validator
500
521
*/
501
522
type : "tuple" ;
523
+ /**
524
+ * If true, the validator accepts an empty array [].
525
+ */
526
+ empty ?: boolean
502
527
/**
503
528
* Validation rules that should be applied to the corresponding element of array
504
529
*/
@@ -516,7 +541,7 @@ export interface RuleURL extends RuleCustom {
516
541
type : "url" ;
517
542
/**
518
543
* If true, the validator accepts an empty string ""
519
- * @default true
544
+ * @default false
520
545
*/
521
546
empty ?: boolean ;
522
547
}
@@ -536,6 +561,21 @@ export interface RuleUUID extends RuleCustom {
536
561
version ?: 0 | 1 | 2 | 3 | 4 | 5 | 6 ;
537
562
}
538
563
564
+ export interface RuleObjectID extends RuleCustom {
565
+ /**
566
+ * Name of built-in validator
567
+ */
568
+ type : "objectID" ;
569
+ /**
570
+ * To inject ObjectID dependency
571
+ */
572
+ ObjectID ?: any ;
573
+ /**
574
+ * Convert HexStringObjectID to ObjectID
575
+ */
576
+ convert ?: boolean | "hexString" ;
577
+ }
578
+
539
579
/**
540
580
* Validation schema definition for custom inline validator
541
581
* @see https://github.com/icebob/fastest-validator#custom-validator
@@ -1107,7 +1147,7 @@ export default class Validator {
1107
1147
* @return {ValidationRule }
1108
1148
*/
1109
1149
getRuleFromSchema (
1110
- name : ValidationRuleName | ValidationRuleName [ ] | { [ key : string ] : unknown }
1150
+ name : ValidationRuleName | ValidationRuleName [ ] | ValidationSchema | ValidationSchema [ ] | { [ key : string ] : unknown }
1111
1151
) : {
1112
1152
messages : MessagesType ;
1113
1153
schema : ValidationSchema ;
0 commit comments