rrdir 10.0.3 → 10.1.0
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 +1 -0
- package/index.js +14 -8
- package/package.json +6 -7
package/README.md
CHANGED
|
@@ -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
|
@@ -10,8 +10,11 @@ const defaults = {
|
|
|
10
10
|
followSymlinks: false,
|
|
11
11
|
exclude: undefined,
|
|
12
12
|
include: undefined,
|
|
13
|
+
insensitive: false,
|
|
13
14
|
};
|
|
14
15
|
|
|
16
|
+
const escRe = str => str.replace(/[|\\{}()[\]^$+*?.-]/g, "\\$&");
|
|
17
|
+
|
|
15
18
|
function makePath(entry, dir, encoding) {
|
|
16
19
|
if (encoding === "buffer") {
|
|
17
20
|
return dir === "." ? entry.name : Buffer.from([...dir, ...sepBuffer, ...entry.name]);
|
|
@@ -29,8 +32,10 @@ function build(dirent, path, stats, opts) {
|
|
|
29
32
|
};
|
|
30
33
|
}
|
|
31
34
|
|
|
32
|
-
function makeMatcher(filters) {
|
|
33
|
-
const res = filters.map(f =>
|
|
35
|
+
function makeMatcher(filters, flags) {
|
|
36
|
+
const res = filters.map(f => {
|
|
37
|
+
return new RegExp(`${escRe(f).replace(/\\\*+/g, ".*").replace(/\/\.\*/, ".*")}$`, flags);
|
|
38
|
+
});
|
|
34
39
|
return str => {
|
|
35
40
|
for (const re of res) {
|
|
36
41
|
if (re.test(str)) return true;
|
|
@@ -39,16 +44,17 @@ function makeMatcher(filters) {
|
|
|
39
44
|
};
|
|
40
45
|
}
|
|
41
46
|
|
|
42
|
-
function makeMatchers({include, exclude}) {
|
|
47
|
+
function makeMatchers({include, exclude, insensitive}) {
|
|
48
|
+
const flags = insensitive ? "i" : "";
|
|
43
49
|
return {
|
|
44
|
-
includeMatcher: include ? makeMatcher(include) : null,
|
|
45
|
-
excludeMatcher: exclude ? makeMatcher(exclude) : null,
|
|
50
|
+
includeMatcher: include ? makeMatcher(include, flags) : null,
|
|
51
|
+
excludeMatcher: exclude ? makeMatcher(exclude, flags) : null,
|
|
46
52
|
};
|
|
47
53
|
}
|
|
48
54
|
|
|
49
55
|
export async function* rrdir(dir, opts = {}, {includeMatcher, excludeMatcher, encoding} = {}) {
|
|
50
56
|
if (includeMatcher === undefined) {
|
|
51
|
-
opts =
|
|
57
|
+
opts = {...defaults, ...opts};
|
|
52
58
|
({includeMatcher, excludeMatcher} = makeMatchers(opts));
|
|
53
59
|
if (/[/\\]$/.test(dir)) dir = dir.substring(0, dir.length - 1);
|
|
54
60
|
encoding = Buffer.isBuffer(dir) ? "buffer" : undefined;
|
|
@@ -98,7 +104,7 @@ export async function* rrdir(dir, opts = {}, {includeMatcher, excludeMatcher, en
|
|
|
98
104
|
|
|
99
105
|
export async function rrdirAsync(dir, opts = {}, {includeMatcher, excludeMatcher, encoding} = {}) {
|
|
100
106
|
if (includeMatcher === undefined) {
|
|
101
|
-
opts =
|
|
107
|
+
opts = {...defaults, ...opts};
|
|
102
108
|
({includeMatcher, excludeMatcher} = makeMatchers(opts));
|
|
103
109
|
if (/[/\\]$/.test(dir)) dir = dir.substring(0, dir.length - 1);
|
|
104
110
|
encoding = Buffer.isBuffer(dir) ? "buffer" : undefined;
|
|
@@ -151,7 +157,7 @@ export async function rrdirAsync(dir, opts = {}, {includeMatcher, excludeMatcher
|
|
|
151
157
|
|
|
152
158
|
export function rrdirSync(dir, opts = {}, {includeMatcher, excludeMatcher, encoding} = {}) {
|
|
153
159
|
if (includeMatcher === undefined) {
|
|
154
|
-
opts =
|
|
160
|
+
opts = {...defaults, ...opts};
|
|
155
161
|
({includeMatcher, excludeMatcher} = makeMatchers(opts));
|
|
156
162
|
if (/[/\\]$/.test(dir)) dir = dir.substring(0, dir.length - 1);
|
|
157
163
|
encoding = Buffer.isBuffer(dir) ? "buffer" : undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rrdir",
|
|
3
|
-
"version": "10.0
|
|
3
|
+
"version": "10.1.0",
|
|
4
4
|
"description": "Recursive directory reader with a delightful API",
|
|
5
5
|
"author": "silverwind <me@silverwind.io>",
|
|
6
6
|
"repository": "silverwind/rrdir",
|
|
@@ -15,13 +15,12 @@
|
|
|
15
15
|
"index.js"
|
|
16
16
|
],
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"eslint": "8.
|
|
19
|
-
"eslint-config-silverwind": "
|
|
20
|
-
"jest": "29.
|
|
21
|
-
"semver": "7.3.7",
|
|
18
|
+
"eslint": "8.24.0",
|
|
19
|
+
"eslint-config-silverwind": "57.0.1",
|
|
20
|
+
"jest": "29.1.2",
|
|
22
21
|
"tempy": "3.0.0",
|
|
23
|
-
"updates": "13.1.
|
|
24
|
-
"versions": "9.3.
|
|
22
|
+
"updates": "13.1.8",
|
|
23
|
+
"versions": "9.3.3"
|
|
25
24
|
},
|
|
26
25
|
"keywords": [
|
|
27
26
|
"recursive readdir",
|