Socket
Socket
Sign inDemoInstall

perfect-debounce

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    perfect-debounce

[![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href] [![Github Actions][github-actions-src]][github-actions-href] [![Codecov][codecov-src]][codecov-href]


Version published
Weekly downloads
715K
decreased by-0.13%
Maintainers
1
Install size
9.02 kB
Created
Weekly downloads
 

Changelog

Source

v1.0.0

compare changes

🩹 Fixes

  • pkg: Add types subpath export (#14)

📖 Documentation

  • Use correct yarn command (#12)
  • Update installation guide for pnpm (#13)

🏡 Chore

  • Update renovate config (#11)
  • Update repo (46bc53a)
  • Eslint ignore coverage (17fe6cf)
  • Lint tests (18fe26a)

❤️ Contributors

Readme

Source

perfect-debounce

npm version npm downloads Github Actions Codecov

An improved debounce function with Promise support.

  • Well tested debounce implementation
  • Native Promise support
  • Avoid duplicate calls while promise is being resolved
  • Configurable trailing and leading behavior

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

  • Clone this repository
  • Enable Corepack using corepack enable (use npm i -g corepack for Node.js < 16.10)
  • Install dependencies using pnpm install
  • Run interactive tests using pnpm dev

License

Made with 💛

Based on sindresorhus/p-debounce.

Published under MIT License.

FAQs

Last updated on 03 May 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc