JavaScript-optional public web frontend for Bluesky
anartia.kelinci.net
sveltekit
atcute
bluesky
typescript
svelte
1export const truncateMiddle = (text: string, max: number): string => {
2 const len = text.length;
3
4 if (len <= max) {
5 return text;
6 }
7
8 const left = Math.ceil((max - 1) / 2);
9 const right = Math.floor((max - 1) / 2);
10
11 return text.slice(0, left) + '…' + text.slice(len - right);
12};
13
14export const truncateRight = (text: string, max: number): string => {
15 if (text.length <= max) {
16 return text;
17 }
18
19 return text.slice(0, max - 1) + '…';
20};