Skip to main content
Deno 2 is finally here 🎉️
Learn more

dom

DOM reference implementation.

This is an implementation that strictly adheres to the DOM specifications (whatwg/dom and wpt/dom).

Current status: test pass 46219/?

Background

No library has been found that attempts to be compliant with the DOM specification. Of the several libraries available, jsdom is the closest to the specification, but it does not behave as specified.

The DOM has a specification. Therefore, an implementation that adheres to the specification is required.

Web platform test(wpt) is a testing platform for any Web API, including the DOM.

For this project, passing wpt tests is considered conformance to the specification.

Install

import * as mod from "https://deno.land/x/dom_std/mod.ts";

Usage

Use a stand-alone Document object.

import { Document, Element } from "https://deno.land/x/dom_std/mod.ts";
import { assertEquals } from "https://deno.land/std/assert/assert_equals.ts";
import { assert } from "https://deno.land/std/assert/assert.ts";

const document = new Document();
const div = document.createElement("div");

assertEquals(div.namespaceURI, null);
assert(div instanceof Element);

Private data

The specification defines each member’s private data with the expression “associate”.

To access private data, use the accessor.

import { $, Document } from "https://deno.land/x/dom_std/mod.ts";
import { assertEquals } from "https://deno.land/std/assert/assert_equals.ts";

const document = new Document();
$(document).type = "html";
const div = document.createElement("div");

assertEquals(div.namespaceURI, "http://www.w3.org/1999/xhtml");

Normally this is done by the DOMParser.

Extension

Only whatwg/dom is implemented. If you want to use features extended by other specifications, import them.

whatwg/html:

"https://deno.land/x/html_std/extends/all.ts";
import { HTMLElement } from "https://deno.land/x/html_std/mod.ts";
import { $, Document } from "https://deno.land/x/dom_std/mod.ts";
import { assert } from "https://deno.land/std/assert/assert_equals.ts";

const document = new Document();
$(document).type = "html";
const div = document.createElement("div");

assert(div instanceof HTMLElement);

License

MIT © 2023 Tomoki Miyauchi