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.

index.js 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.diff = diff;
  6. Object.defineProperty(exports, 'DIFF_DELETE', {
  7. enumerable: true,
  8. get: function () {
  9. return _cleanupSemantic.DIFF_DELETE;
  10. }
  11. });
  12. Object.defineProperty(exports, 'DIFF_EQUAL', {
  13. enumerable: true,
  14. get: function () {
  15. return _cleanupSemantic.DIFF_EQUAL;
  16. }
  17. });
  18. Object.defineProperty(exports, 'DIFF_INSERT', {
  19. enumerable: true,
  20. get: function () {
  21. return _cleanupSemantic.DIFF_INSERT;
  22. }
  23. });
  24. Object.defineProperty(exports, 'Diff', {
  25. enumerable: true,
  26. get: function () {
  27. return _cleanupSemantic.Diff;
  28. }
  29. });
  30. Object.defineProperty(exports, 'diffLinesRaw', {
  31. enumerable: true,
  32. get: function () {
  33. return _diffLines.diffLinesRaw;
  34. }
  35. });
  36. Object.defineProperty(exports, 'diffLinesUnified', {
  37. enumerable: true,
  38. get: function () {
  39. return _diffLines.diffLinesUnified;
  40. }
  41. });
  42. Object.defineProperty(exports, 'diffLinesUnified2', {
  43. enumerable: true,
  44. get: function () {
  45. return _diffLines.diffLinesUnified2;
  46. }
  47. });
  48. Object.defineProperty(exports, 'diffStringsRaw', {
  49. enumerable: true,
  50. get: function () {
  51. return _printDiffs.diffStringsRaw;
  52. }
  53. });
  54. Object.defineProperty(exports, 'diffStringsUnified', {
  55. enumerable: true,
  56. get: function () {
  57. return _printDiffs.diffStringsUnified;
  58. }
  59. });
  60. var _chalk = _interopRequireDefault(require('chalk'));
  61. var _jestGetType = require('jest-get-type');
  62. var _prettyFormat = require('pretty-format');
  63. var _cleanupSemantic = require('./cleanupSemantic');
  64. var _constants = require('./constants');
  65. var _diffLines = require('./diffLines');
  66. var _normalizeDiffOptions = require('./normalizeDiffOptions');
  67. var _printDiffs = require('./printDiffs');
  68. function _interopRequireDefault(obj) {
  69. return obj && obj.__esModule ? obj : {default: obj};
  70. }
  71. var global = (function () {
  72. if (typeof globalThis !== 'undefined') {
  73. return globalThis;
  74. } else if (typeof global !== 'undefined') {
  75. return global;
  76. } else if (typeof self !== 'undefined') {
  77. return self;
  78. } else if (typeof window !== 'undefined') {
  79. return window;
  80. } else {
  81. return Function('return this')();
  82. }
  83. })();
  84. var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;
  85. const getCommonMessage = (message, options) => {
  86. const {commonColor} = (0, _normalizeDiffOptions.normalizeDiffOptions)(
  87. options
  88. );
  89. return commonColor(message);
  90. };
  91. const {
  92. AsymmetricMatcher,
  93. DOMCollection,
  94. DOMElement,
  95. Immutable,
  96. ReactElement,
  97. ReactTestComponent
  98. } = _prettyFormat.plugins;
  99. const PLUGINS = [
  100. ReactTestComponent,
  101. ReactElement,
  102. DOMElement,
  103. DOMCollection,
  104. Immutable,
  105. AsymmetricMatcher
  106. ];
  107. const FORMAT_OPTIONS = {
  108. plugins: PLUGINS
  109. };
  110. const FORMAT_OPTIONS_0 = {...FORMAT_OPTIONS, indent: 0};
  111. const FALLBACK_FORMAT_OPTIONS = {
  112. callToJSON: false,
  113. maxDepth: 10,
  114. plugins: PLUGINS
  115. };
  116. const FALLBACK_FORMAT_OPTIONS_0 = {...FALLBACK_FORMAT_OPTIONS, indent: 0}; // Generate a string that will highlight the difference between two values
  117. // with green and red. (similar to how github does code diffing)
  118. // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
  119. function diff(a, b, options) {
  120. if (Object.is(a, b)) {
  121. return getCommonMessage(_constants.NO_DIFF_MESSAGE, options);
  122. }
  123. const aType = (0, _jestGetType.getType)(a);
  124. let expectedType = aType;
  125. let omitDifference = false;
  126. if (aType === 'object' && typeof a.asymmetricMatch === 'function') {
  127. if (a.$$typeof !== Symbol.for('jest.asymmetricMatcher')) {
  128. // Do not know expected type of user-defined asymmetric matcher.
  129. return null;
  130. }
  131. if (typeof a.getExpectedType !== 'function') {
  132. // For example, expect.anything() matches either null or undefined
  133. return null;
  134. }
  135. expectedType = a.getExpectedType(); // Primitive types boolean and number omit difference below.
  136. // For example, omit difference for expect.stringMatching(regexp)
  137. omitDifference = expectedType === 'string';
  138. }
  139. if (expectedType !== (0, _jestGetType.getType)(b)) {
  140. return (
  141. ' Comparing two different types of values.' +
  142. ` Expected ${_chalk.default.green(expectedType)} but ` +
  143. `received ${_chalk.default.red((0, _jestGetType.getType)(b))}.`
  144. );
  145. }
  146. if (omitDifference) {
  147. return null;
  148. }
  149. switch (aType) {
  150. case 'string':
  151. return (0, _diffLines.diffLinesUnified)(
  152. a.split('\n'),
  153. b.split('\n'),
  154. options
  155. );
  156. case 'boolean':
  157. case 'number':
  158. return comparePrimitive(a, b, options);
  159. case 'map':
  160. return compareObjects(sortMap(a), sortMap(b), options);
  161. case 'set':
  162. return compareObjects(sortSet(a), sortSet(b), options);
  163. default:
  164. return compareObjects(a, b, options);
  165. }
  166. }
  167. function comparePrimitive(a, b, options) {
  168. const aFormat = (0, _prettyFormat.format)(a, FORMAT_OPTIONS);
  169. const bFormat = (0, _prettyFormat.format)(b, FORMAT_OPTIONS);
  170. return aFormat === bFormat
  171. ? getCommonMessage(_constants.NO_DIFF_MESSAGE, options)
  172. : (0, _diffLines.diffLinesUnified)(
  173. aFormat.split('\n'),
  174. bFormat.split('\n'),
  175. options
  176. );
  177. }
  178. function sortMap(map) {
  179. return new Map(Array.from(map.entries()).sort());
  180. }
  181. function sortSet(set) {
  182. return new Set(Array.from(set.values()).sort());
  183. }
  184. function compareObjects(a, b, options) {
  185. let difference;
  186. let hasThrown = false;
  187. const noDiffMessage = getCommonMessage(_constants.NO_DIFF_MESSAGE, options);
  188. try {
  189. const aCompare = (0, _prettyFormat.format)(a, FORMAT_OPTIONS_0);
  190. const bCompare = (0, _prettyFormat.format)(b, FORMAT_OPTIONS_0);
  191. if (aCompare === bCompare) {
  192. difference = noDiffMessage;
  193. } else {
  194. const aDisplay = (0, _prettyFormat.format)(a, FORMAT_OPTIONS);
  195. const bDisplay = (0, _prettyFormat.format)(b, FORMAT_OPTIONS);
  196. difference = (0, _diffLines.diffLinesUnified2)(
  197. aDisplay.split('\n'),
  198. bDisplay.split('\n'),
  199. aCompare.split('\n'),
  200. bCompare.split('\n'),
  201. options
  202. );
  203. }
  204. } catch {
  205. hasThrown = true;
  206. } // If the comparison yields no results, compare again but this time
  207. // without calling `toJSON`. It's also possible that toJSON might throw.
  208. if (difference === undefined || difference === noDiffMessage) {
  209. const aCompare = (0, _prettyFormat.format)(a, FALLBACK_FORMAT_OPTIONS_0);
  210. const bCompare = (0, _prettyFormat.format)(b, FALLBACK_FORMAT_OPTIONS_0);
  211. if (aCompare === bCompare) {
  212. difference = noDiffMessage;
  213. } else {
  214. const aDisplay = (0, _prettyFormat.format)(a, FALLBACK_FORMAT_OPTIONS);
  215. const bDisplay = (0, _prettyFormat.format)(b, FALLBACK_FORMAT_OPTIONS);
  216. difference = (0, _diffLines.diffLinesUnified2)(
  217. aDisplay.split('\n'),
  218. bDisplay.split('\n'),
  219. aCompare.split('\n'),
  220. bCompare.split('\n'),
  221. options
  222. );
  223. }
  224. if (difference !== noDiffMessage && !hasThrown) {
  225. difference =
  226. getCommonMessage(_constants.SIMILAR_MESSAGE, options) +
  227. '\n\n' +
  228. difference;
  229. }
  230. }
  231. return difference;
  232. }