dmp.js 699 B

123456789101112131415161718192021222324
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.convertChangesToDMP = convertChangesToDMP;
  4. /**
  5. * converts a list of change objects to the format returned by Google's [diff-match-patch](https://github.com/google/diff-match-patch) library
  6. */
  7. function convertChangesToDMP(changes) {
  8. var ret = [];
  9. var change, operation;
  10. for (var i = 0; i < changes.length; i++) {
  11. change = changes[i];
  12. if (change.added) {
  13. operation = 1;
  14. }
  15. else if (change.removed) {
  16. operation = -1;
  17. }
  18. else {
  19. operation = 0;
  20. }
  21. ret.push([operation, change.value]);
  22. }
  23. return ret;
  24. }