improve module declarations

This commit is contained in:
falsandtru
2017-09-01 08:57:22 +09:00
parent 2de60d4e1a
commit 5ace485257
+15 -20
View File
@@ -3,23 +3,18 @@
// Definitions by: Dave Taylor <http://davetayls.me>, Samira Bazuzi <https://github.com/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;