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.

24 lines
583 B

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