-
Notifications
You must be signed in to change notification settings - Fork 10
All Methods
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 asrecord
.
Create a root node from existing or new record.
async Model.createRoot(record, options = {}): record
Get root node for selected rootId
.
async Model.fetchRoot(rootId = 1, options = {}): record|false
Get all tree nodes.
async Model.fetchTree(depth = 0, rootId = 1, options = {}): [record]|false
Get all root nodes.
async Model.fetchRoots(options = {}): [record]|false
async record.hasPrevSibling(options = {}): bool
async record.hasNextSibling(options = {}): bool
record.hasChildren(): bool
record.hasParent(): bool
Get previous sibling of the node.
async record.getPrevSibling(options = {}): record|false
Get next sibling of the node.
async record.getNextSibling(options = {}): record|false
Get all siblings of the node including current node or not.
async record.getSiblings(withCurrentNode = false, options = {}): [record]
Get first child of the node.
async record.getFirstChild(options = {}): record|false
Get last child of the node.
async record.getLastChild(options = {}): record|false
Get all children of the node.
async record.getChildren(options = {}): [record]|false
Get all or limited by depth descendants for the node.
async record.getDescendants(depth = 0, options = {}): [record]|false
async record.getParent(options = {}): record|false
Get all or limited by depth ancestors for the node.
async record.getAncestors(depth = 0, options = {}): [record]|false
Get number of direct children nodes (only from one next level).
async record.getNumberChildren(options = {}): number
Get number of descendants (children and their children).
record.getNumberDescendants(): number
Insert the node (from which you call the function) as parent of destination node.
async record.insertAsParentOf(destNode, options = {})
Insert the node (from which you call the function) as previous sibling of destination node.
async record.insertAsPrevSiblingOf(destNode, options = {})
Insert the node (from which you call the function) as next sibling of destination node.
async record.insertAsNextSiblingOf(destNode, options = {})
Insert the node (from which you call the function) as first child of destination node.
async record.insertAsFirstChildOf(destNode, options = {})
Insert the node (from which you call the function) as last child of destination node.
async record.insertAsLastChildOf(destNode, options = {})
Move the node (from which you call the function) as previous sibling of destination node.
async record.moveAsPrevSiblingOf(destNode, options = {})
Move the node (from which you call the function) as next sibling of destination node.
async record.moveAsNextSiblingOf(destNode, options = {})
Move the node (from which you call the function) as first child of destination node.
async record.moveAsFirstChildOf(destNode, options = {})
Move the node (from which you call the function) as last child of destination node.
async record.moveAsLastChildOf(destNode, options = {})
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 the node as last child of the supplied node (new parent)
async record.addChild(parentNode, options = {})
Check if the node is leaf (doesn't have children)
record.isLeaf(): bool
Check if the node is root
record.isRoot(): bool
Check if the node is equal to the supplied node
record.isEqualTo(node): bool
Check if the node is descendant of the supplied node
record.isDescendantOf(node): bool
Check if the node is descendant or sibling to supplied node
record.isDescendantOfOrEqualTo(node): bool
Check if the node is ancestor of the supplied node
record.isAncestorOf(node): bool
Check if the node is valid. It checks the supplied node, or the source node otherwise.
record.isValidNode(node = null): bool
Detach the node from the tree by invalidating its left and right values.
record.detach()
Delete the node with all its children.
async record.delete(options = {})