koatty_validation 1.0.4 → 1.0.12
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/.eslintrc.js +2 -1
- package/CHANGELOG.md +5 -3
- package/LICENSE +1 -1
- package/babel.config.js +0 -5
- package/dist/decorator.d.ts +237 -0
- package/dist/decorator.js +681 -0
- package/dist/decorator.js.map +1 -0
- package/dist/index.d.ts +7 -17
- package/dist/index.js +11 -88
- package/dist/index.js.map +1 -1
- package/dist/rule.d.ts +83 -0
- package/dist/rule.js +291 -0
- package/dist/rule.js.map +1 -0
- package/dist/util.d.ts +60 -257
- package/dist/util.js +331 -799
- package/dist/util.js.map +1 -1
- package/jest.config.js +9 -2
- package/jest_html_reporters.html +1 -1
- package/package.json +23 -18
- package/tsconfig.json +1 -1
- package/dist/lib.d.ts +0 -131
- package/dist/lib.js +0 -422
- package/dist/lib.js.map +0 -1
package/dist/util.d.ts
CHANGED
|
@@ -1,101 +1,10 @@
|
|
|
1
|
-
import { CountryCode } from 'libphonenumber-js';
|
|
2
|
-
import { ValidationOptions, IsIpVersion } from "class-validator";
|
|
3
|
-
interface IsEmailOptions {
|
|
4
|
-
allow_display_name?: boolean;
|
|
5
|
-
require_display_name?: boolean;
|
|
6
|
-
allow_utf8_local_part?: boolean;
|
|
7
|
-
require_tld?: boolean;
|
|
8
|
-
}
|
|
9
|
-
interface IsURLOptions {
|
|
10
|
-
protocols?: string[];
|
|
11
|
-
require_tld?: boolean;
|
|
12
|
-
require_protocol?: boolean;
|
|
13
|
-
require_host?: boolean;
|
|
14
|
-
require_valid_protocol?: boolean;
|
|
15
|
-
allow_underscores?: boolean;
|
|
16
|
-
host_whitelist?: (string | RegExp)[];
|
|
17
|
-
host_blacklist?: (string | RegExp)[];
|
|
18
|
-
allow_trailing_dot?: boolean;
|
|
19
|
-
allow_protocol_relative_urls?: boolean;
|
|
20
|
-
disallow_auth?: boolean;
|
|
21
|
-
}
|
|
22
|
-
declare class ValidateClass {
|
|
23
|
-
private static instance;
|
|
24
|
-
private constructor();
|
|
25
|
-
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* @static
|
|
29
|
-
* @returns
|
|
30
|
-
* @memberof ValidateUtil
|
|
31
|
-
*/
|
|
32
|
-
static getInstance(): ValidateClass;
|
|
33
|
-
/**
|
|
34
|
-
* validated data vs dto class
|
|
35
|
-
*
|
|
36
|
-
* @param {*} Clazz
|
|
37
|
-
* @param {*} data
|
|
38
|
-
* @param {boolean} [convert=false] auto convert parameters type
|
|
39
|
-
* @returns {Promise<any>}
|
|
40
|
-
* @memberof ValidateClass
|
|
41
|
-
*/
|
|
42
|
-
valid(Clazz: any, data: any, convert?: boolean): Promise<any>;
|
|
43
|
-
}
|
|
44
1
|
/**
|
|
45
|
-
*
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
allow_display_name?: boolean;
|
|
50
|
-
require_display_name?: boolean;
|
|
51
|
-
allow_utf8_local_part?: boolean;
|
|
52
|
-
require_tld?: boolean;
|
|
53
|
-
}
|
|
54
|
-
interface IsURLOptions {
|
|
55
|
-
protocols?: string[];
|
|
56
|
-
require_tld?: boolean;
|
|
57
|
-
require_protocol?: boolean;
|
|
58
|
-
require_host?: boolean;
|
|
59
|
-
require_valid_protocol?: boolean;
|
|
60
|
-
allow_underscores?: boolean;
|
|
61
|
-
host_whitelist?: (string | RegExp)[];
|
|
62
|
-
host_blacklist?: (string | RegExp)[];
|
|
63
|
-
allow_trailing_dot?: boolean;
|
|
64
|
-
allow_protocol_relative_urls?: boolean;
|
|
65
|
-
disallow_auth?: boolean;
|
|
66
|
-
}
|
|
67
|
-
declare type HashAlgorithm = "md4" | "md5" | "sha1" | "sha256" | "sha384" | "sha512" | "ripemd128" | "ripemd160" | "tiger128" | "tiger160" | "tiger192" | "crc32" | "crc32b";
|
|
68
|
-
/**
|
|
69
|
-
* Validator Functions
|
|
70
|
-
*/
|
|
71
|
-
export declare const FunctionValidator: any;
|
|
72
|
-
/**
|
|
73
|
-
* type checked rules
|
|
74
|
-
*
|
|
75
|
-
* @export
|
|
76
|
-
* @type {number}
|
|
77
|
-
*/
|
|
78
|
-
export declare type ValidRules = "IsNotEmpty" | "IsDate" | "IsEmail" | "IsIP" | "IsPhoneNumber" | "IsUrl" | "IsHash" | "IsCnName" | "IsIdNumber" | "IsZipCode" | "IsMobile" | "IsPlateNumber";
|
|
79
|
-
/**
|
|
80
|
-
* Use functions or built-in rules for validation.
|
|
81
|
-
*
|
|
82
|
-
* @export
|
|
83
|
-
* @param {string} name
|
|
84
|
-
* @param {*} value
|
|
85
|
-
* @param {string} type
|
|
86
|
-
* @param {(ValidRules | ValidRules[] | Function)} rule
|
|
87
|
-
* @param {string} [message]
|
|
88
|
-
* @param {boolean} [checkType=true]
|
|
89
|
-
* @returns
|
|
90
|
-
*/
|
|
91
|
-
export declare function ValidatorFuncs(name: string, value: any, type: string, rule: ValidRules | ValidRules[] | Function, message?: string, checkType?: boolean): any;
|
|
92
|
-
/**
|
|
93
|
-
* append to the target class method to validated parameter.
|
|
94
|
-
*
|
|
95
|
-
* @export
|
|
96
|
-
* @param {*} target
|
|
97
|
-
* @param {string} propertyKey
|
|
2
|
+
* @ author: richen
|
|
3
|
+
* @ copyright: Copyright (c) - <richenlin(at)gmail.com>
|
|
4
|
+
* @ license: MIT
|
|
5
|
+
* @ version: 2020-03-20 11:34:38
|
|
98
6
|
*/
|
|
7
|
+
import "reflect-metadata";
|
|
99
8
|
/**
|
|
100
9
|
* Set property as included in the process of transformation.
|
|
101
10
|
*
|
|
@@ -105,201 +14,95 @@ export declare function ValidatorFuncs(name: string, value: any, type: string, r
|
|
|
105
14
|
*/
|
|
106
15
|
export declare function setExpose(object: Object, propertyName: string | symbol): void;
|
|
107
16
|
/**
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
* @
|
|
111
|
-
* @returns {PropertyDecorator}
|
|
17
|
+
* get metadata value of a metadata key on the prototype chain of an object and property
|
|
18
|
+
* @param metadataKey metadata key
|
|
19
|
+
* @param target the target of metadataKey
|
|
112
20
|
*/
|
|
113
|
-
export declare function
|
|
21
|
+
export declare function recursiveGetMetadata(metadataKey: any, target: any, propertyKey?: string | symbol): any[];
|
|
114
22
|
/**
|
|
115
|
-
*
|
|
23
|
+
* Dynamically add methods for target class types
|
|
116
24
|
*
|
|
117
|
-
* @
|
|
118
|
-
* @
|
|
119
|
-
|
|
120
|
-
export declare function IsDefined(): PropertyDecorator;
|
|
121
|
-
/**
|
|
122
|
-
* Checks if value is a chinese name.
|
|
123
|
-
*
|
|
124
|
-
* @export
|
|
125
|
-
* @param {string} property
|
|
126
|
-
* @param {ValidationOptions} [validationOptions]
|
|
127
|
-
* @returns {PropertyDecorator}
|
|
25
|
+
* @param {Function} clazz
|
|
26
|
+
* @param {string} protoName
|
|
27
|
+
* @param {Function} func
|
|
128
28
|
*/
|
|
129
|
-
export declare function
|
|
29
|
+
export declare function defineNewProperty(clazz: Function, protoName: string, func: Function): void;
|
|
130
30
|
/**
|
|
131
|
-
* Checks if value is a idCard number(chinese).
|
|
132
31
|
*
|
|
133
|
-
* @export
|
|
134
|
-
* @param {string} property
|
|
135
|
-
* @param {ValidationOptions} [validationOptions]
|
|
136
|
-
* @returns {PropertyDecorator}
|
|
137
|
-
*/
|
|
138
|
-
export declare function IsIdNumber(validationOptions?: ValidationOptions): PropertyDecorator;
|
|
139
|
-
/**
|
|
140
|
-
* Checks if value is a zipCode(chinese).
|
|
141
32
|
*
|
|
142
|
-
* @
|
|
143
|
-
* @param {
|
|
144
|
-
* @param {
|
|
145
|
-
* @returns
|
|
146
|
-
*/
|
|
147
|
-
export declare function IsZipCode(validationOptions?: ValidationOptions): PropertyDecorator;
|
|
148
|
-
/**
|
|
149
|
-
* Checks if value is a mobile phone number(chinese).
|
|
150
|
-
*
|
|
151
|
-
* @export
|
|
152
|
-
* @param {string} property
|
|
153
|
-
* @param {ValidationOptions} [validationOptions]
|
|
154
|
-
* @returns {PropertyDecorator}
|
|
155
|
-
*/
|
|
156
|
-
export declare function IsMobile(validationOptions?: ValidationOptions): PropertyDecorator;
|
|
157
|
-
/**
|
|
158
|
-
* Checks if value is a plate number(chinese).
|
|
159
|
-
*
|
|
160
|
-
* @export
|
|
161
|
-
* @param {string} property
|
|
162
|
-
* @param {ValidationOptions} [validationOptions]
|
|
163
|
-
* @returns {PropertyDecorator}
|
|
164
|
-
*/
|
|
165
|
-
export declare function IsPlateNumber(validationOptions?: ValidationOptions): PropertyDecorator;
|
|
166
|
-
/**
|
|
167
|
-
* Checks value is not empty, undefined, null, '', NaN, [], {} and any empty string(including spaces, tabs, formfeeds, etc.), returns false.
|
|
168
|
-
*
|
|
169
|
-
* @export
|
|
170
|
-
* @param {ValidationOptions} [validationOptions]
|
|
171
|
-
* @returns {PropertyDecorator}
|
|
172
|
-
*/
|
|
173
|
-
export declare function IsNotEmpty(validationOptions?: ValidationOptions): PropertyDecorator;
|
|
174
|
-
/**
|
|
175
|
-
* Checks if value matches ("===") the comparison.
|
|
176
|
-
*
|
|
177
|
-
* @export
|
|
178
|
-
* @param {*} comparison
|
|
179
|
-
* @param {ValidationOptions} [validationOptions]
|
|
180
|
-
* @returns {PropertyDecorator}
|
|
181
|
-
*/
|
|
182
|
-
export declare function Equals(comparison: any, validationOptions?: ValidationOptions): PropertyDecorator;
|
|
183
|
-
/**
|
|
184
|
-
* Checks if value does not match ("!==") the comparison.
|
|
185
|
-
*
|
|
186
|
-
* @export
|
|
187
|
-
* @param {*} comparison
|
|
188
|
-
* @param {ValidationOptions} [validationOptions]
|
|
189
|
-
* @returns {PropertyDecorator}
|
|
190
|
-
*/
|
|
191
|
-
export declare function NotEquals(comparison: any, validationOptions?: ValidationOptions): PropertyDecorator;
|
|
192
|
-
/**
|
|
193
|
-
* Checks if the string contains the seed.
|
|
194
|
-
*
|
|
195
|
-
* @export
|
|
196
|
-
* @param {string} seed
|
|
197
|
-
* @param {ValidationOptions} [validationOptions]
|
|
198
|
-
* @returns {PropertyDecorator}
|
|
199
|
-
*/
|
|
200
|
-
export declare function Contains(seed: string, validationOptions?: ValidationOptions): PropertyDecorator;
|
|
201
|
-
/**
|
|
202
|
-
* Checks if given value is in a array of allowed values.
|
|
203
|
-
*
|
|
204
|
-
* @export
|
|
205
|
-
* @param {any[]} possibleValues
|
|
206
|
-
* @param {ValidationOptions} [validationOptions]
|
|
207
|
-
* @returns {PropertyDecorator}
|
|
33
|
+
* @param {(string | symbol)} metadataKey
|
|
34
|
+
* @param {*} target
|
|
35
|
+
* @param {(string | symbol)} [propertyKey]
|
|
36
|
+
* @returns
|
|
208
37
|
*/
|
|
209
|
-
export declare function
|
|
38
|
+
export declare function getOriginMetadata(metadataKey: string | symbol, target: any, propertyKey?: string | symbol): any;
|
|
210
39
|
/**
|
|
211
|
-
* Checks if given value not in a array of allowed values.
|
|
212
40
|
*
|
|
213
|
-
* @export
|
|
214
|
-
* @param {any[]} possibleValues
|
|
215
|
-
* @param {ValidationOptions} [validationOptions]
|
|
216
|
-
* @returns {PropertyDecorator}
|
|
217
|
-
*/
|
|
218
|
-
export declare function IsNotIn(possibleValues: any[], validationOptions?: ValidationOptions): PropertyDecorator;
|
|
219
|
-
/**
|
|
220
|
-
* Checks if a given value is a real date.
|
|
221
41
|
*
|
|
222
42
|
* @export
|
|
223
|
-
* @param {
|
|
224
|
-
* @
|
|
43
|
+
* @param {*} clazz
|
|
44
|
+
* @param {*} data
|
|
45
|
+
* @param {boolean} [convert=false]
|
|
46
|
+
* @returns
|
|
225
47
|
*/
|
|
226
|
-
export declare function
|
|
48
|
+
export declare function plainToClass(clazz: any, data: any, convert?: boolean): any;
|
|
227
49
|
/**
|
|
228
|
-
*
|
|
50
|
+
* convertDtoParamsType
|
|
229
51
|
*
|
|
230
|
-
* @
|
|
231
|
-
* @param {
|
|
232
|
-
* @param {
|
|
233
|
-
* @returns {
|
|
52
|
+
* @param {*} clazz
|
|
53
|
+
* @param {*} cls
|
|
54
|
+
* @param {*} data
|
|
55
|
+
* @returns {*}
|
|
234
56
|
*/
|
|
235
|
-
export declare function
|
|
57
|
+
export declare function convertDtoParamsType(clazz: any, cls: any, data: any): any;
|
|
236
58
|
/**
|
|
237
|
-
*
|
|
59
|
+
* 绑定参数类型转换
|
|
238
60
|
*
|
|
239
|
-
* @
|
|
240
|
-
* @param {
|
|
241
|
-
* @
|
|
242
|
-
* @returns {PropertyDecorator}
|
|
61
|
+
* @param {*} param
|
|
62
|
+
* @param {string} type
|
|
63
|
+
* @returns {*}
|
|
243
64
|
*/
|
|
244
|
-
export declare function
|
|
65
|
+
export declare function convertParamsType(param: any, type: string): any;
|
|
245
66
|
/**
|
|
246
|
-
*
|
|
247
|
-
* If given value is not a string, then it returns false.
|
|
67
|
+
* Check the base types.
|
|
248
68
|
*
|
|
249
|
-
* @
|
|
250
|
-
* @param {
|
|
251
|
-
* @
|
|
252
|
-
* @param {ValidationOptions} [validationOptions]
|
|
253
|
-
* @returns {PropertyDecorator}
|
|
69
|
+
* @param {*} value
|
|
70
|
+
* @param {string} type
|
|
71
|
+
* @returns {*}
|
|
254
72
|
*/
|
|
255
|
-
export declare function
|
|
73
|
+
export declare function checkParamsType(value: any, type: string): any;
|
|
256
74
|
/**
|
|
257
|
-
* Checks if
|
|
75
|
+
* Checks if value is a chinese name.
|
|
258
76
|
*
|
|
259
|
-
* @
|
|
260
|
-
* @
|
|
261
|
-
* @param {ValidationOptions} [validationOptions]
|
|
262
|
-
* @returns {PropertyDecorator}
|
|
77
|
+
* @param {string} value
|
|
78
|
+
* @returns {boolean}
|
|
263
79
|
*/
|
|
264
|
-
export declare function
|
|
80
|
+
export declare function cnName(value: string): boolean;
|
|
265
81
|
/**
|
|
266
|
-
* Checks if
|
|
82
|
+
* Checks if value is a idCard number.
|
|
267
83
|
*
|
|
268
|
-
* @
|
|
269
|
-
* @
|
|
270
|
-
* @param {ValidationOptions} [validationOptions]
|
|
271
|
-
* @returns {PropertyDecorator}
|
|
84
|
+
* @param {string} value
|
|
85
|
+
* @returns
|
|
272
86
|
*/
|
|
273
|
-
export declare function
|
|
87
|
+
export declare function idNumber(value: string): boolean;
|
|
274
88
|
/**
|
|
275
|
-
* Checks if
|
|
89
|
+
* Checks if value is a mobile phone number.
|
|
276
90
|
*
|
|
277
|
-
* @
|
|
278
|
-
* @
|
|
279
|
-
* If users must enter the intl. prefix (e.g. +41), then you may pass "ZZ" or null as region.
|
|
280
|
-
* See [google-libphonenumber, metadata.js:countryCodeToRegionCodeMap on github]
|
|
281
|
-
* {@link https://github.com/ruimarinho/google-libphonenumber/blob/1e46138878cff479aafe2ce62175c6c49cb58720/src/metadata.js#L33}
|
|
282
|
-
* @param {ValidationOptions} [validationOptions]
|
|
283
|
-
* @returns {PropertyDecorator}
|
|
91
|
+
* @param {string} value
|
|
92
|
+
* @returns {boolean}
|
|
284
93
|
*/
|
|
285
|
-
export declare function
|
|
94
|
+
export declare function mobile(value: string): boolean;
|
|
286
95
|
/**
|
|
287
|
-
* Checks if
|
|
96
|
+
* Checks if value is a zipCode.
|
|
288
97
|
*
|
|
289
|
-
* @
|
|
290
|
-
* @
|
|
291
|
-
* @param {ValidationOptions} [validationOptions]
|
|
292
|
-
* @returns {PropertyDecorator}
|
|
98
|
+
* @param {string} value
|
|
99
|
+
* @returns {boolean}
|
|
293
100
|
*/
|
|
294
|
-
export declare function
|
|
101
|
+
export declare function zipCode(value: string): boolean;
|
|
295
102
|
/**
|
|
296
|
-
*
|
|
297
|
-
* 'sha384', 'sha512', 'ripemd128', 'ripemd160', 'tiger128', 'tiger160', 'tiger192', 'crc32', 'crc32b']
|
|
103
|
+
* Checks if value is a plateNumber.
|
|
298
104
|
*
|
|
299
|
-
* @
|
|
300
|
-
* @
|
|
301
|
-
* @param {ValidationOptions} [validationOptions]
|
|
302
|
-
* @returns {PropertyDecorator}
|
|
105
|
+
* @param {string} value
|
|
106
|
+
* @returns {boolean}
|
|
303
107
|
*/
|
|
304
|
-
export declare function
|
|
305
|
-
export {};
|
|
108
|
+
export declare function plateNumber(value: string): boolean;
|