Skip to content

truncate

truncate(string, maxLength, suffix?) → string · String

Truncate a string to a maximum length, appending a suffix (default "...").

  • string (required): the string to truncate

  • maxLength (required): maximum total length (including suffix)

  • suffix (optional): suffix to append (default "...")

utlx
truncate("Hello World, this is a long string", 15)
// "Hello World,..."

truncate("Hello World", 20)              // "Hello World" (no truncation needed)

Released under AGPL-3.0.