cleanpastedtext 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +44 -2
- package/dist/index.d.ts +133 -0
- package/dist/index.js +1332 -0
- package/package.json +39 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Issaaf Kattan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,45 @@
|
|
|
1
|
-
#
|
|
1
|
+
# cleanpastedtext
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Find and remove the characters you can't see in copied text: zero-width spaces, byte order marks, BiDi controls, Unicode tag characters, variation selectors, odd spaces, and AI-style typography. The same engine powers [cleanpastedtext.com](https://cleanpastedtext.com) and its browser extension.
|
|
4
|
+
|
|
5
|
+
- **Deterministic.** Explicit rules, no AI model. Words are never rewritten.
|
|
6
|
+
- **Detection first.** Every run reports each character it found by name, code point, count and action (removed, replaced or kept).
|
|
7
|
+
- **Emoji-safe.** Joiners and variation selectors that belong to a real emoji sequence are kept.
|
|
8
|
+
- **Local.** No dependencies and no network code. Works in Node 18+ and browsers.
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install cleanpastedtext
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```js
|
|
15
|
+
import { cleanText, PRESETS } from "cleanpastedtext";
|
|
16
|
+
|
|
17
|
+
const { cleanedText, detections } = cleanText("Hello world — “café”", PRESETS["AI Clean"]);
|
|
18
|
+
// cleanedText: 'Hello world - "café"'
|
|
19
|
+
// detections: [{ codepoint: "U+200B", name: "Zero width space", count: 1, action: "removed", ... }, ...]
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Only want to know what's there? `detectHiddenCharacters(text)` returns the hidden-character findings without the typography changes.
|
|
23
|
+
|
|
24
|
+
## Presets
|
|
25
|
+
|
|
26
|
+
| Preset | What it does |
|
|
27
|
+
| --- | --- |
|
|
28
|
+
| AI Clean (default) | Removes hidden characters and standardizes AI-style punctuation. |
|
|
29
|
+
| Safe Clean | Removes invisible and unsafe characters while keeping more formatting. |
|
|
30
|
+
| Keep Typography | Keeps smart quotes, dashes and ellipses while cleaning hidden characters. |
|
|
31
|
+
| Plain ASCII | Converts the result to keyboard characters for code and older systems. |
|
|
32
|
+
| Markdown to Text | Removes common Markdown syntax while keeping typography and list markers. |
|
|
33
|
+
| Join Lines | Joins lines broken by PDF wrapping into paragraphs and removes hidden characters. |
|
|
34
|
+
|
|
35
|
+
`PRESETS` holds the exact options for each, and `PRESET_DESCRIPTIONS` the text above. Pass your own mix of options to `cleanText`, for example `{ ...PRESETS["AI Clean"], removeJoinControls: false }` for Persian or Hindi text, which needs ZWNJ/ZWJ inside words.
|
|
36
|
+
|
|
37
|
+
## What a result can and can't tell you
|
|
38
|
+
|
|
39
|
+
An empty report means the supported checks found nothing. It doesn't prove who wrote the text, and statistical AI watermarks (patterns in word choice) are outside what any character cleaner can see. The [methodology page](https://cleanpastedtext.com/how-it-works) documents every rule.
|
|
40
|
+
|
|
41
|
+
## For AI agents
|
|
42
|
+
|
|
43
|
+
[`cleanpastedtext-mcp`](https://www.npmjs.com/package/cleanpastedtext-mcp) exposes this engine as a local MCP server.
|
|
44
|
+
|
|
45
|
+
MIT © Issaaf Kattan
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CleanPastedText cleaning engine.
|
|
3
|
+
*
|
|
4
|
+
* Detection-first: every run scans the ORIGINAL text and produces a
|
|
5
|
+
* transparent, per-codepoint report (`detections`) naming every hidden
|
|
6
|
+
* character, AI watermark artifact, and typography change — before any
|
|
7
|
+
* transformation happens. NFKC normalization only runs after detection, so
|
|
8
|
+
* characters like U+202F (narrow no-break space, the widely reported ChatGPT
|
|
9
|
+
* watermark character) are counted and named instead of being silently
|
|
10
|
+
* folded into a plain space.
|
|
11
|
+
*
|
|
12
|
+
* Nothing changes silently: the NFKC and whitespace stages diff their own
|
|
13
|
+
* output and report what they rewrote, so an empty report always means the
|
|
14
|
+
* text came out byte-for-byte identical.
|
|
15
|
+
*
|
|
16
|
+
* Emoji-safe: zero width joiners, emoji presentation selectors (U+FE0E /
|
|
17
|
+
* U+FE0F), and emoji tag sequences that are part of a REAL emoji sequence
|
|
18
|
+
* (family ZWJ sequences, hearts with U+FE0F, keycaps, subdivision flags) are
|
|
19
|
+
* preserved in every preset except "Plain ASCII". Protection is granted by
|
|
20
|
+
* parsing the sequence, never by proximity: the supplementary-plane variation
|
|
21
|
+
* selectors (U+E0100–U+E01EF) used for hidden-byte smuggling are never part of
|
|
22
|
+
* an emoji and are always removed when the variation-selector pass is on.
|
|
23
|
+
*/
|
|
24
|
+
export type DetectionCategory = "ai-artifact" | "invisible" | "bidi" | "tag" | "variation-selector" | "control" | "space" | "typography"
|
|
25
|
+
/** Citation and entity markers left behind when an AI chat answer is copied (e.g. ChatGPT's oaicite). */
|
|
26
|
+
| "chat-artifact"
|
|
27
|
+
/** Changes made by the NFKC and whitespace stages rather than by a character strip. */
|
|
28
|
+
| "normalization";
|
|
29
|
+
export type DetectionAction = "removed" | "replaced" | "kept";
|
|
30
|
+
export type Detection = {
|
|
31
|
+
/** Formatted codepoint, e.g. "U+202F". */
|
|
32
|
+
codepoint: string;
|
|
33
|
+
/** Human-readable Unicode name, e.g. "Narrow no-break space". */
|
|
34
|
+
name: string;
|
|
35
|
+
count: number;
|
|
36
|
+
category: DetectionCategory;
|
|
37
|
+
action: DetectionAction;
|
|
38
|
+
/** Extra context, e.g. "Widely reported in ChatGPT output, April 2025". */
|
|
39
|
+
note?: string;
|
|
40
|
+
};
|
|
41
|
+
export type CleaningStats = {
|
|
42
|
+
invisibleCharactersRemoved: number;
|
|
43
|
+
directionalMarkersRemoved: number;
|
|
44
|
+
nbspConverted: number;
|
|
45
|
+
quotesDashesNormalized: number;
|
|
46
|
+
blankLinesCollapsed: number;
|
|
47
|
+
/** AI-artifact spaces + tag characters + variation selectors removed or replaced. */
|
|
48
|
+
aiArtifactsRemoved: number;
|
|
49
|
+
controlCharactersRemoved: number;
|
|
50
|
+
markdownArtifactsRemoved: number;
|
|
51
|
+
/** Codepoints rewritten by Unicode (NFKC) compatibility folding. */
|
|
52
|
+
unicodeNormalized: number;
|
|
53
|
+
/** Trailing whitespace characters trimmed + CRLF/CR line endings converted. */
|
|
54
|
+
whitespaceNormalized: number;
|
|
55
|
+
/** Hard-wrapped line breaks joined inside paragraphs, plus words rejoined across a line-end hyphen. */
|
|
56
|
+
linesJoined: number;
|
|
57
|
+
};
|
|
58
|
+
/** A message decoded from invisible characters found in the input. */
|
|
59
|
+
export type HiddenMessage = {
|
|
60
|
+
/** "tag": Unicode tag characters (U+E0020–U+E007E) spelling ASCII text. "variation-selector": bytes encoded as variation selectors after a visible character. */
|
|
61
|
+
kind: "tag" | "variation-selector";
|
|
62
|
+
/** The decoded text (truncated to 500 characters). */
|
|
63
|
+
text: string;
|
|
64
|
+
/** Number of invisible characters that carried it. */
|
|
65
|
+
carriers: number;
|
|
66
|
+
};
|
|
67
|
+
export type CleaningResult = {
|
|
68
|
+
cleanedText: string;
|
|
69
|
+
stats: CleaningStats;
|
|
70
|
+
detections: Detection[];
|
|
71
|
+
/** Readable messages decoded from invisible characters in the original text. Empty when none. */
|
|
72
|
+
hiddenMessages: HiddenMessage[];
|
|
73
|
+
};
|
|
74
|
+
export type CleaningOptions = {
|
|
75
|
+
normalizeUnicode?: boolean;
|
|
76
|
+
removeInvisibleChars?: boolean;
|
|
77
|
+
removeBiDi?: boolean;
|
|
78
|
+
normalizeWhitespace?: boolean;
|
|
79
|
+
normalizeTypography?: boolean;
|
|
80
|
+
plainAscii?: boolean;
|
|
81
|
+
/** Remove U+E0000–U+E007F tag characters (invisible data smuggling / watermarking). */
|
|
82
|
+
removeTagChars?: boolean;
|
|
83
|
+
/** Remove variation selectors (U+FE00–U+FE0F, U+E0100–U+E01EF) — emoji-safe. */
|
|
84
|
+
removeVariationSelectors?: boolean;
|
|
85
|
+
/** Remove C0/C1 control characters (except tab and newline); U+2028/U+2029/NEL become \n. */
|
|
86
|
+
removeControlChars?: boolean;
|
|
87
|
+
/** Convert exotic Unicode spaces (U+2000–U+200A, U+202F, U+205F, U+3000, U+180E) to regular spaces. */
|
|
88
|
+
normalizeSpaces?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Remove the joiner controls U+200C (ZWNJ) and U+200D (ZWJ) outside emoji.
|
|
91
|
+
* Persian, Hindi, Malayalam and Sinhala words need them, so they get their
|
|
92
|
+
* own switch. Defaults to `removeInvisibleChars` when not set.
|
|
93
|
+
*/
|
|
94
|
+
removeJoinControls?: boolean;
|
|
95
|
+
/** Strip Markdown residue commonly left by AI chat output (headings, **bold**, links, ...). */
|
|
96
|
+
stripMarkdown?: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Join hard-wrapped lines inside a paragraph (PDF, email, terminal copy).
|
|
99
|
+
* Blank lines stay paragraph breaks and list items keep their own line.
|
|
100
|
+
* A word split by a hyphen at the line end is rejoined when the next line
|
|
101
|
+
* starts with a lowercase letter.
|
|
102
|
+
*/
|
|
103
|
+
joinLines?: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Remove citation and entity markers that AI chat apps leave in copied text,
|
|
106
|
+
* such as ChatGPT's ":contentReference[oaicite:0]{index=0}", "【4†source】" and
|
|
107
|
+
* the private-use "cite turn0search0" markers. Entity markers keep their
|
|
108
|
+
* display name.
|
|
109
|
+
*/
|
|
110
|
+
removeChatArtifacts?: boolean;
|
|
111
|
+
};
|
|
112
|
+
export declare const DEFAULT_PRESET = "AI Clean";
|
|
113
|
+
export declare const PRESETS: Record<string, CleaningOptions>;
|
|
114
|
+
/** One-line description of each preset, as shown in the web tool. */
|
|
115
|
+
export declare const PRESET_DESCRIPTIONS: Record<string, string>;
|
|
116
|
+
export declare function formatCodepoint(cp: number): string;
|
|
117
|
+
export declare function codepointName(cp: number): string;
|
|
118
|
+
/**
|
|
119
|
+
* Decodes the two known ways of hiding text in invisible characters:
|
|
120
|
+
* runs of Unicode tag characters that spell ASCII (outside real emoji flag
|
|
121
|
+
* sequences), and "emoji smuggling", where each byte of a UTF-8 message is a
|
|
122
|
+
* variation selector (U+FE00–U+FE0F for 0–15, U+E0100–U+E01EF for 16–255).
|
|
123
|
+
*/
|
|
124
|
+
export declare function findHiddenMessages(text: string): HiddenMessage[];
|
|
125
|
+
export declare function cleanText(text: string, options: CleaningOptions): CleaningResult;
|
|
126
|
+
/**
|
|
127
|
+
* Scans text for hidden characters and AI watermark artifacts without
|
|
128
|
+
* transforming it. Actions reflect what the recommended "AI Clean" preset
|
|
129
|
+
* would do; characters it keeps (emoji parts), visible typography (em dashes,
|
|
130
|
+
* smart quotes) and formatting-only changes are not reported here, so a
|
|
131
|
+
* non-empty result always means real hidden characters are present.
|
|
132
|
+
*/
|
|
133
|
+
export declare function detectHiddenCharacters(text: string): Detection[];
|