https://github.com/litejs/dom
Dependency-free DOM library for handling HTML files on server-side
https://github.com/litejs/dom
document dom domparser html litejs xml xmlhttprequest
Last synced: 25 days ago
JSON representation
Dependency-free DOM library for handling HTML files on server-side
- Host: GitHub
- URL: https://github.com/litejs/dom
- Owner: litejs
- Created: 2014-03-21T09:09:04.000Z (about 12 years ago)
- Default Branch: main
- Last Pushed: 2026-02-19T22:48:29.000Z (2 months ago)
- Last Synced: 2026-02-20T01:06:15.299Z (2 months ago)
- Topics: document, dom, domparser, html, litejs, xml, xmlhttprequest
- Language: JavaScript
- Homepage: https://litejs.com/
- Size: 446 KB
- Stars: 26
- Watchers: 3
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[1]: https://badgen.net/coveralls/c/github/litejs/dom
[2]: https://coveralls.io/r/litejs/dom
[3]: https://packagephobia.now.sh/badge?p=@litejs/dom
[4]: https://packagephobia.now.sh/result?p=@litejs/dom
[5]: https://badgen.net/badge/icon/Buy%20Me%20A%20Tea/orange?icon=kofi&label
[6]: https://www.buymeacoffee.com/lauriro
LiteJS DOM – [![Coverage][1]][2] [![Size][3]][4] [![Buy Me A Tea][5]][6]
==========
Dependency-free DOM library for handling HTML, XML and CSS files on server-side.
```javascript
// const { document } = require("@litejs/dom");
import { document, CSSStyleSheet, DOMParser, XMLSerializer } from "@litejs/dom";
import { XMLHttpRequest } from "@litejs/dom/net.js";
// Build DOM manually
const el = document.createElement("h1");
el.id = 123;
el.className = "large";
const fragment = document.createDocumentFragment();
fragment.appendChild(document.createTextNode("hello"));
el.appendChild(fragment);
// Replace the DOM tree with HTML
el.innerHTML = "hello world";
console.log(el.toString());
//
hello world
// Minify HTML
console.log(el.toString(true));
//
hello world
el.querySelectorAll("b");
// [ "hello world" ]
// Use XMLHttpRequest in server side
const xhr = new XMLHttpRequest();
xhr.open("GET", "https://litejs.com");
xhr.responseType = "document";
xhr.onload = function() {
const doc = xhr.responseXML;
// Work with DOM in familiar way
console.log(doc.querySelector("title").textContent);
}
xhr.send();
// Minify CSS
import { CSS } from "@litejs/dom/css.js";
const sheet = new CSSStyleSheet()
sheet.replaceSync(".a { color: hsl(0 0% 100%) }")
console.log(CSS.minify(sheet, { color: true }))
// .a{color:#fff}
```
## Contributing
Follow [Coding Style Guide](https://github.com/litejs/litejs/wiki/Style-Guide),
run tests `npm install; npm test`.
> Copyright (c) 2014-2026 Lauri Rooden <lauri@rooden.ee>
[MIT License](https://litejs.com/MIT-LICENSE.txt) |
[GitHub repo](https://github.com/litejs/dom) |
[npm package](https://npmjs.org/package/@litejs/dom) |
[Buy Me A Tea][6]