runegrid.html-to-object
v1.0.0
Published
Convert an HTML string to a plain object
Downloads
1
Readme
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' } ]}