blob: fcfaf29686ea413fb032118849fef85d239db0e8 (
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
32
33
34
35
36
|
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 type Author = {
name: string,
email: string
}
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);
});
});
}
|