
Security News
ESLint Adds Official Support for Linting HTML
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
transform-class-properties
Advanced tools
Automatically transforms values of class properties.
Automatically transforms values of class properties.
TypeScript >= 1.5
Enable the experimentalDecorators in tsconfig.json
.
Note: ES5 is min target minimun to build.
npm install transform-class-properties --save
or
yarn add transform-class-properties
import {
Float,
RemoveNonNumeric,
ToUpperCase,
transform,
Trim
} from 'transform-class-properties';
class Book {
@ToUpperCase()
@Trim()
public title: string;
@Float(2)
public price: number;
@RemoveNonNumeric()
public issn: string;
}
const book1 = new Book();
book1.title = ' My first book ';
book1.price = 12.3210;
book1.issn = '1234-5679'
console.log(transform(book1)); // Book { title: 'MY FIRST BOOK', price: 12.32, issn: '12345679' }
Decorator | Description | Class property type |
---|---|---|
@Append(additionalValue: string | number) | Adds value at the end. | string |
@Capitalize() | Capitalize the first letter and lowercase the rest. | string |
@Float(fractionDigits?: number) | Converts number to float. | number |
@Integer() | Converts number to integer. | number |
@Prepend(additionalValue: string | number) | Adds value at the beginning. | string |
@Regex(expression: RegExp) | Returns matched value with regular expression. | string |
@RemoveNonNumeric() | Removes anything non-numeric character. | string |
@RemoveNumeric() | Removes numeric characters. | string |
@Replace(searchValue: string | RegExp, replaceValue: string) | Find and replace value. | string |
@ToLowerCase() | Lower case characters. | string |
@ToUpperCase() | Upper case characters. | string |
@Trim() | Trim characters. | string |
FAQs
Automatically transforms values of class properties.
The npm package transform-class-properties receives a total of 38,347 weekly downloads. As such, transform-class-properties popularity was classified as popular.
We found that transform-class-properties demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.