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

    Function escapeHtml

    • Escapes special HTML characters in a string to their corresponding HTML entities.

      This prevents HTML injection by replacing characters like <, >, &, ", and ' with their safe HTML entity equivalents, so the string can be safely inserted into HTML without being interpreted as markup.

      Parameters

      • html: string

        The input string that may contain HTML special characters.

      Returns string

      A string with HTML characters escaped.

      import { escapeHtml } from '@bnidev/js-utils'
      
      const unsafe = '<div class="test">Hello & welcome!</div>'
      const safe = escapeHtml(unsafe)
      // safe: '&lt;div class=&quot;test&quot;&gt;Hello &amp; welcome!&lt;/div&gt;'