Gathering detailed insights and metrics for html-dom-parser
Gathering detailed insights and metrics for html-dom-parser
npm install html-dom-parser
Typescript
Module System
Node Version
NPM Version
97.1
Supply Chain
99.6
Quality
87.9
Maintenance
100
Vulnerability
100
License
JavaScript (56.69%)
TypeScript (41.34%)
HTML (1.97%)
Total Downloads
195,961,557
Last Day
100,449
Last Week
612,933
Last Month
5,633,850
Last Year
73,177,122
93 Stars
1,626 Commits
22 Forks
2 Watching
1 Branches
8 Contributors
Minified
Minified + Gzipped
Latest Version
5.0.13
Package Id
html-dom-parser@5.0.13
Unpacked Size
128.58 kB
Size
29.56 kB
File Count
54
NPM Version
10.8.2
Node Version
20.18.1
Publised On
25 Dec 2024
Cumulative downloads
Total Downloads
Last day
-23.7%
100,449
Compared to previous day
Last week
-50.4%
612,933
Compared to previous week
Last month
-8.9%
5,633,850
Compared to previous month
Last year
40.9%
73,177,122
Compared to previous year
2
40
HTML to DOM parser that works on both the server (Node.js) and the client (browser):
HTMLDOMParser(string[, options])
The parser converts an HTML string to a JavaScript object that describes the DOM tree.
1import parse from 'html-dom-parser'; 2 3parse('<p>Hello, World!</p>');
1[ 2 Element { 3 type: 'tag', 4 parent: null, 5 prev: null, 6 next: null, 7 startIndex: null, 8 endIndex: null, 9 children: [ 10 Text { 11 type: 'text', 12 parent: [Circular], 13 prev: null, 14 next: null, 15 startIndex: null, 16 endIndex: null, 17 data: 'Hello, World!' 18 } 19 ], 20 name: 'p', 21 attribs: {} 22 } 23]
NPM:
1npm install html-dom-parser --save
Yarn:
1yarn add html-dom-parser
CDN:
1<script src="https://unpkg.com/html-dom-parser@latest/dist/html-dom-parser.min.js"></script> 2<script> 3 window.HTMLDOMParser(/* string */); 4</script>
Import with ES Modules:
1import parse from 'html-dom-parser';
Require with CommonJS:
1const parse = require('html-dom-parser').default;
Parse empty string:
1parse('');
Output:
1[]
Parse string:
1parse('Hello, World!');
1[ 2 Text { 3 type: 'text', 4 parent: null, 5 prev: null, 6 next: null, 7 startIndex: null, 8 endIndex: null, 9 data: 'Hello, World!' 10 } 11]
Parse element with attributes:
1parse('<p class="foo" style="color: #bada55">Hello, <em>world</em>!</p>');
1[ 2 Element { 3 type: 'tag', 4 parent: null, 5 prev: null, 6 next: null, 7 startIndex: null, 8 endIndex: null, 9 children: [ [Text], [Element], [Text] ], 10 name: 'p', 11 attribs: { class: 'foo', style: 'color: #bada55' } 12 } 13]
The server parser is a wrapper of htmlparser2 parseDOM
but with the root parent node excluded. The next section shows the available options you can use with the server parse.
The client parser mimics the server parser by using the DOM API to parse the HTML string.
Because the server parser is a wrapper of htmlparser2, which implements domhandler, you can alter how the server parser parses your code with the following options:
1/** 2 * These are the default options being used if you omit the optional options object. 3 * htmlparser2 will use the same options object for its domhandler so the options 4 * should be combined into a single object like so: 5 */ 6const options = { 7 /** 8 * Options for the domhandler class. 9 * https://github.com/fb55/domhandler/blob/master/src/index.ts#L16 10 */ 11 withStartIndices: false, 12 withEndIndices: false, 13 xmlMode: false, 14 /** 15 * Options for the htmlparser2 class. 16 * https://github.com/fb55/htmlparser2/blob/master/src/Parser.ts#L104 17 */ 18 xmlMode: false, // Will overwrite what is used for the domhandler, otherwise inherited. 19 decodeEntities: true, 20 lowerCaseTags: true, // !xmlMode by default 21 lowerCaseAttributeNames: true, // !xmlMode by default 22 recognizeCDATA: false, // xmlMode by default 23 recognizeSelfClosing: false, // xmlMode by default 24 Tokenizer: Tokenizer, 25};
If you're parsing SVG, you can set lowerCaseTags
to true
without having to enable xmlMode
. This will return all tag names in camelCase and not the HTML standard of lowercase.
[!NOTE] If you're parsing code client-side (in-browser), you cannot control the parsing options. Client-side parsing automatically handles returning some HTML tags in camelCase, such as specific SVG elements, but returns all other tags lowercased according to the HTML standard.
Migrated to TypeScript. CommonJS imports require the .default
key:
1const parse = require('html-dom-parser').default;
Upgraded htmlparser2 to v9.
Upgraded domhandler to v5. Parser options like normalizeWhitespace
have been removed.
Removed Internet Explorer (IE11) support.
Upgraded domhandler
to v4 and htmlparser2
to v6.
Release and publish are automated by Release Please.
No vulnerabilities found.
Reason
security policy file detected
Details
Reason
30 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
packaging workflow detected
Details
Reason
SAST tool is run on all commits
Details
Reason
5 existing vulnerabilities detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
Reason
branch protection is not maximal on development and all release branches
Details
Reason
Found 0/4 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
project is not fuzzed
Details
Score
Last Scanned on 2025-01-06
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