Negotiable Paleobotanist Missions

npm

Check out our latest tech talk, "JavaScript Supply Chain Security" presented by VP of Security, Adam Baldwin.Watch it here »

html-document

0.8.1 • Public • Published

html-document NPM version Build Status Code Climate Coverage

Partial implementation of the DOM, document for node.

Quick example

import Document from 'html-document'; // or var Document = require('html-document');
const document = new Document();
 
let textNode = document.createTextNode('Hello');
let h1 = document.createElement('h1');
h1.setAttribute('id', 'title');
 
h1.appendChild(textNode);
expect(h1.outerHTML, '<h1 id="title">Hello</h1>');

Purpose

The partial implementation allows you to build html like you would in the browser, with the DOM API.

This library will never implement all specifications of the W3C.

API

See the generated API here.

Examples

Inject window, document, Document, DocumentFragment, Node and Event in the global scope.

import 'html-document/lib/global'; // or var Document = require('html-document/lib/global');
 
let textNode = document.createTextNode('Hello');
expect(textNode.textContent, 'Hello');

Create an HTML layout

let document = new Document();
let fragment = document.createDocumentFragment();
fragment.appendChild(new Doctype());
let html = document.createElement('html');
fragment.appendChild(html);
let head = document.createElement('head');
html.appendChild(head);
let body = document.createElement('body');
html.appendChild(body);
expect(fragment.innerHTML, '<!DOCTYPE html><html><head></head><body></body></html>');

install

npm i html-document

Downloadsweekly downloads

100

version

0.8.1

license

MIT

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability