blob: 6cc89b5687bdbca5526db2fe084ac6db4920cb40 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
// 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,
} = {}) {
let files;
try {
files = await readdir(dataPath);
} catch (error) {
throw new AggregateError([error], `Failed to list files from ${dataPath}`);
}
return files
.filter((file) => filter(file))
.map((file) => (joinParentDirectory ? path.join(dataPath, file) : file));
}
|