pipe-validation
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

Validation Pipe

If you are familiar with Nest JS, you know what validation pipes are. It's a way of validating requests using class decleration and decorators. This package is heavily influenced by Nestjs pipe validation. The aim is to make the validation module modular and useable in non-nestjs projects.

This package makes use of class-validator and its decorators for validation.

Usage

Here, we'll focus on real world use cases of the validation pipe.

Installation

    npm i validation-pipe

Basic Usage

    import { IsString, MaxLength, IsBoolean, IsOptional, validationPipe } from 'validation-pipe';

    class User {
        id: number;

        @IsString()
        firstName: string;

        @IsString()
        @MaxLength(4)
        lastName: string;

        @IsBoolean()
        @IsOptional()
        verified: boolean;
    }

    const fromPlainUser = {
        unkownProp: 'hello there',
        firstName: 'another one',
        lastName: 'Khudoiberdiev',
        verified: 'another one'
    };

    validationPipe(User, fromPlainUser, { pretty: false })
    .then((err) => {
        console.log(err);
  })

Package Sidebar

Install

npm i pipe-validation

Weekly Downloads

1

Version

1.0.4

License

ISC

Unpacked Size

55.5 kB

Total Files

14

Last publish

Collaborators

  • thesameeric