MCPcopy Create free account
hub / github.com/vercel/vercel / readConfigFile

Function readConfigFile

packages/frameworks/src/read-config-file.ts:24–45  ·  view source on GitHub ↗
(
  files: string | string[]
)

Source from the content-addressed store, hash-verified

22}
23
24export 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}

Callers

nothing calls this directly

Calls 3

readFileOrNullFunction · 0.70
toStringMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected