dom5

  • Version 3.0.1
  • Published
  • 85.6 kB
  • 3 dependencies
  • BSD-3-Clause license

Install

npm i dom5
yarn add dom5
pnpm add dom5

Overview

Utilities for working with parse5 ASTs

Index

Variables

variable constructors

const constructors: {
text: (value: string) => any;
comment: (comment: string) => any;
element: (tagName: string, namespace?: string | undefined) => any;
fragment: () => Node;
};

    variable predicates

    const predicates: {
    hasClass: (name: string) => Predicate;
    hasAttr: (attr: string) => Predicate;
    hasAttrValue: (attr: string, value: string) => Predicate;
    hasMatchingTagName: (regex: RegExp) => Predicate;
    hasSpaceSeparatedAttrValue: typeof hasSpaceSeparatedAttrValue;
    hasTagName: (name: string) => Predicate;
    hasTextValue: (value: string) => Predicate;
    AND: (...predicates: Predicate[]) => Predicate;
    OR: (...predicates: Predicate[]) => Predicate;
    NOT: (predicateFn: Predicate) => Predicate;
    parentMatches: (predicateFn: Predicate) => Predicate;
    };

      Functions

      function append

      append: (parent: any, newNode: any) => void;

        function childNodesIncludeTemplate

        childNodesIncludeTemplate: (node: any) => Node[] | undefined;

          function cloneNode

          cloneNode: (node: any) => any;

            function defaultChildNodes

            defaultChildNodes: (node: any) => Node[] | undefined;

              function getAttribute

              getAttribute: (element: any, name: string) => string | null;
              • Returns

                The string value of attribute name, or null.

              function getAttributeIndex

              getAttributeIndex: (element: any, name: string) => number;

                function getTextContent

                getTextContent: (node: any) => string;
                • Return the text value of a node or element

                  Equivalent to node.textContent in the browser

                function hasAttribute

                hasAttribute: (element: any, name: string) => boolean;
                • Returns

                  true iff [element] has the attribute [name], false otherwise.

                function hasSpaceSeparatedAttrValue

                hasSpaceSeparatedAttrValue: (name: string, value: string) => Predicate;

                  function insertAfter

                  insertAfter: (parent: any, target: any, newNode: any) => void;

                    function insertBefore

                    insertBefore: (parent: any, target: any, newNode: any) => void;

                      function isCommentNode

                      isCommentNode: (node: any) => boolean;

                        function isDocument

                        isDocument: (node: any) => boolean;

                          function isDocumentFragment

                          isDocumentFragment: (node: any) => boolean;

                            function isElement

                            isElement: (node: any) => boolean;

                              function isTextNode

                              isTextNode: (node: any) => boolean;

                                function nodeWalk

                                nodeWalk: (
                                node: any,
                                predicate: Predicate,
                                getChildNodes?: GetChildNodes
                                ) => Node | null;
                                • Walk the tree down from node, applying the predicate function. Return the first node that matches the given predicate.

                                  Returns

                                  null if no node matches, parse5 node object if a node matches.

                                function nodeWalkAll

                                nodeWalkAll: (
                                node: any,
                                predicate: Predicate,
                                matches?: Node[],
                                getChildNodes?: GetChildNodes
                                ) => Node[];
                                • Walk the tree down from node, applying the predicate function. All nodes matching the predicate function from node to leaves will be returned.

                                function nodeWalkAllPrior

                                nodeWalkAllPrior: (node: any, predicate: Predicate, matches?: Node[]) => Node[];
                                • Equivalent to nodeWalkAll, but only returns nodes that are either ancestors or earlier cousins/siblings in the document.

                                  Nodes are returned in reverse document order, starting from node.

                                function nodeWalkAncestors

                                nodeWalkAncestors: (node: any, predicate: Predicate) => Node | undefined;
                                • Walk the tree up from the parent of node, to its grandparent and so on to the root of the tree. Return the first ancestor that matches the given predicate.

                                function nodeWalkPrior

                                nodeWalkPrior: (node: any, predicate: Predicate) => Node | undefined;
                                • Equivalent to nodeWalk, but only returns nodes that are either ancestors or earlier siblings in the document.

                                  Nodes are searched in reverse document order, starting from the sibling prior to node.

                                function normalize

                                normalize: (node: any) => void;
                                • Normalize the text inside an element

                                  Equivalent to element.normalize() in the browser See https://developer.mozilla.org/en-US/docs/Web/API/Node/normalize

                                function query

                                query: (
                                node: any,
                                predicate: Predicate,
                                getChildNodes?: GetChildNodes
                                ) => Node | null;
                                • Equivalent to nodeWalk, but only matches elements

                                function queryAll

                                queryAll: (
                                node: any,
                                predicate: Predicate,
                                matches?: Node[],
                                getChildNodes?: GetChildNodes
                                ) => Node[];
                                • Equivalent to nodeWalkAll, but only matches elements

                                function remove

                                remove: (node: any) => void;

                                  function removeAttribute

                                  removeAttribute: (element: any, name: string) => void;

                                    function removeFakeRootElements

                                    removeFakeRootElements: (ast: any) => void;
                                    • When parse5 parses an HTML document with parse, it injects missing root elements (html, head and body) if they are missing. This function removes these from the AST if they have no location info, so it requires that the parse5.parse be used with the locationInfo option of true.

                                    function removeNodeSaveChildren

                                    removeNodeSaveChildren: (node: any) => void;
                                    • Removes a node and places its children in its place. If the node has no parent, the operation is impossible and no action takes place.

                                    function replace

                                    replace: (oldNode: any, newNode: any) => void;

                                      function setAttribute

                                      setAttribute: (element: any, name: string, value: string) => void;

                                        function setTextContent

                                        setTextContent: (node: any, value: string) => void;
                                        • Set the text value of a node or element

                                          Equivalent to node.textContent = value in the browser

                                        function treeMap

                                        treeMap: <U>(node: any, mapfn: (node: any) => U[]) => U[];
                                        • Applies mapfn to node and the tree below node, returning a flattened list of results.

                                        Type Aliases

                                        type GetChildNodes

                                        type GetChildNodes = (node: Node) => Node[] | undefined;

                                          type Predicate

                                          type Predicate = (node: Node) => boolean;

                                            Package Files (5)

                                            Dependencies (3)

                                            Dev Dependencies (8)

                                            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/dom5.

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