chaoswd-debouncer
v1.1.1
Published
A lightweight utility for resetting timeouts on user-defined events (keydown, click, etc).
Maintainers
Readme
Debouncer
A lightweight, zero-dependency JavaScript utility for resetting timeouts on user-defined events (like keydown, click, etc).
🚀 Features
- Simple and modern ES module (import/export)
- No dependencies
- Works in browser or Node
- Customizable delay
- Optional attach() helper for DOM events
📦 Installation
npm install chaoswd-debouncer🧩 Usage
Import
import { Debouncer } from 'chaoswd-debouncer';Example
const log = new Debouncer(() => console.log('Typing stopped!'), 1000);
document.querySelector('input').addEventListener('input', e => log.trigger(e));
// The callback runs 1s after the user stops typing.Manual trigger
const d = new Debouncer(() => console.log('done!'), 5000);
d.trigger(); // resets timeout each callCancel
d.cancel(); // clears the active timeoutAttach
const clicker = new Debouncer(() => console.log('Clicked!'), 2000);
clicker.attach(document.getElementById('myButton'), 'click');🧪 Testing
npm testUses Vitest for fast, modern unit testing.
⚙️ Build
npm run buildBuilds to /dist using Vite in library mode.
📁 Project Structure
debouncer/
├─ src/
│ ├─ debouncer.js
│ └─ index.js
├─ tests/
│ └─ debouncer.test.js
├─ dist/
├─ package.json
├─ vite.config.js
└─ README.md📜 License
MIT License © 2025 Chaos Web Development & Jordan Gerber
