@hypernym/utils 1.1.1 → 1.2.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.
@@ -59,5 +59,23 @@ async function getDirStats(path, options) {
59
59
  return dirStats;
60
60
  }
61
61
 
62
+ async function getDirFiles(path, options) {
63
+ const dirPath = node_path.resolve(path);
64
+ const dirFiles = await promises.readdir(dirPath, { withFileTypes: true });
65
+ let fileList = [];
66
+ for (const file of dirFiles) {
67
+ const filePath = node_path.resolve(path, file.name);
68
+ if (file.isDirectory()) {
69
+ if (options?.recursive) {
70
+ fileList = [...fileList, ...await getDirFiles(filePath)];
71
+ }
72
+ } else {
73
+ fileList.push(filePath);
74
+ }
75
+ }
76
+ return fileList;
77
+ }
78
+
62
79
  exports.exists = exists;
80
+ exports.getDirFiles = getDirFiles;
63
81
  exports.getDirStats = getDirStats;
@@ -35,4 +35,15 @@ interface DirStatsOptions {
35
35
  recursive?: boolean;
36
36
  }
37
37
 
38
- export { DirStats, DirStatsOptions, exists, getDirStats };
38
+ /**
39
+ * Scans the specified directory and returns a list of all files.
40
+ *
41
+ * By default, recursive mode is disabled so only one level is scanned.
42
+ */
43
+ declare function getDirFiles(path: string, options?: DirFilesOptions): Promise<string[]>;
44
+
45
+ interface DirFilesOptions {
46
+ recursive?: boolean;
47
+ }
48
+
49
+ export { DirFilesOptions, DirStats, DirStatsOptions, exists, getDirFiles, getDirStats };
@@ -57,4 +57,21 @@ async function getDirStats(path, options) {
57
57
  return dirStats;
58
58
  }
59
59
 
60
- export { exists, getDirStats };
60
+ async function getDirFiles(path, options) {
61
+ const dirPath = resolve(path);
62
+ const dirFiles = await readdir(dirPath, { withFileTypes: true });
63
+ let fileList = [];
64
+ for (const file of dirFiles) {
65
+ const filePath = resolve(path, file.name);
66
+ if (file.isDirectory()) {
67
+ if (options?.recursive) {
68
+ fileList = [...fileList, ...await getDirFiles(filePath)];
69
+ }
70
+ } else {
71
+ fileList.push(filePath);
72
+ }
73
+ }
74
+ return fileList;
75
+ }
76
+
77
+ export { exists, getDirFiles, getDirStats };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hypernym/utils",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "author": "Hypernym Studio",
5
5
  "maintainers": [
6
6
  "Ivo Dolenc (https://github.com/ivodolenc)"