domhandler

  • Version 6.0.1
  • Published
  • 37.2 kB
  • 1 dependency
  • BSD-2-Clause license

Install

npm i domhandler
yarn add domhandler
pnpm add domhandler

Overview

Handler for htmlparser2 that turns pages into a dom

Index

Functions

function cloneNode

cloneNode: <T extends Node>(node: T, recursive?: boolean) => T;
  • Clone a node, and optionally its children.

    Parameter node

    Node to clone.

    Parameter recursive

    Clone child nodes as well.

    Returns

    A clone of the node.

function hasChildren

hasChildren: (node: Node) => node is ParentNode;
  • Checks if node has children.

    Parameter node

    Node to check.

    Returns

    true if the node has children.

function isCDATA

isCDATA: (node: Node) => node is CDATA;
  • Checks if node is a CDATA node.

    Parameter node

    Node to check.

    Returns

    true if the node is a CDATA node.

function isComment

isComment: (node: Node) => node is Comment;
  • Checks if node is a comment node.

    Parameter node

    Node to check.

    Returns

    true if the node is a comment node.

function isDirective

isDirective: (node: Node) => node is ProcessingInstruction;
  • Checks if node is a directive node.

    Parameter node

    Node to check.

    Returns

    true if the node is a directive node.

function isDocument

isDocument: (node: Node) => node is Document;
  • Checks if node is a document node.

    Parameter node

    Node to check.

    Returns

    true if the node is a document node.

function isTag

isTag: (node: Node) => node is Element;
  • Checks if node is an element node.

    Parameter node

    Node to check.

    Returns

    true if the node is an element node.

function isText

isText: (node: Node) => node is Text;
  • Checks if node is a text node.

    Parameter node

    Node to check.

    Returns

    true if the node is a text node.

Classes

class CDATA

class CDATA extends NodeWithChildren {}
  • CDATA nodes.

property nodeType

readonly nodeType: number;

    property type

    type: ElementType.CDATA;

      class Comment

      class Comment extends DataNode {}
      • Comments within the document.

      property nodeType

      readonly nodeType: number;

        property type

        type: ElementType.Comment;

          class DataNode

          abstract class DataNode extends Node {}
          • A node that contains some data.

          constructor

          constructor(data: string);
          • Parameter data

            The content of the data node

          property data

          data: string;

            property nodeValue

            nodeValue: string;
            • Same as data. [DOM spec](https://dom.spec.whatwg.org)-compatible alias.

            class Document

            class Document extends NodeWithChildren {}
            • The root node of the document.

            property "x-mode"

            'x-mode'?: 'no-quirks' | 'quirks' | 'limited-quirks';
            • [Document mode](https://dom.spec.whatwg.org/#concept-document-limited-quirks) (parse5 only).

            property nodeType

            readonly nodeType: number;

              property type

              type: ElementType.Root;

                class DomHandler

                class DomHandler {}
                • Event-based handler that builds a DOM tree from parser callbacks.

                constructor

                constructor(
                callback?: Callback,
                options?: DomHandlerOptions,
                elementCB?: ElementCallback
                );
                • Parameter callback

                  Called once parsing has completed.

                  Parameter options

                  Settings for the handler.

                  Parameter elementCB

                  Callback whenever a tag is closed.

                property dom

                dom: ChildNode[];
                • The elements of the DOM

                property lastNode

                protected lastNode: DataNode;
                • A data node that is still being written to.

                property root

                root: Document;
                • The root element for the DOM

                property tagStack

                protected tagStack: ParentNode[];
                • Stack of open tags.

                method addNode

                protected addNode: (node: ChildNode) => void;

                  method handleCallback

                  protected handleCallback: (error: Error | null) => void;

                    method oncdataend

                    oncdataend: () => void;

                      method oncdatastart

                      oncdatastart: () => void;

                        method onclosetag

                        onclosetag: () => void;

                          method oncomment

                          oncomment: (data: string) => void;

                            method oncommentend

                            oncommentend: () => void;

                              method onend

                              onend: () => void;

                                method onerror

                                onerror: (error: Error) => void;

                                  method onopentag

                                  onopentag: (name: string, attribs: { [key: string]: string }) => void;

                                    method onparserinit

                                    onparserinit: (parser: ParserInterface) => void;

                                      method onprocessinginstruction

                                      onprocessinginstruction: (name: string, data: string) => void;

                                        method onreset

                                        onreset: () => void;

                                          method ontext

                                          ontext: (data: string) => void;

                                            class Element

                                            class Element extends NodeWithChildren {}
                                            • An element within the DOM.

                                            constructor

                                            constructor(
                                            name: string,
                                            attribs: { [name: string]: string },
                                            children?: ChildNode[],
                                            type?: any
                                            );
                                            • Parameter name

                                              Name of the tag, eg. div, span.

                                              Parameter attribs

                                              Object mapping attribute names to attribute values.

                                              Parameter children

                                              Children of the node.

                                              Parameter type

                                              Node type used for the new node instance.

                                            property "x-attribsNamespace"

                                            'x-attribsNamespace'?: Record<string, string>;
                                            • Element attribute namespaces (parse5 only).

                                            property "x-attribsPrefix"

                                            'x-attribsPrefix'?: Record<string, string>;
                                            • Element attribute namespace-related prefixes (parse5 only).

                                            property attribs

                                            attribs: { [name: string]: string };

                                              property attributes

                                              readonly attributes: Attribute[];

                                                property name

                                                name: string;

                                                  property namespace

                                                  namespace?: string;
                                                  • Element namespace (parse5 only).

                                                  property nodeType

                                                  readonly nodeType: number;

                                                    property sourceCodeLocation

                                                    sourceCodeLocation?: TagSourceCodeLocation;
                                                    • parse5 source code location info, with start & end tags.

                                                      Available if parsing with parse5 and location info is enabled.

                                                    property tagName

                                                    tagName: string;
                                                    • Same as name. [DOM spec](https://dom.spec.whatwg.org)-compatible alias.

                                                    property type

                                                    type: any;

                                                      class Node

                                                      abstract class Node {}
                                                      • This object will be used as the prototype for Nodes when creating a DOM-Level-1-compliant structure.

                                                      property endIndex

                                                      endIndex: number;
                                                      • The end index of the node. Requires withEndIndices on the handler to be `true.

                                                      property next

                                                      next: ChildNode;
                                                      • Next sibling

                                                      property nextSibling

                                                      nextSibling: ChildNode;
                                                      • Same as next. [DOM spec](https://dom.spec.whatwg.org)-compatible alias.

                                                      property nodeType

                                                      abstract readonly nodeType: number;
                                                      • [DOM spec](https://dom.spec.whatwg.org/#dom-node-nodetype)-compatible node .

                                                      property parent

                                                      parent: ParentNode;
                                                      • Parent of the node

                                                      property parentNode

                                                      parentNode: ParentNode;
                                                      • Same as parent. [DOM spec](https://dom.spec.whatwg.org)-compatible alias.

                                                      property prev

                                                      prev: ChildNode;
                                                      • Previous sibling

                                                      property previousSibling

                                                      previousSibling: ChildNode;
                                                      • Same as prev. [DOM spec](https://dom.spec.whatwg.org)-compatible alias.

                                                      property sourceCodeLocation

                                                      sourceCodeLocation?: SourceCodeLocation;
                                                      • parse5 source code location info.

                                                        Available if parsing with parse5 and location info is enabled.

                                                      property startIndex

                                                      startIndex: number;
                                                      • The start index of the node. Requires withStartIndices on the handler to be `true.

                                                      property type

                                                      abstract readonly type: ElementType;
                                                      • The type of the node.

                                                      method cloneNode

                                                      cloneNode: <T extends Node>(this: T, recursive?: boolean) => T;
                                                      • Clone this node, and optionally its children.

                                                        Parameter recursive

                                                        Clone child nodes as well.

                                                        Returns

                                                        A clone of the node.

                                                      class NodeWithChildren

                                                      abstract class NodeWithChildren extends Node {}
                                                      • A node that can have children.

                                                      constructor

                                                      constructor(children: ChildNode[]);
                                                      • Parameter children

                                                        Children of the node. Only certain node types can have children.

                                                      property childNodes

                                                      childNodes: ChildNode[];
                                                      • Same as children. [DOM spec](https://dom.spec.whatwg.org)-compatible alias.

                                                      property children

                                                      children: ChildNode[];

                                                        property firstChild

                                                        readonly firstChild: ChildNode;
                                                        • First child of the node.

                                                        property lastChild

                                                        readonly lastChild: ChildNode;
                                                        • Last child of the node.

                                                        class ProcessingInstruction

                                                        class ProcessingInstruction extends DataNode {}
                                                        • Processing instructions, including doc types.

                                                        constructor

                                                        constructor(name: string, data: string);

                                                          property "x-name"

                                                          'x-name'?: string;
                                                          • If this is a doctype, the document type name (parse5 only).

                                                          property "x-publicId"

                                                          'x-publicId'?: string;
                                                          • If this is a doctype, the document type public identifier (parse5 only).

                                                          property "x-systemId"

                                                          'x-systemId'?: string;
                                                          • If this is a doctype, the document type system identifier (parse5 only).

                                                          property name

                                                          name: string;

                                                            property nodeType

                                                            readonly nodeType: number;

                                                              property type

                                                              type: ElementType.Directive;

                                                                class Text

                                                                class Text extends DataNode {}
                                                                • Text within the document.

                                                                property nodeType

                                                                readonly nodeType: number;

                                                                  property type

                                                                  type: ElementType.Text;

                                                                    Interfaces

                                                                    interface DomHandlerOptions

                                                                    interface DomHandlerOptions {}
                                                                    • Configuration options for DomHandler.

                                                                    property withEndIndices

                                                                    withEndIndices?: boolean;
                                                                    • Add an endIndex property to nodes. When the parser is used in a non-streaming fashion, endIndex is an integer indicating the position of the end of the node in the document. false

                                                                    property withStartIndices

                                                                    withStartIndices?: boolean;
                                                                    • Add a startIndex property to nodes. When the parser is used in a non-streaming fashion, startIndex is an integer indicating the position of the start of the node in the document. false

                                                                    property xmlMode

                                                                    xmlMode?: boolean;
                                                                    • Treat the markup as XML. false

                                                                    Type Aliases

                                                                    type AnyNode

                                                                    type AnyNode = ParentNode | ChildNode;
                                                                    • Any node in the DOM tree.

                                                                    type ChildNode

                                                                    type ChildNode = Text | Comment | ProcessingInstruction | Element | CDATA | Document;
                                                                    • A node that can have a parent.

                                                                    type ParentNode

                                                                    type ParentNode = Document | Element | CDATA;
                                                                    • A node that can have children.

                                                                    Package Files (2)

                                                                    Dependencies (1)

                                                                    Dev Dependencies (12)

                                                                    Peer Dependencies (0)

                                                                    No peer dependencies.

                                                                    Badge

                                                                    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/domhandler.

                                                                    • Markdown
                                                                      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/domhandler)
                                                                    • HTML
                                                                      <a href="https://www.jsdocs.io/package/domhandler"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>