Skip to content

Commit

Permalink
fix: correct cell width resolution logic (fixes #88, #9)
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Feb 10, 2019
1 parent 6e167c0 commit ce01874
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/calculateCellWidthIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import stringWidth from 'string-width';
*/
export default (cells) => {
return cells.map((value) => {
return stringWidth(value);
return Math.max(
...value.split('\n').map((line) => {
return stringWidth(line);
})
);
});
};
9 changes: 9 additions & 0 deletions test/calculateCellWidthIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,13 @@ describe('calculateCellWidthIndex', () => {
expect(cellWidthIndex[2]).to.equal(6, 'third column');
});
});
context('cell contains newline characters', () => {
it('picks the longest line length', () => {
const cellWidthIndex = calculateCellWidthIndex([
'aaaa\naa'
]);

expect(cellWidthIndex[0]).to.equal(4);
});
});
});

0 comments on commit ce01874

Please sign in to comment.