mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-24 17:35:16 +00:00
35 lines
936 B
JavaScript
35 lines
936 B
JavaScript
|
/**
|
||
|
* @fileoverview XML character escaper
|
||
|
* @author George Chung
|
||
|
*/
|
||
|
"use strict";
|
||
|
|
||
|
//------------------------------------------------------------------------------
|
||
|
// Public Interface
|
||
|
//------------------------------------------------------------------------------
|
||
|
|
||
|
/**
|
||
|
* Returns the escaped value for a character
|
||
|
* @param {string} s string to examine
|
||
|
* @returns {string} severity level
|
||
|
* @private
|
||
|
*/
|
||
|
module.exports = function(s) {
|
||
|
return (`${s}`).replace(/[<>&"'\x00-\x1F\x7F\u0080-\uFFFF]/gu, c => { // eslint-disable-line no-control-regex
|
||
|
switch (c) {
|
||
|
case "<":
|
||
|
return "<";
|
||
|
case ">":
|
||
|
return ">";
|
||
|
case "&":
|
||
|
return "&";
|
||
|
case "\"":
|
||
|
return """;
|
||
|
case "'":
|
||
|
return "'";
|
||
|
default:
|
||
|
return `&#${c.charCodeAt(0)};`;
|
||
|
}
|
||
|
});
|
||
|
};
|