# sprang-decorators

> Various typescript decorators

Latest version **1.0.1** (published 2018-12-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install sprang-decorators
pnpm add sprang-decorators
yarn add sprang-decorators
bun add sprang-decorators
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2018-12-12 |
| First published | 2018-12-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 54.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Aymeric Trotignon |
| Maintainers | astrok8 |
| Keywords | angular, decorators |

## Links

- npm: https://www.npmjs.com/package/sprang-decorators
- Repository: https://github.com/astroK8/sprang-decorators
- Homepage: https://github.com/astroK8/sprang-decorators#readme
- Issues: https://github.com/astroK8/sprang-decorators/issues
- npm.io page: https://npm.io/package/sprang-decorators

## Dependencies (3)

- [lodash](https://npm.io/package/lodash.md) ^4.17.11
- [es6-shim](https://npm.io/package/es6-shim.md) ^0.35.4
- [sprang-styled-console](https://npm.io/package/sprang-styled-console.md) ^1.0.0

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2018-12-12
- 1.0.0 — 2018-12-12

## README

sprang-decorators
==================

Various typescript decorators

# @Autobind

## Class decorator

```typescript
import { Autobind } from './../decorators-module';

@Autobind
export class X {

    private _myVar;

    constructor() {}

    public method1() {
        this._myVar;
    }

    public method2(v:any) {
        this._myVar=v;
    }

}
```

When method1 or method2 are called "this" will always refer to X class instance.

## Method decorator

```typescript
import { Autobind } from './../decorators-module';

export class X {

    private _myVar;

    constructor() {}

    @Autobind
    public method1() {
        this._myVar;
    }

    public method2(v:any) {
        this._myVar=v;
    }

}
```

When method1 is called "this" will always refer to X class instance.

When method2 is called "this" will depend on the context.

# @Override

```typescript
import { Trace } from './../decorators-module';

export class X {

    @Autobind
    public myMethod() {}

}

export class Y {

    @Override
    public myMethod() {}

}

```

Override decorator will check that:

- X implements myMethod

- If myMethod of X is autobinded, myMethod of Y is automatically autobinded


# @Trace

## Class decorator

```typescript
import { Trace } from './../decorators-module';

@Trace
export class X {

    private _myVar;

    constructor() {}

    public method1() {
        this._myVar;
    }

    public method2(v:any) {
        this._myVar=v;
    }

}
```

Every X instances creation + every call of methods will be logged in the console

## Method decorator

```typescript
import { Trace } from './../decorators-module';

export class X {

    private _myVar;

    constructor() {}

    @Trace
    public method1() {
        this._myVar;
    }

    public method2(v:any) {
        this._myVar=v;
    }

}
```

Every call to method1 will be logged in the console

## Property decorator

```typescript
import { Trace } from './../decorators-module';

export class X {

    @Trace
    private _myVar;

    constructor() {}

    public method1() {
        this._myVar;
    }

    public method2(v:any) {
        this._myVar=v;
    }

}
```

Every modification of _myvar will be logged in the console.

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