|
sfcode
An Online Competing and Development Environment
|
Recursive version of fs.readdir. Exposes a stream API and a promise API.
For more examples, check out examples directory.
const stream = readdirp(root[, options]) — Stream API
stream of entry infosfor await (const entry of stream) with node.js 10+ (asyncIterator).[entry info](#entryinfo) for every file / dir. -on('warn', (error) => {})non-fatalErrorthat prevents a file / dir from being processed. Example: inaccessible to the user. -on('error', (error) => {})fatalErrorwhich also ends the stream. Example: illegal options where passed. -on('end')— we are done. Called when all entries were found and no more will be emitted. -on('close')— stream is destroyed viastream.destroy()`. Could be useful if you want to manually abort even on a non fatal error. At that point the stream is no longer readable and no more entries, warning or errors are emittedconst entries = await readdirp.promise(root[, options]) — Promise API. Returns a list of entry infos.
First argument is awalys root, path in which to start reading and recursing into subdirectories.
fileFilter: ["*.js"]: filter to include or exclude files. A Function, Glob string or Array of glob strings.*.js) which is matched using picomatch, so go there for more information. Globstars (**) are not supported since specifying a recursive pattern for an already recursive function doesn't make sense. Negated globs (as explained in the minimatch documentation) are allowed, e.g., !*.txt matches everything but text files.includes all JavaScript and Json files. ['!.git', '!node_modules']‘ includes all directories except the ’.git' and 'node_modules'.: filter to include/exclude directories found and to recurse into. Directories that do not pass a filter will not be recursed into. -depth: 5: depth at which to stop recursing even if more subdirectories are found -type: 'files': determines if data events on the stream should be emitted for'files'(default),'directories','files_directories', or'all'. Setting to'all'will also include entries for other types of file descriptors like character devices, unix sockets and named pipes. -alwaysStat: false: always returnstatsproperty for every file. Default isfalse, readdirp will returnDirententries. Setting it totruecan double readdir execution time - use it only when you need filesize,mtimeetc. Cannot be enabled on node <10.10.0. -lstat: false: include symlink entries in the stream along with files. Whentrue,fs.lstat<tt>would be used instead offs.stat`Has the following properties:
: path to the file/directory (relative to given root) -fullPath: '/Users/dev/projects/app/assets/javascripts/react.js': full path to the file/directory found -basename: 'react.js': name of the file/directory -dirent: fs.Dirent<tt>: built-in [dir entry object](https://nodejs.org/api/fs.html#fs_class_fs_dirent) - only withalwaysStat: false -stats: fs.Stats<tt>: built in [stat object](https://nodejs.org/api/fs.html#fs_class_fs_stats) - only withalwaysStat: true`highWaterMark option. Fixes race conditions related to for-await looping.bigint support to stat output on Windows. This is backwards-incompatible for some cases. Be careful. It you use it incorrectly, you'll see "TypeError: Cannot mix BigInt and other types, use explicit conversions".readdirp(options) to readdirp(root, options)entryType option to typeto'files_directories' -EntryInfo
- Renamedstat
tostats
- Emitted only whenalwaysStat: true
-direntis emitted instead ofstatsby default withalwaysStat: false
Renamednametobasename
RemovedparentDirandfullParentDir` properties
Supported node.js versions:
- 3.x: node 8+
- 2.x: node 0.6+
Copyright (c) 2012-2019 Thorsten Lorenz, Paul Miller (https://paulmillr.com)
MIT License, see [LICENSE](LICENSE) file.