watch-file-safe

1.0.1 • Public • Published

Watch a file for changes.

Provides a simplified wrapper around chokidar for watching a file.

Installation

yarn add watch-file-safe
npm install watch-file-safe

API

Usage

import watchFile from "watch-file-safe";
 
const watcher = watchFile("/path/to/file.txt");
 
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}`);
});
 
// To stop watching:
watcher.stop();

Types

import watchFile, { Watcher, EventCallback } from "watch-file-safe";
 
function watchFile(path: string): Watcher;
 
type EventCallback = (path: string) => void;
 
type Watcher = {
  onAdd: (cb: EventCallback) => Watcher;
  onRemove: (cb: EventCallback) => Watcher;
  onChange: (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

Package Sidebar

Install

npm i watch-file-safe

Weekly Downloads

310

Version

1.0.1

License

MIT

Unpacked Size

6.55 kB

Total Files

7

Last publish

Collaborators

  • bconnorwhite