( files: string | string[] )
| 22 | } |
| 23 | |
| 24 | export async function readConfigFile<T>( |
| 25 | files: string | string[] |
| 26 | ): Promise<T | null> { |
| 27 | files = Array.isArray(files) ? files : [files]; |
| 28 | |
| 29 | for (const name of files) { |
| 30 | const data = await readFileOrNull(name); |
| 31 | |
| 32 | if (data) { |
| 33 | const str = data.toString('utf8'); |
| 34 | if (name.endsWith('.json')) { |
| 35 | return JSON.parse(str) as T; |
| 36 | } else if (name.endsWith('.toml')) { |
| 37 | return tomlParse(str) as unknown as T; |
| 38 | } else if (name.endsWith('.yaml') || name.endsWith('.yml')) { |
| 39 | return yaml.safeLoad(str, { filename: name }) as T; |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | return null; |
| 45 | } |
nothing calls this directly
no test coverage detected