rrdir 10.0.4 → 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.
Files changed (3) hide show
  1. package/README.md +1 -0
  2. package/index.js +10 -8
  3. package/package.json +5 -5
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,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 = Object.assign({}, defaults, 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 = Object.assign({}, defaults, 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 = Object.assign({}, defaults, 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.0.4",
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",
@@ -16,11 +16,11 @@
16
16
  ],
17
17
  "devDependencies": {
18
18
  "eslint": "8.24.0",
19
- "eslint-config-silverwind": "55.0.0",
20
- "jest": "29.0.3",
19
+ "eslint-config-silverwind": "57.0.1",
20
+ "jest": "29.1.2",
21
21
  "tempy": "3.0.0",
22
- "updates": "13.1.7",
23
- "versions": "9.3.2"
22
+ "updates": "13.1.8",
23
+ "versions": "9.3.3"
24
24
  },
25
25
  "keywords": [
26
26
  "recursive readdir",