UNPKG

fluent-ts-validator

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