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.flow 692B

1234567891011121314151617181920212223242526272829
  1. import _ from 'lodash';
  2. import stringWidth from 'string-width';
  3. import wrapWord from './wrapWord';
  4. /**
  5. * @param {string} value
  6. * @param {number} columnWidth
  7. * @param {boolean} useWrapWord
  8. * @returns {number}
  9. */
  10. export default (value, columnWidth, useWrapWord = false) => {
  11. if (!_.isString(value)) {
  12. throw new TypeError('Value must be a string.');
  13. }
  14. if (!Number.isInteger(columnWidth)) {
  15. throw new TypeError('Column width must be an integer.');
  16. }
  17. if (columnWidth < 1) {
  18. throw new Error('Column width must be greater than 0.');
  19. }
  20. if (useWrapWord) {
  21. return wrapWord(value, columnWidth).length;
  22. }
  23. return Math.ceil(stringWidth(value) / columnWidth);
  24. };