minimal adjustments
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / table / dist / wrapCell.js
1 "use strict";
2
3 Object.defineProperty(exports, "__esModule", {
4   value: true
5 });
6 exports.default = void 0;
7
8 var _wrapString = _interopRequireDefault(require("./wrapString"));
9
10 var _wrapWord = _interopRequireDefault(require("./wrapWord"));
11
12 function _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  */
25 const 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
46 var _default = wrapCell;
47 exports.default = _default;
48 //# sourceMappingURL=wrapCell.js.map