MCPcopy Create free account
hub / github.com/Effect-TS/effect / fileParse

Function fileParse

packages/effect/src/unstable/cli/Primitive.ts:724–740  ·  view source on GitHub ↗
(options?: FileParseOptions)

Source from the content-addressed store, hash-verified

722 * @since 4.0.0
723 */
724export 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

Callers 1

fileSchemaFunction · 0.70

Calls 4

makePrimitiveFunction · 0.70
splitMethod · 0.45
failMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected