All files / dist utils.js

100% Statements 15/15
50% Branches 4/8
100% Functions 3/3
100% Lines 14/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31  2x 2x 2x                 2x         2x 8x   2x 2x 2x 17x 13x 4x 4x 4x      
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.escape = void 0;
const HTML_CHARS = {
    "&": "&",
    "<": "&lt;",
    ">": "&gt;",
    '"': "&quot;",
    "'": "&#039;",
    "{": "&lcub;",
    "}": "&rcub;"
};
const ESC_REG = /[&<>"'\{\}]/g;
/**
 * The escape method should be used sparingly. because for example it can over escape a string if already escaped one. that being said this function should be unecessary once addon full supports the spec.
 * @param text
 */
const escape = (text) => {
    return text ? text.replace(ESC_REG, match => HTML_CHARS[match]) : '';
};
exports.escape = escape;
Eif (!String.prototype.wrap) {
    String.prototype.wrap = function (a = '', b = '') {
        if (!this.toString().trim())
            return '';
        a = (0, exports.escape)(a);
        b = (0, exports.escape)(b);
        return `${a}${this}${b}`; //this should already be escaped
    };
}