mirror of
https://github.com/toss/es-toolkit.git
synced 2024-12-01 02:33:54 +03:00
683 B
683 B
escape
Converts the characters "&", "<", ">", '"', and "'" in str
to their corresponding HTML entities. For example, "<"
becomes "<"
.
Signature
function escape(str: string): string;
Parameters
str
(string
): The string to escape.
Returns
(string
): The escaped string.
Examples
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'