@technobuddha/library
Version:
A large library of useful functions
44 lines (43 loc) • 1.58 kB
JavaScript
;
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.tag = void 0;
var constants_1 = require("../constants");
var build_1 = __importDefault(require("../build"));
var escapeHTML_1 = __importDefault(require("../escapeHTML"));
/**
* Surround text with an HTML tag
*
* @param input The text to surround
* @param tagName The name of the tag
* @param attributes A dictionary of name value pairs to use for attributes
* @returns HTML tag with text
*/
function tag(input, tagName, attributes) {
if (tagName === void 0) { tagName = 'span'; }
if (attributes === void 0) { attributes = {}; }
return build_1.default('<', tagName, Object.entries(attributes).flatMap(function (_a) {
var _b = __read(_a, 2), k = _b[0], v = _b[1];
return [constants_1.space, k, '="', escapeHTML_1.default(v), '"'];
}), '>', escapeHTML_1.default(input), '</', tagName, '>');
}
exports.tag = tag;
exports.default = tag;