MCPcopy Create free account
hub / github.com/RtlZeroMemory/Rezi / alignCellText

Function alignCellText

packages/core/src/widgets/table.ts:440–461  ·  view source on GitHub ↗
(text: string, width: number, align: CellAlign)

Source from the content-addressed store, hash-verified

438 * @returns Padded text
439 */
440export function alignCellText(text: string, width: number, align: CellAlign): string {
441 const textLength = text.length;
442
443 if (textLength >= width) {
444 // Truncate if too long
445 return text.slice(0, width);
446 }
447
448 const padding = width - textLength;
449
450 switch (align) {
451 case "right":
452 return " ".repeat(padding) + text;
453 case "center": {
454 const leftPad = Math.floor(padding / 2);
455 const rightPad = padding - leftPad;
456 return " ".repeat(leftPad) + text + " ".repeat(rightPad);
457 }
458 case "left":
459 return text + " ".repeat(padding);
460 }
461}
462
463/* ========== Focused Row Navigation ========== */
464

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected