Skip to content

Commit 8f3d5d3

Browse files
Add code and others
1 parent 1f96887 commit 8f3d5d3

39 files changed

+8500
-3
lines changed

.babelrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"presets": [
3+
"latest"
4+
]
5+
}

.coveralls.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
service_name: travis-pro
2+
repo_token: OvYsJIALNWutWyozWapQPX865Nw2dHx0i

.github/workflows/node.js.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: Node.js CI
5+
6+
on:
7+
push:
8+
branches: [ main ]
9+
pull_request:
10+
branches: [ main ]
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
17+
strategy:
18+
matrix:
19+
node-version: [12.x]
20+
21+
steps:
22+
- uses: actions/checkout@v2
23+
- name: Use Node.js ${{ matrix.node-version }}
24+
uses: actions/setup-node@v1
25+
with:
26+
node-version: ${{ matrix.node-version }}
27+
- run: npm ci
28+
- run: npm run build --if-present
29+
- run: npm test

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ typings/
8080

8181
# Nuxt.js build / generate output
8282
.nuxt
83-
dist
8483

8584
# Gatsby files
8685
.cache/

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
language: node_js
2+
node_js:
3+
- 12

DOCUMENTATION.md

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
2+
3+
### Table of Contents
4+
5+
- [BTreeNode][1]
6+
- [Parameters][2]
7+
- [Examples][3]
8+
- [value][4]
9+
- [lNode][5]
10+
- [rNode][6]
11+
- [validate][7]
12+
- [Examples][8]
13+
- [toJSON][9]
14+
- [Examples][10]
15+
- [toString][11]
16+
- [Examples][12]
17+
18+
## BTreeNode
19+
20+
Binary Tree node class, contains 2 child nodes and single value.
21+
22+
### Parameters
23+
24+
- `attr` **BTreeNodeStruct** attributes to initialize the node. (optional, default `{}`)
25+
26+
### Examples
27+
28+
```javascript
29+
var node = new BTreeNode({ value: 15 });
30+
var node3 = new BTreeNode({ value: 30 });
31+
var node2 = new BTreeNode({ value: 20, rNode: node, lNode: node3 });
32+
console.log(node2.lNode.value); // 30
33+
```
34+
35+
### value
36+
37+
Type: any
38+
39+
### lNode
40+
41+
Type: [BTreeNode][13]
42+
43+
### rNode
44+
45+
Type: [BTreeNode][13]
46+
47+
### validate
48+
49+
Validates a BTree node, it must have a valid value (no undefined nor null).
50+
51+
#### Examples
52+
53+
```javascript
54+
new BTreeNode(); // throws error saying `A BTree node must have a valid value, cannot be null or undefined`
55+
var node = new BTreeNode({ value: 10 });
56+
console.log(node.validate()); // true
57+
```
58+
59+
Returns **[boolean][14]**
60+
61+
### toJSON
62+
63+
Converts current node and all children nodes in json format.
64+
65+
#### Examples
66+
67+
```javascript
68+
var node = new BTreeNode({ value: 10 });
69+
var lNode = new BTreeNode({ value: 15, lNode: lNode });
70+
console.log(node.toJSON()); // {value:15,lNode: {value: 10,lNode:null,rNode:null},rNode:null}
71+
```
72+
73+
Returns **BTreeNodeStruct**
74+
75+
### toString
76+
77+
Converts current node and all children nodes in json format and append them together.
78+
Goes in direction of U -> L -> R
79+
80+
#### Examples
81+
82+
```javascript
83+
var node = new BTreeNode({ value: 10 });
84+
var lNode = new BTreeNode({ value: 15, lNode: lNode });
85+
console.log(node.toString()); // "1015"
86+
```
87+
88+
Returns **[string][15]**
89+
90+
[1]: #btreenode
91+
92+
[2]: #parameters
93+
94+
[3]: #examples
95+
96+
[4]: #value
97+
98+
[5]: #lnode
99+
100+
[6]: #rnode
101+
102+
[7]: #validate
103+
104+
[8]: #examples-1
105+
106+
[9]: #tojson
107+
108+
[10]: #examples-2
109+
110+
[11]: #tostring
111+
112+
[12]: #examples-3
113+
114+
[13]: #btreenode
115+
116+
[14]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
117+
118+
[15]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String

README.md

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,44 @@
1-
# binary-tree
2-
binary-tree
1+
# @dsinjs/binary-tree
2+
Data structure in your javascript code, Binary Trees.
3+
4+
[![Build Status](https://travis-ci.com/siddhesh321995/node-dsinjs-binarytree.svg?branch=main)](https://travis-ci.com/siddhesh321995/node-dsinjs-binarytree)
5+
![Node.js CI](https://github.com/dsinjs/binary-tree/workflows/Node.js%20CI/badge.svg)
6+
[![Coverage Status](https://coveralls.io/repos/github/siddhesh321995/node-dsinjs-binarytree/badge.svg?branch=main)](https://coveralls.io/github/siddhesh321995/node-dsinjs-binarytree?branch=main)
7+
8+
## Installation:
9+
Using npm
10+
```
11+
npm install @dsinjs/binary-tree --save
12+
```
13+
Or directly on your browser, simply download your file from the following:
14+
- [dsinjs-binarytree.js](dist/dsinjs-binarytree.js) Development version
15+
- [dsinjs-binarytree.min.js](dist/dsinjs-binarytree.min.js) Deployment version
16+
```
17+
<script type="application/javascript" src="dsinjs-binarytree.js"></script>
18+
<script type="application/javascript" src="dsinjs-binarytree.min.js"></script>
19+
```
20+
## Recent features added in the library
21+
- Ajax: XHR wrapper for frontend.
22+
- EventManager: Custom event manager.
23+
24+
## Some sample utility functions
25+
```
26+
const BTreeNode = require('@dsinjs/binary-tree');
27+
```
28+
```
29+
var node = new BTreeNode({ value: 10 });
30+
var nodel = new BTreeNode({ value: 15, lNode: node });
31+
```
32+
33+
## Complete Documentation
34+
Checkout [DOCUMENTATION.md](DOCUMENTATION.md) for complete documentation or View Documentation online at [https://github.com/dsinjs/binary-tree/](https://github.com/dsinjs/binary-tree/)
35+
36+
## All Features:
37+
- Data type check functions.
38+
- Frontend XHR wrapper.
39+
- EnumGenerator, defaultsGenerator functions.
40+
- 0 Dependancy.
41+
42+
## Help us expand:
43+
Let me know in issues/github page or on email which javascript functions to include in next release.
44+
Check all the [Contributors](Contributors.md) to this library.

dist/dsinjs-binarytree.js

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2+
"use strict";
3+
4+
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; }; }();
5+
6+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
7+
8+
/**
9+
* @typedef {{value:T,lNode: BTreeNodeStruct | BTreeNode, rNode: BTreeNodeStruct | BTreeNode}} BTreeNodeStruct
10+
* @interface
11+
* @private
12+
*/
13+
14+
var bTreeNodeStruct = {};
15+
16+
/**
17+
* Binary Tree node class, contains 2 child nodes and single value.
18+
* @class
19+
* @public
20+
* @example
21+
* var node = new BTreeNode({ value: 15 });
22+
* var node3 = new BTreeNode({ value: 30 });
23+
* var node2 = new BTreeNode({ value: 20, rNode: node, lNode: node3 });
24+
* console.log(node2.lNode.value); // 30
25+
*/
26+
27+
var BTreeNode = function () {
28+
/**
29+
*
30+
* @param {BTreeNodeStruct} attr attributes to initialize the node.
31+
*/
32+
function BTreeNode() {
33+
var attr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
34+
35+
_classCallCheck(this, BTreeNode);
36+
37+
/**
38+
* @property value
39+
* Contains actual value
40+
* @type {any}
41+
* @public
42+
*/
43+
this.value = attr.value || null;
44+
45+
/**
46+
* @property lNode
47+
* Contains left child node
48+
* @type {BTreeNode}
49+
* @public
50+
*/
51+
this.lNode = attr.lNode || null;
52+
53+
if (!this.lNode instanceof BTreeNode) {
54+
this.lNode = new BTreeNode(this.lNode);
55+
}
56+
57+
/**
58+
* @property rNode
59+
* Contains right child node
60+
* @type {BTreeNode}
61+
* @public
62+
*/
63+
this.rNode = attr.rNode || null;
64+
65+
if (!this.rNode instanceof BTreeNode) {
66+
this.rNode = new BTreeNode(this.rNode);
67+
}
68+
69+
if (!this.validate()) {
70+
throw new Error("A BTree node must have a valid value, cannot be null or undefined");
71+
}
72+
}
73+
74+
/**
75+
* Validates a BTree node, it must have a valid value (no undefined nor null).
76+
* @public
77+
* @returns {boolean}
78+
* @example
79+
* new BTreeNode(); // throws error saying `A BTree node must have a valid value, cannot be null or undefined`
80+
* var node = new BTreeNode({ value: 10 });
81+
* console.log(node.validate()); // true
82+
*/
83+
84+
85+
_createClass(BTreeNode, [{
86+
key: "validate",
87+
value: function validate() {
88+
return this.value != void 0 || this.value != null;
89+
}
90+
91+
/**
92+
* Converts current node and all children nodes in json format.
93+
* @public
94+
* @returns {BTreeNodeStruct}
95+
* @example
96+
* var node = new BTreeNode({ value: 10 });
97+
* var lNode = new BTreeNode({ value: 15, lNode: lNode });
98+
* console.log(node.toJSON()); // {value:15,lNode: {value: 10,lNode:null,rNode:null},rNode:null}
99+
*/
100+
101+
}, {
102+
key: "toJSON",
103+
value: function toJSON() {
104+
return {
105+
value: this.value && typeof this.value.toJSON === "function" ? this.value.toJSON() : this.value,
106+
lNode: this.lNode === null ? null : this.lNode.toJSON(),
107+
rNode: this.rNode === null ? null : this.rNode.toJSON()
108+
};
109+
}
110+
111+
/**
112+
* Converts current node and all children nodes in json format and append them together.
113+
* Goes in direction of U -> L -> R
114+
* @public
115+
* @returns {string}
116+
* @example
117+
* var node = new BTreeNode({ value: 10 });
118+
* var lNode = new BTreeNode({ value: 15, lNode: lNode });
119+
* console.log(node.toString()); // "1015"
120+
*/
121+
122+
}, {
123+
key: "toString",
124+
value: function toString() {
125+
var leftStr = this.lNode === null ? "" : this.lNode.toString();
126+
var rightStr = this.rNode === null ? "" : this.rNode.toString();
127+
var currStr = typeof this.value.toString === "function" ? this.value.toString() : String(this.value);
128+
129+
return this.value.toString() + leftStr + rightStr;
130+
}
131+
}]);
132+
133+
return BTreeNode;
134+
}();
135+
136+
if (typeof module != "undefined") {
137+
module.exports = BTreeNode;
138+
}
139+
if (typeof window != "undefined") {
140+
window.DSinJS = window.DSinJS || {};
141+
window.DSinJS.BTreeNode = BTreeNode;
142+
}
143+
},{}]},{},[1]);

dist/dsinjs-binarytree.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)