@bnidev/js-utils
    Preparing search index...

    Function stripHtmlTags

    • 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.

      If the input exceeds the maximum allowed length.

      // ES Module
      import { stripHtmlTags } from '@bnidev/js-utils'

      // CommonJS
      const { stripHtmlTags } = require('@bnidev/js-utils')
      stripHtmlTags('<p>Hello <strong>World</strong></p>')
      // → 'Hello World'