tiny-readdir 2.2.1 → 2.4.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/dist/index.js CHANGED
@@ -3,6 +3,7 @@ import fs from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import { isFunction, makeCounterPromise } from './utils.js';
5
5
  /* MAIN */
6
+ //TODO: Streamline the type of dirnmaps
6
7
  const readdir = (rootPath, options) => {
7
8
  const followSymlinks = options?.followSymlinks ?? false;
8
9
  const maxDepth = options?.depth ?? Infinity;
@@ -11,22 +12,34 @@ const readdir = (rootPath, options) => {
11
12
  const isIgnored = isFunction(ignore) ? ignore : (targetPath) => ignore.test(targetPath);
12
13
  const signal = options?.signal ?? { aborted: false };
13
14
  const directories = [];
15
+ const directoriesNames = new Set();
16
+ const directoriesNamesToPaths = {};
14
17
  const files = [];
18
+ const filesNames = new Set();
19
+ const filesNamesToPaths = {};
15
20
  const symlinks = [];
21
+ const symlinksNames = new Set();
22
+ const symlinksNamesToPaths = {};
16
23
  const map = {};
17
24
  const visited = new Set();
18
- const resultEmpty = { directories: [], files: [], symlinks: [], map: {} };
19
- const result = { directories, files, symlinks, map };
25
+ const resultEmpty = { directories: [], directoriesNames: new Set(), directoriesNamesToPaths: {}, files: [], filesNames: new Set(), filesNamesToPaths: {}, symlinks: [], symlinksNames: new Set(), symlinksNamesToPaths: {}, map: {} };
26
+ const result = { directories, directoriesNames, directoriesNamesToPaths, files, filesNames, filesNamesToPaths, symlinks, symlinksNames, symlinksNamesToPaths, map };
20
27
  const { promise, increment, decrement } = makeCounterPromise();
21
28
  let foundPaths = 0;
22
- const handleDirectory = (dirmap, subPath, depth) => {
29
+ const handleDirectory = (dirmap, subPath, name, depth) => {
23
30
  if (visited.has(subPath))
24
31
  return;
25
32
  if (foundPaths >= maxPaths)
26
33
  return;
27
34
  foundPaths += 1;
28
35
  dirmap.directories.push(subPath);
36
+ dirmap.directoriesNames.add(name);
37
+ // dirmap.directoriesNamesToPaths.propertyIsEnumerable(name) || ( dirmap.directoriesNamesToPaths[name] = [] );
38
+ // dirmap.directoriesNamesToPaths[name].push ( subPath );
29
39
  directories.push(subPath);
40
+ directoriesNames.add(name);
41
+ directoriesNamesToPaths.propertyIsEnumerable(name) || (directoriesNamesToPaths[name] = []);
42
+ directoriesNamesToPaths[name].push(subPath);
30
43
  visited.add(subPath);
31
44
  if (depth >= maxDepth)
32
45
  return;
@@ -34,24 +47,36 @@ const readdir = (rootPath, options) => {
34
47
  return;
35
48
  populateResultFromPath(subPath, depth + 1);
36
49
  };
37
- const handleFile = (dirmap, subPath) => {
50
+ const handleFile = (dirmap, subPath, name) => {
38
51
  if (visited.has(subPath))
39
52
  return;
40
53
  if (foundPaths >= maxPaths)
41
54
  return;
42
55
  foundPaths += 1;
43
56
  dirmap.files.push(subPath);
57
+ dirmap.filesNames.add(name);
58
+ // dirmap.filesNamesToPaths.propertyIsEnumerable(name) || ( dirmap.filesNamesToPaths[name] = [] );
59
+ // dirmap.filesNamesToPaths[name].push ( subPath );
44
60
  files.push(subPath);
61
+ filesNames.add(name);
62
+ filesNamesToPaths.propertyIsEnumerable(name) || (filesNamesToPaths[name] = []);
63
+ filesNamesToPaths[name].push(subPath);
45
64
  visited.add(subPath);
46
65
  };
47
- const handleSymlink = (dirmap, subPath, depth) => {
66
+ const handleSymlink = (dirmap, subPath, name, depth) => {
48
67
  if (visited.has(subPath))
49
68
  return;
50
69
  if (foundPaths >= maxPaths)
51
70
  return;
52
71
  foundPaths += 1;
53
72
  dirmap.symlinks.push(subPath);
73
+ dirmap.symlinksNames.add(name);
74
+ // dirmap.symlinksNamesToPaths.propertyIsEnumerable(name) || ( dirmap.symlinksNamesToPaths[name] = [] );
75
+ // dirmap.symlinksNamesToPaths[name].push ( subPath );
54
76
  symlinks.push(subPath);
77
+ symlinksNames.add(name);
78
+ symlinksNamesToPaths.propertyIsEnumerable(name) || (symlinksNamesToPaths[name] = []);
79
+ symlinksNamesToPaths[name].push(subPath);
55
80
  visited.add(subPath);
56
81
  if (!followSymlinks)
57
82
  return;
@@ -61,36 +86,37 @@ const readdir = (rootPath, options) => {
61
86
  return;
62
87
  populateResultFromSymlink(subPath, depth + 1);
63
88
  };
64
- const handleStat = (dirmap, rootPath, stat, depth) => {
89
+ const handleStat = (dirmap, rootPath, name, stat, depth) => {
65
90
  if (signal.aborted)
66
91
  return;
67
92
  if (isIgnored(rootPath))
68
93
  return;
69
94
  if (stat.isDirectory()) {
70
- handleDirectory(dirmap, rootPath, depth);
95
+ handleDirectory(dirmap, rootPath, name, depth);
71
96
  }
72
97
  else if (stat.isFile()) {
73
- handleFile(dirmap, rootPath);
98
+ handleFile(dirmap, rootPath, name);
74
99
  }
75
100
  else if (stat.isSymbolicLink()) {
76
- handleSymlink(dirmap, rootPath, depth);
101
+ handleSymlink(dirmap, rootPath, name, depth);
77
102
  }
78
103
  };
79
104
  const handleDirent = (dirmap, rootPath, dirent, depth) => {
80
105
  if (signal.aborted)
81
106
  return;
82
107
  const separator = (rootPath === path.sep) ? '' : path.sep;
83
- const subPath = `${rootPath}${separator}${dirent.name}`;
108
+ const name = dirent.name;
109
+ const subPath = `${rootPath}${separator}${name}`;
84
110
  if (isIgnored(subPath))
85
111
  return;
86
112
  if (dirent.isDirectory()) {
87
- handleDirectory(dirmap, subPath, depth);
113
+ handleDirectory(dirmap, subPath, name, depth);
88
114
  }
89
115
  else if (dirent.isFile()) {
90
- handleFile(dirmap, subPath);
116
+ handleFile(dirmap, subPath, name);
91
117
  }
92
118
  else if (dirent.isSymbolicLink()) {
93
- handleSymlink(dirmap, subPath, depth);
119
+ handleSymlink(dirmap, subPath, name, depth);
94
120
  }
95
121
  };
96
122
  const handleDirents = (dirmap, rootPath, dirents, depth) => {
@@ -113,7 +139,7 @@ const readdir = (rootPath, options) => {
113
139
  return decrement();
114
140
  if (!dirents.length)
115
141
  return decrement();
116
- const dirmap = map[rootPath] = { directories: [], files: [], symlinks: [] };
142
+ const dirmap = map[rootPath] = { directories: [], directoriesNames: new Set(), directoriesNamesToPaths: {}, files: [], filesNames: new Set(), filesNamesToPaths: {}, symlinks: [], symlinksNames: new Set(), symlinksNamesToPaths: {} };
117
143
  handleDirents(dirmap, rootPath, dirents, depth);
118
144
  decrement();
119
145
  });
@@ -130,8 +156,9 @@ const readdir = (rootPath, options) => {
130
156
  return decrement();
131
157
  if (signal.aborted)
132
158
  return decrement();
133
- const dirmap = map[rootPath] = { directories: [], files: [], symlinks: [] };
134
- handleStat(dirmap, realPath, stat, depth);
159
+ const name = path.basename(realPath);
160
+ const dirmap = map[rootPath] = { directories: [], directoriesNames: new Set(), directoriesNamesToPaths: {}, files: [], filesNames: new Set(), filesNamesToPaths: {}, symlinks: [], symlinksNames: new Set(), symlinksNamesToPaths: {} };
161
+ handleStat(dirmap, realPath, name, stat, depth);
135
162
  decrement();
136
163
  });
137
164
  });
package/dist/types.d.ts CHANGED
@@ -10,8 +10,14 @@ type Options = {
10
10
  };
11
11
  type ResultDirectory = {
12
12
  directories: string[];
13
+ directoriesNames: Set<string>;
14
+ directoriesNamesToPaths: Record<string, string[]>;
13
15
  files: string[];
16
+ filesNames: Set<string>;
17
+ filesNamesToPaths: Record<string, string[]>;
14
18
  symlinks: string[];
19
+ symlinksNames: Set<string>;
20
+ symlinksNamesToPaths: Record<string, string[]>;
15
21
  };
16
22
  type ResultDirectories = {
17
23
  [path: string]: ResultDirectory;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "tiny-readdir",
3
3
  "repository": "github:fabiospampinato/tiny-readdir",
4
4
  "description": "A simple promisified recursive readdir function.",
5
- "version": "2.2.1",
5
+ "version": "2.4.0",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
8
8
  "exports": "./dist/index.js",
package/readme.md CHANGED
@@ -27,6 +27,14 @@ console.log ( result.directories ); // => Array of absolute paths pointing to di
27
27
  console.log ( result.files ); // => Array of absolute paths pointing to files
28
28
  console.log ( result.symlinks ); // => Array of absolute paths pointing to symlinks
29
29
 
30
+ console.log ( result.directoriesNames ); // => Set of directories names found
31
+ console.log ( result.filesNames ); // => Set of files name found
32
+ console.log ( result.symlinksNames ); // => Set of symlinks names found
33
+
34
+ console.log ( result.directoriesNamesToPaths ); // => Record of directories names found to their paths
35
+ console.log ( result.filesNamesToPaths ); // => Record of files names found to their paths
36
+ console.log ( result.symlinksNamesToPaths ); // => Record of symlinks names found to their paths
37
+
30
38
  setTimeout ( () => aborter.abort (), 10000 ); // Aborting if it's going to take longer than 10s
31
39
  ```
32
40
 
package/src/index.ts CHANGED
@@ -8,6 +8,8 @@ import type {Options, ResultDirectory, ResultDirectories, Result} from './types'
8
8
 
9
9
  /* MAIN */
10
10
 
11
+ //TODO: Streamline the type of dirnmaps
12
+
11
13
  const readdir = ( rootPath: string, options?: Options ): Promise<Result> => {
12
14
 
13
15
  const followSymlinks = options?.followSymlinks ?? false;
@@ -17,17 +19,23 @@ const readdir = ( rootPath: string, options?: Options ): Promise<Result> => {
17
19
  const isIgnored = isFunction ( ignore ) ? ignore : ( targetPath: string ) => ignore.test ( targetPath );
18
20
  const signal = options?.signal ?? { aborted: false };
19
21
  const directories: string[] = [];
22
+ const directoriesNames: Set<string> = new Set ();
23
+ const directoriesNamesToPaths: Record<string, string[]> = {};
20
24
  const files: string[] = [];
25
+ const filesNames: Set<string> = new Set ();
26
+ const filesNamesToPaths: Record<string, string[]> = {};
21
27
  const symlinks: string[] = [];
28
+ const symlinksNames: Set<string> = new Set ();
29
+ const symlinksNamesToPaths: Record<string, string[]> = {};
22
30
  const map: ResultDirectories = {};
23
31
  const visited = new Set<string> ();
24
- const resultEmpty: Result = { directories: [], files: [], symlinks: [], map: {} };
25
- const result: Result = { directories, files, symlinks, map };
32
+ const resultEmpty: Result = { directories: [], directoriesNames: new Set (), directoriesNamesToPaths: {}, files: [], filesNames: new Set (), filesNamesToPaths: {}, symlinks: [], symlinksNames: new Set (), symlinksNamesToPaths: {}, map: {} };
33
+ const result: Result = { directories, directoriesNames, directoriesNamesToPaths, files, filesNames, filesNamesToPaths, symlinks, symlinksNames, symlinksNamesToPaths, map };
26
34
  const {promise, increment, decrement} = makeCounterPromise ();
27
35
 
28
36
  let foundPaths = 0;
29
37
 
30
- const handleDirectory = ( dirmap: ResultDirectory, subPath: string, depth: number ): void => {
38
+ const handleDirectory = ( dirmap: ResultDirectory, subPath: string, name: string, depth: number ): void => {
31
39
 
32
40
  if ( visited.has ( subPath ) ) return;
33
41
 
@@ -35,7 +43,13 @@ const readdir = ( rootPath: string, options?: Options ): Promise<Result> => {
35
43
 
36
44
  foundPaths += 1;
37
45
  dirmap.directories.push ( subPath );
46
+ dirmap.directoriesNames.add ( name );
47
+ // dirmap.directoriesNamesToPaths.propertyIsEnumerable(name) || ( dirmap.directoriesNamesToPaths[name] = [] );
48
+ // dirmap.directoriesNamesToPaths[name].push ( subPath );
38
49
  directories.push ( subPath );
50
+ directoriesNames.add ( name );
51
+ directoriesNamesToPaths.propertyIsEnumerable(name) || ( directoriesNamesToPaths[name] = [] );
52
+ directoriesNamesToPaths[name].push ( subPath );
39
53
  visited.add ( subPath );
40
54
 
41
55
  if ( depth >= maxDepth ) return;
@@ -46,7 +60,7 @@ const readdir = ( rootPath: string, options?: Options ): Promise<Result> => {
46
60
 
47
61
  };
48
62
 
49
- const handleFile = ( dirmap: ResultDirectory, subPath: string ): void => {
63
+ const handleFile = ( dirmap: ResultDirectory, subPath: string, name: string ): void => {
50
64
 
51
65
  if ( visited.has ( subPath ) ) return;
52
66
 
@@ -54,12 +68,18 @@ const readdir = ( rootPath: string, options?: Options ): Promise<Result> => {
54
68
 
55
69
  foundPaths += 1;
56
70
  dirmap.files.push ( subPath );
71
+ dirmap.filesNames.add ( name );
72
+ // dirmap.filesNamesToPaths.propertyIsEnumerable(name) || ( dirmap.filesNamesToPaths[name] = [] );
73
+ // dirmap.filesNamesToPaths[name].push ( subPath );
57
74
  files.push ( subPath );
75
+ filesNames.add ( name );
76
+ filesNamesToPaths.propertyIsEnumerable(name) || ( filesNamesToPaths[name] = [] );
77
+ filesNamesToPaths[name].push ( subPath );
58
78
  visited.add ( subPath );
59
79
 
60
80
  };
61
81
 
62
- const handleSymlink = ( dirmap: ResultDirectory, subPath: string, depth: number ): void => {
82
+ const handleSymlink = ( dirmap: ResultDirectory, subPath: string, name: string, depth: number ): void => {
63
83
 
64
84
  if ( visited.has ( subPath ) ) return;
65
85
 
@@ -67,7 +87,13 @@ const readdir = ( rootPath: string, options?: Options ): Promise<Result> => {
67
87
 
68
88
  foundPaths += 1;
69
89
  dirmap.symlinks.push ( subPath );
90
+ dirmap.symlinksNames.add ( name );
91
+ // dirmap.symlinksNamesToPaths.propertyIsEnumerable(name) || ( dirmap.symlinksNamesToPaths[name] = [] );
92
+ // dirmap.symlinksNamesToPaths[name].push ( subPath );
70
93
  symlinks.push ( subPath );
94
+ symlinksNames.add ( name );
95
+ symlinksNamesToPaths.propertyIsEnumerable(name) || ( symlinksNamesToPaths[name] = [] );
96
+ symlinksNamesToPaths[name].push ( subPath );
71
97
  visited.add ( subPath );
72
98
 
73
99
  if ( !followSymlinks ) return;
@@ -80,7 +106,7 @@ const readdir = ( rootPath: string, options?: Options ): Promise<Result> => {
80
106
 
81
107
  };
82
108
 
83
- const handleStat = ( dirmap: ResultDirectory, rootPath: string, stat: fs.Stats, depth: number ): void => {
109
+ const handleStat = ( dirmap: ResultDirectory, rootPath: string, name: string, stat: fs.Stats, depth: number ): void => {
84
110
 
85
111
  if ( signal.aborted ) return;
86
112
 
@@ -88,15 +114,15 @@ const readdir = ( rootPath: string, options?: Options ): Promise<Result> => {
88
114
 
89
115
  if ( stat.isDirectory () ) {
90
116
 
91
- handleDirectory ( dirmap, rootPath, depth );
117
+ handleDirectory ( dirmap, rootPath, name, depth );
92
118
 
93
119
  } else if ( stat.isFile () ) {
94
120
 
95
- handleFile ( dirmap, rootPath );
121
+ handleFile ( dirmap, rootPath, name );
96
122
 
97
123
  } else if ( stat.isSymbolicLink () ) {
98
124
 
99
- handleSymlink ( dirmap, rootPath, depth );
125
+ handleSymlink ( dirmap, rootPath, name, depth );
100
126
 
101
127
  }
102
128
 
@@ -107,21 +133,22 @@ const readdir = ( rootPath: string, options?: Options ): Promise<Result> => {
107
133
  if ( signal.aborted ) return;
108
134
 
109
135
  const separator = ( rootPath === path.sep ) ? '' : path.sep;
110
- const subPath = `${rootPath}${separator}${dirent.name}`;
136
+ const name = dirent.name;
137
+ const subPath = `${rootPath}${separator}${name}`;
111
138
 
112
139
  if ( isIgnored ( subPath ) ) return;
113
140
 
114
141
  if ( dirent.isDirectory () ) {
115
142
 
116
- handleDirectory ( dirmap, subPath, depth );
143
+ handleDirectory ( dirmap, subPath, name, depth );
117
144
 
118
145
  } else if ( dirent.isFile () ) {
119
146
 
120
- handleFile ( dirmap, subPath );
147
+ handleFile ( dirmap, subPath, name );
121
148
 
122
149
  } else if ( dirent.isSymbolicLink () ) {
123
150
 
124
- handleSymlink ( dirmap, subPath, depth );
151
+ handleSymlink ( dirmap, subPath, name, depth );
125
152
 
126
153
  }
127
154
 
@@ -155,7 +182,7 @@ const readdir = ( rootPath: string, options?: Options ): Promise<Result> => {
155
182
 
156
183
  if ( !dirents.length ) return decrement ();
157
184
 
158
- const dirmap = map[rootPath] = { directories: [], files: [], symlinks: [] };
185
+ const dirmap = map[rootPath] = { directories: [], directoriesNames: new Set (), directoriesNamesToPaths: {}, files: [], filesNames: new Set (), filesNamesToPaths: {}, symlinks: [], symlinksNames: new Set (), symlinksNamesToPaths: {} };
159
186
 
160
187
  handleDirents ( dirmap, rootPath, dirents, depth );
161
188
 
@@ -181,9 +208,10 @@ const readdir = ( rootPath: string, options?: Options ): Promise<Result> => {
181
208
 
182
209
  if ( signal.aborted ) return decrement ();
183
210
 
184
- const dirmap = map[rootPath] = { directories: [], files: [], symlinks: [] };
211
+ const name = path.basename ( realPath );
212
+ const dirmap = map[rootPath] = { directories: [], directoriesNames: new Set (), directoriesNamesToPaths: {}, files: [], filesNames: new Set (), filesNamesToPaths: {}, symlinks: [], symlinksNames: new Set (), symlinksNamesToPaths: {} };
185
213
 
186
- handleStat ( dirmap, realPath, stat, depth );
214
+ handleStat ( dirmap, realPath, name, stat, depth );
187
215
 
188
216
  decrement ();
189
217
 
package/src/types.ts CHANGED
@@ -15,8 +15,14 @@ type Options = {
15
15
 
16
16
  type ResultDirectory = {
17
17
  directories: string[],
18
+ directoriesNames: Set<string>,
19
+ directoriesNamesToPaths: Record<string, string[]>,
18
20
  files: string[],
19
- symlinks: string[]
21
+ filesNames: Set<string>,
22
+ filesNamesToPaths: Record<string, string[]>,
23
+ symlinks: string[],
24
+ symlinksNames: Set<string>,
25
+ symlinksNamesToPaths: Record<string, string[]>
20
26
  };
21
27
 
22
28
  type ResultDirectories = {
package/test/index.js CHANGED
@@ -6,6 +6,10 @@ import fs from 'node:fs';
6
6
  import path from 'node:path';
7
7
  import readdir from '../dist/index.js';
8
8
 
9
+ /* HELPERS */
10
+
11
+ const toBasename = filePath => path.basename ( filePath );
12
+
9
13
  /* MAIN */
10
14
 
11
15
  describe ( 'Tiny Readdir', it => {
@@ -41,43 +45,91 @@ describe ( 'Tiny Readdir', it => {
41
45
 
42
46
  const expected = {
43
47
  directories: [folder1Path, folder2Path, folder1DeepPath, root2Path],
48
+ directoriesNames: new Set ( [folder1Path, folder2Path, folder1DeepPath, root2Path].map ( toBasename ) ),
49
+ directoriesNamesToPaths: { folder1: [folder1Path], folder2: [folder2Path], deep: [folder1DeepPath], root2: [root2Path] },
44
50
  files: [file1aPath, file1bPath, file2Path, fileDeep1Path],
51
+ filesNames: new Set ( [file1aPath, file1bPath, file2Path, fileDeep1Path].map ( toBasename ) ),
52
+ filesNamesToPaths: { 'file1a.txt': [file1aPath], 'file1b.txt': [file1bPath], 'file2.txt': [file2Path], 'file1.txt': [fileDeep1Path] },
45
53
  symlinks: [symlink1FromPath, symlink2FromPath],
54
+ symlinksNames: new Set ( [symlink1FromPath, symlink2FromPath].map ( toBasename ) ),
55
+ symlinksNamesToPaths: { symlink: [symlink1FromPath, symlink2FromPath] },
46
56
  map: {
47
57
  [root1Path]: {
48
58
  directories: [folder1Path, folder2Path],
59
+ directoriesNames: new Set ( [folder1Path, folder2Path].map ( toBasename ) ),
60
+ directoriesNamesToPaths: {},
49
61
  files: [],
50
- symlinks: [symlink1FromPath]
62
+ filesNames: new Set (),
63
+ filesNamesToPaths: {},
64
+ symlinks: [symlink1FromPath],
65
+ symlinksNames: new Set ( [symlink1FromPath].map ( toBasename ) ),
66
+ symlinksNamesToPaths: {}
51
67
  },
52
68
  [root2Path]: {
53
69
  directories: [],
70
+ directoriesNames: new Set (),
71
+ directoriesNamesToPaths: {},
54
72
  files: [],
55
- symlinks: [symlink2FromPath]
73
+ filesNames: new Set (),
74
+ filesNamesToPaths: {},
75
+ symlinks: [symlink2FromPath],
76
+ symlinksNames: new Set ( [symlink2FromPath].map ( toBasename ) ),
77
+ symlinksNamesToPaths: {}
56
78
  },
57
79
  [folder1Path]: {
58
80
  directories: [folder1DeepPath],
81
+ directoriesNames: new Set ( [folder1DeepPath].map ( toBasename ) ),
82
+ directoriesNamesToPaths: {},
59
83
  files: [file1aPath, file1bPath],
60
- symlinks: []
84
+ filesNames: new Set ( [file1aPath, file1bPath].map ( toBasename ) ),
85
+ filesNamesToPaths: {},
86
+ symlinks: [],
87
+ symlinksNames: new Set (),
88
+ symlinksNamesToPaths: {}
61
89
  },
62
90
  [folder2Path]: {
63
91
  directories: [],
92
+ directoriesNames: new Set (),
93
+ directoriesNamesToPaths: {},
64
94
  files: [file2Path],
65
- symlinks: []
95
+ filesNames: new Set ( [file2Path].map ( toBasename ) ),
96
+ filesNamesToPaths: {},
97
+ symlinks: [],
98
+ symlinksNames: new Set (),
99
+ symlinksNamesToPaths: {}
66
100
  },
67
101
  [folder1DeepPath]: {
68
102
  directories: [],
103
+ directoriesNames: new Set (),
104
+ directoriesNamesToPaths: {},
69
105
  files: [fileDeep1Path],
70
- symlinks: []
106
+ filesNames: new Set ( [fileDeep1Path].map ( toBasename ) ),
107
+ filesNamesToPaths: {},
108
+ symlinks: [],
109
+ symlinksNames: new Set (),
110
+ symlinksNamesToPaths: {}
71
111
  },
72
112
  [symlink1FromPath]: {
73
113
  directories: [root2Path],
114
+ directoriesNames: new Set ( [root2Path].map ( toBasename ) ),
115
+ directoriesNamesToPaths: {},
74
116
  files: [],
75
- symlinks: []
117
+ filesNames: new Set (),
118
+ filesNamesToPaths: {},
119
+ symlinks: [],
120
+ symlinksNames: new Set (),
121
+ symlinksNamesToPaths: {}
76
122
  },
77
123
  [symlink2FromPath]: {
78
124
  directories: [],
125
+ directoriesNames: new Set (),
126
+ directoriesNamesToPaths: {},
79
127
  files: [],
80
- symlinks: []
128
+ filesNames: new Set (),
129
+ filesNamesToPaths: {},
130
+ symlinks: [],
131
+ symlinksNames: new Set (),
132
+ symlinksNamesToPaths: {}
81
133
  }
82
134
  }
83
135
  };
@@ -128,23 +180,47 @@ describe ( 'Tiny Readdir', it => {
128
180
 
129
181
  const expected = {
130
182
  directories: [folder1Path, folder2Path],
183
+ directoriesNames: new Set ( [folder1Path, folder2Path].map ( toBasename ) ),
184
+ directoriesNamesToPaths: { folder1: [folder1Path], folder2: [folder2Path] },
131
185
  files: [],
186
+ filesNames: new Set (),
187
+ filesNamesToPaths: {},
132
188
  symlinks: [symlink1FromPath],
189
+ symlinksNames: new Set ( [symlink1FromPath].map ( toBasename ) ),
190
+ symlinksNamesToPaths: { symlink: [symlink1FromPath] },
133
191
  map: {
134
192
  [root1Path]: {
135
193
  directories: [folder1Path, folder2Path],
194
+ directoriesNames: new Set ( [folder1Path, folder2Path].map ( toBasename ) ),
195
+ directoriesNamesToPaths: {},
136
196
  files: [],
137
- symlinks: [symlink1FromPath]
197
+ filesNames: new Set (),
198
+ filesNamesToPaths: {},
199
+ symlinks: [symlink1FromPath],
200
+ symlinksNames: new Set ( [symlink1FromPath].map ( toBasename ) ),
201
+ symlinksNamesToPaths: {}
138
202
  },
139
203
  [folder1Path]: {
140
204
  directories: [],
205
+ directoriesNames: new Set (),
206
+ directoriesNamesToPaths: {},
141
207
  files: [],
142
- symlinks: []
208
+ filesNames: new Set (),
209
+ filesNamesToPaths: {},
210
+ symlinks: [],
211
+ symlinksNames: new Set (),
212
+ symlinksNamesToPaths: {}
143
213
  },
144
214
  [folder2Path]: {
145
215
  directories: [],
216
+ directoriesNames: new Set (),
217
+ directoriesNamesToPaths: {},
146
218
  files: [],
147
- symlinks: []
219
+ filesNames: new Set (),
220
+ filesNamesToPaths: {},
221
+ symlinks: [],
222
+ symlinksNames: new Set (),
223
+ symlinksNamesToPaths: {}
148
224
  }
149
225
  }
150
226
  };