rxtutils 1.1.2-beta.22 → 1.1.2-beta.23
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 +2 -2
- package/cjs/validator/decorators.d.ts +11 -22
- package/cjs/validator/validator.cjs +8 -13
- package/cjs/validator/validator.d.ts +3 -3
- package/es/validator/decorators.d.ts +11 -22
- package/es/validator/validator.d.ts +3 -3
- package/es/validator/validator.mjs +8 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -294,10 +294,10 @@ BaseValidator 类提供了两个主要的验证方法:
|
|
|
294
294
|
|
|
295
295
|
```typescript
|
|
296
296
|
// 验证单个字段
|
|
297
|
-
validate(itemKey: string, itemAll: boolean = false):
|
|
297
|
+
validate(itemKey: string, itemAll: boolean = false): string[] | null;
|
|
298
298
|
|
|
299
299
|
// 验证多个或所有字段
|
|
300
|
-
validateAll(itemAll: boolean = false, everyItem: boolean = false, order?: string[]):
|
|
300
|
+
validateAll(itemAll: boolean = false, everyItem: boolean = false, order?: string[]): string[] | null;
|
|
301
301
|
```
|
|
302
302
|
|
|
303
303
|
参数说明:
|
|
@@ -19,8 +19,7 @@ import { BaseValidator } from './validator.js';
|
|
|
19
19
|
* username?: string;
|
|
20
20
|
* }
|
|
21
21
|
*/
|
|
22
|
-
declare function VRequired(noneVals?: any[]): (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined,
|
|
23
|
-
context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
22
|
+
declare function VRequired(noneVals?: any[]): (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
24
23
|
/**
|
|
25
24
|
* 字符串类型验证装饰器
|
|
26
25
|
* 验证值是否为字符串类型
|
|
@@ -33,8 +32,7 @@ context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
|
33
32
|
* username?: string;
|
|
34
33
|
* }
|
|
35
34
|
*/
|
|
36
|
-
declare const VString: (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined,
|
|
37
|
-
context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
35
|
+
declare const VString: (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
38
36
|
/**
|
|
39
37
|
* 数字类型验证装饰器
|
|
40
38
|
* 验证值是否为数字类型
|
|
@@ -47,8 +45,7 @@ context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
|
47
45
|
* age?: number;
|
|
48
46
|
* }
|
|
49
47
|
*/
|
|
50
|
-
declare const VNumber: (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined,
|
|
51
|
-
context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
48
|
+
declare const VNumber: (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
52
49
|
/**
|
|
53
50
|
* 数组类型验证装饰器
|
|
54
51
|
* 验证值是否为数组类型
|
|
@@ -61,8 +58,7 @@ context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
|
61
58
|
* tags?: string[];
|
|
62
59
|
* }
|
|
63
60
|
*/
|
|
64
|
-
declare const VArray: (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined,
|
|
65
|
-
context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
61
|
+
declare const VArray: (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
66
62
|
/**
|
|
67
63
|
* 布尔类型验证装饰器
|
|
68
64
|
* 验证值是否为布尔类型
|
|
@@ -75,8 +71,7 @@ context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
|
75
71
|
* active?: boolean;
|
|
76
72
|
* }
|
|
77
73
|
*/
|
|
78
|
-
declare const VBoolean: (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined,
|
|
79
|
-
context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
74
|
+
declare const VBoolean: (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
80
75
|
/**
|
|
81
76
|
* 最小值验证装饰器
|
|
82
77
|
* 验证数字是否大于或等于指定的最小值
|
|
@@ -90,8 +85,7 @@ context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
|
90
85
|
* age?: number;
|
|
91
86
|
* }
|
|
92
87
|
*/
|
|
93
|
-
declare const VMin: (min: number) => (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined,
|
|
94
|
-
context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
88
|
+
declare const VMin: (min: number) => (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
95
89
|
/**
|
|
96
90
|
* 最大值验证装饰器
|
|
97
91
|
* 验证数字是否小于或等于指定的最大值
|
|
@@ -105,8 +99,7 @@ context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
|
105
99
|
* age?: number;
|
|
106
100
|
* }
|
|
107
101
|
*/
|
|
108
|
-
declare const VMax: (max: number) => (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined,
|
|
109
|
-
context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
102
|
+
declare const VMax: (max: number) => (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
110
103
|
/**
|
|
111
104
|
* 最小长度验证装饰器
|
|
112
105
|
* 验证字符串或数组的长度是否大于或等于指定的最小长度
|
|
@@ -120,8 +113,7 @@ context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
|
120
113
|
* password?: string;
|
|
121
114
|
* }
|
|
122
115
|
*/
|
|
123
|
-
declare const VMinLength: (minLen: number) => (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined,
|
|
124
|
-
context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
116
|
+
declare const VMinLength: (minLen: number) => (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
125
117
|
/**
|
|
126
118
|
* 最大长度验证装饰器
|
|
127
119
|
* 验证字符串或数组的长度是否小于或等于指定的最大长度
|
|
@@ -135,8 +127,7 @@ context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
|
135
127
|
* username?: string;
|
|
136
128
|
* }
|
|
137
129
|
*/
|
|
138
|
-
declare const VMaxLength: (maxLen: number) => (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined,
|
|
139
|
-
context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
130
|
+
declare const VMaxLength: (maxLen: number) => (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
140
131
|
/**
|
|
141
132
|
* 邮箱格式验证装饰器
|
|
142
133
|
* 验证字符串是否符合邮箱格式
|
|
@@ -149,8 +140,7 @@ context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
|
149
140
|
* email?: string;
|
|
150
141
|
* }
|
|
151
142
|
*/
|
|
152
|
-
declare const VEmail: (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined,
|
|
153
|
-
context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
143
|
+
declare const VEmail: (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
154
144
|
/**
|
|
155
145
|
* 正则表达式验证装饰器
|
|
156
146
|
* 验证字符串是否匹配指定的正则表达式模式
|
|
@@ -164,7 +154,6 @@ context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
|
164
154
|
* phone?: string;
|
|
165
155
|
* }
|
|
166
156
|
*/
|
|
167
|
-
declare const VPattern: (pattern: RegExp) => (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined,
|
|
168
|
-
context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
157
|
+
declare const VPattern: (pattern: RegExp) => (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
169
158
|
|
|
170
159
|
export { VArray, VBoolean, VEmail, VMax, VMaxLength, VMin, VMinLength, VNumber, VPattern, VRequired, VString };
|
|
@@ -19,43 +19,38 @@ var BaseValidator = /** @class */ (function () {
|
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* 验证单个字段
|
|
22
|
-
* @param itemKey 要验证的字段名
|
|
23
22
|
* @param itemAll 是否验证所有规则,为true时会验证该字段的所有规则,为false时遇到第一个失败的规则就停止
|
|
23
|
+
* @param itemKey 要验证的字段名
|
|
24
24
|
* @returns 验证错误数组,如果没有错误则返回null
|
|
25
25
|
*/
|
|
26
26
|
BaseValidator.prototype.validate = function (itemKey, itemAll) {
|
|
27
27
|
if (itemAll === void 0) { itemAll = false; }
|
|
28
28
|
var validatorMap = this[this.__keySymbol];
|
|
29
|
-
var errors =
|
|
29
|
+
var errors = [];
|
|
30
30
|
// 校验每个 key
|
|
31
31
|
var validators = validatorMap[itemKey];
|
|
32
32
|
if (!validators) {
|
|
33
|
-
return
|
|
33
|
+
return null;
|
|
34
34
|
}
|
|
35
35
|
for (var _i = 0, validators_1 = validators; _i < validators_1.length; _i++) {
|
|
36
36
|
var validator = validators_1[_i];
|
|
37
37
|
var res = validator(this[itemKey]);
|
|
38
38
|
if (!res.status) {
|
|
39
|
-
|
|
40
|
-
errors[res.name].push(res.message);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
errors[res.name] = [res.message];
|
|
44
|
-
}
|
|
45
|
-
if (!itemAll)
|
|
46
|
-
break;
|
|
39
|
+
errors[res.name].push(res.message);
|
|
47
40
|
}
|
|
41
|
+
if (!itemAll)
|
|
42
|
+
break;
|
|
48
43
|
}
|
|
49
|
-
if (
|
|
44
|
+
if (errors.length) {
|
|
50
45
|
return errors;
|
|
51
46
|
}
|
|
52
47
|
return null;
|
|
53
48
|
};
|
|
54
49
|
/**
|
|
55
50
|
* 验证多个或所有字段
|
|
51
|
+
* @param order 验证字段的顺序,可以指定验证的字段名数组及其顺序
|
|
56
52
|
* @param itemAll 是否验证每个字段的所有规则,为true时会验证字段的所有规则,为false时遇到第一个失败的规则就停止
|
|
57
53
|
* @param everyItem 是否验证所有字段,为true时会验证所有字段,为false时遇到第一个失败的字段就停止
|
|
58
|
-
* @param order 验证字段的顺序,可以指定验证的字段名数组及其顺序
|
|
59
54
|
* @returns 验证错误数组,如果没有错误则返回null
|
|
60
55
|
*/
|
|
61
56
|
BaseValidator.prototype.validateAll = function (order, itemAll, everyItem) {
|
|
@@ -32,16 +32,16 @@ declare class BaseValidator {
|
|
|
32
32
|
constructor();
|
|
33
33
|
/**
|
|
34
34
|
* 验证单个字段
|
|
35
|
-
* @param itemKey 要验证的字段名
|
|
36
35
|
* @param itemAll 是否验证所有规则,为true时会验证该字段的所有规则,为false时遇到第一个失败的规则就停止
|
|
36
|
+
* @param itemKey 要验证的字段名
|
|
37
37
|
* @returns 验证错误数组,如果没有错误则返回null
|
|
38
38
|
*/
|
|
39
|
-
validate(itemKey: string, itemAll?: boolean):
|
|
39
|
+
validate(itemKey: string, itemAll?: boolean): string[] | null;
|
|
40
40
|
/**
|
|
41
41
|
* 验证多个或所有字段
|
|
42
|
+
* @param order 验证字段的顺序,可以指定验证的字段名数组及其顺序
|
|
42
43
|
* @param itemAll 是否验证每个字段的所有规则,为true时会验证字段的所有规则,为false时遇到第一个失败的规则就停止
|
|
43
44
|
* @param everyItem 是否验证所有字段,为true时会验证所有字段,为false时遇到第一个失败的字段就停止
|
|
44
|
-
* @param order 验证字段的顺序,可以指定验证的字段名数组及其顺序
|
|
45
45
|
* @returns 验证错误数组,如果没有错误则返回null
|
|
46
46
|
*/
|
|
47
47
|
validateAll(order?: string[], itemAll?: boolean, everyItem?: boolean): Record<string, string[]> | null;
|
|
@@ -19,8 +19,7 @@ import { BaseValidator } from './validator.js';
|
|
|
19
19
|
* username?: string;
|
|
20
20
|
* }
|
|
21
21
|
*/
|
|
22
|
-
declare function VRequired(noneVals?: any[]): (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined,
|
|
23
|
-
context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
22
|
+
declare function VRequired(noneVals?: any[]): (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
24
23
|
/**
|
|
25
24
|
* 字符串类型验证装饰器
|
|
26
25
|
* 验证值是否为字符串类型
|
|
@@ -33,8 +32,7 @@ context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
|
33
32
|
* username?: string;
|
|
34
33
|
* }
|
|
35
34
|
*/
|
|
36
|
-
declare const VString: (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined,
|
|
37
|
-
context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
35
|
+
declare const VString: (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
38
36
|
/**
|
|
39
37
|
* 数字类型验证装饰器
|
|
40
38
|
* 验证值是否为数字类型
|
|
@@ -47,8 +45,7 @@ context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
|
47
45
|
* age?: number;
|
|
48
46
|
* }
|
|
49
47
|
*/
|
|
50
|
-
declare const VNumber: (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined,
|
|
51
|
-
context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
48
|
+
declare const VNumber: (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
52
49
|
/**
|
|
53
50
|
* 数组类型验证装饰器
|
|
54
51
|
* 验证值是否为数组类型
|
|
@@ -61,8 +58,7 @@ context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
|
61
58
|
* tags?: string[];
|
|
62
59
|
* }
|
|
63
60
|
*/
|
|
64
|
-
declare const VArray: (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined,
|
|
65
|
-
context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
61
|
+
declare const VArray: (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
66
62
|
/**
|
|
67
63
|
* 布尔类型验证装饰器
|
|
68
64
|
* 验证值是否为布尔类型
|
|
@@ -75,8 +71,7 @@ context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
|
75
71
|
* active?: boolean;
|
|
76
72
|
* }
|
|
77
73
|
*/
|
|
78
|
-
declare const VBoolean: (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined,
|
|
79
|
-
context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
74
|
+
declare const VBoolean: (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
80
75
|
/**
|
|
81
76
|
* 最小值验证装饰器
|
|
82
77
|
* 验证数字是否大于或等于指定的最小值
|
|
@@ -90,8 +85,7 @@ context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
|
90
85
|
* age?: number;
|
|
91
86
|
* }
|
|
92
87
|
*/
|
|
93
|
-
declare const VMin: (min: number) => (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined,
|
|
94
|
-
context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
88
|
+
declare const VMin: (min: number) => (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
95
89
|
/**
|
|
96
90
|
* 最大值验证装饰器
|
|
97
91
|
* 验证数字是否小于或等于指定的最大值
|
|
@@ -105,8 +99,7 @@ context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
|
105
99
|
* age?: number;
|
|
106
100
|
* }
|
|
107
101
|
*/
|
|
108
|
-
declare const VMax: (max: number) => (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined,
|
|
109
|
-
context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
102
|
+
declare const VMax: (max: number) => (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
110
103
|
/**
|
|
111
104
|
* 最小长度验证装饰器
|
|
112
105
|
* 验证字符串或数组的长度是否大于或等于指定的最小长度
|
|
@@ -120,8 +113,7 @@ context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
|
120
113
|
* password?: string;
|
|
121
114
|
* }
|
|
122
115
|
*/
|
|
123
|
-
declare const VMinLength: (minLen: number) => (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined,
|
|
124
|
-
context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
116
|
+
declare const VMinLength: (minLen: number) => (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
125
117
|
/**
|
|
126
118
|
* 最大长度验证装饰器
|
|
127
119
|
* 验证字符串或数组的长度是否小于或等于指定的最大长度
|
|
@@ -135,8 +127,7 @@ context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
|
135
127
|
* username?: string;
|
|
136
128
|
* }
|
|
137
129
|
*/
|
|
138
|
-
declare const VMaxLength: (maxLen: number) => (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined,
|
|
139
|
-
context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
130
|
+
declare const VMaxLength: (maxLen: number) => (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
140
131
|
/**
|
|
141
132
|
* 邮箱格式验证装饰器
|
|
142
133
|
* 验证字符串是否符合邮箱格式
|
|
@@ -149,8 +140,7 @@ context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
|
149
140
|
* email?: string;
|
|
150
141
|
* }
|
|
151
142
|
*/
|
|
152
|
-
declare const VEmail: (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined,
|
|
153
|
-
context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
143
|
+
declare const VEmail: (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
154
144
|
/**
|
|
155
145
|
* 正则表达式验证装饰器
|
|
156
146
|
* 验证字符串是否匹配指定的正则表达式模式
|
|
@@ -164,7 +154,6 @@ context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
|
164
154
|
* phone?: string;
|
|
165
155
|
* }
|
|
166
156
|
*/
|
|
167
|
-
declare const VPattern: (pattern: RegExp) => (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined,
|
|
168
|
-
context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
157
|
+
declare const VPattern: (pattern: RegExp) => (message?: ((val: any, value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => string) | string) => (value: undefined, context: ClassFieldDecoratorContext<BaseValidator>) => void;
|
|
169
158
|
|
|
170
159
|
export { VArray, VBoolean, VEmail, VMax, VMaxLength, VMin, VMinLength, VNumber, VPattern, VRequired, VString };
|
|
@@ -32,16 +32,16 @@ declare class BaseValidator {
|
|
|
32
32
|
constructor();
|
|
33
33
|
/**
|
|
34
34
|
* 验证单个字段
|
|
35
|
-
* @param itemKey 要验证的字段名
|
|
36
35
|
* @param itemAll 是否验证所有规则,为true时会验证该字段的所有规则,为false时遇到第一个失败的规则就停止
|
|
36
|
+
* @param itemKey 要验证的字段名
|
|
37
37
|
* @returns 验证错误数组,如果没有错误则返回null
|
|
38
38
|
*/
|
|
39
|
-
validate(itemKey: string, itemAll?: boolean):
|
|
39
|
+
validate(itemKey: string, itemAll?: boolean): string[] | null;
|
|
40
40
|
/**
|
|
41
41
|
* 验证多个或所有字段
|
|
42
|
+
* @param order 验证字段的顺序,可以指定验证的字段名数组及其顺序
|
|
42
43
|
* @param itemAll 是否验证每个字段的所有规则,为true时会验证字段的所有规则,为false时遇到第一个失败的规则就停止
|
|
43
44
|
* @param everyItem 是否验证所有字段,为true时会验证所有字段,为false时遇到第一个失败的字段就停止
|
|
44
|
-
* @param order 验证字段的顺序,可以指定验证的字段名数组及其顺序
|
|
45
45
|
* @returns 验证错误数组,如果没有错误则返回null
|
|
46
46
|
*/
|
|
47
47
|
validateAll(order?: string[], itemAll?: boolean, everyItem?: boolean): Record<string, string[]> | null;
|
|
@@ -17,43 +17,38 @@ var BaseValidator = /** @class */ (function () {
|
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* 验证单个字段
|
|
20
|
-
* @param itemKey 要验证的字段名
|
|
21
20
|
* @param itemAll 是否验证所有规则,为true时会验证该字段的所有规则,为false时遇到第一个失败的规则就停止
|
|
21
|
+
* @param itemKey 要验证的字段名
|
|
22
22
|
* @returns 验证错误数组,如果没有错误则返回null
|
|
23
23
|
*/
|
|
24
24
|
BaseValidator.prototype.validate = function (itemKey, itemAll) {
|
|
25
25
|
if (itemAll === void 0) { itemAll = false; }
|
|
26
26
|
var validatorMap = this[this.__keySymbol];
|
|
27
|
-
var errors =
|
|
27
|
+
var errors = [];
|
|
28
28
|
// 校验每个 key
|
|
29
29
|
var validators = validatorMap[itemKey];
|
|
30
30
|
if (!validators) {
|
|
31
|
-
return
|
|
31
|
+
return null;
|
|
32
32
|
}
|
|
33
33
|
for (var _i = 0, validators_1 = validators; _i < validators_1.length; _i++) {
|
|
34
34
|
var validator = validators_1[_i];
|
|
35
35
|
var res = validator(this[itemKey]);
|
|
36
36
|
if (!res.status) {
|
|
37
|
-
|
|
38
|
-
errors[res.name].push(res.message);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
errors[res.name] = [res.message];
|
|
42
|
-
}
|
|
43
|
-
if (!itemAll)
|
|
44
|
-
break;
|
|
37
|
+
errors[res.name].push(res.message);
|
|
45
38
|
}
|
|
39
|
+
if (!itemAll)
|
|
40
|
+
break;
|
|
46
41
|
}
|
|
47
|
-
if (
|
|
42
|
+
if (errors.length) {
|
|
48
43
|
return errors;
|
|
49
44
|
}
|
|
50
45
|
return null;
|
|
51
46
|
};
|
|
52
47
|
/**
|
|
53
48
|
* 验证多个或所有字段
|
|
49
|
+
* @param order 验证字段的顺序,可以指定验证的字段名数组及其顺序
|
|
54
50
|
* @param itemAll 是否验证每个字段的所有规则,为true时会验证字段的所有规则,为false时遇到第一个失败的规则就停止
|
|
55
51
|
* @param everyItem 是否验证所有字段,为true时会验证所有字段,为false时遇到第一个失败的字段就停止
|
|
56
|
-
* @param order 验证字段的顺序,可以指定验证的字段名数组及其顺序
|
|
57
52
|
* @returns 验证错误数组,如果没有错误则返回null
|
|
58
53
|
*/
|
|
59
54
|
BaseValidator.prototype.validateAll = function (order, itemAll, everyItem) {
|