concept-tree 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -2
- package/dist/index.js +128 -0
- package/package.json +82 -5
package/README.md
CHANGED
|
@@ -1,3 +1,62 @@
|
|
|
1
|
-
|
|
1
|
+
concept-tree
|
|
2
|
+
============
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
|
|
5
|
+
Presentation
|
|
6
|
+
------------
|
|
7
|
+
|
|
8
|
+
The package *concept-tree* helps to make a virtual tree structure and output it in different ways.
|
|
9
|
+
|
|
10
|
+
Alternative solutions:
|
|
11
|
+
|
|
12
|
+
- https://github.com/D-Sketon/fast-archy
|
|
13
|
+
- https://mermaid.ai/open-source/syntax/treeView.html
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
Getting started
|
|
17
|
+
---------------
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm i concept-tree@latest
|
|
21
|
+
vim blabla.ts
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
blabla.ts:
|
|
25
|
+
```JavaScript
|
|
26
|
+
import { conceptTree } from '../src/index.ts';
|
|
27
|
+
|
|
28
|
+
// create a tree
|
|
29
|
+
const myTree = conceptTree('aaa');
|
|
30
|
+
myTree.addPath('xxx/zzz');
|
|
31
|
+
myTree.addPath('xxx/yyy');
|
|
32
|
+
myTree.addSubTree(otherTree);
|
|
33
|
+
myTree.addElem('Abc');
|
|
34
|
+
|
|
35
|
+
// get a sub-tree
|
|
36
|
+
const subTree = myTree.find('xxx')
|
|
37
|
+
|
|
38
|
+
// configure the output
|
|
39
|
+
myTree.setPrefix(0); // 0, 1, 2
|
|
40
|
+
myTree.setNumbering(true);
|
|
41
|
+
myTree.setSorting(true);
|
|
42
|
+
|
|
43
|
+
// outputs
|
|
44
|
+
const lElem = myTree.listElem(); // string[]
|
|
45
|
+
const txt = myTree.drawTree(); // string
|
|
46
|
+
const lPath = myTree.listTree(); // string[]
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Combining with Mermaid.js
|
|
50
|
+
-------------------------
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
Development
|
|
55
|
+
-----------
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
git clone https://github.com/charlyoleg2/bopa_mono
|
|
59
|
+
cd bopa_mono
|
|
60
|
+
npm -w concept-tree install
|
|
61
|
+
npm -w concept-tree run ci
|
|
62
|
+
```
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// src/concept-tree.ts
|
|
2
|
+
const cBDchar = [
|
|
3
|
+
[
|
|
4
|
+
"├──",
|
|
5
|
+
"└──",
|
|
6
|
+
"│"
|
|
7
|
+
],
|
|
8
|
+
[
|
|
9
|
+
"+--",
|
|
10
|
+
"+--",
|
|
11
|
+
"|"
|
|
12
|
+
],
|
|
13
|
+
[
|
|
14
|
+
" ",
|
|
15
|
+
" ",
|
|
16
|
+
" "
|
|
17
|
+
]
|
|
18
|
+
];
|
|
19
|
+
var ConceptTree = class ConceptTree {
|
|
20
|
+
constructor(iName) {
|
|
21
|
+
this.name = "";
|
|
22
|
+
this.sub = [];
|
|
23
|
+
this.prefixx = 0;
|
|
24
|
+
this.numbering = true;
|
|
25
|
+
this.sorting = true;
|
|
26
|
+
if (!["", "."].includes(iName)) this.name = iName;
|
|
27
|
+
}
|
|
28
|
+
getPrefix() {
|
|
29
|
+
return cBDchar[this.prefixx];
|
|
30
|
+
}
|
|
31
|
+
setPrefix(iId) {
|
|
32
|
+
const id = Math.max(0, Math.min(iId, cBDchar.length - 1));
|
|
33
|
+
this.prefixx = id;
|
|
34
|
+
}
|
|
35
|
+
setNumbering(iNumbering) {
|
|
36
|
+
this.numbering = iNumbering;
|
|
37
|
+
}
|
|
38
|
+
setSorting(iSorting) {
|
|
39
|
+
this.sorting = iSorting;
|
|
40
|
+
}
|
|
41
|
+
listElem() {
|
|
42
|
+
return this.sub.map((e) => e.name);
|
|
43
|
+
}
|
|
44
|
+
findElem(iName) {
|
|
45
|
+
let rTree = null;
|
|
46
|
+
for (const obj of this.sub) if (obj.name === iName) rTree = obj;
|
|
47
|
+
return rTree;
|
|
48
|
+
}
|
|
49
|
+
addSubTree(iTree) {
|
|
50
|
+
let pTree = this.findElem(iTree.name);
|
|
51
|
+
if (pTree === null) {
|
|
52
|
+
this.sub.push(iTree);
|
|
53
|
+
pTree = iTree;
|
|
54
|
+
} else console.log(`WARN058: the element ${iTree.name} already exist! Nothing added!`);
|
|
55
|
+
return pTree;
|
|
56
|
+
}
|
|
57
|
+
addElem(iName) {
|
|
58
|
+
let pTree = this.findElem(iName);
|
|
59
|
+
if (pTree === null) {
|
|
60
|
+
const nTree = new ConceptTree(iName);
|
|
61
|
+
this.sub.push(nTree);
|
|
62
|
+
pTree = nTree;
|
|
63
|
+
} else console.log(`WARN063: the element ${iName} already exist! Nothing added!`);
|
|
64
|
+
return pTree;
|
|
65
|
+
}
|
|
66
|
+
addPath(iPath) {
|
|
67
|
+
const lElem = iPath.split("/");
|
|
68
|
+
let pTree = this;
|
|
69
|
+
for (const elem of lElem) if (!["", "."].includes(elem)) {
|
|
70
|
+
const p2Tree = pTree.findElem(elem);
|
|
71
|
+
if (p2Tree === null) pTree = pTree.addElem(elem);
|
|
72
|
+
else pTree = p2Tree;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
_genTxtDiag(iRoot, iLast, iPad, idx) {
|
|
76
|
+
const rList = [];
|
|
77
|
+
if (iRoot) {
|
|
78
|
+
if (this.name !== "") rList.push(`${iPad}${this.name}`);
|
|
79
|
+
} else {
|
|
80
|
+
const pref = iLast ? this.getPrefix()[1] : this.getPrefix()[0];
|
|
81
|
+
const numb = this.numbering ? `${(idx + 1).toString().padStart(3)}.` : "";
|
|
82
|
+
rList.push(`${iPad}${pref}${numb} ${this.name}`);
|
|
83
|
+
}
|
|
84
|
+
const lName = this.listElem();
|
|
85
|
+
if (this.sorting) lName.sort();
|
|
86
|
+
for (const [idx2, elem] of lName.entries()) {
|
|
87
|
+
const eTree = this.findElem(elem);
|
|
88
|
+
if (eTree !== null) {
|
|
89
|
+
eTree.setPrefix(this.prefixx);
|
|
90
|
+
eTree.setNumbering(this.numbering);
|
|
91
|
+
eTree.setSorting(this.sorting);
|
|
92
|
+
const last = idx2 === this.sub.length - 1 ? true : false;
|
|
93
|
+
let lePad = iPad;
|
|
94
|
+
if (!iRoot) {
|
|
95
|
+
if (iLast) lePad += " ".repeat(this.numbering ? 8 : 4);
|
|
96
|
+
else lePad += this.getPrefix()[2] + " ".repeat(this.numbering ? 7 : 3);
|
|
97
|
+
}
|
|
98
|
+
rList.push(...eTree._genTxtDiag(false, last, lePad, idx2));
|
|
99
|
+
} else console.log("ERR127: this should never happen!");
|
|
100
|
+
}
|
|
101
|
+
return rList;
|
|
102
|
+
}
|
|
103
|
+
drawTree() {
|
|
104
|
+
return this._genTxtDiag(true, true, " ", 0).join("\n");
|
|
105
|
+
}
|
|
106
|
+
_genPathList(iRoot, iPad) {
|
|
107
|
+
const rList = [];
|
|
108
|
+
let lePad = iPad;
|
|
109
|
+
if (iRoot) {
|
|
110
|
+
if (this.name !== "") {
|
|
111
|
+
lePad = `${iPad}${this.name}`;
|
|
112
|
+
rList.push(lePad);
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
lePad = `${iPad}/${this.name}`;
|
|
116
|
+
rList.push(lePad);
|
|
117
|
+
}
|
|
118
|
+
for (const elem of this.sub) rList.push(...elem._genPathList(false, lePad));
|
|
119
|
+
return rList;
|
|
120
|
+
}
|
|
121
|
+
listTree() {
|
|
122
|
+
return this._genPathList(true, " ");
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
function conceptTree(iName) {
|
|
126
|
+
return new ConceptTree(iName);
|
|
127
|
+
}
|
|
128
|
+
export { conceptTree };
|
package/package.json
CHANGED
|
@@ -1,6 +1,83 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "concept-tree",
|
|
3
|
+
"description": "build and output virtual tree",
|
|
4
|
+
"version": "1.0.1",
|
|
5
|
+
"private": false,
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/charlyoleg2/bopa_mono.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://charlyoleg2.github.io/bopa_mono/",
|
|
11
|
+
"author": "charlyoleg2",
|
|
12
|
+
"license": "ISC",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"virtual tree",
|
|
15
|
+
"tree structure",
|
|
16
|
+
"mermaid treeView diagram"
|
|
17
|
+
],
|
|
18
|
+
"type": "module",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist/",
|
|
27
|
+
"!dist/**/*.d.ts",
|
|
28
|
+
"!dist/**/*.map",
|
|
29
|
+
"!dist/**/*.test.*",
|
|
30
|
+
"!dist/**/*.spec.*"
|
|
31
|
+
],
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=24.0.0"
|
|
34
|
+
},
|
|
35
|
+
"tsdown": {
|
|
36
|
+
"entry": [
|
|
37
|
+
"src/index.ts"
|
|
38
|
+
],
|
|
39
|
+
"format": "esm",
|
|
40
|
+
"target": "esnext",
|
|
41
|
+
"fixedExtension": false,
|
|
42
|
+
"splitting": false,
|
|
43
|
+
"dts": true,
|
|
44
|
+
"sourcemap": false,
|
|
45
|
+
"clean": true
|
|
46
|
+
},
|
|
47
|
+
"prettier": {
|
|
48
|
+
"useTabs": true,
|
|
49
|
+
"singleQuote": true,
|
|
50
|
+
"trailingComma": "none",
|
|
51
|
+
"printWidth": 100,
|
|
52
|
+
"plugins": [],
|
|
53
|
+
"overrides": []
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"dev": "tsdown --watch",
|
|
57
|
+
"build": "tsdown",
|
|
58
|
+
"check": "tsc --noEmit",
|
|
59
|
+
"pretty": "prettier --check .",
|
|
60
|
+
"format": "prettier --write .",
|
|
61
|
+
"lint": "eslint .",
|
|
62
|
+
"test:unit": "vitest",
|
|
63
|
+
"test:unit:once": "vitest --run",
|
|
64
|
+
"ci": "run-s check build pretty lint test:unit:once",
|
|
65
|
+
"run": "tsx scr/run-concept-tree.ts",
|
|
66
|
+
"clean": "rimraf node_modules build dist tmp"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@eslint/js": "^10.0.1",
|
|
70
|
+
"@types/eslint__js": "^8.42.3",
|
|
71
|
+
"@types/node": "^26.6.6",
|
|
72
|
+
"eslint": "^10.15.0",
|
|
73
|
+
"eslint-config-prettier": "^10.1.8",
|
|
74
|
+
"npm-run-all2": "^9.0.4",
|
|
75
|
+
"prettier": "^3.10.1",
|
|
76
|
+
"rimraf": "^6.1.4",
|
|
77
|
+
"tsdown": "^0.23.7",
|
|
78
|
+
"tsx": "^4.23.15",
|
|
79
|
+
"typescript": "^6.0.3",
|
|
80
|
+
"typescript-eslint": "^8.73.0",
|
|
81
|
+
"vitest": "^5.1.1"
|
|
82
|
+
}
|
|
83
|
+
}
|