collect-your-stuff 2.1.2 → 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.
- package/README.md +32 -3926
- package/browser/collect-your-stuff.js +912 -549
- package/browser/collect-your-stuff.min.js +1 -1
- package/dist/collections/arrayable/ArrayElement.d.ts +6 -11
- package/dist/collections/arrayable/ArrayElement.js +5 -7
- package/dist/collections/arrayable/Arrayable.d.ts +22 -37
- package/dist/collections/arrayable/Arrayable.js +208 -223
- package/dist/collections/doubly-linked-list/DoubleLinker.d.ts +9 -14
- package/dist/collections/doubly-linked-list/DoubleLinker.js +71 -73
- package/dist/collections/doubly-linked-list/DoublyLinkedList.d.ts +19 -36
- package/dist/collections/doubly-linked-list/DoublyLinkedList.js +310 -327
- package/dist/collections/linked-list/LinkedList.d.ts +20 -36
- package/dist/collections/linked-list/LinkedList.js +283 -296
- package/dist/collections/linked-list/Linker.d.ts +8 -13
- package/dist/collections/linked-list/Linker.js +82 -84
- package/dist/collections/linked-tree-list/LinkedTreeList.d.ts +24 -43
- package/dist/collections/linked-tree-list/LinkedTreeList.js +274 -294
- package/dist/collections/linked-tree-list/TreeLinker.d.ts +14 -20
- package/dist/collections/linked-tree-list/TreeLinker.js +91 -94
- package/dist/collections/queue/Queue.d.ts +10 -14
- package/dist/collections/queue/Queue.js +114 -121
- package/dist/collections/queue/Queueable.d.ts +13 -22
- package/dist/collections/queue/Queueable.js +142 -148
- package/dist/collections/queue/TaskQueue.d.ts +8 -17
- package/dist/collections/queue/TaskQueue.js +128 -137
- package/dist/collections/scoped-collection/ScopedCollection.d.ts +42 -0
- package/dist/collections/scoped-collection/ScopedCollection.js +81 -0
- package/dist/collections/scoped-collection/ScopedCollection.min.js +1 -0
- package/dist/collections/stack/Stack.d.ts +11 -15
- package/dist/collections/stack/Stack.js +122 -129
- package/dist/collections/stack/Stackable.d.ts +9 -16
- package/dist/collections/stack/Stackable.js +81 -85
- package/dist/collections/stack/TaskStack.d.ts +8 -17
- package/dist/collections/stack/TaskStack.js +98 -107
- package/dist/main.d.ts +67 -68
- package/dist/main.js +8 -4
- package/dist/main.min.js +1 -1
- package/dist/recipes/ArrayIterator.d.ts +4 -4
- package/dist/recipes/ArrayIterator.js +4 -4
- package/dist/recipes/DoubleLinkerIterator.d.ts +3 -3
- package/dist/recipes/DoubleLinkerIterator.js +3 -3
- package/dist/recipes/IsArrayable.d.ts +13 -33
- package/dist/recipes/IsQueue.d.ts +4 -9
- package/dist/recipes/IsScopedCollection.d.ts +27 -0
- package/dist/recipes/IsScopedCollection.js +5 -0
- package/dist/recipes/IsScopedCollection.min.js +1 -0
- package/dist/recipes/IsStack.d.ts +4 -9
- package/dist/recipes/IsTreeNode.d.ts +1 -1
- package/dist/recipes/LinkerIterator.d.ts +3 -3
- package/dist/recipes/LinkerIterator.js +3 -3
- package/dist/recipes/Runnable.d.ts +3 -16
- package/dist/recipes/Runnable.js +3 -9
- package/dist/recipes/TreeLinkerIterator.d.ts +4 -4
- package/dist/recipes/TreeLinkerIterator.js +36 -36
- package/dist/recipes/recipes.d.ts +1 -4
- package/dist/recipes/recipes.js +19 -22
- package/dist/services/parseTree.d.ts +2 -3
- package/dist/services/parseTree.js +23 -24
- package/dist/services/parseTreeNext.d.ts +2 -3
- package/dist/services/parseTreeNext.js +2 -3
- package/dist/services/services.d.ts +1 -4
- package/dist/services/services.js +19 -22
- package/package.json +4 -4
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
-
* @version 1.1.0
|
|
5
|
-
* @memberOf module:collect-your-stuff
|
|
2
|
+
* arrayable list.
|
|
6
3
|
*/
|
|
7
4
|
import { ArrayElement } from './ArrayElement';
|
|
8
5
|
import { forEachCallback, IsArrayable } from '../../recipes/IsArrayable';
|
|
@@ -21,102 +18,90 @@ export declare class Arrayable implements IsArrayable<ArrayElement>, Iterable<Ar
|
|
|
21
18
|
elementClass: typeof ArrayElement;
|
|
22
19
|
/**
|
|
23
20
|
* Create the new Arrayable instance, configure the Arrayable class.
|
|
24
|
-
* @param
|
|
21
|
+
* @param elementClass The class used to wrap given data as elements.
|
|
25
22
|
*/
|
|
26
23
|
constructor(elementClass?: typeof ArrayElement);
|
|
27
24
|
/**
|
|
28
25
|
* Find the position of an element which must be in this list.
|
|
29
|
-
* @param
|
|
30
|
-
* @returns {number}
|
|
26
|
+
* @param node The element to find
|
|
31
27
|
* @throws {Error} When the element is not in this list
|
|
32
28
|
*/
|
|
33
29
|
private indexOfElement;
|
|
34
30
|
/**
|
|
35
31
|
* Initialize the inner list, should only run once.
|
|
36
|
-
* @param
|
|
37
|
-
* @return {Arrayable}
|
|
32
|
+
* @param initialList Give the array of elements to start in this Arrayable.
|
|
38
33
|
*/
|
|
39
34
|
initialize(initialList: Array<ArrayElement>): Arrayable;
|
|
40
35
|
/**
|
|
41
36
|
* Retrieve the innerList used (the list itself, not a copy).
|
|
42
|
-
* @returns {Array<ArrayElement>}
|
|
43
37
|
*/
|
|
44
38
|
get list(): Array<ArrayElement>;
|
|
45
39
|
/**
|
|
46
40
|
* Retrieve the first Element from the Arrayable
|
|
47
|
-
* @returns
|
|
41
|
+
* @returns The first element, or null when the Arrayable is empty
|
|
48
42
|
*/
|
|
49
43
|
get first(): ArrayElement | null;
|
|
50
44
|
/**
|
|
51
45
|
* Retrieve the last Element from the Arrayable
|
|
52
|
-
* @returns
|
|
46
|
+
* @returns The last element, or null when the Arrayable is empty
|
|
53
47
|
*/
|
|
54
48
|
get last(): ArrayElement | null;
|
|
55
49
|
/**
|
|
56
50
|
* Return the length of the list.
|
|
57
|
-
* @returns {number}
|
|
58
51
|
*/
|
|
59
52
|
get length(): number;
|
|
60
53
|
/**
|
|
61
54
|
* Insert a new node (or data) after a node.
|
|
62
|
-
* @param
|
|
63
|
-
* @param
|
|
64
|
-
* @returns {Arrayable}
|
|
55
|
+
* @param node The existing node as reference, or null to insert at the start of the list
|
|
56
|
+
* @param newNode The new node to go after the existing node
|
|
65
57
|
* @throws {Error} When the reference node is not in this list
|
|
66
58
|
*/
|
|
67
59
|
insertAfter(node: ArrayElement | null, newNode: ArrayElement | any): Arrayable;
|
|
68
60
|
/**
|
|
69
61
|
* Insert a new node (or data) before a node.
|
|
70
|
-
* @param
|
|
71
|
-
* @param
|
|
72
|
-
* @returns {Arrayable}
|
|
62
|
+
* @param node The existing node as reference, or null to insert at the end of the list
|
|
63
|
+
* @param newNode The new node to go before the existing node
|
|
73
64
|
* @throws {Error} When the reference node is not in this list
|
|
74
65
|
*/
|
|
75
66
|
insertBefore(node: ArrayElement | null, newNode: ArrayElement | any): Arrayable;
|
|
76
67
|
/**
|
|
77
68
|
* Add a node (or data) after the given (or last) node in the list.
|
|
78
|
-
* @param
|
|
79
|
-
* @param
|
|
80
|
-
* @returns {Arrayable}
|
|
69
|
+
* @param node The new node to add to the end of the list
|
|
70
|
+
* @param after The existing last node
|
|
81
71
|
*/
|
|
82
72
|
append(node: ArrayElement | any, after?: ArrayElement | null): Arrayable;
|
|
83
73
|
/**
|
|
84
74
|
* Add a node (or data) before the given (or first) node in the list.
|
|
85
|
-
* @param
|
|
86
|
-
* @param
|
|
87
|
-
* @returns {Arrayable}
|
|
75
|
+
* @param node The new node to add to the start of the list
|
|
76
|
+
* @param before The existing first node
|
|
88
77
|
*/
|
|
89
78
|
prepend(node: ArrayElement | any, before?: ArrayElement | null): Arrayable;
|
|
90
79
|
/**
|
|
91
80
|
* Remove an element from this arrayable.
|
|
92
|
-
* @param
|
|
93
|
-
* @
|
|
81
|
+
* @param node The node we wish to remove (and it will be returned after removal)
|
|
82
|
+
* @returns The removed node, or null when it was not in this list (nothing is removed)
|
|
94
83
|
*/
|
|
95
84
|
remove(node: ArrayElement): ArrayElement | null;
|
|
96
85
|
/**
|
|
97
86
|
* Retrieve an ArrayElement item from this list by numeric index, otherwise return null.
|
|
98
|
-
* @param
|
|
99
|
-
* @return {ArrayElement|null}
|
|
87
|
+
* @param index The integer number for retrieving a node by position.
|
|
100
88
|
*/
|
|
101
89
|
item(index: number): ArrayElement | null;
|
|
102
90
|
/**
|
|
103
91
|
* Be able to run forEach on this Arrayable to iterate over the elements.
|
|
104
|
-
* @param
|
|
105
|
-
* @param
|
|
106
|
-
* @returns {Arrayable}
|
|
92
|
+
* @param callback The function to call for-each element
|
|
93
|
+
* @param thisArg Optional, 'this' reference
|
|
107
94
|
*/
|
|
108
95
|
forEach(callback: forEachCallback, thisArg?: Arrayable): Arrayable;
|
|
109
96
|
/**
|
|
110
97
|
* Be able to iterate over this class.
|
|
111
|
-
* @returns {Iterator}
|
|
112
98
|
*/
|
|
113
99
|
[Symbol.iterator](): Iterator<ArrayElement>;
|
|
114
100
|
/**
|
|
115
101
|
* Convert an array to an Arrayable.
|
|
116
|
-
* @param
|
|
117
|
-
* @param
|
|
118
|
-
* @param
|
|
119
|
-
* @returns {Arrayable}
|
|
102
|
+
* @param values An array of values which will be converted to elements in this arrayable
|
|
103
|
+
* @param elementClass The class to use for each element
|
|
104
|
+
* @param classType Provide the type of IsArrayable to use.
|
|
120
105
|
*/
|
|
121
106
|
static fromArray: (values?: Array<any>, elementClass?: typeof ArrayElement, classType?: any) => IsArrayable<IsElement>;
|
|
122
107
|
}
|
|
@@ -1,223 +1,208 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.Arrayable = void 0
|
|
7
|
-
const _ArrayElement = require('./ArrayElement')
|
|
8
|
-
const _ArrayIterator = require('../../recipes/ArrayIterator')
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
class
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
this.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
*
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
return
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Be able to
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
return new _ArrayIterator.ArrayIterator(this.innerList, index)
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Convert an array to an Arrayable.
|
|
214
|
-
* @param {Array} values An array of values which will be converted to elements in this arrayable
|
|
215
|
-
* @param {IsElement} [elementClass=ArrayElement] The class to use for each element
|
|
216
|
-
* @param {IsArrayable<ArrayElement>} [classType=Arrayable] Provide the type of IsArrayable to use.
|
|
217
|
-
* @returns {Arrayable}
|
|
218
|
-
*/
|
|
219
|
-
exports.Arrayable = Arrayable
|
|
220
|
-
Arrayable.fromArray = (values = [], elementClass = _ArrayElement.ArrayElement, classType = Arrayable) => {
|
|
221
|
-
const list = new classType(elementClass)
|
|
222
|
-
return list.initialize(elementClass.fromArray(values).head)
|
|
223
|
-
}
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.Arrayable = void 0
|
|
7
|
+
const _ArrayElement = require('./ArrayElement')
|
|
8
|
+
const _ArrayIterator = require('../../recipes/ArrayIterator')
|
|
9
|
+
/**
|
|
10
|
+
* arrayable list.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Arrayable represents a collection stored as an array.
|
|
15
|
+
*/
|
|
16
|
+
class Arrayable {
|
|
17
|
+
/**
|
|
18
|
+
* Create the new Arrayable instance, configure the Arrayable class.
|
|
19
|
+
* @param elementClass The class used to wrap given data as elements.
|
|
20
|
+
*/
|
|
21
|
+
constructor (elementClass = _ArrayElement.ArrayElement) {
|
|
22
|
+
/** The class used to create this instance, so that it can be recognized as valid without an instanceof check. */
|
|
23
|
+
this.classType = Arrayable
|
|
24
|
+
/** The array which stores the elements of this Arrayable. */
|
|
25
|
+
this.innerList = []
|
|
26
|
+
/** Whether the inner list has been initialized (it can only be initialized once). */
|
|
27
|
+
this.initialized = false
|
|
28
|
+
this.elementClass = elementClass
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Find the position of an element which must be in this list.
|
|
33
|
+
* @param node The element to find
|
|
34
|
+
* @throws {Error} When the element is not in this list
|
|
35
|
+
*/
|
|
36
|
+
indexOfElement (node) {
|
|
37
|
+
const index = this.innerList.indexOf(node)
|
|
38
|
+
if (index < 0) {
|
|
39
|
+
throw new Error('The reference element is not in this list.')
|
|
40
|
+
}
|
|
41
|
+
return index
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Initialize the inner list, should only run once.
|
|
46
|
+
* @param initialList Give the array of elements to start in this Arrayable.
|
|
47
|
+
*/
|
|
48
|
+
initialize (initialList) {
|
|
49
|
+
if (this.initialized) {
|
|
50
|
+
console.warn('Attempt to initialize non-empty list.')
|
|
51
|
+
return this
|
|
52
|
+
}
|
|
53
|
+
this.initialized = true
|
|
54
|
+
this.innerList = initialList
|
|
55
|
+
return this
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Retrieve the innerList used (the list itself, not a copy).
|
|
60
|
+
*/
|
|
61
|
+
get list () {
|
|
62
|
+
return this.innerList
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Retrieve the first Element from the Arrayable
|
|
67
|
+
* @returns The first element, or null when the Arrayable is empty
|
|
68
|
+
*/
|
|
69
|
+
get first () {
|
|
70
|
+
return this.length ? this.innerList[0] : null
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Retrieve the last Element from the Arrayable
|
|
75
|
+
* @returns The last element, or null when the Arrayable is empty
|
|
76
|
+
*/
|
|
77
|
+
get last () {
|
|
78
|
+
return this.length ? this.innerList[this.length - 1] : null
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Return the length of the list.
|
|
83
|
+
*/
|
|
84
|
+
get length () {
|
|
85
|
+
return this.innerList.length
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Insert a new node (or data) after a node.
|
|
90
|
+
* @param node The existing node as reference, or null to insert at the start of the list
|
|
91
|
+
* @param newNode The new node to go after the existing node
|
|
92
|
+
* @throws {Error} When the reference node is not in this list
|
|
93
|
+
*/
|
|
94
|
+
insertAfter (node, newNode) {
|
|
95
|
+
// With no reference element, the new one goes after nothing: at the start of the list
|
|
96
|
+
const insertAt = node === null || typeof node === 'undefined' ? -1 : this.indexOfElement(node)
|
|
97
|
+
this.innerList.splice(insertAt + 1, 0, this.elementClass.make(newNode, this.elementClass))
|
|
98
|
+
return this
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Insert a new node (or data) before a node.
|
|
103
|
+
* @param node The existing node as reference, or null to insert at the end of the list
|
|
104
|
+
* @param newNode The new node to go before the existing node
|
|
105
|
+
* @throws {Error} When the reference node is not in this list
|
|
106
|
+
*/
|
|
107
|
+
insertBefore (node, newNode) {
|
|
108
|
+
// With no reference element, the new one goes before nothing: at the end of the list
|
|
109
|
+
const insertAt = node === null || typeof node === 'undefined' ? this.length : this.indexOfElement(node)
|
|
110
|
+
this.innerList.splice(insertAt, 0, this.elementClass.make(newNode, this.elementClass))
|
|
111
|
+
return this
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Add a node (or data) after the given (or last) node in the list.
|
|
116
|
+
* @param node The new node to add to the end of the list
|
|
117
|
+
* @param after The existing last node
|
|
118
|
+
*/
|
|
119
|
+
append (node, after = this.last) {
|
|
120
|
+
if (after === this.last) {
|
|
121
|
+
// Adding to the end does not need to search for where that is
|
|
122
|
+
this.innerList.push(this.elementClass.make(node, this.elementClass))
|
|
123
|
+
return this
|
|
124
|
+
}
|
|
125
|
+
return this.insertAfter(after, node)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Add a node (or data) before the given (or first) node in the list.
|
|
130
|
+
* @param node The new node to add to the start of the list
|
|
131
|
+
* @param before The existing first node
|
|
132
|
+
*/
|
|
133
|
+
prepend (node, before = this.first) {
|
|
134
|
+
if (before === this.first) {
|
|
135
|
+
// Adding to the start does not need to search for where that is
|
|
136
|
+
this.innerList.unshift(this.elementClass.make(node, this.elementClass))
|
|
137
|
+
return this
|
|
138
|
+
}
|
|
139
|
+
return this.insertBefore(before, node)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Remove an element from this arrayable.
|
|
144
|
+
* @param node The node we wish to remove (and it will be returned after removal)
|
|
145
|
+
* @returns The removed node, or null when it was not in this list (nothing is removed)
|
|
146
|
+
*/
|
|
147
|
+
remove (node) {
|
|
148
|
+
const deleteAt = this.innerList.indexOf(node)
|
|
149
|
+
if (deleteAt < 0) {
|
|
150
|
+
return null
|
|
151
|
+
}
|
|
152
|
+
this.innerList.splice(deleteAt, 1)
|
|
153
|
+
return node
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Retrieve an ArrayElement item from this list by numeric index, otherwise return null.
|
|
158
|
+
* @param index The integer number for retrieving a node by position.
|
|
159
|
+
*/
|
|
160
|
+
item (index) {
|
|
161
|
+
if (index >= this.length) {
|
|
162
|
+
// index is beyond array limit
|
|
163
|
+
return null
|
|
164
|
+
}
|
|
165
|
+
if (index >= 0) {
|
|
166
|
+
// use the positive index at nth position from the beginning of the array
|
|
167
|
+
return this.innerList[index]
|
|
168
|
+
}
|
|
169
|
+
const calculatedIndex = this.length + index
|
|
170
|
+
if (calculatedIndex < 0) {
|
|
171
|
+
// negative index is beyond array limit (minus direction)
|
|
172
|
+
return null
|
|
173
|
+
}
|
|
174
|
+
// Return the item at nth position from the end of the array
|
|
175
|
+
return this.innerList[calculatedIndex]
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Be able to run forEach on this Arrayable to iterate over the elements.
|
|
180
|
+
* @param callback The function to call for-each element
|
|
181
|
+
* @param thisArg Optional, 'this' reference
|
|
182
|
+
*/
|
|
183
|
+
forEach (callback, thisArg = this) {
|
|
184
|
+
for (let i = 0; i < thisArg.length; ++i) {
|
|
185
|
+
callback(thisArg.item(i), i, thisArg)
|
|
186
|
+
}
|
|
187
|
+
return thisArg
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Be able to iterate over this class.
|
|
192
|
+
*/
|
|
193
|
+
[Symbol.iterator] () {
|
|
194
|
+
const index = 0
|
|
195
|
+
return new _ArrayIterator.ArrayIterator(this.innerList, index)
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Convert an array to an Arrayable.
|
|
200
|
+
* @param values An array of values which will be converted to elements in this arrayable
|
|
201
|
+
* @param elementClass The class to use for each element
|
|
202
|
+
* @param classType Provide the type of IsArrayable to use.
|
|
203
|
+
*/
|
|
204
|
+
exports.Arrayable = Arrayable
|
|
205
|
+
Arrayable.fromArray = (values = [], elementClass = _ArrayElement.ArrayElement, classType = Arrayable) => {
|
|
206
|
+
const list = new classType(elementClass)
|
|
207
|
+
return list.initialize(elementClass.fromArray(values).head)
|
|
208
|
+
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
-
* @version 1.1.0
|
|
5
|
-
* @memberOf module:collect-your-stuff
|
|
2
|
+
* doubly linked list item.
|
|
6
3
|
*/
|
|
7
4
|
import { IsDoubleLinker } from '../../recipes/IsDoubleLinker';
|
|
8
5
|
/**
|
|
@@ -20,10 +17,10 @@ export declare class DoubleLinker implements IsDoubleLinker {
|
|
|
20
17
|
prev: DoubleLinker | null;
|
|
21
18
|
/**
|
|
22
19
|
* Create the new DoubleLinker instance, provide the data and optionally the next and prev references.
|
|
23
|
-
* @param
|
|
24
|
-
* @param
|
|
25
|
-
* @param
|
|
26
|
-
* @param
|
|
20
|
+
* @param nodeData The settings for the new linker.
|
|
21
|
+
* @param nodeData.data The data to be stored in this linker
|
|
22
|
+
* @param nodeData.next The reference to the next linker if any
|
|
23
|
+
* @param nodeData.prev The reference to the previous linker if any
|
|
27
24
|
*/
|
|
28
25
|
constructor({ data, next, prev }?: {
|
|
29
26
|
data?: any;
|
|
@@ -32,16 +29,14 @@ export declare class DoubleLinker implements IsDoubleLinker {
|
|
|
32
29
|
});
|
|
33
30
|
/**
|
|
34
31
|
* Make a new DoubleLinker from the data given if it is not already a valid Linker.
|
|
35
|
-
* @param
|
|
36
|
-
* @param
|
|
37
|
-
* @return {DoubleLinker}
|
|
32
|
+
* @param linker Return a valid Linker instance from given data, or even an already valid one.
|
|
33
|
+
* @param classType Provide the type of IsDoubleLinker to use.
|
|
38
34
|
*/
|
|
39
35
|
static make: (linker: DoubleLinker | any, classType?: any) => IsDoubleLinker | any;
|
|
40
36
|
/**
|
|
41
37
|
* Convert an array into DoubleLinker instances, return the head and tail DoubleLinkers.
|
|
42
|
-
* @param
|
|
43
|
-
* @param
|
|
44
|
-
* @returns {{head: DoubleLinker, tail: DoubleLinker}}
|
|
38
|
+
* @param values Provide an array of data that will be converted to a chain of linkers.
|
|
39
|
+
* @param classType Provide the type of IsDoubleLinker to use.
|
|
45
40
|
*/
|
|
46
41
|
static fromArray: (values?: Array<any>, classType?: any) => {
|
|
47
42
|
head: DoubleLinker | any;
|