# helpful-decorators

> Helpful decorators for typescript projects

Latest version **2.1.0** (published 2020-06-19) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2020-06-19 |
| First published | 2017-09-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 24.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 462 |
| Maintainers | netbasal |
| Keywords | decorators, setTimeout decorator, debounce decorator, once decorator, mixin decorator, measure decorator |

## Links

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

## Dependencies (5)

- [lodash.once](https://npm.io/package/lodash.once.md) 4.1.1
- [lodash.delay](https://npm.io/package/lodash.delay.md) 4.1.1
- [lodash.memoize](https://npm.io/package/lodash.memoize.md) 4.1.2
- [lodash.debounce](https://npm.io/package/lodash.debounce.md) 4.0.8
- [lodash.throttle](https://npm.io/package/lodash.throttle.md) 4.1.1

## 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

- 2.1.0 (latest) — 2020-06-19
- 2.0.6 — 2019-11-27
- 2.0.5 — 2019-07-30
- 2.0.4 — 2019-05-25
- 2.0.3 — 2019-03-28
- 2.0.2 — 2019-03-14
- 2.0.1 — 2019-03-14
- 2.0.0 — 2019-03-14
- 1.7.2 — 2018-04-11
- 1.7.1 — 2018-04-11
- 1.7.0 — 2018-01-30
- 1.6.0 — 2018-01-30
- 1.5.1 — 2017-12-12
- 1.5.0 — 2017-11-17
- 1.4.1 — 2017-11-17
- … 4 more at https://npm.io/package/helpful-decorators/versions

## README

[![npm](https://img.shields.io/npm/dt/helpful-decorators.svg)]()
[![Build Status](https://travis-ci.org/NetanelBasal/helpful-decorators.svg?branch=master)](https://travis-ci.org/NetanelBasal/helpful-decorators)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release)
[![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome)

# Helpful Decorators For Typescript Projects

## Installation
```js
npm install helpful-decorators
yarn add helpful-decorators
```

## Usage
`delay` - Add `setTimeout` functionality to the method

```js
import { delay } from 'helpful-decorators';

class Test {
 @delay(1000)
 method() {
   // ...
 }
}
```

`debounce` - Add `debounce` functionality to the method ([options](https://lodash.com/docs/4.17.4#debounce))

```js
import { debounce } from 'helpful-decorators';

class Test {
 @debounce(1000, options)
 method() {
   // ...
 }
}
```

`throttle` - Add `throttle` functionality to the method ([options](https://lodash.com/docs/4.17.4#throttle))
```js
import { throttle } from 'helpful-decorators';

class Test {
 @throttle(1000, options)
 method() {
   // ...
 }
}
```

`once` - Add `once` functionality to the method
```js
import { once } from 'helpful-decorators';

class Test {
 @once
 method() {
   // This will run only once
 }
}
```

`measure` - measure time taken by a function to execute
```js
import { measure } from 'helpful-decorators';

class Test {
 @measure
 doSomething() {
   // Call to doSomething took 0.35 milliseconds.
 }
}
```

`Mixin` - this pattern is used to achieve multiple inheritance
```js
import { Mixin } from 'helpful-decorators';

@Mixin([Disposable, Activatable])
class Test {
}
```

`memo` - memoizes the result of the function
```js
import { memo } from 'helpful-decorators';

class Test {
 
  @memo()
  method() {
    ...memoized
  }
}
```

`bind` - automatically bind methods to class instances
```js
import { bind } from 'helpful-decorators';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  constructor() {
    document.body.addEventListener('click', this.onClick);
  }

  @bind
  onClick($event) {
    console.log($event);
  }
}
```

`SortBy` - sort an array by a specific property in individual elements or non-object items (By default, it sorts by `type === 'string'` and `isDescending === true`)
```js
import { SortBy } from 'helpful-decorators';

class Test {
  
  @SortBy('name', {
    isDescending: false,
    type: 'string'
  })
  names = [ { name: 'b' }, { name: 'a' }, { name: 'c' } ];

  @SortBy('', {
    isDescending: true,
    type: 'date'
  })
  dates = [ '2020-06-17', '2020-06-16', '2020-06-20', '2020-06-10' ];

  @SortBy('', {
    isDescending: false,
    type: 'number'
  })
  numbers = [ 6, 3, 4, 1 ];
}
```
 
License
----

MIT

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