🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

domon

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

domon

A lightweight DOM representation format

latest
Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
6
50%
Maintainers
1
Weekly downloads
 
Created
Source

domon

A lightweight DOM representation format

DOMON is a lightweight data format for representing the DOM without circular references, making it suitable for JSON transport and storage etc.

It looks like (for example, a DOM element):

[ "div", { "id": "myDiv" }, [ "Hello World" ] ]

Install

npm install domon

Usage

The DOMON API looks like:

{
  validate: domon => boolean,
  parse: str => domon,
  stringify: domon => str,
  toDom: ( document, domon ) => dom,
  fromDom: ( document, dom ) => domon
}
const assert = require( 'assert' )
const fs = require( 'fs' )
const domon = require( 'domon' )
const jsdom = require( 'jsdom' ).jsdom

fs.readFile( 'document.html', 'utf8', ( err, html ) => {
  if( err ) throw err

  const domonTree = domon.parse( html )

  assert( domon.validate( domonTree, 'domon-document' ) )
  assert( !domon.validate( 1, 'domon-document' ) )

  const stringed = domon.stringify( domonTree )

  assert( typeof stringed === 'string' )

  const dom = domon.toDom( jsdom(), domonTree )

  assert( dom.nodeType === 9 )

  const domonTree2 = domon.fromDom( jsdom(), dom )

  assert( domon.validate( domonTree2, 'domon-document' ) )
})

Keywords

domon

FAQs

Package last updated on 06 Jul 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts