/ student-intifada / node_modules / perfect-debounce /

[ICO]NameLast modifiedSizeDescription
[PARENTDIR]Parent Directory  -  
[DIR]dist/10 months ago -  
[TXT]README.md10 months ago2.5K595aea1 more query options + view options [كارل مبارك]
[   ]package.json10 months ago1.2Kafd0ccc remove unused [كارل مبارك]
[   ]LICENSE10 months ago1.1K 
README.md

perfect-debounce

npm version npm downloads Github Actions Codecov

An improved debounce function with Promise support.

Usage

Install package:

# npm
npm install perfect-debounce

# yarn
yarn add perfect-debounce

# pnpm
pnpm add perfect-debounce

Import:

// ESM
import { debounce } from 'perfect-debounce'

// CommonJS
const { debounce } = require('perfect-debounce')

Debounce function:

const debounced = debounce(async () => {
  // Some heavy stuff
}, 25)

When calling debounced, it will wait at least for 25ms as configured before actually calling our function. This helps to avoid multiple calls.

To avoid initial wait, we can set leading: true option. It will cause function to be immediately called if there is no other call:

const debounced = debounce(async () => {
  // Some heavy stuff
}, 25, { leading: true })

If executing async function takes longer than debounce value, duplicate calls will be still prevented a last call will happen. To disable this behavior, we can set trailing: false option:

const debounced = debounce(async () => {
  // Some heavy stuff
}, 25, { trailing: false })

💻 Development

License

Made with 💛

Based on sindresorhus/p-debounce.

Published under MIT License.

Apache/2.4.38 (Debian) Server at www.karls.computer Port 80