UNPKG

class-validator-extended

Version:
36 lines (35 loc) 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SET_NOT_CONTAINS = void 0; exports.SetNotContains = SetNotContains; const class_validator_1 = require("class-validator"); const set_not_contains_predicate_1 = require("./set-not-contains.predicate"); /** @hidden */ exports.SET_NOT_CONTAINS = 'setNotContains'; /** * Checks if the given value is a [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) * which does not contain any of the forbidden values. * * #### Example * ```typescript * // Ensure the set does not contain the values 'foo' and 'bar'. * @SetNotContains(['foo', 'bar']) * values: Set<string> * ``` * * @category Set * @param forbidden The values forbidden in the given set. * @param options Generic class-validator options. * @typeParam Value The type of values to check for. */ function SetNotContains(forbidden, options) { return (0, class_validator_1.ValidateBy)({ name: exports.SET_NOT_CONTAINS, validator: { validate: (value, _arguments) => (0, set_not_contains_predicate_1.setNotContains)(value, forbidden), defaultMessage: (0, class_validator_1.buildMessage)(eachPrefix => `${eachPrefix}$property must not contain any of the following values: ${[ ...forbidden, ].join(', ')}`, options), }, }, options); }