Skip to content

truncate

truncate(text, maxLength, suffix): string

Defined in: utils/format.ts:38

Truncate text to a maximum length, adding suffix if truncated.

string

Text to truncate

number

Maximum length including suffix

string = "..."

Suffix to append when truncated (default: ”…”)

string

Truncated text

truncate("Hello, World!", 10); // "Hello, ..."
truncate("Short", 10); // "Short"
truncate("Custom", 6, ""); // "Custo…"