UNPKG

doma

Version:

Parse an HTML string into `DocumentFragment` or one `Element`, in a few bytes (in browser)

11 lines (10 loc) 322 B
const doma = (html) => { if (html === undefined || html === null) { return new DocumentFragment(); } const template = document.createElement('template'); template.innerHTML = html; return template.content; }; doma.one = (html) => doma(html).firstElementChild ?? undefined; export default doma;