refac: escapeHtml, nl2br, TemplateEngine 분리

This commit is contained in:
2021-08-26 01:37:46 +09:00
parent 3b9884160b
commit 5a0a8bedc1
9 changed files with 76 additions and 82 deletions
+19
View File
@@ -0,0 +1,19 @@
/**
* <>& 등을 html에서도 그대로 보이도록 escape주는 함수
* @see https://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery
*/
const entityMap: { [v: string]: string } = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;',
'/': '&#x2F;',
'`': '&#x60;',
'=': '&#x3D;'
};
export function escapeHtml(string: string): string{
return String(string).replace(/[&<>"'`=/]/g, function (s: string) {
return entityMap[s];
});
}