rrdir 10.1.3 → 11.0.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.
Files changed (3) hide show
  1. package/index.js +12 -11
  2. package/package.json +7 -7
  3. package/LICENSE +0 -22
package/index.js CHANGED
@@ -30,22 +30,20 @@ function build(dirent, path, stats, opts) {
30
30
  };
31
31
  }
32
32
 
33
- export function pathGlobToRegex(glob, {flags = undefined, sep = "/"} = {flags: undefined, sep: "/"}) {
34
- if (sep === "\\") sep = "\\\\";
33
+ export function pathGlobToRegex(glob, {flags = undefined} = {flags: undefined}) {
35
34
  return new RegExp(`${glob
36
35
  .replace(/[|\\{}()[\]^$+.-]/g, "\\$&")
37
- .replace(new RegExp(`\\*\\*${sep}\\*`, "g"), ".*")
38
- .replace(/^\*\*/g, ".*")
39
- .replace(new RegExp(`${sep}?\\*\\*$`, "g"), ".*")
40
- .replace(new RegExp(`(${sep})\\*\\*(${sep})`, "g"), (_, p1, p2) => `${p1}.*${p2}`)
41
- .replace(/([^.])\*/g, (_, p1) => `${p1}[^${sep}]*`)
36
+ .replace(/\*\*\/\*/, ".*")
37
+ .replace(/\*\*/g, ".*")
38
+ .replace(/\//g, "[/\\\\]")
39
+ .replace(/([^.])\*/g, (_, p1) => `${p1}[^/\\\\]*`)
42
40
  .replaceAll("**", "*")
43
41
  .replaceAll("?", ".")
44
42
  }$`, flags);
45
43
  }
46
44
 
47
45
  function makeMatcher(filters, flags) {
48
- const regexes = filters.map(filter => pathGlobToRegex(filter, {flags, sep}));
46
+ const regexes = filters.map(filter => pathGlobToRegex(filter, {flags}));
49
47
  return str => {
50
48
  for (const regex of regexes) {
51
49
  if (regex.test(str)) return true;
@@ -84,7 +82,8 @@ export async function* rrdir(dir, opts = {}, {includeMatcher, excludeMatcher, en
84
82
  if (excludeMatcher?.(encoding === "buffer" ? String(path) : path)) continue;
85
83
 
86
84
  const isSymbolicLink = opts.followSymlinks && dirent.isSymbolicLink();
87
- const isIncluded = !includeMatcher || includeMatcher(encoding === "buffer" ? String(path) : path);
85
+ const encodedPath = encoding === "buffer" ? String(path) : path;
86
+ const isIncluded = !includeMatcher || includeMatcher(encodedPath);
88
87
  let stats;
89
88
 
90
89
  if (isIncluded) {
@@ -135,7 +134,8 @@ export async function rrdirAsync(dir, opts = {}, {includeMatcher, excludeMatcher
135
134
  if (excludeMatcher?.(encoding === "buffer" ? String(path) : path)) return;
136
135
 
137
136
  const isSymbolicLink = opts.followSymlinks && dirent.isSymbolicLink();
138
- const isIncluded = !includeMatcher || includeMatcher(encoding === "buffer" ? String(path) : path);
137
+ const encodedPath = encoding === "buffer" ? String(path) : path;
138
+ const isIncluded = !includeMatcher || includeMatcher(encodedPath);
139
139
  let stats;
140
140
 
141
141
  if (isIncluded) {
@@ -188,7 +188,8 @@ export function rrdirSync(dir, opts = {}, {includeMatcher, excludeMatcher, encod
188
188
  if (excludeMatcher?.(encoding === "buffer" ? String(path) : path)) continue;
189
189
 
190
190
  const isSymbolicLink = opts.followSymlinks && dirent.isSymbolicLink();
191
- const isIncluded = !includeMatcher || includeMatcher(encoding === "buffer" ? String(path) : path);
191
+ const encodedPath = encoding === "buffer" ? String(path) : path;
192
+ const isIncluded = !includeMatcher || includeMatcher(encodedPath);
192
193
  let stats;
193
194
 
194
195
  if (isIncluded) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rrdir",
3
- "version": "10.1.3",
3
+ "version": "11.0.1",
4
4
  "description": "Recursive directory reader with a delightful API",
5
5
  "author": "silverwind <me@silverwind.io>",
6
6
  "repository": "silverwind/rrdir",
@@ -9,17 +9,17 @@
9
9
  "type": "module",
10
10
  "sideEffects": false,
11
11
  "engines": {
12
- "node": ">=14"
12
+ "node": ">=16"
13
13
  },
14
14
  "files": [
15
15
  "index.js"
16
16
  ],
17
17
  "devDependencies": {
18
- "eslint": "8.36.0",
19
- "eslint-config-silverwind": "65.1.3",
20
- "updates": "13.2.9",
21
- "versions": "10.4.2",
22
- "vitest": "0.29.7"
18
+ "eslint": "8.39.0",
19
+ "eslint-config-silverwind": "67.0.1",
20
+ "updates": "14.1.0",
21
+ "versions": "11.0.0",
22
+ "vitest": "0.30.1"
23
23
  },
24
24
  "keywords": [
25
25
  "recursive readdir",
package/LICENSE DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) silverwind
2
- All rights reserved.
3
-
4
- Redistribution and use in source and binary forms, with or without
5
- modification, are permitted provided that the following conditions are met:
6
-
7
- 1. Redistributions of source code must retain the above copyright notice, this
8
- list of conditions and the following disclaimer.
9
- 2. Redistributions in binary form must reproduce the above copyright notice,
10
- this list of conditions and the following disclaimer in the documentation
11
- and/or other materials provided with the distribution.
12
-
13
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.