mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
25 lines
638 B
Plaintext
25 lines
638 B
Plaintext
---
|
|
title: Escape an HTML string
|
|
sidebarTitle: Escape HTML
|
|
mode: center
|
|
---
|
|
|
|
The `Bun.escapeHTML()` utility can be used to escape HTML characters in a string. The following replacements are made.
|
|
|
|
- `"` becomes `"""`
|
|
- `&` becomes `"&"`
|
|
- `'` becomes `"'"`
|
|
- `<` becomes `"<"`
|
|
- `>` becomes `">"`
|
|
|
|
This function is optimized for large input. Non-string types will be converted to a string before escaping.
|
|
|
|
```ts
|
|
Bun.escapeHTML("<script>alert('Hello World!')</script>");
|
|
// <script>alert('Hello World!')</script>
|
|
```
|
|
|
|
---
|
|
|
|
See [Docs > API > Utils](/runtime/utils) for more useful utilities.
|