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