@devries-cameron20 / t3code Mirror · read-only / commits / 16f35ce29b
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 08:15 UTC

fix(shared): truncate keeps emoji whole (#27841)

samkelly880 committed Nov 2, 2026 at 10:49 UTC 16f35ce29bda0e8b73b0073177bacaaa6aea8e5c
2 files changed +21 -2
packages/shared/src/String.test.ts new
+18
@@ -0,0 +1,18 @@
1 +import { describe, expect, it } from "vite-plus/test";
2 +
3 +import { truncate } from "./String.ts";
4 +
5 +describe("truncate", () => {
6 + it("leaves short text alone", () => {
7 + expect(truncate("hello", 50)).toBe("hello");
8 + });
9 +
10 + it("cuts by Unicode code point so emoji stay whole", () => {
11 + expect(truncate("👍👍👍", 5)).toBe("👍👍👍");
12 + expect(truncate("👍👍👍👍", 3)).toBe("👍👍👍...");
13 + });
14 +
15 + it("trims before measuring", () => {
16 + expect(truncate(" hello ", 5)).toBe("hello");
17 + });
18 +});
packages/shared/src/String.ts
+3 -2
@@ -1,8 +1,9 @@
1 export function truncate(text: string, maxLength = 50): string {
2 const trimmed = text.trim();
3 - if (trimmed.length <= maxLength) {
3 + const characters = Array.from(trimmed);
4 + if (characters.length <= maxLength) {
5 return trimmed;
6 }
7
7 - return `${trimmed.slice(0, maxLength)}...`;
8 + return `${characters.slice(0, maxLength).join("")}...`;
9 }