🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

@betsys-nestjs/decorators

Package Overview
Dependencies
Maintainers
9
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@betsys-nestjs/decorators

This library is a collection of various decorators using class-validator.

latest
npmnpm
Version
2.0.0
Version published
Weekly downloads
1
-98.04%
Maintainers
9
Weekly downloads
 
Created
Source

@betsys-nestjs/decorators

This is a simple library containing decorators helping you to validate types of properites

Dependencies

PackageVersion
@nestjs/common^10.0.0
class-validator^0.13.2

Usage

The basic usage is similar to the class-validator. Use decorators in your DTOs or commands.

An example of usage - imagine a DTO as following:

export class SomeNiceDto {
    booleanProperty!: boolean;
    intProperty!: number;
};

Which you want to use in the following controller while it is automatically converted from the request:

import { Body, Controller, Post, Req } from '@nestjs/common';
import { Request } from 'express';

@Controller()
export class SomeController {
    @Post('/some-url')
    saveKittens(@Req() request: Request, @Body() body: SomeNiceDto) {
        ...
    }
}

For the DTO you want to be sure, that booleanProperty is of type boolan as well as that intProperty is really an integer.

You can easily enforce that by using the decorators from this lib:

import { IsFieldBoolean, IsFieldInteger, Language } from '@betsys-nestjs/decorators';

export class SomeNiceDto {
    @IsFieldBoolean('booleanProperty', Language.PL)
    booleanProperty!: boolean;

    @IsFieldInteger('intProperty', Language.EN)
    intProperty!: number;
};

The language settings concern the error message. If you do not provide any language, English is returned.

FAQs

Package last updated on 09 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts