Skip to content

Commit ce01874

Browse files
committed
fix: correct cell width resolution logic (fixes #88, #9)
1 parent 6e167c0 commit ce01874

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/calculateCellWidthIndex.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import stringWidth from 'string-width';
88
*/
99
export default (cells) => {
1010
return cells.map((value) => {
11-
return stringWidth(value);
11+
return Math.max(
12+
...value.split('\n').map((line) => {
13+
return stringWidth(line);
14+
})
15+
);
1216
});
1317
};

test/calculateCellWidthIndex.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,13 @@ describe('calculateCellWidthIndex', () => {
1717
expect(cellWidthIndex[2]).to.equal(6, 'third column');
1818
});
1919
});
20+
context('cell contains newline characters', () => {
21+
it('picks the longest line length', () => {
22+
const cellWidthIndex = calculateCellWidthIndex([
23+
'aaaa\naa'
24+
]);
25+
26+
expect(cellWidthIndex[0]).to.equal(4);
27+
});
28+
});
2029
});

0 commit comments

Comments
 (0)