Comparing version 2.5.0 to 2.6.0
@@ -19,3 +19,3 @@ // Load modules | ||
var values = []; | ||
var details = []; | ||
for (var i = 0, il = errors.length; i < il; ++i) { | ||
@@ -31,13 +31,13 @@ var item = errors[i]; | ||
values.push({ message: message, path: item.path || item.context.key, type: item.type }); | ||
details.push({ message: message, path: item.path || item.context.key, type: item.type }); | ||
} | ||
return new internals.ValidationError(values, object); | ||
return new internals.ValidationError(details, object); | ||
}; | ||
internals.ValidationError = function (errors, object) { | ||
internals.ValidationError = function (details, object) { | ||
Error.call(this); | ||
this._errors = errors; | ||
this.details = details; | ||
this._object = object; | ||
@@ -54,3 +54,3 @@ | ||
var message = ''; | ||
this._errors.forEach(function (error) { | ||
this.details.forEach(function (error) { | ||
@@ -70,5 +70,5 @@ message += (message ? '. ' : '') + error.message; | ||
var el = this._errors.length; | ||
var el = this.details.length; | ||
for (var e = el - 1; e >= 0; --e) { // Reverse order to process deepest child first | ||
var error = this._errors[e]; | ||
var error = this.details[e]; | ||
var path = error.path.split('.'); | ||
@@ -110,3 +110,3 @@ var ref = obj; | ||
for (e = 0; e < el; ++e) { | ||
this.message += '\n[' + (e + 1) + '] ' + this._errors[e].message; | ||
this.message += '\n[' + (e + 1) + '] ' + this.details[e].message; | ||
} | ||
@@ -113,0 +113,0 @@ |
@@ -66,2 +66,9 @@ // Load modules | ||
exports.validateCallback = function (object, schema, options, callback) { // Not actually async, just callback interface | ||
var err = exports.validate(object, schema, options); | ||
return callback(err); | ||
}; | ||
exports.describe = function (schema) { | ||
@@ -68,0 +75,0 @@ |
{ | ||
"name": "joi", | ||
"description": "Object schema validation", | ||
"version": "2.5.0", | ||
"version": "2.6.0", | ||
"repository": "git://github.com/spumko/joi", | ||
@@ -6,0 +6,0 @@ "main": "index", |
@@ -139,3 +139,3 @@ <a href="https://github.com/spumko"><img src="https://raw.github.com/spumko/spumko/master/images/from.png" align="right" /></a> | ||
- `abortEarly` - when `true`, stops validation on the first error, otherwise returns all the errors found. Defaults to `true`. | ||
- `convert` - when `true`, attepmts to cast values to the required types (e.g. a string to a number). Defaults to `true`. | ||
- `convert` - when `true`, attempts to cast values to the required types (e.g. a string to a number). Defaults to `true`. | ||
- `modify` - when `true`, converted values are written back to the provided value (only when value is an object). Defaults to `false`. | ||
@@ -142,0 +142,0 @@ - `allowUnknown` - when `true`, allows object to contain unknown keys which are ignored. Defaults to `false`. |
@@ -44,2 +44,23 @@ // Load modules | ||
it('validates object with callback interface', function (done) { | ||
var schema = { | ||
a: Joi.number().min(0).max(3).without('none'), | ||
b: Joi.string().valid('a', 'b', 'c'), | ||
c: Joi.string().email().optional() | ||
}; | ||
var obj = { | ||
a: 1, | ||
b: 'a', | ||
c: 'joe@example.com' | ||
}; | ||
Joi.validateCallback(obj, schema, null, function (err) { | ||
expect(err).to.not.exist; | ||
done(); | ||
}); | ||
}); | ||
it('validates null', function (done) { | ||
@@ -859,3 +880,3 @@ | ||
expect(errFull).to.exist | ||
expect(errFull._errors.length).to.be.greaterThan(errOne._errors.length); | ||
expect(errFull.details.length).to.be.greaterThan(errOne.details.length); | ||
done(); | ||
@@ -931,6 +952,6 @@ }); | ||
expect(err).to.exist; | ||
expect(err._errors).to.have.length(3); | ||
expect(err._errors[0].type).to.equal('number.base'); | ||
expect(err._errors[1].type).to.equal('string.base'); | ||
expect(err._errors[2].type).to.equal('boolean.base'); | ||
expect(err.details).to.have.length(3); | ||
expect(err.details[0].type).to.equal('number.base'); | ||
expect(err.details[1].type).to.equal('string.base'); | ||
expect(err.details[2].type).to.equal('boolean.base'); | ||
done(); | ||
@@ -937,0 +958,0 @@ }); |
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
337807
4395