npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

advanced-html-parser

v1.1.0

Published

Can use html parser in react-native, titanium, and anywhere. This is based on [xmldom](https://github.com/jindw/xmldom).

Downloads

376

Readme

advanced-html-parser

Can use html parser in react-native, titanium, and anywhere. This is based on xmldom. This library is based on react-native-html-parser where it has much more features and it can decode almost all charecters set, also added support to CSS3 selectors and typescript.

Install:


npm install advanced-html-parser

Example


const IDOMParser = require("advanced-html-parser");
// or import IDOMParser from 'advanced-html-parser'
const doc = IDOMParser.parse(`<div class="test" href="google"><span> test </span><span> test </span></div>`);
const attr = doc.documentElement.querySelector("span").closest(".test").getAttribute("href"); // google

CSS3 Selector support

The library uses css-select and it support all advanced selectors css-select support like #info > .description > .small strong:first-child span and more. See css-select for more info.

Speed up the parsing

The libray is very fast, and if you want to use it to scrap some data from website. then using the settings below may speed the parsing.

    const doc = IDOMParser.parse(page, {
        ignoreTags: ["script", "style", "head"] // This will remove all those tags before begining to parse the string.
        onlyBody: true
    });

Node Class

export interface Node {
    readonly nodeName: string;
    readonly tagName: string;
    readonly nodeType: number;
    readonly firstChild: Element | null;
    readonly lastChild: Element | null;
    readonly previousSibling: Element | null;
    readonly nextSibling: Element | null;
    readonly attributes: NamedNodeMap | null;
    readonly parentNode: Node | null;
    readonly childNodes: NodeList<Node> | null;
    readonly children: Node[];
    readonly ownerDocument: Document | null;
    nodeValue: string | null;
    value: string | null;
    readonly namespaceURI: string | null;
    readonly prefix: string | null;
    readonly localName: string | null;
    readonly insertBefore: (newChild: Node, refChild: Element) => Element;
    readonly replaceChild: (newChild: Node, refChild: Element) => void;
    readonly removeChild: (oldChild: Node) => void;
    readonly remove: () => void;
    readonly appendChild: (child: Node) => void;
    readonly hasChildNodes: () => boolean;
    readonly cloneNode: (deep: boolean) => Node;
    readonly normalize: () => void;
    readonly isSupported: (feature: number, version: string) => boolean;
    readonly hasAttributes: () => boolean;
    readonly lookupPrefix: (namespaceURI: string) => Node | null;
    readonly lookupNamespaceURI: (prefix: string) => Node | null;
    readonly isDefaultNamespace: (namespaceURI: string) => boolean;
    readonly toString: () => string;
    innerHTML: string;
    textContent: string;
    readonly outerHTML: string;
    /*
        RawText
    */
    readonly innerText: () => string;
    /*
        structored text based
    */
    readonly text: () => string;

}

Element

export interface Element extends Node {
    readonly hasAttribute: (attrName: string) => boolean;
    readonly getAttribute: (attrName: string) => string;
    readonly getAttributeNode: (attrName: string) => Attribute;
    readonly setAttribute: (name: string, value: string) => void;
    readonly removeAttribute: (name: string) => any;
    readonly setAttributeNode: (newAttr: string) => Attribute;
    readonly setAttributeNodeNS: (newAttr: string) => Attribute;
    readonly removeAttributeNode: (oldAttr: string) => void;
    //get real attribute name,and remove it by removeAttributeNode
    readonly removeAttributeNS: (namespaceURI: string, localName: string) => void;
    readonly hasAttributeNS: (namespaceURI: string, localName: string) => boolean;
    readonly getAttributeNS: (namespaceURI: string, localName: string) => Attribute;
    readonly setAttributeNS: (namespaceURI: string, qualifiedName: string, value: string) => Attribute;
    readonly getAttributeNodeNS: (namespaceURI: string, qualifiedName: string) => Attribute;
    readonly getElementsByTagName: (tagName: string) => NodeList<Element>;
    readonly getElementsByClassName: (className: string) => NodeList<Element>;
    readonly getElementsByTagNameNS: (namespaceURI: string, localName: string) => NodeList<Element>;
    readonly getElementsByAttribute: (attribute: string, selector: string, undefine: string) => NodeList<Element>;
    readonly querySelectorAll: (selector: string) => NodeList<Element>;
    readonly querySelector: (selector: string) => Element | null;
    readonly closest: (selector: string) => Element | null;
    readonly classList: ClassList;
}

Document

export interface Document {
    readonly nodeName: string;
    readonly nodeType: number;
    readonly doctype: string | null;
    readonly documentElement: Element;
    readonly insertBefore: (newChild: Node, refChild: Node) => Element;
    readonly removeChild: (child: Node) => void;
    readonly importNode: (importedNode: Node, deep: number) => Element;
    readonly getElementById: (id: string) => Element | null;
    readonly getElementByClassName: (className: string) => Element | null;
    readonly getElementByAttribute: (attibute: string) => Element | null;
    readonly createElement: (tagName: string) => Element;
    readonly createDocumentFragment: () => DocumentFragment;
    readonly createTextNode: (data: string) => Text;
    readonly createComment: (data: string) => Node;
    readonly createCDATASection: (data: string) => Node;
    readonly createProcessingInstruction: (target: string, data: string) => Node;
    readonly createAttribute: (name: string) => Attribute;
    readonly createEntityReference: (name: string) => Attribute;
    readonly createElementNS: (namespaceURI: string, qualifiedName: string) => Element;
    readonly createAttributeNS: (namespaceURI: string, qualifiedName: string) => Attribute;
}

Parser Options


export interface Options {
    xmlns?: { xml?: string };
    /*
        default text/html
    */
    mimeType?: string;

    /*

        Ignore parsing tags eg script, style etc
        This is for performance issue, will use RegExp to clean the html string before parsing it.

    */
    ignoreTags?:string[];

    /*
        Parse only the body.
        this will extract the <body> from the html string and parse it only
    */
    onlyBody?: boolean;

      /*
        override the errorHandler. 

    */
    errorHandler?: ErrorHandler;
}