(options?: FileParseOptions)
| 722 | * @since 4.0.0 |
| 723 | */ |
| 724 | export const fileParse = (options?: FileParseOptions): Primitive<unknown> => { |
| 725 | return makePrimitive( |
| 726 | "FileParse", |
| 727 | Effect.fnUntraced(function*(filePath) { |
| 728 | const fileFormat = options?.format ?? filePath.split(".").pop() as string |
| 729 | const parser = fileParsers[fileFormat] |
| 730 | if (parser === undefined) { |
| 731 | return yield* Effect.fail(`Unsupported file format: ${fileFormat}`) |
| 732 | } |
| 733 | const content = yield* fileText.parse(filePath) |
| 734 | return yield* Effect.try({ |
| 735 | try: () => parser(content), |
| 736 | catch: (error) => `Failed to parse '.${fileFormat}' file content: ${error}` |
| 737 | }) |
| 738 | }) |
| 739 | ) |
| 740 | } |
| 741 | |
| 742 | /** |
| 743 | * Represents options which can be provided to methods that deal with parsing |
no test coverage detected