UNPKG

modella-validators

Version:
13 lines (11 loc) 347 B
var typeCheck = require('../deps/type'); module.exports = function type(attr, type) { return function(Model){ if ('string' !== typeof type) return; Model.validate(function(model){ var val = model.attrs[attr]; if(val !== undefined && typeCheck(val) !== type) model.error(attr, "should be a " + type); }); }; };