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

Function decodeString

packages/effect/src/unstable/encoding/Ndjson.ts:174–196  ·  view source on GitHub ↗
(options?: {
  readonly ignoreEmptyLines?: boolean | undefined
})

Source from the content-addressed store, hash-verified

172 * @since 4.0.0
173 */
174export const decodeString = <IE = never, Done = unknown>(options?: {
175 readonly ignoreEmptyLines?: boolean | undefined
176}): Channel.Channel<
177 Arr.NonEmptyReadonlyArray<unknown>,
178 IE | NdjsonError,
179 Done,
180 Arr.NonEmptyReadonlyArray<string>,
181 IE,
182 Done
183> => {
184 const lines = Channel.splitLines<IE, Done>().pipe(
185 options?.ignoreEmptyLines === true ?
186 Channel.filterArray((line) => line.length > 0) :
187 identity
188 )
189 return Channel.mapEffect(lines, (chunk) => {
190 try {
191 return Effect.succeed(Arr.map(chunk, (line) => JSON.parse(line)))
192 } catch (cause) {
193 return Effect.fail(new NdjsonError({ kind: "Unpack", cause }))
194 }
195 })
196}
197
198/**
199 * Creates a channel that decodes UTF-8 byte chunks and parses them as NDJSON.

Callers 3

decodeFunction · 0.85
decodeSchemaStringFunction · 0.85
Ndjson.tsFile · 0.85

Calls 5

pipeMethod · 0.65
succeedMethod · 0.45
mapMethod · 0.45
parseMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected