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