Category
Truncate text to a certain length, optionally appending a suffix when truncated.
Time complexity: O(n)
Space complexity: O(n)
Text to truncate
Maximum length before text is truncated
Suffix to append if text was truncated
Truncated text
String
truncate('hello, world', 5, '...'); // 'hello...' Copy
truncate('hello, world', 5, '...'); // 'hello...'
Truncate text to a certain length, optionally appending a suffix when truncated.
Time complexity: O(n)
Space complexity: O(n)