npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

dboun

v1.0.2

Published

A utility to debounce functions for better performance and control.

Downloads

10

Readme

dboun

The dboun function is a utility designed to limit the rate at which a function is executed. It ensures that the provided function (fn) is called only after a specified delay (delay) has elapsed since the last invocation. By default, the delay is set to 400 milliseconds.

This is particularly useful for handling events that fire frequently, such as resizing, scrolling, or typing, by preventing the provided function from being called excessively.

Usage Example

Scenario: Search Input with Debounce

// Define the function to handle search
function handleSearch(query: string): void {
    console.log("Searching for:", query);
}

// Create a debounced version of the search handler
const debouncedSearch = dboun(handleSearch, 300);

// Simulate typing in a search box
const input = document.querySelector('#searchBox');
input?.addEventListener('input', (event: Event) => {
    const target = event.target as HTMLInputElement;
    debouncedSearch(target.value);
});

In this example:

  • handleSearch is the function that handles the search logic.
  • debouncedSearch ensures that handleSearch is executed only after 300 milliseconds of inactivity in typing.

Parameters

  1. fn (Function): The function to be executed after the debounce delay.

    • This is the callback function that will be invoked after the specified delay.
  2. delay (Number, optional): The number of milliseconds to wait before invoking fn. Defaults to 400 milliseconds.

    • This determines the debounce interval.

Returns

The dboun function returns a new debounced version of fn. The returned function delays the invocation of fn until after delay milliseconds have passed since the last time the returned function was called.

How It Works

  • When the returned function is called, it clears any existing timer set for the function (clearTimeout(timeout)).
  • A new timer is then set (setTimeout) to invoke fn after the specified delay.
  • If the returned function is called again before the delay period ends, the previous timer is cleared and reset.

Practical Applications

  1. Input Handling: Debouncing prevents excessive execution of event handlers when users type in an input field.
  2. Resize Events: Manage performance by debouncing window resize event handlers.
  3. Scroll Events: Avoid performance bottlenecks by controlling how often scroll event handlers are executed.

Notes

  • If you need immediate execution followed by a delay (throttle-like behavior), this function does not provide that functionality out of the box.
  • Always ensure delay is appropriate for the use case to balance responsiveness and performance.

Browser Compatibility

The dboun function uses modern JavaScript/TypeScript features, making it compatible with most modern environments. For older environments, consider transpiling the code.

Testing

// Test debounced function
const log = dboun((message: string) => console.log(message), 500);
log("Hello"); // Will not log immediately
log("Hello again"); // Resets the timer; only this message will log after 500ms