watch-dir-safe

1.0.2 • Public • Published

Watch a directory for changes.

Provides a simplified wrapper around chokidar for watching a directory.

Installation

yarn add watch-dir-safe
npm install watch-dir-safe

API

Usage

import watchDir from "watch-dir-safe";
 
const watcher = watchDir("/path/to/dir");
 
watcher.onReady(() => {
  console.log(`Ready`);
}).onAdd((path: string) => {
  console.log(`Added ${path}`);
}).onChange((path: string) => {
  console.log(`Changed ${path}`);
}).onRemove((path: string) => {
  console.log(`Removed ${path}`);
}).onAddDir((path: string) => {
  console.log(`Added dir ${path}`);
}).onRemoveDir((path: string) => {
  console.log(`Added dir ${path}`);
});
 
// To stop watching:
watcher.stop();

Types

import watchDir, { Watcher, EventCallback } from "watch-dir-safe";
 
function watchDir(path: string): Watcher;
 
type EventCallback = (path: string) => void;
 
type Watcher = {
  onAdd: (cb: EventCallback) => Watcher;
  onRemove: (cb: EventCallback) => Watcher;
  onChange: (cb: EventCallback) => Watcher;
  onAddDir: (cb: EventCallback) => Watcher;
  onRemoveDir: (cb: EventCallback) => Watcher;
  onReady: (cb: () => void) => Watcher;
  stop: () => Promise<boolean>;
}

Dependenciesdependencies

  • chokidar: A neat wrapper around node.js fs.watch / fs.watchFile / fsevents.

Dev DependenciesDavid


License license

MIT


Related Packages

Readme

Keywords

none

Package Sidebar

Install

npm i watch-dir-safe

Weekly Downloads

488

Version

1.0.2

License

MIT

Unpacked Size

7.07 kB

Total Files

7

Last publish

Collaborators

  • bconnorwhite