@fastcar/core 0.2.61 → 0.2.62
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/package.json
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { DataTypes } from "../constant/DataTypes";
|
|
2
2
|
import TypeUtil from "./TypeUtil";
|
|
3
3
|
|
|
4
|
-
const NumberRegex = /^[0-9]+$/;
|
|
5
|
-
|
|
6
4
|
//类型校验器
|
|
7
5
|
export default class ValidationUtil {
|
|
8
6
|
//是否为空
|
|
@@ -32,7 +30,7 @@ export default class ValidationUtil {
|
|
|
32
30
|
|
|
33
31
|
//修改数字的判断方法
|
|
34
32
|
static isNumber(param: any): boolean {
|
|
35
|
-
return
|
|
33
|
+
return !isNaN(param);
|
|
36
34
|
}
|
|
37
35
|
|
|
38
36
|
static isString(param: any): boolean {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const TypeUtil_1 = require("./TypeUtil");
|
|
4
|
-
const NumberRegex = /^[0-9]+$/;
|
|
5
4
|
//类型校验器
|
|
6
5
|
class ValidationUtil {
|
|
7
6
|
//是否为空
|
|
@@ -27,7 +26,7 @@ class ValidationUtil {
|
|
|
27
26
|
}
|
|
28
27
|
//修改数字的判断方法
|
|
29
28
|
static isNumber(param) {
|
|
30
|
-
return
|
|
29
|
+
return !isNaN(param);
|
|
31
30
|
}
|
|
32
31
|
static isString(param) {
|
|
33
32
|
return typeof param === "string";
|
package/test/unit/valid-test.ts
CHANGED
|
@@ -7,66 +7,71 @@ import { ValidationUtil } from "../../src/utils";
|
|
|
7
7
|
|
|
8
8
|
describe("表单校验测试", () => {
|
|
9
9
|
it("表单单个测试", () => {
|
|
10
|
-
class A {
|
|
11
|
-
//简单类型
|
|
12
|
-
@ValidForm
|
|
13
|
-
test(@Rule() @NotNull a?: string) {
|
|
14
|
-
console.log(a);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
let instance = new A();
|
|
18
|
-
instance.test("");
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("表单复合型测试", () => {
|
|
22
|
-
type B = {
|
|
23
|
-
c: string;
|
|
24
|
-
d?: number;
|
|
25
|
-
};
|
|
26
10
|
class A {
|
|
27
11
|
//简单类型
|
|
28
12
|
@ValidForm
|
|
29
13
|
test(
|
|
30
14
|
@Rule({
|
|
31
|
-
a: { required: true },
|
|
32
|
-
})
|
|
33
|
-
a: string,
|
|
34
|
-
@Rule({
|
|
35
|
-
c: { required: true },
|
|
36
|
-
d: { type: "number", minSize: 1, maxSize: 10 },
|
|
15
|
+
a: { required: true, type: "int" },
|
|
37
16
|
})
|
|
38
|
-
|
|
17
|
+
{ a }: { a: any }
|
|
39
18
|
) {
|
|
40
|
-
console.log(a
|
|
19
|
+
console.log(a);
|
|
41
20
|
}
|
|
42
21
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
instance.test("a", { c: "c", d: 13 }); //校验失败
|
|
22
|
+
console.log("");
|
|
23
|
+
new A().test({ a: [] });
|
|
46
24
|
});
|
|
47
25
|
|
|
48
|
-
it("
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
26
|
+
// it("表单复合型测试", () => {
|
|
27
|
+
// type B = {
|
|
28
|
+
// c: string;
|
|
29
|
+
// d?: number;
|
|
30
|
+
// };
|
|
31
|
+
// class A {
|
|
32
|
+
// //简单类型
|
|
33
|
+
// @ValidForm
|
|
34
|
+
// test(
|
|
35
|
+
// @Rule({
|
|
36
|
+
// a: { required: true },
|
|
37
|
+
// })
|
|
38
|
+
// a: string,
|
|
39
|
+
// @Rule({
|
|
40
|
+
// c: { required: true },
|
|
41
|
+
// d: { type: "number", minSize: 1, maxSize: 10 },
|
|
42
|
+
// })
|
|
43
|
+
// b: B
|
|
44
|
+
// ) {
|
|
45
|
+
// console.log(a, b);
|
|
46
|
+
// }
|
|
47
|
+
// }
|
|
48
|
+
// let instance = new A();
|
|
49
|
+
// instance.test("a", { c: "c", d: 6 }); // 校验通过
|
|
50
|
+
// instance.test("a", { c: "c", d: 13 }); //校验失败
|
|
51
|
+
// });
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
//简单类型
|
|
58
|
-
@ValidForm
|
|
59
|
-
test(a: string, @Rule() @NotNull b: B) {
|
|
60
|
-
console.log(a, b);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
let instance = new A();
|
|
64
|
-
instance.test("a", { c: "c", d: 13 }); //校验失败
|
|
65
|
-
});
|
|
53
|
+
// it("表单类测试", () => {
|
|
54
|
+
// class B {
|
|
55
|
+
// @NotNull
|
|
56
|
+
// c!: string;
|
|
66
57
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
58
|
+
// @Size({ minSize: 1, maxSize: 10 })
|
|
59
|
+
// d?: number;
|
|
60
|
+
// }
|
|
61
|
+
// class A {
|
|
62
|
+
// //简单类型
|
|
63
|
+
// @ValidForm
|
|
64
|
+
// test(a: string, @Rule() @NotNull b: B) {
|
|
65
|
+
// console.log(a, b);
|
|
66
|
+
// }
|
|
67
|
+
// }
|
|
68
|
+
// let instance = new A();
|
|
69
|
+
// instance.test("a", { c: "c", d: 13 }); //校验失败
|
|
70
|
+
// });
|
|
71
|
+
|
|
72
|
+
// it("测试map是否为空", () => {
|
|
73
|
+
// let d = new Map();
|
|
74
|
+
// d.set("hello", "world");
|
|
75
|
+
// console.log(ValidationUtil.isNotNull(d) == true);
|
|
76
|
+
// });
|
|
72
77
|
});
|