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

Function decode

packages/effect/src/encoding/Yaml.ts:1470–1486  ·  view source on GitHub ↗
(input: string, f: (parser: YamlParser) => A)

Source from the content-addressed store, hash-verified

1468}
1469
1470const decode = <A>(input: string, f: (parser: YamlParser) => A): Result.Result<A, EncodingError> => {
1471 try {
1472 const raws = (input.includes("\r") ? input.replace(/\r\n?/g, "\n") : input).split("\n")
1473 const lines = new Array<Line>(raws.length)
1474 for (let index = 0; index < raws.length; index++) lines[index] = makeLine(raws[index], index + 1)
1475 return Result.succeed(f(new YamlParser(lines)))
1476 } catch (e) {
1477 return Result.fail(
1478 new EncodingError({
1479 module: "Yaml",
1480 kind: "Decode",
1481 input,
1482 message: e instanceof Error ? e.message : "Invalid input"
1483 })
1484 )
1485 }
1486}
1487
1488/**
1489 * Parses a single YAML document into JavaScript values.

Callers 2

parseFunction · 0.70
parseAllFunction · 0.70

Calls 6

makeLineFunction · 0.85
failMethod · 0.65
fFunction · 0.50
splitMethod · 0.45
replaceMethod · 0.45
succeedMethod · 0.45

Tested by

no test coverage detected