@irwinproject/storybook-addon-tsdoc
Version:
Generate mdx documentation from your typescript!
33 lines (32 loc) • 985 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.escape = void 0;
const HTML_CHARS = {
"&": "&",
"<": "<",
">": ">",
'"': """,
"'": "'",
"{": "{",
"}": "}"
};
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
};
}