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 🙏

© 2026 – Pkg Stats / Ryan Hefner

kk-debounce

v1.0.5

Published

A lightweight, zero-dependency utility for debounce and throttle in JavaScript and TypeScript apps, with built-in React hooks for common UI workflows.

Downloads

598

Readme

kk-debounce 🚀

CI bundle size npm version license install size

A lightweight, zero-dependency utility for debounce and throttle in JavaScript and TypeScript apps, with built-in React hooks for common UI workflows.

Features

  • Debounce callbacks with numeric delays or temporal objects
  • Throttle frequent events like scroll, resize, and mouse movement
  • Debounced signal controller with value, isPending, cancel(), and flush()
  • React hooks for debounce, debounced signals, and throttled callbacks
  • ESM and CJS package exports
  • Zero runtime dependencies

Requirements

  • Node.js 18+
  • React 18+ for kk-debounce/react

React is optional unless you import from kk-debounce/react.

📦 Installation

Install with your preferred package manager:

npm install kk-debounce
pnpm add kk-debounce
yarn add kk-debounce

Supported Environments

  • JavaScript and TypeScript projects
  • React applications via kk-debounce/react
  • Browser applications using ESM or CJS builds
  • Node.js runtimes

Subpath Imports

Import only what you need:

import { debounce } from 'kk-debounce/debounce';
import { debouncedSignal } from 'kk-debounce/debounceSignal';
import { throttle } from 'kk-debounce/throttle';
import {
  useDebounce,
  useDebounceSignal,
  useThrottled,
} from 'kk-debounce/react';

🚀 Usage

Debounce

import { debounce } from 'kk-debounce';

const handleSearch = debounce((query) => {
  console.log('Searching for:', query);
}, 500);

// This will only fire once, 500ms after the last call.
handleSearch('Hello');
handleSearch('Hello World');

Throttle

import { throttle } from 'kk-debounce';

const handleScroll = throttle((position) => {
  console.log('Scroll position:', position);
}, 200);

window.addEventListener('scroll', () => {
  handleScroll(window.scrollY);
});

Debounced Signal

import { debouncedSignal } from 'kk-debounce';

let searchTerm = '';

const updateSearch = debouncedSignal(
  () => searchTerm,
  (nextValue) => {
    searchTerm = nextValue;
    console.log('Searching for:', nextValue);
  },
  { seconds: 2 }
);

updateSearch('rea');
updateSearch('react');

if (updateSearch.isPending) {
  console.log('Waiting for typing to stop...');
}

updateSearch.flush();

React: useDebounce and useThrottled

import { useState } from 'react';
import { useDebounce, useThrottled } from 'kk-debounce/react';

export function SearchBox() {
  const [query, setQuery] = useState('');

  const saveDraft = useDebounce((value: string) => {
    console.log('Saving draft:', value);
  }, 300);

  const trackTyping = useThrottled((value: string) => {
    console.log('Typing:', value);
  }, 500);

  return (
    <input
      value={query}
      onChange={(event) => {
        const nextValue = event.target.value;
        setQuery(nextValue);
        saveDraft(nextValue);
        trackTyping(nextValue);
      }}
      placeholder="Search..."
    />
  );
}

React: useDebounceSignal

import { useState } from 'react';
import { useDebounceSignal } from 'kk-debounce/react';

export function ProfileEditor() {
  const [name, setName] = useState('John Doe');
  const [draftName, setDraftName] = useState(name);

  const debouncedUpdate = useDebounceSignal(
    () => name,
    (value) => setName(value),
    800,
    { autoAbort: true } // autoAbort defaults to true; shown here for clarity
  );

  return (
    <div>
      <input
        value={draftName}
        onChange={(event) => {
          const nextValue = event.target.value;
          setDraftName(nextValue);
          debouncedUpdate(nextValue);
        }}
      />

      {debouncedUpdate.isPending && <p>Saving...</p>}

      <button onClick={() => debouncedUpdate.flush()}>Save now</button>
    </div>
  );
}

API

debounce(callback, wait, options?)

Creates a debounced function that delays execution until calls stop for the configured wait time.

  • Supports number (ms) or temporal objects like { minutes: 1, seconds: 30 }
  • Supports options.behavior:
  • trailing (default): invoke after delay with the latest arguments
  • leading: invoke immediately on the first call, then wait for the next window
  • Supports options.autoAbort and external options.signal
  • Returns a callable function with .cancel()

throttle(callback, wait)

Creates a throttled function that runs immediately, then limits how often subsequent calls can execute.

  • Supports number or temporal objects
  • Returns a callable function with .cancel()

debouncedSignal(getter, setter, wait, options?)

Creates a debounced controller for state-like values.

  • value: current committed or pending value
  • isPending: whether an update is waiting to run
  • cancel(): clear the pending update
  • flush(): apply the pending value immediately

React Hooks

  • useDebounce(callback, wait, options?)
  • useDebounceSignal(getter, setter, wait, options?)
  • useThrottled(callback, wait)

Why use kk-debounce?

  • Small footprint: Zero dependencies.
  • Easy to use: Simple API for debounce, throttle, and React hooks.
  • Framework-friendly: Works in plain JavaScript/TypeScript and ships custom hooks for React.
  • Performance: Ideal for search inputs, window resizing, scroll events, and autosave flows.

License

MIT © Ink01101011