# decoratory

> Utility decorators for TypeScript.

Latest version **0.2.0** (published 2021-12-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install decoratory
pnpm add decoratory
yarn add decoratory
bun add decoratory
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2021-12-27 |
| First published | 2021-12-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | H1ghBre4k3r |
| Maintainers | h1ghbre4k3r |
| Keywords | typescript, decorators |

## Links

- npm: https://www.npmjs.com/package/decoratory
- Repository: https://github.com/H1ghBre4k3r/decoratory
- Homepage: https://github.com/H1ghBre4k3r/decoratory#readme
- Issues: https://github.com/H1ghBre4k3r/decoratory/issues
- npm.io page: https://npm.io/package/decoratory

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.2.0 (latest) — 2021-12-27
- 0.1.0 — 2021-12-26

## README

# Decoratory

Simple and easy to use utility decorators for TypeScript projects. Many decorators are inspired by decorators from other languages (e.g., Java).

## Installation

```sh
$ npm i decoratory
```

## Usage

This package provides several decorators for usage in your TypeScript projects:

### Deprecated

If you want to mark a method as deprecated, u can annotate it with `@Deprecated`

```ts
import { Deprecated } from "decoratory";

class MyClass {
    @Deprecated
    public deprecatedMethod() {
        // ...
    }
}

new MyClass().deprecatedMethod(); // This will print a deprecation warning to the console
```

If you want to provide your own deprecation message, you can do that by using `@Deprecated` with an extra argument:

```ts
import { Deprecated } from "decoratory";

class MyClass {
    @Deprecated("Custom Message")
    public deprecatedMethod() {
        // ...
    }
}

new MyClass().deprecatedMethod(); // This will print "Custom Message" to the console
```

### Readonly

If you want to ensure, that a property can only be assigned _once_, you can use the `@Readonly` decorator:

```ts
import { Readonly } from "decoratory";

class MyClass {
    @Readonly
    public foo = 24;

    public myFunction() {
        this.foo = 1337;
    }
}

new MyClass().myFunction(); // This will throw a TypeError, since `MyClass.foo` cannot be reassigned
```

### Observe

You can observe all changes (re-assignments) to a property by using the `@Observe` decorator:

```ts
import { Observe } from "decoratory";

class MyClass {
    @Observe
    public foo = 42;
}
```

Now, all changes to `MyClass.foo` will be logged to the console. To perform certain actions on reassignment, you can provide a custom callback to the decorator, which will get called with the new value upon each reassignment:

```ts
import { Observe } from "decoratory";

function observeCallback(newValue: unknown) {
    console.log(`setting value to ${newValue}`);
}

class MyClass {
    @Observe(observeCallback)
    public foo = 42;
}
```

---
_Source: https://npm.io/package/decoratory · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
