
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
@bscotch/debounce-watch
Advanced tools
Monitor files for changes, debounce events, and finally trigger consequences.
⚠ In active development and subject to major change! ⚠
There are some great libraries out there for triggering code when files change, including chokidar and nodemon.
A file watcher utility that debounces file changes before triggering an event is much harder to find. That's the purpose of Debounce Watch.
📢 Announcement 📢 The deployed version of this package found on npm is from an internal fork of the public repo. The public repo will eventually be deleted. Non-Bscotch users should use the npm package for the most up-to-date version.
The goal of "Debouncing" is to prevent an event-invoked action from being invoked multiple times while redundant events keep happening. In essence, once the events start we want to wait until they stop before firing off some action in response.
This is useful for cases where file system changes occur in batches but you only want subsequent actions to occur once all changes are complete (e.g. when compiling a Typescript project to JavaScript).
Nodemon and chokidar provide delay options to approximately get at this, such that the triggered action will occur that amount of time after the first event is detected. However, there is no way to guarantee that the delay will encompass all events in a batch.
Debounce Watch uses chokidar to watch for file system changes, collects a list of all changes that have occurred, and calls a function you provide on that list once the file system changes become less frequent than your debounce timeout.
Install with npm install @bscotch/debounce-watch
.
Use in your code:
// (Example in Typescript)
import { debounceWatch } from '@bscotch/debounce-watch';
import type { DebouncedEventsProcessor } from '@bscotch/debounce-watch';
// Your function can be sync or async
const processDebouncedEvents: DebouncedEventsProcessor = (events) => {
for (const event of events) {
if (event.event == 'add') {
// Do something related to a file being added!
}
}
};
const watcher = await debounceWatch('folder/of/files', processDebouncedEvents, {
onlyFileExtensions: ['ts', 'js'],
debounceWaitSeconds: 0.2,
allowOverlappingRuns: true,
});
FAQs
Monitor files for changes, debounce events, and finally trigger consequences.
We found that @bscotch/debounce-watch 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
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.