Gathering detailed insights and metrics for node-html-better-parser
Gathering detailed insights and metrics for node-html-better-parser
Gathering detailed insights and metrics for node-html-better-parser
Gathering detailed insights and metrics for node-html-better-parser
A very fast HTML parser, generating a simplified DOM, with basic element query support.
npm install node-html-better-parser
Typescript
Module System
Node Version
NPM Version
99.5
Supply Chain
100
Quality
88.3
Maintenance
100
Vulnerability
100
License
HTML (97.15%)
TypeScript (2.84%)
JavaScript (0.01%)
Total Downloads
3,122,624
Last Day
2,335
Last Week
85,879
Last Month
355,938
Last Year
2,923,895
MIT License
156 Commits
1 Forks
2 Branches
1 Contributors
Updated on Jun 23, 2025
Minified
Minified + Gzipped
Latest Version
1.5.1
Package Id
node-html-better-parser@1.5.1
Unpacked Size
53.30 kB
Size
13.01 kB
File Count
6
NPM Version
10.8.2
Node Version
20.18.0
Published on
Jun 23, 2025
Cumulative downloads
Total Downloads
Last Day
-21.2%
2,335
Compared to previous day
Last Week
-0.7%
85,879
Compared to previous week
Last Month
-2.9%
355,938
Compared to previous month
Last Year
1,436.3%
2,923,895
Compared to previous year
1
8
Fast HTML Parser is a very fast HTML parser. Which will generate a simplified DOM tree, with basic element query support.
Per the design, it intends to parse massive HTML files in lowest price, thus the
performance is the top priority. For this reason, some malformatted HTML may not
be able to parse correctly, but most usual errors are covered (eg. HTML4 style
no closing <li>
, <td>
etc).
About this fork: I created this fork to provide a simple API for editing the html and especially the attributes.
1npm install --save node-html-better-parser
Faster than htmlparser2!
1fast-html-parser: 2.18409 ms/file ± 1.37431 2high5 : 4.55435 ms/file ± 2.51132 3htmlparser : 27.6920 ms/file ± 171.588 4htmlparser2-dom : 6.22320 ms/file ± 3.48772 5htmlparser2 : 3.58360 ms/file ± 2.23658 6hubbub : 16.1774 ms/file ± 8.95079 7libxmljs : 7.19406 ms/file ± 7.04495 8parse5 : 10.7590 ms/file ± 8.09687
Tested with htmlparser-benchmark.
1import { parse } from 'node-html-better-parser'; 2 3const root = parse('<ul id="list"><li>Hello World</li></ul>'); 4 5console.log(root.firstChild.structure); 6// ul#list 7// li 8// #text 9 10console.log(root.querySelector('#list')); 11// { tagName: 'ul', 12// rawAttrs: 'id="list"', 13// childNodes: 14// [ { tagName: 'li', 15// rawAttrs: '', 16// childNodes: [Object], 17// classNames: [] } ], 18// id: 'list', 19// classNames: [] } 20console.log(root.toString()); 21// <ul id="list"><li>Hello World</li></ul> 22root.set_content('<li>Hello World</li>'); 23root.toString(); // <li>Hello World</li>
1var HTMLParser = require('node-html-parser'); 2 3var root = HTMLParser.parse('<ul id="list"><li>Hello World</li></ul>');
Parse given data, and return root of the generated DOM.
The root is actually a fictive node that contains the nodes found in the content provided. The content can be found in root.childNodes
, or accessed with root.firstChild
if the parsed HTML has a root node (think about <b>siblings</b> <i>nodes</i>
).
1{ 2 lowerCaseTagName: false, // convert tag name to lower case (hurt performance heavily) 3 script: false, // retrieve content in <script> (hurt performance slightly) 4 style: false, // retrieve content in <style> (hurt performance slightly) 5 pre: false, // retrieve content in <pre> (hurt performance slightly) 6 comment: false // retrieve comments (hurt performance slightly) 7}
Returns weither the provided node is a block. A node is considered a block is it has a tag represented as block instead of inline in html specs.
property name | description |
---|---|
text | Get unescaped text value of current node and its children. Like innerText . (slow for the first time) |
tagName | Get the tag name of the current element |
classNames | Get the classes of the current element |
parentNode | Get the parent HTMLNode |
rawText | Get escpaed (as-it) text value of current node and its children. May have & in it. (fast) |
structuredText | Get structured Text |
structure | Get DOM structure |
childNodes | Get the children nodes |
children | Get the children HTMLElement |
firstChild | Get first child node |
lastChild | Get last child node |
attributes | Get attributes |
rawAttributes | Get escaped (as-it) attributes |
innerHTML | Get innerHTML |
outerHTML | Get outerHTML |
method | parameters | return |
---|---|---|
trimRight() | Trim element from right (in block) after seeing pattern in a TextNode. | |
removeWhitespace() | Remove whitespaces in this sub tree. | |
querySelectorAll(selector: string) | * selector: CSS selector Note: only tagName , #id , .class selectors supported. | Query CSS selector to find matching nodes. |
querySelector(selector: string) | * selector: CSS selector Note: only tagName , #id , .class selectors supported. And not behave the same as standard querySelectorAll() as it will stop searching sub tree after find a match. | Query CSS selector to find matching node. |
appendChild(node: Node) | * node: HTMLElement or Text node | Append a child node to childNodes |
setAttribute(key: string, value: string | null) | * key: The HTML attribute key * value: The HTML attribute name | Set value to key attribute. If value is null, remove the attribute instead. |
setAttributes(attributes: Attributes) | * attributes: An object containing the key: value pairs we expect for this node | Replace all the current attributes by the provided attribute set. |
removeAttributes(key: string) | * key: The HTML attribute key | Remove the attribute denoted by key . |
toString() | Same as outerHTML | |
set_content(content: string | Node | Node[]) | * content: The new content for this node | Set content for this node. Notice: Do not set content of the root node. |
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
5 existing vulnerabilities detected
Details
Reason
4 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 3
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More