Skip to content

All Methods

Anton Demushkin edited this page Aug 5, 2019 · 2 revisions

I'm trying to keep all functions good-documented, but if you're here you definitely need more info about the functions with examples etc.

P.S. Don't forget to star this library. It stimulates me to support the library! ⭐️

P.P.S. If you feel like you could help me with the library (writing docs, adding new features, testing, fixing bugs or anything else) - you are welcome! If you need any info or have a question, just email me at fremail@yandex.com

Let's call the Model as Model and the instance of that model as record.

Create root node

Create a root node from existing or new record.

async Model.createRoot(record, options = {}): record

Fetch root node

Get root node for selected rootId.

async Model.fetchRoot(rootId = 1, options = {}): record|false

Fetch tree

Get all tree nodes.

async Model.fetchTree(depth = 0, rootId = 1, options = {}): [record]|false

Fetch roots

Get all root nodes.

async Model.fetchRoots(options = {}): [record]|false

Test if node has previous sibling

async record.hasPrevSibling(options = {}): bool

Test if node has next sibling

async record.hasNextSibling(options = {}): bool

Test if node has children

record.hasChildren(): bool

Test if node has parent

record.hasParent(): bool

Get previous sibling

Get previous sibling of the node.

async record.getPrevSibling(options = {}): record|false

Get next sibling

Get next sibling of the node.

async record.getNextSibling(options = {}): record|false

Get siblings

Get all siblings of the node including current node or not.

async record.getSiblings(withCurrentNode = false, options = {}): [record]

Get first child

Get first child of the node.

async record.getFirstChild(options = {}): record|false

Get last child

Get last child of the node.

async record.getLastChild(options = {}): record|false

Get children

Get all children of the node.

async record.getChildren(options = {}): [record]|false

Get descendants

Get all or limited by depth descendants for the node.

async record.getDescendants(depth = 0, options = {}): [record]|false

Get parent

async record.getParent(options = {}): record|false

Get ancestors

Get all or limited by depth ancestors for the node.

async record.getAncestors(depth = 0, options = {}): [record]|false

Get number of children

Get number of direct children nodes (only from one next level).

async record.getNumberChildren(options = {}): number

Get number of descendants

Get number of descendants (children and their children).

record.getNumberDescendants(): number

Insert as parent

Insert the node (from which you call the function) as parent of destination node.

async record.insertAsParentOf(destNode, options = {})

Insert as previous sibling

Insert the node (from which you call the function) as previous sibling of destination node.

async record.insertAsPrevSiblingOf(destNode, options = {})

Insert as next sibling

Insert the node (from which you call the function) as next sibling of destination node.

async record.insertAsNextSiblingOf(destNode, options = {})

Insert as first child

Insert the node (from which you call the function) as first child of destination node.

async record.insertAsFirstChildOf(destNode, options = {})

Insert as last child

Insert the node (from which you call the function) as last child of destination node.

async record.insertAsLastChildOf(destNode, options = {})

Move as previous sibling

Move the node (from which you call the function) as previous sibling of destination node.

async record.moveAsPrevSiblingOf(destNode, options = {})

Move as next sibling

Move the node (from which you call the function) as next sibling of destination node.

async record.moveAsNextSiblingOf(destNode, options = {})

Move as first child

Move the node (from which you call the function) as first child of destination node.

async record.moveAsFirstChildOf(destNode, options = {})

Move as last child

Move the node (from which you call the function) as last child of destination node.

async record.moveAsLastChildOf(destNode, options = {})

Make node root

Make this node a root node and move all its descendants to the new tree. Only for multiple-root trees.

async record.makeRoot(options = {})
// deprecated from v. 1.2.0:
async record.makeRoot(newRootId, options = {})

Add child

Add the node as last child of the supplied node (new parent)

async record.addChild(parentNode, options = {})

Test if node is leaf

Check if the node is leaf (doesn't have children)

record.isLeaf(): bool

Test if node is root

Check if the node is root

record.isRoot(): bool

Check if node is equal

Check if the node is equal to the supplied node

record.isEqualTo(node): bool

Check if node is descendant

Check if the node is descendant of the supplied node

record.isDescendantOf(node): bool

Check if node is descendant or sibling

Check if the node is descendant or sibling to supplied node

record.isDescendantOfOrEqualTo(node): bool

Check if node is ancestor

Check if the node is ancestor of the supplied node

record.isAncestorOf(node): bool

Check if node is valid

Check if the node is valid. It checks the supplied node, or the source node otherwise.

record.isValidNode(node = null): bool

Detach node from tree

Detach the node from the tree by invalidating its left and right values.

record.detach()

Delete node

Delete the node with all its children.

async record.delete(options = {})