https://github.com/victrme/slim-htmlparser2
The fast & forgiving HTML parser, slimmed down.
https://github.com/victrme/slim-htmlparser2
deno html htmlparser2 javascript parser
Last synced: 9 months ago
JSON representation
The fast & forgiving HTML parser, slimmed down.
- Host: GitHub
- URL: https://github.com/victrme/slim-htmlparser2
- Owner: victrme
- License: mit
- Created: 2024-11-10T22:14:57.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-16T14:30:31.000Z (about 1 year ago)
- Last Synced: 2025-03-29T10:33:29.751Z (10 months ago)
- Topics: deno, html, htmlparser2, javascript, parser
- Language: TypeScript
- Homepage: https://jsr.io/@victr/slim-htmlparser2
- Size: 165 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# slim-htmlparser2
[](https://npmjs.org/package/htmlparser2)
[![JSR Version]()](https://jsr.io/@victr/slim-htmlparser2)
[](https://npmjs.org/package/htmlparser2)
The fast & forgiving HTML parser, only with Parser.
_htmlparser2 is [the fastest HTML parser](#performance), and takes some shortcuts to get there._
## Usage
`htmlparser2` itself provides a callback interface that allows consumption of documents with minimal allocations.
```js
import * as htmlparser2 from '@victr/htmlparser2'
const parser = new htmlparser2.Parser({
onopentag(name, attributes) {
if (name === 'script' && attributes.type === 'text/javascript') {
console.log('JS! Hooray!')
}
},
ontext(text) {
console.log('-->', text)
},
onclosetag(tagname) {
if (tagname === 'script') {
console.log("That's it?!")
}
},
})
parser.write("Xyz const foo = '<<bar>>';")
parser.end()
```
Output (with multiple text events combined):
```
--> Xyz
JS! Hooray!
--> const foo = '<>';
That's it?!
```
## Performance
```
htmlparser2 : 2.17215 ms/file ± 3.81587
node-html-parser : 2.35983 ms/file ± 1.54487
html5parser : 2.43468 ms/file ± 2.81501
neutron-html5parser: 2.61356 ms/file ± 1.70324
htmlparser2-dom : 3.09034 ms/file ± 4.77033
html-dom-parser : 3.56804 ms/file ± 5.15621
libxmljs : 4.07490 ms/file ± 2.99869
htmljs-parser : 6.15812 ms/file ± 7.52497
parse5 : 9.70406 ms/file ± 6.74872
htmlparser : 15.0596 ms/file ± 89.0826
html-parser : 28.6282 ms/file ± 22.6652
saxes : 45.7921 ms/file ± 128.691
html5 : 120.844 ms/file ± 153.944
```