UNPKG

class-validator-extended

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