UNPKG

@incdevco/framework

Version:
47 lines (24 loc) 779 B
var Promise = require('bluebird'); function LengthValidator(config) { 'use strict'; this.maximum = config.maximum; this.minimum = config.minimum; } LengthValidator.prototype.validate = function (input, context) { 'use strict'; var self = this; return Promise.try(function () { if (self.maximum) { if (input.length > self.maximum) { throw new Error('Must be less than ' + self.maximum + ' characters long.'); } } if (self.minimum) { if (input.length < self.minimum) { throw new Error('Must be at least ' + self.minimum + ' characters long.'); } } return true; }) }; module.exports = LengthValidator;