Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/felix-kaestner/decorator
TypeScript class decorators
https://github.com/felix-kaestner/decorator
typescript
Last synced: about 5 hours ago
JSON representation
TypeScript class decorators
- Host: GitHub
- URL: https://github.com/felix-kaestner/decorator
- Owner: felix-kaestner
- License: mit
- Created: 2022-01-15T14:59:39.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-05-02T00:29:15.000Z (7 months ago)
- Last Synced: 2024-05-02T06:12:42.468Z (7 months ago)
- Topics: typescript
- Language: TypeScript
- Homepage:
- Size: 2.16 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Decorator
## Install
Install with `npm` or `yarn`:
```
$ npm i git+https://github.com/felix-kaestner/decorator
``````
$ yarn add git+https://github.com/felix-kaestner/decorator
```## Usage
```TypeScript
import {sealed} from '@felix-kaestner/decorator'@sealed
class BugReport {
title: string;constructor(t: string) {
this.title = t
}
}
```## API
### @sealed
Apply [Object.seal](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal) on a class constructor and prototype with `@sealed`.
```TypeScript
import {sealed} from '@felix-kaestner/decorator'@sealed
class BugReport {
title: string;constructor(t: string) {
this.title = t
}
}
```### @immutable
Apply [Object.freeze](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze) on a class constructor and prototype with `@immutable`.
```TypeScript
import {immutable} from '@felix-kaestner/decorator'@immutable
class BugReport {
title: string;constructor(t: string) {
this.title = t
}
}
```### @final
Apply both [Object.seal](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal) and [Object.freeze](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze) on a class constructor and prototype with `@final`.
```TypeScript
import final from '@felix-kaestner/decorator'@final
class BugReport {
title: string;constructor(t: string) {
this.title = t
}
}
```This is equivalent to using both `@sealed` and `@immutable`.
## Contribute
All contributions in any form are welcome! 🙌
Just use the [Issue](.github/ISSUE_TEMPLATE) and [Pull Request](.github/PULL_REQUEST_TEMPLATE) templates and
I will be happy to review your suggestions. 👍---
Released under the [MIT License](LICENSE).