consultant
Advanced tools
Comparing version 0.1.26 to 0.1.27
import { RuleCollection } from './Rule'; | ||
import { ValidationResult } from './Validator'; | ||
export interface PickResult { | ||
items: Input; | ||
export interface ConsumeResult extends ValidationResult { | ||
remainder: Input; | ||
@@ -11,4 +10,4 @@ } | ||
validate(rules: RuleCollection): ValidationResult; | ||
pick(keys: string[]): PickResult; | ||
consume(rules: RuleCollection): ConsumeResult; | ||
} | ||
export default Input; |
@@ -13,8 +13,7 @@ "use strict"; | ||
}; | ||
Input.prototype.pick = function (keys) { | ||
var picked = immunity.pickFromObject(this.source, keys); | ||
return { | ||
items: new Input(picked.items), | ||
Input.prototype.consume = function (rules) { | ||
var picked = immunity.pickFromObject(this.source, Object.keys(rules)); | ||
return Object.assign({ | ||
remainder: new Input(picked.remainder) | ||
}; | ||
}, this.validate(rules)); | ||
}; | ||
@@ -21,0 +20,0 @@ return Input; |
@@ -46,14 +46,13 @@ "use strict"; | ||
var errors = []; | ||
if (rule.validate === undefined) { | ||
return []; | ||
if (rule.validate !== undefined) { | ||
item.value.forEach(function (currentValue) { | ||
var validationMethodResult = rule.validate(currentValue); | ||
if (validationMethodResult !== true) { | ||
errors = errors.concat([ | ||
{ error: "validation failed. value is \"" + currentValue + "\": " + validationMethodResult } | ||
]); | ||
} | ||
}); | ||
} | ||
item.value.forEach(function (currentValue) { | ||
var validationMethodResult = rule.validate(currentValue); | ||
if (validationMethodResult !== true) { | ||
return [ | ||
{ error: "validation failed. value is \"" + currentValue + "\": " + validationMethodResult } | ||
]; | ||
} | ||
}); | ||
return []; | ||
return errors; | ||
}; | ||
@@ -91,3 +90,3 @@ Validator.prototype.findValues = function (rule, argv, key) { | ||
var resultErrors = {}; | ||
var isValid = false; | ||
var isValid = true; | ||
for (var _i = 0, _a = Object.keys(rules); _i < _a.length; _i++) { | ||
@@ -116,3 +115,3 @@ var ruleKey = _a[_i]; | ||
if (item.errors.length > 0) { | ||
isValid = true; | ||
isValid = false; | ||
resultErrors = immunity.appendToObject(resultErrors, (_c = {}, | ||
@@ -119,0 +118,0 @@ _c[ruleKey] = item.errors, |
@@ -19,3 +19,3 @@ { | ||
], | ||
"version": "0.1.26", | ||
"version": "0.1.27", | ||
"homepage": "", | ||
@@ -22,0 +22,0 @@ "author": "Eser Ozvataf <eser@ozvataf.com>", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
41044
577