8 lines · 206 B · TypeScript
RawDownload
export function truncate(text: string, maxLength = 50): string {  const trimmed = text.trim();  if (trimmed.length <= maxLength) {    return trimmed;  }   return `${trimmed.slice(0, maxLength)}...`;}