@foldrun/core 18.3.1 → 18.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/joiners.d.ts +4 -1
- package/dist/src/joiners.js +48 -9
- package/package.json +1 -1
- package/src/joiners.ts +43 -6
package/dist/src/joiners.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
/** The indices (UTF-16) of every
|
|
1
|
+
/** The indices (UTF-16) of every invisible in `text` that is spelling, not
|
|
2
|
+
* hiding: a joiner of a joining script or emoji; and a run of bidi marks on a
|
|
3
|
+
* LINE with right-to-left letters, not splitting a Latin word (Codex review:
|
|
4
|
+
* judged per line, per whole run, by letters alone). */
|
|
2
5
|
export declare function spellingJoiners(text: string): Set<number>;
|
package/dist/src/joiners.js
CHANGED
|
@@ -19,17 +19,56 @@ const JOINER_SCRIPTS = [
|
|
|
19
19
|
"Tibetan", "Myanmar", "Khmer", "Mongolian",
|
|
20
20
|
];
|
|
21
21
|
const LETTER = `(?:${JOINER_SCRIPTS.map((s) => `[\\p{scx=${s}}&&[\\p{L}\\p{M}]]`).join("|")})`;
|
|
22
|
-
/** A ZWNJ or ZWJ with a letter or mark of a joining script on
|
|
23
|
-
|
|
22
|
+
/** A ZWNJ or ZWJ with a letter or mark of a joining script on one side and
|
|
23
|
+
* a letter or mark on the other — inside a word, or where a Persian suffix
|
|
24
|
+
* follows a Latin word («channelها», «webhooksاند»; cloudhost, 11 Nov). */
|
|
25
|
+
const ANY_LETTER = "[\\p{L}\\p{M}]";
|
|
26
|
+
const IN_WORD = new RegExp(`(?<=${LETTER})[\\u200C\\u200D](?=${ANY_LETTER})|(?<=${ANY_LETTER})[\\u200C\\u200D](?=${LETTER})`, "gv");
|
|
24
27
|
/** A ZWJ between two emoji (a skin tone or VS16 may follow the first). */
|
|
25
|
-
const IN_EMOJI = /(?<=\p{Extended_Pictographic}\u{FE0F}?[\u{1F3FB}-\u{1F3FF}]?)
|
|
26
|
-
/**
|
|
28
|
+
const IN_EMOJI = /(?<=\p{Extended_Pictographic}\u{FE0F}?[\u{1F3FB}-\u{1F3FF}]?)\u200D(?=\p{Extended_Pictographic})/gu;
|
|
29
|
+
/** A right-to-left LETTER (Arabic-script, Hebrew, Syriac, Thaana, N'Ko) —
|
|
30
|
+
* letters only, so a mark (ALM is Arabic-script) is never its own evidence. */
|
|
31
|
+
const RTL_LETTER = new RegExp("[[\\p{scx=Arabic}\\p{scx=Hebrew}\\p{scx=Syriac}\\p{scx=Thaana}\\p{scx=Nko}]&&\\p{L}]", "v");
|
|
32
|
+
/** A run of bidi MARKS — LRM, RLM, ALM. Unlike overrides and isolates they
|
|
33
|
+
* move nothing: they settle where a neutral (a backtick, a dot) sits, which
|
|
34
|
+
* is how a Latin file name stays in order inside Persian text. */
|
|
35
|
+
const MARKS = /[\u200E\u200F\u061C]+/gu;
|
|
36
|
+
const LATIN = /\p{scx=Latin}/u;
|
|
37
|
+
const MARKS_ANY = /[\u200E\u200F\u061C]/u;
|
|
38
|
+
/** The indices (UTF-16) of every invisible in `text` that is spelling, not
|
|
39
|
+
* hiding: a joiner of a joining script or emoji; and a run of bidi marks on a
|
|
40
|
+
* LINE with right-to-left letters, not splitting a Latin word (Codex review:
|
|
41
|
+
* judged per line, per whole run, by letters alone). */
|
|
27
42
|
export function spellingJoiners(text) {
|
|
28
43
|
const at = new Set();
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
44
|
+
if (/[\u200C\u200D]/.test(text))
|
|
45
|
+
for (const re of [IN_WORD, IN_EMOJI])
|
|
46
|
+
for (const m of text.matchAll(re))
|
|
47
|
+
at.add(m.index);
|
|
48
|
+
if (/[\u200E\u200F\u061C]/.test(text)) {
|
|
49
|
+
// Line by line, each line classified once (Codex review: rescanning the
|
|
50
|
+
// line for every run of marks was quadratic on hostile input).
|
|
51
|
+
let lineStart = 0;
|
|
52
|
+
while (lineStart <= text.length) {
|
|
53
|
+
const nl = text.indexOf("\n", lineStart);
|
|
54
|
+
const lineEnd = nl === -1 ? text.length : nl;
|
|
55
|
+
const line = text.slice(lineStart, lineEnd);
|
|
56
|
+
if (MARKS_ANY.test(line) && RTL_LETTER.test(line)) {
|
|
57
|
+
for (const m of line.matchAll(MARKS)) {
|
|
58
|
+
const start = lineStart + m.index;
|
|
59
|
+
const end = start + m[0].length;
|
|
60
|
+
// "ig\u200E\u200Enore": marks between two Latin letters split a
|
|
61
|
+
// word; they order nothing there, so they are still hidden text.
|
|
62
|
+
if (LATIN.test(text[start - 1] ?? "") && LATIN.test(text[end] ?? ""))
|
|
63
|
+
continue;
|
|
64
|
+
for (let k = start; k < end; k++)
|
|
65
|
+
at.add(k);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (nl === -1)
|
|
69
|
+
break;
|
|
70
|
+
lineStart = nl + 1;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
34
73
|
return at;
|
|
35
74
|
}
|
package/package.json
CHANGED
package/src/joiners.ts
CHANGED
|
@@ -21,15 +21,52 @@ const JOINER_SCRIPTS = [
|
|
|
21
21
|
];
|
|
22
22
|
const LETTER = `(?:${JOINER_SCRIPTS.map((s) => `[\\p{scx=${s}}&&[\\p{L}\\p{M}]]`).join("|")})`;
|
|
23
23
|
|
|
24
|
-
/** A ZWNJ or ZWJ with a letter or mark of a joining script on
|
|
25
|
-
|
|
24
|
+
/** A ZWNJ or ZWJ with a letter or mark of a joining script on one side and
|
|
25
|
+
* a letter or mark on the other — inside a word, or where a Persian suffix
|
|
26
|
+
* follows a Latin word («channelها», «webhooksاند»; cloudhost, 11 Nov). */
|
|
27
|
+
const ANY_LETTER = "[\\p{L}\\p{M}]";
|
|
28
|
+
const IN_WORD = new RegExp(`(?<=${LETTER})[\\u200C\\u200D](?=${ANY_LETTER})|(?<=${ANY_LETTER})[\\u200C\\u200D](?=${LETTER})`, "gv");
|
|
26
29
|
/** A ZWJ between two emoji (a skin tone or VS16 may follow the first). */
|
|
27
|
-
const IN_EMOJI = /(?<=\p{Extended_Pictographic}\u{FE0F}?[\u{1F3FB}-\u{1F3FF}]?)
|
|
30
|
+
const IN_EMOJI = /(?<=\p{Extended_Pictographic}\u{FE0F}?[\u{1F3FB}-\u{1F3FF}]?)\u200D(?=\p{Extended_Pictographic})/gu;
|
|
28
31
|
|
|
29
|
-
/**
|
|
32
|
+
/** A right-to-left LETTER (Arabic-script, Hebrew, Syriac, Thaana, N'Ko) —
|
|
33
|
+
* letters only, so a mark (ALM is Arabic-script) is never its own evidence. */
|
|
34
|
+
const RTL_LETTER = new RegExp("[[\\p{scx=Arabic}\\p{scx=Hebrew}\\p{scx=Syriac}\\p{scx=Thaana}\\p{scx=Nko}]&&\\p{L}]", "v");
|
|
35
|
+
/** A run of bidi MARKS — LRM, RLM, ALM. Unlike overrides and isolates they
|
|
36
|
+
* move nothing: they settle where a neutral (a backtick, a dot) sits, which
|
|
37
|
+
* is how a Latin file name stays in order inside Persian text. */
|
|
38
|
+
const MARKS = /[\u200E\u200F\u061C]+/gu;
|
|
39
|
+
const LATIN = /\p{scx=Latin}/u;
|
|
40
|
+
const MARKS_ANY = /[\u200E\u200F\u061C]/u;
|
|
41
|
+
|
|
42
|
+
/** The indices (UTF-16) of every invisible in `text` that is spelling, not
|
|
43
|
+
* hiding: a joiner of a joining script or emoji; and a run of bidi marks on a
|
|
44
|
+
* LINE with right-to-left letters, not splitting a Latin word (Codex review:
|
|
45
|
+
* judged per line, per whole run, by letters alone). */
|
|
30
46
|
export function spellingJoiners(text: string): Set<number> {
|
|
31
47
|
const at = new Set<number>();
|
|
32
|
-
if (
|
|
33
|
-
|
|
48
|
+
if (/[\u200C\u200D]/.test(text)) for (const re of [IN_WORD, IN_EMOJI]) for (const m of text.matchAll(re)) at.add(m.index!);
|
|
49
|
+
if (/[\u200E\u200F\u061C]/.test(text)) {
|
|
50
|
+
// Line by line, each line classified once (Codex review: rescanning the
|
|
51
|
+
// line for every run of marks was quadratic on hostile input).
|
|
52
|
+
let lineStart = 0;
|
|
53
|
+
while (lineStart <= text.length) {
|
|
54
|
+
const nl = text.indexOf("\n", lineStart);
|
|
55
|
+
const lineEnd = nl === -1 ? text.length : nl;
|
|
56
|
+
const line = text.slice(lineStart, lineEnd);
|
|
57
|
+
if (MARKS_ANY.test(line) && RTL_LETTER.test(line)) {
|
|
58
|
+
for (const m of line.matchAll(MARKS)) {
|
|
59
|
+
const start = lineStart + m.index!;
|
|
60
|
+
const end = start + m[0].length;
|
|
61
|
+
// "ig\u200E\u200Enore": marks between two Latin letters split a
|
|
62
|
+
// word; they order nothing there, so they are still hidden text.
|
|
63
|
+
if (LATIN.test(text[start - 1] ?? "") && LATIN.test(text[end] ?? "")) continue;
|
|
64
|
+
for (let k = start; k < end; k++) at.add(k);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (nl === -1) break;
|
|
68
|
+
lineStart = nl + 1;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
34
71
|
return at;
|
|
35
72
|
}
|