rrdir 10.0.1 → 10.0.3

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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/index.js +12 -25
  3. package/package.json +3 -3
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 minimal 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.
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
7
 
8
8
  ## Usage
9
9
  ```console
package/index.js CHANGED
@@ -30,11 +30,10 @@ function build(dirent, path, stats, opts) {
30
30
  }
31
31
 
32
32
  function makeMatcher(filters) {
33
+ const res = filters.map(f => new RegExp(`${f.replace(/\*+/g, ".*").replace(/\/\.\*/, ".*")}$`));
33
34
  return str => {
34
- for (const filter of filters) {
35
- const re = new RegExp(`${filter.replace(/\*+/g, ".*").replace(/\/\.\*/, ".*")}$`);
36
- const matches = re.test(str);
37
- if (matches) return true;
35
+ for (const re of res) {
36
+ if (re.test(str)) return true;
38
37
  }
39
38
  return false;
40
39
  };
@@ -56,21 +55,17 @@ export async function* rrdir(dir, opts = {}, {includeMatcher, excludeMatcher, en
56
55
  }
57
56
 
58
57
  let dirents = [];
59
-
60
58
  try {
61
59
  dirents = await readdir(dir, {encoding, withFileTypes: true});
62
60
  } catch (err) {
63
- if (opts.strict) {
64
- throw err;
65
- } else {
66
- yield {path: dir, err};
67
- }
61
+ if (opts.strict) throw err;
62
+ yield {path: dir, err};
68
63
  }
69
64
  if (!dirents.length) return;
70
65
 
71
66
  for (const dirent of dirents) {
72
67
  const path = makePath(dirent, dir, encoding);
73
- if (excludeMatcher && excludeMatcher(encoding === "buffer" ? String(path) : path)) continue;
68
+ if (excludeMatcher?.(encoding === "buffer" ? String(path) : path)) continue;
74
69
 
75
70
  const isSymbolicLink = opts.followSymlinks && dirent.isSymbolicLink();
76
71
  const isIncluded = !includeMatcher || includeMatcher(encoding === "buffer" ? String(path) : path);
@@ -111,21 +106,17 @@ export async function rrdirAsync(dir, opts = {}, {includeMatcher, excludeMatcher
111
106
 
112
107
  const results = [];
113
108
  let dirents = [];
114
-
115
109
  try {
116
110
  dirents = await readdir(dir, {encoding, withFileTypes: true});
117
111
  } catch (err) {
118
- if (opts.strict) {
119
- throw err;
120
- } else {
121
- results.push({path: dir, err});
122
- }
112
+ if (opts.strict) throw err;
113
+ results.push({path: dir, err});
123
114
  }
124
115
  if (!dirents.length) return results;
125
116
 
126
117
  await Promise.all(dirents.map(async dirent => {
127
118
  const path = makePath(dirent, dir, encoding);
128
- if (excludeMatcher && excludeMatcher(encoding === "buffer" ? String(path) : path)) return;
119
+ if (excludeMatcher?.(encoding === "buffer" ? String(path) : path)) return;
129
120
 
130
121
  const isSymbolicLink = opts.followSymlinks && dirent.isSymbolicLink();
131
122
  const isIncluded = !includeMatcher || includeMatcher(encoding === "buffer" ? String(path) : path);
@@ -168,21 +159,17 @@ export function rrdirSync(dir, opts = {}, {includeMatcher, excludeMatcher, encod
168
159
 
169
160
  const results = [];
170
161
  let dirents = [];
171
-
172
162
  try {
173
163
  dirents = readdirSync(dir, {encoding, withFileTypes: true});
174
164
  } catch (err) {
175
- if (opts.strict) {
176
- throw err;
177
- } else {
178
- results.push({path: dir, err});
179
- }
165
+ if (opts.strict) throw err;
166
+ results.push({path: dir, err});
180
167
  }
181
168
  if (!dirents.length) return results;
182
169
 
183
170
  for (const dirent of dirents) {
184
171
  const path = makePath(dirent, dir, encoding);
185
- if (excludeMatcher && excludeMatcher(encoding === "buffer" ? String(path) : path)) continue;
172
+ if (excludeMatcher?.(encoding === "buffer" ? String(path) : path)) continue;
186
173
 
187
174
  const isSymbolicLink = opts.followSymlinks && dirent.isSymbolicLink();
188
175
  const isIncluded = !includeMatcher || includeMatcher(encoding === "buffer" ? String(path) : path);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rrdir",
3
- "version": "10.0.1",
3
+ "version": "10.0.3",
4
4
  "description": "Recursive directory reader with a delightful API",
5
5
  "author": "silverwind <me@silverwind.io>",
6
6
  "repository": "silverwind/rrdir",
@@ -20,8 +20,8 @@
20
20
  "jest": "29.0.3",
21
21
  "semver": "7.3.7",
22
22
  "tempy": "3.0.0",
23
- "updates": "13.1.5",
24
- "versions": "9.3.0"
23
+ "updates": "13.1.7",
24
+ "versions": "9.3.2"
25
25
  },
26
26
  "keywords": [
27
27
  "recursive readdir",