@viveeditor/sanitize 0.0.0-stage → 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 viveEditor contributors
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,25 @@
1
- # Temporary Holding Version
1
+ # @viveeditor/sanitize
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Server-side sanitizer that keeps exactly the HTML viveEditor produces and removes everything else.
4
+
5
+ Part of [viveEditor](https://github.com/mtvrkan/viveeditor#readme), a free, open-source rich text editor.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install @viveeditor/sanitize
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { sanitizeHtml } from '@viveeditor/sanitize'
17
+
18
+ const clean = sanitizeHtml(request.body.html, { embeds: true })
19
+ ```
20
+
21
+ Keeps exactly the HTML viveEditor produces and removes everything else, using a full HTML5 parser. HTML over `maxBytes` (2 MB by default) throws `TOO_LARGE`, hostile structure throws `TOO_COMPLEX`. The PHP package `viveeditor/sanitizer` shares the same allowlist and test corpus. See [Sanitize on the server](https://github.com/mtvrkan/viveeditor#sanitize-on-the-server).
22
+
23
+ ## License
24
+
25
+ MIT
@@ -0,0 +1,73 @@
1
+ interface ElementRule {
2
+ readonly attributes?: readonly string[];
3
+ readonly styles?: readonly string[];
4
+ }
5
+ interface EmbedProviderRule {
6
+ readonly label: string;
7
+ readonly host: string;
8
+ readonly width: number;
9
+ readonly height: number;
10
+ readonly compactHeight?: number;
11
+ readonly compactTypes?: readonly string[];
12
+ readonly fluid: boolean;
13
+ readonly sandbox: string;
14
+ readonly allow: string;
15
+ }
16
+ interface SanitizeProfile {
17
+ readonly version: number;
18
+ readonly limits: {
19
+ readonly maxBytes: number;
20
+ readonly maxDepth: number;
21
+ readonly maxAttributeLength: number;
22
+ readonly maxImageSrcLength: number;
23
+ readonly maxUrlLength: number;
24
+ readonly maxTextAttributeLength: number;
25
+ readonly maxStyleValueLength: number;
26
+ readonly maxSpan: number;
27
+ readonly maxImageSize: number;
28
+ readonly maxListStart: number;
29
+ readonly maxTableWidth: number;
30
+ readonly maxEmbedStart: number;
31
+ readonly maxEmbedTitle: number;
32
+ readonly maxMentionId: number;
33
+ readonly maxMentionLabel: number;
34
+ readonly maxMathLength: number;
35
+ readonly maxMathDepth: number;
36
+ readonly maxFootnoteLength: number;
37
+ readonly maxAttributes: number;
38
+ readonly maxNesting: number;
39
+ readonly maxExtraElements: number;
40
+ };
41
+ readonly dropWithContent: readonly string[];
42
+ readonly elements: Readonly<Record<string, ElementRule>>;
43
+ readonly mentionClass: string;
44
+ readonly footnoteElements: readonly string[];
45
+ readonly textAlign: readonly string[];
46
+ readonly linkProtocols: readonly string[];
47
+ readonly linkRel: string;
48
+ readonly image: {
49
+ readonly loading: string;
50
+ readonly decoding: string;
51
+ readonly referrerpolicy: string;
52
+ readonly base64Types: readonly string[];
53
+ };
54
+ readonly embedProviders: Readonly<Record<string, EmbedProviderRule>>;
55
+ readonly spotifyTypes: readonly string[];
56
+ readonly colorKeywordsRejected: readonly string[];
57
+ readonly namedColors: readonly string[];
58
+ }
59
+ export declare const VIVE_PROFILE: SanitizeProfile;
60
+ interface SanitizeOptions {
61
+ embeds?: boolean;
62
+ allowBase64?: boolean;
63
+ allowRelativeImages?: boolean;
64
+ maxBytes?: number;
65
+ }
66
+ type SanitizeErrorCode = "TOO_LARGE" | "TOO_COMPLEX";
67
+ export declare class SanitizeError extends Error {
68
+ readonly code: SanitizeErrorCode;
69
+ constructor(code: SanitizeErrorCode, message: string);
70
+ }
71
+ export declare function sanitizeHtml(input: string, options?: SanitizeOptions): string;
72
+ export type { ElementRule, EmbedProviderRule, SanitizeErrorCode, SanitizeOptions, SanitizeProfile };
73
+ //# sourceMappingURL=index.d.mts.map