UNPKG

@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
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.max = exports.Max = void 0; const messages_1 = __importDefault(require("./messages")); const ValidationRule_1 = __importDefault(require("./ValidationRule")); class Max extends ValidationRule_1.default { constructor(max) { super(); this.max = max; this.setPriority(2); } get errorMessage() { return this.lang(messages_1.default.max); } validate() { const max = typeof (this.max) == 'function' ? this.max() : this.max; let valType = typeof this.value, limitType = typeof max; if (valType == 'bigint') valType = 'number'; if (limitType == 'bigint') limitType = 'number'; if (limitType == valType && (valType == 'number' || valType == 'string' || (this.value instanceof Date && max instanceof Date))) this.isValid = this.value <= max; else this.isValid = false; return this; } } exports.Max = Max; const max = (maxVal) => new Max(maxVal); exports.max = max;