npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@buka/class-transformer-extra

v2.1.4

Published

class-transformer-extra contains methods that's aren't included in the class-transform package.

Downloads

73,541

Readme

@buka/class-transformer-extra

version downloads dependencies license Codecov

@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({ optional: true }) | 123 | "123" | | @ToLowerCase() | "ABC" | "abc" | | @ToUpperCase() | "abc" | "ABC" | | @Replace("-", "_") | "a-b-c" | "a_b_c" |

@Split, @Trim, @ToLowerCase, @ToUpperCase and @Replace will do nothing if the value isn't string. When set optional: true, undefined will not be transformed.

Date

| method | before transformer | after transformer | | :---------------------------------------------- | :----------------- | :----------------------- | | @ToDate({ optional: true }) | "2024-01-01" | new Date("2024-01-01") | | @FormatDate("YYYY/MM/DD", { optional: true }) | "2024-01-01" | "2024/01/01" |

Number

| method | before transformer | after transformer | | :------------------------------ | :----------------- | :---------------- | | @ToNumber({ optional: true }) | "123" | 123 | | @ToBigInt({ optional: true }) | "123" | 123n |

ToNumber() and @ToBigInt() will return NaN if the value isn't number

Boolean

| method | before transformer | after transformer | | :------------- | :----------------- | :---------------- | | @ToBoolean() | 1 | true |

ToBoolean() has multiple parameters to adapt to different needs, examples:

ToBoolean(v => Boolean(v)), { optional: true }): If the value is undefined, do nothing. Otherwise, v => Boolean(v) will be used to transform value.

ToBoolean(['0', 'false', false], { optional: true }):

If the value is '0' or 'false' or false, transform to false, and if the value is undefined, do nothing, otherwise value will be transform to 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] |

@Filter, @Flatten, @Uniq and @UniqBy will do nothing if the value isn't array.

Contribute

If you want to report bug or add new decorators, please submit an Issue or Pull Request.

Q&A

  1. Why can't it be used with the @IsOptional decorator?

    The latest version of class-validator@^0.14.1 is not set metadata that can identify @IsOptional. If the identifiers are added in later versions, I will also follow up. And the identifier had be add in develop branch of class-validator.