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.

47 lines
1.4 KiB

4 years ago
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _wrapString = _interopRequireDefault(require("./wrapString"));
  7. var _wrapWord = _interopRequireDefault(require("./wrapWord"));
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. /**
  10. * Wrap a single cell value into a list of lines
  11. *
  12. * Always wraps on newlines, for the remainder uses either word or string wrapping
  13. * depending on user configuration.
  14. *
  15. * @param {string} cellValue
  16. * @param {number} columnWidth
  17. * @param {boolean} useWrapWord
  18. * @returns {Array}
  19. */
  20. const wrapCell = (cellValue, columnWidth, useWrapWord) => {
  21. // First split on literal newlines
  22. const cellLines = cellValue.split('\n'); // Then iterate over the list and word-wrap every remaining line if necessary.
  23. for (let lineNr = 0; lineNr < cellLines.length;) {
  24. let lineChunks;
  25. if (useWrapWord) {
  26. lineChunks = (0, _wrapWord.default)(cellLines[lineNr], columnWidth);
  27. } else {
  28. lineChunks = (0, _wrapString.default)(cellLines[lineNr], columnWidth);
  29. } // Replace our original array element with whatever the wrapping returned
  30. cellLines.splice(lineNr, 1, ...lineChunks);
  31. lineNr += lineChunks.length;
  32. }
  33. return cellLines;
  34. };
  35. var _default = wrapCell;
  36. exports.default = _default;
  37. //# sourceMappingURL=wrapCell.js.map