All files / src/utils truncate.ts

100% Statements 4/4
100% Branches 5/5
100% Functions 1/1
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 51x 9x 9x 9x  
export function truncate(str: string, length = 500): string {
	if (length < 0) throw new Error("Length must be non-negative");
	return str.length > length ? `${str.slice(0, length)}...` : str;
}