treenode.ts 0.6.0 → 0.7.0
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/dist/TreeNode.d.ts +61 -4
- package/dist/TreeNode.d.ts.map +1 -1
- package/dist/TreeNode.js +249 -31
- package/dist/TreeNode.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/treenode.ts.d.ts +157 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/package.json +12 -11
package/dist/TreeNode.d.ts
CHANGED
|
@@ -3,12 +3,17 @@ import { IParseable } from "./IParseable";
|
|
|
3
3
|
* Search callback passed to `.pre`, `.post`, and `.breadth`.
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export type SearchCallback<T> = (node: TreeNode<T>) => boolean | void;
|
|
7
7
|
/**
|
|
8
8
|
* Search methods on TreeNode, passed to `.flatten`.
|
|
9
9
|
* @public
|
|
10
10
|
*/
|
|
11
|
-
export
|
|
11
|
+
export type SearchStrategy = "pre" | "post" | "breadth";
|
|
12
|
+
/**
|
|
13
|
+
* Nested array representation of a tree.
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export type NestedArray<T> = T | [T, ...(NestedArray<T> | T[])[]];
|
|
12
17
|
/**
|
|
13
18
|
* @public
|
|
14
19
|
*/
|
|
@@ -16,6 +21,7 @@ export declare class TreeNode<T> {
|
|
|
16
21
|
model: T;
|
|
17
22
|
parent: TreeNode<T> | null;
|
|
18
23
|
children: TreeNode<T>[];
|
|
24
|
+
private _index;
|
|
19
25
|
constructor(model: T, parent?: TreeNode<T> | null, children?: TreeNode<T>[]);
|
|
20
26
|
/**
|
|
21
27
|
* Parses object into a tree and returns the root node.
|
|
@@ -29,10 +35,35 @@ export declare class TreeNode<T> {
|
|
|
29
35
|
* Indices from the root to the node.
|
|
30
36
|
*/
|
|
31
37
|
get indices(): number[];
|
|
38
|
+
/**
|
|
39
|
+
* Compressed path key: positive = run of first-children, negative = child index.
|
|
40
|
+
* e.g. [0,0,0,1,0,0] -> "3,-1,2"
|
|
41
|
+
*/
|
|
42
|
+
get pathKey(): string;
|
|
32
43
|
/**
|
|
33
44
|
* Returns true if the node has children.
|
|
34
45
|
*/
|
|
35
46
|
get hasChildren(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Returns true if the node is the root (has no parent).
|
|
49
|
+
*/
|
|
50
|
+
get isRoot(): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Returns true if the node is a leaf (has no children).
|
|
53
|
+
*/
|
|
54
|
+
get isLeaf(): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Returns the root node of the tree.
|
|
57
|
+
*/
|
|
58
|
+
get root(): TreeNode<T>;
|
|
59
|
+
/**
|
|
60
|
+
* Returns the depth of the node (root is 0).
|
|
61
|
+
*/
|
|
62
|
+
get depth(): number;
|
|
63
|
+
/**
|
|
64
|
+
* Returns siblings of this node (excluding self).
|
|
65
|
+
*/
|
|
66
|
+
get siblings(): TreeNode<T>[];
|
|
36
67
|
/**
|
|
37
68
|
* Add node as a child.
|
|
38
69
|
*/
|
|
@@ -46,13 +77,18 @@ export declare class TreeNode<T> {
|
|
|
46
77
|
*/
|
|
47
78
|
drop(): TreeNode<T>;
|
|
48
79
|
/**
|
|
49
|
-
* Returns a shallow
|
|
80
|
+
* Returns a deep copy of structure, shallow copy of model.
|
|
50
81
|
*/
|
|
51
82
|
clone(): TreeNode<T>;
|
|
52
83
|
/**
|
|
53
84
|
* Returns a node given a list of indices
|
|
54
85
|
*/
|
|
55
86
|
fetch(indices: number[]): TreeNode<T> | null;
|
|
87
|
+
/**
|
|
88
|
+
* Returns a node given a pathKey string.
|
|
89
|
+
* @see pathKey
|
|
90
|
+
*/
|
|
91
|
+
fetchByPathKey(pathKey: string): TreeNode<T> | null;
|
|
56
92
|
/**
|
|
57
93
|
* Returns list of nodes to the root.
|
|
58
94
|
*/
|
|
@@ -64,7 +100,7 @@ export declare class TreeNode<T> {
|
|
|
64
100
|
/**
|
|
65
101
|
* Iterates over a node's children and returns a new root node.
|
|
66
102
|
*/
|
|
67
|
-
mapAsync<U>(callback: (node: TreeNode<T>, parent
|
|
103
|
+
mapAsync<U>(callback: (node: TreeNode<T>, parent: TreeNode<U> | undefined) => Promise<U>, parent?: TreeNode<U>): Promise<TreeNode<U>>;
|
|
68
104
|
/**
|
|
69
105
|
* Breadth-first search, return true in the callback to end iteration.
|
|
70
106
|
*/
|
|
@@ -77,10 +113,31 @@ export declare class TreeNode<T> {
|
|
|
77
113
|
* Depth-first post-order search, return true in the callback to end iteration.
|
|
78
114
|
*/
|
|
79
115
|
post(callback: SearchCallback<T>): TreeNode<T> | null;
|
|
116
|
+
/**
|
|
117
|
+
* Find the first node matching the predicate.
|
|
118
|
+
*/
|
|
119
|
+
find(predicate: (node: TreeNode<T>) => boolean, method?: SearchStrategy): TreeNode<T> | null;
|
|
120
|
+
/**
|
|
121
|
+
* Find all nodes matching the predicate.
|
|
122
|
+
*/
|
|
123
|
+
findAll(predicate: (node: TreeNode<T>) => boolean, method?: SearchStrategy): TreeNode<T>[];
|
|
80
124
|
/**
|
|
81
125
|
* Returns a list of nodes.
|
|
82
126
|
*/
|
|
83
127
|
flatten(method: SearchStrategy): TreeNode<T>[];
|
|
128
|
+
/**
|
|
129
|
+
* Returns a nested array representation of the tree.
|
|
130
|
+
* - Leaf -> value
|
|
131
|
+
* - Single child -> [model, ...childResult]
|
|
132
|
+
* - Multiple leaf children -> [model, [leaves...]]
|
|
133
|
+
* - Multiple mixed children -> [model, child1Result, child2Result, ...]
|
|
134
|
+
*/
|
|
135
|
+
toNestedArray(): NestedArray<T>;
|
|
136
|
+
/**
|
|
137
|
+
* Creates a tree from a nested array representation.
|
|
138
|
+
* @see toNestedArray
|
|
139
|
+
*/
|
|
140
|
+
static fromNestedArray<T>(input: NestedArray<T>): TreeNode<T>;
|
|
84
141
|
/**
|
|
85
142
|
* Returns an object representation of the tree.
|
|
86
143
|
*/
|
package/dist/TreeNode.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeNode.d.ts","sourceRoot":"","sources":["../src/TreeNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C;;;GAGG;AACH,
|
|
1
|
+
{"version":3,"file":"TreeNode.d.ts","sourceRoot":"","sources":["../src/TreeNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C;;;GAGG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,OAAO,GAAG,IAAI,CAAC;AAEtE;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,MAAM,GAAG,SAAS,CAAC;AAExD;;;GAGG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;AAElE;;GAEG;AACH,qBAAa,QAAQ,CAAC,CAAC;IAIZ,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI;IAC1B,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE;IALhC,OAAO,CAAC,MAAM,CAAa;gBAGlB,KAAK,EAAE,CAAC,EACR,MAAM,GAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAW,EACjC,QAAQ,GAAE,QAAQ,CAAC,CAAC,CAAC,EAAO;IAGrC;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC;IAMjD;;OAEG;IACH,IAAI,K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
|
@@ -9,12 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g =
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
18
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -35,10 +35,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
39
|
-
for (var i = 0,
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
+
if (ar || !(i in from)) {
|
|
41
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
+
ar[i] = from[i];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
42
46
|
};
|
|
43
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
48
|
exports.TreeNode = void 0;
|
|
@@ -52,6 +56,7 @@ var TreeNode = /** @class */ (function () {
|
|
|
52
56
|
this.model = model;
|
|
53
57
|
this.parent = parent;
|
|
54
58
|
this.children = children;
|
|
59
|
+
this._index = 0;
|
|
55
60
|
}
|
|
56
61
|
/**
|
|
57
62
|
* Parses object into a tree and returns the root node.
|
|
@@ -66,9 +71,7 @@ var TreeNode = /** @class */ (function () {
|
|
|
66
71
|
* Index of the node among its siblings.
|
|
67
72
|
*/
|
|
68
73
|
get: function () {
|
|
69
|
-
|
|
70
|
-
return 0;
|
|
71
|
-
return this.parent.children.indexOf(this);
|
|
74
|
+
return this._index;
|
|
72
75
|
},
|
|
73
76
|
enumerable: false,
|
|
74
77
|
configurable: true
|
|
@@ -78,9 +81,45 @@ var TreeNode = /** @class */ (function () {
|
|
|
78
81
|
* Indices from the root to the node.
|
|
79
82
|
*/
|
|
80
83
|
get: function () {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
+
var indices = [];
|
|
85
|
+
var node = this;
|
|
86
|
+
while (node.parent) {
|
|
87
|
+
indices.push(node.index);
|
|
88
|
+
node = node.parent;
|
|
89
|
+
}
|
|
90
|
+
return indices.reverse();
|
|
91
|
+
},
|
|
92
|
+
enumerable: false,
|
|
93
|
+
configurable: true
|
|
94
|
+
});
|
|
95
|
+
Object.defineProperty(TreeNode.prototype, "pathKey", {
|
|
96
|
+
/**
|
|
97
|
+
* Compressed path key: positive = run of first-children, negative = child index.
|
|
98
|
+
* e.g. [0,0,0,1,0,0] -> "3,-1,2"
|
|
99
|
+
*/
|
|
100
|
+
get: function () {
|
|
101
|
+
var indices = this.indices;
|
|
102
|
+
if (indices.length === 0)
|
|
103
|
+
return '';
|
|
104
|
+
var parts = [];
|
|
105
|
+
var zeroCount = 0;
|
|
106
|
+
for (var _i = 0, indices_1 = indices; _i < indices_1.length; _i++) {
|
|
107
|
+
var idx = indices_1[_i];
|
|
108
|
+
if (idx === 0) {
|
|
109
|
+
zeroCount++;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
if (zeroCount > 0) {
|
|
113
|
+
parts.push(zeroCount);
|
|
114
|
+
zeroCount = 0;
|
|
115
|
+
}
|
|
116
|
+
parts.push(-idx);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (zeroCount > 0) {
|
|
120
|
+
parts.push(zeroCount);
|
|
121
|
+
}
|
|
122
|
+
return parts.join(',');
|
|
84
123
|
},
|
|
85
124
|
enumerable: false,
|
|
86
125
|
configurable: true
|
|
@@ -95,11 +134,70 @@ var TreeNode = /** @class */ (function () {
|
|
|
95
134
|
enumerable: false,
|
|
96
135
|
configurable: true
|
|
97
136
|
});
|
|
137
|
+
Object.defineProperty(TreeNode.prototype, "isRoot", {
|
|
138
|
+
/**
|
|
139
|
+
* Returns true if the node is the root (has no parent).
|
|
140
|
+
*/
|
|
141
|
+
get: function () {
|
|
142
|
+
return this.parent === null;
|
|
143
|
+
},
|
|
144
|
+
enumerable: false,
|
|
145
|
+
configurable: true
|
|
146
|
+
});
|
|
147
|
+
Object.defineProperty(TreeNode.prototype, "isLeaf", {
|
|
148
|
+
/**
|
|
149
|
+
* Returns true if the node is a leaf (has no children).
|
|
150
|
+
*/
|
|
151
|
+
get: function () {
|
|
152
|
+
return !this.hasChildren;
|
|
153
|
+
},
|
|
154
|
+
enumerable: false,
|
|
155
|
+
configurable: true
|
|
156
|
+
});
|
|
157
|
+
Object.defineProperty(TreeNode.prototype, "root", {
|
|
158
|
+
/**
|
|
159
|
+
* Returns the root node of the tree.
|
|
160
|
+
*/
|
|
161
|
+
get: function () {
|
|
162
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
163
|
+
var node = this;
|
|
164
|
+
while (node.parent) {
|
|
165
|
+
node = node.parent;
|
|
166
|
+
}
|
|
167
|
+
return node;
|
|
168
|
+
},
|
|
169
|
+
enumerable: false,
|
|
170
|
+
configurable: true
|
|
171
|
+
});
|
|
172
|
+
Object.defineProperty(TreeNode.prototype, "depth", {
|
|
173
|
+
/**
|
|
174
|
+
* Returns the depth of the node (root is 0).
|
|
175
|
+
*/
|
|
176
|
+
get: function () {
|
|
177
|
+
return this.parent ? this.parent.depth + 1 : 0;
|
|
178
|
+
},
|
|
179
|
+
enumerable: false,
|
|
180
|
+
configurable: true
|
|
181
|
+
});
|
|
182
|
+
Object.defineProperty(TreeNode.prototype, "siblings", {
|
|
183
|
+
/**
|
|
184
|
+
* Returns siblings of this node (excluding self).
|
|
185
|
+
*/
|
|
186
|
+
get: function () {
|
|
187
|
+
var _this = this;
|
|
188
|
+
if (this.isRoot)
|
|
189
|
+
return [];
|
|
190
|
+
return this.parent.children.filter(function (child) { return child !== _this; });
|
|
191
|
+
},
|
|
192
|
+
enumerable: false,
|
|
193
|
+
configurable: true
|
|
194
|
+
});
|
|
98
195
|
/**
|
|
99
196
|
* Add node as a child.
|
|
100
197
|
*/
|
|
101
198
|
TreeNode.prototype.add = function (child) {
|
|
102
199
|
child.parent = this;
|
|
200
|
+
child._index = this.children.length;
|
|
103
201
|
this.children.push(child);
|
|
104
202
|
return child;
|
|
105
203
|
};
|
|
@@ -113,21 +211,27 @@ var TreeNode = /** @class */ (function () {
|
|
|
113
211
|
* Remove current node and its children from the tree and return.
|
|
114
212
|
*/
|
|
115
213
|
TreeNode.prototype.drop = function () {
|
|
116
|
-
if (this.
|
|
117
|
-
var idx = this.
|
|
214
|
+
if (!this.isRoot) {
|
|
215
|
+
var idx = this._index;
|
|
118
216
|
this.parent.children.splice(idx, 1);
|
|
217
|
+
// Update indices of subsequent siblings
|
|
218
|
+
for (var i = idx; i < this.parent.children.length; i++) {
|
|
219
|
+
this.parent.children[i]._index = i;
|
|
220
|
+
}
|
|
119
221
|
this.parent = null;
|
|
222
|
+
this._index = 0;
|
|
120
223
|
}
|
|
121
224
|
return this;
|
|
122
225
|
};
|
|
123
226
|
/**
|
|
124
|
-
* Returns a shallow
|
|
227
|
+
* Returns a deep copy of structure, shallow copy of model.
|
|
125
228
|
*/
|
|
126
229
|
TreeNode.prototype.clone = function () {
|
|
127
230
|
var node = new TreeNode(this.model);
|
|
128
|
-
node.children = this.children.map(function (child) {
|
|
231
|
+
node.children = this.children.map(function (child, i) {
|
|
129
232
|
var newChild = child.clone();
|
|
130
233
|
newChild.parent = node;
|
|
234
|
+
newChild._index = i;
|
|
131
235
|
return newChild;
|
|
132
236
|
});
|
|
133
237
|
return node;
|
|
@@ -138,35 +242,57 @@ var TreeNode = /** @class */ (function () {
|
|
|
138
242
|
TreeNode.prototype.fetch = function (indices) {
|
|
139
243
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
140
244
|
var node = this;
|
|
141
|
-
for (var _i = 0,
|
|
142
|
-
var i =
|
|
245
|
+
for (var _i = 0, indices_2 = indices; _i < indices_2.length; _i++) {
|
|
246
|
+
var i = indices_2[_i];
|
|
143
247
|
node = node.children[i];
|
|
144
248
|
if (!node)
|
|
145
249
|
return null;
|
|
146
250
|
}
|
|
147
|
-
return node
|
|
251
|
+
return node;
|
|
252
|
+
};
|
|
253
|
+
/**
|
|
254
|
+
* Returns a node given a pathKey string.
|
|
255
|
+
* @see pathKey
|
|
256
|
+
*/
|
|
257
|
+
TreeNode.prototype.fetchByPathKey = function (pathKey) {
|
|
258
|
+
if (pathKey === '')
|
|
259
|
+
return this;
|
|
260
|
+
var indices = [];
|
|
261
|
+
var parts = pathKey.split(',').map(Number);
|
|
262
|
+
for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
|
|
263
|
+
var part = parts_1[_i];
|
|
264
|
+
if (part >= 0) {
|
|
265
|
+
for (var i = 0; i < part; i++) {
|
|
266
|
+
indices.push(0);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
indices.push(-part);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return this.fetch(indices);
|
|
148
274
|
};
|
|
149
275
|
/**
|
|
150
276
|
* Returns list of nodes to the root.
|
|
151
277
|
*/
|
|
152
278
|
TreeNode.prototype.path = function () {
|
|
153
279
|
var path = [];
|
|
154
|
-
var
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return path;
|
|
280
|
+
var node = this;
|
|
281
|
+
while (node) {
|
|
282
|
+
path.push(node);
|
|
283
|
+
node = node.parent;
|
|
284
|
+
}
|
|
285
|
+
return path.reverse();
|
|
161
286
|
};
|
|
162
287
|
/**
|
|
163
288
|
* Iterates over a node's children and returns a new root node.
|
|
164
289
|
*/
|
|
165
290
|
TreeNode.prototype.map = function (callback) {
|
|
166
291
|
var node = new TreeNode(callback(this));
|
|
167
|
-
node.children = this.children.map(function (child) {
|
|
292
|
+
node.children = this.children.map(function (child, i) {
|
|
168
293
|
var newChild = child.map(callback);
|
|
169
294
|
newChild.parent = node;
|
|
295
|
+
newChild._index = i;
|
|
170
296
|
return newChild;
|
|
171
297
|
});
|
|
172
298
|
return node;
|
|
@@ -186,7 +312,7 @@ var TreeNode = /** @class */ (function () {
|
|
|
186
312
|
case 1:
|
|
187
313
|
node = new (_a.apply(TreeNode, [void 0, _c.sent()]))();
|
|
188
314
|
_b = node;
|
|
189
|
-
return [4 /*yield*/, Promise.all(this.children.map(function (child) { return __awaiter(_this, void 0, void 0, function () {
|
|
315
|
+
return [4 /*yield*/, Promise.all(this.children.map(function (child, i) { return __awaiter(_this, void 0, void 0, function () {
|
|
190
316
|
var newChild;
|
|
191
317
|
return __generator(this, function (_a) {
|
|
192
318
|
switch (_a.label) {
|
|
@@ -194,6 +320,7 @@ var TreeNode = /** @class */ (function () {
|
|
|
194
320
|
case 1:
|
|
195
321
|
newChild = _a.sent();
|
|
196
322
|
newChild.parent = node;
|
|
323
|
+
newChild._index = i;
|
|
197
324
|
return [2 /*return*/, newChild];
|
|
198
325
|
}
|
|
199
326
|
});
|
|
@@ -210,8 +337,9 @@ var TreeNode = /** @class */ (function () {
|
|
|
210
337
|
*/
|
|
211
338
|
TreeNode.prototype.breadth = function (callback) {
|
|
212
339
|
var queue = [this];
|
|
213
|
-
|
|
214
|
-
|
|
340
|
+
var head = 0;
|
|
341
|
+
while (head < queue.length) {
|
|
342
|
+
var node = queue[head++];
|
|
215
343
|
if (callback(node))
|
|
216
344
|
return node;
|
|
217
345
|
for (var i = 0, childCount = node.children.length; i < childCount; i++) {
|
|
@@ -246,6 +374,25 @@ var TreeNode = /** @class */ (function () {
|
|
|
246
374
|
return this;
|
|
247
375
|
return null;
|
|
248
376
|
};
|
|
377
|
+
/**
|
|
378
|
+
* Find the first node matching the predicate.
|
|
379
|
+
*/
|
|
380
|
+
TreeNode.prototype.find = function (predicate, method) {
|
|
381
|
+
if (method === void 0) { method = "pre"; }
|
|
382
|
+
return this[method](function (node) { return predicate(node); });
|
|
383
|
+
};
|
|
384
|
+
/**
|
|
385
|
+
* Find all nodes matching the predicate.
|
|
386
|
+
*/
|
|
387
|
+
TreeNode.prototype.findAll = function (predicate, method) {
|
|
388
|
+
if (method === void 0) { method = "pre"; }
|
|
389
|
+
var results = [];
|
|
390
|
+
this[method](function (node) {
|
|
391
|
+
if (predicate(node))
|
|
392
|
+
results.push(node);
|
|
393
|
+
});
|
|
394
|
+
return results;
|
|
395
|
+
};
|
|
249
396
|
/**
|
|
250
397
|
* Returns a list of nodes.
|
|
251
398
|
*/
|
|
@@ -256,6 +403,77 @@ var TreeNode = /** @class */ (function () {
|
|
|
256
403
|
});
|
|
257
404
|
return list;
|
|
258
405
|
};
|
|
406
|
+
/**
|
|
407
|
+
* Returns a nested array representation of the tree.
|
|
408
|
+
* - Leaf -> value
|
|
409
|
+
* - Single child -> [model, ...childResult]
|
|
410
|
+
* - Multiple leaf children -> [model, [leaves...]]
|
|
411
|
+
* - Multiple mixed children -> [model, child1Result, child2Result, ...]
|
|
412
|
+
*/
|
|
413
|
+
TreeNode.prototype.toNestedArray = function () {
|
|
414
|
+
if (this.isLeaf) {
|
|
415
|
+
return this.model;
|
|
416
|
+
}
|
|
417
|
+
if (this.children.length === 1) {
|
|
418
|
+
var childResult = this.children[0].toNestedArray();
|
|
419
|
+
if (Array.isArray(childResult)) {
|
|
420
|
+
return __spreadArray([this.model], childResult, true);
|
|
421
|
+
}
|
|
422
|
+
return [this.model, childResult];
|
|
423
|
+
}
|
|
424
|
+
// Multiple children
|
|
425
|
+
var allLeaves = this.children.every(function (c) { return c.isLeaf; });
|
|
426
|
+
if (allLeaves) {
|
|
427
|
+
return [this.model, this.children.map(function (c) { return c.model; })];
|
|
428
|
+
}
|
|
429
|
+
return __spreadArray([this.model], this.children.map(function (c) { return c.toNestedArray(); }), true);
|
|
430
|
+
};
|
|
431
|
+
/**
|
|
432
|
+
* Creates a tree from a nested array representation.
|
|
433
|
+
* @see toNestedArray
|
|
434
|
+
*/
|
|
435
|
+
TreeNode.fromNestedArray = function (input) {
|
|
436
|
+
if (!Array.isArray(input)) {
|
|
437
|
+
return new TreeNode(input);
|
|
438
|
+
}
|
|
439
|
+
var model = input[0], rest = input.slice(1);
|
|
440
|
+
var node = new TreeNode(model);
|
|
441
|
+
if (rest.length === 0) {
|
|
442
|
+
return node;
|
|
443
|
+
}
|
|
444
|
+
if (rest.length === 1 && Array.isArray(rest[0])) {
|
|
445
|
+
var inner = rest[0];
|
|
446
|
+
var hasArrays_1 = inner.some(function (x) { return Array.isArray(x); });
|
|
447
|
+
if (!hasArrays_1) {
|
|
448
|
+
// Multiple leaf children
|
|
449
|
+
for (var _i = 0, _a = inner; _i < _a.length; _i++) {
|
|
450
|
+
var leaf = _a[_i];
|
|
451
|
+
node.addModel(leaf);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
else {
|
|
455
|
+
// Single non-leaf child
|
|
456
|
+
node.add(TreeNode.fromNestedArray(inner));
|
|
457
|
+
}
|
|
458
|
+
return node;
|
|
459
|
+
}
|
|
460
|
+
var hasArrays = rest.some(function (x) { return Array.isArray(x); });
|
|
461
|
+
if (!hasArrays) {
|
|
462
|
+
// Chain: [model, a, b, c] = model -> a -> b -> c
|
|
463
|
+
var current = node;
|
|
464
|
+
for (var _b = 0, _c = rest; _b < _c.length; _b++) {
|
|
465
|
+
var val = _c[_b];
|
|
466
|
+
current = current.addModel(val);
|
|
467
|
+
}
|
|
468
|
+
return node;
|
|
469
|
+
}
|
|
470
|
+
// Multiple children with at least one non-leaf
|
|
471
|
+
for (var _d = 0, rest_1 = rest; _d < rest_1.length; _d++) {
|
|
472
|
+
var childResult = rest_1[_d];
|
|
473
|
+
node.add(TreeNode.fromNestedArray(childResult));
|
|
474
|
+
}
|
|
475
|
+
return node;
|
|
476
|
+
};
|
|
259
477
|
/**
|
|
260
478
|
* Returns an object representation of the tree.
|
|
261
479
|
*/
|
package/dist/TreeNode.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeNode.js","sourceRoot":"","sources":["../src/TreeNode.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA;;GAEG;AACH;IACE,kBACS,KAAQ,EACR,MAAiC,EACjC,QAA4B;QAD5B,uBAAA,EAAA,aAAiC;QACjC,yBAAA,EAAA,aAA4B;QAF5B,UAAK,GAAL,KAAK,CAAG;QACR,WAAM,GAAN,MAAM,CAA2B;QACjC,aAAQ,GAAR,QAAQ,CAAoB;IAClC,CAAC;IAEJ;;OAEG;IACI,cAAK,GAAZ,UAAgB,IAAmB;QACjC,IAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACtC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAC,KAAK,IAAK,OAAA,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK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ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACnF,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uCAAmF;AAA1E,oGAAA,QAAQ,OAAA"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @public
|
|
3
|
+
*/
|
|
4
|
+
export declare interface IParseable<T> {
|
|
5
|
+
model: T;
|
|
6
|
+
children: IParseable<T>[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Nested array representation of a tree.
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export declare type NestedArray<T> = T | [T, ...(NestedArray<T> | T[])[]];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Search callback passed to `.pre`, `.post`, and `.breadth`.
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export declare type SearchCallback<T> = (node: TreeNode<T>) => boolean | void;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Search methods on TreeNode, passed to `.flatten`.
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export declare type SearchStrategy = "pre" | "post" | "breadth";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export declare class TreeNode<T> {
|
|
31
|
+
model: T;
|
|
32
|
+
parent: TreeNode<T> | null;
|
|
33
|
+
children: TreeNode<T>[];
|
|
34
|
+
private _index;
|
|
35
|
+
constructor(model: T, parent?: TreeNode<T> | null, children?: TreeNode<T>[]);
|
|
36
|
+
/**
|
|
37
|
+
* Parses object into a tree and returns the root node.
|
|
38
|
+
*/
|
|
39
|
+
static parse<T>(tree: IParseable<T>): TreeNode<T>;
|
|
40
|
+
/**
|
|
41
|
+
* Index of the node among its siblings.
|
|
42
|
+
*/
|
|
43
|
+
get index(): number;
|
|
44
|
+
/**
|
|
45
|
+
* Indices from the root to the node.
|
|
46
|
+
*/
|
|
47
|
+
get indices(): number[];
|
|
48
|
+
/**
|
|
49
|
+
* Compressed path key: positive = run of first-children, negative = child index.
|
|
50
|
+
* e.g. [0,0,0,1,0,0] -> "3,-1,2"
|
|
51
|
+
*/
|
|
52
|
+
get pathKey(): string;
|
|
53
|
+
/**
|
|
54
|
+
* Returns true if the node has children.
|
|
55
|
+
*/
|
|
56
|
+
get hasChildren(): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Returns true if the node is the root (has no parent).
|
|
59
|
+
*/
|
|
60
|
+
get isRoot(): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Returns true if the node is a leaf (has no children).
|
|
63
|
+
*/
|
|
64
|
+
get isLeaf(): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Returns the root node of the tree.
|
|
67
|
+
*/
|
|
68
|
+
get root(): TreeNode<T>;
|
|
69
|
+
/**
|
|
70
|
+
* Returns the depth of the node (root is 0).
|
|
71
|
+
*/
|
|
72
|
+
get depth(): number;
|
|
73
|
+
/**
|
|
74
|
+
* Returns siblings of this node (excluding self).
|
|
75
|
+
*/
|
|
76
|
+
get siblings(): TreeNode<T>[];
|
|
77
|
+
/**
|
|
78
|
+
* Add node as a child.
|
|
79
|
+
*/
|
|
80
|
+
add(child: TreeNode<T>): TreeNode<T>;
|
|
81
|
+
/**
|
|
82
|
+
* Add model as a child.
|
|
83
|
+
*/
|
|
84
|
+
addModel(model: T): TreeNode<T>;
|
|
85
|
+
/**
|
|
86
|
+
* Remove current node and its children from the tree and return.
|
|
87
|
+
*/
|
|
88
|
+
drop(): TreeNode<T>;
|
|
89
|
+
/**
|
|
90
|
+
* Returns a deep copy of structure, shallow copy of model.
|
|
91
|
+
*/
|
|
92
|
+
clone(): TreeNode<T>;
|
|
93
|
+
/**
|
|
94
|
+
* Returns a node given a list of indices
|
|
95
|
+
*/
|
|
96
|
+
fetch(indices: number[]): TreeNode<T> | null;
|
|
97
|
+
/**
|
|
98
|
+
* Returns a node given a pathKey string.
|
|
99
|
+
* @see pathKey
|
|
100
|
+
*/
|
|
101
|
+
fetchByPathKey(pathKey: string): TreeNode<T> | null;
|
|
102
|
+
/**
|
|
103
|
+
* Returns list of nodes to the root.
|
|
104
|
+
*/
|
|
105
|
+
path(): TreeNode<T>[];
|
|
106
|
+
/**
|
|
107
|
+
* Iterates over a node's children and returns a new root node.
|
|
108
|
+
*/
|
|
109
|
+
map<U>(callback: (node: TreeNode<T>) => U): TreeNode<U>;
|
|
110
|
+
/**
|
|
111
|
+
* Iterates over a node's children and returns a new root node.
|
|
112
|
+
*/
|
|
113
|
+
mapAsync<U>(callback: (node: TreeNode<T>, parent: TreeNode<U> | undefined) => Promise<U>, parent?: TreeNode<U>): Promise<TreeNode<U>>;
|
|
114
|
+
/**
|
|
115
|
+
* Breadth-first search, return true in the callback to end iteration.
|
|
116
|
+
*/
|
|
117
|
+
breadth(callback: SearchCallback<T>): TreeNode<T> | null;
|
|
118
|
+
/**
|
|
119
|
+
* Depth-first pre-order search, return true in the callback to end iteration.
|
|
120
|
+
*/
|
|
121
|
+
pre(callback: SearchCallback<T>): TreeNode<T> | null;
|
|
122
|
+
/**
|
|
123
|
+
* Depth-first post-order search, return true in the callback to end iteration.
|
|
124
|
+
*/
|
|
125
|
+
post(callback: SearchCallback<T>): TreeNode<T> | null;
|
|
126
|
+
/**
|
|
127
|
+
* Find the first node matching the predicate.
|
|
128
|
+
*/
|
|
129
|
+
find(predicate: (node: TreeNode<T>) => boolean, method?: SearchStrategy): TreeNode<T> | null;
|
|
130
|
+
/**
|
|
131
|
+
* Find all nodes matching the predicate.
|
|
132
|
+
*/
|
|
133
|
+
findAll(predicate: (node: TreeNode<T>) => boolean, method?: SearchStrategy): TreeNode<T>[];
|
|
134
|
+
/**
|
|
135
|
+
* Returns a list of nodes.
|
|
136
|
+
*/
|
|
137
|
+
flatten(method: SearchStrategy): TreeNode<T>[];
|
|
138
|
+
/**
|
|
139
|
+
* Returns a nested array representation of the tree.
|
|
140
|
+
* - Leaf -> value
|
|
141
|
+
* - Single child -> [model, ...childResult]
|
|
142
|
+
* - Multiple leaf children -> [model, [leaves...]]
|
|
143
|
+
* - Multiple mixed children -> [model, child1Result, child2Result, ...]
|
|
144
|
+
*/
|
|
145
|
+
toNestedArray(): NestedArray<T>;
|
|
146
|
+
/**
|
|
147
|
+
* Creates a tree from a nested array representation.
|
|
148
|
+
* @see toNestedArray
|
|
149
|
+
*/
|
|
150
|
+
static fromNestedArray<T>(input: NestedArray<T>): TreeNode<T>;
|
|
151
|
+
/**
|
|
152
|
+
* Returns an object representation of the tree.
|
|
153
|
+
*/
|
|
154
|
+
toObject(): IParseable<T>;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export { }
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.55.2"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "treenode.ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Tree-like data structure for typescript",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"build:docs": "npm run build:api && api-documenter markdown --input ./temp --output ./docs",
|
|
11
11
|
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
|
|
12
12
|
"prepare": "tsc",
|
|
13
|
-
"test": "jest"
|
|
13
|
+
"test": "jest",
|
|
14
|
+
"test:coverage": "jest --coverage"
|
|
14
15
|
},
|
|
15
16
|
"repository": {
|
|
16
17
|
"type": "git",
|
|
@@ -26,15 +27,15 @@
|
|
|
26
27
|
},
|
|
27
28
|
"homepage": "https://github.com/lubert/treenode.ts#readme",
|
|
28
29
|
"devDependencies": {
|
|
29
|
-
"@microsoft/api-documenter": "^7.
|
|
30
|
-
"@microsoft/api-extractor": "^7.
|
|
31
|
-
"@types/jest": "^
|
|
32
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
33
|
-
"@typescript-eslint/parser": "^
|
|
34
|
-
"eslint": "^
|
|
35
|
-
"jest": "^
|
|
36
|
-
"ts-jest": "^
|
|
37
|
-
"typescript": "^
|
|
30
|
+
"@microsoft/api-documenter": "^7.28.2",
|
|
31
|
+
"@microsoft/api-extractor": "^7.55.2",
|
|
32
|
+
"@types/jest": "^29.5.14",
|
|
33
|
+
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
34
|
+
"@typescript-eslint/parser": "^7.18.0",
|
|
35
|
+
"eslint": "^8.57.1",
|
|
36
|
+
"jest": "^29.7.0",
|
|
37
|
+
"ts-jest": "^29.2.6",
|
|
38
|
+
"typescript": "^5.7.3"
|
|
38
39
|
},
|
|
39
40
|
"dependencies": {}
|
|
40
41
|
}
|