simple-utility-debounce
raw JSON → 1.0.0 verified Mon Apr 27 auth: no javascript
A minimal debounce utility function that delays invoking a callback until after a specified wait period. Version 1.0.0 (latest) is a single-function package with no dependencies. Lightweight alternative to lodash.debounce, targeting npm users who need a quick, zero-dependency debounce. No TypeScript types included. Last updated in 2023, with no recent activity or releases.
Common errors
error TypeError: debounce is not a function ↓
cause Incorrect import: using named import instead of default import, or CommonJS without .default.
fix
Use: import debounce from 'simple-utility-debounce' (ESM) or const debounce = require('simple-utility-debounce').default (CJS).
error Module '"simple-utility-debounce"' has no default export ↓
cause TypeScript strict mode or incorrect import syntax.
fix
Add 'esModuleInterop: true' in tsconfig.json or use namespace import: import * as debounce from 'simple-utility-debounce'.
Warnings
gotcha No TypeScript types available; users must declare their own types or use a type assertion. ↓
fix Add a declaration file (e.g., debounce.d.ts) with 'declare module "simple-utility-debounce" { ... }' or use @ts-ignore.
gotcha The debounced function does not return a promise; it returns undefined. Cannot await completion. ↓
fix Wrap in a Promise if needed: const debouncedFn = debounce(() => new Promise(resolve => ...), wait);
Install
npm install simple-utility-debounce yarn add simple-utility-debounce pnpm add simple-utility-debounce Imports
- debounce wrong
const { debounce } = require('simple-utility-debounce')correctimport debounce from 'simple-utility-debounce' - debounce (require) wrong
const debounce = require('simple-utility-debounce')correctconst debounce = require('simple-utility-debounce').default
Quickstart
import debounce from 'simple-utility-debounce';
const log = () => console.log('Debounced!');
const debouncedLog = debounce(log, 200);
debouncedLog();
debouncedLog(); // Only runs once after 200ms delay
debouncedLog.cancel(); // Cancel pending invocation