Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Readme

happy-dom

Happy-dom is a module that provides a DOM-like abstraction that's pretty popular for test frameworks and server-side rendering, because it's a lot faster and lighter than more full-fledged browser-like options. By default, happy-dom doesn't support Deno, which is the basis for Val Town's runtime, but there's a fork that conveniently swaps out the thing it doesn't support, which is the Node.js vm module.

Another way to work with the DOM is to use domino.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
export let happyDomExample = (async () => {
const { Window } = await import("npm:@zuisong/happy-dom-deno");
const window = new Window({
url: "https://localhost:8080",
width: 1024,
height: 768,
});
const document = window.document;
document.body.innerHTML = "<div class=\"container\"></div>";
const container = document.querySelector(".container");
const button = document.createElement("button");
container.appendChild(button);
// Outputs "<div class="container"><button></button></div>"
return document.body.innerHTML;
})();
October 23, 2023