Trim Text
1 min read
Description
Intelligently truncates text at word boundaries to maintain readability. Unlike basic string truncation that cuts words mid-character, this function finds the last complete word within the specified length and adds ellipsis appropriately. Returns both the processed text and a boolean indicating whether truncation occurred.
Code
const trimText = (
input: string,
length: number = 80,
): [text: string,