@react-input-validator/rules
Version:
The validation rule objects used by the packages: `@react-input-validator/core`, `@react-input-validator/native` and `@react-input-validator/web`
37 lines (36 loc) • 1.26 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.min = exports.Min = void 0;
const messages_1 = __importDefault(require("./messages"));
const ValidationRule_1 = __importDefault(require("./ValidationRule"));
class Min extends ValidationRule_1.default {
constructor(min) {
super();
this.min = min;
this.setPriority(2);
}
get errorMessage() {
return this.lang(messages_1.default.min);
}
validate() {
const min = typeof (this.min) == 'function' ? this.min() : this.min;
let valType = typeof this.value, limitType = typeof min;
if (valType == 'bigint')
valType = 'number';
if (limitType == 'bigint')
limitType = 'number';
if (limitType == valType && (valType == 'number' ||
valType == 'string' ||
(this.value instanceof Date && min instanceof Date)))
this.isValid = this.value >= min;
else
this.isValid = false;
return this;
}
}
exports.Min = Min;
const min = (minVal) => new Min(minVal);
exports.min = min;