Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ThreadGitControls.logic.ts

17 lines669 Bytes

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)}`;
14​
15export function compactMenuBranchLabel(branch: string): string {
16 return truncateMiddle(branch, 24);