custom-class-validator-tools
v1.1.36
Published
Downloads
1,301
Readme
String type decorator
| Decorator | Type | Description| | --- | --- | --- | | @IsNullableString | string | null | If want to ignore value ≠= ‘’, @IsNullableString({ blank: true }) | | @IsUndefinableString | string | undefined | If want to ignore value ≠= ‘’, @IsUndefinableString({ blank: true }) | | @IsOptionalString | string | null | undefined | If want to ignore value ≠= ‘’, @IsOptionalString({ blank: true }) | | @IsNotEmptyNumberString | string | Checks a string is a number | | @IsNotEmptyBooleanString | string | Checks a string is a boolean | | @IsNullableNumberString | string | null | Checks a string is a number or null | | @IsNullableBooleanString | string | null | Checks a string is a boolean or null | | @IsUndefinableNumberString | string | undefined | Checks a string is a number or undefined | | @IsUndefinableBooleanString | string | undefined | Checks a string is a boolean or null | | @IsOptionalNumberString | string | null | undefined | Checks a string is a number or null or undefined | | @IsOptionalBooleanString | string | null | undefined | Checks a string is a boolean or null or undefined |
Number type decorator
| Decorator | Type | |----------------------|--------| | @IsNotEmptyNumber | number | | @IsNullableNumber | nubmer | null | | @IsUndefinableNumber | number | undefined | | @IsOptionalNumber | number | null | undefined | | | |
Boolean type decorator
| Decorator | Type | | --- | --- | | @IsNotEmptyBoolean | boolean | | @IsNullableBoolean | boolean | null | | @IsUndefinalbeBoolean | boolean | undefined | | @IsOptionalBoolean | boolean | null | undefined |
ValidateNested usage case
import { isNotEmptyString, IsNotEmptyBoolean, isNullable, IsUndefinable } from 'custom-class-validator-tools';
import { IsInstance, ArrayNotEmpty, ValidateNested } from 'class-validator';
import { Type } from 'class-transformer';
class Tag {
@IsNotEmptyString()
tag1: string;
@IsNotEmptyString()
tag2: string;
}
class Result {
@IsNotEmptyBoolean()
failed: boolean;
}
class Post {
@IsNullable()
@ArrayNotEmpty()
@IsInstance(Tag, { each: true })
@ValidateNested({ each: true })
@Type(() => Tag)
tags: Tag[] | null;
@IsUndefinable()
@IsInstance(Result)
@ValidateNested()
@Type(() => Result)
result?: Result;
}