este-library-oldschool
Version:
Library for github.com/steida/este.git
71 lines (65 loc) • 1.98 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.Min');
goog.provide('este.validators.min');
goog.require('este.validators.Base');
goog.require('goog.math');
goog.require('goog.string');
/**
@param {number} min
@param {function(): string=} getMsg
@constructor
@extends {este.validators.Base}
*/
este.validators.Min = function(min1, getMsg) {
this.min = min1;
este.validators.Min.superClass_.constructor.call(this, getMsg);
}
extend(este.validators.Min, superClass);
/**
@type {number}
@protected
*/
este.validators.Min.prototype.min = 0;
/**
@override
*/
este.validators.Min.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.min;
};
/**
@override
*/
este.validators.Min.prototype.getMsg = function() {
/**
@desc Min validator message.
*/
return este.validators.Min.MSG_VALIDATOR_MIN = goog.getMsg('Please enter a value greater than or equal to {$min}.', {
'min': this.min
});
};
/**
@param {number} min
@param {function(): string=} getMsg
@return {function(): este.validators.Min}
*/
este.validators.min = function(min, getMsg) {
return function() {
return new este.validators.Min(min, getMsg);
};
};