type MayNode = Node | null | undefined | void export function ifNodeContains(root: MayNode, node: MayNode): boolean { if (!root) { return false } while (node) { if (node === root) { return true } node = node.parentNode } return false } export function createElementFromHTML(htmlString: string) { const div = document.createElement('div'); div.innerHTML = htmlString.trim(); // Change this to div.childNodes to support multiple top-level nodes return div.firstChild as HTMLElement | null; }