rrdir 10.0.4 → 10.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/index.js +13 -11
- package/package.json +6 -7
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
> Recursive directory reader with a delightful API
|
|
5
5
|
|
|
6
|
-
`rrdir` recursively reads a directory and returns entries within via an async iterator or async/sync as Array. It has
|
|
6
|
+
`rrdir` recursively reads a directory and returns entries within via an async iterator or async/sync as Array. It has zero 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
7
|
|
|
8
8
|
## Usage
|
|
9
9
|
```console
|
|
@@ -42,6 +42,7 @@ The directory to read, either absolute or relative. Pass a `Buffer` to switch th
|
|
|
42
42
|
- `exclude` *Array*: Path globs to exclude, e.g. `["**/*.js"]`. Default: `undefined`.
|
|
43
43
|
- `include` *Array*: Path globs to include, e.g. `["**/*.map"]`. Default: `undefined`.
|
|
44
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`.
|
|
45
46
|
|
|
46
47
|
#### `entry` *Object*
|
|
47
48
|
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {readdir, stat, lstat} from "fs/promises";
|
|
2
|
-
import {readdirSync, statSync, lstatSync} from "fs";
|
|
3
|
-
import {sep} from "path";
|
|
1
|
+
import {readdir, stat, lstat} from "node:fs/promises";
|
|
2
|
+
import {readdirSync, statSync, lstatSync} from "node:fs";
|
|
3
|
+
import {sep} from "node:path";
|
|
4
4
|
|
|
5
5
|
const sepBuffer = Buffer.from(sep);
|
|
6
6
|
|
|
@@ -10,6 +10,7 @@ const defaults = {
|
|
|
10
10
|
followSymlinks: false,
|
|
11
11
|
exclude: undefined,
|
|
12
12
|
include: undefined,
|
|
13
|
+
insensitive: false,
|
|
13
14
|
};
|
|
14
15
|
|
|
15
16
|
const escRe = str => str.replace(/[|\\{}()[\]^$+*?.-]/g, "\\$&");
|
|
@@ -31,9 +32,9 @@ function build(dirent, path, stats, opts) {
|
|
|
31
32
|
};
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
function makeMatcher(filters) {
|
|
35
|
+
function makeMatcher(filters, flags) {
|
|
35
36
|
const res = filters.map(f => {
|
|
36
|
-
return new RegExp(`${escRe(f).replace(/\\\*+/g, ".*").replace(/\/\.\*/, ".*")}
|
|
37
|
+
return new RegExp(`${escRe(f).replace(/\\\*+/g, ".*").replace(/\/\.\*/, ".*")}$`, flags);
|
|
37
38
|
});
|
|
38
39
|
return str => {
|
|
39
40
|
for (const re of res) {
|
|
@@ -43,16 +44,17 @@ function makeMatcher(filters) {
|
|
|
43
44
|
};
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
function makeMatchers({include, exclude}) {
|
|
47
|
+
function makeMatchers({include, exclude, insensitive}) {
|
|
48
|
+
const flags = insensitive ? "i" : "";
|
|
47
49
|
return {
|
|
48
|
-
includeMatcher: include ? makeMatcher(include) : null,
|
|
49
|
-
excludeMatcher: exclude ? makeMatcher(exclude) : null,
|
|
50
|
+
includeMatcher: include ? makeMatcher(include, flags) : null,
|
|
51
|
+
excludeMatcher: exclude ? makeMatcher(exclude, flags) : null,
|
|
50
52
|
};
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
export async function* rrdir(dir, opts = {}, {includeMatcher, excludeMatcher, encoding} = {}) {
|
|
54
56
|
if (includeMatcher === undefined) {
|
|
55
|
-
opts =
|
|
57
|
+
opts = {...defaults, ...opts};
|
|
56
58
|
({includeMatcher, excludeMatcher} = makeMatchers(opts));
|
|
57
59
|
if (/[/\\]$/.test(dir)) dir = dir.substring(0, dir.length - 1);
|
|
58
60
|
encoding = Buffer.isBuffer(dir) ? "buffer" : undefined;
|
|
@@ -102,7 +104,7 @@ export async function* rrdir(dir, opts = {}, {includeMatcher, excludeMatcher, en
|
|
|
102
104
|
|
|
103
105
|
export async function rrdirAsync(dir, opts = {}, {includeMatcher, excludeMatcher, encoding} = {}) {
|
|
104
106
|
if (includeMatcher === undefined) {
|
|
105
|
-
opts =
|
|
107
|
+
opts = {...defaults, ...opts};
|
|
106
108
|
({includeMatcher, excludeMatcher} = makeMatchers(opts));
|
|
107
109
|
if (/[/\\]$/.test(dir)) dir = dir.substring(0, dir.length - 1);
|
|
108
110
|
encoding = Buffer.isBuffer(dir) ? "buffer" : undefined;
|
|
@@ -155,7 +157,7 @@ export async function rrdirAsync(dir, opts = {}, {includeMatcher, excludeMatcher
|
|
|
155
157
|
|
|
156
158
|
export function rrdirSync(dir, opts = {}, {includeMatcher, excludeMatcher, encoding} = {}) {
|
|
157
159
|
if (includeMatcher === undefined) {
|
|
158
|
-
opts =
|
|
160
|
+
opts = {...defaults, ...opts};
|
|
159
161
|
({includeMatcher, excludeMatcher} = makeMatchers(opts));
|
|
160
162
|
if (/[/\\]$/.test(dir)) dir = dir.substring(0, dir.length - 1);
|
|
161
163
|
encoding = Buffer.isBuffer(dir) ? "buffer" : undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rrdir",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.1.1",
|
|
4
4
|
"description": "Recursive directory reader with a delightful API",
|
|
5
5
|
"author": "silverwind <me@silverwind.io>",
|
|
6
6
|
"repository": "silverwind/rrdir",
|
|
@@ -15,12 +15,11 @@
|
|
|
15
15
|
"index.js"
|
|
16
16
|
],
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"eslint": "8.
|
|
19
|
-
"eslint-config-silverwind": "
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"versions": "9.3.2"
|
|
18
|
+
"eslint": "8.29.0",
|
|
19
|
+
"eslint-config-silverwind": "65.0.0",
|
|
20
|
+
"updates": "13.2.4",
|
|
21
|
+
"versions": "10.4.1",
|
|
22
|
+
"vitest": "0.25.8"
|
|
24
23
|
},
|
|
25
24
|
"keywords": [
|
|
26
25
|
"recursive readdir",
|