# debounce

> Delay function calls until a set time elapses after the last invocation

Latest version **3.0.0** (published 2025-11-02) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 60/100 (C)** — status: stable.

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2025-11-02 |
| First published | 2013-08-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=20 |
| Dependencies | 0 |
| Unpacked size | 8.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 851 |
| Maintainers | sindresorhus |
| Keywords | debounce, debouncing, function, throttle, invoke, limit, limited, interval, rate, batch, rate-limit |

## Links

- npm: https://www.npmjs.com/package/debounce
- Repository: https://github.com/sindresorhus/debounce
- Homepage: https://github.com/sindresorhus/debounce#readme
- Issues: https://github.com/sindresorhus/debounce/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/debounce

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 3.0.0 (latest) — 2025-11-02
- 2.2.0 — 2024-10-14
- 2.1.1 — 2024-09-09
- 2.1.0 — 2024-05-25
- 2.0.0 — 2023-11-15
- 1.2.1 — 2021-03-09
- 1.2.0 — 2018-08-14
- 1.1.0 — 2017-10-30
- 1.0.2 — 2017-04-21
- 1.0.0 — 2014-06-21
- 0.0.3 — 2013-08-21
- 0.0.2 — 2013-08-21

## README

# debounce

> Delay function calls until a set time elapses after the last invocation

## Install

```sh
npm install debounce
```

## Usage

```js
import debounce from 'debounce';

function resize() {
	console.log('height', window.innerHeight);
	console.log('width', window.innerWidth);
}

window.onresize = debounce(resize, 200);
```

To check if the debounce delay is currently active:

```js
window.onresize.isPending;
```

To later clear the timer and cancel currently scheduled executions:

```js
window.onresize.clear();
```

Execute immediately only if a call is pending (and reset the timer):

```js
window.onresize.flush();
```

To execute immediately and reset the timer if it was previously set:

```js
window.onresize.trigger();
```

## API

### debounce(fn, wait, options?)

Creates a debounced function that delays execution until `wait` milliseconds have passed since its last invocation.

Set the `immediate` option to `true` to execute the function immediately at the start of the `wait` interval, preventing issues such as double-clicks on a button.

The returned function has the following methods:

- `.isPending` indicates whether the debounce delay is currently active.
- `.clear()` cancels any scheduled executions.
- `.flush()` if an execution is scheduled then it will be immediately executed and the timer will be cleared.
- `.trigger()` executes the function immediately and clears the timer if it was previously set.

## Related

- [p-debounce](https://github.com/sindresorhus/p-debounce) - Similar but handles promises
- [throttleit](https://github.com/sindresorhus/throttleit) - Throttle a function to limit its execution rate

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