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.

calculateCellHeight.js 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 _stringWidth = _interopRequireDefault(require("string-width"));
  8. var _wrapWord = _interopRequireDefault(require("./wrapWord"));
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. /**
  11. * @param {string} value
  12. * @param {number} columnWidth
  13. * @param {boolean} useWrapWord
  14. * @returns {number}
  15. */
  16. const calculateCellHeight = (value, columnWidth, useWrapWord = false) => {
  17. if (!_lodash.default.isString(value)) {
  18. throw new TypeError('Value must be a string.');
  19. }
  20. if (!Number.isInteger(columnWidth)) {
  21. throw new TypeError('Column width must be an integer.');
  22. }
  23. if (columnWidth < 1) {
  24. throw new Error('Column width must be greater than 0.');
  25. }
  26. if (useWrapWord) {
  27. return (0, _wrapWord.default)(value, columnWidth).length;
  28. }
  29. return Math.ceil((0, _stringWidth.default)(value) / columnWidth);
  30. };
  31. var _default = calculateCellHeight;
  32. exports.default = _default;
  33. //# sourceMappingURL=calculateCellHeight.js.map