UNPKG

fluent-ts-validator

Version:
37 lines 997 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const IsIterable_1 = require("../../shared/IsIterable"); /** * Validates if given value is in a collection of allowed values or in an object/enum. * * @export * @class IsInValidator * @implements {PropertyValidator<T>} * @template T */ class IsInValidator { constructor(obj) { this.obj = obj; } isValid(input) { if (IsIterable_1.isIterable(this.obj)) { return this.isElementOfIterable(input); } else { return this.isValueInObject(input); } } isElementOfIterable(input) { for (let element of this.obj) { if (element === input) { return true; } } return false; } isValueInObject(input) { return Object.keys(this.obj).find(key => this.obj[key] === input) != null; } } exports.IsInValidator = IsInValidator; //# sourceMappingURL=IsInValidator.js.map