UNPKG

@irwinproject/storybook-addon-tsdoc

Version:
33 lines (32 loc) 985 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.escape = void 0; const HTML_CHARS = { "&": "&amp;", "<": "&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; if (!String.prototype.wrap) { String.prototype.wrap = function (a = '', b = '', esc = true) { if (!this.toString().trim()) return ''; if (esc) { a = (0, exports.escape)(a); b = (0, exports.escape)(b); } return `${a}${this}${b}`; //this should already be escaped }; }