Tiny wrapper around superstruct for using in decorator way
import"reflect-metadata";import{bind,validate,string,number,size}from'@mrhitman/validator';classTest{
@bind(size(string(),4,20))// should be only one decorator that combine foo: string;
@bind(number())// should be only one decorator that combine foo: number;}consttest=newTest();test.bar=3;console.log(validate(test));[StructError: Atpath: foo--Expectedastring,butreceived: undefinedatModule._compile(node:internal/modules/cjs/loader:1101:14)atFunction.Module._load(node:internal/modules/cjs/loader:822:12)atFunction.executeUserEntryPoint[asrunMain](node:internal/modules/run_main:79:12){value: undefined,key: 'foo',type: 'string',refinement: undefined,path: ['foo'],branch: [Test{},undefined],failures: [Function(anonymous)]},undefined]
with nestjs > 10 version
import{bind,validate,string,number,size,ValidationPipe}from'@mrhitman/validator';classTest{
@bind(size(string(),4,20))// should be only one decorator that combine foo: string;
@bind(number())// should be only one decorator that combine foo: number;}
@Controller('example')exportclassExampleController{
@Post()
@UsePipes(newValidationPipe())create(@Body()dto: Test){// Your controller logic here}}