Comparing version 0.2.4 to 0.2.5
@@ -46,3 +46,4 @@ // Load modules | ||
if (!skipFunctions || typeof unprocessedObject[unprocessedKey] !== 'function') { | ||
var unprocessedValueType = typeof unprocessedObject[unprocessedKey]; | ||
if ((!skipFunctions || unprocessedValueType !== 'function') && unprocessedValueType !== 'undefined') { | ||
errors.add('the key (' + unprocessedKey + ') is not allowed', unprocessedKey); | ||
@@ -55,3 +56,3 @@ } | ||
var converted = null; | ||
var converted; | ||
var errorFilter = function (error) { | ||
@@ -90,7 +91,7 @@ | ||
} | ||
return { value: value }; | ||
} | ||
catch (err) { | ||
return null; | ||
return; | ||
} | ||
@@ -97,0 +98,0 @@ } |
@@ -74,3 +74,3 @@ // Load modules | ||
if (!result) { | ||
errors.add('the value of `' + key + '` must be an Array', keyPath); | ||
errors.add('the value of ' + key + ' must be an Array', keyPath); | ||
} | ||
@@ -155,3 +155,3 @@ | ||
var vals = invalidValues.map(function (d) { return JSON.stringify(d); }).join(', ').replace(/[\']/g, '\''); | ||
var msg = 'the value(s) `' + vals + '` in array `' + key + '` must be of the following type(s) ' + Sys.inspect(validTypes); | ||
var msg = 'the value(s) ' + vals + ' in array ' + key + ' must be of the following type(s) ' + Sys.inspect(validTypes); | ||
errors.add(msg, keyPath); | ||
@@ -196,3 +196,3 @@ } | ||
if (components.indexOf(true) >= 0) { | ||
errors.add('the values supplied to array `' + key + '` must contain ' + JSON.stringify(validTypes), keyPath); | ||
errors.add('the values supplied to array ' + key + ' must contain ' + JSON.stringify(validTypes), keyPath); | ||
return false; | ||
@@ -210,3 +210,3 @@ } | ||
errors.add('the values supplied to array `' + key + '` must contain ' + JSON.stringify(validTypes), keyPath); | ||
errors.add('the values supplied to array ' + key + ' must contain ' + JSON.stringify(validTypes), keyPath); | ||
@@ -213,0 +213,0 @@ return false; |
@@ -243,3 +243,3 @@ // Load modules | ||
if (!result) { | ||
errors.add('the value of `' + key + '` must exist without ' + peers, keyPath); | ||
errors.add('the value of ' + key + ' must exist without ' + peers, keyPath); | ||
} | ||
@@ -364,3 +364,3 @@ | ||
status = false; | ||
errors.add('the value of `' + key + '` is not allowed to be ' + this.__invalids._values[this.__invalids._values.indexOf(value)], keyPath); | ||
errors.add('the value of ' + key + ' is not allowed to be ' + this.__invalids._values[this.__invalids._values.indexOf(value)], keyPath); | ||
if (this.options.shortCircuit === true) { | ||
@@ -388,3 +388,3 @@ return status; | ||
errors.add('the value of `' + key + '` must be one of ' + valids.join(', '), keyPath); | ||
errors.add('the value of ' + key + ' must be one of ' + valids.join(', '), keyPath); | ||
@@ -391,0 +391,0 @@ if (this.options.shortCircuit === true) { |
@@ -48,3 +48,3 @@ // Load modules | ||
if (!result) { | ||
errors.add('the value of `' + key + '` must be a boolean', keyPath); | ||
errors.add('the value of ' + key + ' must be a boolean', keyPath); | ||
} | ||
@@ -51,0 +51,0 @@ |
@@ -39,3 +39,3 @@ // Load modules | ||
if (!result) { | ||
errors.add('the value of `' + key + '` must be a Function', keyPath); | ||
errors.add('the value of ' + key + ' must be a Function', keyPath); | ||
} | ||
@@ -42,0 +42,0 @@ |
@@ -47,3 +47,3 @@ // Load modules | ||
if (typeof value !== 'number' && typeof value !== 'string') { | ||
errors.add('the value of `' + key + '` must be a number', keyPath); | ||
errors.add('the value of ' + key + ' must be a number', keyPath); | ||
return false; | ||
@@ -72,3 +72,3 @@ } | ||
if (!result) { | ||
errors.add('the value of `' + key + '` must be larger than (or equal to) ' + n, keyPath); | ||
errors.add('the value of ' + key + ' must be larger than (or equal to) ' + n, keyPath); | ||
} | ||
@@ -96,3 +96,3 @@ | ||
if (!result) { | ||
errors.add('the value of `' + key + '` must be less than (or equal to) ' + n, keyPath); | ||
errors.add('the value of ' + key + ' must be less than (or equal to) ' + n, keyPath); | ||
} | ||
@@ -117,3 +117,3 @@ return result; | ||
if (!result) { | ||
errors.add('the value of `' + key + '` must be an integer', keyPath); | ||
errors.add('the value of ' + key + ' must be an integer', keyPath); | ||
} | ||
@@ -140,3 +140,3 @@ | ||
if (!result) { | ||
errors.add('the value of `' + key + '` must be a float or double', keyPath); | ||
errors.add('the value of ' + key + ' must be a float or double', keyPath); | ||
} | ||
@@ -143,0 +143,0 @@ |
@@ -6,3 +6,2 @@ // Load modules | ||
var Utils = require('../utils'); | ||
var Validator = require('../'); | ||
@@ -51,3 +50,3 @@ | ||
if (typeof value !== 'object') { | ||
errors.add('the value of `' + key + '` must be an object', keyPath); | ||
errors.add('the value of ' + key + ' must be an object', keyPath); | ||
return false; | ||
@@ -70,7 +69,7 @@ } | ||
var self = this; | ||
var traverse = function (obj, config, errors, keyPath) { | ||
var keys = Object.keys(config); | ||
var unprocessedObject = Utils.clone(obj || {}); | ||
var result = true; | ||
@@ -92,5 +91,18 @@ for (var i = 0, il = keys.length; i < il; ++i) { | ||
} | ||
delete unprocessedObject[key]; | ||
} | ||
return true; | ||
if (keys.length) { // Only error on unknown keys when config specifies a structure | ||
Object.keys(unprocessedObject).forEach(function (unprocessedKey) { | ||
var unprocessedValueType = typeof unprocessedObject[unprocessedKey]; | ||
if (unprocessedValueType !== 'function' && unprocessedValueType !== 'undefined') { | ||
errors.add('the key (' + unprocessedKey + ') is not allowed', unprocessedKey); | ||
result = false; | ||
} | ||
}); | ||
} | ||
return result; | ||
}; | ||
@@ -97,0 +109,0 @@ |
@@ -42,3 +42,3 @@ // Load modules | ||
if (!result) { | ||
errors.add('the value of `' + key + '` must be a string', keyPath); | ||
errors.add('the value of ' + key + ' must be a string', keyPath); | ||
} | ||
@@ -76,3 +76,3 @@ | ||
if (!result) { | ||
errors.add('the value of `' + key + '` must be at least ' + n + ' characters long', keyPath); | ||
errors.add('the value of ' + key + ' must be at least ' + n + ' characters long', keyPath); | ||
} | ||
@@ -102,3 +102,3 @@ | ||
if (!result) { | ||
errors.add('the value of `' + key + '` must be less than (or equal to) ' + n + ' characters long', keyPath); | ||
errors.add('the value of ' + key + ' must be less than (or equal to) ' + n + ' characters long', keyPath); | ||
} | ||
@@ -126,3 +126,3 @@ | ||
if (!result) { | ||
errors.add('the value of `' + key + '` must match the RegExp `' + n.toString() + '`', keyPath); | ||
errors.add('the value of ' + key + ' must match the RegExp ' + n.toString(), keyPath); | ||
} | ||
@@ -152,3 +152,3 @@ return result; | ||
if (!result) { | ||
errors.add('the value of `' + key + '` must be a valid JavaScript Date format', keyPath); | ||
errors.add('the value of ' + key + ' must be a valid JavaScript Date format', keyPath); | ||
} | ||
@@ -189,3 +189,3 @@ return result; | ||
if (!result) { | ||
errors.add('The value of `' + key + '` must be a valid email', keyPath); | ||
errors.add('The value of ' + key + ' must be a valid email', keyPath); | ||
} | ||
@@ -192,0 +192,0 @@ return result; |
{ | ||
"name": "joi", | ||
"description": "Object schema validation", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"author": "Van Nguyen <the.gol.effect@gmail.com>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -135,2 +135,4 @@ // Load modules | ||
expect(Joi.validate({ auth: { mode: 'try' } }, config)).to.be.null; | ||
expect(Joi.validate({ something: undefined }, config)).to.be.null; | ||
expect(Joi.validate({ auth: { something: undefined }}, config)).to.be.null; | ||
@@ -140,2 +142,59 @@ done(); | ||
it('should validate an unknown option', function (done) { | ||
var config = { | ||
auth: Joi.types.Object({ | ||
mode: T.String().valid('required', 'optional', 'try').optional().nullOk() | ||
}).optional().nullOk() | ||
}; | ||
expect(Joi.validate({ auth: { unknown: true } }, config)).to.not.be.null; | ||
expect(Joi.validate({ something: false }, config)).to.not.be.null; | ||
done(); | ||
}); | ||
it('should work with complex configs', function (done) { | ||
var config = { | ||
handler: [T.Object(), T.Function(), T.String().valid('notFound').optional()], | ||
payload: T.String().valid('stream', 'raw', 'parse').nullOk(), | ||
response: T.Object({ | ||
schema: T.Object().nullOk().optional(), | ||
sample: T.Number().optional(), | ||
failAction: T.String().optional().valid('error', 'log', 'ignore') | ||
}).optional().nullOk().allow(true).allow(false), | ||
auth: [ | ||
T.Object({ | ||
mode: T.String().valid(['required', 'optional', 'try']).nullOk(), | ||
scope: T.String().nullOk(), | ||
tos: T.Number().nullOk(), | ||
entity: T.String().nullOk(), | ||
strategy: T.String().nullOk(), | ||
strategies: T.Array().nullOk(), | ||
payload: T.String().nullOk() | ||
}).optional().nullOk(), | ||
T.Boolean().allow(false).optional().nullOk(), | ||
T.String().optional().nullOk() | ||
] | ||
}; | ||
expect(Joi.validate({ payload: 'raw' }, config)).to.be.null; | ||
expect(Joi.validate({ auth: { mode: 'required', payload: 'required' }, payload: 'raw' }, config)).to.be.null; | ||
done(); | ||
}); | ||
it('should not require optional numbers', function (done) { | ||
var config = { | ||
position: T.Number(), | ||
suggestion: T.String() | ||
}; | ||
expect(Joi.validate({ suggestion: 'something' }, config)).to.be.null; | ||
expect(Joi.validate({ position: 1 }, config)).to.be.null; | ||
done(); | ||
}); | ||
it('should validate object successfully when config has an array of types', function (done) { | ||
@@ -142,0 +201,0 @@ |
@@ -0,0 +0,0 @@ // Load modules |
Sorry, the diff of this file is not supported yet
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
281369
3064