# @kuoruan/throttle-debounce

> Typescript throttle and debounce

Latest version **1.0.5** (published 2020-04-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install @kuoruan/throttle-debounce
pnpm add @kuoruan/throttle-debounce
yarn add @kuoruan/throttle-debounce
bun add @kuoruan/throttle-debounce
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2020-04-25 |
| First published | 2020-03-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Xingwang Liao |
| Maintainers | kuoruan |
| Keywords | throttle-debounce, throttle, debounce, typescript |

## Links

- npm: https://www.npmjs.com/package/@kuoruan/throttle-debounce
- Repository: https://github.com/kuoruan/es-packages
- Homepage: https://github.com/kuoruan/es-packages/tree/master/packages/throttle-debounce#readme
- Issues: https://github.com/kuoruan/es-packages/issues
- npm.io page: https://npm.io/package/@kuoruan/throttle-debounce

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

- 1.0.5 (latest) — 2020-04-25
- 1.0.4 — 2020-03-15
- 1.0.3 — 2020-03-14
- 1.0.2 — 2020-03-07
- 1.0.1 — 2020-03-07
- 1.0.0 — 2020-03-07

## README

# throttle-debounce

Typescript version of throttle and debounce function.

## Install

``` sh
npm install --save @kuoruan/throttle-debounce
```

Or with Yarn

``` sh
yarn add @kuoruan/throttle-debounce
```

## Useage

### throttle

``` js
import { throttle } from "@kuoruan/throttle-debounce";

const onWindowResize = throttle(function(this: Window, e: Event) {
  console.log("resized", this.innerWidth, this.innerHeight);
}, 20);

window.addEventListener("resize", onWindowResize, false);
```

### debounce

``` ts
import { debounce } from "@kuoruan/throttle-debounce";

const input: HTMLInputElement = document.querySelector("#search");

const onInputChange = debounce(function(this: HTMLInputElement, e: Event) {
  console.log("Your input is: " + this.value);
}, 100);

input.addEventListener("change", onInputChange, false);
```

## API

### throttle

**function <T extends (...args: any[]) => any>(func: T, threshhold?: number, scope?: any): T;**

#### func

Type: ```T extends (...args: any[]) => any``` (Function)

Optional: false

The function to be throttled.

#### threshhold

Type: ```number```

Optional: true

Default: 20

The threshhold in milliseconds, must greater than zero.

#### scope

Type: any

Optional: true

The ```context``` or ```thisArg``` used by apply. See: [Function.prototype.apply()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply)

### debounce

**function <T extends (...args: any[]) => any>(func: T, delay?: number, scope?: any): T;**

#### func

Type: ```T extends (...args: any[]) => any``` (Function)

Optional: false

The function to be debounced.

#### delay

Type: ```number```

Optional: true

Default: 20

The delay in milliseconds, must greater than zero.

#### scope

Type: any

Optional: true

The ```context``` or ```thisArg``` used by apply. See: [Function.prototype.apply()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply)

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