Skip to content

Commit 1f681f5

Browse files
committed
update changelog
1 parent bbf5ccc commit 1f681f5

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

CHANGELOG.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,78 @@
11
--------------------------------------------------
2+
<a name="1.5.0"></a>
3+
# 1.5.0 (2020-06-18)
4+
5+
## New `tuple` validation rule
6+
Thanks for [@Gamote](https://github.com/Gamote), in this version there is a new `tuple`. This rule checks if a value is an `Array` with the elements order as described by the schema.
7+
8+
**Example**
9+
```js
10+
const schema = {
11+
grade: { type: "tuple", items: ["string", "number", "string"] }
12+
};
13+
```
14+
15+
```js
16+
const schema = {
17+
location: { type: "tuple", empty: false, items: [
18+
{ type: "number", min: 35, max: 45 },
19+
{ type: "number", min: -75, max: -65 }
20+
] }
21+
}
22+
```
23+
24+
## Define aliases & custom rules in constructor options [#162](https://github.com/icebob/fastest-validator/issues/162)
25+
You can define aliases & custom rules in constructor options instead of using `v.alias` and `v.add`.
26+
27+
**Example**
28+
29+
```js
30+
const v = new Validator({
31+
aliases: {
32+
username: {
33+
type: 'string',
34+
min: 4,
35+
max: 30
36+
}
37+
},
38+
customRules: {
39+
even: function({ schema, messages }, path, context) {
40+
return {
41+
source: `
42+
if (value % 2 != 0)
43+
${this.makeError({ type: "evenNumber", actual: "value", messages })}
44+
45+
return value;
46+
`
47+
};
48+
})
49+
}
50+
});
51+
```
52+
53+
## Support plugins
54+
Thanks for [@erfanium](https://github.com/erfanium), you can create plugin for `fastest-validator`.
55+
56+
**Example**
57+
```js
58+
// Plugin Side
59+
function myPlugin(validator){
60+
// you can modify validator here
61+
// e.g.: validator.add(...)
62+
// or : validator.alias(...)
63+
}
64+
// Validator Side
65+
const v = new Validator();
66+
v.plugin(myPlugin)
67+
```
68+
69+
## Changes
70+
- Allow `empty` property in `string` rule with pattern [#149](https://github.com/icebob/fastest-validator/issues/149)
71+
- Add `empty` property to `url` and `email` rule [#150](https://github.com/icebob/fastest-validator/issues/150)
72+
- Fix custom rule issue when multiple rules [#155](https://github.com/icebob/fastest-validator/issues/155)
73+
- Update type definition [#156](https://github.com/icebob/fastest-validator/issues/156)
74+
75+
--------------------------------------------------
276
<a name="1.4.2"></a>
377
# 1.4.2 (2020-06-03)
478

0 commit comments

Comments
 (0)