Skip to content

Commit 8741d26

Browse files
authored
Merge pull request #94 from icebob/next
New rewritten version 1.0.0
2 parents 80cff51 + 47eb1af commit 8741d26

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+8548
-2638
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ cache:
33
directories:
44
- node_modules
55
node_js:
6+
- "13"
7+
- "12"
68
- "10"
79
- "8"
10+
11+
script:
12+
- npm run test:travis
13+
814
after_success:
915
- npm run coverall

.vscode/launch.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"type": "node",
99
"request": "launch",
1010
"name": "Launch dev",
11-
"program": "${workspaceRoot}\\examples\\custom.js"
11+
"program": "${workspaceRoot}\\examples\\next.js"
1212
},
1313
{
1414
"type": "node",
@@ -26,6 +26,18 @@
2626
"cwd": "${workspaceRoot}",
2727
"runtimeArgs": [
2828
"--nolazy"
29+
]
30+
},
31+
{
32+
"type": "node",
33+
"request": "launch",
34+
"name": "Jest single",
35+
"program": "${workspaceRoot}/node_modules/jest-cli/bin/jest.js",
36+
"args": ["--runInBand", "${fileBasenameNoExtension}"],
37+
"console": "internalConsole",
38+
"cwd": "${workspaceRoot}",
39+
"runtimeArgs": [
40+
"--nolazy"
2941
]
3042
},
3143
{
@@ -36,4 +48,4 @@
3648
"port": 5858
3749
}
3850
]
39-
}
51+
}

CHANGELOG.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,100 @@
1+
--------------------------------------------------
2+
<a name="1.0.0"></a>
3+
# 1.0.0 (2019-11-xx)
4+
5+
The full library has been rewritten. It uses code generators in order to be much faster.
6+
7+
## Breaking changes
8+
This new version contains several breaking changes.
9+
10+
### Rule logic changed
11+
The rule codes have been rewritten to code generator functions. Therefore if you use custom validators, you should rewrite them after upgrading.
12+
13+
### Convert values
14+
The `number`, `boolean` and `date` rules have a `convert: true` property. In the previous version it doesn't modify the value in the checked object, just converted the value to the rules. In the version 1.0 this property converts the values in the checked object, as well.
15+
16+
## New
17+
18+
### Sanitizations
19+
The sanitization function is implemented. There are several rules which contains sanitizers. **Please note, the sanitizers change the original checked object values.**
20+
21+
| Rule | Property | Description |
22+
| ---- | -------- | ----------- |
23+
`boolean` | `convert` | Convert the value to a boolean.
24+
`number` | `convert` | Convert the value to a number.
25+
`date` | `convert` | Convert the value to a date.
26+
`string` | `trim` | Trim the value.
27+
`string` | `trimLeft` | Left trim the value.
28+
`string` | `trimRight` | Right trim the value.
29+
`string` | `lowercase` | Lowercase the value.
30+
`string` | `uppercase` | Uppercase the value.
31+
`string` | `localeLowercase` | Lowercase the value with `String.toLocaleLowerCase`.
32+
`string` | `localeUppercase` | Uppercase the value with `String.toLocaleUpperCase`.
33+
`string` | `padStart` | Left padding the value.
34+
`string` | `padEnd` | Right padding the value.
35+
`string` | `convert` | Convert the value to a string.
36+
`email` | `normalize` | Trim & lowercase the value.
37+
`forbidden` | `remove` | Remove the forbidden field.
38+
`object` | `strict: "remove"` | Remove additional properties in the object.
39+
`*` | `default` | Use this default value if the value is `null` or `undefined`.
40+
41+
### Root element validation
42+
Basically the validator expects that you want to validate a Javascript object. If you want others, you can define the root level schema, as well. In this case set the `$$root: true` property.
43+
44+
**Example to validate a `string` variable instead of `object`**
45+
```js
46+
const schema = {
47+
$$root: true,
48+
type: "string",
49+
min: 3,
50+
max: 6
51+
};
52+
53+
v.validate("John", schema); // Valid
54+
v.validate("Al", schema); // Fail, too short.
55+
```
56+
57+
### Enhanced shorthand types
58+
You can use string-based shorthand validation definitions in the schema with properties.
59+
60+
```js
61+
{
62+
password: "string|min:6",
63+
age: "number|optional|integer|positive|min:0|max:99",
64+
65+
retry: ["number|integer|min:0", "boolean"] // multiple types
66+
}
67+
```
68+
69+
## Other changes
70+
71+
### New `equal` rule
72+
It checks the value equal (`==`) to a static value or another property. The `strict` property uses `===` to check values.
73+
74+
**Example with static value**:
75+
```js
76+
const schema = {
77+
agreeTerms: { type: "equal", value: true, strict: true } // strict means `===`
78+
}
79+
80+
v.validate({ agreeTerms: true }, schema); // Valid
81+
v.validate({ agreeTerms: false }, schema); // Fail
82+
```
83+
84+
**Example with other field**:
85+
```js
86+
const schema = {
87+
password: { type: "string", min: 6 },
88+
confirmPassword: { type: "equal", field: "password" }
89+
}
90+
91+
v.validate({ password: "123456", confirmPassword: "123456" }, schema); // Valid
92+
v.validate({ password: "123456", confirmPassword: "pass1234" }, schema); // Fail
93+
```
94+
95+
### `properties` in object rule
96+
You can use the `properties` property besides the `props` property in the object rule.
97+
198
--------------------------------------------------
299
<a name="0.6.19"></a>
3100
# 0.6.19 (2019-10-25)

0 commit comments

Comments
 (0)