babakfp
babakfp5mo ago

Looking for an alternative to deno_dom

Hi I'm looking for an alternative library to https://deno.land/x/deno_dom@v0.1.45/deno-dom-wasm.ts Problems with deno_demo: https://stackoverflow.com/a/76630979/10799492
Stack Overflow
Why does getAttribute not exist on type "Node"?
I'm converting some Javascript I wrote into a Deno TypeScript module. The script uses deno-dom to get all the "a[href]" links off of a page, and returns a list of links. The script is wor...
3 Replies
Deno AI Helper
Deno AI Helper5mo ago
Hello! If you're seeking an alternative to deno_dom, you might want to consider using LinkeDOM. According to the documentation, LinkeDOM is a DOM-like namespace that can be used in environments like Deno, which don't implement the DOM. It focuses on being fast and implementing features useful for server-side rendering. However, it's important to note that LinkeDOM may allow you to do things that are invalid DOM operations, and it does not type check under the Deno CLI. If you require strict type checking, this might not be the best option for you. Here's a basic example of how to use LinkeDOM with Deno, as provided in the documentation:
// Import LinkeDOM
import { DOMParser, HTMLDocument } from "https://esm.run/linkedom";

// Your HTML string
const html = `<html><head></head><body><h1>Hello Denosaurus!</h1></body></html>`;

// Parse the HTML string to create a DOM
const document = new DOMParser().parseFromString(html, "text/html");

// Use the DOM as you would in a browser environment
const h1 = document.querySelector("h1");
console.log(h1.textContent); // Should log "Hello Denosaurus!"
// Import LinkeDOM
import { DOMParser, HTMLDocument } from "https://esm.run/linkedom";

// Your HTML string
const html = `<html><head></head><body><h1>Hello Denosaurus!</h1></body></html>`;

// Parse the HTML string to create a DOM
const document = new DOMParser().parseFromString(html, "text/html");

// Use the DOM as you would in a browser environment
const h1 = document.querySelector("h1");
console.log(h1.textContent); // Should log "Hello Denosaurus!"
Keep in mind that if you're using LinkeDOM with Deno, you need to use the --no-check=remote flag to avoid diagnostics stopping the execution of your program, as LinkeDOM does not type check. If you require correctness or features not related to server-side rendering, the documentation suggests considering deno_dom, but since you're looking for an alternative, LinkeDOM could be a suitable choice depending on your use case. 🦕
Leokuma
Leokuma5mo ago
In one of my projects in the past I still considered deno_dom to be the best. I don't remember if I found an alternative You can use type assertions to fix the compiler warnings
jeff.hykin
jeff.hykin5mo ago
I had the same problem, tried a handful of other libraries including hacking up some NPM ones, but I ultimately ended up back on deno dom using that getAttribute workaround.