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

Method scan

packages/effect/src/encoding/JsonArray.ts:398–415  ·  view source on GitHub ↗
(text: string, i: number, out: Array<unknown>)

Source from the content-addressed store, hash-verified

396 // Continues the captured value from `i`, completing it if it ends in this
397 // chunk. Returns the index after the value, or the chunk length.
398 scan(text: string, i: number, out: Array<unknown>): number {
399 const end = this.scalar ? this.scanScalar(text, i) : this.scanNested(text, i)
400 if (end === -1) return text.length
401 const source = this.buffer + text.slice(Math.max(this.start - this.base, 0), end)
402 this.checkSize(source.length)
403 const mode = this.capture
404 this.capture = NONE
405 this.buffer = ""
406 let value: unknown
407 try {
408 value = JSON.parse(source)
409 } catch (cause) {
410 throw this.fail("Syntax", "Invalid JSON value", this.start, cause)
411 }
412 if (mode === ELEMENT) out.push(value)
413 else if (mode === KEY) this.key = value as string
414 return end
415 }
416
417 // A scalar ends at the first delimiter, which `JSON.parse` then validates.
418 scanScalar(text: string, i: number): number {

Callers 2

feedMethod · 0.95
beginMethod · 0.95

Calls 7

scanScalarMethod · 0.95
scanNestedMethod · 0.95
checkSizeMethod · 0.95
failMethod · 0.95
sliceMethod · 0.80
pushMethod · 0.65
parseMethod · 0.45

Tested by

no test coverage detected