14 lines
365 B
JavaScript
14 lines
365 B
JavaScript
/**
|
|
* Escape XML special characters in a string
|
|
* @param {string} text - The text to escape
|
|
* @returns {string} The escaped text
|
|
*/
|
|
function escapeXml(text) {
|
|
if (!text) return '';
|
|
return text.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"').replaceAll("'", ''');
|
|
}
|
|
|
|
module.exports = {
|
|
escapeXml,
|
|
};
|