Ohm-Management - Projektarbeit B-ME
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.

makeConfig.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _lodash = _interopRequireDefault(require("lodash"));
  7. var _getBorderCharacters = _interopRequireDefault(require("./getBorderCharacters"));
  8. var _validateConfig = _interopRequireDefault(require("./validateConfig"));
  9. var _calculateMaximumColumnWidthIndex = _interopRequireDefault(require("./calculateMaximumColumnWidthIndex"));
  10. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11. /**
  12. * Merges user provided border characters with the default border ("honeywell") characters.
  13. *
  14. * @param {Object} border
  15. * @returns {Object}
  16. */
  17. const makeBorder = (border = {}) => {
  18. return Object.assign({}, (0, _getBorderCharacters.default)('honeywell'), border);
  19. };
  20. /**
  21. * Creates a configuration for every column using default
  22. * values for the missing configuration properties.
  23. *
  24. * @param {Array[]} rows
  25. * @param {Object} columns
  26. * @param {Object} columnDefault
  27. * @returns {Object}
  28. */
  29. const makeColumns = (rows, columns = {}, columnDefault = {}) => {
  30. const maximumColumnWidthIndex = (0, _calculateMaximumColumnWidthIndex.default)(rows);
  31. _lodash.default.times(rows[0].length, index => {
  32. if (_lodash.default.isUndefined(columns[index])) {
  33. columns[index] = {};
  34. }
  35. columns[index] = Object.assign({
  36. alignment: 'left',
  37. paddingLeft: 1,
  38. paddingRight: 1,
  39. truncate: Infinity,
  40. width: maximumColumnWidthIndex[index],
  41. wrapWord: false
  42. }, columnDefault, columns[index]);
  43. });
  44. return columns;
  45. };
  46. /**
  47. * Makes a new configuration object out of the userConfig object
  48. * using default values for the missing configuration properties.
  49. *
  50. * @param {Array[]} rows
  51. * @param {Object} userConfig
  52. * @returns {Object}
  53. */
  54. const makeConfig = (rows, userConfig = {}) => {
  55. (0, _validateConfig.default)('config.json', userConfig);
  56. const config = _lodash.default.cloneDeep(userConfig);
  57. config.border = makeBorder(config.border);
  58. config.columns = makeColumns(rows, config.columns, config.columnDefault);
  59. if (!config.drawHorizontalLine) {
  60. /**
  61. * @returns {boolean}
  62. */
  63. config.drawHorizontalLine = () => {
  64. return true;
  65. };
  66. }
  67. return config;
  68. };
  69. var _default = makeConfig;
  70. exports.default = _default;
  71. //# sourceMappingURL=makeConfig.js.map