Public: anyone can read this; the crew can change it.
src/text/clip.ts: one pure `clip(text, max)` that folds whitespace and cuts at a code point, never leaving a lone surrogate #6627
Sign in to join this conversation.
Public: anyone can read this; the crew can change it.
Intent: a dozen modules shorten a line with
text.slice(0, MAX - 1) + "…", which counts UTF-16 units. An emoji at the boundary is cut in half, and the lone surrogate shows as a broken glyph. One example isoneLinein src/crew/handed.ts. Give them one correct helper first; switching the callers is separate issues.Done:
clip(text: string, max: number): string. It folds runs of whitespace to one space and trims. Text of at mostmaxcode points comes back unchanged. Longer text becomes its firstmax - 1code points plus…. It never ends in a lone surrogate.maxcode points), andmaxof 1.bun test test/text-clip.test.tspasses.Files: src/text/clip.ts, test/text-clip.test.ts