1 | import { FSWatcher } from 'fs';
|
2 |
|
3 | /**
|
4 | * Watch for changes on `filename`, where filename is either a file or a directory.
|
5 | * The second argument is optional.
|
6 | *
|
7 | * If `options` is provided as a string, it specifies the encoding.
|
8 | * Otherwise `options` should be passed as an object.
|
9 | *
|
10 | * The listener callback gets two arguments, `(eventType, filePath)`,
|
11 | * which is the same with `fs.watch`.
|
12 | * `eventType` is either `update` or `remove`,
|
13 | * `filePath` is the name of the file which triggered the event.
|
14 | *
|
15 | * @param {Filename} filename File or directory to watch.
|
16 | * @param {Options|string} options
|
17 | * @param {Function} callback
|
18 | */
|
19 | declare function watch(pathName: PathName): Watcher;
|
20 | declare function watch(pathName: PathName, options: Options) : Watcher;
|
21 | declare function watch(pathName: PathName, callback: Callback): Watcher;
|
22 | declare function watch(pathName: PathName, options: Options, callback: Callback): Watcher;
|
23 |
|
24 | type EventType = 'update' | 'remove';
|
25 | type Callback = (eventType: EventType, filePath: string) => any;
|
26 | type PathName = string | Array<string>;
|
27 | type FilterReturn = boolean | symbol;
|
28 |
|
29 | type Options = {
|
30 | /**
|
31 | * Indicates whether the process should continue to run
|
32 | * as long as files are being watched.
|
33 | * @default true
|
34 | */
|
35 | persistent ?: boolean;
|
36 |
|
37 | /**
|
38 | * Indicates whether all subdirectories should be watched.
|
39 | * @default false
|
40 | */
|
41 | recursive ?: boolean;
|
42 |
|
43 | /**
|
44 | * Specifies the character encoding to be used for the filename
|
45 | * passed to the listener.
|
46 | * @default 'utf8'
|
47 | */
|
48 | encoding ?: string;
|
49 |
|
50 | /**
|
51 | * Only files which pass this filter (when it returns `true`)
|
52 | * will be sent to the listener.
|
53 | */
|
54 | filter ?: RegExp | ((file: string, skip: symbol) => FilterReturn);
|
55 |
|
56 | /**
|
57 | * Delay time of the callback function.
|
58 | * @default 200
|
59 | */
|
60 | delay ?: number;
|
61 | };
|
62 |
|
63 | export declare interface Watcher extends FSWatcher {
|
64 | /**
|
65 | * Returns `true` if the watcher has been closed.
|
66 | */
|
67 | isClosed(): boolean;
|
68 |
|
69 | /**
|
70 | * Returns all watched paths.
|
71 | */
|
72 | getWatchedPaths(): Array<string>;
|
73 | }
|
74 |
|
75 | export default watch;
|
76 |
|
\ | No newline at end of file |