@exadel/esl
Version:
Exadel Smart Library (ESL) is the lightweight custom elements library that provide a set of super-flexible components
30 lines (29 loc) • 1.57 kB
TypeScript
export interface SanitizeOptions {
/** List of tags to remove from the sanitized tree. Scripts are always disallowed. */
disallowedTags?: readonly string[];
/** List of allowed first-level tags under the sanitized root container. */
allowedRoots?: readonly string[];
/** List of attributes that should be treated as URL-bearing attributes. */
urlAttributes?: readonly string[];
/** List of allowed URL protocols. Empty string means relative URLs are allowed. */
allowedUrlProtocols?: readonly string[];
}
/**
* Lightly sanitizes html string from malicious attributes, values, and scripts
* Can also remove disallowed tags and filter first-level root tags.
* NOTE: This is a lightweight sanitizer for rich-text HTML and SVG detection.
* For complex or security-critical sanitization, prefer specialized libraries such as DOMPurify.
* @param html - html string to sanitize
* @param options - sanitize options
*/
export declare function sanitize(html: string, options?: SanitizeOptions): string;
/**
* Sanitizes Element from malicious attributes, values, and scripts.
* Useful when you need to sanitize already parsed html.
* Can also remove disallowed tags and filter first-level root tags.
* NOTE: This is a lightweight sanitizer for rich-text HTML and SVG detection.
* For complex or security-critical sanitization, prefer specialized libraries such as DOMPurify.
* @param el - Element to sanitize
* @param options - sanitize options
*/
export declare function sanitize<T extends Element>(el: T, options?: SanitizeOptions): T;