koatty_validation 1.0.10 → 1.2.0

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.
@@ -0,0 +1,81 @@
1
+ {
2
+ "configurations": [
3
+ {
4
+ "name": "Launch Koatty Project",
5
+ "type": "node",
6
+ "request": "launch",
7
+ "args": [
8
+ "${workspaceRoot}/src/App.ts"
9
+ ],
10
+ "runtimeArgs": [
11
+ "--nolazy",
12
+ "-r",
13
+ "ts-node/register"
14
+ ],
15
+ "envFile": "/Users/richen/Workspace/.env",
16
+ "sourceMaps": true,
17
+ "cwd": "${workspaceRoot}",
18
+ "protocol": "inspector",
19
+ "internalConsoleOptions": "neverOpen"
20
+ },
21
+ {
22
+ "name": "Launch GoPackage",
23
+ "type": "go",
24
+ "request": "launch",
25
+ "mode": "auto",
26
+ "program": "${workspaceFolder}/main.go",
27
+ "envFile": "/Users/richen/Workspace/.env",
28
+ "args": []
29
+ },
30
+ {
31
+ "name": "Launch Java Project",
32
+ "type": "java",
33
+ "request": "launch",
34
+ "mainClass": "",
35
+ "envFile": "/Users/richen/Workspace/.env"
36
+ },
37
+ {
38
+ "name": "Launch Node.js Project",
39
+ "type": "node",
40
+ "request": "launch",
41
+ "mode": "auto",
42
+ "program": "${workspaceFolder}/app.js",
43
+ "envFile": "/Users/richen/Workspace/.env",
44
+ "args": []
45
+ },
46
+ {
47
+ "name": "Launch Typescript Project",
48
+ "type": "node",
49
+ "request": "launch",
50
+ "args": [
51
+ "${workspaceRoot}/src/index.ts"
52
+ ],
53
+ "runtimeArgs": [
54
+ "--nolazy",
55
+ "-r",
56
+ "ts-node/register"
57
+ ],
58
+ "envFile": "/Users/richen/Workspace/.env",
59
+ "sourceMaps": true,
60
+ "cwd": "${workspaceRoot}",
61
+ "protocol": "inspector",
62
+ "internalConsoleOptions": "neverOpen"
63
+ },
64
+ {
65
+ "type": "node",
66
+ "name": "vscode-jest-tests",
67
+ "request": "launch",
68
+ "console": "integratedTerminal",
69
+ "internalConsoleOptions": "neverOpen",
70
+ "disableOptimisticBPs": true,
71
+ "program": "${workspaceFolder}/node_modules/.bin/jest",
72
+ "cwd": "${workspaceFolder}",
73
+ "args": [
74
+ "--config",
75
+ "jest.config.js",
76
+ "--runInBand",
77
+ "--watchAll=false"
78
+ ]
79
+ }
80
+ ]
81
+ }
package/CHANGELOG.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
- ### [1.0.10](https://github.com/koatty/koatty_validation/compare/v1.0.8...v1.0.10) (2021-11-25)
5
+ ## [1.2.0](https://github.com/koatty/koatty_validation/compare/v1.1.0...v1.2.0) (2022-02-25)
6
6
 
7
- ### [1.0.8](https://github.com/koatty/koatty_validation/compare/v1.0.6...v1.0.8) (2021-11-23)
7
+ ## [1.1.0](https://github.com/koatty/koatty_validation/compare/v1.0.12...v1.1.0) (2022-02-16)
8
8
 
9
- ### [1.0.6](https://github.com/koatty/koatty_validation/compare/v1.0.4...v1.0.6) (2021-11-20)
9
+ ## [2.0.0](https://github.com/koatty/koatty_validation/compare/v1.0.12...v2.0.0) (2022-02-16)
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # koatty_validation
2
- Validation Util for Koatty and ThinkORM. Based on class-validator, extended parameter type checking and restricted attribute functions.
2
+ Validation Util for Koatty. Based on class-validator, extended parameter type checking and restricted attribute functions.
3
3
 
4
4
 
5
5
  # User Decorators
@@ -22,11 +22,11 @@ Validation Util for Koatty and ThinkORM. Based on class-validator, extended para
22
22
  * @IsIn
23
23
  * @IsNotIn
24
24
  * @IsDate
25
- * @Min
26
- * @Max
27
- * @Length
25
+ * @Gt
26
+ * @Gte
27
+ * @Lt
28
+ * @Lte
28
29
 
29
-
30
30
  * @Valid
31
31
  * @Validated
32
32
 
@@ -60,35 +60,41 @@ export class UserDTO {
60
60
 
61
61
  ## FunctionValidator
62
62
 
63
- * FunctionValidator.IsCnName
64
- * FunctionValidator.IsIdNumber
65
- * FunctionValidator.IsZipCode
66
- * FunctionValidator.IsMobile
67
- * FunctionValidator.IsPlateNumber
68
- * FunctionValidator.IsEmail
69
- * FunctionValidator.IsIP
70
- * FunctionValidator.IsPhoneNumber
71
- * FunctionValidator.IsUrl
72
- * FunctionValidator.IsHash
73
- * FunctionValidator.IsNotEmpty
74
- * FunctionValidator.Equals
75
- * FunctionValidator.NotEquals
76
- * FunctionValidator.Contains
77
- * FunctionValidator.IsIn
78
- * FunctionValidator.IsNotIn
79
- * FunctionValidator.IsDate
80
- * FunctionValidator.Min
81
- * FunctionValidator.Max
82
- * FunctionValidator.Length
63
+ * IsCnName
64
+ * IsIdNumber
65
+ * IsZipCode
66
+ * IsMobile
67
+ * IsPlateNumber
68
+ * IsEmail
69
+ * IsIP
70
+ * IsPhoneNumber
71
+ * IsUrl
72
+ * IsHash
73
+ * IsNotEmpty
74
+ * Equals
75
+ * NotEquals
76
+ * Contains
77
+ * IsIn
78
+ * IsNotIn
79
+ * IsDate
80
+ * Gt
81
+ * Gte
82
+ * Lt
83
+ * Lte
84
+
85
+ exp:
83
86
 
84
87
  ```js
85
- if (!FunctionValidator.IsNotEmpty(data)) {
86
- console.log('error');
87
- }
88
+ const str = "";
89
+ // throw Error
90
+ FunctionValidator.IsNotEmpty(str, "cannot be empty");
91
+ FunctionValidator.Contains(str, {message: "must contain s", value: "s"});
88
92
  ```
89
93
 
90
94
  ## ClassValidator
91
95
 
96
+ exp:
97
+
92
98
  ```js
93
99
  class SchemaClass {
94
100
  @IsDefined
package/dist/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2020, Koatty
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/dist/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # koatty_validation
2
+ Validation Util for Koatty. Based on class-validator, extended parameter type checking and restricted attribute functions.
3
+
4
+
5
+ # User Decorators
6
+
7
+ * @IsDefined
8
+ * @IsCnName
9
+ * @IsIdNumber
10
+ * @IsZipCode
11
+ * @IsMobile
12
+ * @IsPlateNumber
13
+ * @IsEmail
14
+ * @IsIP
15
+ * @IsPhoneNumber
16
+ * @IsUrl
17
+ * @IsHash
18
+ * @IsNotEmpty
19
+ * @Equals
20
+ * @NotEquals
21
+ * @Contains
22
+ * @IsIn
23
+ * @IsNotIn
24
+ * @IsDate
25
+ * @Gt
26
+ * @Gte
27
+ * @Lt
28
+ * @Lte
29
+
30
+ * @Valid
31
+ * @Validated
32
+
33
+
34
+
35
+ ```js
36
+
37
+ export class Controller {
38
+
39
+ Test(@Valid("IsNotEmpty", "can not be empty!!") id: number){
40
+ //todo
41
+ }
42
+
43
+ @Validated() // use dto validation
44
+ TestDto(user: UserDTO) {
45
+
46
+ }
47
+ }
48
+
49
+ export class UserDTO {
50
+ @IsNotEmpty({ message: "can not be empty!!" })
51
+ phoneNum: string;
52
+
53
+ @IsCnName({ message: "must be cn name"})
54
+ userName: string;
55
+ }
56
+
57
+ ```
58
+
59
+ # Validator for manual
60
+
61
+ ## FunctionValidator
62
+
63
+ * IsCnName
64
+ * IsIdNumber
65
+ * IsZipCode
66
+ * IsMobile
67
+ * IsPlateNumber
68
+ * IsEmail
69
+ * IsIP
70
+ * IsPhoneNumber
71
+ * IsUrl
72
+ * IsHash
73
+ * IsNotEmpty
74
+ * Equals
75
+ * NotEquals
76
+ * Contains
77
+ * IsIn
78
+ * IsNotIn
79
+ * IsDate
80
+ * Gt
81
+ * Gte
82
+ * Lt
83
+ * Lte
84
+
85
+ exp:
86
+
87
+ ```js
88
+ const str = "";
89
+ // throw Error
90
+ FunctionValidator.IsNotEmpty(str, "cannot be empty");
91
+ FunctionValidator.Contains(str, {message: "must contain s", value: "s"});
92
+ ```
93
+
94
+ ## ClassValidator
95
+
96
+ exp:
97
+
98
+ ```js
99
+ class SchemaClass {
100
+ @IsDefined
101
+ id: number;
102
+
103
+ @IsNotEmpty
104
+ name: string;
105
+ }
106
+
107
+
108
+ ClassValidator.valid(SchemaClass, {name: ''}).catch(err => {
109
+ console.log(err);
110
+ })
111
+ ```
112
+