Gathering detailed insights and metrics for @node-projects/node-html-parser-esm
Gathering detailed insights and metrics for @node-projects/node-html-parser-esm
Gathering detailed insights and metrics for @node-projects/node-html-parser-esm
Gathering detailed insights and metrics for @node-projects/node-html-parser-esm
npm install @node-projects/node-html-parser-esm
Typescript
Module System
Node Version
NPM Version
73.9
Supply Chain
98.9
Quality
82.1
Maintenance
100
Vulnerability
100
License
HTML (97.76%)
JavaScript (1.41%)
TypeScript (0.84%)
Total Downloads
15,210
Last Day
1
Last Week
37
Last Month
179
Last Year
6,246
15 Stars
244 Commits
1 Forks
2 Watching
1 Branches
2 Contributors
Minified
Minified + Gzipped
Latest Version
6.2.0
Package Id
@node-projects/node-html-parser-esm@6.2.0
Unpacked Size
66.86 kB
Size
18.36 kB
File Count
22
NPM Version
9.7.1
Node Version
20.10.0
Publised On
26 Dec 2023
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
362.5%
37
Compared to previous week
Last month
-59.5%
179
Compared to previous month
Last year
4.1%
6,246
Compared to previous year
1
23
This is a fork wich compiles to esm modules for usage direct in browser. You need to load javascript package "he" to the browser
Fast HTML Parser is a very fast HTML parser. Which will generate a simplified DOM tree, with 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).
1npm install --save node-html-parser
Note: when using Fast HTML Parser in a Typescript project the minimum Typescript version supported is
^4.1.2
.
-- 2022-08-10
1html-parser :24.1595 ms/file ± 18.7667 2htmljs-parser :4.72064 ms/file ± 5.67689 3html-dom-parser :2.18055 ms/file ± 2.96136 4html5parser :1.69639 ms/file ± 2.17111 5cheerio :12.2122 ms/file ± 8.10916 6parse5 :6.50626 ms/file ± 4.02352 7htmlparser2 :2.38179 ms/file ± 3.42389 8htmlparser :17.4820 ms/file ± 128.041 9high5 :3.95188 ms/file ± 2.52313 10node-html-parser:2.04288 ms/file ± 1.25203 11node-html-parser (last release):2.00527 ms/file ± 1.21317
Tested with htmlparser-benchmark.
1import { parse } from 'node-html-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 the data provided, and return the root of the generated DOM.
data, data to parse
options, parse options
1{ 2 lowerCaseTagName: false, // convert tag name to lower case (hurts performance heavily) 3 comment: false, // retrieve comments (hurts performance slightly) 4 voidTag:{ 5 tags: ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'], // optional and case insensitive, default value is ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'] 6 addClosingSlash: true // optional, default false. void tag serialisation, add a final slash <br/> 7 }, 8 blockTextElements: { 9 script: true, // keep text content when parsing 10 noscript: true, // keep text content when parsing 11 style: true, // keep text content when parsing 12 pre: true // keep text content when parsing 13 } 14}
Parse the data provided, return true if the given data is valid, and return false if not.
1classDiagram 2direction TB 3class HTMLElement{ 4 this trimRight() 5 this removeWhitespace() 6 Node[] querySelectorAll(string selector) 7 Node querySelector(string selector) 8 HTMLElement[] getElementsByTagName(string tagName) 9 Node closest(string selector) 10 Node appendChild(Node node) 11 this insertAdjacentHTML('beforebegin' | 'afterbegin' | 'beforeend' | 'afterend' where, string html) 12 this setAttribute(string key, string value) 13 this setAttributes(Record~string, string~ attrs) 14 this removeAttribute(string key) 15 string getAttribute(string key) 16 this exchangeChild(Node oldNode, Node newNode) 17 this removeChild(Node node) 18 string toString() 19 this set_content(string content) 20 this set_content(Node content) 21 this set_content(Node[] content) 22 this remove() 23 this replaceWith((string | Node)[] ...nodes) 24 ClassList classList 25 HTMLElement clone() 26 HTMLElement getElementById(string id) 27 string text 28 string rawText 29 string tagName 30 string structuredText 31 string structure 32 Node firstChild 33 Node lastChild 34 Node nextSibling 35 HTMLElement nextElementSibling 36 Node previousSibling 37 HTMLElement previousElementSibling 38 string innerHTML 39 string outerHTML 40 string textContent 41 Record~string, string~ attributes 42 [number, number] range 43} 44class Node{ 45 <<abstract>> 46 string toString() 47 Node clone() 48 this remove() 49 number nodeType 50 string innerText 51 string textContent 52} 53class ClassList{ 54 add(string c) 55 replace(string c1, string c2) 56 remove(string c) 57 toggle(string c) 58 boolean contains(string c) 59 number length 60 string[] value 61 string toString() 62} 63class CommentNode{ 64 CommentNode clone() 65 string toString() 66} 67class TextNode{ 68 TextNode clone() 69 string toString() 70 string rawText 71 string trimmedRawText 72 string trimmedText 73 string text 74 boolean isWhitespace 75} 76Node --|> HTMLElement 77Node --|> CommentNode 78Node --|> TextNode 79Node ..> ClassList
Trim element from right (in block) after seeing pattern in a TextNode.
Remove whitespaces in this sub tree.
Query CSS selector to find matching nodes.
Note: Full range of CSS3 selectors supported since v3.0.0.
Query CSS Selector to find matching node.
Get all elements with the specified tagName.
Note: Use * for all elements.
Query closest element by css selector.
Append a child node to childNodes
Parses the specified text as HTML and inserts the resulting nodes into the DOM tree at a specified position.
Set value
to key
attribute.
Set attributes of the element.
Remove key
attribute.
Get key
attribute.
Exchanges given child with new child.
Remove child node.
Same as outerHTML
Set content. Notice: Do not set content of the root node.
Remove current element.
Replace current element with other node(s).
Add class name.
Replace class name with another one.
Remove class name.
Toggle class. Remove it if it is already included, otherwise add.
Returns true if the classname is already in the classList.
Get class names.
Clone a node.
Get element by it's ID.
Get unescaped text value of current node and its children. Like innerText
.
(slow for the first time)
Get escaped (as-is) text value of current node and its children. May have
&
in it. (fast)
Get or Set tag name of HTMLElement. Notice: the returned value would be an uppercase string.
Get structured Text.
Get DOM structure.
Get first child node.
Get last child node.
Set or Get innerHTML.
Get outerHTML.
Returns a reference to the next child node of the current element's parent.
Returns a reference to the next child element of the current element's parent.
Returns a reference to the previous child node of the current element's parent.
Returns a reference to the previous child element of the current element's parent.
Get or Set textContent of current element, more efficient than set_content.
Get all attributes of current element. Notice: do not try to change the returned value.
Corresponding source code start and end indexes (ie [ 0, 40 ])
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
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
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
22 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-12-23
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