diff --git a/types/dompurify/index.d.ts b/types/dompurify/index.d.ts index 5406156bca..267f762f2b 100644 --- a/types/dompurify/index.d.ts +++ b/types/dompurify/index.d.ts @@ -3,23 +3,18 @@ // Definitions by: Dave Taylor , Samira Bazuzi // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -export = DOMPurify; export as namespace DOMPurify; -declare var DOMPurify: DOMPurify; +export declare function sanitize(source: string | Node): string; +export declare function sanitize(source: string | Node, config: Config & { RETURN_DOM_FRAGMENT?: false; RETURN_DOM?: false; }): string; +export declare function sanitize(source: string | Node, config: Config & { RETURN_DOM_FRAGMENT: true; }): DocumentFragment; +export declare function sanitize(source: string | Node, config: Config & { RETURN_DOM: true; }): HTMLElement; +export declare function sanitize(source: string | Node, config: Config): string | HTMLElement | DocumentFragment; +export declare function addHook(hook: 'uponSanitizeElement', cb: (currentNode: Element, data: SanitizeElementHookEvent, config: Config) => void): void; +export declare function addHook(hook: 'uponSanitizeAttribute', cb: (currentNode: Element, data: SanitizeAttributeHookEvent, config: Config) => void): void; +export declare function addHook(hook: HookName, cb: (currentNode: Element, data: HookEvent, config: Config) => void): void; -interface DOMPurify { - sanitize(source: string | Node): string; - sanitize(source: string | Node, config: DOMPurifyConfig & { RETURN_DOM_FRAGMENT?: false; RETURN_DOM?: false; }): string; - sanitize(source: string | Node, config: DOMPurifyConfig & { RETURN_DOM_FRAGMENT: true; }): DocumentFragment; - sanitize(source: string | Node, config: DOMPurifyConfig & { RETURN_DOM: true; }): HTMLElement; - sanitize(source: string | Node, config: DOMPurifyConfig): string | HTMLElement | DocumentFragment; - addHook(hook: 'uponSanitizeElement', cb: (currentNode: Element, data: DOMPurifySanitizeElementHookEvent, config: DOMPurifyConfig) => void): void; - addHook(hook: 'uponSanitizeAttribute', cb: (currentNode: Element, data: DOMPurifySanitizeAttributeHookEvent, config: DOMPurifyConfig) => void): void; - addHook(hook: DOMPurifyHookName, cb: (currentNode: Element, data: DOMPurifyHookEvent, config: DOMPurifyConfig) => void): void; -} - -interface DOMPurifyConfig { +interface Config { ADD_ATTR?: string[]; ADD_TAGS?: string[]; ALLOW_DATA_ATTR?: boolean; @@ -36,7 +31,7 @@ interface DOMPurifyConfig { WHOLE_DOCUMENT?: boolean; } -type DOMPurifyHookName +type HookName = 'beforeSanitizeElements' | 'uponSanitizeElement' | 'afterSanitizeElements' @@ -47,17 +42,17 @@ type DOMPurifyHookName | 'uponSanitizeShadowNode' | 'afterSanitizeShadowDOM'; -type DOMPurifyHookEvent - = DOMPurifySanitizeElementHookEvent - | DOMPurifySanitizeAttributeHookEvent +type HookEvent + = SanitizeElementHookEvent + | SanitizeAttributeHookEvent | null; -interface DOMPurifySanitizeElementHookEvent { +interface SanitizeElementHookEvent { tagName: string; allowedTags: string[]; } -interface DOMPurifySanitizeAttributeHookEvent { +interface SanitizeAttributeHookEvent { attrName: string; attrValue: string; keepAttr: boolean;