normalizeDiffOptions.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.normalizeDiffOptions = exports.noColor = void 0;
  6. var _chalk = _interopRequireDefault(require('chalk'));
  7. function _interopRequireDefault(obj) {
  8. return obj && obj.__esModule ? obj : {default: obj};
  9. }
  10. /**
  11. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  12. *
  13. * This source code is licensed under the MIT license found in the
  14. * LICENSE file in the root directory of this source tree.
  15. */
  16. const noColor = string => string;
  17. exports.noColor = noColor;
  18. const DIFF_CONTEXT_DEFAULT = 5;
  19. const OPTIONS_DEFAULT = {
  20. aAnnotation: 'Expected',
  21. aColor: _chalk.default.green,
  22. aIndicator: '-',
  23. bAnnotation: 'Received',
  24. bColor: _chalk.default.red,
  25. bIndicator: '+',
  26. changeColor: _chalk.default.inverse,
  27. changeLineTrailingSpaceColor: noColor,
  28. commonColor: _chalk.default.dim,
  29. commonIndicator: ' ',
  30. commonLineTrailingSpaceColor: noColor,
  31. compareKeys: undefined,
  32. contextLines: DIFF_CONTEXT_DEFAULT,
  33. emptyFirstOrLastLinePlaceholder: '',
  34. expand: true,
  35. includeChangeCounts: false,
  36. omitAnnotationLines: false,
  37. patchColor: _chalk.default.yellow
  38. };
  39. const getCompareKeys = compareKeys =>
  40. compareKeys && typeof compareKeys === 'function'
  41. ? compareKeys
  42. : OPTIONS_DEFAULT.compareKeys;
  43. const getContextLines = contextLines =>
  44. typeof contextLines === 'number' &&
  45. Number.isSafeInteger(contextLines) &&
  46. contextLines >= 0
  47. ? contextLines
  48. : DIFF_CONTEXT_DEFAULT; // Pure function returns options with all properties.
  49. const normalizeDiffOptions = (options = {}) => ({
  50. ...OPTIONS_DEFAULT,
  51. ...options,
  52. compareKeys: getCompareKeys(options.compareKeys),
  53. contextLines: getContextLines(options.contextLines)
  54. });
  55. exports.normalizeDiffOptions = normalizeDiffOptions;