Skip to content

truncate

truncate(text, maxLength, options?): string

Defined in: packages/core/src/string/truncate.ts:42

Truncates text to at most maxLength UTF-16 code units, counting each code unit as one unit of length.

This is a simple truncation that does not consider grapheme clusters or wide characters. Use @ac-kit/format-monospace’s truncateToWidth for truncation based on visible width in monospace fonts.

string

The input string to be truncated.

number

The maximum allowed length of the string including the ellipsis.

TruncateOptions

Options to customize the ellipsis behavior.

string

The truncated string with ellipsis if needed.