@buka/class-transformer-extra
contains methods that's aren't included in the class-transformer
package.
Install
npm install @buka/class-transformer-extra class-transformer
# OR
yarn install @buka/class-transformer-extra class-transformer
# OR
pnpm install @buka/class-transformer-extra class-transformer
Usage
String
method | before transformer | after transformer |
---|
@Split(",") | "a,b,c" | ["a", "b", "c"] |
@Trim() | " abc " | "abc" |
@ToString() | 123 | "123" |
@ToLowerCase() | "ABC" | "abc" |
@ToUpperCase() | "abc" | "ABC" |
@Replace("-", "_") | "a-b-c" | "a_b_c" |
Date
method | before transformer | after transformer |
---|
@ToDate() | "2024-01-01" | new Date("2024-01-01") |
@FormatDate("YYYY/MM/DD") | "2024-01-01" | "2024/01/01" |
Number
method | before transformer | after transformer |
---|
@ToNumber() | "123" | 123 |
@ToBigInt() | "123" | 123n |
Boolean
method | before transformer | after transformer |
---|
@ToBoolean() | 1 | true |
Array
method | before transformer | after transformer |
---|
@Filter((num: number) => num > 3) | [1,2,3.4,5] | [4,5] |
@Flatten() | [1, [2, [3, 4, [5]]]] | [1,2,3,4,5] |
@Uniq() | [1,1,2,3,4,4,5] | [1,2,3,4,5] |
@UniqBy(Math.abs) | [-1, 1, 2, 3, -3] | [-1, 2, 3] |
Contribute
If you want to report bug or add new decorators, please submit an Issue or Pull Request.