collect-your-stuff 2.1.1 → 2.2.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.
Files changed (75) hide show
  1. package/README.md +32 -3241
  2. package/browser/collect-your-stuff.js +1585 -1193
  3. package/browser/collect-your-stuff.min.js +1 -1
  4. package/dist/collections/arrayable/ArrayElement.d.ts +33 -38
  5. package/dist/collections/arrayable/ArrayElement.js +64 -66
  6. package/dist/collections/arrayable/Arrayable.d.ts +107 -122
  7. package/dist/collections/arrayable/Arrayable.js +208 -223
  8. package/dist/collections/doubly-linked-list/DoubleLinker.d.ts +45 -50
  9. package/dist/collections/doubly-linked-list/DoubleLinker.js +71 -73
  10. package/dist/collections/doubly-linked-list/DoublyLinkedList.d.ts +108 -125
  11. package/dist/collections/doubly-linked-list/DoublyLinkedList.js +310 -327
  12. package/dist/collections/linked-list/LinkedList.d.ts +110 -126
  13. package/dist/collections/linked-list/LinkedList.js +283 -296
  14. package/dist/collections/linked-list/Linker.d.ts +41 -46
  15. package/dist/collections/linked-list/Linker.js +82 -84
  16. package/dist/collections/linked-tree-list/LinkedTreeList.d.ts +140 -159
  17. package/dist/collections/linked-tree-list/LinkedTreeList.js +274 -294
  18. package/dist/collections/linked-tree-list/TreeLinker.d.ts +65 -71
  19. package/dist/collections/linked-tree-list/TreeLinker.js +91 -94
  20. package/dist/collections/queue/Queue.d.ts +55 -59
  21. package/dist/collections/queue/Queue.js +114 -119
  22. package/dist/collections/queue/Queueable.d.ts +74 -83
  23. package/dist/collections/queue/Queueable.js +142 -146
  24. package/dist/collections/queue/TaskQueue.d.ts +59 -68
  25. package/dist/collections/queue/TaskQueue.js +128 -137
  26. package/dist/collections/scoped-collection/ScopedCollection.d.ts +42 -0
  27. package/dist/collections/scoped-collection/ScopedCollection.js +81 -0
  28. package/dist/collections/scoped-collection/ScopedCollection.min.js +1 -0
  29. package/dist/collections/stack/Stack.d.ts +60 -64
  30. package/dist/collections/stack/Stack.js +122 -127
  31. package/dist/collections/stack/Stackable.d.ts +52 -59
  32. package/dist/collections/stack/Stackable.js +81 -85
  33. package/dist/collections/stack/TaskStack.d.ts +56 -65
  34. package/dist/collections/stack/TaskStack.js +98 -107
  35. package/dist/main.d.ts +4 -5
  36. package/dist/main.js +9 -5
  37. package/dist/main.min.js +1 -1
  38. package/dist/recipes/ArrayIterator.d.ts +20 -20
  39. package/dist/recipes/ArrayIterator.js +39 -39
  40. package/dist/recipes/DoubleLinkerIterator.d.ts +18 -18
  41. package/dist/recipes/DoubleLinkerIterator.js +33 -33
  42. package/dist/recipes/IsArrayable.d.ts +85 -105
  43. package/dist/recipes/IsArrayable.js +5 -5
  44. package/dist/recipes/IsDoubleLinker.d.ts +14 -14
  45. package/dist/recipes/IsDoubleLinker.js +5 -5
  46. package/dist/recipes/IsElement.d.ts +14 -14
  47. package/dist/recipes/IsElement.js +5 -5
  48. package/dist/recipes/IsLinker.d.ts +10 -10
  49. package/dist/recipes/IsLinker.js +5 -5
  50. package/dist/recipes/IsQueue.d.ts +32 -37
  51. package/dist/recipes/IsQueue.js +5 -5
  52. package/dist/recipes/IsScopedCollection.d.ts +27 -0
  53. package/dist/recipes/IsScopedCollection.js +5 -0
  54. package/dist/recipes/IsScopedCollection.min.js +1 -0
  55. package/dist/recipes/IsStack.d.ts +31 -36
  56. package/dist/recipes/IsStack.js +5 -5
  57. package/dist/recipes/IsTree.d.ts +11 -11
  58. package/dist/recipes/IsTree.js +5 -5
  59. package/dist/recipes/IsTreeNode.d.ts +29 -29
  60. package/dist/recipes/IsTreeNode.js +5 -5
  61. package/dist/recipes/LinkerIterator.d.ts +18 -18
  62. package/dist/recipes/LinkerIterator.js +33 -33
  63. package/dist/recipes/Runnable.d.ts +42 -55
  64. package/dist/recipes/Runnable.js +63 -69
  65. package/dist/recipes/TreeLinkerIterator.d.ts +20 -20
  66. package/dist/recipes/TreeLinkerIterator.js +36 -36
  67. package/dist/recipes/recipes.d.ts +12 -15
  68. package/dist/recipes/recipes.js +19 -22
  69. package/dist/services/parseTree.d.ts +8 -9
  70. package/dist/services/parseTree.js +23 -24
  71. package/dist/services/parseTreeNext.d.ts +16 -17
  72. package/dist/services/parseTreeNext.js +41 -42
  73. package/dist/services/services.d.ts +10 -13
  74. package/dist/services/services.js +19 -22
  75. package/package.json +4 -4
@@ -1,294 +1,274 @@
1
- 'use strict'
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true
5
- })
6
- exports.LinkedTreeList = void 0
7
- require('core-js/modules/esnext.iterator.constructor.js')
8
- require('core-js/modules/esnext.iterator.for-each.js')
9
- var _TreeLinker = require('./TreeLinker')
10
- var _TreeLinkerIterator = require('../../recipes/TreeLinkerIterator')
11
- var _DoublyLinkedList = require('../doubly-linked-list/DoublyLinkedList')
12
- /**
13
- * @file doubly linked tree list.
14
- * @author Joshua Heagle <joshuaheagle@gmail.com>
15
- * @version 1.1.0
16
- * @memberOf module:collect-your-stuff
17
- */
18
-
19
- /**
20
- * Use one of the accessors of DoublyLinkedList (which keeps track of the head, tail and length) for a LinkedTreeList.
21
- * @param {string} name The accessor to use
22
- * @param {LinkedTreeList} list The list to use it on
23
- * @returns {*}
24
- */
25
- const borrowedGetter = (name, list) => Object.getOwnPropertyDescriptor(_DoublyLinkedList.DoublyLinkedList.prototype, name).get.call(list)
26
- /**
27
- * LinkedTreeList represents a collection stored with a root and spreading in branching (tree) formation.
28
- * @extends DoublyLinkedList
29
- */
30
- class LinkedTreeList {
31
- /**
32
- * Create the new LinkedTreeList instance, configure the list class.
33
- * @param {TreeLinker} [linkerClass=TreeLinker] The class used to wrap given data as tree linkers.
34
- */
35
- constructor (linkerClass = _TreeLinker.TreeLinker) {
36
- /** The class used to create this instance, so that it can be recognized as valid without an instanceof check. */
37
- this.classType = LinkedTreeList
38
- /** A linker of the list (null when the list is empty); the head is found by walking back from it. */
39
- this.innerList = null
40
- /** Whether the inner list has been initialized (it can only be initialized once). */
41
- this.initialized = false
42
- /** The last linker, remembered so that adding to the end does not need to walk the whole list (null when not known yet). */
43
- this.tailCache = null
44
- /** The number of linkers, kept up to date by the list's own methods so that the length does not need to walk the whole list (null when not known yet). */
45
- this.countCache = null
46
- /** The node these linkers are the children of, remembered so that it is known even while the list is empty (undefined until it is known). */
47
- this.ownerNode = undefined
48
- this.linkerClass = linkerClass
49
- }
50
-
51
- /**
52
- * Initialize the inner list, should only run once.
53
- * @param {TreeLinker} initialList Give the list of tree-linkers to start in this linked-tree-list.
54
- * @return {LinkedTreeList}
55
- */
56
- initialize (initialList) {
57
- if (this.initialized) {
58
- console.warn('Attempt to initialize LinkedTreeList which is not empty.')
59
- return this
60
- }
61
- this.initialized = true
62
- this.innerList = initialList
63
- return this
64
- }
65
-
66
- /**
67
- * Retrieve the innerList used (the list itself, not a copy).
68
- * @returns {TreeLinker}
69
- */
70
- get list () {
71
- return this.innerList
72
- }
73
-
74
- /**
75
- * Retrieve the first TreeLinker in the list.
76
- * @returns {TreeLinker}
77
- */
78
- get first () {
79
- return borrowedGetter('first', this)
80
- }
81
-
82
- /**
83
- * Retrieve the last TreeLinker in the list. The end is remembered, so this does not walk the list.
84
- * @returns {TreeLinker}
85
- */
86
- get last () {
87
- return borrowedGetter('last', this)
88
- }
89
-
90
- /**
91
- * Return the length of the list. It is kept up to date by the list's own methods, so this does not walk the list
92
- * (call reset() after linkers were changed directly).
93
- * @returns {number}
94
- */
95
- get length () {
96
- return borrowedGetter('length', this)
97
- }
98
-
99
- /**
100
- * Get the parent of this tree list: the node these linkers are the children of (remembered even while the list is
101
- * empty), or null for the linkers at the top of a tree.
102
- * @return {TreeLinker|null}
103
- */
104
- get parent () {
105
- if (this.ownerNode !== undefined) {
106
- return this.ownerNode
107
- }
108
- const first = this.first
109
- return first === null ? null : first.parent
110
- }
111
-
112
- /**
113
- * Set the parent of this tree list: every linker in it gets the node as its parent, and the node gets this list as its
114
- * children. Linkers added to the list later get this parent too.
115
- * @param {TreeLinker|null} parent The new node to use as the parent for this group of children
116
- */
117
- set parent (parent) {
118
- this.ownerNode = parent
119
- let current = this.first
120
- while (current !== null) {
121
- current.parent = parent
122
- current = current.next
123
- }
124
- if (parent) {
125
- parent.children = this
126
- }
127
- }
128
-
129
- /**
130
- * Return the root parent of the entire tree.
131
- * @return {TreeLinker}
132
- */
133
- get rootParent () {
134
- let current = this.first
135
- if (!current) {
136
- return null
137
- }
138
- let parent = this.first.parent
139
- while (parent !== null) {
140
- current = parent
141
- parent = current.parent
142
- }
143
- return current
144
- }
145
-
146
- /**
147
- * Set the children on a parent item.
148
- * @param {TreeLinker} item The TreeLinker node (one of the linkers of this list) that will be the parent of the children
149
- * @param {LinkedTreeList|null} [children=null] The LinkedTreeList which has the child nodes to use, or null to remove the children of the item
150
- * @throws {Error} When the item is not one of the linkers of this list
151
- */
152
- setChildren (item, children = null) {
153
- // The item must be one of the linkers of this list (only the siblings are checked, not the whole tree)
154
- let isChild = false
155
- this.forEach(linker => {
156
- if (linker === item) {
157
- isChild = true
158
- }
159
- })
160
- if (!isChild) {
161
- throw new Error('The item is not one of the linkers of this list.')
162
- }
163
- if (children === null || typeof children === 'undefined') {
164
- item.children = null
165
- return
166
- }
167
- children.parent = item
168
- }
169
-
170
- /**
171
- * Make a linker of the given node (or data) and make this list's parent its parent.
172
- * @param {TreeLinker|*} newNode The node (or data) which is being added to this list
173
- * @returns {TreeLinker}
174
- */
175
- adopt (newNode) {
176
- const linker = this.linkerClass.make(newNode, this.linkerClass)
177
- linker.parent = this.parent
178
- return linker
179
- }
180
-
181
- /**
182
- * Insert a new node (or data) after a node. The new node gets the parent of this list.
183
- * @param {TreeLinker|*} node The existing node as reference, or null to insert at the start of the list
184
- * @param {TreeLinker|*} newNode The new node to go after the existing node
185
- * @returns {LinkedTreeList}
186
- */
187
- insertAfter (node, newNode) {
188
- return _DoublyLinkedList.DoublyLinkedList.prototype.insertAfter.call(this, node, this.adopt(newNode))
189
- }
190
-
191
- /**
192
- * Insert a new node (or data) before a node. The new node gets the parent of this list.
193
- * @param {TreeLinker|*} node The existing node as reference, or null to insert at the end of the list
194
- * @param {TreeLinker|*} newNode The new node to go before the existing node
195
- * @returns {LinkedTreeList}
196
- */
197
- insertBefore (node, newNode) {
198
- return _DoublyLinkedList.DoublyLinkedList.prototype.insertBefore.call(this, node, this.adopt(newNode))
199
- }
200
-
201
- /**
202
- * Add a node (or data) after the given (or last) node in the list.
203
- * @param {TreeLinker|*} node The new node to add to the end of the list
204
- * @param {TreeLinker} after The existing last node
205
- * @returns {TreeLinker}
206
- */
207
- append (node, after = this.last) {
208
- return _DoublyLinkedList.DoublyLinkedList.prototype.append.call(this, node, after)
209
- }
210
-
211
- /**
212
- * Add a node (or data) before the given (or first) node in the list.
213
- * @param {TreeLinker|*} node The new node to add to the start of the list
214
- * @param {TreeLinker} before The existing first node
215
- * @returns {TreeLinker}
216
- */
217
- prepend (node, before = this.first) {
218
- return _DoublyLinkedList.DoublyLinkedList.prototype.prepend.call(this, node, before)
219
- }
220
-
221
- /**
222
- * Remove a linker from this linked list. The removed node no longer has a parent.
223
- * @param {TreeLinker} node The node we wish to remove (and it will be returned after removal)
224
- * @return {TreeLinker|null} The removed node, or null when there was nothing to remove
225
- */
226
- remove (node) {
227
- const owner = this.parent
228
- const removed = _DoublyLinkedList.DoublyLinkedList.prototype.remove.call(this, node)
229
- if (removed && removed.parent === owner) {
230
- // Remember whose children these are (the list may now be empty), the removed node no longer has that parent
231
- this.ownerNode = owner
232
- removed.parent = null
233
- }
234
- return removed
235
- }
236
-
237
- /**
238
- * Refresh all references (the head, the end and the length) by walking the list once, and return the head. The
239
- * list's own methods keep these up to date, so this is only needed after linkers were changed directly.
240
- * @return {TreeLinker}
241
- */
242
- reset () {
243
- return _DoublyLinkedList.DoublyLinkedList.prototype.reset.call(this)
244
- }
245
-
246
- /**
247
- * Retrieve a TreeLinker item from this list by numeric index, otherwise return null.
248
- * @param {number} index The integer number for retrieving a node by position.
249
- * @returns {TreeLinker|null}
250
- */
251
- item (index) {
252
- return _DoublyLinkedList.DoublyLinkedList.prototype.item.call(this, index)
253
- }
254
-
255
- /**
256
- * Be able to run forEach on this LinkedTreeList to iterate over the TreeLinker Items.
257
- * @param {forEachCallback} callback The function to call for-each tree node
258
- * @param {LinkedTreeList} thisArg Optional, 'this' reference
259
- * @return {LinkedTreeList} The list which was iterated.
260
- */
261
- forEach (callback, thisArg = this) {
262
- let index = 0
263
- let current = thisArg.first
264
- while (current !== null) {
265
- callback(current, index, thisArg)
266
- current = current.next
267
- ++index
268
- }
269
- return thisArg
270
- }
271
-
272
- /**
273
- * Be able to iterate over this class: the linkers of this list and everything below them (left-first). It stays within
274
- * this list (it does not start at, or climb up to, the parents), use the parseTree service to parse a whole tree.
275
- * @returns {Iterator}
276
- */
277
- [Symbol.iterator] () {
278
- // The linkers of this list and everything below them, left-first. It stays within this list: it does not start at,
279
- // or climb up to, the parents (use the parseTree service to parse a whole tree)
280
- return new _TreeLinkerIterator.TreeLinkerIterator(this.first, this.parent)
281
- }
282
- }
283
- /**
284
- * Convert an array into a LinkedTreeList instance, return the new instance.
285
- * @param {Array} [values=[]] An array of values which will be converted to nodes in this tree-list
286
- * @param {TreeLinker} [linkerClass=TreeLinker] The class to use for each node
287
- * @param {IsArrayable<TreeLinker>} [classType=LinkedTreeList] Provide the type of IsArrayable to use.
288
- * @returns {LinkedTreeList}
289
- */
290
- exports.LinkedTreeList = LinkedTreeList
291
- LinkedTreeList.fromArray = (values = [], linkerClass = _TreeLinker.TreeLinker, classType = LinkedTreeList) => {
292
- const list = new classType(linkerClass)
293
- return list.initialize(linkerClass.fromArray(values).head)
294
- }
1
+ 'use strict'
2
+
3
+ Object.defineProperty(exports, '__esModule', {
4
+ value: true
5
+ })
6
+ exports.LinkedTreeList = void 0
7
+ require('core-js/modules/esnext.iterator.constructor.js')
8
+ require('core-js/modules/esnext.iterator.for-each.js')
9
+ const _TreeLinker = require('./TreeLinker')
10
+ const _TreeLinkerIterator = require('../../recipes/TreeLinkerIterator')
11
+ const _DoublyLinkedList = require('../doubly-linked-list/DoublyLinkedList')
12
+ /**
13
+ * doubly linked tree list.
14
+ */
15
+
16
+ /**
17
+ * Use one of the accessors of DoublyLinkedList (which keeps track of the head, tail and length) for a LinkedTreeList.
18
+ * @param name The accessor to use
19
+ * @param list The list to use it on
20
+ */
21
+ const borrowedGetter = (name, list) => Object.getOwnPropertyDescriptor(_DoublyLinkedList.DoublyLinkedList.prototype, name).get.call(list)
22
+ /**
23
+ * LinkedTreeList represents a collection stored with a root and spreading in branching (tree) formation.
24
+ * @extends DoublyLinkedList
25
+ */
26
+ class LinkedTreeList {
27
+ /**
28
+ * Create the new LinkedTreeList instance, configure the list class.
29
+ * @param linkerClass The class used to wrap given data as tree linkers.
30
+ */
31
+ constructor (linkerClass = _TreeLinker.TreeLinker) {
32
+ /** The class used to create this instance, so that it can be recognized as valid without an instanceof check. */
33
+ this.classType = LinkedTreeList
34
+ /** A linker of the list (null when the list is empty); the head is found by walking back from it. */
35
+ this.innerList = null
36
+ /** Whether the inner list has been initialized (it can only be initialized once). */
37
+ this.initialized = false
38
+ /** The last linker, remembered so that adding to the end does not need to walk the whole list (null when not known yet). */
39
+ this.tailCache = null
40
+ /** The number of linkers, kept up to date by the list's own methods so that the length does not need to walk the whole list (null when not known yet). */
41
+ this.countCache = null
42
+ /** The node these linkers are the children of, remembered so that it is known even while the list is empty (undefined until it is known). */
43
+ this.ownerNode = undefined
44
+ this.linkerClass = linkerClass
45
+ }
46
+
47
+ /**
48
+ * Initialize the inner list, should only run once.
49
+ * @param initialList Give the list of tree-linkers to start in this linked-tree-list.
50
+ */
51
+ initialize (initialList) {
52
+ if (this.initialized) {
53
+ console.warn('Attempt to initialize LinkedTreeList which is not empty.')
54
+ return this
55
+ }
56
+ this.initialized = true
57
+ this.innerList = initialList
58
+ return this
59
+ }
60
+
61
+ /**
62
+ * Retrieve the innerList used (the list itself, not a copy).
63
+ */
64
+ get list () {
65
+ return this.innerList
66
+ }
67
+
68
+ /**
69
+ * Retrieve the first TreeLinker in the list.
70
+ */
71
+ get first () {
72
+ return borrowedGetter('first', this)
73
+ }
74
+
75
+ /**
76
+ * Retrieve the last TreeLinker in the list. The end is remembered, so this does not walk the list.
77
+ */
78
+ get last () {
79
+ return borrowedGetter('last', this)
80
+ }
81
+
82
+ /**
83
+ * Return the length of the list. It is kept up to date by the list's own methods, so this does not walk the list
84
+ * (call reset() after linkers were changed directly).
85
+ */
86
+ get length () {
87
+ return borrowedGetter('length', this)
88
+ }
89
+
90
+ /**
91
+ * Get the parent of this tree list: the node these linkers are the children of (remembered even while the list is
92
+ * empty), or null for the linkers at the top of a tree.
93
+ */
94
+ get parent () {
95
+ if (this.ownerNode !== undefined) {
96
+ return this.ownerNode
97
+ }
98
+ const first = this.first
99
+ return first === null ? null : first.parent
100
+ }
101
+
102
+ /**
103
+ * Set the parent of this tree list: every linker in it gets the node as its parent, and the node gets this list as its
104
+ * children. Linkers added to the list later get this parent too.
105
+ * @param parent The new node to use as the parent for this group of children
106
+ */
107
+ set parent (parent) {
108
+ this.ownerNode = parent
109
+ let current = this.first
110
+ while (current !== null) {
111
+ current.parent = parent
112
+ current = current.next
113
+ }
114
+ if (parent) {
115
+ parent.children = this
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Return the root parent of the entire tree.
121
+ */
122
+ get rootParent () {
123
+ let current = this.first
124
+ if (!current) {
125
+ return null
126
+ }
127
+ let parent = this.first.parent
128
+ while (parent !== null) {
129
+ current = parent
130
+ parent = current.parent
131
+ }
132
+ return current
133
+ }
134
+
135
+ /**
136
+ * Set the children on a parent item.
137
+ * @param item The TreeLinker node (one of the linkers of this list) that will be the parent of the children
138
+ * @param children The LinkedTreeList which has the child nodes to use, or null to remove the children of the item
139
+ * @throws {Error} When the item is not one of the linkers of this list
140
+ */
141
+ setChildren (item, children = null) {
142
+ // The item must be one of the linkers of this list (only the siblings are checked, not the whole tree)
143
+ let isChild = false
144
+ this.forEach(linker => {
145
+ if (linker === item) {
146
+ isChild = true
147
+ }
148
+ })
149
+ if (!isChild) {
150
+ throw new Error('The item is not one of the linkers of this list.')
151
+ }
152
+ if (children === null || typeof children === 'undefined') {
153
+ item.children = null
154
+ return
155
+ }
156
+ children.parent = item
157
+ }
158
+
159
+ /**
160
+ * Make a linker of the given node (or data) and make this list's parent its parent.
161
+ * @param newNode The node (or data) which is being added to this list
162
+ */
163
+ adopt (newNode) {
164
+ const linker = this.linkerClass.make(newNode, this.linkerClass)
165
+ linker.parent = this.parent
166
+ return linker
167
+ }
168
+
169
+ /**
170
+ * Insert a new node (or data) after a node. The new node gets the parent of this list.
171
+ * @param node The existing node as reference, or null to insert at the start of the list
172
+ * @param newNode The new node to go after the existing node
173
+ */
174
+ insertAfter (node, newNode) {
175
+ return _DoublyLinkedList.DoublyLinkedList.prototype.insertAfter.call(this, node, this.adopt(newNode))
176
+ }
177
+
178
+ /**
179
+ * Insert a new node (or data) before a node. The new node gets the parent of this list.
180
+ * @param node The existing node as reference, or null to insert at the end of the list
181
+ * @param newNode The new node to go before the existing node
182
+ */
183
+ insertBefore (node, newNode) {
184
+ return _DoublyLinkedList.DoublyLinkedList.prototype.insertBefore.call(this, node, this.adopt(newNode))
185
+ }
186
+
187
+ /**
188
+ * Add a node (or data) after the given (or last) node in the list.
189
+ * @param node The new node to add to the end of the list
190
+ * @param after The existing last node
191
+ */
192
+ append (node, after = this.last) {
193
+ return _DoublyLinkedList.DoublyLinkedList.prototype.append.call(this, node, after)
194
+ }
195
+
196
+ /**
197
+ * Add a node (or data) before the given (or first) node in the list.
198
+ * @param node The new node to add to the start of the list
199
+ * @param before The existing first node
200
+ */
201
+ prepend (node, before = this.first) {
202
+ return _DoublyLinkedList.DoublyLinkedList.prototype.prepend.call(this, node, before)
203
+ }
204
+
205
+ /**
206
+ * Remove a linker from this linked list. The removed node no longer has a parent.
207
+ * @param node The node we wish to remove (and it will be returned after removal)
208
+ * @returns The removed node, or null when there was nothing to remove
209
+ */
210
+ remove (node) {
211
+ const owner = this.parent
212
+ const removed = _DoublyLinkedList.DoublyLinkedList.prototype.remove.call(this, node)
213
+ if (removed && removed.parent === owner) {
214
+ // Remember whose children these are (the list may now be empty), the removed node no longer has that parent
215
+ this.ownerNode = owner
216
+ removed.parent = null
217
+ }
218
+ return removed
219
+ }
220
+
221
+ /**
222
+ * Refresh all references (the head, the end and the length) by walking the list once, and return the head. The
223
+ * list's own methods keep these up to date, so this is only needed after linkers were changed directly.
224
+ */
225
+ reset () {
226
+ return _DoublyLinkedList.DoublyLinkedList.prototype.reset.call(this)
227
+ }
228
+
229
+ /**
230
+ * Retrieve a TreeLinker item from this list by numeric index, otherwise return null.
231
+ * @param index The integer number for retrieving a node by position.
232
+ */
233
+ item (index) {
234
+ return _DoublyLinkedList.DoublyLinkedList.prototype.item.call(this, index)
235
+ }
236
+
237
+ /**
238
+ * Be able to run forEach on this LinkedTreeList to iterate over the TreeLinker Items.
239
+ * @param callback The function to call for-each tree node
240
+ * @param thisArg Optional, 'this' reference
241
+ * @returns The list which was iterated.
242
+ */
243
+ forEach (callback, thisArg = this) {
244
+ let index = 0
245
+ let current = thisArg.first
246
+ while (current !== null) {
247
+ callback(current, index, thisArg)
248
+ current = current.next
249
+ ++index
250
+ }
251
+ return thisArg
252
+ }
253
+
254
+ /**
255
+ * Be able to iterate over this class: the linkers of this list and everything below them (left-first). It stays within
256
+ * this list (it does not start at, or climb up to, the parents), use the parseTree service to parse a whole tree.
257
+ */
258
+ [Symbol.iterator] () {
259
+ // The linkers of this list and everything below them, left-first. It stays within this list: it does not start at,
260
+ // or climb up to, the parents (use the parseTree service to parse a whole tree)
261
+ return new _TreeLinkerIterator.TreeLinkerIterator(this.first, this.parent)
262
+ }
263
+ }
264
+ /**
265
+ * Convert an array into a LinkedTreeList instance, return the new instance.
266
+ * @param values An array of values which will be converted to nodes in this tree-list
267
+ * @param linkerClass The class to use for each node
268
+ * @param classType Provide the type of IsArrayable to use.
269
+ */
270
+ exports.LinkedTreeList = LinkedTreeList
271
+ LinkedTreeList.fromArray = (values = [], linkerClass = _TreeLinker.TreeLinker, classType = LinkedTreeList) => {
272
+ const list = new classType(linkerClass)
273
+ return list.initialize(linkerClass.fromArray(values).head)
274
+ }