Skip to content

Commit 11204af

Browse files
committed
fix(types): add missing types, harmonize defaults, correct some default error, ordonne like the documentation
1 parent 9657fdc commit 11204af

File tree

1 file changed

+74
-40
lines changed

1 file changed

+74
-40
lines changed

index.d.ts

Lines changed: 74 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ export interface RuleArray<T = any> extends RuleCustom {
6666
* The array must contain this element too
6767
*/
6868
contains?: T | T[];
69+
/**
70+
* The array must be unique (array of objects is always unique).
71+
*/
72+
unique?: boolean;
6973
/**
7074
* Every element must be an element of the enum array
7175
*/
@@ -74,10 +78,10 @@ export interface RuleArray<T = any> extends RuleCustom {
7478
* Validation rules that should be applied to each element of array
7579
*/
7680
items?: ValidationRule;
77-
/**
78-
* The array must be unique (array of objects is always unique).
81+
/**
82+
* Wrap value into array if different type provided
7983
*/
80-
unique?: boolean;
84+
convert?: boolean
8185
}
8286

8387
/**
@@ -122,7 +126,6 @@ export interface RuleCurrency extends RuleCustom {
122126
type: "currency";
123127
/**
124128
* The currency symbol expected in string (as prefix)
125-
* @default null
126129
*/
127130
currencySymbol?: string;
128131
/**
@@ -173,13 +176,19 @@ export interface RuleEmail extends RuleCustom {
173176
type: "email";
174177
/**
175178
* If true, the validator accepts an empty string ""
176-
* @default true
179+
* @default false
177180
*/
178181
empty?: boolean;
179182
/**
180183
* Checker method. Can be quick or precise
184+
* @default quick
181185
*/
182186
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;
183192
/**
184193
* Minimum value length
185194
*/
@@ -188,8 +197,6 @@ export interface RuleEmail extends RuleCustom {
188197
* Maximum value length
189198
*/
190199
max?: number;
191-
192-
normalize?: boolean;
193200
}
194201

195202
/**
@@ -229,8 +236,7 @@ export interface RuleEqual<T = any> extends RuleCustom {
229236
/**
230237
* Strict value checking.
231238
*
232-
* @type {'boolean'}
233-
* @memberof RuleEqual
239+
* @default false
234240
*/
235241
strict?: boolean;
236242
}
@@ -248,8 +254,7 @@ export interface RuleForbidden extends RuleCustom {
248254
/**
249255
* Removes the forbidden value.
250256
*
251-
* @type {'boolean'}
252-
* @memberof RuleForbidden
257+
* @default false
253258
*/
254259
remove?: boolean;
255260
}
@@ -377,28 +382,14 @@ export interface RuleObject extends RuleCustom {
377382
maxProps?: number;
378383
}
379384

380-
export interface RuleObjectID extends RuleCustom {
381-
/**
382-
* Name of built-in validator
383-
*/
384-
type: "objectID";
385-
/**
386-
* To inject ObjectID dependency
387-
*/
388-
ObjectID?: any;
389-
/**
390-
* Convert HexStringObjectID to ObjectID
391-
*/
392-
convert?: boolean | "hexString";
393-
}
394-
395385
export interface RuleRecord extends RuleCustom {
396386
/**
397387
* Name of built-in validator
398388
*/
399389
type: "record";
400390
/**
401391
* Key validation rule
392+
* @default "string"
402393
*/
403394
key?: RuleString;
404395
/**
@@ -445,14 +436,14 @@ export interface RuleString extends RuleCustom {
445436
* The value must be an element of the enum array
446437
*/
447438
enum?: string[];
448-
/**
449-
* The value must be a numeric string
450-
*/
451-
numeric?: boolean;
452439
/**
453440
* The value must be an alphabetic string
454441
*/
455442
alpha?: boolean;
443+
/**
444+
* The value must be a numeric string
445+
*/
446+
numeric?: boolean;
456447
/**
457448
* The value must be an alphanumeric string
458449
*/
@@ -463,37 +454,61 @@ export interface RuleString extends RuleCustom {
463454
alphadash?: boolean;
464455
/**
465456
* The value must be a hex string
466-
* @default false
467457
*/
468458
hex?: boolean;
469459
/**
470460
* The value must be a singleLine string
471-
* @default false
472461
*/
473462
singleLine?: boolean;
474463
/**
475464
* The value must be a base64 string
476-
* @default false
477465
*/
478466
base64?: boolean;
479467
/**
480-
* if true and the type is not a String, converts with String()
481-
* @default false
468+
* If true, the value will be trimmed. It's a sanitizer, it will change the value in the original object.
482469
*/
483-
convert?: boolean;
484-
485470
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+
*/
486474
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+
*/
487478
trimRight?: boolean;
488-
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+
*/
489482
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+
*/
490486
padEnd?: number;
487+
/**
488+
* The padding character for the padStart and padEnd.
489+
* @default " "
490+
*/
491491
padChar?: string;
492-
492+
/**
493+
* If true, the value will be lower-cased. It's a sanitizer, it will change the value in the original object.
494+
*/
493495
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+
*/
494499
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+
*/
495503
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+
*/
496507
localeUppercase?: boolean;
508+
/**
509+
* if true and the type is not a String, converts with String()
510+
*/
511+
convert?: boolean;
497512
}
498513

499514
/**
@@ -505,6 +520,10 @@ export interface RuleTuple<T = any> extends RuleCustom {
505520
* Name of built-in validator
506521
*/
507522
type: "tuple";
523+
/**
524+
* If true, the validator accepts an empty array [].
525+
*/
526+
empty?: boolean
508527
/**
509528
* Validation rules that should be applied to the corresponding element of array
510529
*/
@@ -522,7 +541,7 @@ export interface RuleURL extends RuleCustom {
522541
type: "url";
523542
/**
524543
* If true, the validator accepts an empty string ""
525-
* @default true
544+
* @default false
526545
*/
527546
empty?: boolean;
528547
}
@@ -542,6 +561,21 @@ export interface RuleUUID extends RuleCustom {
542561
version?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
543562
}
544563

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+
545579
/**
546580
* Validation schema definition for custom inline validator
547581
* @see https://github.com/icebob/fastest-validator#custom-validator

0 commit comments

Comments
 (0)