A lightweight HTML parser for JavaScript that converts your native HTML code into an Array of JavaScript Objects.
$ npm install --save html-to-object
const h2o = require('html-to-object');
const results = h2o('path/to/file.html', [options]);
Returns the parsed elements as prebuilt DOM nodes to easily append them to the page.
const fs = require('fs');
const h2o = require('html-to-object');
const results = h2o('path/to/file.html', { build: true });
In case of preloaded .html file content.
const fs = require('fs');
const h2o = require('html-to-object');
const html = fs.readFileSync('path/to/file.html', 'utf8');
const results = h2o(html, { targetIsFile: false });
Will define the attributes property of each element as an Object instead of an Array.
const h2o = require('html-to-object');
const results = h2o('path/to/file.html', { attributesAsObject: true });