Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Node

A node in the hierarchy

Hierarchy

  • Node

Implemented by

Index

Properties

name

name: string

A name for this node

Methods

addChild

  • addChild(child: Node, position?: number): Node
  • Add a new child to this node, optionally specifying the index

    Parameters

    • child: Node

      The new child node

    • Optional position: number

      The index where the new node should be inserted (optional)

    Returns Node

    the inserted node

findChild

  • findChild(child: Node): number
  • Find the specified node and return the index

    throws

    NodeNotFoundError

    Parameters

    • child: Node

      the node to search for

    Returns number

    the index or null, if no node was found

getChildByName

  • getChildByName(name: string): Node
  • Get a child based on the given name

    Parameters

    • name: string

      the name of the child node

    Returns Node

    the found node or null

getChildren

  • getChildren(): Node[]
  • Get all children of this node, if any.

    Returns Node[]

    the children of this node. If the node doesn't contain any children, an empty array is returned

getData

  • getData(key: string): any

getLevel

  • getLevel(): number
  • The distance of this node from the root node.

    If it IS the root node, it's 0. If it's parent is the root node it's 1 and so on.

    Returns number

getNodeByPath

  • getNodeByPath(path: string, pathSeparator?: string): Bluebird<Node>
  • Get a node by specifying its path. This can be an absolute path, starting with the path separator or a relative path starting from the current node.

    Parameters

    • path: string

      The path string

    • Optional pathSeparator: string

      an optional path separator

    Returns Bluebird<Node>

getNodeByPathArray

  • getNodeByPathArray(pathNodes: Array<string>, absolute: boolean): Bluebird<Node>
  • Retrieve a node by specifying all node names in between

    Parameters

    • pathNodes: Array<string>

      an array of node names forming the path

    • absolute: boolean

      should the path be treated absolute? (if not, relative from the current node is used)

    Returns Bluebird<Node>

getParent

  • Return the parent node of this node

    Returns Node

    the parent node or null, if no parent node exists

getPath

  • getPath(pathSeparator?: string): Bluebird<string>
  • Return an absolute path to this node starting with the pathSeparator.

    Parameters

    • Optional pathSeparator: string

      The optional path separator [/]

    Returns Bluebird<string>

getPathNodes

  • getPathNodes(): Bluebird<Array<Node>>
  • Get all nodes in the direct path from root for this node

    Returns Bluebird<Array<Node>>

getRoot

isRoot

  • isRoot(): boolean
  • Return, wether this node is the root node (has now parent)

    Returns boolean

    true, if this node is the root node

removeChild

  • removeChild(child: Node | number): void
  • Remove a child by specifying the node or index that should be removed.

    throws

    NodeNotFoundError

    Parameters

    • child: Node | number

      The child node or index to be removed

    Returns void

setData

  • setData(key: string, value: any): Node
  • Set arbitrary data to the node

    Parameters

    • key: string

      A key

    • value: any

      The value

    Returns Node

    A reference back to the node

setParent

  • setParent(node: Node): void
  • Set the parent of this node

    Parameters

    Returns void

toJSON

  • toJSON(): string
  • Return a JSON representation of the node

    Returns string

walk

  • walk(direction: Direction.up | Direction.down | Direction.left | Direction.right | Direction.rootUp | (Direction.up | Direction.down | Direction.left | Direction.right | Direction.rootUp)[], action: ActionFunction): Bluebird<void>
  • Walk the tree in the given direction and call the action function on each node you encounter.

    The direction can also be an array of directions. In this case, the next direction will be called, if there's no node left in the first direction.

    For example, specify [Direction.left, Direction.right] will walk through the children in the left direction. After the first child is encountered, the parent node is walked and so on.

    throws

    InvalidDirectionError

    throws

    NodeNotFoundError

    Parameters

    • direction: Direction.up | Direction.down | Direction.left | Direction.right | Direction.rootUp | (Direction.up | Direction.down | Direction.left | Direction.right | Direction.rootUp)[]
    • action: ActionFunction

    Returns Bluebird<void>

Generated using TypeDoc