fastest-validator
Advanced tools
Comparing version 0.6.4 to 0.6.5
@@ -416,2 +416,3 @@ (function (global, factory) { | ||
* @param {Object} schema | ||
* @throws {Error} Invalid schema | ||
*/ | ||
@@ -421,19 +422,18 @@ Validator.prototype.compile = function(schema) { | ||
var self = this; | ||
var rules; | ||
if (Array.isArray(schema)) { | ||
// Multiple schemas | ||
if (schema.length == 0) | ||
{ throw new Error("If the schema is an Array, must contain at least one element!"); } | ||
if (schema.length == 0) { | ||
throw new Error("If the schema is an Array, must contain at least one element!"); | ||
} | ||
return this._checkWrapper(flatten_1(schema.map(function (r) { return this$1._processRule(r, null, false); })), true); | ||
var rules = flatten_1(schema.map(function (r) { return this$1._processRule(r, null, false); })); | ||
return this._checkWrapper(rules, true); | ||
} else if (schema != null && typeof schema === "object") { | ||
rules = flatten_1(Object.keys(schema).map(function (name) { return self._processRule(schema[name], name, false); })); | ||
} else | ||
{ throw new Error("Invalid schema!"); } | ||
var rules$1 = flatten_1(Object.keys(schema).map(function (name) { return this$1._processRule(schema[name], name, false); })); | ||
return this._checkWrapper(rules$1); | ||
} | ||
return this._checkWrapper(rules); | ||
throw new Error("Invalid schema!"); | ||
}; | ||
@@ -451,8 +451,2 @@ | ||
if (typeof rule === "string") { | ||
rule = { | ||
type: rule | ||
}; | ||
} | ||
if (Array.isArray(rule)) { | ||
@@ -471,13 +465,20 @@ // Compile the multiple schemas | ||
if (this.rules[rule.type]) { | ||
checks.push({ | ||
fn: this.rules[rule.type], | ||
type: rule.type, | ||
name: name, | ||
schema: rule, | ||
iterate: iterate | ||
}); | ||
} else | ||
{ throw new Error("Invalid '" + rule.type + "' type in validator schema!"); } | ||
if (typeof rule === "string") { | ||
rule = { | ||
type: rule | ||
}; | ||
} | ||
if (!this.rules[rule.type]) { | ||
throw new Error("Invalid '" + rule.type + "' type in validator schema!"); | ||
} | ||
checks.push({ | ||
fn: this.rules[rule.type], | ||
type: rule.type, | ||
name: name, | ||
schema: rule, | ||
iterate: iterate | ||
}); | ||
// Nested schema | ||
@@ -484,0 +485,0 @@ if (rule.type === "object" && rule.props) { |
@@ -9,3 +9,3 @@ { | ||
"dependencies": { | ||
"fastest-validator": "^0.5.0", | ||
"fastest-validator": "^0.6.5", | ||
"serve": "^6.0.2" | ||
@@ -12,0 +12,0 @@ }, |
@@ -58,21 +58,21 @@ "use strict"; | ||
* @param {Object} schema | ||
* @throws {Error} Invalid schema | ||
*/ | ||
Validator.prototype.compile = function(schema) { | ||
const self = this; | ||
let rules; | ||
if (Array.isArray(schema)) { | ||
// Multiple schemas | ||
if (schema.length == 0) | ||
if (schema.length == 0) { | ||
throw new Error("If the schema is an Array, must contain at least one element!"); | ||
} | ||
return this._checkWrapper(flatten(schema.map(r => this._processRule(r, null, false))), true); | ||
const rules = flatten(schema.map(r => this._processRule(r, null, false))); | ||
return this._checkWrapper(rules, true); | ||
} else if (schema != null && typeof schema === "object") { | ||
rules = flatten(Object.keys(schema).map(name => self._processRule(schema[name], name, false))); | ||
} else | ||
throw new Error("Invalid schema!"); | ||
const rules = flatten(Object.keys(schema).map(name => this._processRule(schema[name], name, false))); | ||
return this._checkWrapper(rules); | ||
} | ||
return this._checkWrapper(rules); | ||
throw new Error("Invalid schema!"); | ||
}; | ||
@@ -88,10 +88,4 @@ | ||
Validator.prototype._processRule = function(rule, name, iterate) { | ||
let checks = []; | ||
const checks = []; | ||
if (typeof rule === "string") { | ||
rule = { | ||
type: rule | ||
}; | ||
} | ||
if (Array.isArray(rule)) { | ||
@@ -110,13 +104,20 @@ // Compile the multiple schemas | ||
if (this.rules[rule.type]) { | ||
checks.push({ | ||
fn: this.rules[rule.type], | ||
type: rule.type, | ||
name: name, | ||
schema: rule, | ||
iterate: iterate | ||
}); | ||
} else | ||
if (typeof rule === "string") { | ||
rule = { | ||
type: rule | ||
}; | ||
} | ||
if (!this.rules[rule.type]) { | ||
throw new Error("Invalid '" + rule.type + "' type in validator schema!"); | ||
} | ||
checks.push({ | ||
fn: this.rules[rule.type], | ||
type: rule.type, | ||
name: name, | ||
schema: rule, | ||
iterate: iterate | ||
}); | ||
// Nested schema | ||
@@ -123,0 +124,0 @@ if (rule.type === "object" && rule.props) { |
{ | ||
"name": "fastest-validator", | ||
"version": "0.6.4", | ||
"version": "0.6.5", | ||
"description": "The fastest JS validator library for NodeJS", | ||
"main": "index.js", | ||
"browser": "dist/browser/index.min.js", | ||
"main": "dist/index.js", | ||
"browser": "dist/index.min.js", | ||
"scripts": { | ||
@@ -29,3 +29,3 @@ "bench": "node benchmark/index.js", | ||
"files": [ | ||
"dist/browser/index.js", | ||
"dist", | ||
"examples", | ||
@@ -32,0 +32,0 @@ "lib", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
162515
41
1827
1