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
npm install node-html-better-parser
Typescript
Module System
Node Version
NPM Version
98.9
Supply Chain
100
Quality
79.3
Maintenance
100
Vulnerability
100
License
HTML (97.77%)
TypeScript (2.23%)
Total Downloads
1,534,025
Last Day
1,279
Last Week
58,571
Last Month
244,276
Last Year
1,505,660
144 Commits
1 Forks
1 Watching
2 Branches
1 Contributors
Latest Version
1.4.7
Package Id
node-html-better-parser@1.4.7
Unpacked Size
154.81 kB
Size
25.55 kB
File Count
10
NPM Version
8.19.4
Node Version
16.20.2
Publised On
09 Sept 2024
Cumulative downloads
Total Downloads
Last day
-10%
1,279
Compared to previous day
Last week
2%
58,571
Compared to previous week
Last month
-16%
244,276
Compared to previous month
Last year
6,198.5%
1,505,660
Compared to previous year
1
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
2 existing vulnerabilities detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-12-16
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