Jacky Zhao
2025-03-28 7ca9dd9a704bb7a4db410306fcb2f58baa7dea53
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
export const escapeHTML = (unsafe: string) => {
  return unsafe
    .replaceAll("&", "&")
    .replaceAll("<", "&lt;")
    .replaceAll(">", "&gt;")
    .replaceAll('"', "&quot;")
    .replaceAll("'", "&#039;")
}
 
export const unescapeHTML = (html: string) => {
  return html
    .replaceAll("&amp;", "&")
    .replaceAll("&lt;", "<")
    .replaceAll("&gt;", ">")
    .replaceAll("&quot;", '"')
    .replaceAll("&#039;", "'")
}