rrdir 14.0.1 → 14.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 -1
- package/dist/index.d.ts +14 -20
- package/dist/index.js +20 -7
- package/package.json +11 -15
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# rrdir
|
|
2
|
-
[](https://www.npmjs.org/package/rrdir) [](https://www.npmjs.org/package/rrdir) [](https://packagephobia.com/result?p=rrdir)
|
|
2
|
+
[](https://www.npmjs.org/package/rrdir) [](https://www.npmjs.org/package/rrdir) [](https://packagephobia.com/result?p=rrdir) [](https://depx.co/pkg/rrdir)
|
|
3
3
|
|
|
4
4
|
> Recursive directory reader with a delightful API
|
|
5
5
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { Stats } from "node:fs";
|
|
2
|
-
import { Matcher } from "picomatch";
|
|
3
2
|
|
|
4
3
|
//#region index.d.ts
|
|
5
4
|
type Encoding = "utf8" | "buffer";
|
|
6
|
-
type Dir = string |
|
|
7
|
-
type DirNodeCompatible = string | Buffer;
|
|
5
|
+
type Dir = string | Buffer;
|
|
8
6
|
type RRDirOpts = {
|
|
9
7
|
strict?: boolean;
|
|
10
8
|
stats?: boolean;
|
|
@@ -13,37 +11,33 @@ type RRDirOpts = {
|
|
|
13
11
|
exclude?: string[];
|
|
14
12
|
insensitive?: boolean;
|
|
15
13
|
};
|
|
14
|
+
type Matcher = ((path: string) => boolean) | null;
|
|
16
15
|
type InternalOpts = {
|
|
17
16
|
includeMatcher?: Matcher;
|
|
18
17
|
excludeMatcher?: Matcher;
|
|
19
18
|
encoding?: Encoding;
|
|
20
19
|
};
|
|
21
|
-
type Entry = {
|
|
22
|
-
/** The path to the entry, will be relative if `dir` is given relative. If `dir` is a `Uint8Array`, this will be too. Always present. */
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
/** Boolean indicating whether the entry is a symbolic link. `undefined` on error. */
|
|
27
|
-
symlink?: boolean;
|
|
28
|
-
/** A [`fs.stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats) object, present when `options.stats` is set. `undefined` on error. */
|
|
29
|
-
stats?: Stats;
|
|
30
|
-
/** Any error encountered while reading this entry. `undefined` on success. */
|
|
20
|
+
type Entry<T = Dir> = {
|
|
21
|
+
/** The path to the entry, will be relative if `dir` is given relative. If `dir` is a `Uint8Array`, this will be too. Always present. */path: T; /** Boolean indicating whether the entry is a directory. `undefined` on error. */
|
|
22
|
+
directory?: boolean; /** Boolean indicating whether the entry is a symbolic link. `undefined` on error. */
|
|
23
|
+
symlink?: boolean; /** A [`fs.stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats) object, present when `options.stats` is set. `undefined` on error. */
|
|
24
|
+
stats?: Stats; /** Any error encountered while reading this entry. `undefined` on success. */
|
|
31
25
|
err?: Error;
|
|
32
26
|
};
|
|
33
|
-
declare function rrdir(dir:
|
|
27
|
+
declare function rrdir<T extends Dir>(dir: T, opts?: RRDirOpts, {
|
|
34
28
|
includeMatcher,
|
|
35
29
|
excludeMatcher,
|
|
36
30
|
encoding
|
|
37
|
-
}?: InternalOpts): AsyncGenerator<Entry
|
|
38
|
-
declare function rrdirAsync(dir:
|
|
31
|
+
}?: InternalOpts): AsyncGenerator<Entry<T>>;
|
|
32
|
+
declare function rrdirAsync<T extends Dir>(dir: T, opts?: RRDirOpts, {
|
|
39
33
|
includeMatcher,
|
|
40
34
|
excludeMatcher,
|
|
41
35
|
encoding
|
|
42
|
-
}?: InternalOpts): Promise<Entry
|
|
43
|
-
declare function rrdirSync(dir:
|
|
36
|
+
}?: InternalOpts): Promise<Array<Entry<T>>>;
|
|
37
|
+
declare function rrdirSync<T extends Dir>(dir: T, opts?: RRDirOpts, {
|
|
44
38
|
includeMatcher,
|
|
45
39
|
excludeMatcher,
|
|
46
40
|
encoding
|
|
47
|
-
}?: InternalOpts): Entry
|
|
41
|
+
}?: InternalOpts): Array<Entry<T>>;
|
|
48
42
|
//#endregion
|
|
49
|
-
export { Dir,
|
|
43
|
+
export { Dir, Encoding, Entry, RRDirOpts, rrdir, rrdirAsync, rrdirSync };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { lstat, readdir, stat } from "node:fs/promises";
|
|
2
2
|
import { lstatSync, readdirSync, statSync } from "node:fs";
|
|
3
3
|
import { resolve, sep } from "node:path";
|
|
4
|
-
import picomatch from "picomatch";
|
|
5
4
|
|
|
6
5
|
//#region index.ts
|
|
7
6
|
const encoder = new TextEncoder();
|
|
@@ -34,14 +33,28 @@ function build(dirent, path, stats, opts) {
|
|
|
34
33
|
...opts.stats ? { stats } : {}
|
|
35
34
|
};
|
|
36
35
|
}
|
|
37
|
-
function
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
function globToRegex(pattern, insensitive) {
|
|
37
|
+
pattern = pattern.replace(/\\/g, "/");
|
|
38
|
+
const endsWithDoubleStar = pattern.endsWith("/**");
|
|
39
|
+
let regex = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "__DOUBLESTAR__").replace(/\*/g, "[^/]*").replace(/__DOUBLESTAR__/g, ".*");
|
|
40
|
+
if (endsWithDoubleStar) {
|
|
41
|
+
regex = regex.slice(0, -3);
|
|
42
|
+
regex = `^${regex}(?:/.*)?$`;
|
|
43
|
+
} else regex = `^${regex}$`;
|
|
44
|
+
return new RegExp(regex, insensitive ? "i" : "");
|
|
45
|
+
}
|
|
46
|
+
function createMatcher(patterns, insensitive) {
|
|
47
|
+
if (!patterns?.length) return null;
|
|
48
|
+
const regexes = patterns.map((pattern) => globToRegex(pattern, insensitive));
|
|
49
|
+
return (path) => {
|
|
50
|
+
const normalizedPath = resolve(path).replace(/\\/g, "/");
|
|
51
|
+
return regexes.some((regex) => regex.test(normalizedPath));
|
|
41
52
|
};
|
|
53
|
+
}
|
|
54
|
+
function makeMatchers({ include, exclude, insensitive }) {
|
|
42
55
|
return {
|
|
43
|
-
includeMatcher: include
|
|
44
|
-
excludeMatcher: exclude
|
|
56
|
+
includeMatcher: createMatcher(include || [], insensitive || false),
|
|
57
|
+
excludeMatcher: createMatcher(exclude || [], insensitive || false)
|
|
45
58
|
};
|
|
46
59
|
}
|
|
47
60
|
async function* rrdir(dir, opts = {}, { includeMatcher, excludeMatcher, encoding } = {}) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rrdir",
|
|
3
|
-
"version": "14.0
|
|
3
|
+
"version": "14.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,20 +16,16 @@
|
|
|
16
16
|
"engines": {
|
|
17
17
|
"node": ">=22"
|
|
18
18
|
},
|
|
19
|
-
"dependencies": {
|
|
20
|
-
"picomatch": "4.0.3"
|
|
21
|
-
},
|
|
22
19
|
"devDependencies": {
|
|
23
|
-
"@types/node": "
|
|
24
|
-
"
|
|
25
|
-
"eslint": "
|
|
26
|
-
"
|
|
27
|
-
"tsdown": "
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"vitest": "
|
|
33
|
-
"vitest-config-silverwind": "10.4.2"
|
|
20
|
+
"@types/node": "25.1.0",
|
|
21
|
+
"eslint": "9.39.2",
|
|
22
|
+
"eslint-config-silverwind": "118.0.1",
|
|
23
|
+
"tsdown": "0.20.1",
|
|
24
|
+
"tsdown-config-silverwind": "1.7.3",
|
|
25
|
+
"typescript-config-silverwind": "14.0.0",
|
|
26
|
+
"updates": "17.0.8",
|
|
27
|
+
"versions": "14.0.3",
|
|
28
|
+
"vitest": "4.0.18",
|
|
29
|
+
"vitest-config-silverwind": "10.6.1"
|
|
34
30
|
}
|
|
35
31
|
}
|