domhandler

  • Version 4.3.0
  • Published
  • 43.4 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 recursive

    Clone child nodes as well.

    Returns

    A clone of the node.

function hasChildren

hasChildren: (node: Node) => node is NodeWithChildren;
  • Parameter node

    Node to check.

    Returns

    true if the node is a NodeWithChildren (has children), false otherwise.

function isCDATA

isCDATA: (node: Node) => node is NodeWithChildren;
  • Parameter node

    Node to check.

    Returns

    true if the node has the type CDATA, false otherwise.

function isComment

isComment: (node: Node) => node is DataNode;
  • Parameter node

    Node to check.

    Returns

    true if the node has the type Comment, false otherwise.

function isDirective

isDirective: (node: Node) => node is ProcessingInstruction;
  • Parameter node

    Node to check.

    Returns

    true if the node has the type ProcessingInstruction, false otherwise.

function isDocument

isDocument: (node: Node) => node is Document;
  • Parameter node

    Node to check.

    Returns

    true if the node has the type ProcessingInstruction, false otherwise.

function isTag

isTag: (node: Node) => node is Element;
  • Parameter node

    Node to check.

    Returns

    true if the node is a Element, false otherwise.

function isText

isText: (node: Node) => node is Text;
  • Parameter node

    Node to check.

    Returns

    true if the node has the type Text, false otherwise.

Classes

class Comment

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

constructor

constructor(data: string);

    class DataNode

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

    constructor

    constructor(type: any, data: string);
    • Parameter type

      The type of the node

      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.

      constructor

      constructor(children: Node[]);

        property "x-mode"

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

        class DomHandler

        class DomHandler {}

          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: Node[];
          • 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: NodeWithChildren[];
          • Stack of open tags.

          method addNode

          protected addNode: (node: Node) => 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?: Node[],
                                      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.

                                      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 tagName

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

                                            class Node

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

                                            constructor

                                            constructor(type: any);
                                            • Parameter type

                                              The type of the node.

                                            property endIndex

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

                                            property next

                                            next: Node;
                                            • Next sibling

                                            property nextSibling

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

                                            property nodeType

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

                                            property parent

                                            parent: NodeWithChildren;
                                            • Parent of the node

                                            property parentNode

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

                                            property prev

                                            prev: Node;
                                            • Previous sibling

                                            property previousSibling

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

                                            property sourceCodeLocation

                                            sourceCodeLocation?: {
                                            startOffset: number;
                                            endOffset: number;
                                            startLine: number;
                                            endLine: number;
                                            startColumn: number;
                                            endColumn: number;
                                            };
                                            • 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

                                            type: any;

                                              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

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

                                              constructor

                                              constructor(type: any, children: Node[]);
                                              • Parameter type

                                                Type of the node.

                                                Parameter children

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

                                              property childNodes

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

                                              property children

                                              children: Node[];

                                                property firstChild

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

                                                property lastChild

                                                readonly lastChild: Node;
                                                • 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;

                                                    class Text

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

                                                    constructor

                                                    constructor(data: string);

                                                      Interfaces

                                                      interface DomHandlerOptions

                                                      interface DomHandlerOptions {}

                                                        property normalizeWhitespace

                                                        normalizeWhitespace?: boolean;
                                                        • Replace all whitespace with single spaces.

                                                          **Note:** Enabling this might break your markup.

                                                          false

                                                          Deprecated

                                                        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

                                                        Package Files (2)

                                                        Dependencies (1)

                                                        Dev Dependencies (11)

                                                        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>