UNPKG

class-validator-extended

Version:
27 lines (26 loc) 909 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Nullable = Nullable; const class_validator_1 = require("class-validator"); /** * Only validates the given value if it is not `null`. * * This is similar to the built-in `@IsOptional` except that it does not allow `undefined`. Note that this validator * does not work as expected with `{ each: true }` (because it is based on `@ValidateIf` which does not either). * * #### Example * ```typescript * // Ensure the value is a string or null (but not undefined). * @Nullable() * @IsString() * value: string | null * ``` * * @category Common * @param options Generic class-validator options. */ function Nullable(options) { return function nullableDecorator(prototype, propertyKey) { (0, class_validator_1.ValidateIf)(object => object[propertyKey] !== null, options)(prototype, propertyKey); }; }