Comparing version 0.4.1 to 0.9.0
@@ -38,3 +38,3 @@ var _ = require('underscore'); | ||
if (rule === 'type') { | ||
// Use deep match to descend into the collection and verify each item and/or key | ||
@@ -126,2 +126,2 @@ // Stop at default maxDepth (50) to prevent infinite loops in self-associations | ||
throw new Error("Not implemented yet! If you'd like to contribute, tweet @mikermcneil."); | ||
} | ||
} |
@@ -20,2 +20,7 @@ var _ = require('underscore'); | ||
// if args is an array we need to make it a nested array | ||
if (Array.isArray(args)) { | ||
args = [args]; | ||
} | ||
// Ensure args is a list, then prepend it with data | ||
@@ -25,5 +30,6 @@ if ( !_.isArray(args) ) { | ||
} | ||
// push data on to front | ||
args.unshift(data); | ||
// Lookup rule and determine outcome | ||
@@ -35,3 +41,3 @@ var outcome; | ||
} | ||
try { | ||
try { | ||
outcome = rule.apply(rule, args); | ||
@@ -48,4 +54,4 @@ } | ||
// On failure-- stop and get out. | ||
// If a cb was specified, call it with a first-arity error object. | ||
// On failure-- stop and get out. | ||
// If a cb was specified, call it with a first-arity error object. | ||
// Otherwise, return a list of error objets. | ||
@@ -57,3 +63,3 @@ function failure() { | ||
var argStr = _.reduce(args, function (memo, arg, i) { | ||
// Prepend w/ comma if this isn't the first argument | ||
@@ -67,3 +73,3 @@ return ( (i > 0) ? ',' : '' ) + arg; | ||
return [{ | ||
data: data, | ||
data: data, | ||
message: errMsg, | ||
@@ -86,3 +92,3 @@ rule: ruleName, | ||
function deepMatchType (data, ruleset, depth, keyName) { | ||
var errors = []; | ||
@@ -107,6 +113,6 @@ | ||
} | ||
// Handle plurals (arrays with a schema rule) | ||
// Match each object in data array against ruleset until error is detected | ||
_.each(data, function (model) { | ||
_.each(data, function (model) { | ||
errors = errors.concat(deepMatchType(model, ruleset[0], depth+1, keyName)); | ||
@@ -183,4 +189,4 @@ }); | ||
else rule = rules[ruleName]; | ||
// Determine outcome | ||
@@ -204,4 +210,4 @@ if (!rule) { | ||
// On failure-- stop and get out. | ||
// If a cb was specified, call it with a first-arity error object. | ||
// On failure-- stop and get out. | ||
// If a cb was specified, call it with a first-arity error object. | ||
// Otherwise, return a list of error objets. | ||
@@ -224,2 +230,2 @@ function failure(datum, ruleName, keyName) { | ||
} | ||
} | ||
} |
@@ -5,3 +5,3 @@ var _ = require('underscore'); | ||
module.exports = { | ||
// Type rules | ||
@@ -14,2 +14,5 @@ 'empty' : function (x) { return x === ''; }, | ||
'object' : _.isObject, | ||
'json' : function (x) { return x.constructor.name === 'Object'; }, | ||
'string' : _.isString, | ||
@@ -48,2 +51,3 @@ 'alpha' : function (x){ return check(x).isAlpha();}, | ||
'date' : function (x) { return check(x).isDate(); }, | ||
'datetime': function (x) { return check(x).isDate(); }, | ||
@@ -66,5 +70,5 @@ 'hexadecimal': function (x) { return check(x).hexadecimal(); }, | ||
'equals' : function (x, equals) { return check(x).equals(equals); }, | ||
'contains' : function (x, str) { return check(x).contains(str); }, | ||
'notContains': function (x, str) { return check(x).notContains(str); }, | ||
'len' : function (x, min, max) { return check(x).len(min, max); }, | ||
'contains' : function (x, str) { return check(x).contains(str); }, | ||
'notContains': function (x, str) { return check(x).notContains(str); }, | ||
'len' : function (x, min, max) { return check(x).len(min, max); }, | ||
'in' : function (x, arrayOrString) { return check(x).isIn(arrayOrString); }, | ||
@@ -71,0 +75,0 @@ 'notIn' : function (x, arrayOrString) { return check(x).notIn(arrayOrString); }, |
{ | ||
"name": "anchor", | ||
"version": "0.4.1", | ||
"version": "0.9.0", | ||
"description": "Recursive validation library with support for objects and lists", | ||
@@ -20,6 +20,6 @@ "main": "index.js", | ||
"dependencies": { | ||
"validator": "~0.4.22", | ||
"validator": "0.4.22", | ||
"underscore": "1.4.4", | ||
"async": "~0.2.6" | ||
"async": "0.2.6" | ||
} | ||
} |
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
32306
684
+ Addedasync@0.2.6(transitive)
+ Addedvalidator@0.4.22(transitive)
- Removedasync@0.2.10(transitive)
- Removedvalidator@0.4.28(transitive)
Updatedasync@0.2.6
Updatedvalidator@0.4.22