UNPKG

@decaf-ts/decorator-validation

Version:
56 lines 2.18 kB
"use strict"; 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); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.StepValidator = void 0; const Validator_1 = require("./Validator.cjs"); const constants_1 = require("./constants.cjs"); const decorators_1 = require("./decorators.cjs"); /** * @summary Step Validator * * @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#STEP} * * @class StepValidator * @extends Validator * * @category Validators */ let StepValidator = class StepValidator extends Validator_1.Validator { constructor(message = constants_1.DEFAULT_ERROR_MESSAGES.STEP) { super(message, "number", "string"); } /** * @summary Validates a model * * @param {string} value * @param {number} step * @param {StepValidatorOptions} options * * @return {string | undefined} * * @override * * @see Validator#hasErrors */ hasErrors(value, options) { if (typeof value === "undefined") return; return Number(value) % Number(options.step) !== 0 ? this.getMessage(options.message || this.message, options.step) : undefined; } }; exports.StepValidator = StepValidator; exports.StepValidator = StepValidator = __decorate([ (0, decorators_1.validator)(constants_1.ValidationKeys.STEP), __metadata("design:paramtypes", [String]) ], StepValidator); //# sourceMappingURL=StepValidator.js.map