glenlivet-htmltojson

0.0.1 • Public • Published

glenlivet-htmltojson

A Glenlivet plugin that transforms HTML into JSON declaratively.

Installation

npm install glenlivet-htmltojson

Usage

var glenlivet = require('glenlivet');
var Bottle = glenlivet.Bottle;
 
glenlivet.plugins.register(require('glenlivet-htmltojson'));
 
var getLinks = new Bottle({
    htmlToJson: {
        "links": function () {
            return this.map("a", {
                "label": "->text()",
                "url": "->attr('href')"
            });
        }
    }
});
 
getLinks.htmlToJson({
    htmlToJson: {
        html: '<div><a href="http://www.prolificinteractive.com">Prolific Interactive</a><a href="http://www.github.com">Github</a></div>'
    }
}, function (result) {
    console.log(result.htmlToJson.json);
});

The resulting json should be:

{
    "links": [
        {
            "label": "Prolific Interactive",
            "url": "http://www.prolificinteractive.com"
        },
        {
            "label": "Github",
            "url": "http://www.github.com"
        }
    ]
}

Readme

Keywords

Package Sidebar

Install

npm i glenlivet-htmltojson

Weekly Downloads

1

Version

0.0.1

License

MIT

Last publish

Collaborators

  • ericweber