« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util/io.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/io.js')
-rw-r--r--src/util/io.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/util/io.js b/src/util/io.js
new file mode 100644
index 0000000..1d74399
--- /dev/null
+++ b/src/util/io.js
@@ -0,0 +1,14 @@
+// Utility functions for interacting with files and other external data
+// interfacey constructs.
+
+import { readdir } from 'fs/promises';
+import * as path from 'path';
+
+export async function findFiles(dataPath, {
+    filter = f => true,
+    joinParentDirectory = true,
+} = {}) {
+    return (await readdir(dataPath))
+        .filter(file => filter(file))
+        .map(file => joinParentDirectory ? path.join(dataPath, file) : file);
+}