2024-09-03 17:34:40 +03:00
|
|
|
# escape
|
|
|
|
|
2024-09-03 17:53:24 +03:00
|
|
|
Converts the characters "&", "<", ">", '"', and "'" in `str` to their corresponding HTML entities. For example, `"<"` becomes `"<"`.
|
2024-09-03 17:34:40 +03:00
|
|
|
|
|
|
|
## Signature
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
function escape(str: string): string;
|
|
|
|
```
|
|
|
|
|
|
|
|
### Parameters
|
|
|
|
|
|
|
|
- `str` (`string`): The string to escape.
|
|
|
|
|
|
|
|
### Returns
|
|
|
|
|
|
|
|
(`string`): The escaped string.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
import { escape } from 'es-toolkit/string';
|
|
|
|
|
|
|
|
escape('This is a <div> element.'); // returns 'This is a <div> element.'
|
|
|
|
escape('This is a "quote"'); // returns 'This is a "quote"'
|
|
|
|
escape("This is a 'quote'"); // returns 'This is a 'quote''
|
|
|
|
escape('This is a & symbol'); // returns 'This is a & symbol'
|
|
|
|
```
|