UNPKG

@livy/util

Version:
33 lines (32 loc) 1.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HTML = void 0; const helpers_1 = require("./helpers"); const HTMLRawMarker = Symbol('HTML raw marker'); /** * HTMLMask('...') masks a string as an HTML chunk so it will not be escaped * You don't need to call this function manually, use HTML() instead. */ function HTMLMask(value) { return { [HTMLRawMarker]: true, toString() { return value; } }; } function HTML(...args) { if (typeof args[0] === 'string') { return HTMLMask(args[0]); } else { const [strings, ...keys] = args; return HTMLMask(strings.slice(1).reduce((carry, string, index) => { const data = keys[index]; return carry.concat(typeof data === 'object' && data !== null && HTMLRawMarker in data ? String(data) : (0, helpers_1.escapeHtmlEntities)(String(data)), string); }, strings[0])); } } exports.HTML = HTML;