Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

diffLines.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.diffLinesRaw =
  6. exports.diffLinesUnified2 =
  7. exports.diffLinesUnified =
  8. void 0;
  9. var _diffSequences = _interopRequireDefault(require('diff-sequences'));
  10. var _cleanupSemantic = require('./cleanupSemantic');
  11. var _normalizeDiffOptions = require('./normalizeDiffOptions');
  12. var _printDiffs = require('./printDiffs');
  13. function _interopRequireDefault(obj) {
  14. return obj && obj.__esModule ? obj : {default: obj};
  15. }
  16. /**
  17. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  18. *
  19. * This source code is licensed under the MIT license found in the
  20. * LICENSE file in the root directory of this source tree.
  21. */
  22. const isEmptyString = lines => lines.length === 1 && lines[0].length === 0; // Compare two arrays of strings line-by-line. Format as comparison lines.
  23. const diffLinesUnified = (aLines, bLines, options) =>
  24. (0, _printDiffs.printDiffLines)(
  25. diffLinesRaw(
  26. isEmptyString(aLines) ? [] : aLines,
  27. isEmptyString(bLines) ? [] : bLines
  28. ),
  29. (0, _normalizeDiffOptions.normalizeDiffOptions)(options)
  30. ); // Given two pairs of arrays of strings:
  31. // Compare the pair of comparison arrays line-by-line.
  32. // Format the corresponding lines in the pair of displayable arrays.
  33. exports.diffLinesUnified = diffLinesUnified;
  34. const diffLinesUnified2 = (
  35. aLinesDisplay,
  36. bLinesDisplay,
  37. aLinesCompare,
  38. bLinesCompare,
  39. options
  40. ) => {
  41. if (isEmptyString(aLinesDisplay) && isEmptyString(aLinesCompare)) {
  42. aLinesDisplay = [];
  43. aLinesCompare = [];
  44. }
  45. if (isEmptyString(bLinesDisplay) && isEmptyString(bLinesCompare)) {
  46. bLinesDisplay = [];
  47. bLinesCompare = [];
  48. }
  49. if (
  50. aLinesDisplay.length !== aLinesCompare.length ||
  51. bLinesDisplay.length !== bLinesCompare.length
  52. ) {
  53. // Fall back to diff of display lines.
  54. return diffLinesUnified(aLinesDisplay, bLinesDisplay, options);
  55. }
  56. const diffs = diffLinesRaw(aLinesCompare, bLinesCompare); // Replace comparison lines with displayable lines.
  57. let aIndex = 0;
  58. let bIndex = 0;
  59. diffs.forEach(diff => {
  60. switch (diff[0]) {
  61. case _cleanupSemantic.DIFF_DELETE:
  62. diff[1] = aLinesDisplay[aIndex];
  63. aIndex += 1;
  64. break;
  65. case _cleanupSemantic.DIFF_INSERT:
  66. diff[1] = bLinesDisplay[bIndex];
  67. bIndex += 1;
  68. break;
  69. default:
  70. diff[1] = bLinesDisplay[bIndex];
  71. aIndex += 1;
  72. bIndex += 1;
  73. }
  74. });
  75. return (0, _printDiffs.printDiffLines)(
  76. diffs,
  77. (0, _normalizeDiffOptions.normalizeDiffOptions)(options)
  78. );
  79. }; // Compare two arrays of strings line-by-line.
  80. exports.diffLinesUnified2 = diffLinesUnified2;
  81. const diffLinesRaw = (aLines, bLines) => {
  82. const aLength = aLines.length;
  83. const bLength = bLines.length;
  84. const isCommon = (aIndex, bIndex) => aLines[aIndex] === bLines[bIndex];
  85. const diffs = [];
  86. let aIndex = 0;
  87. let bIndex = 0;
  88. const foundSubsequence = (nCommon, aCommon, bCommon) => {
  89. for (; aIndex !== aCommon; aIndex += 1) {
  90. diffs.push(
  91. new _cleanupSemantic.Diff(_cleanupSemantic.DIFF_DELETE, aLines[aIndex])
  92. );
  93. }
  94. for (; bIndex !== bCommon; bIndex += 1) {
  95. diffs.push(
  96. new _cleanupSemantic.Diff(_cleanupSemantic.DIFF_INSERT, bLines[bIndex])
  97. );
  98. }
  99. for (; nCommon !== 0; nCommon -= 1, aIndex += 1, bIndex += 1) {
  100. diffs.push(
  101. new _cleanupSemantic.Diff(_cleanupSemantic.DIFF_EQUAL, bLines[bIndex])
  102. );
  103. }
  104. };
  105. (0, _diffSequences.default)(aLength, bLength, isCommon, foundSubsequence); // After the last common subsequence, push remaining change items.
  106. for (; aIndex !== aLength; aIndex += 1) {
  107. diffs.push(
  108. new _cleanupSemantic.Diff(_cleanupSemantic.DIFF_DELETE, aLines[aIndex])
  109. );
  110. }
  111. for (; bIndex !== bLength; bIndex += 1) {
  112. diffs.push(
  113. new _cleanupSemantic.Diff(_cleanupSemantic.DIFF_INSERT, bLines[bIndex])
  114. );
  115. }
  116. return diffs;
  117. };
  118. exports.diffLinesRaw = diffLinesRaw;