Repository: icebob/fastest-validator
Pull request #98 (2019-11-15 22:16:33)

Beta2


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0c99432..78f0f47 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,13 @@
 --------------------------------------------------
-<a name="1.0.0"></a>
-# 1.0.0 (2019-11-xx)
+<a name="1.0.0-beta2"></a>
+# 1.0.0-beta2 (2019-11-15)
+
+## Changes
+- fix array rule return value issue.
+
+--------------------------------------------------
+<a name="1.0.0-beta1"></a>
+# 1.0.0-beta1 (2019-11-15)
 
 The full library has been rewritten. It uses code generators in order to be much faster.
 
diff --git a/README.md b/README.md
index 47ed64c..af79ea7 100644
--- a/README.md
+++ b/README.md
@@ -25,15 +25,15 @@
 * unit tests & 100% coverage
 
 # How fast?
-Very fast! ~5 million validations/sec (on Intel i7-4770K, Node.JS: 10.16.0)
+Very fast! 8 million validations/sec (on Intel i7-4770K, Node.JS: 10.16.0)
 ```
 √ validate                        8,461,975 rps
 ```
 
 Compared to other popular libraries:
 
-[![Result](https://user-images.githubusercontent.com/306521/47523074-79cdec80-d897-11e8-86a0-ad07556be8bc.png)](https://github.com/icebob/validator-benchmark#result)
-> 100x faster than Joi.
+[![Result](https://user-images.githubusercontent.com/306521/68978853-404a8500-07fc-11ea-94e4-0c25546dad04.png)](https://github.com/icebob/validator-benchmark#result)
+> 50x faster than Joi.
 
 **Would you like to test it?**
 
diff --git a/examples/next.js b/examples/next.js
index 833dab4..fb3c15a 100644
--- a/examples/next.js
+++ b/examples/next.js
@@ -20,9 +20,9 @@ v.add("even", function({ schema, messages }, path, context) {
 });
 
 const schema = {
-	id: "number|positive|integer|convert",
-	name: "string|min: 3|max: 255|padStart: 5",
-	token: "forbidden|remove",
+	//id: "number|positive|integer|convert",
+	//name: "string|min: 3|max: 255|padStart: 5",
+	//token: "forbidden|remove",
 	//password: { type: "string", min: 6 },
 	//confirmPassword: { type: "equal", field: "password" },
 	//roles: { type: "array", items: "string", min: 1, default: ["user"] },
@@ -59,7 +59,8 @@ const schema = {
 			weightMin: "The '${field}' must be greater than {expected}! Actual: {actual}"
 		}
 	}*/
-	num: { type: "even" }
+	includes: { type: "multi", optional: true, rules: [ { type: "string" }, { type: "array", items: "string" } ] },
+	//num: { type: "even" }
 };
 
 const check = v.compile(schema);
@@ -90,6 +91,9 @@ const obj = {
 
 	createdAt: Date.now(),
 
+	//includes: "test1",
+	//includes: ["test1", "test2"],
+
 	weight: 10,
 	num: 2
 };
diff --git a/lib/rules/array.js b/lib/rules/array.js
index e05a3fd..9cd3a71 100644
--- a/lib/rules/array.js
+++ b/lib/rules/array.js
@@ -87,6 +87,8 @@ module.exports = function({ schema, messages }, path, context) {
 		*/
 		src.push(`
 			}
+
+			return value;
 		`);
 	}
 
diff --git a/package-lock.json b/package-lock.json
index 9f0c5f5..53ad01a 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
 {
   "name": "fastest-validator",
-  "version": "1.0.0-beta1",
+  "version": "1.0.0-beta2",
   "lockfileVersion": 1,
   "requires": true,
   "dependencies": {
diff --git a/package.json b/package.json
index 777ec06..bedd2ff 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "fastest-validator",
-  "version": "1.0.0-beta1",
+  "version": "1.0.0-beta2",
   "description": "The fastest JS validator library for NodeJS",
   "main": "index.js",
   "browser": "dist/index.min.js",


Test patch:
diff --git a/test/rules/array.spec.js b/test/rules/array.spec.js
index 6096842..080d9fa 100644
--- a/test/rules/array.spec.js
+++ b/test/rules/array.spec.js
@@ -91,4 +91,23 @@ describe("Test rule: array", () => {
 		]);
 	});
 
+	describe("Test sanitization", () => {
+
+		it("should trim all items", () => {
+			let schema = {
+				roles: { type: "array", items: "string|trim" }
+			};
+			let check = v.compile(schema);
+
+			const obj = {
+				roles: ["  admin", "user   ", "  moderator  "]
+			};
+
+			expect(check(obj)).toEqual(true);
+			expect(obj).toEqual({
+				roles: ["admin", "user", "moderator"]
+			});
+		});
+
+	});
 });
diff --git a/test/typescript/rules/array.spec.ts b/test/typescript/rules/array.spec.ts
index 7fc7ae2..370bab1 100644
--- a/test/typescript/rules/array.spec.ts
+++ b/test/typescript/rules/array.spec.ts
@@ -96,4 +96,24 @@ describe('TypeScript Definitions', () => {
             ]);
         });
     });
+
+	describe("Test sanitization", () => {
+
+		it("should trim all items", () => {
+			let schema = {
+				roles: { type: "array", items: "string|trim" } as RuleArray
+			};
+			let check = v.compile(schema);
+
+			const obj = {
+				roles: ["  admin", "user   ", "  moderator  "]
+			};
+
+			expect(check(obj)).toEqual(true);
+			expect(obj).toEqual({
+				roles: ["admin", "user", "moderator"]
+			});
+		});
+
+	});
 });