UNPKG

968 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.IsEnum = exports.isEnum = exports.IS_ENUM = void 0;
4const ValidateBy_1 = require("../common/ValidateBy");
5exports.IS_ENUM = 'isEnum';
6/**
7 * Checks if a given value is an enum
8 */
9function isEnum(value, entity) {
10 const enumValues = Object.keys(entity).map(k => entity[k]);
11 return enumValues.indexOf(value) >= 0;
12}
13exports.isEnum = isEnum;
14/**
15 * Checks if a given value is an enum
16 */
17function IsEnum(entity, validationOptions) {
18 return (0, ValidateBy_1.ValidateBy)({
19 name: exports.IS_ENUM,
20 constraints: [entity],
21 validator: {
22 validate: (value, args) => isEnum(value, args.constraints[0]),
23 defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be a valid enum value', validationOptions),
24 },
25 }, validationOptions);
26}
27exports.IsEnum = IsEnum;
28//# sourceMappingURL=IsEnum.js.map
\No newline at end of file