$ show capricorn86/happy-dom
Happy DOM is a JavaScript implementation of a web browser without a graphical user interface, designed to run in Node.js. It provides a comprehensive simulation of browser APIs including the DOM, HTML/SVG elements, CSSOM, Fetch, WebSocket, Canvas, Custom Elements, Shadow DOM, and more. The library is primarily used as a test environment for JavaScript frameworks (React, Vue, Angular, Lit, etc.) and supports server-side rendering via an optional server-renderer package. The codebase is a monorepo containing the core happy-dom package along with companion packages for global registration, Jest environment, server rendering, and a pluggable canvas adapter. It is actively maintained with thousands of tests and a large community. However, it exhibits moderate technical drift: some APIs are incomplete, there is significant boilerplate duplication across SVG/HTML element implementations, and a few deprecated settings linger. Overall, it is a solid, well-structured library but not exceptional in craftsmanship due to the repetitive patterns and some incomplete implementations.
The LLM identified 3 files worth highlighting for reuse:
A utility class that safely binds methods from a source object (class prototype) to a target Proxy handler, ensuring correct `this` context and preventing property shadowing. It stores original bound methods in a WeakMap keyed by the target object, and returns a function to clean up bindings. This pattern is used across multiple Proxy-based live collections (MediaList, NodeList, DOMTokenList, etc.) to avoid leaking internal methods. It is self-contained with no external dependencies beyond a few symbol definitions and could be extracted into a standalone package for any Proxy-heavy JavaScript project.
A static utility that parses CSS rule strings into structured objects (selector, properties, at-rule type, etc.). It handles regular style rules, media queries, keyframes, font-face, supports, container, and scope rules using regex-based tokenization. The parser is modular (each rule type has its own parsing method) and returns a consistent `IStyleRule` interface. It does not depend on the Happy DOM DOM tree or window context, making it reusable in any CSS parsing context, such as build tools or minifiers.
A static utility that parses data URIs (data:[<mediatype>][;base64],<data>) into their component parts: MIME type, charset, base64 flag, and decoded body as a Uint8Array. It validates syntax and handles percent-encoding. The class has no dependencies external to the JavaScript runtime and returns a simple interface. This is a classic reusable utility that could be extracted into a standalone npm package for any application needing to process inline data URIs.