Open History to see the last commit
1import { splitsSurrogatePair } from "@t3tools/shared/assistantCitations";
2
3function truncateMiddle(value: string, maxLength: number): string {
4 if (value.length <= maxLength) {
5 return value;
6 }
7
8 const headLength = Math.ceil((maxLength - 1) / 2);
9 const tailStart = value.length - Math.floor((maxLength - 1) / 2);
10 const headEnd = splitsSurrogatePair(value, headLength) ? headLength - 1 : headLength;
11 const tailFrom = splitsSurrogatePair(value, tailStart) ? tailStart + 1 : tailStart;
12 return `${value.slice(0, headEnd)}…${value.slice(tailFrom)}`;
13}
14
15export function compactMenuBranchLabel(branch: string): string {
16 return truncateMiddle(branch, 24);
17}