text-sanctifier 1.1.0 → 1.3.0
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/README.md +65 -4
- package/bin/text-sanctifier.js +519 -0
- package/dist/text-sanctifier.min.js +13 -11
- package/dist/types/index.d.ts +7 -0
- package/dist/types/inspectText.d.ts +13 -2
- package/dist/types/sanctifyText.d.ts +8 -4
- package/package.json +8 -3
- package/src/index.d.ts +7 -0
- package/src/index.js +9 -0
- package/src/inspectText.js +386 -339
- package/src/sanctifyText.js +511 -507
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
export type UnicodeTrashReport = import("./inspectText.js").UnicodeTrashReport;
|
|
2
|
+
export type TrashCategory = import("./inspectText.js").TrashCategory;
|
|
3
|
+
export type TrashFinding = import("./inspectText.js").TrashFinding;
|
|
4
|
+
export type TrashCounts = import("./inspectText.js").TrashCounts;
|
|
5
|
+
export type DetailedTrashReport = import("./inspectText.js").DetailedTrashReport;
|
|
6
|
+
export type InspectDetailedOptions = import("./inspectText.js").InspectDetailedOptions;
|
|
7
|
+
export type SanctifyOptions = import("./sanctifyText.js").SanctifyOptions;
|
|
1
8
|
import { inspectText } from './inspectText.js';
|
|
2
9
|
import { inspectTextDetailed } from './inspectText.js';
|
|
3
10
|
import { getRecommendedSanctifierOptions } from './inspectText.js';
|
|
@@ -14,7 +14,12 @@ export function inspectText(text: string): UnicodeTrashReport;
|
|
|
14
14
|
* - `nul`: U+0000
|
|
15
15
|
* - `c0_control`: U+0001–U+001F except tab, LF and CR; and U+007F
|
|
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
|
|
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")
|
|
17
21
|
*
|
|
22
|
+
* `codePoint` is the full code point; `offset` and `column` count UTF-16 units.
|
|
18
23
|
* Every occurrence is counted; only the first `maxFindings` are listed.
|
|
19
24
|
* One pass over the string, no regex, no copy.
|
|
20
25
|
*
|
|
@@ -47,6 +52,7 @@ export function getNewlineStats(text: string): {
|
|
|
47
52
|
* @return {!SanctifyOptions}
|
|
48
53
|
*/
|
|
49
54
|
export function getRecommendedSanctifierOptions(report: UnicodeTrashReport): SanctifyOptions;
|
|
55
|
+
export type SanctifyOptions = import("./sanctifyText.js").SanctifyOptions;
|
|
50
56
|
export type UnicodeTrashReport = {
|
|
51
57
|
hasControlChars: boolean;
|
|
52
58
|
hasInvisibleChars: boolean;
|
|
@@ -56,10 +62,11 @@ export type UnicodeTrashReport = {
|
|
|
56
62
|
hasNonKeyboardChars: boolean;
|
|
57
63
|
summary: string[];
|
|
58
64
|
};
|
|
59
|
-
export type TrashCategory = "bidi_control" | "zero_width" | "nonbreaking_space" | "bom" | "nul" | "c0_control" | "c1_control";
|
|
65
|
+
export type TrashCategory = "bidi_control" | "zero_width" | "nonbreaking_space" | "bom" | "nul" | "c0_control" | "c1_control" | "invisible_format" | "hangul_filler" | "variation_selector" | "tag";
|
|
60
66
|
/**
|
|
61
67
|
* One located character.
|
|
62
|
-
* - `offset`: 0-based UTF-16 index into the input (a JS string index)
|
|
68
|
+
* - `offset`: 0-based UTF-16 index into the input (a JS string index); for a code point
|
|
69
|
+
* above U+FFFF, the index of its high surrogate.
|
|
63
70
|
* - `line`: 1-based; lines end at LF, CR, or CRLF (counted once).
|
|
64
71
|
* - `column`: 1-based, in UTF-16 code units from the start of the line.
|
|
65
72
|
* - `atStart`: present on `bom` findings only; true at offset 0, where a BOM is legitimate.
|
|
@@ -80,6 +87,10 @@ export type TrashCounts = {
|
|
|
80
87
|
nul: number;
|
|
81
88
|
c0_control: number;
|
|
82
89
|
c1_control: number;
|
|
90
|
+
invisible_format: number;
|
|
91
|
+
hangul_filler: number;
|
|
92
|
+
variation_selector: number;
|
|
93
|
+
tag: number;
|
|
83
94
|
};
|
|
84
95
|
export type DetailedTrashReport = {
|
|
85
96
|
/**
|
|
@@ -91,7 +91,7 @@ export namespace summonSanctifier {
|
|
|
91
91
|
* ⚠️ Note: This is plain-text normalization/filtering — not an HTML/XSS sanitizer.
|
|
92
92
|
*
|
|
93
93
|
* @param {string} text
|
|
94
|
-
* @param {boolean} [purgeInvisibleChars=false] - Remove ZWSP, NBSP, bidi, etc.
|
|
94
|
+
* @param {boolean} [purgeInvisibleChars=false] - Remove ZWSP, NBSP, bidi, tags, variation selectors, etc.
|
|
95
95
|
* @param {boolean} [purgeEmojis=false] - Remove emoji characters entirely.
|
|
96
96
|
* @param {boolean} [nukeControls=false] - Remove non-whitespace control characters.
|
|
97
97
|
* @param {boolean} [keyboardOnlyFilter=false] - Keep printable ASCII + full emoji sequences only (drops other Unicode).
|
|
@@ -121,9 +121,13 @@ export function normalizeTypographicJank(text: string): string;
|
|
|
121
121
|
* Purges invisible Unicode "trash" characters and removes them.
|
|
122
122
|
*
|
|
123
123
|
* Targets:
|
|
124
|
-
* - Non-breaking spaces (
|
|
125
|
-
* - Zero-width spaces and miscellaneous Unicode spaces (
|
|
126
|
-
* - Bidi controls: marks, embeddings/overrides and isolates (
|
|
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"
|
|
127
131
|
*
|
|
128
132
|
* @param {string} text
|
|
129
133
|
* @returns {string}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "text-sanctifier",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A brutal text normalizer and invisible trash scrubber for modern web projects.",
|
|
6
6
|
"engines": {
|
|
@@ -9,8 +9,12 @@
|
|
|
9
9
|
"main": "./src/index.js",
|
|
10
10
|
"module": "./src/index.js",
|
|
11
11
|
"browser": "./dist/text-sanctifier.min.js",
|
|
12
|
+
"bin": {
|
|
13
|
+
"text-sanctifier": "bin/text-sanctifier.js"
|
|
14
|
+
},
|
|
12
15
|
"files": [
|
|
13
16
|
"src",
|
|
17
|
+
"bin",
|
|
14
18
|
"dist/text-sanctifier.min.js",
|
|
15
19
|
"dist/types",
|
|
16
20
|
"LICENSE",
|
|
@@ -33,9 +37,10 @@
|
|
|
33
37
|
"scripts": {
|
|
34
38
|
"build": "node scripts/buildc.js",
|
|
35
39
|
"build:types": "tsc -p tsconfig.types.json",
|
|
36
|
-
"test": "
|
|
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",
|
|
37
42
|
"test-min": "node tests/sanctifyText.test.min.js",
|
|
38
|
-
"ci": "npm run test && npm run build && npm run build:types && npm run test-min"
|
|
43
|
+
"ci": "npm run test && npm run build && npm run build:types && npm run test:types && npm run test-min"
|
|
39
44
|
},
|
|
40
45
|
"keywords": [
|
|
41
46
|
"text",
|
package/src/index.d.ts
CHANGED
|
@@ -3,3 +3,10 @@ import { inspectTextDetailed } from './inspectText.js';
|
|
|
3
3
|
import { getRecommendedSanctifierOptions } from './inspectText.js';
|
|
4
4
|
import { summonSanctifier } from './sanctifyText.js';
|
|
5
5
|
export { inspectText, inspectTextDetailed, getRecommendedSanctifierOptions, summonSanctifier };
|
|
6
|
+
export type UnicodeTrashReport = import('./inspectText.js').UnicodeTrashReport;
|
|
7
|
+
export type TrashCategory = import('./inspectText.js').TrashCategory;
|
|
8
|
+
export type TrashFinding = import('./inspectText.js').TrashFinding;
|
|
9
|
+
export type TrashCounts = import('./inspectText.js').TrashCounts;
|
|
10
|
+
export type DetailedTrashReport = import('./inspectText.js').DetailedTrashReport;
|
|
11
|
+
export type InspectDetailedOptions = import('./inspectText.js').InspectDetailedOptions;
|
|
12
|
+
export type SanctifyOptions = import('./sanctifyText.js').SanctifyOptions;
|
package/src/index.js
CHANGED
|
@@ -7,6 +7,15 @@ export { inspectText, inspectTextDetailed, getRecommendedSanctifierOptions };
|
|
|
7
7
|
import { summonSanctifier } from './sanctifyText.js';
|
|
8
8
|
export { summonSanctifier };
|
|
9
9
|
|
|
10
|
+
// Type-only re-exports so TypeScript consumers can name these from the package root.
|
|
11
|
+
/** @typedef {import('./inspectText.js').UnicodeTrashReport} UnicodeTrashReport */
|
|
12
|
+
/** @typedef {import('./inspectText.js').TrashCategory} TrashCategory */
|
|
13
|
+
/** @typedef {import('./inspectText.js').TrashFinding} TrashFinding */
|
|
14
|
+
/** @typedef {import('./inspectText.js').TrashCounts} TrashCounts */
|
|
15
|
+
/** @typedef {import('./inspectText.js').DetailedTrashReport} DetailedTrashReport */
|
|
16
|
+
/** @typedef {import('./inspectText.js').InspectDetailedOptions} InspectDetailedOptions */
|
|
17
|
+
/** @typedef {import('./sanctifyText.js').SanctifyOptions} SanctifyOptions */
|
|
18
|
+
|
|
10
19
|
|
|
11
20
|
// In Future: export helpers for power users
|
|
12
21
|
// export { purgeInvisibleTrash, purgeEmojisCharacters, normalizeNewlines, trimSpacesAroundNewlines, collapseParagraphs, collapseExtraSpaces, purgeControlCharacters } from './sanctifyText.js';
|