chokidar

  • Version 6.0.0
  • Published
  • 202 kB
  • 1 dependency
  • MIT license

Install

npm i chokidar
yarn add chokidar
pnpm add chokidar

Overview

Minimal and efficient cross-platform file watching library

Index

Variables

variable _default

const _default: { watch: typeof watch; FSWatcher: typeof FSWatcher };

    Functions

    function watch

    watch: (paths: string | string[], options?: ChokidarOptions) => FSWatcher;
    • Instantiates watcher with paths to be tracked.

      Parameter paths

      file / directory paths

      Parameter options

      opts, such as atomic, awaitWriteFinish, ignored, and others

      Returns

      an instance of FSWatcher for chaining.

      Example 1

      const watcher = watch('.').on('all', (event, path) => { console.log(event, path); }); watch('.', { atomic: true, awaitWriteFinish: true, ignored: (f, stats) => stats?.isFile() && !f.endsWith('.js') })

    Classes

    class FSWatcher

    class FSWatcher extends EventEmitter<FSWatcherEventMap> {}
    • Watches files & directories for changes. Emitted events: add, addDir, change, unlink, unlinkDir, all, error

      new FSWatcher() .add(directories) .on('add', path => log('File', path, 'was added'))

    constructor

    constructor(
    _opts?: Partial<
    BasicOptions & {
    ignored: Matcher | Matcher[];
    awaitWriteFinish: boolean | Partial<AWF>;
    }
    >,
    scheduler?: Scheduler
    );

      property closed

      readonly closed: boolean;

        property options

        options: FSWInstanceOptions;

          method add

          add: (paths_: Path | Path[]) => FSWatcher;
          • Adds paths to be watched on an existing FSWatcher instance.

            Parameter paths_

            file or file list

          method close

          close: () => Promise<void>;
          • Close watchers and remove all listeners from watched paths.

          method getWatched

          getWatched: () => Record<string, string[]>;
          • Expose list of watched paths. The result has a null prototype, so a directory named __proto__ is an ordinary own key.

          method unwatch

          unwatch: (paths_: Path | Path[]) => FSWatcher;
          • Close watchers or start ignoring events from specified paths.

          Interfaces

          interface FSWatcherEventMap

          interface FSWatcherEventMap {}

            property [EV.ADD_DIR]

            [EV.ADD_DIR]: EmitArgs;

              property [EV.ADD]

              [EV.ADD]: EmitArgs;

                property [EV.ALL]

                [EV.ALL]: [event: EventName, ...EmitArgs];

                  property [EV.CHANGE]

                  [EV.CHANGE]: EmitArgs;

                    property [EV.ERROR]

                    [EV.ERROR]: Parameters<WatchHandlers['errHandler']>;

                      property [EV.RAW]

                      [EV.RAW]: Parameters<WatchHandlers['rawEmitter']>;

                        property [EV.READY]

                        [EV.READY]: [];
                          [EV.UNLINK_DIR]: EmitArgs;

                            property [EV.UNLINK]

                            [EV.UNLINK]: EmitArgs;

                              interface Scheduler

                              interface Scheduler {}

                                method clearTimeout

                                clearTimeout: (timer: SchedulerTimer | undefined) => void;

                                  method now

                                  now: () => number;

                                    method setTimeout

                                    setTimeout: (callback: () => void, delay: number) => SchedulerTimer;

                                      interface SchedulerTimer

                                      interface SchedulerTimer {}

                                        method ref

                                        ref: () => SchedulerTimer;

                                          method unref

                                          unref: () => SchedulerTimer;

                                            Type Aliases

                                            type AWF

                                            type AWF = {
                                            stabilityThreshold: number;
                                            pollInterval: number;
                                            };

                                              type BackendStrategy

                                              type BackendStrategy =
                                              | 'polling'
                                              | 'native-per-directory'
                                              | 'native-recursive-preferred';

                                                type ChokidarOptions

                                                type ChokidarOptions = Partial<
                                                BasicOptions & {
                                                ignored: Matcher | Matcher[];
                                                awaitWriteFinish: boolean | Partial<AWF>;
                                                }
                                                >;

                                                  type EmitArgs

                                                  type EmitArgs = [path: Path, stats?: Stats];

                                                    type EmitArgsWithName

                                                    type EmitArgsWithName = [event: EventName, ...EmitArgs];

                                                      type EmitErrorArgs

                                                      type EmitErrorArgs = [error: Error, stats?: Stats];

                                                        type FSWInstanceOptions

                                                        type FSWInstanceOptions = BasicOptions & {
                                                        ignored: readonly Matcher[];
                                                        awaitWriteFinish: false | AWF;
                                                        backendStrategy: BackendStrategy;
                                                        backendCapabilities: import('./backend.js').BackendCapabilities;
                                                        };

                                                          type Matcher

                                                          type Matcher = string | RegExp | MatchFunction | MatcherObject;

                                                            type MatcherObject

                                                            type MatcherObject = {
                                                            path: string;
                                                            recursive?: boolean;
                                                            };

                                                              type MatchFunction

                                                              type MatchFunction = (val: string, stats?: Stats) => boolean;

                                                                type Throttler

                                                                type Throttler = {
                                                                timeoutObject: SchedulerTimer;
                                                                clear: (invokeRelease?: boolean) => number;
                                                                count: number;
                                                                };

                                                                  type ThrottleType

                                                                  type ThrottleType = 'readdir' | 'watch' | 'add' | 'remove' | 'change';

                                                                    type WatchBackend

                                                                    type WatchBackend = 'auto' | 'native' | 'native-recursive' | 'polling';

                                                                      Package Files (2)

                                                                      Dependencies (1)

                                                                      Dev Dependencies (4)

                                                                      Peer Dependencies (0)

                                                                      No peer dependencies.

                                                                      Badge

                                                                      To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                      You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/chokidar.

                                                                      • Markdown
                                                                        [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/chokidar)
                                                                      • HTML
                                                                        <a href="https://www.jsdocs.io/package/chokidar"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>