# dettle

> A tiny fully-featured debounce and throttle implementation.

Latest version **1.0.5** (published 2025-01-11) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 40/100 (D)** — status: maintenance-mode.

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

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2025-01-11 |
| First published | 2023-01-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 24 |
| Maintainers | fabiospampinato |
| Keywords | tiny, debounce, throttle |

## Links

- npm: https://www.npmjs.com/package/dettle
- Repository: https://github.com/fabiospampinato/dettle
- Homepage: https://github.com/fabiospampinato/dettle#readme
- Issues: https://github.com/fabiospampinato/dettle/issues
- npm.io page: https://npm.io/package/dettle

## Alternatives

- [postcss-color-hex-alpha](https://npm.io/package/postcss-color-hex-alpha.md) — 6.4M weekly downloads
- [randomcolor](https://npm.io/package/randomcolor.md) — 348.0K weekly downloads
- [bows](https://npm.io/package/bows.md) — 1.3K weekly downloads
- [ep_prefer_color_scheme](https://npm.io/package/ep_prefer_color_scheme.md) — 260 weekly downloads
- [coc-yank](https://npm.io/package/coc-yank.md) — 61 weekly downloads

## Recent versions

- 1.0.5 (latest) — 2025-01-11
- 1.0.4 — 2024-06-30
- 1.0.3 — 2024-06-30
- 1.0.2 — 2024-04-04
- 1.0.1 — 2023-01-27
- 1.0.0 — 2023-01-27

## README

# Dettle

A tiny fully-featured debounce and throttle implementation.

## Install

```sh
npm install --save dettle
```

## Usage

```ts
import {debounce, throttle} from 'dettle';

const fn = () => console.log ( 'Fired!' );

// Debouncing
// The following options are supported:
// `leading`: whether the function should be called when the timeout is created, defaults to `false`
// `trailing`: whether the function should be called when the timeout expires, defaults to `true`
// `maxWait`: the maximum amount of time that can pass before the function is called, defaults to `Infinity`

const debounced = debounce ( fn, 1000, {
  leading: false,
  trailing: true,
  maxWait: Infinity
});

debounced (); // Schedule function for execution
debounced (); // Re-schedule function for execution

debounced.flush (); // Execute the function immediately, if there's a scheduled execution
debounced.cancel (); // Cancel the scheduled execution

// Throttling
// The API for throttling is basically the same, except that:
// - `leading`: is `true` by default rather than `false`
// - `maxWait`: is set implicitly for you to be equal to the wait time

const throttled = throttle ( fn, 1000, {
  leading: true,
  trailing: true
});

throttled (); // Call the function immediately
throttled (); // Schedule function for execution

throttled.flush (); // Execute the function immediately, if there's a scheduled execution
throttled.cancel (); // Cancel the scheduled execution
```

## License

MIT © Fabio Spampinato

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