import SanitizeHtml from "sanitize-html";
import { given } from "@nivinjoseph/n-defensive";
/**
* Utility class for sanitizing HTML content to prevent XSS attacks.
* Provides safe HTML sanitization while maintaining allowed elements and attributes.
*
* @example
* ```typescript
* const html = '
*
Hello World
*
This is bold text with a link
*

*
* `;
* const sanitized = HtmlSanitizer.sanitize(html);
* ```
*/
public static sanitize(html: string): string
{
given(html, "html").ensureHasValue().ensureIsString();
const sanitized = SanitizeHtml(html, this._createOptions());
return sanitized;
}
/**
* Creates the sanitization options for the HTML sanitizer.
* Configures allowed tags, attributes, and URL schemes.
*
* @private
* @returns Sanitization options object
*/
private static _createOptions(): SanitizeHtml.IOptions
{
// Permissive enough to reject stylesheet-escape tricks (`;` to chain declarations,
// `<`/`>` for markup injection, `{`/`}` to close a value and open a block) while
// still allowing CSS functional notation like rgb(), calc(), var(), "quoted" font
// names, etc. The property allowlist below excludes every property whose CSS
// grammar accepts a `