> 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
