@eddaic/nestjs-decorators
Version:
Additional decorators intended for use with NestJS framework.
41 lines (40 loc) • 1.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isBigInt = isBigInt;
exports.IsBigInt = IsBigInt;
const class_validator_1 = require("class-validator");
const util_1 = require("../util");
/**
* Checks if the value is a bigint or can be converted to a bigint.
* @param value
* @returns
*/
function isBigInt(value) {
if (typeof value === 'bigint') {
return true;
}
else if ((0, class_validator_1.isNumber)(value, { maxDecimalPlaces: 0 })) {
return true;
}
else if ((0, class_validator_1.isString)(value) && (0, class_validator_1.isNumberString)(value)) {
return (0, util_1.tryBigInt)(`${value}`);
}
else {
return false;
}
}
/**
* Checks if the value is a bigint or can be converted to a bigint.
* @param options
* @returns
*/
function IsBigInt(options) {
return (0, class_validator_1.ValidateBy)({
name: 'isBigInt',
constraints: [options],
validator: {
validate: isBigInt,
defaultMessage: (0, class_validator_1.buildMessage)((_, args) => `${args?.property} property must be a BigInt`, options),
},
}, options);
}