1.2.26 • Published 2 weeks ago
custom-class-validator-tools
Licence
MIT
Version
1.2.26
Deps
4
Size
108 kB
Vulns
0
Weekly
0
String type decorator
| Decorator | Type | Description |
|---|---|---|
| @IsNullableString | string | null |
| @IsUndefinableString | string | undefined |
| @IsOptionalString | string | null |
| @IsNotEmptyNumberString | string | Checks a string is a number |
| @IsNotEmptyBooleanString | string | Checks a string is a boolean |
| @IsNullableNumberString | string | null |
| @IsNullableBooleanString | string | null |
| @IsUndefinableNumberString | string | undefined |
| @IsUndefinableBooleanString | string | undefined |
| @IsOptionalNumberString | string | null |
| @IsOptionalBooleanString | string | null |
Number type decorator
| Decorator | Type |
|---|---|
| @IsNotEmptyNumber | number |
| @IsNullableNumber | nubmer |
| @IsUndefinableNumber | number |
| @IsOptionalNumber | number |
Boolean type decorator
| Decorator | Type |
|---|---|
| @IsNotEmptyBoolean | boolean |
| @IsNullableBoolean | boolean |
| @IsUndefinalbeBoolean | boolean |
| @IsOptionalBoolean | boolean |
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;
}