Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

Latest commit

 

History

History
53 lines (37 loc) · 1.54 KB

README.md

File metadata and controls

53 lines (37 loc) · 1.54 KB

Chokidar Watcher

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.

Install

npm install --save chokidar-watcher

API

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

Usage

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 );

License

MIT © Fabio Spampinato