class-validator-extended
Version:
Additional validators for class-validator.
34 lines (33 loc) • 1.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SET_MAX_SIZE = void 0;
exports.SetMaxSize = SetMaxSize;
const class_validator_1 = require("class-validator");
const set_max_size_predicate_1 = require("./set-max-size.predicate");
/** @hidden */
exports.SET_MAX_SIZE = 'setMaxSize';
/**
* Checks if the given value is a [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
* with a size less than or equal to `maximum`.
*
* #### Example
* ```typescript
* // Ensure the set has at most 5 entries.
* @SetMaxSize(5)
* values: Set<string>
* ```
*
* @category Set
* @param maximum The maximum allowed size of the set.
* @param options Generic class-validator options.
*/
function SetMaxSize(maximum, options) {
return (0, class_validator_1.ValidateBy)({
name: exports.SET_MAX_SIZE,
constraints: [maximum],
validator: {
validate: (value, _arguments) => (0, set_max_size_predicate_1.setMaxSize)(value, maximum),
defaultMessage: (0, class_validator_1.buildMessage)(eachPrefix => `${eachPrefix}$property must contain not more than $constraint1 elements`, options),
},
}, options);
}