UNPKG

@decaf-ts/decorator-validation

Version:
54 lines 2.19 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; import { Validator } from "./Validator.js"; import { DEFAULT_ERROR_MESSAGES, ValidationKeys } from "./constants.js"; import { validator } from "./decorators.js"; import { valueLength } from "./utils.js"; /** * @summary Minimum Length Validator * @description Validates strings and Arrays on their minimum length * * @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#MIN_LENGTH} * * @class MinLengthValidator * @extends Validator * * @category Validators */ let MinLengthValidator = class MinLengthValidator extends Validator { constructor(message = DEFAULT_ERROR_MESSAGES.MIN_LENGTH) { super(message, String.name, Array.name, Set.name, Map.name); } /** * * @param {string | Array} value * @param {MinLengthValidatorOptions} options * * @return {string | undefined} * * @memberOf module:decorator-validation * @override * * @see Validator#hasErrors */ hasErrors(value, options) { if (typeof value === "undefined") return; return valueLength(value) < options.minlength ? this.getMessage(options.message || this.message, options.minlength) : undefined; } }; MinLengthValidator = __decorate([ validator(ValidationKeys.MIN_LENGTH), __metadata("design:paramtypes", [String]) ], MinLengthValidator); export { MinLengthValidator }; //# sourceMappingURL=MinLengthValidator.js.map