• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * @fileoverview XML character escaper
3 * @author George Chung
4 */
5"use strict";
6
7//------------------------------------------------------------------------------
8// Public Interface
9//------------------------------------------------------------------------------
10
11/**
12 * Returns the escaped value for a character
13 * @param {string} s string to examine
14 * @returns {string} severity level
15 * @private
16 */
17module.exports = function(s) {
18    return (`${s}`).replace(/[<>&"'\x00-\x1F\x7F\u0080-\uFFFF]/gu, c => { // eslint-disable-line no-control-regex
19        switch (c) {
20            case "<":
21                return "&lt;";
22            case ">":
23                return "&gt;";
24            case "&":
25                return "&amp;";
26            case "\"":
27                return "&quot;";
28            case "'":
29                return "&apos;";
30            default:
31                return `&#${c.charCodeAt(0)};`;
32        }
33    });
34};
35