MCPcopy Create free account
hub / github.com/callstack/agent-device / readBody

Function readBody

src/daemon/network-log.ts:350–367  ·  view source on GitHub ↗
(
  line: string,
  json: Record<string, unknown> | null,
  jsonKeys: string[],
)

Source from the content-addressed store, hash-verified

348}
349
350function readBody(
351 line: string,
352 json: Record<string, unknown> | null,
353 jsonKeys: string[],
354): string | undefined {
355 if (json) {
356 for (const key of jsonKeys) {
357 if (json[key] !== undefined) return stringifyValue(json[key]);
358 }
359 }
360 for (const key of jsonKeys) {
361 const escaped = key.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
362 const regex = new RegExp(`\\b${escaped}["'=: ]+(.+)$`, 'i');
363 const match = regex.exec(line);
364 if (match?.[1]) return match[1].trim();
365 }
366 return undefined;
367}
368
369function stringifyValue(value: unknown): string {
370 if (typeof value === 'string') return value;

Callers 1

parseNetworkLineFunction · 0.85

Calls 1

stringifyValueFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…