cvitool 1.0.763 → 1.0.765
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/build/src/cutil.d.ts +11 -2
- package/build/src/cutil.js +10 -5
- package/package.json +1 -1
- package/src/cutil.ts +13 -8
package/build/src/cutil.d.ts
CHANGED
|
@@ -32,7 +32,10 @@ interface validateParams {
|
|
|
32
32
|
subValidate?: {
|
|
33
33
|
[key: string]: validateParams;
|
|
34
34
|
};
|
|
35
|
-
func?: (value: any) =>
|
|
35
|
+
func?: (value: any) => {
|
|
36
|
+
pass: boolean;
|
|
37
|
+
message?: string;
|
|
38
|
+
};
|
|
36
39
|
}
|
|
37
40
|
declare const RegStr: {
|
|
38
41
|
zzs: string;
|
|
@@ -48,6 +51,9 @@ declare const RegStr: {
|
|
|
48
51
|
idNumber: string;
|
|
49
52
|
mongoId: string;
|
|
50
53
|
ratio: string;
|
|
54
|
+
date: string;
|
|
55
|
+
time: string;
|
|
56
|
+
dateTime: string;
|
|
51
57
|
};
|
|
52
58
|
/**
|
|
53
59
|
* 获取一个随机字符串
|
|
@@ -146,7 +152,10 @@ declare function validate(value: {
|
|
|
146
152
|
[key: string]: any;
|
|
147
153
|
}, rule: {
|
|
148
154
|
[key: string]: validateParams;
|
|
149
|
-
}, finalFunc?: (value: any) =>
|
|
155
|
+
}, finalFunc?: (value: any) => {
|
|
156
|
+
pass: boolean;
|
|
157
|
+
message?: string;
|
|
158
|
+
}): {
|
|
150
159
|
message: string;
|
|
151
160
|
field: string;
|
|
152
161
|
pass: boolean;
|
package/build/src/cutil.js
CHANGED
|
@@ -42,7 +42,10 @@ const RegStr = {
|
|
|
42
42
|
mobilePhoneNumber: '^1[3-9]\\d{9}$',
|
|
43
43
|
idNumber: '^\\d{17}[\\dXx]$',
|
|
44
44
|
mongoId: '^[a-f\\d]{24}$',
|
|
45
|
-
ratio: '^[1-9]\\d?:[1-9]\\d?$'
|
|
45
|
+
ratio: '^[1-9]\\d?:[1-9]\\d?$',
|
|
46
|
+
date: '^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])$',
|
|
47
|
+
time: '^([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d$',
|
|
48
|
+
dateTime: '^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01]) ([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d$'
|
|
46
49
|
};
|
|
47
50
|
exports.RegStr = RegStr;
|
|
48
51
|
/**
|
|
@@ -550,8 +553,9 @@ function validate(value, rule, finalFunc) {
|
|
|
550
553
|
if (funcs.length) {
|
|
551
554
|
for (const funcReg of funcs) {
|
|
552
555
|
const { fieldName, fieldValue, func } = funcReg;
|
|
553
|
-
|
|
554
|
-
|
|
556
|
+
const execFuncRes = func(fieldValue);
|
|
557
|
+
if (!execFuncRes.pass) {
|
|
558
|
+
result.message = execFuncRes.message || 'field value not pass validate';
|
|
555
559
|
result.field = fieldName;
|
|
556
560
|
result.pass = false;
|
|
557
561
|
return result;
|
|
@@ -559,8 +563,9 @@ function validate(value, rule, finalFunc) {
|
|
|
559
563
|
}
|
|
560
564
|
}
|
|
561
565
|
if (finalFunc) {
|
|
562
|
-
|
|
563
|
-
|
|
566
|
+
const execFuncRes = finalFunc(value);
|
|
567
|
+
if (!execFuncRes.pass) {
|
|
568
|
+
result.message = execFuncRes.message || 'params not pass validate';
|
|
564
569
|
result.field = '';
|
|
565
570
|
result.pass = false;
|
|
566
571
|
return result;
|
package/package.json
CHANGED
package/src/cutil.ts
CHANGED
|
@@ -47,7 +47,7 @@ interface validateParams {
|
|
|
47
47
|
subRange?: [number, number],
|
|
48
48
|
subLength?: number,
|
|
49
49
|
subValidate?: { [key: string]: validateParams },
|
|
50
|
-
func?: (value: any) => boolean
|
|
50
|
+
func?: (value: any) => { pass: boolean, message?: string }
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
const RegStr = {
|
|
@@ -63,7 +63,10 @@ const RegStr = {
|
|
|
63
63
|
mobilePhoneNumber: '^1[3-9]\\d{9}$',
|
|
64
64
|
idNumber: '^\\d{17}[\\dXx]$',
|
|
65
65
|
mongoId: '^[a-f\\d]{24}$',
|
|
66
|
-
ratio: '^[1-9]\\d?:[1-9]\\d?$'
|
|
66
|
+
ratio: '^[1-9]\\d?:[1-9]\\d?$',
|
|
67
|
+
date: '^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])$',
|
|
68
|
+
time: '^([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d$',
|
|
69
|
+
dateTime: '^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01]) ([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d$'
|
|
67
70
|
};
|
|
68
71
|
|
|
69
72
|
/**
|
|
@@ -425,13 +428,13 @@ function uuid() {
|
|
|
425
428
|
* @param rule
|
|
426
429
|
* @returns
|
|
427
430
|
*/
|
|
428
|
-
function validate(value: { [key: string]: any }, rule: { [key: string]: validateParams }, finalFunc?: (value: any) => boolean): { message: string, field: string, pass: boolean } {
|
|
431
|
+
function validate(value: { [key: string]: any }, rule: { [key: string]: validateParams }, finalFunc?: (value: any) => { pass: boolean, message?: string }): { message: string, field: string, pass: boolean } {
|
|
429
432
|
const result = {
|
|
430
433
|
message: '',
|
|
431
434
|
field: '',
|
|
432
435
|
pass: true
|
|
433
436
|
};
|
|
434
|
-
const funcs: { fieldName: string, fieldValue: any, func: (value: any) => boolean }[] = [];
|
|
437
|
+
const funcs: { fieldName: string, fieldValue: any, func: (value: any) => { pass: boolean, message?: string } }[] = [];
|
|
435
438
|
for (const fieldName in rule) {
|
|
436
439
|
const fieldValidate = rule[fieldName];
|
|
437
440
|
const fieldValue = value[fieldName];
|
|
@@ -576,8 +579,9 @@ function validate(value: { [key: string]: any }, rule: { [key: string]: validate
|
|
|
576
579
|
if (funcs.length) {
|
|
577
580
|
for (const funcReg of funcs) {
|
|
578
581
|
const { fieldName, fieldValue, func } = funcReg;
|
|
579
|
-
|
|
580
|
-
|
|
582
|
+
const execFuncRes = func(fieldValue);
|
|
583
|
+
if (!execFuncRes.pass) {
|
|
584
|
+
result.message = execFuncRes.message || 'field value not pass validate';
|
|
581
585
|
result.field = fieldName;
|
|
582
586
|
result.pass = false;
|
|
583
587
|
return result;
|
|
@@ -585,8 +589,9 @@ function validate(value: { [key: string]: any }, rule: { [key: string]: validate
|
|
|
585
589
|
}
|
|
586
590
|
}
|
|
587
591
|
if (finalFunc) {
|
|
588
|
-
|
|
589
|
-
|
|
592
|
+
const execFuncRes = finalFunc(value);
|
|
593
|
+
if (!execFuncRes.pass) {
|
|
594
|
+
result.message = execFuncRes.message || 'params not pass validate';
|
|
590
595
|
result.field = '';
|
|
591
596
|
result.pass = false;
|
|
592
597
|
return result;
|