From 385faccb5a5be64acd5ca65ace26d6a7db37b64f Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 16 Apr 2022 23:37:12 -0300 Subject: HSMusic REPL + supporting internal improvements --- src/util/io.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/util/io.js (limited to 'src/util/io.js') 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); +} -- cgit 1.3.0-6-gf8a5