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

debounce-lite

v1.0.2

Published

Dual-strategy debounce: extend vs fixedDeadline, with leading/trailing, maxWait, cancel/flush.

Downloads

19

Readme

debounce-lite

Dual-strategy debounce for modern apps — classic extend debounce and a unique fixedDeadline mode.
TypeScript-first, zero deps, tiny, and production-ready.

Why? Most debouncers only “extend the deadline.” debounce-lite also supports a fixed deadline: the first call starts a timer that won’t be pushed out by subsequent calls — perfect when you want predictable latency.


Features

  • Two strategies: extend (classic) and fixedDeadline (first call sets deadline)
  • Controls: leading, trailing, maxWait, cancel(), flush(), pending()
  • Great DX: TS types, JSDoc, argument & this preservation, optional AbortSignal
  • Zero dependenciesTinyCJS build (works everywhere)

Live Demo

Try it here: https://debounce-lite.surge.sh


Install

npm i debounce-lite
# pnpm add debounce-lite
# yarn add debounce-lite

Quick start

Extend (classic) debounce

import { debounceExtend } from "debounce-lite";

const save = (q: string) => api.save(q);

const debouncedSave = debounceExtend(save, 300, {
  trailing: true,
  leading: false,
  maxWait: 2000,
});

input.addEventListener("input", (e) => debouncedSave((e.target as HTMLInputElement).value));

Fixed-deadline debounce (the differentiator)

import { debounceFixedDeadline } from "debounce-lite";

// First call starts a 300ms deadline; later calls DON'T extend it.
const stableLatencySave = debounceFixedDeadline(save, 300);

input.addEventListener("input", (e) => stableLatencySave((e.target as HTMLInputElement).value));

React demo

See the playground in examples/react. It shows both strategies, live controls, and a log.


API

createDebouncedFunction(fn, options) → DebouncedFunction

Build your own with full control.

Options | Name | Type | Default | Description | |---|---|---:|---| | wait | number | — | Delay in ms. | | leading | boolean | false | Invoke on the leading edge. | | trailing | boolean | true | Invoke on the trailing edge. | | maxWait | number | Infinity | Ensures an invoke no later than this many ms since the first call of the cycle. | | strategy | "extend" \| "fixedDeadline" | "extend" | Deadline behavior (see below). |

Returns a debounced function with:

  • (...args): Promise<TResult>
  • (...args, { signal?: AbortSignal }): Promise<TResult> (optional per-call AbortSignal)
  • .cancel(): void
  • .flush(): TResult | undefined
  • .pending(): boolean

Convenience helpers

  • debounceExtend(fn, wait, opts?) — classic debounce
  • debounceFixedDeadline(fn, wait, opts?) — fixed deadline

Type signatures

export interface DebounceOptions {
  wait: number;
  leading?: boolean;
  trailing?: boolean;
  maxWait?: number;
  strategy?: "extend" | "fixedDeadline";
}

export interface DebouncedFunction<TArgs extends any[], TResult> {
  (...args: TArgs): Promise<TResult>;
  (...args: [...TArgs, { signal?: AbortSignal }]): Promise<TResult>;
  cancel(): void;
  flush(): TResult | undefined;
  pending(): boolean;
}

Strategy semantics (at a glance)

  • extend (classic): each call resets the wait timer
    a──┐ b──┐ c──┐ |invoke c|
  • fixedDeadline: first call fixes the deadline; later calls don’t move it
    a────────────|deadline| (invokes with latest args seen before deadline)

Use extend to reduce call volume while users type; use fixedDeadline when you need stable latency (e.g., “always respond ~300ms after first keystroke, regardless of flurries”).


Recipes

Cancel pending work

const d = debounceExtend(save, 300);
router.beforeEach(() => d.cancel());

Flush immediately (e.g., on blur)

input.addEventListener("blur", () => void d.flush());

Abort per call

const ctrl = new AbortController();
d(query, { signal: ctrl.signal });
ctrl.abort(); // rejects that call's promise with AbortError

Common questions

How is this different from throttle?
Throttle limits call rate; debounce delays until quiet (or deadline). fixedDeadline is still a debounce—just with a stable end time.

Does it work with CommonJS and ESM?
Yes. Package ships CJS with types. Import via import { … } from "debounce-lite" (bundlers/TS) or const { … } = require("debounce-lite").


License

MIT © MrFarhan


Changelog

See Git commits. Initial public release adds both strategies, controls, React example, and tests.