UNPKG

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