dmp.js 580 B

123456789101112131415161718192021
  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. */
  4. export 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. }