Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/litejs/dom-lite
A small DOM library for server-side testing, rendering, and handling of HTML files
https://github.com/litejs/dom-lite
document dom domparser html litejs xml xmlhttprequest
Last synced: 3 months ago
JSON representation
A small DOM library for server-side testing, rendering, and handling of HTML files
- Host: GitHub
- URL: https://github.com/litejs/dom-lite
- Owner: litejs
- Created: 2014-03-21T09:09:04.000Z (over 10 years ago)
- Default Branch: main
- Last Pushed: 2024-02-24T22:45:38.000Z (9 months ago)
- Last Synced: 2024-04-10T00:49:45.087Z (7 months ago)
- Topics: document, dom, domparser, html, litejs, xml, xmlhttprequest
- Language: JavaScript
- Homepage: https://litejs.com/
- Size: 229 KB
- Stars: 21
- Watchers: 5
- 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/lauriroLiteJS DOM – [![Coverage][1]][2] [![Size][3]][4] [![Buy Me A Tea][5]][6]
==========Dependency-free DOM library for handling HTML files on server-side.
[DOM spec](https://dom.spec.whatwg.org/) |
[Selectors Level 3](http://www.w3.org/TR/selectors/)Examples
--------```javascript
const { document, DOMParser, XMLSerializer } = require("@litejs/dom");// 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 parsed HTML
el.innerHTML = "hello world";
el.toString();
//hello world
// minify output
el.toString(true);
//hello world
el.querySelectorAll("b");
// [ "hello world" ]// Use XMLHttpRequest in server side
const { XMLHttpRequest } = require("@litejs/dom/net.js");
const xhr = new XMLHttpRequest();
xhr.open("GET", "https://litejs.com");
xhr.responseType = "document";
xhr.onload = function() {
const document = xhr.responseXML;
// Work with DOM in familiar way
console.log(document.querySelector("title").textContent);
}
xhr.send();
```## Contributing
Follow [Coding Style Guide](https://github.com/litejs/litejs/wiki/Style-Guide),
run tests `npm install; npm test`.> Copyright (c) 2014-2024 Lauri Rooden <[email protected]>
[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]