rrdir 11.0.1 → 12.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/README.md +2 -2
  2. package/index.js +7 -25
  3. package/package.json +12 -8
package/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # rrdir
2
- [![](https://img.shields.io/npm/v/rrdir.svg?style=flat)](https://www.npmjs.org/package/rrdir) [![](https://img.shields.io/npm/dm/rrdir.svg)](https://www.npmjs.org/package/rrdir) [![](https://img.shields.io/bundlephobia/minzip/rrdir.svg)](https://bundlephobia.com/package/rrdir)
2
+ [![](https://img.shields.io/npm/v/rrdir.svg?style=flat)](https://www.npmjs.org/package/rrdir) [![](https://img.shields.io/npm/dm/rrdir.svg)](https://www.npmjs.org/package/rrdir) [![](https://packagephobia.com/badge?p=rrdir)](https://packagephobia.com/result?p=rrdir)
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 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.
6
+ `rrdir` recursively reads a directory and returns entries within via an async iterator or async/sync as Array. It 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
@@ -1,6 +1,7 @@
1
1
  import {readdir, stat, lstat} from "node:fs/promises";
2
2
  import {readdirSync, statSync, lstatSync} from "node:fs";
3
3
  import {sep} from "node:path";
4
+ import picomatch from "picomatch";
4
5
 
5
6
  const sepBuffer = Buffer.from(sep);
6
7
 
@@ -30,33 +31,14 @@ function build(dirent, path, stats, opts) {
30
31
  };
31
32
  }
32
33
 
33
- export function pathGlobToRegex(glob, {flags = undefined} = {flags: undefined}) {
34
- return new RegExp(`${glob
35
- .replace(/[|\\{}()[\]^$+.-]/g, "\\$&")
36
- .replace(/\*\*\/\*/, ".*")
37
- .replace(/\*\*/g, ".*")
38
- .replace(/\//g, "[/\\\\]")
39
- .replace(/([^.])\*/g, (_, p1) => `${p1}[^/\\\\]*`)
40
- .replaceAll("**", "*")
41
- .replaceAll("?", ".")
42
- }$`, flags);
43
- }
44
-
45
- function makeMatcher(filters, flags) {
46
- const regexes = filters.map(filter => pathGlobToRegex(filter, {flags}));
47
- return str => {
48
- for (const regex of regexes) {
49
- if (regex.test(str)) return true;
50
- }
51
- return false;
52
- };
53
- }
54
-
55
34
  function makeMatchers({include, exclude, insensitive}) {
56
- const flags = insensitive ? "i" : "";
35
+ const opts = {
36
+ dot: true,
37
+ flags: insensitive ? "i" : undefined,
38
+ };
57
39
  return {
58
- includeMatcher: include ? makeMatcher(include, flags) : null,
59
- excludeMatcher: exclude ? makeMatcher(exclude, flags) : null,
40
+ includeMatcher: include?.length ? picomatch(include, opts) : null,
41
+ excludeMatcher: exclude?.length ? picomatch(exclude, opts) : null,
60
42
  };
61
43
  }
62
44
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rrdir",
3
- "version": "11.0.1",
3
+ "version": "12.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,18 @@
9
9
  "type": "module",
10
10
  "sideEffects": false,
11
11
  "engines": {
12
- "node": ">=16"
12
+ "node": ">=18"
13
13
  },
14
14
  "files": [
15
15
  "index.js"
16
16
  ],
17
17
  "devDependencies": {
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"
18
+ "eslint": "8.47.0",
19
+ "eslint-config-silverwind": "74.1.2",
20
+ "updates": "14.3.5",
21
+ "versions": "11.0.2",
22
+ "vitest": "0.34.2",
23
+ "vitest-config-silverwind": "3.0.0"
23
24
  },
24
25
  "keywords": [
25
26
  "recursive readdir",
@@ -31,5 +32,8 @@
31
32
  "crawl",
32
33
  "crawler",
33
34
  "scandir"
34
- ]
35
+ ],
36
+ "dependencies": {
37
+ "picomatch": "2.3.1"
38
+ }
35
39
  }