// Pre-compiled regex for better performance const HTML_TAG_REGEX = /<[^>]*>/g; /** * Removes HTML tags from a string * @param str - The input string containing HTML * @returns A string with HTML tags removed * @example * ```ts * // Basic usage * stripHtml('

Hello World

') // 'Hello World' * stripHtml('
Test
') // 'Test' * * // Email preview text generation * const emailBody = '

Welcome!

Thanks for signing up.

' * const preview = stripHtml(emailBody) // 'Welcome! Thanks for signing up.' * * // Notification sanitization * const notification = '

New message

' * const safeText = stripHtml(notification) // 'alert("xss")New message' * * // Blog post excerpt for meta description * const post = '

This is a great post.

' * const excerpt = stripHtml(post).slice(0, 160) // 'This is a great post.' * * // Search indexing - extract text content * const htmlContent = '

Searchable text

' * const indexableText = stripHtml(htmlContent) // 'Searchable text' * ``` */ export const stripHtml = (str: string): string => { if (!str) return str; return str.replace(HTML_TAG_REGEX, ""); };