Comparing version 0.1.1 to 0.1.4
{ | ||
"name": "treenode", | ||
"main": "dist/treenode.min.js", | ||
"main": "dist/treenode.js", | ||
"ignore": [ | ||
"test", | ||
"source", | ||
"test", | ||
"node_modules", | ||
@@ -8,0 +8,0 @@ ".bowerrc", |
@@ -1,108 +0,122 @@ | ||
/** | ||
* A simple tree data structure in JS. | ||
* | ||
*/ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var TreeNode = (function () { | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(["exports"], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports); | ||
global.treenode = mod.exports; | ||
} | ||
})(this, function (exports) { | ||
/** | ||
* Constructor. | ||
* A simple tree data structure in JS. | ||
* | ||
* @param data | ||
* @param parent | ||
* @returns {TreeNode} | ||
* @constructor | ||
*/ | ||
"use strict"; | ||
function TreeNode(data, parent) { | ||
_classCallCheck(this, TreeNode); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
this.data = data; | ||
this.parent = parent; | ||
this.children = []; | ||
return this; | ||
} | ||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | ||
_createClass(TreeNode, [{ | ||
key: "addChild", | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var TreeNode = (function () { | ||
/** | ||
* Add child. Returns the newly created child. | ||
* Constructor. | ||
* | ||
* @param data | ||
* @param parent | ||
* @returns {TreeNode} | ||
* @constructor | ||
*/ | ||
value: function addChild(data) { | ||
var child = new TreeNode(data, this); | ||
this.children.push(child); | ||
return child; | ||
function TreeNode(data, parent) { | ||
_classCallCheck(this, TreeNode); | ||
this.data = data; | ||
this.parent = parent; | ||
this.children = []; | ||
return this; | ||
} | ||
}, { | ||
key: "find", | ||
/** | ||
* Given a data object, returns the tree node containing it, if any. If not found, returns null. | ||
* @param data | ||
* @returns {TreeNode} || null | ||
*/ | ||
value: function find(data) { | ||
if (data === this.data) { | ||
return this; | ||
_createClass(TreeNode, [{ | ||
key: "addChild", | ||
/** | ||
* Add child. Returns the newly created child. | ||
* @param data | ||
* @returns {TreeNode} | ||
*/ | ||
value: function addChild(data) { | ||
var child = new TreeNode(data, this); | ||
this.children.push(child); | ||
return child; | ||
} | ||
}, { | ||
key: "find", | ||
for (var i = 0, _length = this.children.length, target = null; i < _length; i++) { | ||
target = this.children[i].find(data); | ||
if (target) { | ||
return target; | ||
/** | ||
* Given a data object, returns the tree node containing it, if any. If not found, returns null. | ||
* @param data | ||
* @returns {TreeNode} || null | ||
*/ | ||
value: function find(data) { | ||
if (data === this.data) { | ||
return this; | ||
} | ||
} | ||
return null; | ||
} | ||
}, { | ||
key: "leaves", | ||
for (var i = 0, _length = this.children.length, target = null; i < _length; i++) { | ||
target = this.children[i].find(data); | ||
if (target) { | ||
return target; | ||
} | ||
} | ||
/** | ||
* Returns an array of all leaf nodes below this one. | ||
* @returns {Array} | ||
*/ | ||
value: function leaves() { | ||
if (this.children.length === 0) { | ||
// this is a leaf | ||
return [this]; | ||
return null; | ||
} | ||
}, { | ||
key: "leaves", | ||
// if not a leaf, return all children's leaves recursively | ||
var leaves = []; | ||
for (var i = 0, _length2 = this.children.length; i < _length2; i++) { | ||
leaves.push.apply(leaves, this.children[i].leaves()); | ||
/** | ||
* Returns an array of all leaf nodes below this one. | ||
* @returns {Array} | ||
*/ | ||
value: function leaves() { | ||
if (this.children.length === 0) { | ||
// this is a leaf | ||
return [this]; | ||
} | ||
// if not a leaf, return all children's leaves recursively | ||
var leaves = []; | ||
for (var i = 0, _length2 = this.children.length; i < _length2; i++) { | ||
leaves.push.apply(leaves, this.children[i].leaves()); | ||
} | ||
return leaves; | ||
} | ||
return leaves; | ||
} | ||
}, { | ||
key: "root", | ||
}, { | ||
key: "root", | ||
/** | ||
* Returns the root node of this tree. | ||
* @returns {TreeNode} | ||
*/ | ||
value: function root() { | ||
if (!this.parent) { | ||
return this; | ||
/** | ||
* Returns the root node of this tree. | ||
* @returns {TreeNode} | ||
*/ | ||
value: function root() { | ||
if (!this.parent) { | ||
return this; | ||
} | ||
return this.parent.root(); | ||
} | ||
return this.parent.root(); | ||
} | ||
}]); | ||
}]); | ||
return TreeNode; | ||
})(); | ||
return TreeNode; | ||
})(); | ||
exports.TreeNode = TreeNode; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRyZWUtbm9kZS5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7OztJQUlhLFFBQVE7Ozs7Ozs7Ozs7QUFTTixhQVRGLFFBQVEsQ0FTTCxJQUFJLEVBQUUsTUFBTSxFQUFFOzhCQVRqQixRQUFROztBQVViLFlBQUksQ0FBQyxJQUFJLEdBQUcsSUFBSSxDQUFDO0FBQ2pCLFlBQUksQ0FBQyxNQUFNLEdBQUcsTUFBTSxDQUFDO0FBQ3JCLFlBQUksQ0FBQyx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AgKiBAcmV0dXJucyB7QXJyYXl9XG4gICAgICovXG4gICAgbGVhdmVzKCkge1xuICAgICAgICBpZiAodGhpcy5jaGlsZHJlbi5sZW5ndGggPT09IDApIHtcbiAgICAgICAgICAgIC8vIHRoaXMgaXMgYSBsZWFmXG4gICAgICAgICAgICByZXR1cm4gW3RoaXNdO1xuICAgICAgICB9XG5cbiAgICAgICAgLy8gaWYgbm90IGEgbGVhZiwgcmV0dXJuIGFsbCBjaGlsZHJlbidzIGxlYXZlcyByZWN1cnNpdmVseVxuICAgICAgICBsZXQgbGVhdmVzID0gW107XG4gICAgICAgIGZvciAobGV0IGkgPSAwLCBsZW5ndGggPSB0aGlzLmNoaWxkcmVuLmxlbmd0aDsgaSA8IGxlbmd0aDsgaSsrKSB7XG4gICAgICAgICAgICBsZWF2ZXMucHVzaC5hcHBseShsZWF2ZXMsIHRoaXMuY2hpbGRyZW5baV0ubGVhdmVzKCkpO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBsZWF2ZXM7XG4gICAgfVxuXG4gICAgLyoqXG4gICAgICogUmV0dXJucyB0aGUgcm9vdCBub2RlIG9mIHRoaXMgdHJlZS5cbiAgICAgKiBAcmV0dXJucyB7VHJlZU5vZGV9XG4gICAgICovXG4gICAgcm9vdCgpIHtcbiAgICAgICAgaWYgKCF0aGlzLnBhcmVudCkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIHRoaXMucGFyZW50LnJvb3QoKTtcbiAgICB9XG59Il0sInNvdXJjZVJvb3QiOiIvc291cmNlLyJ9 | ||
exports.TreeNode = TreeNode; | ||
}); | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRyZWVub2RlLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OztRQUlhLFFBQVE7Ozs7Ozs7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ic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0= |
@@ -1,1 +0,1 @@ | ||
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),TreeNode=function(){function e(t,r){return _classCallCheck(this,e),this.data=t,this.parent=r,this.children=[],this}return _createClass(e,[{key:"addChild",value:function(t){var r=new e(t,this);return this.children.push(r),r}},{key:"find",value:function(e){if(e===this.data)return this;for(var t=0,r=this.children.length,n=null;r>t;t++)if(n=this.children[t].find(e))return n;return null}},{key:"leaves",value:function t(){if(0===this.children.length)return[this];for(var t=[],e=0,r=this.children.length;r>e;e++)t.push.apply(t,this.children[e].leaves());return t}},{key:"root",value:function(){return this.parent?this.parent.root():this}}]),e}();exports.TreeNode=TreeNode; | ||
!function(e,t){if("function"==typeof define&&define.amd)define(["exports"],t);else if("undefined"!=typeof exports)t(exports);else{var n={exports:{}};t(n.exports),e.treenode=n.exports}}(this,function(e){"use strict";function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),r=function(){function e(n,r){return t(this,e),this.data=n,this.parent=r,this.children=[],this}return n(e,[{key:"addChild",value:function(t){var n=new e(t,this);return this.children.push(n),n}},{key:"find",value:function(e){if(e===this.data)return this;for(var t=0,n=this.children.length,r=null;n>t;t++)if(r=this.children[t].find(e))return r;return null}},{key:"leaves",value:function r(){if(0===this.children.length)return[this];for(var r=[],e=0,t=this.children.length;t>e;e++)r.push.apply(r,this.children[e].leaves());return r}},{key:"root",value:function(){return this.parent?this.parent.root():this}}]),e}();e.TreeNode=r}); |
@@ -48,3 +48,3 @@ // vars and includes | ||
.pipe(sourcemaps.init()) | ||
.pipe(babel()) | ||
.pipe(babel({ modules: "umd" })) | ||
.pipe(concat('treenode.js')) | ||
@@ -69,3 +69,3 @@ .pipe(sourcemaps.write()) | ||
return stream.done() | ||
.pipe(babel()) | ||
.pipe(babel({ modules: "umd" })) | ||
.pipe(concat('treenode.min.js')) | ||
@@ -72,0 +72,0 @@ .pipe(uglify()) |
{ | ||
"name": "treenode", | ||
"version": "0.1.1", | ||
"version": "0.1.4", | ||
"description": "Very simple tree data structure in JS", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -48,2 +48,6 @@ Tree Node | ||
* 0.1.4 Better module export syntax | ||
* 0.1.3 Updated packaging for Bower | ||
* 0.1.2 Updated packaging | ||
* 0.1.1 Updated packaging | ||
* 0.1.0 Initial release |
@@ -1,2 +0,2 @@ | ||
var TreeNode = require('../dist/treenode.js').TreeNode; | ||
var TreeNode = require('../dist/treenode').TreeNode; | ||
@@ -3,0 +3,0 @@ describe("TreeNode Class", function() { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53909
306
53