class Trees
Install
npm install class-trees
Using
import Tree from 'class-trees';
tree = new Tree('html', { body: 'htmlTagValue' });
tree.addChild('head', { body: '' });
tree.getKey(); // html
Documentation
Table of Contents
Tree
Class tree
Parameters
key
meta
parent
addChild
add to Node's children map a child
Parameters
key
meta
Examples
const tree =
Returns Tree
getKey
get Node's key
Examples
const tree = 'html';tree; // 'html'
Returns any
getMeta
get Node's meta
Examples
const tree = 'html' body: '' ;tree; // { body: '' }
Returns any
getParent
get Node's parent
Examples
const tree = 'html';const node = tree;node === tree; // true
Returns any
getChildren
get Node's children
Examples
const tree = 'html';const tree.addChild'head' 'head_meta';tree; // [{ key: 'head', meta: 'head_meta' }]
Returns Map<any, any>
removeChild
remove Node's children
Parameters
key
Examples
const tree = 'html';tree;tree; // truetree; // false
Returns boolean
hasChildren
check if Node has children
Examples
const tree = 'html';tree; // falsetree;tree; // true
Returns boolean
hasChild
check if Node has child by Key
Parameters
key
Examples
const tree = 'html';tree; // falsetree;tree; // true
Returns boolean
getChild
get Node's child by Key
Parameters
key
Examples
const tree = 'html';tree; // undefinedtree;tree; // 'head'
Returns any
getDeepChild
Get tree's deep child
Parameters
keys
Examples
const tree = 'html';const headNode = tree;const metaNode = headNode;metaNode === tree;headNode === tree;tree; // undefined
Returns any