All files / roosterjs-content-model-dom/lib/domUtils unwrap.ts

87.5% Statements 7/8
50% Branches 2/4
100% Functions 1/1
87.5% Lines 7/8

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 15 16 17 18 19 20        1x   263x   263x       263x 261x     263x 263x    
/**
 * Removes the node and keep all children in place, return the parentNode where the children are attached
 * @param node the node to remove
 */
export function unwrap(node: Node): Node | null {
    // Unwrap requires a parentNode
    const parentNode = node ? node.parentNode : null;
 
    Iif (!parentNode) {
        return null;
    }
 
    while (node.firstChild) {
        parentNode.insertBefore(node.firstChild, node);
    }
 
    parentNode.removeChild(node);
    return parentNode;
}