Function
parse
(
path: string,
content: string,
format?: "json" | "yaml" | "ini" | "toml"
)
Source from the content-addressed store, hash-verified
| 42 | |
| 43 | /** @internal */ |
| 44 | export const parse = ( |
| 45 | path: string, |
| 46 | content: string, |
| 47 | format?: "json" | "yaml" | "ini" | "toml" |
| 48 | ): Effect.Effect<unknown, string> => { |
| 49 | const parser = fileParsers[format ?? path.split(".").pop() as string] |
| 50 | if (parser === undefined) { |
| 51 | return Effect.fail(`Unsupported file format: ${format}`) |
| 52 | } |
| 53 | |
| 54 | return Effect.try({ |
| 55 | try: () => parser(content), |
| 56 | catch: (e) => `Could not parse ${format} file (${path}): ${e}` |
| 57 | }) |
| 58 | } |
Tested by
no test coverage detected