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.

README.md 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. # jsdiff
  2. [![Build Status](https://secure.travis-ci.org/kpdecker/jsdiff.svg)](http://travis-ci.org/kpdecker/jsdiff)
  3. [![Sauce Test Status](https://saucelabs.com/buildstatus/jsdiff)](https://saucelabs.com/u/jsdiff)
  4. A javascript text differencing implementation.
  5. Based on the algorithm proposed in
  6. ["An O(ND) Difference Algorithm and its Variations" (Myers, 1986)](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.6927).
  7. ## Installation
  8. ```bash
  9. npm install diff --save
  10. ```
  11. ## API
  12. * `Diff.diffChars(oldStr, newStr[, options])` - diffs two blocks of text, comparing character by character.
  13. Returns a list of change objects (See below).
  14. Options
  15. * `ignoreCase`: `true` to ignore casing difference. Defaults to `false`.
  16. * `Diff.diffWords(oldStr, newStr[, options])` - diffs two blocks of text, comparing word by word, ignoring whitespace.
  17. Returns a list of change objects (See below).
  18. Options
  19. * `ignoreCase`: Same as in `diffChars`.
  20. * `Diff.diffWordsWithSpace(oldStr, newStr[, options])` - diffs two blocks of text, comparing word by word, treating whitespace as significant.
  21. Returns a list of change objects (See below).
  22. * `Diff.diffLines(oldStr, newStr[, options])` - diffs two blocks of text, comparing line by line.
  23. Options
  24. * `ignoreWhitespace`: `true` to ignore leading and trailing whitespace. This is the same as `diffTrimmedLines`
  25. * `newlineIsToken`: `true` to treat newline characters as separate tokens. This allows for changes to the newline structure to occur independently of the line content and to be treated as such. In general this is the more human friendly form of `diffLines` and `diffLines` is better suited for patches and other computer friendly output.
  26. Returns a list of change objects (See below).
  27. * `Diff.diffTrimmedLines(oldStr, newStr[, options])` - diffs two blocks of text, comparing line by line, ignoring leading and trailing whitespace.
  28. Returns a list of change objects (See below).
  29. * `Diff.diffSentences(oldStr, newStr[, options])` - diffs two blocks of text, comparing sentence by sentence.
  30. Returns a list of change objects (See below).
  31. * `Diff.diffCss(oldStr, newStr[, options])` - diffs two blocks of text, comparing CSS tokens.
  32. Returns a list of change objects (See below).
  33. * `Diff.diffJson(oldObj, newObj[, options])` - diffs two JSON objects, comparing the fields defined on each. The order of fields, etc does not matter in this comparison.
  34. Returns a list of change objects (See below).
  35. * `Diff.diffArrays(oldArr, newArr[, options])` - diffs two arrays, comparing each item for strict equality (===).
  36. Options
  37. * `comparator`: `function(left, right)` for custom equality checks
  38. Returns a list of change objects (See below).
  39. * `Diff.createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader)` - creates a unified diff patch.
  40. Parameters:
  41. * `oldFileName` : String to be output in the filename section of the patch for the removals
  42. * `newFileName` : String to be output in the filename section of the patch for the additions
  43. * `oldStr` : Original string value
  44. * `newStr` : New string value
  45. * `oldHeader` : Additional information to include in the old file header
  46. * `newHeader` : Additional information to include in the new file header
  47. * `options` : An object with options. Currently, only `context` is supported and describes how many lines of context should be included.
  48. * `Diff.createPatch(fileName, oldStr, newStr, oldHeader, newHeader)` - creates a unified diff patch.
  49. Just like Diff.createTwoFilesPatch, but with oldFileName being equal to newFileName.
  50. * `Diff.structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options)` - returns an object with an array of hunk objects.
  51. This method is similar to createTwoFilesPatch, but returns a data structure
  52. suitable for further processing. Parameters are the same as createTwoFilesPatch. The data structure returned may look like this:
  53. ```js
  54. {
  55. oldFileName: 'oldfile', newFileName: 'newfile',
  56. oldHeader: 'header1', newHeader: 'header2',
  57. hunks: [{
  58. oldStart: 1, oldLines: 3, newStart: 1, newLines: 3,
  59. lines: [' line2', ' line3', '-line4', '+line5', '\\ No newline at end of file'],
  60. }]
  61. }
  62. ```
  63. * `Diff.applyPatch(source, patch[, options])` - applies a unified diff patch.
  64. Return a string containing new version of provided data. `patch` may be a string diff or the output from the `parsePatch` or `structuredPatch` methods.
  65. The optional `options` object may have the following keys:
  66. - `fuzzFactor`: Number of lines that are allowed to differ before rejecting a patch. Defaults to 0.
  67. - `compareLine(lineNumber, line, operation, patchContent)`: Callback used to compare to given lines to determine if they should be considered equal when patching. Defaults to strict equality but may be overridden to provide fuzzier comparison. Should return false if the lines should be rejected.
  68. * `Diff.applyPatches(patch, options)` - applies one or more patches.
  69. This method will iterate over the contents of the patch and apply to data provided through callbacks. The general flow for each patch index is:
  70. - `options.loadFile(index, callback)` is called. The caller should then load the contents of the file and then pass that to the `callback(err, data)` callback. Passing an `err` will terminate further patch execution.
  71. - `options.patched(index, content, callback)` is called once the patch has been applied. `content` will be the return value from `applyPatch`. When it's ready, the caller should call `callback(err)` callback. Passing an `err` will terminate further patch execution.
  72. Once all patches have been applied or an error occurs, the `options.complete(err)` callback is made.
  73. * `Diff.parsePatch(diffStr)` - Parses a patch into structured data
  74. Return a JSON object representation of the a patch, suitable for use with the `applyPatch` method. This parses to the same structure returned by `Diff.structuredPatch`.
  75. * `convertChangesToXML(changes)` - converts a list of changes to a serialized XML format
  76. All methods above which accept the optional `callback` method will run in sync mode when that parameter is omitted and in async mode when supplied. This allows for larger diffs without blocking the event loop. This may be passed either directly as the final parameter or as the `callback` field in the `options` object.
  77. ### Change Objects
  78. Many of the methods above return change objects. These objects consist of the following fields:
  79. * `value`: Text content
  80. * `added`: True if the value was inserted into the new string
  81. * `removed`: True if the value was removed from the old string
  82. Note that some cases may omit a particular flag field. Comparison on the flag fields should always be done in a truthy or falsy manner.
  83. ## Examples
  84. Basic example in Node
  85. ```js
  86. require('colors');
  87. const Diff = require('diff');
  88. const one = 'beep boop';
  89. const other = 'beep boob blah';
  90. const diff = Diff.diffChars(one, other);
  91. diff.forEach((part) => {
  92. // green for additions, red for deletions
  93. // grey for common parts
  94. const color = part.added ? 'green' :
  95. part.removed ? 'red' : 'grey';
  96. process.stderr.write(part.value[color]);
  97. });
  98. console.log();
  99. ```
  100. Running the above program should yield
  101. <img src="images/node_example.png" alt="Node Example">
  102. Basic example in a web page
  103. ```html
  104. <pre id="display"></pre>
  105. <script src="diff.js"></script>
  106. <script>
  107. const one = 'beep boop',
  108. other = 'beep boob blah',
  109. color = '';
  110. let span = null;
  111. const diff = Diff.diffChars(one, other),
  112. display = document.getElementById('display'),
  113. fragment = document.createDocumentFragment();
  114. diff.forEach((part) => {
  115. // green for additions, red for deletions
  116. // grey for common parts
  117. const color = part.added ? 'green' :
  118. part.removed ? 'red' : 'grey';
  119. span = document.createElement('span');
  120. span.style.color = color;
  121. span.appendChild(document
  122. .createTextNode(part.value));
  123. fragment.appendChild(span);
  124. });
  125. display.appendChild(fragment);
  126. </script>
  127. ```
  128. Open the above .html file in a browser and you should see
  129. <img src="images/web_example.png" alt="Node Example">
  130. **[Full online demo](http://kpdecker.github.com/jsdiff)**
  131. ## Compatibility
  132. [![Sauce Test Status](https://saucelabs.com/browser-matrix/jsdiff.svg)](https://saucelabs.com/u/jsdiff)
  133. jsdiff supports all ES3 environments with some known issues on IE8 and below. Under these browsers some diff algorithms such as word diff and others may fail due to lack of support for capturing groups in the `split` operation.
  134. ## License
  135. See [LICENSE](https://github.com/kpdecker/jsdiff/blob/master/LICENSE).