npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

easyconvert

v0.0.2

Published

HTML to JSON parser for easyplate

Downloads

41

Readme

EasyConvert

EasyConvert is a pure JavaScript HTML parser that converts HTML into JSON directly readable by EasyPlate.

This project is a fork of Himalay destined to be integrated with EasyPlate

npm install easyconvert

Usage

var easyconvert = require('easyconvert');
var html = require('fs').readFileSync('/webpage.html');
var json = easyconvert.parse(html);

Installed globally, easyconvert can also be used from the command-line to convert HTML files to JSON files, or as a pipe transform.

easyconvert webpage.html webpage.json
# or as a pipe
echo "<h1>Hello</h1>" | easyconvert > hello.json

Run easyconvert --help for more information.

Example Input/Output

<div class='post post-featured'>
	<p>Easyconvert parsed me...</p>
	<!-- ...and I liked it. -->
</div>
{
  "div_1": {
    "tag": "div",
    "attribute": {
      "class": "post post-featured"
    },
    "innerHTML": "\n",
    "child": {
      "p_0": {
        "tag": "p",
        "attribute": {},
        "innerHTML": "Easyconvert parsed me...",
        "child": {}
      },
      "comment": " ...and I liked it. "
    }
  },
  "innerHTML": "\n"
}

Note: Text nodes containing only whitespace were removed from the output for readability.

Features

Synchronous

HTML is turned into JSON, that's it. Easyplate is completely synchronous and does not require any complicated callbacks.

Parses Attributes

Easyplate does a couple things when processing attributes:

  • Camel-cases attribute names
  • Attributes without values are set to their names (i.e. disabled turns into disabled="disabled")
  • Groups data-* attributes into a dataset object
  • Attempts to caste any value to a number if !Nan
  • Parses the style attribute into a hash map

Handles Weirdness

Easyplate handles a lot of HTML's fringe cases, like:

  • Closes unclosed tags <p><b>...</p>
  • Ignores extra closing tags <span>...</b></span>
  • Properly handles void tags like <meta> and <img>
  • Properly handles self-closing tags like <input/>
  • Handles <!doctype> and <-- comments -->
  • Does not parse the contents of <script>, <style>, and HTML5 <template> tags

Preserves Whitespace

Easyplate does not cut corners and returns an accurate representation of the HTML supplied.

The following example does absolutely nothing. It simply parses the HTML to JSON then parses the JSON back into HTML, which is the exact same as the original. (Of course if the original was malformed, Himalaya probably buffed out the kinks.)

Why "Easyplate"?

Because Himalay is a great lib, and I want to make it integrated with EasyPlate.

Contributing

Follow me on Twitter for updates or just for the lolz and please check out my other repositories if I have earned it. I thank you for reading.