blob: 637cb8cc7b1625c0de562a370405d28d72c0677b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
import { readFile, readdir } from "fs";
export async function findAsync<T>(arr: T[], callback: (t: T) => Promise<boolean>): Promise<T> {
const results = await Promise.all(arr.map(callback));
const index = results.findIndex(result => result);
return arr[index];
}
export function getFile(base_dir: string, repository: string, file: string): Promise<string | null> {
return new Promise(resolve => {
readFile(`${base_dir}/${repository}/${file}`, (err, content) => {
if(err) {
resolve(null);
return;
}
resolve(content.toString().replace(/\n/gu, ""));
});
});
}
export function getDirectory(directory: string): Promise<string[]> {
return new Promise<string[]>(resolve => {
readdir(directory, (err, dir_content) => {
if(err) {
resolve([]);
}
resolve(dir_content);
});
});
}
|