UNPKG

3.96 kBTypeScriptView Raw
1// Type definitions for sanitize-html 2.9
2// Project: https://github.com/punkave/sanitize-html
3// Definitions by: Rogier Schouten <https://github.com/rogierschouten>
4// Afshin Darian <https://github.com/afshin>
5// Rinze de Laat <https://github.com/biermeester>
6// Johan Davidsson <https://github.com/johandavidson>
7// Jianrong Yu <https://github.com/YuJianrong>
8// GP <https://github.com/paambaati>
9// Dariusz Syncerek <https://github.com/dsyncerek>
10// Piotr Błażejewicz <https://github.com/peterblazejewicz>
11// Pirasis Leelatanon <https://github.com/1pete>
12// Alex Rantos <https://github.com/alex-rantos>
13// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
14
15import { ParserOptions } from "htmlparser2";
16
17export = sanitize;
18
19declare function sanitize(dirty: string, options?: sanitize.IOptions): string;
20
21declare namespace sanitize {
22 interface Attributes { [attr: string]: string; }
23
24 interface Tag { tagName: string; attribs: Attributes; text?: string | undefined; }
25
26 type Transformer = (tagName: string, attribs: Attributes) => Tag;
27
28 type AllowedAttribute = string | { name: string; multiple?: boolean | undefined; values: string[] };
29
30 type DisallowedTagsModes = 'discard' | 'escape' | 'recursiveEscape';
31
32 // tslint:disable-next-line:interface-name
33 interface IDefaults {
34 allowedAttributes: Record<string, AllowedAttribute[]>;
35 allowedSchemes: string[];
36 allowedSchemesByTag: { [index: string]: string[] };
37 allowedSchemesAppliedToAttributes: string[];
38 allowedTags: string[];
39 allowProtocolRelative: boolean;
40 disallowedTagsMode: DisallowedTagsModes;
41 enforceHtmlBoundary: boolean;
42 selfClosing: string[];
43 }
44
45 // tslint:disable-next-line:interface-name
46 interface IFrame {
47 tag: string;
48 attribs: { [index: string]: string };
49 text: string;
50 tagPosition: number;
51 mediaChildren: string[];
52 }
53
54 // tslint:disable-next-line:interface-name
55 interface IOptions {
56 allowedAttributes?: Record<string, AllowedAttribute[]> | false | undefined;
57 allowedStyles?: { [index: string]: { [index: string]: RegExp[] } } | undefined;
58 allowedClasses?: { [index: string]: boolean | Array<string | RegExp> } | undefined;
59 allowedIframeDomains?: string[] | undefined;
60 allowedIframeHostnames?: string[] | undefined;
61 allowIframeRelativeUrls?: boolean | undefined;
62 allowedSchemes?: string[] | boolean | undefined;
63 allowedSchemesByTag?: { [index: string]: string[] } | boolean | undefined;
64 allowedSchemesAppliedToAttributes?: string[] | undefined;
65 allowedScriptDomains?: string[] | undefined;
66 allowedScriptHostnames?: string[] | undefined;
67 allowProtocolRelative?: boolean | undefined;
68 allowedTags?: string[] | false | undefined;
69 allowVulnerableTags?: boolean | undefined;
70 textFilter?: ((text: string, tagName: string) => string) | undefined;
71 exclusiveFilter?: ((frame: IFrame) => boolean) | undefined;
72 nestingLimit?: number | undefined;
73 nonTextTags?: string[] | undefined;
74 /** @default true */
75 parseStyleAttributes?: boolean | undefined;
76 selfClosing?: string[] | undefined;
77 transformTags?: { [tagName: string]: string | Transformer } | undefined;
78 parser?: ParserOptions | undefined;
79 disallowedTagsMode?: DisallowedTagsModes | undefined;
80 /**
81 * Setting this option to true will instruct sanitize-html to discard all characters outside of html tag boundaries
82 * -- before `<html>` and after `</html>` tags
83 * @see {@link https://github.com/apostrophecms/sanitize-html/#discarding-text-outside-of-htmlhtml-tags}
84 * @default true
85 */
86 enforceHtmlBoundary?: boolean | undefined;
87 }
88
89 const defaults: IDefaults;
90 const options: IOptions;
91
92 function simpleTransform(tagName: string, attribs: Attributes, merge?: boolean): Transformer;
93}
94
\No newline at end of file