MCPcopy Create free account
hub / github.com/pomber/code-surfer / getChanges

Function getChanges

packs/step-parser/src/differ.ts:16–43  ·  view source on GitHub ↗
(oldCode: string, newCode: string)

Source from the content-addressed store, hash-verified

14 };
15
16function getChanges(oldCode: string, newCode: string) {
17 const changes = diffLines(normalize(oldCode), normalize(newCode));
18 let index = 0;
19 const chunks: { op: "-" | "+"; count: number; index: number }[] = [];
20 changes.forEach(({ count = 0, removed, added }) => {
21 if (removed) {
22 chunks.push({
23 op: "-",
24 count,
25 index
26 });
27 }
28
29 if (added) {
30 chunks.push({
31 op: "+",
32 count,
33 index
34 });
35 }
36
37 if (!removed) {
38 index += count;
39 }
40 });
41
42 return chunks;
43}
44
45function normalize(text: string) {
46 return text && text.trimEnd().concat("\n");

Callers 1

getStepIdsFunction · 0.85

Calls 1

normalizeFunction · 0.85

Tested by

no test coverage detected