UNPKG

@szegedsw/lib-node

Version:

A little framework published by Szeged Software Zrt. in order to enhance api endpoint security and create reuseable code. Email module, Logging system, and much more. Further improvements are expected.

25 lines 945 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EnumValidator = void 0; const logger_1 = require("../logger/logger"); const validator_1 = require("./validator"); class EnumValidator extends validator_1.Validator { constructor(enumVar, isAllowEmpty = false) { const vals = Object.values(enumVar); if (vals.length > 0) { const str = `^(${vals .toString() .split(",") .concat(isAllowEmpty ? [""] : []) .join("|")})$`; logger_1.Logger.trace(`converted string from enum: ${str}`); const regexp = new RegExp(str); super(regexp, `Should be one of the following values: ${vals.toString()}`); } else { throw new Error("Invalid EnumValidator construction!"); } } } exports.EnumValidator = EnumValidator; //# sourceMappingURL=enum-validator.js.map