@technobuddha/library
Version:
A large library of useful functions
16 lines (15 loc) • 583 B
JavaScript
import { space } from '../constants';
import build from '../build';
import escapeHTML from '../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
*/
export function tag(input, tagName = 'span', attributes = {}) {
return build('<', tagName, Object.entries(attributes).flatMap(([k, v]) => [space, k, '="', escapeHTML(v), '"']), '>', escapeHTML(input), '</', tagName, '>');
}
export default tag;