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.

table.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _drawTable = _interopRequireDefault(require("./drawTable"));
  7. var _calculateCellWidthIndex = _interopRequireDefault(require("./calculateCellWidthIndex"));
  8. var _makeConfig = _interopRequireDefault(require("./makeConfig"));
  9. var _calculateRowHeightIndex = _interopRequireDefault(require("./calculateRowHeightIndex"));
  10. var _mapDataUsingRowHeightIndex = _interopRequireDefault(require("./mapDataUsingRowHeightIndex"));
  11. var _alignTableData = _interopRequireDefault(require("./alignTableData"));
  12. var _padTableData = _interopRequireDefault(require("./padTableData"));
  13. var _validateTableData = _interopRequireDefault(require("./validateTableData"));
  14. var _stringifyTableData = _interopRequireDefault(require("./stringifyTableData"));
  15. var _truncateTableData = _interopRequireDefault(require("./truncateTableData"));
  16. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  17. /**
  18. * @typedef {string} table~cell
  19. */
  20. /**
  21. * @typedef {table~cell[]} table~row
  22. */
  23. /**
  24. * @typedef {Object} table~columns
  25. * @property {string} alignment Cell content alignment (enum: left, center, right) (default: left).
  26. * @property {number} width Column width (default: auto).
  27. * @property {number} truncate Number of characters are which the content will be truncated (default: Infinity).
  28. * @property {boolean} wrapWord When true the text is broken at the nearest space or one of the special characters
  29. * @property {number} paddingLeft Cell content padding width left (default: 1).
  30. * @property {number} paddingRight Cell content padding width right (default: 1).
  31. */
  32. /**
  33. * @typedef {Object} table~border
  34. * @property {string} topBody
  35. * @property {string} topJoin
  36. * @property {string} topLeft
  37. * @property {string} topRight
  38. * @property {string} bottomBody
  39. * @property {string} bottomJoin
  40. * @property {string} bottomLeft
  41. * @property {string} bottomRight
  42. * @property {string} bodyLeft
  43. * @property {string} bodyRight
  44. * @property {string} bodyJoin
  45. * @property {string} joinBody
  46. * @property {string} joinLeft
  47. * @property {string} joinRight
  48. * @property {string} joinJoin
  49. */
  50. /**
  51. * Used to tell whether to draw a horizontal line.
  52. * This callback is called for each non-content line of the table.
  53. * The default behavior is to always return true.
  54. *
  55. * @typedef {Function} drawHorizontalLine
  56. * @param {number} index
  57. * @param {number} size
  58. * @returns {boolean}
  59. */
  60. /**
  61. * @typedef {Object} table~config
  62. * @property {table~border} border
  63. * @property {table~columns[]} columns Column specific configuration.
  64. * @property {table~columns} columnDefault Default values for all columns. Column specific settings overwrite the default values.
  65. * @property {table~drawHorizontalLine} drawHorizontalLine
  66. */
  67. /**
  68. * Generates a text table.
  69. *
  70. * @param {table~row[]} data
  71. * @param {table~config} userConfig
  72. * @returns {string}
  73. */
  74. const table = (data, userConfig = {}) => {
  75. let rows;
  76. (0, _validateTableData.default)(data);
  77. rows = (0, _stringifyTableData.default)(data);
  78. const config = (0, _makeConfig.default)(rows, userConfig);
  79. rows = (0, _truncateTableData.default)(data, config);
  80. const rowHeightIndex = (0, _calculateRowHeightIndex.default)(rows, config);
  81. rows = (0, _mapDataUsingRowHeightIndex.default)(rows, rowHeightIndex, config);
  82. rows = (0, _alignTableData.default)(rows, config);
  83. rows = (0, _padTableData.default)(rows, config);
  84. const cellWidthIndex = (0, _calculateCellWidthIndex.default)(rows[0]);
  85. return (0, _drawTable.default)(rows, config.border, cellWidthIndex, rowHeightIndex, config.drawHorizontalLine);
  86. };
  87. var _default = table;
  88. exports.default = _default;
  89. //# sourceMappingURL=table.js.map