项目作者: fabiospampinato

项目描述 :
File system watcher based on chokidar that emits add/change/rename/unlink events.
高级语言: TypeScript
项目地址: git://github.com/fabiospampinato/chokidar-watcher.git
创建时间: 2019-05-08T19:09:20Z
项目社区:https://github.com/fabiospampinato/chokidar-watcher

开源协议:MIT License

下载


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

  1. npm install --save chokidar-watcher

API

This library provides the following interface:

  1. type Handler = ( filePath: string, nextFilePathOrStats?: import ( 'fs' ).Stats | string ) => void;
  2. type Handlers = {
  3. add?: ( filePath: string, stats: fs.Stats ) => void,
  4. change?: ( filePath: string, stats: fs.Stats ) => void,
  5. rename?: ( prevFilePath: string, nextFilePath: string ) => void,
  6. unlink?: ( filePath: string ) => void
  7. };
  8. function watcher ( paths: ChokidarPaths, options: ChokidarOptions, handler: Handler ): ChokidarWatcher // Basically the same API as chokidar, plus the "handler" function which will handle all events
  9. function watcher ( paths: ChokidarPaths, options: ChokidarOptions, handlers: Handlers ): ChokidarWatcher // Basically the same API as chokidar, plus the "handlers" object

Usage

  1. import watcher from 'chokidar-watcher';
  2. const options = {
  3. usePolling: true,
  4. interval: 100
  5. };
  6. const handlers = {
  7. add ( filePath, stats ) { /* ... */ },
  8. change ( filePath, stats ) { /* ... */ },
  9. rename ( prevFilePath, nextFilePath ) { /* ... */ },
  10. unlink ( filePath ) { /* ... */ }
  11. };
  12. watcher ( '/Users/fabio/Desktop', options, handlers );

License

MIT © Fabio Spampinato