1 import wrapString from './wrapString';
2 import wrapWord from './wrapWord';
5 * Wrap a single cell value into a list of lines
7 * Always wraps on newlines, for the remainder uses either word or string wrapping
8 * depending on user configuration.
10 * @param {string} cellValue
11 * @param {number} columnWidth
12 * @param {boolean} useWrapWord
15 export default (cellValue, columnWidth, useWrapWord) => {
16 // First split on literal newlines
17 const cellLines = cellValue.split('\n');
19 // Then iterate over the list and word-wrap every remaining line if necessary.
20 for (let lineNr = 0; lineNr < cellLines.length;) {
24 lineChunks = wrapWord(cellLines[lineNr], columnWidth);
26 lineChunks = wrapString(cellLines[lineNr], columnWidth);
29 // Replace our original array element with whatever the wrapping returned
30 cellLines.splice(lineNr, 1, ...lineChunks);
31 lineNr += lineChunks.length;