File system watcher based on chokidar
that emits add/change/rename/unlink events.
The main reason this library exists is to provide a "rename" event too, if you don't need that you might just want to use chokidar
directly.
npm install --save chokidar-watcher
This library provides the following interface:
type Handler = ( filePath: string, nextFilePathOrStats?: import ( 'fs' ).Stats | string ) => void;
type Handlers = {
add?: ( filePath: string, stats: fs.Stats ) => void,
change?: ( filePath: string, stats: fs.Stats ) => void,
rename?: ( prevFilePath: string, nextFilePath: string ) => void,
unlink?: ( filePath: string ) => void
};
function watcher ( paths: ChokidarPaths, options: ChokidarOptions, handler: Handler ): ChokidarWatcher // Basically the same API as chokidar, plus the "handler" function which will handle all events
function watcher ( paths: ChokidarPaths, options: ChokidarOptions, handlers: Handlers ): ChokidarWatcher // Basically the same API as chokidar, plus the "handlers" object
import watcher from 'chokidar-watcher';
const options = {
usePolling: true,
interval: 100
};
const handlers = {
add ( filePath, stats ) { /* ... */ },
change ( filePath, stats ) { /* ... */ },
rename ( prevFilePath, nextFilePath ) { /* ... */ },
unlink ( filePath ) { /* ... */ }
};
watcher ( '/Users/fabio/Desktop', options, handlers );
MIT © Fabio Spampinato