@jsvision/ui / alignCell
Function: alignCell()
alignCell(
text,width,align,measure):string
Defined in: ui/src/table/columns.ts:205
Clip text to exactly width cells (width-aware — never splits a wide/CJK glyph), then pad to the requested alignment: left pads on the right, right pads on the left, center splits the remainder (an odd extra cell goes to the right). The result is always exactly width cells. This only clips and pads; the caller is responsible for sanitizing before drawing.
Parameters
text
string
The cell text.
width
number
The target cell width (≤ 0 returns an empty string).
align
The horizontal alignment.
measure
(s) => number
Per-glyph display-width function (measures in terminal cells, wide-glyph aware).
Returns
string
A string that occupies exactly width terminal cells.
Example
ts
import { alignCell } from '@jsvision/ui';
alignCell('Ada', 6, 'right', (s) => s.length); // ' Ada'
alignCell('Bartholomew', 6, 'left', (s) => s.length); // 'Bartho' (clipped to 6 cells)