# debounce-fn

> Debounce a function

Latest version **6.0.0** (published 2023-11-05) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 40/100 (D)** — status: abandoned.

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

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 6.0.0 |
| Published | 2023-11-05 |
| First published | 2014-08-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=18 |
| Dependencies | 1 |
| Unpacked size | 7.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 133 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | debounce, function, debouncer, fn, func, throttle, delay, invoked |

## Links

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

## Dependencies (1)

- [mimic-function](https://npm.io/package/mimic-function.md) ^5.0.0

## Recent versions

- 6.0.0 (latest) — 2023-11-05
- 5.1.2 — 2022-06-11
- 5.1.1 — 2022-06-11
- 5.1.0 — 2022-01-01
- 5.0.0 — 2021-02-28
- 4.0.0 — 2020-02-19
- 3.0.1 — 2019-04-21
- 3.0.0 — 2019-04-10
- 1.0.0 — 2017-06-03
- 0.0.1-security — 2016-03-23
- 2.0.0 — 2016-03-22
- 0.1.0 — 2015-10-10
- 0.0.0 — 2014-08-04

## README

# debounce-fn

> [Debounce](https://davidwalsh.name/javascript-debounce-function) a function

## Install

```sh
npm install debounce-fn
```

## Usage

```js
import debounceFunction from 'debounce-fn';

window.onresize = debounceFunction(() => {
	// Do something on window resize
}, {wait: 100});
```

## API

### debounceFunction(input, options?)

Returns a debounced function that delays calling the `input` function until after `wait` milliseconds have elapsed since the last time the debounced function was called.

It comes with a `.cancel()` method to cancel any scheduled `input` function calls.

#### input

Type: `Function`

Function to debounce.

#### options

Type: `object`

##### wait

Type: `number`\
Default: `0`

Time in milliseconds to wait until the `input` function is called.

##### maxWait

Type: `number`\
Default: `Infinity`

The maximum time the `input` function is allowed to be delayed before it's invoked.

This can be used to limit the number of calls handled in a constant stream. For example, a media player sending updates every few milliseconds but wants to be handled only once a second.

##### before

Type: `boolean`\
Default: `false`

Trigger the function on the leading edge of the `wait` interval.

For example, can be useful for preventing accidental double-clicks on a "submit" button from firing a second time.

##### after

Type: `boolean`\
Default: `true`

Trigger the function on the trailing edge of the `wait` interval.

## Related

- [p-debounce](https://github.com/sindresorhus/p-debounce) - Debounce promise-returning & async functions

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