async-validate
Advanced tools
Comparing version 0.4.7 to 0.4.8
@@ -78,2 +78,10 @@ ## Guide | ||
#### Values | ||
Used with the `array` type as a shorthand for validating array values, may be an `object` or `array` containing validation rules. | ||
When `values` is an object it is applied to all array elements in the source array otherwise each `values` entry is compared against each source array entry which allows mixed types to be used in arrays. | ||
Note that `values` is expanded to `fields`, see [deep rules](#deep-rules). | ||
#### Enumerable | ||
@@ -80,0 +88,0 @@ |
@@ -228,4 +228,27 @@ var iterator = require('./iterator') | ||
func(series, function(rule, callback) { | ||
var validator = getValidationOptions(rule, options); | ||
var validator = getValidationOptions(rule, options) | ||
, len | ||
, i; | ||
if(rule.type === 'array' && typeof rule.values === 'object') { | ||
len = Array.isArray(rule.values) | ||
? rule.values.length : Array.isArray(rule.value) | ||
? rule.value.length : 0; | ||
if(len) { | ||
rule.fields = {}; | ||
} | ||
// object declaration applies to all array values | ||
if(!Array.isArray(rule.values)) { | ||
for(i = 0;i < len;i++) { | ||
rule.fields[i] = rule.values; | ||
} | ||
}else{ | ||
for(i = 0;i < len;i++) { | ||
rule.fields[i] = rule.values[i]; | ||
} | ||
} | ||
} | ||
var deep = (rule.type === 'object' || rule.type === 'array') | ||
@@ -232,0 +255,0 @@ && typeof(rule.fields) === 'object'; |
@@ -17,2 +17,3 @@ var plugin = require('zephyr') | ||
} | ||
// reason constants | ||
@@ -44,3 +45,6 @@ this.reasons = Reason.reasons; | ||
if(typeof this.rule.message === 'function') { | ||
// TODO: allow calls to raise() and error() this would | ||
// TODO: stack overflow right now | ||
msg = this.rule.message.call(this, message, args); | ||
}else{ | ||
@@ -200,3 +204,3 @@ msg = this.rule.message | ||
this.reasons.type, | ||
this.messages.types[type], rule.field, rule.type); | ||
this.messages.types[type], this.field, rule.type); | ||
} | ||
@@ -207,3 +211,3 @@ // straight typeof check | ||
this.reasons.type, | ||
this.messages.types[type], rule.field, rule.type); | ||
this.messages.types[type], this.field, rule.type); | ||
} | ||
@@ -261,2 +265,4 @@ } | ||
Validator.prototype.format = format; | ||
Validator.prototype.isRoot = isRoot; | ||
@@ -263,0 +269,0 @@ Validator.prototype.shouldValidate = shouldValidate; |
{ | ||
"name": "async-validate", | ||
"description": "Asynchronous validation for object properties.", | ||
"version": "0.4.7", | ||
"version": "0.4.8", | ||
"author": "muji <noop@xpm.io>", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -15,2 +15,3 @@ Table of Contents | ||
* [Length](#length) | ||
* [Values](#values) | ||
* [Enumerable](#enumerable) | ||
@@ -155,2 +156,10 @@ * [Date Format](#date-format) | ||
#### Values | ||
Used with the `array` type as a shorthand for validating array values, may be an `object` or `array` containing validation rules. | ||
When `values` is an object it is applied to all array elements in the source array otherwise each `values` entry is compared against each source array entry which allows mixed types to be used in arrays. | ||
Note that `values` is expanded to `fields`, see [deep rules](#deep-rules). | ||
#### Enumerable | ||
@@ -157,0 +166,0 @@ |
117410
73
2702
542