este-library-oldschool
Version:
Library for github.com/steida/este.git
72 lines (65 loc) • 2 kB
JavaScript
// Generated by github.com/steida/coffee2closure 900.1.18
/**
@fileoverview Validate string length range.
*/
var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.superClass_ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
goog.provide('este.validators.RangeLength');
goog.provide('este.validators.rangeLength');
goog.require('este.validators.Base');
goog.require('este.validators.min');
goog.require('este.validators.max');
/**
@param {number} min
@param {number} max
@param {function(): string=} getMsg
@constructor
@extends {este.validators.Base}
*/
este.validators.RangeLength = function(min1, max1, getMsg) {
this.min = min1;
this.max = max1;
este.validators.RangeLength.superClass_.constructor.call(this, getMsg);
}
extend(este.validators.RangeLength, superClass);
/**
@type {number}
@protected
*/
este.validators.RangeLength.prototype.min = 0;
/**
@type {number}
@protected
*/
este.validators.RangeLength.prototype.max = 0;
/**
@override
*/
este.validators.RangeLength.prototype.validate = function() {
var ref;
goog.asserts.assertString(this.value);
return (this.min <= (ref = this.value.length) && ref <= this.max);
};
/**
@override
*/
este.validators.RangeLength.prototype.getMsg = function() {
/**
@desc RangeLength validator message.
*/
return este.validators.RangeLength.MSG_VALIDATOR_RANGE_LENGTH = goog.getMsg('Please enter a value between {$min} and {$max} characters long.', {
'min': this.min,
'max': this.max
});
};
/**
@param {number} min
@param {number} max
@param {function(): string=} getMsg
@return {function(): este.validators.RangeLength}
*/
este.validators.rangeLength = function(min, max, getMsg) {
return function() {
return new este.validators.RangeLength(min, max, getMsg);
};
};