Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report
Generated on May 1, 2024 via pnpm

htmlparser2 9.0.0

Fast & forgiving HTML/XML parser
Package summary
Share
0
issues
2
licenses
4
BSD-2-Clause
2
MIT
Package created
28 Aug 2011
Version published
10 May 2023
Maintainers
1
Total deps
6
Direct deps
4
License
MIT

Issues

0
This package has no issues

Licenses

BSD 2-Clause "Simplified" License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
place-warranty
Cannot
hold-liable
Must
include-copyright
include-license
4 Packages, Including:
domelementtype@2.3.0
domhandler@5.0.3
domutils@3.1.0
entities@4.5.0

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
2 Packages, Including:
dom-serializer@2.0.0
htmlparser2@9.0.0
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

4
All Dependencies CSV
β“˜ This is a list of htmlparser2 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities
domelementtype2.3.02.84 kBBSD-2-Clause
prod
domhandler5.0.312.29 kBBSD-2-Clause
prod
domutils3.1.023.28 kBBSD-2-Clause
prod
entities4.5.075.55 kBBSD-2-Clause
prod

Visualizations

Frequently Asked Questions

What does htmlparser2 do?

Htmlparser2 is a fast and forgiving HTML/XML parser. This Javascript library is designed for high-speed parsing of HTML and XML documents. It's considered the fastest HTML parser and takes shortcuts to achieve this speed. While it excels in performance, it may not strictly comply with the HTML spec, for which a package like parse5 can be used. It's useful when processing HTML/XML documents in your Node.js applications allowing you to analyze, manipulate, or traverse the structure of the content.

How do you use htmlparser2?

Htmlparser2 is easy to use with a clear API. You need to install it first via npm using the command: npm install htmlparser2. After installation, you can import the package into your JavaScript file and initiate a Parser instance like this:

import * as htmlparser2 from "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?!");
        }
    },
});

The Parser instance comes with different event handlers such as onopentag, ontext, and onclosetag that execute your custom code when certain events occur. You can also use Htmlparser2 with streams which is efficient for handling large data. Here's an example of using Htmlparser2 with streams:

import { WritableStream } from "htmlparser2/lib/WritableStream";

const parserStream = new WritableStream({
    ontext(text) {
        console.log("Streaming:", text);
    },
});

const htmlStream = fs.createReadStream("./my-file.html");
htmlStream.pipe(parserStream).on("finish", () => console.log("done"));

Where are the htmlparser2 docs?

The documentation for Htmlparser2 is available at the official GitHub repository, both in the README file and the wiki. The README provides a general overview and use-cases, while the wiki delves deep into the parser's events and options. The package is part of a larger 'Ecosystem' that includes other related packages, which you can explore for more advanced use-cases. You can also test out Htmlparser2 at the AST Explorer for interactive learning.