diff --git a/src/node.js b/src/node.js index d41c9d3..8f9dad0 100644 --- a/src/node.js +++ b/src/node.js @@ -12,21 +12,11 @@ class Node { this.children = this.children || []; } - // Gets the parent node. - // @return {object} The parent node. - getParent() { - return this.parent; - } // Gets the child nodes. - // @return {array} An array of child nodes. - getChildNodes() { + // @return {array} Returns an array of child nodes. + getChildren() { return this.children; } - // Checks if this node has children. - // @return {boolean} true if the node has child nodes; otherwise, false. - hasChildNodes() { - return this.children.length > 0; - } // Gets the first child node. // @return {object} Returns the first child node on success, null otherwise. getFirstChild() { @@ -48,6 +38,11 @@ class Node { } return node; } + // Gets the parent node. + // @return {object} Returns the parent node. + getParent() { + return this.parent; + } // Gets previous sibling node. // @return {object} Returns the previous sibling node on success, null otherwise. getPreviousSibling() { @@ -60,6 +55,11 @@ class Node { } return node; } + // Checks whether this node has children. + // @return {boolean} Returns true if the node has children, false otherwise. + hasChildren() { + return this.children.length > 0; + } } // IE8 compatibility output diff --git a/test/index.js b/test/index.js index e4896bb..d59f2da 100644 --- a/test/index.js +++ b/test/index.js @@ -614,15 +614,15 @@ test('[node] getChildren/getParent/getFirstChild/getPreviousSibling/getNextSibli const alpha = _.find(nodes, node => node.id === 'alpha'); const bravo = _.find(nodes, node => node.id === 'bravo'); - // hasChildNodes - t.same(root.hasChildNodes(), true); - t.same(alpha.hasChildNodes(), false); - t.same(bravo.hasChildNodes(), true); - - // getChildNodes - t.same(root.getChildNodes().length, 2); - t.same(root.getChildNodes()[0], alpha); - t.same(root.getChildNodes()[1], bravo); + // hasChildren + t.same(root.hasChildren(), true); + t.same(alpha.hasChildren(), false); + t.same(bravo.hasChildren(), true); + + // getChildren + t.same(root.getChildren().length, 2); + t.same(root.getChildren()[0], alpha); + t.same(root.getChildren()[1], bravo); // getParent t.same(alpha.getParent(), root);