diff --git a/README.md b/README.md index e182a0dd..39250a98 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ chokidar.watch('.').on('all', (event, path) => { // Initialize watcher. const watcher = chokidar.watch('file, dir, or array', { - ignored: /(^|[\/\\])\../, // ignore dotfiles + ignored: (path, stats) => stats?.isFile() && !path.endsWith('.js'), // only watch js files persistent: true }); @@ -261,6 +261,30 @@ execute a command on each change, or get a stdio stream of change events. Details in [`.github/full_changelog.md`](.github/full_changelog.md). +If you've used globs before and want do replicate the functionality with v4: + +```js +// v3 +chok.watch('**/*.js'); +chok.watch("./directory/**/*"); + +// v4 +chok.watch('.', { + ignored: (path, stats) => stats?.isFile() && !path.endsWith('.js'), // only watch js files +}); +chok.watch('./directory'); + +// other way +import { glob } from 'node:fs/promises'; +const watcher = watch(await glob('**/*.js')); + +// unwatching +// v3 +chok.unwatch('**/*.js'); +// v4 +chok.unwatch(await glob('**/*.js')); +``` + ## Also Why was chokidar named this way? What's the meaning behind it?