1.0.13 • Published 3 years ago

nestjs-yup v1.0.13

Weekly downloads
11
License
ISC
Repository
-
Last release
3 years ago

Status


📝 Table of Contents

🧐 About

Integrate Yup with Nest.js.

🎥 Demo / Working

npm.io

🎈 Usage

In DTO file

  • Create your own yup schema.
  • Use the decorator UseSchema.
import { UseSchema } from 'nestjs-yup';

For example:

import * as yup from 'yup';
import { UseSchema } from 'nestjs-yup';

export const authSchema = yup.object({
  username: yup.string().required().min(4).max(20),
  password: yup
    .string()
    .required()
    .min(8)
    .max(20)
    .matches(
      /((?=.*\d)|(?=.*\W))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/,
      'password too weak',
    ),
});

@UseSchema(authSchema)
export class AuthCredentialsDto {
  username: string;

  password: string;
}

In Controller file

import { YupValidationPipe } from 'nestjs-yup';

For example:

 @Post('/signup')
  signUp(
    @Body(YupValidationPipe)
    authCredentialsDto: AuthCredentialsDto,
  ): Promise<void> {
    return this.authService.signUp(authCredentialsDto);
  }

Installing

npm i nestjs-yup

Don't forget to install yup as well.

npm i yup
npm i -D @types/yup

Quick Example

Please go to example folder.

npm run start:dev

or running via docker

docker-compose up

✍️ Authors

🎉 Acknowledgements

References

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago