UNPKG

class-validator-extended

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