text-sanctifier 1.3.2 → 1.3.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "text-sanctifier",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "type": "module",
5
5
  "description": "A brutal text normalizer and invisible trash scrubber for modern web projects.",
6
6
  "engines": {
@@ -27,6 +27,10 @@
27
27
  "types": "./dist/types/index.d.ts",
28
28
  "default": "./src/index.js"
29
29
  },
30
+ "./hidden": {
31
+ "types": "./dist/types/hiddenText.d.ts",
32
+ "default": "./src/hiddenText.js"
33
+ },
30
34
  "./browser": {
31
35
  "types": "./dist/types/index.d.ts",
32
36
  "default": "./dist/text-sanctifier.min.js"
@@ -1,223 +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
- }
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
+ }