1 | export declare type RuleType = 'string' | 'number' | 'boolean' | 'method' | 'regexp' | 'integer' | 'float' | 'array' | 'object' | 'enum' | 'date' | 'url' | 'hex' | 'email' | 'pattern' | 'any';
|
2 | export interface ValidateOption {
|
3 | suppressWarning?: boolean;
|
4 | suppressValidatorError?: boolean;
|
5 | first?: boolean;
|
6 | firstFields?: boolean | string[];
|
7 | messages?: Partial<ValidateMessages>;
|
8 |
|
9 | keys?: string[];
|
10 | error?: (rule: InternalRuleItem, message: string) => ValidateError;
|
11 | }
|
12 | export declare type SyncErrorType = Error | string;
|
13 | export declare type SyncValidateResult = boolean | SyncErrorType | SyncErrorType[];
|
14 | export declare type ValidateResult = void | Promise<void> | SyncValidateResult;
|
15 | export interface RuleItem {
|
16 | type?: RuleType;
|
17 | required?: boolean;
|
18 | pattern?: RegExp | string;
|
19 | min?: number;
|
20 | max?: number;
|
21 | len?: number;
|
22 | enum?: Array<string | number | boolean | null | undefined>;
|
23 | whitespace?: boolean;
|
24 | fields?: Record<string, Rule>;
|
25 | options?: ValidateOption;
|
26 | defaultField?: Rule;
|
27 | transform?: (value: Value) => Value;
|
28 | message?: string | ((a?: string) => string);
|
29 | asyncValidator?: (rule: InternalRuleItem, value: Value, callback: (error?: string | Error) => void, source: Values, options: ValidateOption) => void | Promise<void>;
|
30 | validator?: (rule: InternalRuleItem, value: Value, callback: (error?: string | Error) => void, source: Values, options: ValidateOption) => SyncValidateResult | void;
|
31 | }
|
32 | export declare type Rule = RuleItem | RuleItem[];
|
33 | export declare type Rules = Record<string, Rule>;
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | export declare type ExecuteRule = (rule: InternalRuleItem, value: Value, source: Values, errors: string[], options: ValidateOption, type?: string) => void;
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | export declare type ExecuteValidator = (rule: InternalRuleItem, value: Value, callback: (error?: string[]) => void, source: Values, options: ValidateOption) => void;
|
58 | declare type ValidateMessage<T extends any[] = unknown[]> = string | ((...args: T) => string);
|
59 | declare type FullField = string | undefined;
|
60 | declare type EnumString = string | undefined;
|
61 | declare type Pattern = string | RegExp | undefined;
|
62 | declare type Range = number | undefined;
|
63 | declare type Type = string | undefined;
|
64 | export interface ValidateMessages {
|
65 | default?: ValidateMessage;
|
66 | required?: ValidateMessage<[FullField]>;
|
67 | enum?: ValidateMessage<[FullField, EnumString]>;
|
68 | whitespace?: ValidateMessage<[FullField]>;
|
69 | date?: {
|
70 | format?: ValidateMessage;
|
71 | parse?: ValidateMessage;
|
72 | invalid?: ValidateMessage;
|
73 | };
|
74 | types?: {
|
75 | string?: ValidateMessage<[FullField, Type]>;
|
76 | method?: ValidateMessage<[FullField, Type]>;
|
77 | array?: ValidateMessage<[FullField, Type]>;
|
78 | object?: ValidateMessage<[FullField, Type]>;
|
79 | number?: ValidateMessage<[FullField, Type]>;
|
80 | date?: ValidateMessage<[FullField, Type]>;
|
81 | boolean?: ValidateMessage<[FullField, Type]>;
|
82 | integer?: ValidateMessage<[FullField, Type]>;
|
83 | float?: ValidateMessage<[FullField, Type]>;
|
84 | regexp?: ValidateMessage<[FullField, Type]>;
|
85 | email?: ValidateMessage<[FullField, Type]>;
|
86 | url?: ValidateMessage<[FullField, Type]>;
|
87 | hex?: ValidateMessage<[FullField, Type]>;
|
88 | };
|
89 | string?: {
|
90 | len?: ValidateMessage<[FullField, Range]>;
|
91 | min?: ValidateMessage<[FullField, Range]>;
|
92 | max?: ValidateMessage<[FullField, Range]>;
|
93 | range?: ValidateMessage<[FullField, Range, Range]>;
|
94 | };
|
95 | number?: {
|
96 | len?: ValidateMessage<[FullField, Range]>;
|
97 | min?: ValidateMessage<[FullField, Range]>;
|
98 | max?: ValidateMessage<[FullField, Range]>;
|
99 | range?: ValidateMessage<[FullField, Range, Range]>;
|
100 | };
|
101 | array?: {
|
102 | len?: ValidateMessage<[FullField, Range]>;
|
103 | min?: ValidateMessage<[FullField, Range]>;
|
104 | max?: ValidateMessage<[FullField, Range]>;
|
105 | range?: ValidateMessage<[FullField, Range, Range]>;
|
106 | };
|
107 | pattern?: {
|
108 | mismatch?: ValidateMessage<[FullField, Value, Pattern]>;
|
109 | };
|
110 | }
|
111 | export interface InternalValidateMessages extends ValidateMessages {
|
112 | clone: () => InternalValidateMessages;
|
113 | }
|
114 | export declare type Value = any;
|
115 | export declare type Values = Record<string, Value>;
|
116 | export interface ValidateError {
|
117 | message?: string;
|
118 | fieldValue?: Value;
|
119 | field?: string;
|
120 | }
|
121 | export declare type ValidateFieldsError = Record<string, ValidateError[]>;
|
122 | export declare type ValidateCallback = (errors: ValidateError[] | null, fields: ValidateFieldsError | Values) => void;
|
123 | export interface RuleValuePackage {
|
124 | rule: InternalRuleItem;
|
125 | value: Value;
|
126 | source: Values;
|
127 | field: string;
|
128 | }
|
129 | export interface InternalRuleItem extends Omit<RuleItem, 'validator'> {
|
130 | field?: string;
|
131 | fullField?: string;
|
132 | fullFields?: string[];
|
133 | validator?: RuleItem['validator'] | ExecuteValidator;
|
134 | }
|
135 | export {};
|