> For the complete documentation index, see [llms.txt](https://angular-ru.gitbook.io/sdk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://angular-ru.gitbook.io/sdk/cdk/class-transformer.md).

# @angular-ru/cdk/class-transformer

```typescript
import {
  ONLY_TO_CLASS,
  transformAsPrepareFieldsFromClass,
  transformParseFloat,
  transformParseInt,
  transformToBoolean,
  transformToClass,
  transformToFormatDateTime,
  transformToNullableBoolean,
  transformToNumber,
  transformToPrettyFormat,
  transformToStringVal,
  transformToTrim,
  transformToUnix,
  transformDateToFormat,
} from '@angular-ru/cdk/class-transformer';

describe('[TEST]: Integration with class-transformer', () => {
  @Exclude()
  class IsoDto {
    @Expose() @Transform(transformToNumber, ONLY_TO_CLASS) public a?: string;
    @Expose() @Transform(transformToNumber, ONLY_TO_CLASS) public b?: string;
  }

  @Exclude()
  class DemoDto {
    @Expose() @Transform(transformToFormatDateTime, ONLY_TO_CLASS) public startDate?: number;
    @Expose() @Transform(transformToUnix, ONLY_TO_CLASS) public endDate?: string;
    @Expose() @Transform(transformToTrim, ONLY_TO_CLASS) public comment?: string;
    @Expose() @Transform(transformToPrettyFormat, ONLY_TO_CLASS) public lastChanged?: number;
    @Expose() @Transform(transformToStringVal, ONLY_TO_CLASS) public enabled?: boolean;
    @Expose() @Transform(transformParseFloat, ONLY_TO_CLASS) public floatVal?: number;
    @Expose() @Transform(transformParseInt, ONLY_TO_CLASS) public intVal?: number;
    @Expose() @Transform(transformToNumber, ONLY_TO_CLASS) public numVal?: string;
    @Expose() @Transform(transformToBoolean, ONLY_TO_CLASS) public checked?: boolean;
    @Expose() @Transform(transformToNullableBoolean, ONLY_TO_CLASS) public checkedNullable?: Nullable<boolean>;

    @Expose()
    @Type(transformToClass(IsoDto))
    @Transform(transformAsPrepareFieldsFromClass(IsoDto), ONLY_TO_CLASS)
    public iso?: IsoDto;

    @Expose()
    @Transform(transformDateToFormat({format: 'dd.MM.yyyy', timezone: 'GMT+03:00'}), ONLY_TO_CLASS)
    public dateCustomFormatWithTimezone?: number;
    @Expose()
    @Transform(transformDateToFormat({format: 'dd.MM.yyyy HH:mm', timezone: 'GMT+06:00'}), ONLY_TO_CLASS)
    public datetimeCustomFormatWithTimezone?: number;
    @Expose()
    @Transform(transformDateToFormat({format: 'dd.MM.yyyy'}), ONLY_TO_CLASS)
    public dateCustomFormatWithoutTimezone?: number;
    @Expose() @Transform(transformDateToFormat(), ONLY_TO_CLASS) public dateCustomFormatEmptyOptions?: number;
  }

  it('should be correct use @Transform', () => {
    expect(
      plainToClass(DemoDto, {
        startDate: 757803600000,
        endDate: '01.06.1994',
        comment: '   Hello World   ',
        lastChanged: 757803600000,
        enabled: false,
        floatVal: 123.25,
        intVal: 11.5,
        numVal: '1234',
        iso: {
          a: ' 2 ',
          b: ' 3 ',
          c: false,
        },
        checked: undefined,
        checkedNullable: undefined,
        dateCustomFormatWithTimezone: 1622657925000,
        datetimeCustomFormatWithTimezone: 1622657925000,
        dateCustomFormatWithoutTimezone: 1622657925000,
        dateCustomFormatEmptyOptions: 1622657925000,
      } as DemoDto),
    ).toEqual({
      startDate: '06.01.1994 00:00:00',
      endDate: 757803600000,
      comment: 'Hello World',
      lastChanged: '06.01.1994 00:00:00',
      enabled: 'false',
      floatVal: 123.25,
      intVal: 11,
      numVal: 1234,
      iso: {a: 2, b: 3},
      checked: false,
      checkedNullable: null,
      dateCustomFormatWithTimezone: '02.06.2021',
      datetimeCustomFormatWithTimezone: '03.06.2021 00:18',
      dateCustomFormatWithoutTimezone: expect.any(String),
      dateCustomFormatEmptyOptions: expect.any(String),
    });
  });

  it('should be invalid transform to number as NaN', (): void => {
    const actual: DemoDto = new DemoDto();
    actual.numVal = 'INVALID NUMBER';
    expect(actual.numVal).toEqual('INVALID NUMBER');
    expect(plainToClass(DemoDto, actual).numVal).toEqual(NaN);
  });

  it('should be correct transform to number', (): void => {
    const actual: DemoDto = new DemoDto();
    actual.numVal = ' 100 ';
    expect(actual.numVal).toEqual(' 100 ');
    expect(plainToClass(DemoDto, actual).numVal).toEqual(100);
  });
});
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://angular-ru.gitbook.io/sdk/cdk/class-transformer.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
