truncate
truncate(str: string, maxLength: number, suffix: string): stringSource: string.ts:131
Truncates a string to a specified length
Parameters
str(string) — The input stringmaxLength(number) — Maximum length of the resultsuffix(string, default: "'...'") — Suffix to append if truncated
Returns
string— Truncated string
Example
CODE
truncate('Hello World', 5) // 'Hello...'
truncate('Hello World', 5, '…') // 'Hello…'
truncate('Hi', 10) // 'Hi'