UNPKG

2.81 kBMarkdownView Raw
1# rrdir
2[![](https://img.shields.io/npm/v/rrdir.svg?style=flat)](https://www.npmjs.org/package/rrdir) [![](https://img.shields.io/npm/dm/rrdir.svg)](https://www.npmjs.org/package/rrdir) [![](https://img.shields.io/bundlephobia/minzip/rrdir.svg)](https://bundlephobia.com/package/rrdir)
3
4> Recursive directory reader with a delightful API
5
6`rrdir` recursively reads a directory and returns entries within via an async iterator or async/sync as Array. It has no dependencies and can typically iterate millions of files in a matter of seconds. Memory usage is `O(1)` for the async iterator and `O(n)` for the Array variants.
7
8## Usage
9```console
10npm i rrdir
11```
12```js
13import {rrdir, rrdirAsync, rrdirSync} from "rrdir";
14
15for await (const entry of rrdir("dir")) {
16 // => {path: 'dir/file', directory: false, symlink: false}
17}
18
19const entries = await rrdirAsync("dir");
20// => [{path: 'dir/file', directory: false, symlink: false}]
21
22const entries = rrdirSync("dir");
23// => [{path: 'dir/file', directory: false, symlink: false}]
24
25```
26
27## API
28### `rrdir(dir, [options])`
29### `rrdirAsync(dir, [options])`
30### `rrdirSync(dir, [options])`
31
32`rrdir` is an async iterator which yields `entry`. `rrdirAsync` and `rrdirSync` return an Array of `entry`.
33
34#### `dir` *String* | *Buffer*
35
36The directory to read, either absolute or relative. Pass a `Buffer` to switch the module into `Buffer` mode which is required to be able to read every file, like for example files with names that are invalid UTF-8 sequences.
37
38#### `options` *Object*
39
40- `stats` *boolean*: Whether to include `entry.stats`. Will reduce performance. Default: `false`.
41- `followSymlinks` *boolean*: Whether to follow symlinks for both recursion and `stat` calls. Default: `false`.
42- `exclude` *Array*: Path globs to exclude, e.g. `["**/*.js"]`. Default: `undefined`.
43- `include` *Array*: Path globs to include, e.g. `["**/*.map"]`. Default: `undefined`.
44- `strict` *boolean*: Whether to throw immediately when reading an entry fails. Default: `false`.
45- `insensitive` *boolean: Whether `include` and `exclude` match case-insensitively. Default: `false`.
46
47#### `entry` *Object*
48
49- `path` *string* | *Buffer*: The path to the entry, will be relative if `dir` is given relative. If `dir` is a `Buffer`, this will be too. Always present.
50- `directory` *boolean*: Boolean indicating whether the entry is a directory. `undefined` on error.
51- `symlink` *boolean*: Boolean indicating whether the entry is a symbolic link. `undefined` on error.
52- `stats` *Object*: A [`fs.stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats) object, present when `options.stats` is set. `undefined` on error.
53- `err` *Error*: Any error encountered while reading this entry. `undefined` on success.
54
55© [silverwind](https://github.com/silverwind), distributed under BSD licence