este-library-oldschool
Version:
Library for github.com/steida/este.git
71 lines (65 loc) • 1.97 kB
JavaScript
// Generated by github.com/steida/coffee2closure 900.1.18
/**
@fileoverview Validate number or string number.
*/
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.Max');
goog.provide('este.validators.max');
goog.require('este.validators.Base');
goog.require('goog.math');
goog.require('goog.string');
/**
@param {number} max
@param {function(): string=} getMsg
@constructor
@extends {este.validators.Base}
*/
este.validators.Max = function(max1, getMsg) {
this.max = max1;
este.validators.Max.superClass_.constructor.call(this, getMsg);
}
extend(este.validators.Max, superClass);
/**
@type {number}
@protected
*/
este.validators.Max.prototype.max = 0;
/**
@override
*/
este.validators.Max.prototype.validate = function() {
var isStringOrNumber, ref, value;
isStringOrNumber = (ref = typeof this.value) === 'string' || ref === 'number';
goog.asserts.assert(isStringOrNumber, 'Expected string or number.');
value = this.value;
if (goog.isString(value)) {
value = goog.string.toNumber(value);
}
value = /** @type {number} */(value);
if (!goog.math.isFiniteNumber(value)) {
return false;
}
return value <= this.max;
};
/**
@override
*/
este.validators.Max.prototype.getMsg = function() {
/**
@desc Max validator message.
*/
return este.validators.Max.MSG_VALIDATOR_MAX = goog.getMsg('Please enter a value less than or equal to {$max}.', {
'max': this.max
});
};
/**
@param {number} max
@param {function(): string=} getMsg
@return {function(): este.validators.Max}
*/
este.validators.max = function(max, getMsg) {
return function() {
return new este.validators.Max(max, getMsg);
};
};