Skip to content

Commit b773573

Browse files
authored
fix: prevents table from throwing with negative numbers in .repeat() (#41)
1 parent cad3c03 commit b773573

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/components/table.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -385,12 +385,16 @@ export class Table extends Component {
385385
let string = "";
386386
let prevData = "";
387387
for (const [j, dataCell] of dataRow.entries()) {
388-
if (j !== 0) string += " ".repeat(headers[j - 1].width - textWidth(prevData) + 1);
388+
if (j !== 0) {
389+
const padding = Math.max(0, headers[j - 1].width - textWidth(prevData) + 1);
390+
string += " ".repeat(padding);
391+
}
389392
string += dataCell;
390393
prevData = dataCell;
391394
}
392395

393-
string += " ".repeat(this.rectangle.value.width - textWidth(string) - 2);
396+
const endPadding = Math.max(0, this.rectangle.value.width - textWidth(string) - 2);
397+
string += " ".repeat(endPadding);
394398
return string;
395399
}),
396400
rectangle: new Computed(() => {

0 commit comments

Comments
 (0)