nano-dom
A minimal DOM-like implementation
Last updated 6 months ago by andcake .
MIT · Repository · Original npm · Tarball · package.json
$ cnpm install nano-dom 
SYNC missed versions from official npm registry.

nano-dom

A light DOM implementation that can be used to test DOM modification on the server-side. This package contains a simple HTML parser to convert the HTML source code to a DOM structure. It provides only the most basic DOM API to be still useful.

Installation

$ npm i nano-dom -D

Usage

import Document from 'nano-dom';

const document = new Document('<div class="greeting">Hello world!</div>');

console.log(document.querySelector('.greeting').innerHTML); // Hello world!

Support for custom tags

You can configure which custom tags are allowed to be self-closing ones. If not configured, you may have to close them explicitly.

import { options }, Document from 'nano-dom';

options.customSelfClosingTags = ['chicken', 'run'];

const document = new Document(`
    <div class="yard">
        <chicken name="Prillan"/>
        <my-non-self-closing>text content</my-non-self-closing>
        <run speed="fast"/>
    </div>
`);

Supported DOM API

  • DOMText
  • DOMElement
    • childNodes
    • children
    • nodeName
    • nodeType
    • tagName
    • className
    • classList
    • firstElementChild
    • innerHTML
    • outerHTML
    • appendChild()
    • replaceChild()
    • removeChild()
    • remove()
    • setAttribute()
    • removeAttribute()
    • getAttribute()
    • addEventListener()
    • removeEventListener()
    • dispatchEvent()
    • getElementByTagName()
    • getElementByClassName()
    • getElementById()
    • querySelectorAll()
    • querySelector()
    • click()
    • focus()
    • blur()
  • Document
    • documentElement
    • childNodes
    • children
    • nodeType
    • body
    • head
    • createElement()
    • createTextNode()
    • getElementById()
    • getElementsByTagName()
    • getElementsByClassName()
    • querySelectorAll()
    • querySelector()
    • addEventListener()
    • removeEventListener()

Current Tags

  • 0.3.3                                ...           latest (6 months ago)

30 Versions

  • 0.3.3                                ...           6 months ago
  • 0.3.2                                ...           6 months ago
  • 0.3.1                                ...           6 months ago
  • 0.3.0                                ...           6 months ago
  • 0.2.4                                ...           10 months ago
  • 0.2.3                                ...           10 months ago
  • 0.2.2                                ...           10 months ago
  • 0.2.1                                ...           10 months ago
  • 0.2.0                                ...           10 months ago
  • 0.1.12                                ...           2 years ago
  • 0.1.11                                ...           2 years ago
  • 0.1.10                                ...           2 years ago
  • 0.1.9                                ...           2 years ago
  • 0.1.8                                ...           2 years ago
  • 0.1.7                                ...           2 years ago
  • 0.1.6                                ...           2 years ago
  • 0.1.5                                ...           2 years ago
  • 0.1.4                                ...           2 years ago
  • 0.1.3                                ...           2 years ago
  • 0.1.2                                ...           2 years ago
  • 0.1.1                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
  • 0.0.9                                ...           2 years ago
  • 0.0.8                                ...           2 years ago
  • 0.0.7                                ...           2 years ago
  • 0.0.6                                ...           2 years ago
  • 0.0.5                                ...           2 years ago
  • 0.0.4                                ...           2 years ago
  • 0.0.3                                ...           2 years ago
  • 0.0.2                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 30
Last Day 0
Last Week 30
Last Month 2
Dependencies (0)
None
Dev Dependencies (7)
Dependents (1)

Copyright 2014 - 2017 © taobao.org |