escapeHtml
The escapeHtml
function escapes special HTML characters in a string to their corresponding HTML entities.
Syntax
typescript
escapeHtml(str: string): string
Parameters
Name | Type | Description |
---|---|---|
str | string | The input string to be escaped. |
Returns
Type | Description |
---|---|
string | The escaped string with HTML entities. |
Example
typescript
escapeHtml('<div class="test">"Hello" & \'World\'</div>');
// Output: '<div class="test">"Hello" & 'World'</div>'
Notes
- Escapes the following characters:
&
,<
,>
,"
, and'
. - Throws
TypeError
if the input is not a string.