1.0.0 • Published 8 years ago

runegrid.html-to-object v1.0.0

Weekly downloads
1
License
ISC
Repository
-
Last release
8 years ago

html-to-object

Convert an HTML string to a plain object.

Warning!

The HTML parsing is non-compliant. It really only parses basic XML, relying on the xml-parser module under the hood. Don't use if you need to build objects from arbitrary HTML.

Install

npm install runegrid.html-to-object

Usage

var HTO = require('runegrid.html-to-object');

var html = '<div><p>Hi</p></div>';

// Mapping of the property name to give each of the
// components of the elements created
var PROP_MAP = {
    name: 'tagName',
    attributes: 'attrs',
    content: 'content',
    children: 'children'
};

var obj = HTO({}, html, PROP_MAP);

// => { tagName: 'div', children: [ { tagName: 'p', content: 'Hi' } ]}
1.0.0

8 years ago