0.0.1 • Published 7 years ago

@vzvu3k6k/domic v0.0.1

Weekly downloads
-
License
CC0-1.0
Repository
github
Last release
7 years ago

domic

Wraps a tree from DomHandler of htmlparser2 and provides getAttribute, textContent, querySelector and querySelectorAll.

import Document from '@vzvu3k6k/domic'
import htmlparser from 'htmlparser2'

let html = '<html><body><p class="foo">Hello, <i>domic</i>.</p></body></html>'
let plainAst = htmlparser.parseDOM(html)
let document = new Document(plainAst)

let body = document.querySelector('html > body')
let p = body.querySelectorAll('p')[0]
console.log(p.getAttribute('class')) // "foo"
console.log(p.textContent) // "Hello, domic."

querySelector and querySelectorAll are powered by css-selector.

See Also

  • jsdom: A JavaScript implementation of the DOM and HTML standards
  • cheerio: jQuery-like DOM manipulation and traversing