UNPKG

class-validator-extended

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