UNPKG

@eddaic/nestjs-decorators

Version:

Additional decorators intended for use with NestJS framework.

45 lines (44 loc) 1.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.transformBigInt = transformBigInt; exports.TransformBigInt = TransformBigInt; const class_transformer_1 = require("class-transformer"); const class_validator_1 = require("class-validator"); const util_1 = require("../util"); const validator_1 = require("../validator"); function transformBigInt(value, options) { if (typeof value === 'bigint') { return value; } if ((0, validator_1.isBigInt)(value)) { if (typeof value === 'bigint') { return value; } else if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') { return BigInt(value); } else { return null; } } else if (options?.rounding !== undefined && (0, class_validator_1.isNumber)(value)) { return BigInt((0, util_1.round)(value, options.rounding)); } else { return null; } } /** * Transform value into bigint using specified options. If the value * cannot be converted into bigint, null is returned. * * Otherwise a the value will be returned rounded as necessary * using the specified rounding policy. * @param options {@link TransformIntOptions} * @returns */ function TransformBigInt(options) { return (0, class_transformer_1.Transform)(({ value }) => transformBigInt(value, options), options); }