@jsvision/ui / stringWidth
Function: stringWidth()
stringWidth(
s):number
Defined in: ui/src/controls/measure.ts:39
Display width of a string, summed over its glyphs. Use this to measure text the way the screen buffer draws it — feed it to a grid's column-width / alignment math so auto-sized and CJK columns line up with what actually renders (a naive s.length counts a wide glyph as one column and drifts).
Parameters
s
string
The string to measure.
Returns
number
The total display width in columns.
Example
ts
import { stringWidth } from '@jsvision/ui';
stringWidth('ab'); // 2 — two narrow glyphs
stringWidth('日本'); // 4 — each wide CJK glyph is 2 columns