- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/worker/project/unseen.ts?version=278&format=json
42 linesengine 100%Last change engine in version 81, 3 versions changed it
You're reading version 278. The newest is 318, and no version since then changed this file.
1// Characters a reader can't see, refused in text the engine keeps and prints:
2// version messages, starting notes, line notes and
3// announcements. In a terminal, ESC and C1 start escape sequences that can
4// set the clipboard or draw a fake link, so `abso log` and news must never
5// carry them. The same list as the website's announcements and Issues.
7const UNSEEN: [number, number, string][] = [
8 [0x00, 0x08, "a control character"],
9 [0x0b, 0x1f, "a control character"],
10 [0x7f, 0x9f, "a control character"],
11 [0x180e, 0x180e, "the Mongolian vowel separator (U+180E)"],
12 [0x200b, 0x200f, "a zero-width or direction mark (U+200B-200F)"],
13 [0x2028, 0x2029, "a line or paragraph separator (U+2028-2029)"],
14 [0x202a, 0x202e, "a bidirectional embedding or override (U+202A-202E)"],
15 [0x2060, 0x2064, "an invisible joiner or operator (U+2060-2064)"],
16 [0x2066, 0x2069, "a bidirectional isolate (U+2066-2069)"],
17 [0xfe00, 0xfe0f, "a variation selector (U+FE00-FE0F)"],
18 [0xfeff, 0xfeff, "a byte order mark (U+FEFF)"],
19 [0xe0000, 0xe007f, "a tag character (U+E0000-E007F)"],
20 [0xe0100, 0xe01ef, "a variation selector (U+E0100-E01EF)"],
21];
23/**
24 * The first character in `text` a reader can't see, as "<what> at character N", or null.
25 * \n and \t pass, and so does \r before \n, since a message file written on Windows ends its lines that way.
26 */
27export function unseenIn(text: string): string | null {
28 const chars = [...text];
29 for (const [i, ch] of chars.entries()) {
30 const c = ch.codePointAt(0)!;
31 if (c === 0x0d && chars[i + 1] === "\n") continue;
32 const hit = UNSEEN.find(([lo, hi]) => c >= lo && c <= hi);
33 if (hit) return `${hit[2]} at character ${i + 1}`;
34 }
35 return null;
36}
38/** Why `text`, named `what` ("the message"), can't be kept, or null. */
39export function unseenError(what: string, text: unknown): string | null {
40 const hit = typeof text === "string" ? unseenIn(text) : null;
41 return hit === null ? null : `${what} holds ${hit}, which a reader can't see; take it out`;
42}