b-fuze / deno-dom

Browser DOM & HTML parser in Deno
https://jsr.io/@b-fuze/deno-dom
MIT License
421 stars 48 forks source link

Method `normalize` is missing on `Node` #106

Open henningko opened 2 years ago

henningko commented 2 years ago

The method normalize seems to be missing from Node. It "merges" child text nodes, so that no text nodes are adjacent to another: https://developer.mozilla.org/en-US/docs/Web/API/Node/normalize

This example unwraps the node el, which can be any existing element with a parent node

import {
  DOMParser,
  Node,
  Document,
} from "https://deno.land/x/deno_dom/deno-dom-wasm.ts";

const parent = el.parentNode;
while (el.firstChild) parent.insertBefore(el.firstChild, el);
parent.removeChild(el);
parent.normalize();
// Error: Property 'normalize' does not exist on type 'Node'.