« get me outta code hell

io.js « util « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util/io.js
blob: 4a6e95f3bc079bd8411a0fa05b2d14aeff0a8f6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/** @format */

// 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 = () => true,
  joinParentDirectory = true,
} = {}) {
  return (await readdir(dataPath))
    .filter((file) => filter(file))
    .map((file) => (joinParentDirectory ? path.join(dataPath, file) : file));
}