-
-
Notifications
You must be signed in to change notification settings - Fork 79
Closed
Labels
Description
On line 38 you should be checking (I believe) that width is even, not half-width.
Lines 33 to 45 in 37fa97c
| const alignCenter = (subject, width) => { | |
| let halfWidth; | |
| halfWidth = width / 2; | |
| if (halfWidth % 2 === 0) { | |
| return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth); | |
| } else { | |
| halfWidth = Math.floor(halfWidth); | |
| return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth + 1); | |
| } | |
| }; |
Here's a little program to illustrate the issue.
#!/usr/bin/env node
const { table } = require('table');
const data = [
["ten characters"],
["ten characte"]
]
const config = {
columns: {
0: {
alignment: "center"
}
}
}
const output = table(data, config);
console.log(output);And here's the output
> ./index.js
╔════════════════╗
║ ten characters ║
╟────────────────╢
║ ten characte ║
╚════════════════╝Reactions are currently unavailable