INNER CODE UNIT · TypeScript

lines

tomascupr/sandstorm · clients/typescript/src/index.ts:122

  const lines = raw.split(/\r?\n/);
  const dataLines: string[] = [];
  let event: string | undefined;
  for (const line of lines) {
    if (!line || line.startsWith(":")) continue; // comments / keepalives
    if (line.startsWith("data:")) {
      // Per SSE spec: strip a single leading space after the colon; multiple
      // data lines are joined with "\n" to reconstruct multi-line payloads.
      const raw = line.slice(5);
      dataLines.push(raw.startsWith(" ") ? raw.slice(1) : raw);
    } else if (line.startsWith("event:")) {
      event = line.slice(6).trim();
    }
  }
  if (dataLines.length === 0) return null;
  const data = dataLines.join("\n");
  let json: unknown = null;
  try {

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…