text-sanctifier 1.3.0 → 1.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.
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Category of one BMP code point (one UTF-16 code unit), or null when it is not trash.
3
+ * Surrogates return null; the caller pairs them and uses classifyAstral.
4
+ * @param {number} c
5
+ * @returns {TrashCategory|null}
6
+ */
7
+ export function classifyCodeUnit(c: number): TrashCategory | null;
8
+ /**
9
+ * Category of a code point above U+FFFF, or null when it is not trash.
10
+ * @param {number} c
11
+ * @returns {TrashCategory|null}
12
+ */
13
+ export function classifyAstral(c: number): TrashCategory | null;
14
+ /** @typedef {import('./inspectText.js').TrashCategory} TrashCategory */
15
+ /**
16
+ * Removed by `nukeControls`. Categories: bidi_control, nul, c0_control, c1_control.
17
+ * Global: reset `lastIndex` before calling `.test()`.
18
+ * @type {RegExp}
19
+ */
20
+ export const CONTROL_CHARS_REGEX: RegExp;
21
+ /**
22
+ * Removed by `purgeInvisibleChars`. Categories: bidi_control, zero_width, nonbreaking_space, bom, invisible_format, hangul_filler, variation_selector, tag.
23
+ * Global: reset `lastIndex` before calling `.test()`.
24
+ * @type {RegExp}
25
+ */
26
+ export const INVISIBLE_TRASH_REGEX: RegExp;
27
+ export type TrashCategory = import("./inspectText.js").TrashCategory;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Decodes tag characters to the ASCII they shadow: U+E0020–U+E007E become
3
+ * U+0020–U+007E. Anything else (U+E0001 LANGUAGE TAG, U+E007F CANCEL TAG, unassigned
4
+ * tags, other characters) is written as `<U+XXXX>`, so the result is printable.
5
+ * @param {string} text
6
+ * @returns {string}
7
+ */
8
+ export function decodeTagText(text: string): string;
9
+ /**
10
+ * Finds runs of tag characters, variation selectors and invisible operators.
11
+ * Consecutive characters of the same kind form one run. Two kinds of sequence are
12
+ * legitimate and listed under `benign` instead of `runs`:
13
+ * - the subdivision flags of England, Scotland and Wales: U+1F3F4 followed by the
14
+ * tags for "gbeng", "gbsct" or "gbwls" and U+E007F
15
+ * - a single U+FE0E or U+FE0F (text or emoji presentation) after another character
16
+ * @param {string} text
17
+ * @returns {HiddenTextScan}
18
+ */
19
+ export function findHiddenRuns(text: string): HiddenTextScan;
20
+ export type HiddenRunKind = "tag" | "variation_selector" | "invisible_operator";
21
+ export type HiddenRun = {
22
+ kind: HiddenRunKind;
23
+ /**
24
+ * - UTF-16 index of the first character
25
+ */
26
+ offset: number;
27
+ /**
28
+ * - UTF-16 index just past the last character
29
+ */
30
+ end: number;
31
+ /**
32
+ * - number of code points in the run
33
+ */
34
+ count: number;
35
+ /**
36
+ * - tag runs only: the ASCII the tags spell (see decodeTagText)
37
+ */
38
+ decoded?: string;
39
+ };
40
+ export type HiddenTextScan = {
41
+ /**
42
+ * - runs that may hide text, in order
43
+ */
44
+ runs: HiddenRun[];
45
+ /**
46
+ * - [offset, end) spans of legitimate
47
+ * sequences (subdivision flags, a single emoji or text presentation selector)
48
+ */
49
+ benign: Array<[number, number]>;
50
+ };
@@ -4,9 +4,11 @@ export type TrashFinding = import("./inspectText.js").TrashFinding;
4
4
  export type TrashCounts = import("./inspectText.js").TrashCounts;
5
5
  export type DetailedTrashReport = import("./inspectText.js").DetailedTrashReport;
6
6
  export type InspectDetailedOptions = import("./inspectText.js").InspectDetailedOptions;
7
+ export type NewlineStats = import("./inspectText.js").NewlineStats;
7
8
  export type SanctifyOptions = import("./sanctifyText.js").SanctifyOptions;
8
9
  import { inspectText } from './inspectText.js';
9
10
  import { inspectTextDetailed } from './inspectText.js';
11
+ import { getNewlineStats } from './inspectText.js';
10
12
  import { getRecommendedSanctifierOptions } from './inspectText.js';
11
13
  import { summonSanctifier } from './sanctifyText.js';
12
- export { inspectText, inspectTextDetailed, getRecommendedSanctifierOptions, summonSanctifier };
14
+ export { inspectText, inspectTextDetailed, getNewlineStats, getRecommendedSanctifierOptions, summonSanctifier };
@@ -6,18 +6,18 @@ export function inspectText(text: string): UnicodeTrashReport;
6
6
  /**
7
7
  * Locates invisible and control characters, one finding per character.
8
8
  *
9
- * Categories:
9
+ * Categories (generated from scripts/categories.js by `npm run gen`):
10
10
  * - `bidi_control`: U+061C, U+200E, U+200F, U+202A–U+202E, U+2066–U+2069
11
11
  * - `zero_width`: U+200B–U+200D, U+2060
12
- * - `nonbreaking_space`: non-breaking and typographic spaces U+00A0, U+2000–U+200A, U+202F, U+3000
13
- * - `bom`: U+FEFF (`atStart` says whether it sits at offset 0)
12
+ * - `nonbreaking_space`: U+00A0, U+2000–U+200A, U+202F, U+205F, U+3000 (non-breaking and typographic spaces)
13
+ * - `bom`: U+FEFF (`atStart` is true at offset 0, where a BOM is legitimate)
14
14
  * - `nul`: U+0000
15
- * - `c0_control`: U+0001–U+001F except tab, LF and CR; and U+007F
15
+ * - `c0_control`: U+0001–U+0008, U+000B, U+000C, U+000E–U+001F, U+007F (tab, LF and CR are whitespace, not trash)
16
16
  * - `c1_control`: U+0080–U+009F
17
- * - `invisible_format`: soft hyphen U+00AD, U+034F, U+180E, invisible operators U+2061–U+2064
17
+ * - `invisible_format`: U+00AD (soft hyphen), U+034F (combining grapheme joiner), U+17B4, U+17B5 (Khmer inherent vowels), U+180E (Mongolian vowel separator), U+2061–U+2064 (invisible operators), U+2065 (reserved), U+206A–U+206F (deprecated format characters), U+FFF0–U+FFF8 (reserved), U+1BCA0–U+1BCA3 (shorthand format controls), U+1D173–U+1D17A (musical formatting), U+E0080–U+E00FF (reserved), U+E01F0–U+E0FFF (reserved) (every other Default_Ignorable_Code_Point, which renderers draw as nothing)
18
18
  * - `hangul_filler`: U+115F, U+1160, U+3164, U+FFA0 (letters that render blank)
19
- * - `variation_selector`: U+FE00–U+FE0F, U+E0100–U+E01EF (including VS16 in emoji)
20
- * - `tag`: U+E0000–U+E007F (tag characters, used for "ASCII smuggling")
19
+ * - `variation_selector`: U+180B–U+180D (Mongolian FVS1-FVS3), U+180F (Mongolian FVS4), U+FE00–U+FE0F (VS1-VS16, including VS16 in emoji), U+E0100–U+E01EF (VS17-VS256)
20
+ * - `tag`: U+E0000–U+E007F (tag characters, used for "ASCII smuggling" of hidden instructions)
21
21
  *
22
22
  * `codePoint` is the full code point; `offset` and `column` count UTF-16 units.
23
23
  * Every occurrence is counted; only the first `maxFindings` are listed.
@@ -29,23 +29,19 @@ export function inspectText(text: string): UnicodeTrashReport;
29
29
  */
30
30
  export function inspectTextDetailed(text: string, options?: InspectDetailedOptions): DetailedTrashReport;
31
31
  /**
32
- * Counts the number of different newline types in a string.
32
+ * @typedef {Object} NewlineStats
33
+ * @property {number} crlf - CR LF pairs.
34
+ * @property {number} cr - CRs not followed by LF.
35
+ * @property {number} lf - LFs not preceded by CR.
36
+ * @property {('CRLF'|'CR'|'LF')[]} types - Styles present, in the order CRLF, CR, LF.
37
+ * @property {boolean} mixed - True when more than one style is present.
38
+ */
39
+ /**
40
+ * Counts each newline style in one pass, with no regex and no copy.
33
41
  * @param {string} text
34
- * @returns {{
35
- * crlf: number,
36
- * cr: number,
37
- * lf: number,
38
- * types: string[],
39
- * mixed: boolean
40
- * }}
42
+ * @returns {NewlineStats}
41
43
  */
42
- export function getNewlineStats(text: string): {
43
- crlf: number;
44
- cr: number;
45
- lf: number;
46
- types: string[];
47
- mixed: boolean;
48
- };
44
+ export function getNewlineStats(text: string): NewlineStats;
49
45
  /**
50
46
  * Creates defaultOptions for summonSanctifier based on inspectText result
51
47
  * @param {!UnicodeTrashReport} report
@@ -62,6 +58,28 @@ export type UnicodeTrashReport = {
62
58
  hasNonKeyboardChars: boolean;
63
59
  summary: string[];
64
60
  };
61
+ export type NewlineStats = {
62
+ /**
63
+ * - CR LF pairs.
64
+ */
65
+ crlf: number;
66
+ /**
67
+ * - CRs not followed by LF.
68
+ */
69
+ cr: number;
70
+ /**
71
+ * - LFs not preceded by CR.
72
+ */
73
+ lf: number;
74
+ /**
75
+ * - Styles present, in the order CRLF, CR, LF.
76
+ */
77
+ types: ("CRLF" | "CR" | "LF")[];
78
+ /**
79
+ * - True when more than one style is present.
80
+ */
81
+ mixed: boolean;
82
+ };
65
83
  export type TrashCategory = "bidi_control" | "zero_width" | "nonbreaking_space" | "bom" | "nul" | "c0_control" | "c1_control" | "invisible_format" | "hangul_filler" | "variation_selector" | "tag";
66
84
  /**
67
85
  * One located character.
@@ -113,6 +131,7 @@ export type DetailedTrashReport = {
113
131
  export type InspectDetailedOptions = {
114
132
  /**
115
133
  * - Cap on listed findings (non-negative integer or Infinity).
134
+ * Each listed finding is an object, so memory grows with the number listed; 0 builds none (counts only).
116
135
  */
117
136
  maxFindings?: number;
118
137
  };
@@ -117,22 +117,6 @@ export function sanctifyText(text: string, purgeInvisibleChars?: boolean, purgeE
117
117
  * @returns {string}
118
118
  */
119
119
  export function normalizeTypographicJank(text: string): string;
120
- /**
121
- * Purges invisible Unicode "trash" characters and removes them.
122
- *
123
- * Targets:
124
- * - Non-breaking spaces ( )
125
- * - Zero-width spaces and miscellaneous Unicode spaces ( –‍,  , ⁠,  , )
126
- * - Bidi controls: marks, embeddings/overrides and isolates (؜, ‎, ‏, ‪–‮, ⁦–⁩)
127
- * - Invisible format characters: soft hyphen, CGJ, Mongolian vowel separator, invisible operators (­, ͏, ᠎, ⁡–⁤)
128
- * - Hangul fillers (ᅟ, ᅠ, ㅤ, ᅠ)
129
- * - Variation selectors (︀–️, \u{E0100}–\u{E01EF}), including VS16 in emoji
130
- * - Tag characters (\u{E0000}–\u{E007F}), used for "ASCII smuggling"
131
- *
132
- * @param {string} text
133
- * @returns {string}
134
- */
135
- export const INVISIBLE_TRASH_REGEX: RegExp;
136
120
  /**
137
121
  * Matches any character that is NOT:
138
122
  * - Printable ASCII (U+0020–U+007E)
@@ -142,19 +126,6 @@ export const INVISIBLE_TRASH_REGEX: RegExp;
142
126
  export const ASCII_KEYBOARD_SAFE_REGEX: RegExp;
143
127
  /** @type {RegExp} */
144
128
  export let EMOJI_REGEX: RegExp;
145
- /**
146
- * Nukes hidden control characters that are invisible and often dangerous.
147
- * (Excludes necessary whitespace like \n and \t.)
148
- *
149
- * Control characters nuked:
150
- * - ASCII control range (0x00-0x1F, 0x7F)
151
- * - Unicode control range (0x80-0x9F)
152
- * - Bidi controls (U+061C, U+200E, U+200F, U+202A–U+202E, U+2066–U+2069)
153
- *
154
- * @param {string} text
155
- * @returns {string}
156
- */
157
- export const CONTROL_CHARS_REGEX: RegExp;
158
129
  export type SanctifyOptions = {
159
130
  purgeInvisibleChars?: boolean;
160
131
  purgeEmojis?: boolean;
@@ -169,3 +140,6 @@ export type SanctifyOptions = {
169
140
  maxLength?: number;
170
141
  onMaxLength?: "throw" | "truncate" | "noop";
171
142
  };
143
+ import { CONTROL_CHARS_REGEX } from './categories.generated.js';
144
+ import { INVISIBLE_TRASH_REGEX } from './categories.generated.js';
145
+ export { CONTROL_CHARS_REGEX, INVISIBLE_TRASH_REGEX };
package/package.json CHANGED
@@ -1,74 +1,76 @@
1
- {
2
- "name": "text-sanctifier",
3
- "version": "1.3.0",
4
- "type": "module",
5
- "description": "A brutal text normalizer and invisible trash scrubber for modern web projects.",
6
- "engines": {
7
- "node": ">=18"
8
- },
9
- "main": "./src/index.js",
10
- "module": "./src/index.js",
11
- "browser": "./dist/text-sanctifier.min.js",
12
- "bin": {
13
- "text-sanctifier": "bin/text-sanctifier.js"
14
- },
15
- "files": [
16
- "src",
17
- "bin",
18
- "dist/text-sanctifier.min.js",
19
- "dist/types",
20
- "LICENSE",
21
- "README.md",
22
- "ADDITIONAL_TERMS.md",
23
- "robots.txt"
24
- ],
25
- "exports": {
26
- ".": {
27
- "types": "./dist/types/index.d.ts",
28
- "default": "./src/index.js"
29
- },
30
- "./browser": {
31
- "types": "./dist/types/index.d.ts",
32
- "default": "./dist/text-sanctifier.min.js"
33
- }
34
- },
35
- "types": "./dist/types/index.d.ts",
36
- "sideEffects": false,
37
- "scripts": {
38
- "build": "node scripts/buildc.js",
39
- "build:types": "tsc -p tsconfig.types.json",
40
- "test:types": "tsc -p tests/types/tsconfig.json",
41
- "test": "node tests/sanctifyText.test.js && node tests/inspectTextDetailed.test.js && node tests/cli.test.js",
42
- "test-min": "node tests/sanctifyText.test.min.js",
43
- "ci": "npm run test && npm run build && npm run build:types && npm run test:types && npm run test-min"
44
- },
45
- "keywords": [
46
- "text",
47
- "sanitize",
48
- "normalize",
49
- "invisible",
50
- "scrubber",
51
- "unicode",
52
- "clean",
53
- "sanctify"
54
- ],
55
- "author": "WATT3D <WATT3D@protonmail.com>",
56
- "license": "SEE LICENSE IN LICENSE",
57
- "repository": {
58
- "type": "git",
59
- "url": "git+https://github.com/iWhatty/text-sanctifier.git"
60
- },
61
- "bugs": {
62
- "url": "https://github.com/iWhatty/text-sanctifier/issues"
63
- },
64
- "homepage": "https://github.com/iWhatty/text-sanctifier#readme",
65
- "directories": {
66
- "test": "tests"
67
- },
68
- "devDependencies": {
69
- "esbuild": "^0.25.3",
70
- "google-closure-compiler": "^20240317.0.0",
71
- "terser": "^5.39.0",
72
- "typescript": "^5.9.3"
73
- }
74
- }
1
+ {
2
+ "name": "text-sanctifier",
3
+ "version": "1.3.2",
4
+ "type": "module",
5
+ "description": "A brutal text normalizer and invisible trash scrubber for modern web projects.",
6
+ "engines": {
7
+ "node": ">=18"
8
+ },
9
+ "main": "./src/index.js",
10
+ "module": "./src/index.js",
11
+ "browser": "./dist/text-sanctifier.min.js",
12
+ "bin": {
13
+ "text-sanctifier": "bin/text-sanctifier.js"
14
+ },
15
+ "files": [
16
+ "src",
17
+ "bin",
18
+ "dist/text-sanctifier.min.js",
19
+ "dist/types",
20
+ "LICENSE",
21
+ "README.md",
22
+ "ADDITIONAL_TERMS.md",
23
+ "robots.txt"
24
+ ],
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/types/index.d.ts",
28
+ "default": "./src/index.js"
29
+ },
30
+ "./browser": {
31
+ "types": "./dist/types/index.d.ts",
32
+ "default": "./dist/text-sanctifier.min.js"
33
+ }
34
+ },
35
+ "types": "./dist/types/index.d.ts",
36
+ "sideEffects": false,
37
+ "scripts": {
38
+ "gen": "node scripts/gen-categories.js",
39
+ "gen:check": "node scripts/gen-categories.js --check",
40
+ "build": "node scripts/buildc.js",
41
+ "build:types": "tsc -p tsconfig.types.json",
42
+ "test:types": "tsc -p tests/types/tsconfig.json",
43
+ "test": "node tests/sanctifyText.test.js && node tests/inspectTextDetailed.test.js && node tests/cli.test.js",
44
+ "test-min": "node tests/sanctifyText.test.min.js",
45
+ "ci": "npm run gen:check && npm run test && npm run build && npm run build:types && npm run test:types && npm run test-min"
46
+ },
47
+ "keywords": [
48
+ "text",
49
+ "sanitize",
50
+ "normalize",
51
+ "invisible",
52
+ "scrubber",
53
+ "unicode",
54
+ "clean",
55
+ "sanctify"
56
+ ],
57
+ "author": "WATT3D <WATT3D@protonmail.com>",
58
+ "license": "SEE LICENSE IN LICENSE",
59
+ "repository": {
60
+ "type": "git",
61
+ "url": "git+https://github.com/iWhatty/text-sanctifier.git"
62
+ },
63
+ "bugs": {
64
+ "url": "https://github.com/iWhatty/text-sanctifier/issues"
65
+ },
66
+ "homepage": "https://github.com/iWhatty/text-sanctifier#readme",
67
+ "directories": {
68
+ "test": "tests"
69
+ },
70
+ "devDependencies": {
71
+ "esbuild": "^0.25.3",
72
+ "google-closure-compiler": "^20240317.0.0",
73
+ "terser": "^5.39.0",
74
+ "typescript": "^5.9.3"
75
+ }
76
+ }
@@ -0,0 +1,223 @@
1
+ // src/categories.generated.js
2
+ //
3
+ // Generated by scripts/gen-categories.js from the table in scripts/categories.js.
4
+ // Do not edit: change the table and run `npm run gen`. `npm run ci` fails while this file is stale.
5
+
6
+ /** @typedef {import('./inspectText.js').TrashCategory} TrashCategory */
7
+
8
+ /**
9
+ * Removed by `nukeControls`. Categories: bidi_control, nul, c0_control, c1_control.
10
+ * Global: reset `lastIndex` before calling `.test()`.
11
+ * @type {RegExp}
12
+ */
13
+ export const CONTROL_CHARS_REGEX = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069]+/g;
14
+
15
+ /**
16
+ * Removed by `purgeInvisibleChars`. Categories: bidi_control, zero_width, nonbreaking_space, bom, invisible_format, hangul_filler, variation_selector, tag.
17
+ * Global: reset `lastIndex` before calling `.test()`.
18
+ * @type {RegExp}
19
+ */
20
+ export const INVISIBLE_TRASH_REGEX = /[\u00A0\u00AD\u034F\u061C\u115F\u1160\u17B4\u17B5\u180B-\u180F\u2000-\u200F\u202A-\u202F\u205F-\u206F\u3000\u3164\uFE00-\uFE0F\uFEFF\uFFA0\uFFF0-\uFFF8\u{1BCA0}-\u{1BCA3}\u{1D173}-\u{1D17A}\u{E0000}-\u{E0FFF}]+/gu;
21
+
22
+ /**
23
+ * Category of one BMP code point (one UTF-16 code unit), or null when it is not trash.
24
+ * Surrogates return null; the caller pairs them and uses classifyAstral.
25
+ * @param {number} c
26
+ * @returns {TrashCategory|null}
27
+ */
28
+ export function classifyCodeUnit(c) {
29
+ return c < 0x2000 ? classifyBelow2000(c) : classifyFrom2000(c);
30
+ }
31
+
32
+ // Two halves rather than one tree: V8 inlines a function only while its bytecode is
33
+ // small (460 bytes by default), and the single pass is much faster when it does.
34
+
35
+ /** @param {number} c @returns {TrashCategory|null} */
36
+ function classifyBelow2000(c) {
37
+ if (c < 0x00AE) {
38
+ if (c < 0x0020) {
39
+ if (c < 0x000B) {
40
+ if (c < 0x0001) {
41
+ return 'nul';
42
+ }
43
+ if (c < 0x0009) {
44
+ return 'c0_control';
45
+ }
46
+ return null;
47
+ }
48
+ if (c < 0x000D) {
49
+ return 'c0_control';
50
+ }
51
+ if (c < 0x000E) {
52
+ return null;
53
+ }
54
+ return 'c0_control';
55
+ }
56
+ if (c < 0x00A0) {
57
+ if (c < 0x007F) {
58
+ return null;
59
+ }
60
+ if (c < 0x0080) {
61
+ return 'c0_control';
62
+ }
63
+ return 'c1_control';
64
+ }
65
+ if (c < 0x00A1) {
66
+ return 'nonbreaking_space';
67
+ }
68
+ if (c < 0x00AD) {
69
+ return null;
70
+ }
71
+ return 'invisible_format';
72
+ }
73
+ if (c < 0x1161) {
74
+ if (c < 0x061C) {
75
+ if (c < 0x034F) {
76
+ return null;
77
+ }
78
+ if (c < 0x0350) {
79
+ return 'invisible_format';
80
+ }
81
+ return null;
82
+ }
83
+ if (c < 0x061D) {
84
+ return 'bidi_control';
85
+ }
86
+ if (c < 0x115F) {
87
+ return null;
88
+ }
89
+ return 'hangul_filler';
90
+ }
91
+ if (c < 0x180B) {
92
+ if (c < 0x17B4) {
93
+ return null;
94
+ }
95
+ if (c < 0x17B6) {
96
+ return 'invisible_format';
97
+ }
98
+ return null;
99
+ }
100
+ if (c < 0x180F) {
101
+ if (c < 0x180E) {
102
+ return 'variation_selector';
103
+ }
104
+ return 'invisible_format';
105
+ }
106
+ if (c < 0x1810) {
107
+ return 'variation_selector';
108
+ }
109
+ return null;
110
+ }
111
+
112
+ /** @param {number} c @returns {TrashCategory|null} */
113
+ function classifyFrom2000(c) {
114
+ if (c < 0x2070) {
115
+ if (c < 0x2030) {
116
+ if (c < 0x2010) {
117
+ if (c < 0x200B) {
118
+ return 'nonbreaking_space';
119
+ }
120
+ if (c < 0x200E) {
121
+ return 'zero_width';
122
+ }
123
+ return 'bidi_control';
124
+ }
125
+ if (c < 0x202A) {
126
+ return null;
127
+ }
128
+ if (c < 0x202F) {
129
+ return 'bidi_control';
130
+ }
131
+ return 'nonbreaking_space';
132
+ }
133
+ if (c < 0x2061) {
134
+ if (c < 0x205F) {
135
+ return null;
136
+ }
137
+ if (c < 0x2060) {
138
+ return 'nonbreaking_space';
139
+ }
140
+ return 'zero_width';
141
+ }
142
+ if (c < 0x2066) {
143
+ return 'invisible_format';
144
+ }
145
+ if (c < 0x206A) {
146
+ return 'bidi_control';
147
+ }
148
+ return 'invisible_format';
149
+ }
150
+ if (c < 0xFE10) {
151
+ if (c < 0x3164) {
152
+ if (c < 0x3000) {
153
+ return null;
154
+ }
155
+ if (c < 0x3001) {
156
+ return 'nonbreaking_space';
157
+ }
158
+ return null;
159
+ }
160
+ if (c < 0x3165) {
161
+ return 'hangul_filler';
162
+ }
163
+ if (c < 0xFE00) {
164
+ return null;
165
+ }
166
+ return 'variation_selector';
167
+ }
168
+ if (c < 0xFFA0) {
169
+ if (c < 0xFEFF) {
170
+ return null;
171
+ }
172
+ if (c < 0xFF00) {
173
+ return 'bom';
174
+ }
175
+ return null;
176
+ }
177
+ if (c < 0xFFF0) {
178
+ if (c < 0xFFA1) {
179
+ return 'hangul_filler';
180
+ }
181
+ return null;
182
+ }
183
+ if (c < 0xFFF9) {
184
+ return 'invisible_format';
185
+ }
186
+ return null;
187
+ }
188
+
189
+ /**
190
+ * Category of a code point above U+FFFF, or null when it is not trash.
191
+ * @param {number} c
192
+ * @returns {TrashCategory|null}
193
+ */
194
+ export function classifyAstral(c) {
195
+ if (c < 0xE0000) {
196
+ if (c < 0x1BCA4) {
197
+ if (c < 0x1BCA0) {
198
+ return null;
199
+ }
200
+ return 'invisible_format';
201
+ }
202
+ if (c < 0x1D173) {
203
+ return null;
204
+ }
205
+ if (c < 0x1D17B) {
206
+ return 'invisible_format';
207
+ }
208
+ return null;
209
+ }
210
+ if (c < 0xE0100) {
211
+ if (c < 0xE0080) {
212
+ return 'tag';
213
+ }
214
+ return 'invisible_format';
215
+ }
216
+ if (c < 0xE01F0) {
217
+ return 'variation_selector';
218
+ }
219
+ if (c < 0xE1000) {
220
+ return 'invisible_format';
221
+ }
222
+ return null;
223
+ }