Skip to content

nestjs-class-transformers 1.1.0

Install from the command line:
Learn more about npm packages
$ npm install @algoan/nestjs-class-transformers@1.1.0
Install via package.json:
"@algoan/nestjs-class-transformers": "1.1.0"

About this version

Nestjs class transformers

Extends class-transformers package with additional features.

Installation

npm install --save @algoan/nestjs-class-transformers

EnumFallback

Usage

import { EnumFallback } from '@algoan/nestjs-class-transformers';

export enum UserRole {
  ADMIN = 'ADMIN',
  READER = 'READER',
}

class User {
  @EnumFallback({
    type: UserRole,
    fallback: (value: UserRole) => UserRole.READER // if the role is not "ADMIN" or "READER", then the role will be "READER".
  })
  public role?: UserRole;
}

It works with array too:

import { EnumFallback } from '@algoan/nestjs-class-transformers';

export enum UserRole {
  ADMIN = 'ADMIN',
  READER = 'READER',
}

class User {
  @EnumFallback({
    type: UserRole,
    fallback: (value: UserRole) => UserRole.READER // if an array element is not "ADMIN" or "READER", then the role will be "READER".
  })
  public roles: UserRole[];
}

Details


Assets

  • nestjs-class-transformers-1.1.0.tgz

Download activity

  • Total downloads 3,376
  • Last 30 days 161
  • Last week 41
  • Today 0

Recent versions

View all