UNPKG

1.85 kBTypeScriptView Raw
1type Mode = "auto" | "watch" | "poll";
2
3interface Options {
4 /**
5 * Interval to pass to fs.watchFile.
6 */
7 interval?: number | undefined;
8 /**
9 * Delay for events called in succession for the same file/event in milliseconds.
10 */
11 debounceDelay?: number | undefined;
12 /**
13 * Force the watch mode. Either 'auto' (default),
14 * 'watch' (force native events), or 'poll' (force stat polling).
15 */
16 mode?: Mode | undefined;
17 /**
18 * The current working directory to base file patterns from. Default is `process.cwd()`.
19 */
20 cwd?: string | undefined;
21}
22
23declare namespace gaze {
24 class Gaze {
25 constructor(
26 patterns: string | string[],
27 options?: Options | null,
28 callback?: (error: Error | null, watcher: Gaze) => void,
29 );
30
31 /**
32 * Wrapper for EventEmitter.emit. `added`|`changed`|`renamed`|`deleted` events will also trigger the `all` event.
33 */
34 emit(event: string, ...args: any): boolean;
35
36 /**
37 * Unwatch all files and reset the watch instance.
38 */
39 close(): void;
40
41 /**
42 * Adds file(s) patterns to be watched.
43 */
44 add(patterns: string | string[]): void;
45
46 /**
47 * Removes a file or directory from being watched. Does not recurse directories.
48 */
49 remove(filepath: string): void;
50
51 /**
52 * Returns the currently watched files.
53 */
54 watched(): string[];
55
56 /**
57 * Returns the currently watched files with relative paths.
58 */
59 relative(dir: string, unixify: boolean): string[];
60 }
61}
62
63declare function gaze(
64 patterns: string | string[],
65 options?: Options | null,
66 callback?: (error: Error | null, watcher: gaze.Gaze) => void,
67): void;
68
69export = gaze;