Getting Started
The class-transformer
package is a zero-dependency utility library helping you to quickly transform class instances to plain objects and vice-versa. It works well with the class-validator
library. The main features include:
conditionally transforming object properties
excluding specific properties from the transformed object
exposing properties under a different name on the transformed object
supports both NodeJS and browsers
fully three-shakable
zero external dependencies
Installation
To start using class-transformer install the required packages via NPM:
Import the reflect-metadata
package at the first line of your application:
As the last step, you need to enable emitting decorator metadata in your Typescript config. Add these two lines to your tsconfig.json
file under the compilerOptions
key:
Now you are ready to use class-transformer with Typescript!
Basic Usage
The most basic usage is to transform a class to a plain object:
Last updated