UNPKG

@thi.ng/file-io

Version:

Assorted file I/O utils (w/ logging support) for NodeJS/Bun

53 lines 1.91 kB
import { type Event, type IClear, type INotify, type IObjectOf, type Listener, type Predicate } from "@thi.ng/api"; import type { ILogger } from "@thi.ng/logger"; import { type FSWatcher } from "node:fs"; export interface WatcherOpts { /** * Number of milliseconds between observing a file change and notifying * attached listeners. * * @defaultValue 100 */ delay: number; /** * Logger instance for showing debug info (must have DEBUG level enabled) */ logger: ILogger; } export interface PathWatchOpts { /** * If enabled (default) and if the path refers to a directory, any file * changes within that dir (or any subdir) will trigger an event. */ recursive: boolean; /** * File extension filter. If given, events are only triggered for paths * matching this filter. */ ext: string | RegExp | Predicate<string>; } export declare const EVENT_ADDED = "added"; export declare const EVENT_CHANGED = "changed"; export declare const EVENT_REMOVED = "removed"; export declare class Watcher implements IClear, INotify { watchers: IObjectOf<FSWatcher>; opts: WatcherOpts; protected _signal: boolean; constructor(opts?: Partial<WatcherOpts>); addAll(paths: (string | [string, Partial<PathWatchOpts>])[]): void; add(path: string, opts?: Partial<PathWatchOpts>): boolean; remove(path: string): boolean; removeAll(paths: Iterable<string>): void; clear(): void; installSignalHandler(): void; addListener(id: string, fn: Listener<string>, scope?: any): boolean; removeListener(id: string, fn: Listener<string>, scope?: any): boolean; notify(event: Event<string>): boolean; } /** * Creates a new {@link Watcher} instance with given options. * * @param opts */ export declare const fileWatcher: (opts?: Partial<WatcherOpts>) => Watcher; //# sourceMappingURL=watch.d.ts.map