# shiki-decorators

> [![Build Status](https://travis-ci.com/shikimori/shiki-decorators.svg?branch=master)](https://travis-ci.com/shikimori/shiki-decorators)

Latest version **1.0.1** (published 2020-11-28) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2020-11-28 |
| First published | 2020-07-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 16.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | morr |
| Maintainers | morr |

## Links

- npm: https://www.npmjs.com/package/shiki-decorators
- Repository: https://github.com/shikimori/shiki-decoratos
- Homepage: https://github.com/shikimori/shiki-decorators
- Issues: https://github.com/shikimori/shiki-decoratos/issues
- npm.io page: https://npm.io/package/shiki-decorators

## Dependencies (2)

- [bind-decorator](https://npm.io/package/bind-decorator.md) 1.0.11
- [memoize-decorator](https://npm.io/package/memoize-decorator.md) ^1.0.2

## Recent versions

- 1.0.1 (latest) — 2020-11-28
- 1.0.0 — 2020-11-15
- 0.15.32 — 2020-11-14
- 0.15.31 — 2020-11-14
- 0.15.30 — 2020-11-14
- 0.15.29 — 2020-11-14
- 0.15.28 — 2020-11-13
- 0.15.27 — 2020-11-12
- 0.15.26 — 2020-11-12
- 0.15.25 — 2020-11-08
- 0.15.24 — 2020-11-07
- 0.15.23 — 2020-11-07
- 0.15.22 — 2020-11-07
- 0.15.21 — 2020-11-05
- 0.15.20 — 2020-11-04
- … 84 more at https://npm.io/package/shiki-decorators/versions

## README

[![Build Status](https://travis-ci.com/shikimori/shiki-decorators.svg?branch=master)](https://travis-ci.com/shikimori/shiki-decorators)

# shiki-decorators
This repository contains set of useful es7 decorators: `bind`, `memoize`, `chain`, `throttle` and `debounce`.

### `@bind` uses [NoHomey/bind-decorator](https://github.com/NoHomey/bind-decorator)
Binds method to the current context.

```js
import { bind } from 'shiki-decorators';
// or to import with tree shaking use
// import bind from 'shiki-decorators/src/bind';

class Example {
  a = 'a from example'

  @bind
  foo() {
    console.log(this.a);
  }

  boo() {
    console.log(this.a);
  }
}

const example = new Example();
const z = { a: 'a from z' };
z.foo = example.foo;
z.boo = example.boo;

z.foo();
z.boo();

// Output
// a from example
// a from z
```


### `@memoize` uses [andreypopp/memoize-decorator](https://github.com/andreypopp/memoize-decorator)
A method/getter decorator which is when applied to a method or a getter
memoizes the result of the first call and returns it on subsequent calls.

```js
import { memoize } from 'shiki-decorators';
// or to import with tree shaking use
// import memoize from 'shiki-decorators/src/memoize';

class Example {
  @memoize
  foo() {
    console.log('heavy method computations');
    return 'foo';
  }

  @memoize
  get boo() {
    console.log('heavy getter computations');
    return 'boo';
  }
}

let example = new Example();

console.log(example.foo()); // prints '', and then prints "1"
console.log(example.boo); // prints '', and then prints "1"

console.log(example.foo()); // just prints '1'
console.log(example.boo); // just prints '1'

// Output
// heavy method computations
// foo
// heavy getter computations
// boo
// foo
// boo
```

### `@chain`
Allows chaining execution of a function. Each method returns a called object,
allowing the calls to be chained together in a single statement.

```js
import { chain } from 'shiki-decorators';
// or to import with tree shaking use
// import chain from 'shiki-decorators/src/chain';

class Example {
  @chain
  foo(num) {
    console.log('num:', num);
  }
}

const example = new Example();
example.foo(1).foo(2);

// Output
// num: 1
// num: 2
```


### `@throttle`
Throttle execution of a function. Especially useful for rate limiting execution of handlers on events like resize and scroll.

```js
import { throttle } from 'shiki-decorators';
// or to import with tree shaking use
// import throttle from 'shiki-decorators/src/throttle';

class Example {
  @throttle(1000)
  foo(num) {
    console.log('num:', num);
  }
}

const example = new Example();

example.foo(1); // Will execute the callback
example.foo(2); // Won’t execute callback
example.foo(3); // Won’t execute callback

setTimeout(() => {
  example.foo(10); // Will execute the callback
}, 900);

setTimeout(() => {
  example.foo(100); // Will execute the callback
}, 1200);

// Output
// num: 1
// num: 10
// num: 100
```


### `@debounce`
Debounce execution of a function. Debouncing, unlike throttling, guarantees that
a function is only executed a single time, either at the very beginning of a
series of calls, or at the very end.
```js
import { debounce } from 'shiki-decorators';
// or to import with tree shaking use
// import debounce from 'shiki-decorators/src/debounce';

class Example {
  @debounce(1000)
  foo(num) {
    console.log('num:', num);
  }
}

const example = new Example();

example.foo(1); // Won't execute callback
example.foo(2); // Won’t execute callback
example.foo(3); // Will execute the callback

setTimeout(() => {
  example.foo(10); // Will execute the callback
}, 1200);

// Output
// num: 3
// num: 10
```


####
Package release command
```sh
GITHUB_TOKEN=... npm run release
```

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