Comparing version 0.10.1 to 0.11.0
@@ -36,3 +36,3 @@ 'use strict'; | ||
/** | ||
* Validator method, used by model | ||
* Validator method, used by rules | ||
* @param {Object} def The property configuration | ||
@@ -49,2 +49,6 @@ * @param {String} key The key name of the property | ||
}; | ||
// Handle `empty` prop for string values | ||
if (def.empty && typeof value === 'string' && def.type !== 'array' && value.length === 0) { | ||
return value; | ||
} | ||
// Execute check | ||
@@ -51,0 +55,0 @@ return types.check({ def: parsedDef, key: key, value: value, fail: fail, errors: this.errors }); |
@@ -23,5 +23,15 @@ 'use strict'; | ||
default: function _default(context) { | ||
// Ensure array | ||
if (!Array.isArray(context.value)) { | ||
return context.fail('Value must be an array'); | ||
} | ||
// If empty (and empty allowed), move forward | ||
if (context.def.empty && context.value.length === 0) { | ||
return context.value; | ||
} | ||
// If empty (and not empty allowed), fail | ||
if (!context.def.empty && context.value.length === 0) { | ||
return context.fail('Value must not be empty array'); | ||
} | ||
// Specific array sub-validation | ||
if (!context.def.values) return true; | ||
@@ -28,0 +38,0 @@ var promises = context.value.map(function (elem, idx) { |
@@ -11,3 +11,3 @@ 'use strict'; | ||
default: function _default(context) { | ||
if (typeof context.value !== 'string') { | ||
if (typeof context.value !== 'string' || context.value.length === 0) { | ||
context.fail('Value must be a string'); | ||
@@ -14,0 +14,0 @@ } |
{ | ||
"name": "obey", | ||
"version": "0.10.1", | ||
"version": "0.11.0", | ||
"description": "Data modelling and validation library", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -62,3 +62,3 @@ # Obey | ||
fname: { type: 'string', description: 'First Name' }, | ||
lname: { type: 'string', description: 'Last Name' }, | ||
lname: { type: 'string', description: 'Last Name', empty: true }, | ||
phone: { type: 'phone:numeric', min: 7, max: 10 }, | ||
@@ -132,2 +132,3 @@ // Array | ||
* `generator`: uses a method to create a default value if no value is supplied, see [Generators](#generators) | ||
* `empty`: Set to `true` allows empty string or array, (default `false`) | ||
* `default`: The default value if no value specified | ||
@@ -134,0 +135,0 @@ * `min`: The minimum character length for a string, lowest number, or minimum items in array |
36542
23
651
296