All Projects → Conduitry → cheap-watch

Conduitry / cheap-watch

Licence: MIT license
If it works, why use something else? // Mirror of https://git.chor.date/Conduitry/cheap-watch

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to cheap-watch

watcher
The file system watcher that strives for perfection, with no native dependencies and optional rename detection support.
Stars: ✭ 37 (-42.19%)
Mutual labels:  watch, file, watcher
Cpx
A cli tool to watch and copy file globs.
Stars: ✭ 394 (+515.63%)
Mutual labels:  watch, file
Fileboy
fileboy,文件变更监听通知工具,使用 Go 编写。Fileboy, File Change Monitoring Notification Tool, written with Go.
Stars: ✭ 345 (+439.06%)
Mutual labels:  watch, file
Multiwatch
Simple task runner on directory changes that doesn't produce tons of logs if everything is OK 👌
Stars: ✭ 74 (+15.63%)
Mutual labels:  watch, watcher
File
The Hoa\File library.
Stars: ✭ 322 (+403.13%)
Mutual labels:  file, watcher
toxic-decorators
Library of Javascript decorators
Stars: ✭ 26 (-59.37%)
Mutual labels:  watch, watcher
Proxy Watcher
A library that recursively watches an object for mutations via Proxies and tells you which paths changed.
Stars: ✭ 35 (-45.31%)
Mutual labels:  watch, watcher
compose-watcher
Watch volumes and restart services in docker compose
Stars: ✭ 27 (-57.81%)
Mutual labels:  watch, watcher
Funzzy
Yet another fancy watcher. (Rust)
Stars: ✭ 142 (+121.88%)
Mutual labels:  watch, watcher
Php Watcher
Monitor for any changes in your php application and automatically restart it (suitable for async apps).
Stars: ✭ 303 (+373.44%)
Mutual labels:  asynchronous, watch
Tokio File Unix
Asynchronous support for epollable files via Tokio on Unix-like platforms
Stars: ✭ 29 (-54.69%)
Mutual labels:  asynchronous, file
Denon
👀 Monitor any changes in your Deno application and automatically restart.
Stars: ✭ 725 (+1032.81%)
Mutual labels:  watch, watcher
pwatch
Process watcher(pwatch)
Stars: ✭ 33 (-48.44%)
Mutual labels:  watch, watcher
Git Repo Watcher
A simple bash script to watch a git repository and pull upstream changes if needed.
Stars: ✭ 73 (+14.06%)
Mutual labels:  watch, watcher
gowatch
watch go files for developer, support run test case and auto reload server application
Stars: ✭ 18 (-71.87%)
Mutual labels:  watch, watcher
flow-watch
clear the console and run flow on file changes
Stars: ✭ 30 (-53.12%)
Mutual labels:  watch, file-watcher
read-yaml
Very thin wrapper around js-yaml for directly reading in YAML files.
Stars: ✭ 25 (-60.94%)
Mutual labels:  file
asynchronous
A D port of Python's asyncio library
Stars: ✭ 35 (-45.31%)
Mutual labels:  asynchronous
ext-pq
PostgreSQL client library (libpq) binding
Stars: ✭ 33 (-48.44%)
Mutual labels:  asynchronous
SimpleStorage
💾 Simplify Android Storage Access Framework for file management across API levels.
Stars: ✭ 498 (+678.13%)
Mutual labels:  file

Cheap Watch: If it works, why use something else?

npm version Build Status

Cheap Watch is a small, simple, dependency-free, cross-platform file system watcher for Node.js 8+.

Constructor

new CheapWatch({ dir, filter, watch = true, debounce = 10 })

  • dir - The directory whose contents to watch. It's recommended, though not required, for this to be an absolute path, say one returned by path.resolve.
  • filter({ path, stats }) - (optional) A function to decide whether a given file or directory should be watched. It's passed an object containing the file or directory's relative path and its stats. It should return true or false (or a Promise resolving to one of those). Returning false for a directory means that none of its contents will be watched.
  • watch - (optional) Whether to actually watch the directory for changes. Defaults to true. If false, you can retrieve all of the files and directories within a given directory along with their initial Stats but changes will not be monitored.
  • debounce - (optional) Length of timeout in milliseconds to use to debounce incoming events from fs.watch. Defaults to 10. Multiple events are often emitted for a single change, and events can also be emitted before fs.stat reports the changes. So we will wait until debounce milliseconds have passed since the last fs.watch event for a file or directory before handling it. The default of 10ms Works On My Machine.

Methods

init()

Initialize the watcher, traverse the directory to find the initial files and directories, and set up watchers to look for changes.

This returns a Promise that resolves once the initial contents of the directory have been traversed and all of the watchers have been set up.

close()

Close all FSWatcher instances, and stop watching for file changes.

Properties

paths

A Map of the watched files and directories. Each key is a relative path from the CheapWatch's dir, and each value is a Stats object for the file or directory. Paths are always separated by forward slashes, regardless of platform. This Map is kept up to date as files are changed on disk.

You can use stats.isFile() and stats.isDirectory() to determine whether something is a file or a directory.

Events

A CheapWatch is an EventEmitter, and emits two events to report a new, updated, or deleted file or directory.

+ { path, stats, isNew }

A + event is emitted whenever a watched file or directory is created or updated. It's emitted with an object containing a path string, a stats object, and an isNew boolean which will be true for newly created files and directories and false for updated ones.

- { path, stats }

A - event is emitted whenever a watched file or directory is deleted. It's emitted with an object containing a path string and a stats object. stats will be the most recent Stats collected for the file or directory before it was deleted.

Usage

import CheapWatch from 'cheap-watch';

const watch = new CheapWatch({ dir, /* ... */ });

await watch.init();

for (const [path, stats] of watch.paths) {
	/* ... */
}

watch.on('+', ({ path, stats, isNew }) => { /* ... */ });
watch.on('-', ({ path, stats }) => { /* ... */ });

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].