@yeger/debounce
TypeScript icon, indicating that this package has built-in type declarations

2.0.9 • Public • Published

@yeger/debounce

A tiny TypeScript library for debouncing functions.

CI NPM Coverage MIT npm bundle size

Features

  • Debounce any callback. Usefull for preventing flickering when using ResizeObserver.
  • ⏱️ Optional delays for callback invocations.
  • 🐭 Tiny.

Installation

# yarn
$ yarn add @yeger/debounce

# npm
$ npm install @yeger/debounce

Usage

import { debounce } from '@yeger/debounce'

// Take an existing function
function resize(): void {
  // ...
}

// Debounce it using the library
const debouncedResize = debounce(() => resize())

// And use the debounced function
const resizeObserver = new ResizeObserver(debouncedResize)

Optionally, a delay for the invocation of the debounced method can be passed.

const debouncedResize = debounce(() => resize(), 200)

Development

# install dependencies
$ pnpm install

# build for production
$ pnpm build

# lint project files
$ pnpm lint

# run tests
$ pnpm test

License

MIT - Copyright © Jan Müller

Package Sidebar

Install

npm i @yeger/debounce

Weekly Downloads

5,682

Version

2.0.9

License

MIT

Unpacked Size

4.87 kB

Total Files

5

Last publish

Collaborators

  • yeger