You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The full module has been rewritten. It uses code generators in order to be much faster.
4
+
5
+
The full library has been rewritten. It uses code generators in order to be much faster.
5
6
6
7
## Breaking changes
8
+
This new version contains several breaking changes.
7
9
8
10
### Rule logic changed
9
-
The rule codes have been rewritten to code generator functions.
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.
10
15
11
16
## New
12
17
13
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`.
14
40
15
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
+
constschema= {
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.
Copy file name to clipboardExpand all lines: README.md
+67-40Lines changed: 67 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -245,7 +245,7 @@ v.validate("Al", schema); // Fail, too short.
245
245
```
246
246
247
247
# Sanitizations
248
-
The library contains several sanitizations. **Please note, the sanitizers change the original object.**
248
+
The library contains several sanitizaters. **Please note, the sanitizers change the original checked object.**
249
249
250
250
## Default values
251
251
The most common sanitizer is the `default` property. With it, you can define a default value for all properties. If the property value is `null` or `undefined`, the validator set the defined default value into the property.
expect(v.makeError({type: "required",messages: v.messages})).toBe("errors.push({ type: \"required\", message: \"The '{field}' field is required.\", field: field });");
197
+
expect(v.makeError({type: "stringMin",field: "firstName",expected: 6,actual: 3,messages: v.messages})).toBe("errors.push({ type: \"stringMin\", message: \"The '{field}' field length must be greater than or equal to {expected} characters long.\", field: \"firstName\", expected: 6, actual: 3 });");
0 commit comments