Skip to content

Commit 1fda5b7

Browse files
authored
Merge pull request #98 from icebob/next
Beta2
2 parents 8741d26 + d8c2dfe commit 1fda5b7

File tree

8 files changed

+63
-11
lines changed

8 files changed

+63
-11
lines changed

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
--------------------------------------------------
2-
<a name="1.0.0"></a>
3-
# 1.0.0 (2019-11-xx)
2+
<a name="1.0.0-beta2"></a>
3+
# 1.0.0-beta2 (2019-11-15)
4+
5+
## Changes
6+
- fix array rule return value issue.
7+
8+
--------------------------------------------------
9+
<a name="1.0.0-beta1"></a>
10+
# 1.0.0-beta1 (2019-11-15)
411

512
The full library has been rewritten. It uses code generators in order to be much faster.
613

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525
* unit tests & 100% coverage
2626

2727
# How fast?
28-
Very fast! ~5 million validations/sec (on Intel i7-4770K, Node.JS: 10.16.0)
28+
Very fast! 8 million validations/sec (on Intel i7-4770K, Node.JS: 10.16.0)
2929
```
3030
√ validate 8,461,975 rps
3131
```
3232

3333
Compared to other popular libraries:
3434

35-
[![Result](https://user-images.githubusercontent.com/306521/47523074-79cdec80-d897-11e8-86a0-ad07556be8bc.png)](https://github.com/icebob/validator-benchmark#result)
36-
> 100x faster than Joi.
35+
[![Result](https://user-images.githubusercontent.com/306521/68978853-404a8500-07fc-11ea-94e4-0c25546dad04.png)](https://github.com/icebob/validator-benchmark#result)
36+
> 50x faster than Joi.
3737
3838
**Would you like to test it?**
3939

examples/next.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ v.add("even", function({ schema, messages }, path, context) {
2020
});
2121

2222
const schema = {
23-
id: "number|positive|integer|convert",
24-
name: "string|min: 3|max: 255|padStart: 5",
25-
token: "forbidden|remove",
23+
//id: "number|positive|integer|convert",
24+
//name: "string|min: 3|max: 255|padStart: 5",
25+
//token: "forbidden|remove",
2626
//password: { type: "string", min: 6 },
2727
//confirmPassword: { type: "equal", field: "password" },
2828
//roles: { type: "array", items: "string", min: 1, default: ["user"] },
@@ -59,7 +59,8 @@ const schema = {
5959
weightMin: "The '${field}' must be greater than {expected}! Actual: {actual}"
6060
}
6161
}*/
62-
num: { type: "even" }
62+
includes: { type: "multi", optional: true, rules: [ { type: "string" }, { type: "array", items: "string" } ] },
63+
//num: { type: "even" }
6364
};
6465

6566
const check = v.compile(schema);
@@ -90,6 +91,9 @@ const obj = {
9091

9192
createdAt: Date.now(),
9293

94+
//includes: "test1",
95+
//includes: ["test1", "test2"],
96+
9397
weight: 10,
9498
num: 2
9599
};

lib/rules/array.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ module.exports = function({ schema, messages }, path, context) {
8787
*/
8888
src.push(`
8989
}
90+
91+
return value;
9092
`);
9193
}
9294

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fastest-validator",
3-
"version": "1.0.0-beta1",
3+
"version": "1.0.0-beta2",
44
"description": "The fastest JS validator library for NodeJS",
55
"main": "index.js",
66
"browser": "dist/index.min.js",

test/rules/array.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,23 @@ describe("Test rule: array", () => {
9191
]);
9292
});
9393

94+
describe("Test sanitization", () => {
95+
96+
it("should trim all items", () => {
97+
let schema = {
98+
roles: { type: "array", items: "string|trim" }
99+
};
100+
let check = v.compile(schema);
101+
102+
const obj = {
103+
roles: [" admin", "user ", " moderator "]
104+
};
105+
106+
expect(check(obj)).toEqual(true);
107+
expect(obj).toEqual({
108+
roles: ["admin", "user", "moderator"]
109+
});
110+
});
111+
112+
});
94113
});

test/typescript/rules/array.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,24 @@ describe('TypeScript Definitions', () => {
9696
]);
9797
});
9898
});
99+
100+
describe("Test sanitization", () => {
101+
102+
it("should trim all items", () => {
103+
let schema = {
104+
roles: { type: "array", items: "string|trim" } as RuleArray
105+
};
106+
let check = v.compile(schema);
107+
108+
const obj = {
109+
roles: [" admin", "user ", " moderator "]
110+
};
111+
112+
expect(check(obj)).toEqual(true);
113+
expect(obj).toEqual({
114+
roles: ["admin", "user", "moderator"]
115+
});
116+
});
117+
118+
});
99119
});

0 commit comments

Comments
 (0)