codekingpro/portable-devtools
115k
1/**
2 * converts a list of change objects to the format returned by Google's [diff-match-patch](https://github.com/google/diff-match-patch) library
3 */
4export function convertChangesToDMP(changes) {
5 const ret = [];
6 let change, operation;
7 for (let i = 0; i < changes.length; i++) {
8 change = changes[i];
9 if (change.added) {
10 operation = 1;
11 }
12 else if (change.removed) {
13 operation = -1;
14 }
15 else {
16 operation = 0;
17 }
18 ret.push([operation, change.value]);
19 }
20 return ret;
21}
22 