0.2.0 • Published 5 years ago
dominum v0.2.0
dominum
Portmanteau of DOM and minimum
A modular representation of the DOM for use in Node.
There is already the excellent jsdom library, but for some targeted use cases, it is a heavier solution than needed.
Currently is mostly limited to creating Node types and with some means to modify them. Future additons may be added in other modules to keep the package light.
Installation
npm i -P dominum
Use cases
- Building templates server-side. These typically only require DOM creation
methods without need for traversal, or after-the-fact manipulaion.
Templating libraries which rely on the DOM, but which only use a subset
of DOM APIs can use such modular DOM to build strings (e.g., with
w3c-xmlserializer
).
Goals
- Support a minimum of methods and properties for being able to create all Node types and modify them.
- Allow all created Node types have the methods and properties needed to preserve their children/state so they can be serialized.
- Support exporting all classes with proper inheritance hierarchy so can extend as needed.
- Use formal mix-in names where possible, but also allow better composability by splitting up mix-ins or making classes mix in custom mix-ins.
Non-goals
- Be fully faithful to the DOM in every neglibile way of no use to regular
DOM building libraries, e.g., erring directly-invoked constructors or
prototype
properties. Use jsdom for more fully accurate behavior (and more complete APIs). - Support all DOM APIs.
Usage
ESM
The classes are available as such:
import {
DOMException,
Node, ParentNode, ChildNode,
NamedNodeMap, NodeList,
setNodeListWritingPermission, setNamedNodeMapWritingPermission,
Element, HTMLElement,
Attr,
DocumentFragment,
ProcessingInstruction,
CharacterData, Comment,
Text, CDATASection,
DocumentType,
Document, HTMLDocument, XMLDocument,
// Custom
createHTMLDocument
} from 'dominum';
You can also import the specific module files:
import {Document} from 'dominum/src/Document';
Node.js
const {createHTMLDocument} = require('dominum');
Browser
Dominum.createHTMLDocument();
To-dos
- Add browser tests