class-validator-extended
Version:
Additional validators for class-validator.
32 lines (31 loc) • 1.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NEGATIVE_BIGINT = void 0;
exports.NegativeBigInt = NegativeBigInt;
const class_validator_1 = require("class-validator");
const negative_bigint_predicate_1 = require("./negative-bigint.predicate");
/** @hidden */
exports.NEGATIVE_BIGINT = 'negativeBigInt';
/**
* Checks if the given value is a [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt)
* less than zero.
*
* #### Example
* ```typescript
* // Ensure the value is less than 0.
* @NegativeBigInt()
* negativeNumber: BigInt
* ```
*
* @category BigInt
* @param options Generic class-validator options.
*/
function NegativeBigInt(options) {
return (0, class_validator_1.ValidateBy)({
name: exports.NEGATIVE_BIGINT,
validator: {
validate: (value, _arguments) => (0, negative_bigint_predicate_1.negativeBigInt)(value),
defaultMessage: (0, class_validator_1.buildMessage)(eachPrefix => `${eachPrefix}$property must be a negative BigInt`, options),
},
}, options);
}