File size: 471 Bytes
b39afbe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/**
 * Copyright (c) 2023 MERCENARIES.AI PTE. LTD.
 * All rights reserved.
 */

function escapeHtmlSpecialChars(text: string) {
  if (!text || text.length === 0) {
    console.warn('null text passed into escapeHtmlSpecialChars');
    return '';
  }
  const map: Record<string, string> = {
    '<': '&lt;',
    '>': '&gt;',
    '&': '&amp;',
    '"': '&quot;',
    "'": '&#039;'
  };
  return text.replace(/[<>&"']/g, (m) => map[m]);
}

export { escapeHtmlSpecialChars };