Skip to content

Commit f83fa74

Browse files
authored
Merge pull request #52 from sittingbool/sittingbool/adding-typedef
sittingbool/adding typedef
2 parents 05d26e7 + f245336 commit f83fa74

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

index.d.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/** type declaration for fastest-validator */
2+
3+
declare interface ValidationRuleObject {
4+
type: string;
5+
optional?: boolean;
6+
min?: number;
7+
max?: number;
8+
length?: number;
9+
pattern?: RegExp;
10+
contains?: string;
11+
enum?: any;
12+
values?: any[];
13+
alpha?: boolean;
14+
numeric?: boolean;
15+
alphanum?: boolean;
16+
alphadash?: boolean;
17+
equal?: any;
18+
notEqual?: any;
19+
positive?: boolean;
20+
negative?: boolean;
21+
integer?: boolean;
22+
convert?: boolean;
23+
items?: string;
24+
props?: ValidationSchema;
25+
check?: (value: any, ValidationSchema) => boolean | ValidationResult;
26+
}
27+
28+
declare type ValidationRule = ValidationRuleObject | ValidationRuleObject[] | string;
29+
30+
declare interface ValidationSchema {
31+
[key: string]: ValidationRule;
32+
}
33+
34+
35+
declare interface ValidationError {
36+
type: string;
37+
field: string;
38+
message: string;
39+
expected?: any;
40+
actual?: any;
41+
}
42+
43+
declare type ValidationResult = ValidationError[];
44+
declare type ValidationObject = { [key: string]: any };
45+
46+
declare class Validator {
47+
constructor(opts?: any);
48+
49+
add(type: string, fn: any): void;
50+
51+
makeError(type: string, expected: any, actual: any): ValidationResult;
52+
53+
compile(schema: ValidationSchema): (object: ValidationObject) => boolean | ValidationResult;
54+
55+
validate(obj: ValidationObject, schema: ValidationSchema): boolean | ValidationResult;
56+
}
57+
58+
declare module "fastest-validator" {
59+
export = Validator;
60+
}

0 commit comments

Comments
 (0)