Options
All
  • Public
  • Public/Protected
  • All
Menu

Class DocumentNode

A document node. Is a "root" node, so it cannot have a parent. DOM trees are not required to have a DocumentNode root, but it exists as a utility to make DOM processing easier.

Hierarchy

Index

Constructors

constructor

Properties

childNodes

childNodes: Node[] = []

Children of this node. Do not modify this directly, use NodeLogic or instance methods.

nextSibling

nextSibling: null | Node = null

Next sibling node, or null if none exists. Do not modify this directly, use NodeLogic or instance methods.

Readonly nodeData

nodeData: Record<PropertyKey, unknown> = {}

Extra DOM data associated with this node. This object prototypically inherits from the parent node's nodeData.

Readonly nodeTags

nodeTags: Set<string> = ...

Set of unique string tags applied to this node. These tags do not inherit and are unique to each instance. Meaning is tag-specific.

Readonly nodeType

nodeType: NodeType

Type of this node

parentNode

parentNode: null | NodeWithChildren = null

Parent of this node, or null if there is none. Do not modify this directly, use NodeLogic or instance methods.

prevSibling

prevSibling: null | Node = null

Previous sibling node, or null if none exists. Do not modify this directly, use NodeLogic or instance methods.

Accessors

firstChild

  • get firstChild(): null | Node
  • The first child node of this parent, or null if there are no children.

    Returns null | Node

firstChildTag

  • get firstChildTag(): null | TagNode

firstChildText

lastChild

  • get lastChild(): null | Node
  • The last child node of this parent, or null if there are no children.

    Returns null | Node

lastChildTag

  • get lastChildTag(): null | TagNode

lastChildText

nextSiblingTag

  • get nextSiblingTag(): null | TagNode
  • The closest following sibling that is a TagNode, or null if none exists.

    Returns null | TagNode

nextSiblingText

  • get nextSiblingText(): null | TextNode

prevSiblingTag

  • get prevSiblingTag(): null | TagNode
  • The closest previous sibling that is a TagNode, or null if none exists.

    Returns null | TagNode

prevSiblingText

  • get prevSiblingText(): null | TextNode

Methods

appendChild

  • appendChild(child: Node): void

appendChildren

  • appendChildren(children: Node[]): void

appendSibling

  • appendSibling(node: Node): void

clear

  • clear(): void

clone

createDomFromChildren

findChildNode

  • findChildNode(matcher: (node: Node) => boolean, deep?: boolean): null | Node
  • Finds the first child node that matches a condition. Returns null if no match found.

    Parameters

    • matcher: (node: Node) => boolean

      Callback to test condition

        • (node: Node): boolean
        • Parameters

          Returns boolean

    • deep: boolean = true

      If true, children of child nodes will also be searched.

    Returns null | Node

    First matching child, or null

findChildNodeByNodeType

findChildNodes

  • findChildNodes(matcher: (node: Node) => boolean, deep?: boolean): Node[]
  • Finds all child nodes that match a condition. Returns an empty array if no matches found.

    Parameters

    • matcher: (node: Node) => boolean

      Callback to test condition

        • (node: Node): boolean
        • Parameters

          Returns boolean

    • deep: boolean = true

      If true, children of child nodes will also be searched.

    Returns Node[]

    Array of all Nodes that match condition

findChildNodesByNodeType

findChildTag

  • findChildTag(matcher: (tag: TagNode) => boolean, deep?: boolean): null | TagNode
  • Finds the first child TagNode that matches a condition. Returns null if no match found.

    Parameters

    • matcher: (tag: TagNode) => boolean

      Callback to test condition

    • deep: boolean = true

      If true, children of child nodes will also be searched.

    Returns null | TagNode

    First TagNode that matches the condition, or null.

findChildTagByTagName

  • findChildTagByTagName(tagName: "m-fragment", deep?: boolean): null | MFragmentNode
  • findChildTagByTagName(tagName: "m-content", deep?: boolean): null | MContentNode
  • findChildTagByTagName(tagName: "m-slot", deep?: boolean): null | MSlotNode
  • findChildTagByTagName(tagName: "m-var", deep?: boolean): null | MVarNode
  • findChildTagByTagName(tagName: "m-scope", deep?: boolean): null | MScopeNode
  • findChildTagByTagName(tagName: "m-import", deep?: boolean): null | MImportNode
  • findChildTagByTagName(tagName: "m-if", deep?: boolean): null | MIfNode
  • findChildTagByTagName(tagName: "m-for", deep?: boolean): null | MForNode
  • findChildTagByTagName(tagName: "m-data", deep?: boolean): null | MDataNode
  • findChildTagByTagName(tagName: "style", deep?: boolean): null | StyleNode
  • findChildTagByTagName(tagName: "script", deep?: boolean): null | ScriptNode
  • findChildTagByTagName(tagName: "a", deep?: boolean): null | AnchorNode
  • findChildTagByTagName(tagName: "m-whitespace", deep?: boolean): null | MWhitespaceNode
  • findChildTagByTagName(tagName: string, deep?: boolean): null | TagNode

findChildTags

  • findChildTags(matcher: (tag: TagNode) => boolean, deep?: boolean): TagNode[]
  • Finds all child TagNodes that match a condition. Returns an empty array if no matches found.

    Parameters

    • matcher: (tag: TagNode) => boolean

      Callback to test condition

    • deep: boolean = true

      If true, children of child nodes will also be searched.

    Returns TagNode[]

    Array of all TagNodes that match condition

findChildTagsByTagName

  • findChildTagsByTagName(tagName: "m-fragment", deep?: boolean): MFragmentNode[]
  • findChildTagsByTagName(tagName: "m-content", deep?: boolean): MContentNode[]
  • findChildTagsByTagName(tagName: "m-slot", deep?: boolean): MSlotNode[]
  • findChildTagsByTagName(tagName: "m-var", deep?: boolean): MVarNode[]
  • findChildTagsByTagName(tagName: "m-scope", deep?: boolean): MScopeNode[]
  • findChildTagsByTagName(tagName: "m-import", deep?: boolean): MImportNode[]
  • findChildTagsByTagName(tagName: "m-if", deep?: boolean): MIfNode[]
  • findChildTagsByTagName(tagName: "m-for", deep?: boolean): MForNode[]
  • findChildTagsByTagName(tagName: "m-data", deep?: boolean): MDataNode[]
  • findChildTagsByTagName(tagName: "style", deep?: boolean): StyleNode[]
  • findChildTagsByTagName(tagName: "script", deep?: boolean): ScriptNode[]
  • findChildTagsByTagName(tagName: "a", deep?: boolean): AnchorNode[]
  • findChildTagsByTagName(tagName: "m-whitespace", deep?: boolean): MWhitespaceNode[]
  • findChildTagsByTagName(tagName: string, deep?: boolean): TagNode[]

findNext

  • findNext(matcher: (node: Node) => boolean, deep?: boolean): null | Node
  • Finds the next node that matches a callback. The next node is defined as the first matching child, sibling, or sibling's child node starting from this node. This only checks child and sibling nodes, it will not move further up the DOM tree. To check only sibling nodes, set node to false.

    Parameters

    • matcher: (node: Node) => boolean

      Callback to test nodes

        • (node: Node): boolean
        • Parameters

          Returns boolean

    • deep: boolean = true

      If true or not specified, then child nodes will be checked

    Returns null | Node

    The first matching node, or null if none found.

getChildTags

prependChild

  • prependChild(child: Node): void

prependChildren

  • prependChildren(children: Node[]): void

prependSibling

  • prependSibling(node: Node): void

removeSelf

  • removeSelf(keepChildren?: boolean): void
  • Removes this node from the DOM, but optionally preserves children. If keepChildren is true, then child nodes will be reattached to the DOM in place of this node. Effectively "promotes" child nodes.

    Parameters

    • keepChildren: boolean = false

      If true, child nodes will be kept.

    Returns void

replaceSelf

  • replaceSelf(nodes: Node[]): void
  • Remove this node and all children from the DOM, and insert one or more nodes in its place

    Parameters

    • nodes: Node[]

      Nodes to insert in replacement. Can be empty.

    Returns void

setRootScope

  • setRootScope(rootScope: null | Record<PropertyKey, unknown>): void
  • Set the root scope of this DOM. The root scope is inherited by all nodes, but is read-only.

    Parameters

    • rootScope: null | Record<PropertyKey, unknown>

      Scope object to inherit from

    Returns void

toHtml

  • toHtml(): string

Static isDocumentNode

Static isNodeWithChildren

Generated using TypeDoc