/** * Truncate a string, cutting off the start and replacing with an ellipsis when * it exceeds a length constraint. */ export function ellipsifyStart(text: string, length: number): string { return text.length <= length ? text : length === 0 ? "" : length === 1 ? "…" : "…" + text.substr(-(length - 1)); } /** * Truncate a string, cutting off the end and replacing with an ellipsis when it * exceeds a length constraint. */ export function ellipsifyEnd(text: string, length: number): string { return text.length > length ? text.substr(0, length - 1) + "…" : text; }