blob: 4d88fb85766f2c5906c9287278081f545f6ef227 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
---
name: Escape an HTML string
---
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](/docs/api/utils) for more useful utilities.
|