
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
mini-debounce
Advanced tools
Extremely small and modern debounce library (smaller than tiny-debounce)
mini-debounceAn extremely small and modern debounce library that is supported by all major browsers.
mini-debounce is only 94 bytes, that's smaller than tiny-debounce by 161 bytes!!!
yarn add mini-debounce
# or
npm install mini-debounce
| Name | Type | Description |
|---|---|---|
| callback | Function | The function to be debounced |
| timeout | number | The number of milliseconds to wait after called |
| Type | Description |
|---|---|
| Function | Returns the new debounced function, once called the previous timeout is cancelled and a new timeout is initiated |
"Okay but what does that function return?"
It returns the id from setTimeout which allows you to run clearTimeout in order to cancel the debounced call.
The function is not exported as default as to provide better intellisense.
import {debounce} from 'mini-debounce'
// or
const {debounce} = require('mini-debounce')
// Create the debounced function
const debouncedLog = debounce(x => console.log('[LOG]', x), 1000)
// Use it
debouncedLog('Hello...')
debouncedLog("It's me")
debouncedLog('I was wondering')
debouncedLog('if after all')
// 1000 milliseconds later
// => "[LOG] if after all"
// You can cancel them as well
const id = debouncedLog('This will never appear')
clearTimeout(id)
Here we'll demonstrate an implementation of a debounced search input.
class Search {
state = {query: ''}
search = debounce(query => {
/* this will only be run 1000 milliseconds after no changes */
fetch(`https://example.com/api?q=${query}`).then(/* do whatever */)
}, 1000)
handleChange = event => {
const query = event.target.value
this.setState({query})
this.search(query)
}
render() {
return <input value={this.state.query} onChange={this.handleChange} />
}
}
// Now as a function
function Search() {
const [query, setQuery] = useState('')
const search = debounce(query => {
fetch(/* you know */).then(/* do whatever */)
}, 1000)
function handleChange(event) {
const query = event.target.value
setQuery(query)
search(query)
}
return <input value={query} onChange={handleChange} />
}
MIT License Copyright © 2019 Christopher Holden Brown
FAQs
Extremely small and modern debounce library (smaller than tiny-debounce)
The npm package mini-debounce receives a total of 3,958 weekly downloads. As such, mini-debounce popularity was classified as popular.
We found that mini-debounce demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.