UNPKG

class-validator-extended

Version:
34 lines (33 loc) 1.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MAP_SIZE = void 0; exports.MapSize = MapSize; const class_validator_1 = require("class-validator"); const map_size_predicate_1 = require("./map-size.predicate"); /** @hidden */ exports.MAP_SIZE = 'mapSize'; /** * Checks if the given value is a [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) * with a size of exactly `size`. * * #### Example * ```typescript * // Ensure the map has exactly 5 entries. * @MapSize(5) * values: Map<string, string> * ``` * * @category Map * @param size The allowed size of the map. * @param options Generic class-validator options. */ function MapSize(size, options) { return (0, class_validator_1.ValidateBy)({ name: exports.MAP_SIZE, constraints: [size], validator: { validate: (value, _arguments) => (0, map_size_predicate_1.mapSize)(value, size), defaultMessage: (0, class_validator_1.buildMessage)(eachPrefix => `${eachPrefix}$property must contain exactly $constraint1 element(s)`, options), }, }, options); }