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,146 +1,142 @@
1
- 'use strict'
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true
5
- })
6
- exports.Queueable = void 0
7
- var _Linker = require('../linked-list/Linker')
8
- /**
9
- * Queueable represents a runnable entry in a queue.
10
- * @extends Linker
11
- */
12
- class Queueable {
13
- /**
14
- * Create a queueable item that can be used in a queue.
15
- * @param {Object} [queueableData={}] The settings for the new queueable.
16
- * @param {*} [queueableData.task=null] The data to be stored in this queueable
17
- * @param {Queueable|null} [queueableData.next=null] The reference to the next queueable if any
18
- * @param {boolean|Function} [queueableData.ready=false] Indicate if the queueable is ready to run
19
- */
20
- constructor ({
21
- task = null,
22
- next = null,
23
- ready = false
24
- } = {}) {
25
- /** The task (or data) this queueable holds. */
26
- this.data = null
27
- /** The queueable after this one, or null when this is the last. */
28
- this.next = null
29
- /** Whether this queueable has been run to completion. */
30
- this.complete = false
31
- /** Whether this queueable may run, or a function which answers that when asked. */
32
- this.ready = false
33
- /** Whether this queueable is running right now. */
34
- this.running = false
35
- this.classType = Queueable
36
- this.data = task
37
- this.next = next
38
- this.complete = false
39
- this.ready = ready
40
- this.running = false
41
- }
42
-
43
- /**
44
- * Check ready state.
45
- * @return {boolean}
46
- */
47
- get isReady () {
48
- return typeof this.ready === 'function' ? this.ready() : this.ready
49
- }
50
-
51
- /**
52
- * Retrieve the data which should be formed as a task.
53
- * @return {*}
54
- */
55
- get task () {
56
- if (typeof this.data === 'function') {
57
- return this.data
58
- }
59
- return complete => typeof complete === 'function' ? complete({
60
- context: this.data
61
- }).context : this.data
62
- }
63
-
64
- /**
65
- * Set this queueable as completed.
66
- * @param {Object} [completeResponse={}] The result to report for the task.
67
- * @param {*} [completeResponse.success=true] Indicate when the task failed (use false) or give a success message
68
- * @param {*} [completeResponse.error=false] Indicate a task was error-free (use false) or give an error message
69
- * @param {*} [completeResponse.context=null] Provide additional data in the response
70
- * @return {completeResponse}
71
- */
72
- markCompleted ({
73
- success = true,
74
- error = false,
75
- context = null
76
- } = {}) {
77
- this.complete = true
78
- this.running = false
79
- return {
80
- success: success,
81
- error: error,
82
- context: context
83
- }
84
- }
85
-
86
- /**
87
- * Intend to run the queued task when it is ready. If ready, mark this task as running and run the task.
88
- * @return {completeResponse}
89
- */
90
- run () {
91
- if (!this.isReady) {
92
- // Not yet ready, return with errors
93
- return {
94
- success: false,
95
- error: 'Task is not ready',
96
- context: this.data
97
- }
98
- }
99
- if (this.running) {
100
- // Already running, return error since we cannot run again
101
- return {
102
- success: false,
103
- error: 'Queued task is already running, possible missing \'complete\' callback',
104
- context: this.data
105
- }
106
- }
107
- this.running = true
108
- // Wrap the task in the markCompleted function, so we can set flags and format the response
109
- return this.task(this.markCompleted.bind(this))
110
- }
111
- }
112
- /**
113
- * Make a new Queueable from the data given if it is not already a valid Queueable.
114
- * @param {Queueable|*} queueable Return a valid Queueable instance from given data, or even an already valid one.
115
- * @param {IsLinker} [classType=Queueable] Provide the type of IsLinker to use.
116
- * @return {Queueable}
117
- */
118
- exports.Queueable = Queueable
119
- Queueable.make = (queueable, classType = Queueable) => {
120
- if (queueable === null || typeof queueable !== 'object') {
121
- // It is not an object (or it is null), so instantiate the Queueable with an element as the data
122
- return new classType({
123
- task: queueable,
124
- ready: true
125
- })
126
- }
127
- if (queueable.classType) {
128
- // Already valid Queueable, return as-is
129
- return queueable
130
- }
131
- if (!('task' in queueable)) {
132
- queueable = {
133
- task: queueable,
134
- ready: true
135
- }
136
- }
137
- // Create the new node as the configured #classType
138
- return new classType(queueable)
139
- }
140
- /**
141
- * Convert an array into Queueable instances, return the head and tail Queueables.
142
- * @param {Array} values Provide an array of data that will be converted to a chain of queueable linkers.
143
- * @param {IsLinker} [classType=Queueable] Provide the type of IsLinker to use.
144
- * @returns {{head: Queueable, tail: Queueable}}
145
- */
146
- Queueable.fromArray = (values = [], classType = Queueable) => _Linker.Linker.fromArray(values, classType)
1
+ 'use strict'
2
+
3
+ Object.defineProperty(exports, '__esModule', {
4
+ value: true
5
+ })
6
+ exports.Queueable = void 0
7
+ const _Linker = require('../linked-list/Linker')
8
+ /**
9
+ * Queueable represents a runnable entry in a queue.
10
+ * @extends Linker
11
+ */
12
+ class Queueable {
13
+ /**
14
+ * Create a queueable item that can be used in a queue.
15
+ * @param queueableData The settings for the new queueable.
16
+ * @param queueableData.task The data to be stored in this queueable
17
+ * @param queueableData.next The reference to the next queueable if any
18
+ * @param queueableData.ready Indicate if the queueable is ready to run
19
+ */
20
+ constructor ({
21
+ task = null,
22
+ next = null,
23
+ ready = false
24
+ } = {}) {
25
+ /** The task (or data) this queueable holds. */
26
+ this.data = null
27
+ /** The queueable after this one, or null when this is the last. */
28
+ this.next = null
29
+ /** Whether this queueable has been run to completion. */
30
+ this.complete = false
31
+ /** Whether this queueable may run, or a function which answers that when asked. */
32
+ this.ready = false
33
+ /** Whether this queueable is running right now. */
34
+ this.running = false
35
+ this.classType = Queueable
36
+ this.data = task
37
+ this.next = next
38
+ this.complete = false
39
+ this.ready = ready
40
+ this.running = false
41
+ }
42
+
43
+ /**
44
+ * Check ready state.
45
+ */
46
+ get isReady () {
47
+ return typeof this.ready === 'function' ? this.ready() : this.ready
48
+ }
49
+
50
+ /**
51
+ * Retrieve the data which should be formed as a task.
52
+ */
53
+ get task () {
54
+ if (typeof this.data === 'function') {
55
+ return this.data
56
+ }
57
+ return complete => typeof complete === 'function'
58
+ ? complete({
59
+ context: this.data
60
+ }).context
61
+ : this.data
62
+ }
63
+
64
+ /**
65
+ * Set this queueable as completed.
66
+ * @param completeResponse The result to report for the task.
67
+ * @param completeResponse.success Indicate when the task failed (use false) or give a success message
68
+ * @param completeResponse.error Indicate a task was error-free (use false) or give an error message
69
+ * @param completeResponse.context Provide additional data in the response
70
+ */
71
+ markCompleted ({
72
+ success = true,
73
+ error = false,
74
+ context = null
75
+ } = {}) {
76
+ this.complete = true
77
+ this.running = false
78
+ return {
79
+ success,
80
+ error,
81
+ context
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Intend to run the queued task when it is ready. If ready, mark this task as running and run the task.
87
+ */
88
+ run () {
89
+ if (!this.isReady) {
90
+ // Not yet ready, return with errors
91
+ return {
92
+ success: false,
93
+ error: 'Task is not ready',
94
+ context: this.data
95
+ }
96
+ }
97
+ if (this.running) {
98
+ // Already running, return error since we cannot run again
99
+ return {
100
+ success: false,
101
+ error: 'Queued task is already running, possible missing \'complete\' callback',
102
+ context: this.data
103
+ }
104
+ }
105
+ this.running = true
106
+ // Wrap the task in the markCompleted function, so we can set flags and format the response
107
+ return this.task(this.markCompleted.bind(this))
108
+ }
109
+ }
110
+ /**
111
+ * Make a new Queueable from the data given if it is not already a valid Queueable.
112
+ * @param queueable Return a valid Queueable instance from given data, or even an already valid one.
113
+ * @param classType Provide the type of IsLinker to use.
114
+ */
115
+ exports.Queueable = Queueable
116
+ Queueable.make = (queueable, classType = Queueable) => {
117
+ if (queueable === null || typeof queueable !== 'object') {
118
+ // It is not an object (or it is null), so instantiate the Queueable with an element as the data
119
+ return new classType({
120
+ task: queueable,
121
+ ready: true
122
+ })
123
+ }
124
+ if (queueable.classType) {
125
+ // Already valid Queueable, return as-is
126
+ return queueable
127
+ }
128
+ if (!('task' in queueable)) {
129
+ queueable = {
130
+ task: queueable,
131
+ ready: true
132
+ }
133
+ }
134
+ // Create the new node as the configured #classType
135
+ return new classType(queueable)
136
+ }
137
+ /**
138
+ * Convert an array into Queueable instances, return the head and tail Queueables.
139
+ * @param values Provide an array of data that will be converted to a chain of queueable linkers.
140
+ * @param classType Provide the type of IsLinker to use.
141
+ */
142
+ Queueable.fromArray = (values = [], classType = Queueable) => _Linker.Linker.fromArray(values, classType)
@@ -1,68 +1,59 @@
1
- /**
2
- * @file task queue
3
- * @author Joshua Heagle <joshuaheagle@gmail.com>
4
- * @version 1.1.0
5
- * @memberOf module:collect-your-stuff
6
- */
7
- import { Queueable } from './Queueable';
8
- import { IsArrayable } from '../../recipes/IsArrayable';
9
- import { IsLinker } from '../../recipes/IsLinker';
10
- import { completeResponse } from '../../recipes/Runnable';
11
- /**
12
- * Maintain a series of queued tasks (Queueables): dequeue() takes the next task from the front and RUNS it, giving each
13
- * task in turn a chance to run (a task which is not ready, or which has not finished, is placed at the back again).
14
- * This is a task scheduler, for a plain first-in-first-out collection of items use Queue.
15
- */
16
- export declare class TaskQueue {
17
- /** The list which stores the queueables, the first is next to be dequeued. */
18
- queuedList: IsArrayable<any>;
19
- private listClass;
20
- private queueableClass;
21
- /**
22
- * Instantiate the queue with the given queue list.
23
- * @param {Iterable|LinkedList} queuedList Give the list of queueables to start in this queue.
24
- * @param {IsArrayable} [listClass=LinkedList] The type of list to create when no queued list is given.
25
- * @param {Queueable} [queueableClass=Queueable] The class used to wrap queued items.
26
- */
27
- constructor(queuedList?: IsArrayable<any>, listClass?: any, queueableClass?: typeof Queueable);
28
- /**
29
- * Take a queued task from the front of the queue and run it if ready. A task which is not ready yet is kept in the
30
- * queue (never dropped), a task which is still running is reported as blocking and left to finish on its own, and
31
- * completed tasks are discarded.
32
- * @return {completeResponse|*}
33
- */
34
- dequeue(): completeResponse | any;
35
- /**
36
- * Return true if the queue is empty (there are no tasks in the queue list)
37
- * @return {boolean}
38
- */
39
- empty(): boolean;
40
- /**
41
- * Add a queued task to the end of the queue
42
- * @param {Queueable} queueable Add a new queueable to the end of the queue
43
- */
44
- enqueue(queueable: Queueable): void;
45
- /**
46
- * Take a look at the next queued task
47
- * @return {Queueable}
48
- */
49
- peek(): IsLinker;
50
- /**
51
- * Remove the next queued item and return it.
52
- * @return {Queueable|null}
53
- */
54
- remove(): Queueable | null;
55
- /**
56
- * Get the length of the current queue.
57
- * @return {number}
58
- */
59
- size(): number;
60
- /**
61
- * Convert an array to a TaskQueue.
62
- * @param {Array} values An array of values which will be converted to queueables in this queue
63
- * @param {Queueable} queueableClass The class to use for each queueable
64
- * @param {TaskQueue|Iterable} listClass The class to use to manage the queueables
65
- * @returns {TaskQueue}
66
- */
67
- static fromArray: (values?: Array<any>, queueableClass?: typeof Queueable, listClass?: any) => TaskQueue;
68
- }
1
+ /**
2
+ * task queue
3
+ */
4
+ import { Queueable } from './Queueable';
5
+ import { IsArrayable } from '../../recipes/IsArrayable';
6
+ import { IsLinker } from '../../recipes/IsLinker';
7
+ import { completeResponse } from '../../recipes/Runnable';
8
+ /**
9
+ * Maintain a series of queued tasks (Queueables): dequeue() takes the next task from the front and RUNS it, giving each
10
+ * task in turn a chance to run (a task which is not ready, or which has not finished, is placed at the back again).
11
+ * This is a task scheduler, for a plain first-in-first-out collection of items use Queue.
12
+ */
13
+ export declare class TaskQueue {
14
+ /** The list which stores the queueables, the first is next to be dequeued. */
15
+ queuedList: IsArrayable<any>;
16
+ private listClass;
17
+ private queueableClass;
18
+ /**
19
+ * Instantiate the queue with the given queue list.
20
+ * @param queuedList Give the list of queueables to start in this queue.
21
+ * @param listClass The type of list to create when no queued list is given.
22
+ * @param queueableClass The class used to wrap queued items.
23
+ */
24
+ constructor(queuedList?: IsArrayable<any>, listClass?: any, queueableClass?: typeof Queueable);
25
+ /**
26
+ * Take a queued task from the front of the queue and run it if ready. A task which is not ready yet is kept in the
27
+ * queue (never dropped), a task which is still running is reported as blocking and left to finish on its own, and
28
+ * completed tasks are discarded.
29
+ */
30
+ dequeue(): completeResponse | any;
31
+ /**
32
+ * Return true if the queue is empty (there are no tasks in the queue list)
33
+ */
34
+ empty(): boolean;
35
+ /**
36
+ * Add a queued task to the end of the queue
37
+ * @param queueable Add a new queueable to the end of the queue
38
+ */
39
+ enqueue(queueable: Queueable): void;
40
+ /**
41
+ * Take a look at the next queued task
42
+ */
43
+ peek(): IsLinker;
44
+ /**
45
+ * Remove the next queued item and return it.
46
+ */
47
+ remove(): Queueable | null;
48
+ /**
49
+ * Get the length of the current queue.
50
+ */
51
+ size(): number;
52
+ /**
53
+ * Convert an array to a TaskQueue.
54
+ * @param values An array of values which will be converted to queueables in this queue
55
+ * @param queueableClass The class to use for each queueable
56
+ * @param listClass The class to use to manage the queueables
57
+ */
58
+ static fromArray: (values?: Array<any>, queueableClass?: typeof Queueable, listClass?: any) => TaskQueue;
59
+ }