All files / src/virtual-dom/helpers parseFromString.ts

100% Statements 6/6
42.86% Branches 3/7
100% Functions 1/1
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 1510x   51x   51x       51x   51x     51x  
export default function parseFromString(markup: string, type: 'html' | 'xml' = 'xml') : NodeListOf<ChildNode> {
 
    const mime = type === 'html' ? 'text/html' : 'application/xml';
 
    const wrappedMarkup = type === 'html' ?
        `<!DOCTYPE html>\n<html><body>${markup}</body></html>` :
        `<?xml version="1.0" encoding="UTF-8"?>\n<xml>${markup}</xml>`;
 
    const doc = new DOMParser().parseFromString(wrappedMarkup, mime);
 
    const tag = type === 'html' ? 'body' : 'xml';
 
    // Extract the inner node
    return doc.getElementsByTagName(tag)[0].childNodes;
}