0.2.0 • Published 4 years ago

dominum v0.2.0

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

npm Dependencies devDependencies

testing badge coverage badge

Known Vulnerabilities Total Alerts Code Quality: Javascript

License

issuehunt-to-marktext

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

  1. 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

  1. Support a minimum of methods and properties for being able to create all Node types and modify them.
  2. Allow all created Node types have the methods and properties needed to preserve their children/state so they can be serialized.
  3. Support exporting all classes with proper inheritance hierarchy so can extend as needed.
  4. 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

  1. 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).
  2. 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

  1. Add browser tests
0.2.0

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago