summaryrefslogtreecommitdiff
path: root/includes/external/chvfs/node_modules/node-watch/lib/watch.d.ts
blob: 9eca5d4c9044b70b55af116e6bfa3f270e12cc2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { FSWatcher } from 'fs';

/**
 *  Watch for changes on `filename`, where filename is either a file or a directory.
 *  The second argument is optional.
 *
 *  If `options` is provided as a string, it specifies the encoding.
 *  Otherwise `options` should be passed as an object.
 *
 *  The listener callback gets two arguments, `(eventType, filePath)`,
 *  which is the same with `fs.watch`.
 *  `eventType` is either `update` or `remove`,
 *  `filePath` is the name of the file which triggered the event.
 *
 * @param {Filename} filename File or directory to watch.
 * @param {Options|string} options
 * @param {Function} callback
 */
declare function watch(pathName: PathName): Watcher;
declare function watch(pathName: PathName, options: Options) : Watcher;
declare function watch(pathName: PathName, callback: Callback): Watcher;
declare function watch(pathName: PathName, options: Options, callback: Callback): Watcher;

type EventType = 'update' | 'remove';
type Callback = (eventType: EventType, filePath: string) => any;
type PathName = string | Array<string>;
type FilterReturn = boolean | symbol;

type Options = {
  /**
   * Indicates whether the process should continue to run
   * as long as files are being watched.
   * @default true
   */
  persistent ?: boolean;

  /**
   * Indicates whether all subdirectories should be watched.
   * @default false
   */
  recursive ?: boolean;

  /**
   * Specifies the character encoding to be used for the filename
   * passed to the listener.
   * @default 'utf8'
   */
  encoding ?: string;

  /**
   * Only files which pass this filter (when it returns `true`)
   * will be sent to the listener.
   */
  filter ?: RegExp | ((file: string, skip: symbol) => FilterReturn);

  /**
   * Delay time of the callback function.
   * @default 200
   */
  delay ?: number;
};

declare interface Watcher extends FSWatcher {
  /**
   * Returns `true` if the watcher has been closed.
   */
  isClosed(): boolean;

  /**
   * Returns all watched paths.
   */
  getWatchedPaths(): Array<string>;
}

export default watch;