escape es-toolkit
Converts characters with special meaning in HTML to safe entities.
Usage
escape(str)
Use escape when you want to safely insert text into HTML. It converts special characters like &, <, >, ", and ' to HTML entities to prevent XSS attacks and ensure HTML is displayed correctly.
It's essential for security when displaying user input in HTML.
You can use it in templates or comment systems.
It's also useful when putting JSON strings in HTML attributes.
Parameters
strstringrequired
The string to convert for safe use in HTML.
Returns
Returns a new string with characters converted to HTML entities.
Source: es-toolkit
Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.