将这个 dto 实例再次通过 class-transformer 包的 classToPlain 函数将 dto 实例转化成普通对象 controller 方法收到相应参数 当然了,这是nestjs借助了ValidationPipe使用class-validator和calss-transformer,我们也可以自定义pipe来使用这两个包。 以上便是nestjs中如何使用class-validator和class-transformer,希望对你有...
import{IsEmail}from"class-validator";import{transformAndValidate}from"class-transformer-validator";// declare the class using class-validator decoratorsclassUser{@IsEmail()publicemail:string;publichello():string{return"World!";}}// then load the JSON string from any part of your appconstuserJson...
About DTO decorators with class-transformer and class-validator. Resources Readme License MIT license Activity Custom properties Stars 0 stars Watchers 2 watching Forks 2 forks Report repository Releases 8 tags Packages No packages published Languages TypeScript 95.5% JavaScript 4.5% ...
A simple wrapper around class-transformer and class-validator which provides nice and programmer-friendly API.. Latest version: 0.9.1, last published: 5 years ago. Start using class-transformer-validator in your project by running `npm i class-transforme
Description When we combine class-validator and class-transformer an error occurs when we try to validate a property (numberString in this case) and then transform it into a number, this happens no matter what order the decorators are. M...
import {f, PropertyValidatorError} from '@marcj/marshal'; class Entity { @f.validator((value: any) => { if (value.length > 10) { return new PropertyValidatorError('too_long', 'Too long :()'); } }) name: string; } Partial serialization Most of the time, you want to have full...