Comparing version 0.9.3 to 0.9.4
@@ -279,2 +279,2 @@ /** | ||
throw new Error('Not implemented yet! If you\'d like to contribute, tweet @mikermcneil.'); | ||
} | ||
} |
@@ -68,14 +68,9 @@ /** | ||
// remove data from the front | ||
args.shift(); | ||
// Construct error message | ||
var errMsg = ''; | ||
var argStr = _.reduce(args, function (memo, arg, i) { | ||
// Prepend w/ comma if this isn't the first argument | ||
return ( (i > 0) ? ',' : '' ) + arg; | ||
}, ''); | ||
// If for some reasons the first argument was empty | ||
if(argStr[0] === ',') argStr = argStr.slice(1); | ||
errMsg += 'Validation error: "'+data+'" '; | ||
errMsg += 'Rule "' + ruleName + '(' + argStr + ')" failed.'; | ||
errMsg += 'Rule "' + ruleName + '(' + args.join(',') + ')" failed.'; | ||
@@ -124,17 +119,23 @@ // Construct error object | ||
// If this is a schema rule, check each item in the data collection | ||
if (_.isArray(ruleset) && ruleset.length !== 0) { | ||
if (ruleset.length > 1) { | ||
throw new Error ('[] (or schema) rules can contain only one item.'); | ||
if (_.isArray(ruleset)) { | ||
if (ruleset.length !== 0) { | ||
if (ruleset.length > 1) { | ||
throw new Error ('[] (or schema) rules can contain only one item.'); | ||
} | ||
// Handle plurals (arrays with a schema rule) | ||
// Match each object in data array against ruleset until error is detected | ||
_.each(data, function (model) { | ||
errors = errors.concat(deepMatchType(model, ruleset[0], depth+1, keyName)); | ||
}); | ||
return errors; | ||
} | ||
// Handle plurals (arrays with a schema rule) | ||
// Match each object in data array against ruleset until error is detected | ||
_.each(data, function (model) { | ||
errors = errors.concat(deepMatchType(model, ruleset[0], depth+1, keyName)); | ||
}); | ||
return errors; | ||
// Leaf rules land here and execute the iterator | ||
else return matchType(data, ruleset, keyName); | ||
} | ||
// If the current rule is an object, check each key | ||
else if (!_.isArray(ruleset) && _.isObject(ruleset)) { | ||
// && _.isObject(ruleset) is a redundant test (already tested aboved), always true at this point | ||
// !_.isArray(ruleset) is also redundant test, just need to refactor if else | ||
else { | ||
@@ -154,5 +155,2 @@ // Don't treat empty object as a ruleset | ||
} | ||
// Leaf rules land here and execute the iterator | ||
else return matchType(data, ruleset, keyName); | ||
} | ||
@@ -159,0 +157,0 @@ |
{ | ||
"name": "anchor", | ||
"version": "0.9.3", | ||
"version": "0.9.4", | ||
"description": "Recursive validation library with support for objects and lists", | ||
@@ -20,6 +20,6 @@ "main": "index.js", | ||
"dependencies": { | ||
"validator": "0.4.22", | ||
"underscore": "1.4.4", | ||
"async": "0.2.6" | ||
"validator": "1.5.0", | ||
"underscore": "1.5.1", | ||
"async": "0.2.9" | ||
} | ||
} |
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
827
36141
+ Addedasync@0.2.9(transitive)
+ Addedunderscore@1.5.1(transitive)
+ Addedvalidator@1.5.0(transitive)
- Removedasync@0.2.6(transitive)
- Removedunderscore@1.4.4(transitive)
- Removedvalidator@0.4.22(transitive)
Updatedasync@0.2.9
Updatedunderscore@1.5.1
Updatedvalidator@1.5.0