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

flatman-parse

v1.4.7

Published

A library for parsing HTML

Downloads

35

Readme

Flatman Parse 1.2.10

License: MIT

All 45 tests pass

Description

An HTML parser

Takes your raw HTML and returns a JavaScript array with a structure similar to this:

<div class="titlebar"></div>
[{
  tagName : 'div',
  attributes : {
    className : 'titlebar'
  },
  children : []
}]

Installation

NPM

npm i -S flatman-parse
const parseHtml = require('flatman-parse');

Download the flatman-parse.js and use on the client

<script src="flatman-parse.js"></script>

Nodes

  • Regular Node
  • DocType
  • Comment

Regular Node

{
  tagName : 'div',
  attributes : {},
  children : []
}

DocType

{
  tagName : 'doctype',
  rootElement : String,
  type : 'public'|'private',
  publicIdentifier : String,
  privateIdentifier : String
}

XML Declaration

{
  tagName : 'xml',
  attributes : {
    version : String,
    encoding : String,
  }
}

Comment

{
  tagName : 'comment',
  value : value: String
}

Style attribute

<div style="float: left; margin-left: auto"></div>
  {
    tagName : 'div',
    attributes : {
      style  : {
        float : 'left',
        marginLeft : 'auto'
      }
    }
  }

Usage

On the server

const parseHtml = require('flatman-parse');
const result = parseHtml('<div class="my-div"></div>');

On the client

var result = parseHtml('<div class="my-div"></div>');

Tests

   Loading tests (45)

  1. The Acid Test ................................................... PASSED
  2. Basic scaffold .................................................. PASSED
  3. Comment ......................................................... PASSED
  4. div.test ........................................................ PASSED
  5. Doc type ........................................................ PASSED
  6. Doc type HTML4 .................................................. PASSED
  7. Doc type ........................................................ PASSED
  8. h1 .............................................................. PASSED
  9. h4, p, hr, h6, ul, li ........................................... PASSED
  10. hr .............................................................. PASSED
  11. input ........................................................... PASSED
  12. div > input ..................................................... PASSED
  13. div > input + div ............................................... PASSED
  14. div > input + [string] .......................................... PASSED
  15. link ............................................................ PASSED
  16. meta ............................................................ PASSED
  17. attributes (multiline) .......................................... PASSED
  18. comment (multiline) ............................................. PASSED
  19. (div > div + div) * 2 ........................................... PASSED
  20. div > div ....................................................... PASSED
  21. h6 + p .......................................................... PASSED
  22. div.test > [string] ............................................. PASSED
  23. div.test > [string] + div.sibling ............................... PASSED
  24. script .......................................................... PASSED
  25. script (jquery) ................................................. PASSED
  26. nested script (jquery) .......................................... PASSED
  27. <input/> ........................................................ PASSED
  28. <div/> (error) .................................................. PASSED
  29. div ............................................................. PASSED
  30. style (bootstrap) ............................................... PASSED
  31. style nested (bootstrap) ........................................ PASSED
  32. svg (groups) .................................................... PASSED
  33. svg (polygon) ................................................... PASSED
  34. <div> + <div> ................................................... PASSED
  35. ul .............................................................. PASSED
  36. xml declaration ................................................. PASSED
  37. Custom tags ..................................................... PASSED
  38. DocType parse ................................................... PASSED
  39. input (optional slash) .......................................... PASSED
  40. No spaces ....................................................... PASSED
  41. style attribute ................................................. PASSED
  42. svg (acid test) ................................................. PASSED
  43. svg (g tag) ..................................................... PASSED
  44. React public HTML ............................................... PASSED
  45. svg (use maybe closed) .......................................... PASSED

  + 45 test passed
  Completed in ..................................................... 3.71s