UNPKG

mihawk

Version:

A tiny & simple mock server tool, support json,js,cjs,ts(typescript).

37 lines (36 loc) 966 B
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseStompMsg = void 0; function parseStompMsg(stmopDataRaw) { if (!stmopDataRaw || typeof stmopDataRaw !== 'string') { return { command: 'UnkonwnCommand', headers: null, body: 'Exception: Empty or invalid stomp message, check it plz!', }; } const msg = { command: '', headers: {}, body: '', }; const lines = stmopDataRaw.split('\n'); msg.command = lines[0]; let bodyEnd = false; for (const line of lines) { if (line === '') { bodyEnd = true; continue; } if (bodyEnd) { msg.body += line + '\n'; } else { const [key, value] = line.split(':'); msg.headers[key] = value; } } msg.body = msg.body.trim(); return msg; } exports.parseStompMsg = parseStompMsg;