Skip to content

truncateToWidth

truncateToWidth(text, maxWidth, options?): string

Defined in: truncate-to-width.ts:20

Truncates text to at most maxWidth columns, counting wide characters (CJK ideographs, fullwidth characters, emoji) as two columns and combining marks as zero columns.

maxWidth counts monospace columns, not UTF-16 code units or code points — a surrogate pair can be split across the cut. Use truncate for a code-unit-based cut.

string

The input string to be truncated.

number

The maximum allowed width of the string including the ellipsis.

TruncateOptions

Options to customize the ellipsis behavior.

string

The truncated string with ellipsis if needed.