MCPcopy
hub / github.com/di-sukharev/opencommit / parseEvent

Function parseEvent

out/cli.cjs:34152–34209  ·  view source on GitHub ↗
(chunk, decoder)

Source from the content-addressed store, hash-verified

34150 return sequence;
34151 }
34152 function parseEvent(chunk, decoder) {
34153 var _a5;
34154 if (!chunk.length) {
34155 return null;
34156 }
34157 const td = new TextDecoder();
34158 const raw = td.decode(chunk);
34159 const lines = raw.split(/\r?\n|\r/g);
34160 let publish = false;
34161 const rawEvent = {};
34162 for (const line of lines) {
34163 if (!line) {
34164 continue;
34165 }
34166 const delim = line.indexOf(":");
34167 if (delim === 0) {
34168 continue;
34169 }
34170 const field = delim > 0 ? line.substring(0, delim) : "";
34171 let value = delim > 0 ? line.substring(delim + 1) : "";
34172 if (value.charAt(0) === " ") {
34173 value = value.substring(1);
34174 }
34175 switch (field) {
34176 case "event": {
34177 publish = true;
34178 rawEvent.event = value;
34179 break;
34180 }
34181 case "data": {
34182 publish = true;
34183 (_a5 = rawEvent.data) !== null && _a5 !== void 0 ? _a5 : rawEvent.data = "";
34184 rawEvent.data += value + "\n";
34185 break;
34186 }
34187 case "id": {
34188 publish = true;
34189 rawEvent.id = value;
34190 break;
34191 }
34192 case "retry": {
34193 const r3 = parseInt(value, 10);
34194 if (!Number.isNaN(r3)) {
34195 publish = true;
34196 rawEvent.retry = r3;
34197 }
34198 break;
34199 }
34200 }
34201 }
34202 if (!publish) {
34203 return null;
34204 }
34205 if (rawEvent.data != null) {
34206 rawEvent.data = rawEvent.data.slice(0, -1);
34207 }
34208 return decoder(rawEvent);
34209 }

Callers 2

startFunction · 0.85

Calls 3

decoderFunction · 0.85
decodeMethod · 0.45
sliceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…