UNPKG

class-validator-extended

Version:
34 lines (33 loc) 1.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MAX_BIGINT = void 0; exports.MaxBigInt = MaxBigInt; const class_validator_1 = require("class-validator"); const max_bigint_predicate_1 = require("./max-bigint.predicate"); /** @hidden */ exports.MAX_BIGINT = 'maxBigInt'; /** * Checks if the given value is a [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) * not greater than `maximum`. * * #### Example * ```typescript * // Ensure the value is less than 9000. * @MaxBigInt(8_999) * underNineThousand: BigInt * ``` * * @category BigInt * @param maximum The maximum allowed value. * @param options Generic class-validator options. */ function MaxBigInt(maximum, options) { return (0, class_validator_1.ValidateBy)({ name: exports.MAX_BIGINT, constraints: [maximum], validator: { validate: (value, _arguments) => (0, max_bigint_predicate_1.maxBigInt)(value, maximum), defaultMessage: (0, class_validator_1.buildMessage)(eachPrefix => `${eachPrefix}$property must not be larger than $constraint1`, options), }, }, options); }