UNPKG

ts-api-core

Version:

Nodejs api framework core

39 lines 1.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LengthValidator = void 0; /* eslint-disable @typescript-eslint/restrict-plus-operands */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ const abstract_validator_1 = require("../abstract.validator"); /** * 字符串长度校验 * @param lengthMin * @param lengthMax * @param message */ class LengthValidator extends abstract_validator_1.AbstractValidator { constructor(lengthMin = 0, lengthMax = 50, message) { super(); this.lengthMin = 0; this.lengthMax = 50; this.lengthMin = lengthMin; this.lengthMax = lengthMax; this.setDefaultMessage(message !== null && message !== void 0 ? message : ""); } valid(param) { if (typeof param === "string") { this.convertMessage("参数长度不合法,期望长度范围:" + this.lengthMin + "-" + this.lengthMax + ",实际长度:" + param.length); return param.length >= this.lengthMin && param.length <= this.lengthMax; } else { this.convertMessage("参数类型不合法,无法获取长度"); return false; } } } exports.LengthValidator = LengthValidator; //# sourceMappingURL=length.validator.js.map