collect-your-stuff 2.1.1 → 2.1.2
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 +898 -213
- package/browser/collect-your-stuff.js +677 -648
- package/browser/collect-your-stuff.min.js +1 -1
- package/dist/collections/arrayable/ArrayElement.d.ts +38 -38
- package/dist/collections/arrayable/ArrayElement.js +66 -66
- package/dist/collections/arrayable/Arrayable.d.ts +122 -122
- package/dist/collections/arrayable/Arrayable.js +2 -2
- package/dist/collections/doubly-linked-list/DoubleLinker.d.ts +50 -50
- package/dist/collections/doubly-linked-list/DoubleLinker.js +1 -1
- package/dist/collections/doubly-linked-list/DoublyLinkedList.d.ts +125 -125
- package/dist/collections/doubly-linked-list/DoublyLinkedList.js +3 -3
- package/dist/collections/linked-list/LinkedList.d.ts +126 -126
- package/dist/collections/linked-list/LinkedList.js +3 -3
- package/dist/collections/linked-list/Linker.d.ts +46 -46
- package/dist/collections/linked-list/Linker.js +1 -1
- package/dist/collections/linked-tree-list/LinkedTreeList.d.ts +159 -159
- package/dist/collections/linked-tree-list/LinkedTreeList.js +3 -3
- package/dist/collections/linked-tree-list/TreeLinker.d.ts +71 -71
- package/dist/collections/linked-tree-list/TreeLinker.js +2 -2
- package/dist/collections/queue/Queue.d.ts +59 -59
- package/dist/collections/queue/Queue.js +11 -9
- package/dist/collections/queue/Queueable.d.ts +83 -83
- package/dist/collections/queue/Queueable.js +9 -7
- package/dist/collections/queue/TaskQueue.d.ts +68 -68
- package/dist/collections/queue/TaskQueue.js +2 -2
- package/dist/collections/stack/Stack.d.ts +64 -64
- package/dist/collections/stack/Stack.js +11 -9
- package/dist/collections/stack/Stackable.d.ts +59 -59
- package/dist/collections/stack/Stackable.js +1 -1
- package/dist/collections/stack/TaskStack.d.ts +65 -65
- package/dist/collections/stack/TaskStack.js +2 -2
- package/dist/main.d.ts +68 -68
- package/dist/main.js +1 -1
- package/dist/recipes/ArrayIterator.d.ts +20 -20
- package/dist/recipes/ArrayIterator.js +39 -39
- package/dist/recipes/DoubleLinkerIterator.d.ts +18 -18
- package/dist/recipes/DoubleLinkerIterator.js +33 -33
- package/dist/recipes/IsArrayable.d.ts +105 -105
- package/dist/recipes/IsArrayable.js +5 -5
- package/dist/recipes/IsDoubleLinker.d.ts +14 -14
- package/dist/recipes/IsDoubleLinker.js +5 -5
- package/dist/recipes/IsElement.d.ts +14 -14
- package/dist/recipes/IsElement.js +5 -5
- package/dist/recipes/IsLinker.d.ts +10 -10
- package/dist/recipes/IsLinker.js +5 -5
- package/dist/recipes/IsQueue.d.ts +37 -37
- package/dist/recipes/IsQueue.js +5 -5
- package/dist/recipes/IsStack.d.ts +36 -36
- package/dist/recipes/IsStack.js +5 -5
- package/dist/recipes/IsTree.d.ts +11 -11
- package/dist/recipes/IsTree.js +5 -5
- package/dist/recipes/IsTreeNode.d.ts +29 -29
- package/dist/recipes/IsTreeNode.js +5 -5
- package/dist/recipes/LinkerIterator.d.ts +18 -18
- package/dist/recipes/LinkerIterator.js +33 -33
- package/dist/recipes/Runnable.d.ts +55 -55
- package/dist/recipes/Runnable.js +69 -69
- package/dist/recipes/TreeLinkerIterator.d.ts +20 -20
- package/dist/recipes/TreeLinkerIterator.js +1 -1
- package/dist/recipes/recipes.d.ts +15 -15
- package/dist/recipes/recipes.js +2 -2
- package/dist/services/parseTree.d.ts +9 -9
- package/dist/services/parseTree.js +1 -1
- package/dist/services/parseTreeNext.d.ts +17 -17
- package/dist/services/parseTreeNext.js +42 -42
- package/dist/services/services.d.ts +13 -13
- package/dist/services/services.js +2 -2
- package/package.json +2 -2
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file queueable item.
|
|
3
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
-
* @version 1.1.0
|
|
5
|
-
* @memberOf module:collect-your-stuff
|
|
6
|
-
*/
|
|
7
|
-
import { completeResponse, IsRunnable } from '../../recipes/Runnable';
|
|
8
|
-
import { IsLinker } from '../../recipes/IsLinker';
|
|
9
|
-
/**
|
|
10
|
-
* Queueable represents a runnable entry in a queue.
|
|
11
|
-
* @extends Linker
|
|
12
|
-
*/
|
|
13
|
-
export declare class Queueable implements IsLinker, IsRunnable {
|
|
14
|
-
/** The class used to create this instance, so that it can be recognized as valid without an instanceof check. */
|
|
15
|
-
readonly classType: typeof Queueable;
|
|
16
|
-
/** The task (or data) this queueable holds. */
|
|
17
|
-
data: any;
|
|
18
|
-
/** The queueable after this one, or null when this is the last. */
|
|
19
|
-
next: Queueable | null;
|
|
20
|
-
/** Whether this queueable has been run to completion. */
|
|
21
|
-
complete: boolean;
|
|
22
|
-
/** Whether this queueable may run, or a function which answers that when asked. */
|
|
23
|
-
ready: Function | boolean;
|
|
24
|
-
/** Whether this queueable is running right now. */
|
|
25
|
-
running: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Create a queueable item that can be used in a queue.
|
|
28
|
-
* @param {Object} [queueableData={}] The settings for the new queueable.
|
|
29
|
-
* @param {*} [queueableData.task=null] The data to be stored in this queueable
|
|
30
|
-
* @param {Queueable|null} [queueableData.next=null] The reference to the next queueable if any
|
|
31
|
-
* @param {boolean|Function} [queueableData.ready=false] Indicate if the queueable is ready to run
|
|
32
|
-
*/
|
|
33
|
-
constructor({ task, next, ready }?: {
|
|
34
|
-
task?: any;
|
|
35
|
-
next?: Queueable | null;
|
|
36
|
-
ready?: boolean | Function;
|
|
37
|
-
});
|
|
38
|
-
/**
|
|
39
|
-
* Check ready state.
|
|
40
|
-
* @return {boolean}
|
|
41
|
-
*/
|
|
42
|
-
get isReady(): boolean;
|
|
43
|
-
/**
|
|
44
|
-
* Retrieve the data which should be formed as a task.
|
|
45
|
-
* @return {*}
|
|
46
|
-
*/
|
|
47
|
-
get task(): any;
|
|
48
|
-
/**
|
|
49
|
-
* Set this queueable as completed.
|
|
50
|
-
* @param {Object} [completeResponse={}] The result to report for the task.
|
|
51
|
-
* @param {*} [completeResponse.success=true] Indicate when the task failed (use false) or give a success message
|
|
52
|
-
* @param {*} [completeResponse.error=false] Indicate a task was error-free (use false) or give an error message
|
|
53
|
-
* @param {*} [completeResponse.context=null] Provide additional data in the response
|
|
54
|
-
* @return {completeResponse}
|
|
55
|
-
*/
|
|
56
|
-
markCompleted({ success, error, context }?: {
|
|
57
|
-
success?: any;
|
|
58
|
-
error?: any;
|
|
59
|
-
context?: any;
|
|
60
|
-
}): completeResponse;
|
|
61
|
-
/**
|
|
62
|
-
* Intend to run the queued task when it is ready. If ready, mark this task as running and run the task.
|
|
63
|
-
* @return {completeResponse}
|
|
64
|
-
*/
|
|
65
|
-
run(): completeResponse;
|
|
66
|
-
/**
|
|
67
|
-
* Make a new Queueable from the data given if it is not already a valid Queueable.
|
|
68
|
-
* @param {Queueable|*} queueable Return a valid Queueable instance from given data, or even an already valid one.
|
|
69
|
-
* @param {IsLinker} [classType=Queueable] Provide the type of IsLinker to use.
|
|
70
|
-
* @return {Queueable}
|
|
71
|
-
*/
|
|
72
|
-
static make: (queueable: Queueable | any, classType?: any) => IsLinker;
|
|
73
|
-
/**
|
|
74
|
-
* Convert an array into Queueable instances, return the head and tail Queueables.
|
|
75
|
-
* @param {Array} values Provide an array of data that will be converted to a chain of queueable linkers.
|
|
76
|
-
* @param {IsLinker} [classType=Queueable] Provide the type of IsLinker to use.
|
|
77
|
-
* @returns {{head: Queueable, tail: Queueable}}
|
|
78
|
-
*/
|
|
79
|
-
static fromArray: (values?: Array<any>, classType?: any) => {
|
|
80
|
-
head: IsLinker;
|
|
81
|
-
tail: IsLinker;
|
|
82
|
-
};
|
|
83
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @file queueable item.
|
|
3
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
+
* @version 1.1.0
|
|
5
|
+
* @memberOf module:collect-your-stuff
|
|
6
|
+
*/
|
|
7
|
+
import { completeResponse, IsRunnable } from '../../recipes/Runnable';
|
|
8
|
+
import { IsLinker } from '../../recipes/IsLinker';
|
|
9
|
+
/**
|
|
10
|
+
* Queueable represents a runnable entry in a queue.
|
|
11
|
+
* @extends Linker
|
|
12
|
+
*/
|
|
13
|
+
export declare class Queueable implements IsLinker, IsRunnable {
|
|
14
|
+
/** The class used to create this instance, so that it can be recognized as valid without an instanceof check. */
|
|
15
|
+
readonly classType: typeof Queueable;
|
|
16
|
+
/** The task (or data) this queueable holds. */
|
|
17
|
+
data: any;
|
|
18
|
+
/** The queueable after this one, or null when this is the last. */
|
|
19
|
+
next: Queueable | null;
|
|
20
|
+
/** Whether this queueable has been run to completion. */
|
|
21
|
+
complete: boolean;
|
|
22
|
+
/** Whether this queueable may run, or a function which answers that when asked. */
|
|
23
|
+
ready: Function | boolean;
|
|
24
|
+
/** Whether this queueable is running right now. */
|
|
25
|
+
running: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Create a queueable item that can be used in a queue.
|
|
28
|
+
* @param {Object} [queueableData={}] The settings for the new queueable.
|
|
29
|
+
* @param {*} [queueableData.task=null] The data to be stored in this queueable
|
|
30
|
+
* @param {Queueable|null} [queueableData.next=null] The reference to the next queueable if any
|
|
31
|
+
* @param {boolean|Function} [queueableData.ready=false] Indicate if the queueable is ready to run
|
|
32
|
+
*/
|
|
33
|
+
constructor({ task, next, ready }?: {
|
|
34
|
+
task?: any;
|
|
35
|
+
next?: Queueable | null;
|
|
36
|
+
ready?: boolean | Function;
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* Check ready state.
|
|
40
|
+
* @return {boolean}
|
|
41
|
+
*/
|
|
42
|
+
get isReady(): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Retrieve the data which should be formed as a task.
|
|
45
|
+
* @return {*}
|
|
46
|
+
*/
|
|
47
|
+
get task(): any;
|
|
48
|
+
/**
|
|
49
|
+
* Set this queueable as completed.
|
|
50
|
+
* @param {Object} [completeResponse={}] The result to report for the task.
|
|
51
|
+
* @param {*} [completeResponse.success=true] Indicate when the task failed (use false) or give a success message
|
|
52
|
+
* @param {*} [completeResponse.error=false] Indicate a task was error-free (use false) or give an error message
|
|
53
|
+
* @param {*} [completeResponse.context=null] Provide additional data in the response
|
|
54
|
+
* @return {completeResponse}
|
|
55
|
+
*/
|
|
56
|
+
markCompleted({ success, error, context }?: {
|
|
57
|
+
success?: any;
|
|
58
|
+
error?: any;
|
|
59
|
+
context?: any;
|
|
60
|
+
}): completeResponse;
|
|
61
|
+
/**
|
|
62
|
+
* Intend to run the queued task when it is ready. If ready, mark this task as running and run the task.
|
|
63
|
+
* @return {completeResponse}
|
|
64
|
+
*/
|
|
65
|
+
run(): completeResponse;
|
|
66
|
+
/**
|
|
67
|
+
* Make a new Queueable from the data given if it is not already a valid Queueable.
|
|
68
|
+
* @param {Queueable|*} queueable Return a valid Queueable instance from given data, or even an already valid one.
|
|
69
|
+
* @param {IsLinker} [classType=Queueable] Provide the type of IsLinker to use.
|
|
70
|
+
* @return {Queueable}
|
|
71
|
+
*/
|
|
72
|
+
static make: (queueable: Queueable | any, classType?: any) => IsLinker;
|
|
73
|
+
/**
|
|
74
|
+
* Convert an array into Queueable instances, return the head and tail Queueables.
|
|
75
|
+
* @param {Array} values Provide an array of data that will be converted to a chain of queueable linkers.
|
|
76
|
+
* @param {IsLinker} [classType=Queueable] Provide the type of IsLinker to use.
|
|
77
|
+
* @returns {{head: Queueable, tail: Queueable}}
|
|
78
|
+
*/
|
|
79
|
+
static fromArray: (values?: Array<any>, classType?: any) => {
|
|
80
|
+
head: IsLinker;
|
|
81
|
+
tail: IsLinker;
|
|
82
|
+
};
|
|
83
|
+
}
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', {
|
|
|
4
4
|
value: true
|
|
5
5
|
})
|
|
6
6
|
exports.Queueable = void 0
|
|
7
|
-
|
|
7
|
+
const _Linker = require('../linked-list/Linker')
|
|
8
8
|
/**
|
|
9
9
|
* Queueable represents a runnable entry in a queue.
|
|
10
10
|
* @extends Linker
|
|
@@ -56,9 +56,11 @@ class Queueable {
|
|
|
56
56
|
if (typeof this.data === 'function') {
|
|
57
57
|
return this.data
|
|
58
58
|
}
|
|
59
|
-
return complete => typeof complete === 'function'
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
return complete => typeof complete === 'function'
|
|
60
|
+
? complete({
|
|
61
|
+
context: this.data
|
|
62
|
+
}).context
|
|
63
|
+
: this.data
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
/**
|
|
@@ -77,9 +79,9 @@ class Queueable {
|
|
|
77
79
|
this.complete = true
|
|
78
80
|
this.running = false
|
|
79
81
|
return {
|
|
80
|
-
success
|
|
81
|
-
error
|
|
82
|
-
context
|
|
82
|
+
success,
|
|
83
|
+
error,
|
|
84
|
+
context
|
|
83
85
|
}
|
|
84
86
|
}
|
|
85
87
|
|
|
@@ -1,68 +1,68 @@
|
|
|
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
|
+
* @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
|
+
}
|
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, '__esModule', {
|
|
|
4
4
|
value: true
|
|
5
5
|
})
|
|
6
6
|
exports.TaskQueue = void 0
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const _Queueable = require('./Queueable')
|
|
8
|
+
const _LinkedList = require('../linked-list/LinkedList')
|
|
9
9
|
/**
|
|
10
10
|
* @file task queue
|
|
11
11
|
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
import { Linker } from '../linked-list/Linker';
|
|
2
|
-
import { IsArrayable } from '../../recipes/IsArrayable';
|
|
3
|
-
import { IsStack } from '../../recipes/IsStack';
|
|
4
|
-
/**
|
|
5
|
-
* A last-in-first-out collection: items are added to the top with push and taken from the top with pop. Any value can
|
|
6
|
-
* be stacked (it is stored as it is, whether it is a function, an object or null), and adding and taking are constant
|
|
7
|
-
* time. To stack tasks which are run as they are taken use TaskStack.
|
|
8
|
-
*/
|
|
9
|
-
export declare class Stack<T = any> implements IsStack<T>, Iterable<T> {
|
|
10
|
-
/** The list which stores the stacked items, the first is the top of the stack. */
|
|
11
|
-
stackedList: IsArrayable<any>;
|
|
12
|
-
private readonly linkerClass;
|
|
13
|
-
/**
|
|
14
|
-
* Instantiate the stack, optionally with a list of items to start from.
|
|
15
|
-
* @param {IsArrayable|null} [stackedList=null] The list of linkers to start in this stack (the first is the top)
|
|
16
|
-
* @param {IsArrayable} [listClass=LinkedList] The type of list to create when no stacked list is given
|
|
17
|
-
* @param {Linker} [linkerClass=Linker] The class used to hold each stacked item
|
|
18
|
-
*/
|
|
19
|
-
constructor(stackedList?: IsArrayable<any> | null, listClass?: any, linkerClass?: typeof Linker);
|
|
20
|
-
/**
|
|
21
|
-
* Check whether the stack has no items.
|
|
22
|
-
* @return {boolean}
|
|
23
|
-
*/
|
|
24
|
-
empty(): boolean;
|
|
25
|
-
/**
|
|
26
|
-
* Look at the item on the top of the stack, without removing it.
|
|
27
|
-
* @return {*|null} The item, or null when the stack is empty
|
|
28
|
-
*/
|
|
29
|
-
peek(): T | null;
|
|
30
|
-
/**
|
|
31
|
-
* Take the item from the top of the stack.
|
|
32
|
-
* @return {*|null} The item, or null when the stack is empty
|
|
33
|
-
*/
|
|
34
|
-
pop(): T | null;
|
|
35
|
-
/**
|
|
36
|
-
* Add an item to the top of the stack.
|
|
37
|
-
* @param {*} data The item to add
|
|
38
|
-
* @return {Stack} This stack, so that adding can be chained
|
|
39
|
-
*/
|
|
40
|
-
push(data: T): this;
|
|
41
|
-
/**
|
|
42
|
-
* Count the items in the stack.
|
|
43
|
-
* @return {number}
|
|
44
|
-
*/
|
|
45
|
-
size(): number;
|
|
46
|
-
/**
|
|
47
|
-
* The item on the top of the stack (the same as peek).
|
|
48
|
-
* @return {*|null} The item, or null when the stack is empty
|
|
49
|
-
*/
|
|
50
|
-
top(): T | null;
|
|
51
|
-
/**
|
|
52
|
-
* Iterate over the items from the top of the stack to the bottom, without removing them.
|
|
53
|
-
* @return {Iterator}
|
|
54
|
-
*/
|
|
55
|
-
[Symbol.iterator](): Iterator<T>;
|
|
56
|
-
/**
|
|
57
|
-
* Convert an array to a Stack by pushing each value in turn, so the last value is on the top.
|
|
58
|
-
* @param {Array} [values=[]] The items to stack
|
|
59
|
-
* @param {IsArrayable} [listClass=LinkedList] The type of list used to store the items
|
|
60
|
-
* @param {Linker} [linkerClass=Linker] The class used to hold each stacked item
|
|
61
|
-
* @returns {Stack}
|
|
62
|
-
*/
|
|
63
|
-
static fromArray: <T_1 = any>(values?: Array<T_1>, listClass?: any, linkerClass?: typeof Linker) => Stack<T_1>;
|
|
64
|
-
}
|
|
1
|
+
import { Linker } from '../linked-list/Linker';
|
|
2
|
+
import { IsArrayable } from '../../recipes/IsArrayable';
|
|
3
|
+
import { IsStack } from '../../recipes/IsStack';
|
|
4
|
+
/**
|
|
5
|
+
* A last-in-first-out collection: items are added to the top with push and taken from the top with pop. Any value can
|
|
6
|
+
* be stacked (it is stored as it is, whether it is a function, an object or null), and adding and taking are constant
|
|
7
|
+
* time. To stack tasks which are run as they are taken use TaskStack.
|
|
8
|
+
*/
|
|
9
|
+
export declare class Stack<T = any> implements IsStack<T>, Iterable<T> {
|
|
10
|
+
/** The list which stores the stacked items, the first is the top of the stack. */
|
|
11
|
+
stackedList: IsArrayable<any>;
|
|
12
|
+
private readonly linkerClass;
|
|
13
|
+
/**
|
|
14
|
+
* Instantiate the stack, optionally with a list of items to start from.
|
|
15
|
+
* @param {IsArrayable|null} [stackedList=null] The list of linkers to start in this stack (the first is the top)
|
|
16
|
+
* @param {IsArrayable} [listClass=LinkedList] The type of list to create when no stacked list is given
|
|
17
|
+
* @param {Linker} [linkerClass=Linker] The class used to hold each stacked item
|
|
18
|
+
*/
|
|
19
|
+
constructor(stackedList?: IsArrayable<any> | null, listClass?: any, linkerClass?: typeof Linker);
|
|
20
|
+
/**
|
|
21
|
+
* Check whether the stack has no items.
|
|
22
|
+
* @return {boolean}
|
|
23
|
+
*/
|
|
24
|
+
empty(): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Look at the item on the top of the stack, without removing it.
|
|
27
|
+
* @return {*|null} The item, or null when the stack is empty
|
|
28
|
+
*/
|
|
29
|
+
peek(): T | null;
|
|
30
|
+
/**
|
|
31
|
+
* Take the item from the top of the stack.
|
|
32
|
+
* @return {*|null} The item, or null when the stack is empty
|
|
33
|
+
*/
|
|
34
|
+
pop(): T | null;
|
|
35
|
+
/**
|
|
36
|
+
* Add an item to the top of the stack.
|
|
37
|
+
* @param {*} data The item to add
|
|
38
|
+
* @return {Stack} This stack, so that adding can be chained
|
|
39
|
+
*/
|
|
40
|
+
push(data: T): this;
|
|
41
|
+
/**
|
|
42
|
+
* Count the items in the stack.
|
|
43
|
+
* @return {number}
|
|
44
|
+
*/
|
|
45
|
+
size(): number;
|
|
46
|
+
/**
|
|
47
|
+
* The item on the top of the stack (the same as peek).
|
|
48
|
+
* @return {*|null} The item, or null when the stack is empty
|
|
49
|
+
*/
|
|
50
|
+
top(): T | null;
|
|
51
|
+
/**
|
|
52
|
+
* Iterate over the items from the top of the stack to the bottom, without removing them.
|
|
53
|
+
* @return {Iterator}
|
|
54
|
+
*/
|
|
55
|
+
[Symbol.iterator](): Iterator<T>;
|
|
56
|
+
/**
|
|
57
|
+
* Convert an array to a Stack by pushing each value in turn, so the last value is on the top.
|
|
58
|
+
* @param {Array} [values=[]] The items to stack
|
|
59
|
+
* @param {IsArrayable} [listClass=LinkedList] The type of list used to store the items
|
|
60
|
+
* @param {Linker} [linkerClass=Linker] The class used to hold each stacked item
|
|
61
|
+
* @returns {Stack}
|
|
62
|
+
*/
|
|
63
|
+
static fromArray: <T_1 = any>(values?: Array<T_1>, listClass?: any, linkerClass?: typeof Linker) => Stack<T_1>;
|
|
64
|
+
}
|
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, '__esModule', {
|
|
|
6
6
|
exports.Stack = void 0
|
|
7
7
|
require('core-js/modules/esnext.iterator.constructor.js')
|
|
8
8
|
require('core-js/modules/esnext.iterator.for-each.js')
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
const _LinkedList = require('../linked-list/LinkedList')
|
|
10
|
+
const _Linker = require('../linked-list/Linker')
|
|
11
11
|
/**
|
|
12
12
|
* @file stack.
|
|
13
13
|
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
@@ -101,13 +101,15 @@ class Stack {
|
|
|
101
101
|
return {
|
|
102
102
|
next: () => {
|
|
103
103
|
const result = linkers.next()
|
|
104
|
-
return result.done
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
104
|
+
return result.done
|
|
105
|
+
? {
|
|
106
|
+
done: true,
|
|
107
|
+
value: undefined
|
|
108
|
+
}
|
|
109
|
+
: {
|
|
110
|
+
done: false,
|
|
111
|
+
value: result.value.data
|
|
112
|
+
}
|
|
111
113
|
}
|
|
112
114
|
}
|
|
113
115
|
}
|
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file stack.
|
|
3
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
-
* @version 1.1.0
|
|
5
|
-
* @memberOf module:collect-your-stuff
|
|
6
|
-
*/
|
|
7
|
-
import { IsRunnable } from '../../recipes/Runnable';
|
|
8
|
-
import { IsLinker } from '../../recipes/IsLinker';
|
|
9
|
-
/**
|
|
10
|
-
* Stackable represents a runnable entry in stack.
|
|
11
|
-
* @extends Linker
|
|
12
|
-
*/
|
|
13
|
-
export declare class Stackable implements IsLinker, IsRunnable {
|
|
14
|
-
/** The class used to create this instance, so that it can be recognized as valid without an instanceof check. */
|
|
15
|
-
readonly classType: typeof Stackable;
|
|
16
|
-
/** The task (or data) this stackable holds. */
|
|
17
|
-
data: any;
|
|
18
|
-
/** The stackable below this one, or null when this is the bottom. */
|
|
19
|
-
next: Stackable | null;
|
|
20
|
-
/**
|
|
21
|
-
* Create a stackable item that can be used in a stack.
|
|
22
|
-
* @param {Object} [stackData={}] The settings for the new stackable.
|
|
23
|
-
* @param {*} [stackData.task=null] The data to be stored in this stackable
|
|
24
|
-
* @param {Stackable|null} [stackData.next=null] The reference to the next stackable if any
|
|
25
|
-
* @param {boolean|Function} [stackData.ready=false] Indicate if the stackable is ready to run
|
|
26
|
-
*/
|
|
27
|
-
constructor({ task, next, ready }?: {
|
|
28
|
-
task?: any;
|
|
29
|
-
next?: Stackable | null;
|
|
30
|
-
ready?: boolean;
|
|
31
|
-
});
|
|
32
|
-
/**
|
|
33
|
-
* Retrieve the data which should be formed as a task.
|
|
34
|
-
* @return {*}
|
|
35
|
-
*/
|
|
36
|
-
get task(): any;
|
|
37
|
-
/**
|
|
38
|
-
* Run the stacked task.
|
|
39
|
-
* @return {*}
|
|
40
|
-
*/
|
|
41
|
-
run(): any;
|
|
42
|
-
/**
|
|
43
|
-
* Make a new Stackable from the data given if it is not already a valid Stackable.
|
|
44
|
-
* @param {Stackable|*} stackable Return a valid Stackable instance from given data, or even an already valid one.
|
|
45
|
-
* @param {IsLinker} [classType=Stackable] Provide the type of IsLinker to use.
|
|
46
|
-
* @return {Stackable}
|
|
47
|
-
*/
|
|
48
|
-
static make: (stackable: Stackable | any, classType?: any) => Stackable;
|
|
49
|
-
/**
|
|
50
|
-
* Convert an array into Stackable instances, return the head and tail Stackables.
|
|
51
|
-
* @param {Array} [values=[]] Provide an array of data that will be converted to a chain of stackable linkers.
|
|
52
|
-
* @param {IsLinker} [classType=Stackable] Provide the type of IsLinker to use.
|
|
53
|
-
* @returns {{head: Stackable, tail: Stackable}}
|
|
54
|
-
*/
|
|
55
|
-
static fromArray: (values?: Array<any>, classType?: any) => {
|
|
56
|
-
head: IsLinker;
|
|
57
|
-
tail: IsLinker;
|
|
58
|
-
};
|
|
59
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @file stack.
|
|
3
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
+
* @version 1.1.0
|
|
5
|
+
* @memberOf module:collect-your-stuff
|
|
6
|
+
*/
|
|
7
|
+
import { IsRunnable } from '../../recipes/Runnable';
|
|
8
|
+
import { IsLinker } from '../../recipes/IsLinker';
|
|
9
|
+
/**
|
|
10
|
+
* Stackable represents a runnable entry in stack.
|
|
11
|
+
* @extends Linker
|
|
12
|
+
*/
|
|
13
|
+
export declare class Stackable implements IsLinker, IsRunnable {
|
|
14
|
+
/** The class used to create this instance, so that it can be recognized as valid without an instanceof check. */
|
|
15
|
+
readonly classType: typeof Stackable;
|
|
16
|
+
/** The task (or data) this stackable holds. */
|
|
17
|
+
data: any;
|
|
18
|
+
/** The stackable below this one, or null when this is the bottom. */
|
|
19
|
+
next: Stackable | null;
|
|
20
|
+
/**
|
|
21
|
+
* Create a stackable item that can be used in a stack.
|
|
22
|
+
* @param {Object} [stackData={}] The settings for the new stackable.
|
|
23
|
+
* @param {*} [stackData.task=null] The data to be stored in this stackable
|
|
24
|
+
* @param {Stackable|null} [stackData.next=null] The reference to the next stackable if any
|
|
25
|
+
* @param {boolean|Function} [stackData.ready=false] Indicate if the stackable is ready to run
|
|
26
|
+
*/
|
|
27
|
+
constructor({ task, next, ready }?: {
|
|
28
|
+
task?: any;
|
|
29
|
+
next?: Stackable | null;
|
|
30
|
+
ready?: boolean;
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* Retrieve the data which should be formed as a task.
|
|
34
|
+
* @return {*}
|
|
35
|
+
*/
|
|
36
|
+
get task(): any;
|
|
37
|
+
/**
|
|
38
|
+
* Run the stacked task.
|
|
39
|
+
* @return {*}
|
|
40
|
+
*/
|
|
41
|
+
run(): any;
|
|
42
|
+
/**
|
|
43
|
+
* Make a new Stackable from the data given if it is not already a valid Stackable.
|
|
44
|
+
* @param {Stackable|*} stackable Return a valid Stackable instance from given data, or even an already valid one.
|
|
45
|
+
* @param {IsLinker} [classType=Stackable] Provide the type of IsLinker to use.
|
|
46
|
+
* @return {Stackable}
|
|
47
|
+
*/
|
|
48
|
+
static make: (stackable: Stackable | any, classType?: any) => Stackable;
|
|
49
|
+
/**
|
|
50
|
+
* Convert an array into Stackable instances, return the head and tail Stackables.
|
|
51
|
+
* @param {Array} [values=[]] Provide an array of data that will be converted to a chain of stackable linkers.
|
|
52
|
+
* @param {IsLinker} [classType=Stackable] Provide the type of IsLinker to use.
|
|
53
|
+
* @returns {{head: Stackable, tail: Stackable}}
|
|
54
|
+
*/
|
|
55
|
+
static fromArray: (values?: Array<any>, classType?: any) => {
|
|
56
|
+
head: IsLinker;
|
|
57
|
+
tail: IsLinker;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', {
|
|
|
4
4
|
value: true
|
|
5
5
|
})
|
|
6
6
|
exports.Stackable = void 0
|
|
7
|
-
|
|
7
|
+
const _Linker = require('../linked-list/Linker')
|
|
8
8
|
/**
|
|
9
9
|
* Stackable represents a runnable entry in stack.
|
|
10
10
|
* @extends Linker
|