UNPKG

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