Removes all HTML tags from a string, returning plain text.
Applies the tag-stripping regular expression in a loop to handle nested or malformed tags safely. To mitigate potential performance risks from ambiguous regular expressions (e.g. catastrophic backtracking), the function enforces a maximum input length.
Parameters
html: string
The input string that may contain HTML.
maxLength: number = 1000
Maximum allowed input length. Defaults to 1000 characters.
Throws an error if the input exceeds this limit.
Returns string
The plain text string with all HTML tags removed.
Throws
If the input exceeds the maximum allowed length.
Example: Imports
// ES Module import { stripHtmlTags } from'@bnidev/js-utils'
Removes all HTML tags from a string, returning plain text.
Applies the tag-stripping regular expression in a loop to handle nested or malformed tags safely. To mitigate potential performance risks from ambiguous regular expressions (e.g. catastrophic backtracking), the function enforces a maximum input length.