Truncate String

Truncates a string to a specified length.

CategoryStrings
AuthorPol Gubau
Since1.0.0
Last Updated2025-03-15
TypeSync
CompatibilityUniversal

Example

  • Input

    truncateString('This is a long string', 10)

    Output:

    'This is a...'

Return

Returns the truncated string with an optional suffix.

Type: string

Props

NameTypeDefaultRequiredDescription
strstringnullYesThe string to truncate.
lengthnumber50NoThe maximum length of the truncated string.
suffixstring...NoThe suffix to append after truncating.

Notes

This function truncates the string to a specified length, appending a suffix if necessary.

Tags

  • string
  • truncate

Related