Skip to main content

Escape an HTML string

还没翻译译自英文(bun.com)本页 5 段都还没译

Bun.escapeHTML() escapes HTML characters in a string. It makes the following replacements.

  • " becomes """
  • & becomes "&"
  • ' becomes "'"
  • < becomes "&lt;"
  • > becomes "&gt;"

This function is optimized for large input. It converts non-string values to a string before escaping them.

Bun.escapeHTML("<script>alert('Hello World!')</script>");
// &lt;script&gt;alert(&#x27;Hello World!&#x27;)&lt;/script&gt;

See Utils.

翻訳 © 2026 fanyi.dev · 原文 © 2026 the Bun project (LICENSE.md names no copyright holder) (MIT)