# htmlparser2-es6

> A minimalist, self-contained ES6 HTML/XML parser based on htmlparser2

Latest version **0.4.6** (published 2017-11-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install htmlparser2-es6
pnpm add htmlparser2-es6
yarn add htmlparser2-es6
bun add htmlparser2-es6
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.6 |
| Published | 2017-11-18 |
| First published | 2017-11-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| Author | David Brown |
| Maintainers | scri.pt |
| Keywords | html, parser, streams, xml, dom, rss, feed, atom |

## Links

- npm: https://www.npmjs.com/package/htmlparser2-es6
- Repository: https://github.com/browndav/htmlparser2
- Homepage: https://github.com/browndav/htmlparser2#readme
- Issues: http://github.com/browndav/htmlparser2/issues
- npm.io page: https://npm.io/package/htmlparser2-es6

## Dependencies (3)

- [babel-cli](https://npm.io/package/babel-cli.md) ^6.26.0
- [event-emitter](https://npm.io/package/event-emitter.md) ^0.3.5
- [babel-preset-es2015](https://npm.io/package/babel-preset-es2015.md) ^6.24.1

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.4.6 (latest) — 2017-11-18
- 0.4.5 — 2017-11-12
- 0.4.4 — 2017-11-06
- 0.4.3 — 2017-11-06
- 0.4.2 — 2017-11-06
- 0.4.1 — 2017-11-05
- 0.4.0 — 2017-11-05
- 0.3.92 — 2017-11-05

## README

# htmlparser2-es6

A minimalist ES6-compatible HTML/XML parser. A callback interface is provided.

## Installation
	npm install htmlparser2-es6

A live demo of the original htmlparser2 is available [here](https://astexplorer.net/#/2AmVrGuGVJ).

## Usage

```javascript
var htmlparser = require("htmlparser2-es6");
var parser = new htmlparser({
	onopentag: function(name, attribs){
		if(name === "script" && attribs.type === "text/javascript"){
			console.log("JS! Hooray!");
		}
	},
	ontext: function(text){
		console.log("-->", text);
	},
	onclosetag: function(tagname){
		if(tagname === "script"){
			console.log("That's it?!");
		}
	}
}, {decodeEntities: true});
parser.write("Xyz <script type='text/javascript'>var foo = '<<bar>>';</ script>");
parser.end();
```

Output (simplified):

```
--> Xyz
JS! Hooray!
--> var foo = '<<bar>>';
That's it?!
```

## Documentation

Read more about the original htmlparser2 module and its options in the [htmlparser2 wiki](https://github.com/fb55/htmlparser2/wiki/Parser-options). Note that this module only provides the `Parser` interface.

## Performance

After having some artificial benchmarks for some time, __@AndreasMadsen__ published his [`htmlparser-benchmark`](https://github.com/AndreasMadsen/htmlparser-benchmark), which benchmarks HTML parses based on real-world websites.

At the time of writing, the latest versions of all supported parsers show the following performance characteristics on [Travis CI](https://travis-ci.org/AndreasMadsen/htmlparser-benchmark/builds/10805007) (please note that Travis doesn't guarantee equal conditions for all tests):

```
gumbo-parser   : 34.9208 ms/file ± 21.4238
html-parser    : 24.8224 ms/file ± 15.8703
html5          : 419.597 ms/file ± 264.265
htmlparser     : 60.0722 ms/file ± 384.844
htmlparser2-dom: 12.0749 ms/file ± 6.49474
htmlparser2    : 7.49130 ms/file ± 5.74368
hubbub         : 30.4980 ms/file ± 16.4682
libxmljs       : 14.1338 ms/file ± 18.6541
parse5         : 22.0439 ms/file ± 15.3743
sax            : 49.6513 ms/file ± 26.6032
```

---
_Source: https://npm.io/package/htmlparser2-es6 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
