(oldCode: string, newCode: string)
| 14 | }; |
| 15 | |
| 16 | function 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 | |
| 45 | function normalize(text: string) { |
| 46 | return text && text.trimEnd().concat("\n"); |
no test coverage detected