"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }); const NEWLINES_RE = /(\r\n|\r|\n)/g; function encode(chunk) { return "comment" in chunk ? encodeComment(chunk.comment) : encodeMessage(chunk); } function encodeData(text) { if (!text) return ""; const lines = `${text}`.replace(NEWLINES_RE, ` `).split(/\n/); let line = "", output = ""; for (let i = 0, numLines = lines.length; i < numLines; ++i) line = lines[i], output += `data: ${line}`, output += i + 1 === numLines ? ` ` : ` `; return output; } function encodeComment(comment) { return `: ${comment.replace(NEWLINES_RE, ` : `)} `; } function encodeMessage(message) { let output = ""; return message.event && (output += `event: ${message.event} `), typeof message.retry == "number" && Number.isFinite(message.retry) && (output += `retry: ${message.retry} `), (typeof message.id == "string" || typeof message.id == "number") && (output += `id: ${message.id} `), typeof message.data == "string" ? output += encodeData(message.data) : output && (output += ` `), output; } exports.encode = encode; exports.encodeComment = encodeComment; exports.encodeData = encodeData; //# sourceMappingURL=index.cjs.map