.ts
TypeScript
(application/typescript)
/**
 * Escapes HTML code in the given text.
 *
 * @param text - The text to escape.
 * @returns The escaped text.
 */
export default function escapeHtmlCode(text: string): string {
  return (text || "")
    .split(/&/gm)
    .join("&")
    .split(/</gm)
    .join("&lt;")
    .split(/>/gm)
    .join("&gt;");
}