Skip to content

Commit

Permalink
Added custom validation support to validator
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Dec 11, 2013
1 parent 872d15e commit b919191
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/utils/validation.js
Expand Up @@ -115,5 +115,19 @@ var validateType = (require.modules || {}).validation = module.exports = functio
if (schemaType === Boolean) return assert(_.isBoolean(value), 'boolean');
if (schemaType === Date) return assert(_.isDate(value), 'date');
if (schemaType instanceof RegExp) return assert(schemaType.test(value || ''), 'regex match on ' + schemaType.toString(), (value || 'nothing').toString());

var virtualThis = {
fail: fail,
assert: assert,
pass: pass
};

for(var i = 0; i < validateType.extra.length; i++) {
var result = validateType.extra[i].call(virtualThis, schemaType, value, property);
if(result) return result;
}

return assert(value instanceof schemaType, 'instanceof ' + schemaType.toString());
};
};

validateType.extra = [];

0 comments on commit b919191

Please sign in to comment.