diff --git a/src/utils/truncate.ts b/src/utils/truncate.ts index fa35c10e..c0a1d716 100644 --- a/src/utils/truncate.ts +++ b/src/utils/truncate.ts @@ -131,11 +131,15 @@ export function truncateToWidthNoEllipsis( * @param singleLine If true, also truncates at the first newline * @returns The truncated string with ellipsis if needed */ + export function truncate( str: string, maxWidth: number, singleLine: boolean = false, ): string { + // Undefined or null protection + if (!str) return '' + let result = str // If singleLine is true, truncate at first newline