💻 사용법 How to use
let escape_name = "A & B";
escape_name = html_escape(escape_name);
console.log(escape_name);
// 결과
// A & B
🎈 결과
A & B
💻 코드 Code (ES6+)
/**
* 엔티티 코드 매핑을 위한 변수
* @type {{"`": string, "\"": string, "&": string, "'": string, "<": string, "=": string, ">": string, "/": string}}
*/
let entityMap = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": ''',
'/': '/',
'`': '`',
'=': '='
};
/**
* 특수 문자를 엔티티 코드로 변환 한다
* @param str
* @returns {*}
*/
function html_escape(str){
for (const [specialCharacter, entityCode] of Object.entries(entityMap)) {
str = str.split(specialCharacter).join(entityCode);
}
return str;
}
2022.07.07 - [javascript] - [jQuery] 엔티티 코드 변환 / entity mapping escape