UNPKG

3.91 kBTypeScriptView Raw
1// Type definitions for sanitize-html 2.6
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// A penguin <https://github.com/sirMerr>
7// Johan Davidsson <https://github.com/johandavidson>
8// Jianrong Yu <https://github.com/YuJianrong>
9// GP <https://github.com/paambaati>
10// Dariusz Syncerek <https://github.com/dsyncerek>
11// Piotr Błażejewicz <https://github.com/peterblazejewicz>
12// Pirasis Leelatanon <https://github.com/1pete>
13// Alex Rantos <https://github.com/alex-rantos>
14// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
15
16import { ParserOptions } from "htmlparser2";
17
18export = sanitize;
19
20declare function sanitize(dirty: string, options?: sanitize.IOptions): string;
21
22declare namespace sanitize {
23 interface Attributes { [attr: string]: string; }
24
25 interface Tag { tagName: string; attribs: Attributes; text?: string | undefined; }
26
27 type Transformer = (tagName: string, attribs: Attributes) => Tag;
28
29 type AllowedAttribute = string | { name: string; multiple?: boolean | undefined; values: string[] };
30
31 type DisallowedTagsModes = 'discard' | 'escape' | 'recursiveEscape';
32
33 // tslint:disable-next-line:interface-name
34 interface IDefaults {
35 allowedAttributes: Record<string, AllowedAttribute[]>;
36 allowedSchemes: string[];
37 allowedSchemesByTag: { [index: string]: string[] };
38 allowedSchemesAppliedToAttributes: string[];
39 allowedTags: string[];
40 allowProtocolRelative: boolean;
41 disallowedTagsMode: DisallowedTagsModes;
42 enforceHtmlBoundary: boolean;
43 selfClosing: string[];
44 }
45
46 // tslint:disable-next-line:interface-name
47 interface IFrame {
48 tag: string;
49 attribs: { [index: string]: string };
50 text: string;
51 tagPosition: number;
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 selfClosing?: string[] | undefined;
75 transformTags?: { [tagName: string]: string | Transformer } | undefined;
76 parser?: ParserOptions | undefined;
77 disallowedTagsMode?: DisallowedTagsModes | undefined;
78 /**
79 * Setting this option to true will instruct sanitize-html to discard all characters outside of html tag boundaries
80 * -- before `<html>` and after `</html>` tags
81 * @see {@link https://github.com/apostrophecms/sanitize-html/#discarding-text-outside-of-htmlhtml-tags}
82 * @default true
83 */
84 enforceHtmlBoundary?: boolean | undefined;
85 }
86
87 const defaults: IDefaults;
88 const options: IOptions;
89
90 function simpleTransform(tagName: string, attribs: Attributes, merge?: boolean): Transformer;
91}
92
\No newline at end of file