import sanitizeHtml from 'sanitize-html';

/**
 * Sanitizes user input to prevent XSS attacks and remove malicious content
 * Allows only safe text content, removing all HTML tags and scripts
 * @param input - The string to sanitize
 * @returns Sanitized string with all HTML tags and scripts removed
 */
export function sanitizeText(input: string | undefined | null): string | undefined | null {
    if (!input) {
        return input;
    }

    return sanitizeHtml(input, {
        allowedTags: [], // No HTML tags allowed
        allowedAttributes: {}, // No attributes allowed
        allowedSchemes: [], // No URL schemes allowed
    }).trim();
}

