collect-your-stuff 1.2.7 → 1.2.8
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 +2525 -2525
- package/browser/collect-your-stuff.js +22766 -22761
- package/browser/collect-your-stuff.min.js +1 -1
- package/dist/collections/arrayable/ArrayElement.d.ts +36 -36
- package/dist/collections/arrayable/ArrayElement.js +64 -64
- package/dist/collections/arrayable/Arrayable.d.ts +108 -108
- package/dist/collections/arrayable/Arrayable.js +188 -188
- package/dist/collections/doubly-linked-list/DoubleLinker.d.ts +46 -46
- package/dist/collections/doubly-linked-list/DoubleLinker.js +69 -69
- package/dist/collections/doubly-linked-list/DoublyLinkedList.d.ts +113 -113
- package/dist/collections/doubly-linked-list/DoublyLinkedList.js +274 -269
- package/dist/collections/doubly-linked-list/DoublyLinkedList.min.js +1 -1
- package/dist/collections/linked-list/LinkedList.d.ts +109 -109
- package/dist/collections/linked-list/LinkedList.js +233 -233
- package/dist/collections/linked-list/Linker.d.ts +43 -43
- package/dist/collections/linked-list/Linker.js +80 -80
- package/dist/collections/linked-tree-list/LinkedTreeList.d.ts +135 -135
- package/dist/collections/linked-tree-list/LinkedTreeList.js +252 -252
- package/dist/collections/linked-tree-list/TreeLinker.d.ts +63 -63
- package/dist/collections/linked-tree-list/TreeLinker.js +79 -79
- package/dist/collections/queue/Queue.d.ts +63 -63
- package/dist/collections/queue/Queue.js +130 -130
- package/dist/collections/queue/Queueable.d.ts +77 -77
- package/dist/collections/queue/Queueable.js +141 -141
- package/dist/collections/stack/Stack.d.ts +63 -63
- package/dist/collections/stack/Stack.js +106 -106
- package/dist/collections/stack/Stackable.d.ts +56 -56
- package/dist/collections/stack/Stackable.js +83 -83
- package/dist/main.d.ts +40 -40
- package/dist/main.js +50 -50
- package/dist/recipes/ArrayIterator.d.ts +10 -10
- package/dist/recipes/ArrayIterator.js +29 -29
- package/dist/recipes/DoubleLinkerIterator.d.ts +9 -9
- package/dist/recipes/DoubleLinkerIterator.js +24 -24
- 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/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 +9 -9
- package/dist/recipes/LinkerIterator.js +24 -24
- package/dist/recipes/Runnable.d.ts +54 -54
- package/dist/recipes/Runnable.js +68 -68
- package/dist/recipes/TreeLinkerIterator.d.ts +9 -9
- package/dist/recipes/TreeLinkerIterator.js +25 -25
- package/dist/recipes/recipes.d.ts +15 -15
- package/dist/recipes/recipes.js +22 -22
- package/dist/services/parseTree.d.ts +9 -9
- package/dist/services/parseTree.js +24 -24
- package/dist/services/parseTreeNext.d.ts +14 -14
- package/dist/services/parseTreeNext.js +47 -47
- package/dist/services/services.d.ts +13 -13
- package/dist/services/services.js +22 -22
- package/package.json +1 -1
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.Stack = void 0
|
|
7
|
-
var _Stackable = require('./Stackable')
|
|
8
|
-
var _LinkedList = require('../linked-list/LinkedList')
|
|
9
|
-
/**
|
|
10
|
-
* @file stack.
|
|
11
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
12
|
-
* @version 1.0.0
|
|
13
|
-
* @memberOf module:collect-your-stuff
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Store a collection of items which can only be inserted and removed from the top.
|
|
18
|
-
*/
|
|
19
|
-
class Stack {
|
|
20
|
-
/**
|
|
21
|
-
* Instantiate the state with the starter stacked list.
|
|
22
|
-
* @param {Iterable|LinkedList} stackedList
|
|
23
|
-
* @param {IsArrayable} listClass
|
|
24
|
-
* @param {Stackable} stackableClass
|
|
25
|
-
*/
|
|
26
|
-
constructor (stackedList = null, listClass = _LinkedList.LinkedList, stackableClass = _Stackable.Stackable) {
|
|
27
|
-
this.listClass = listClass
|
|
28
|
-
this.stackableClass = stackableClass
|
|
29
|
-
if (stackedList === null) {
|
|
30
|
-
stackedList = new listClass(stackableClass)
|
|
31
|
-
}
|
|
32
|
-
this.stackedList = stackedList
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Return true if the stack is empty (there are no tasks in the stacked list)
|
|
37
|
-
* @return {boolean}
|
|
38
|
-
*/
|
|
39
|
-
empty () {
|
|
40
|
-
return this.size() <= 0
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Take a look at the next stacked task
|
|
45
|
-
* @return {Stackable}
|
|
46
|
-
*/
|
|
47
|
-
top () {
|
|
48
|
-
return this.stackedList.first
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Remove the next stacked task and return it.
|
|
53
|
-
* @return {Stackable|null}
|
|
54
|
-
*/
|
|
55
|
-
pop () {
|
|
56
|
-
const next = this.remove()
|
|
57
|
-
if (!next) {
|
|
58
|
-
return {
|
|
59
|
-
success: 'No more stackable tasks in the stack',
|
|
60
|
-
error: false,
|
|
61
|
-
context: this.stackedList
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return next.run()
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Push a stackable task to the top of the stack.
|
|
69
|
-
* @param {Stackable|*} stackable Add a new stackable to the top of the stack
|
|
70
|
-
*/
|
|
71
|
-
push (stackable) {
|
|
72
|
-
this.stackedList.prepend(stackable)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Remove the next stacked task and return it.
|
|
77
|
-
* @return {Stackable|null}
|
|
78
|
-
*/
|
|
79
|
-
remove () {
|
|
80
|
-
if (this.empty()) {
|
|
81
|
-
return null
|
|
82
|
-
}
|
|
83
|
-
return this.stackedList.remove(this.stackedList.first)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Get the size of the current stack.
|
|
88
|
-
* @return {number}
|
|
89
|
-
*/
|
|
90
|
-
size () {
|
|
91
|
-
return this.stackedList.length
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Convert an array to a Stack.
|
|
96
|
-
* @param {Array} values An array of values which will be converted to stackables in this queue
|
|
97
|
-
* @param {Stackable} stackableClass The class to use for each stackable
|
|
98
|
-
* @param {Stack|Iterable} listClass The class to use to manage the stackables
|
|
99
|
-
* @returns {Stack}
|
|
100
|
-
*/
|
|
101
|
-
exports.Stack = Stack
|
|
102
|
-
Stack.fromArray = (values = [], stackableClass = _Stackable.Stackable, listClass = _LinkedList.LinkedList) => {
|
|
103
|
-
const list = new listClass(stackableClass)
|
|
104
|
-
list.initialize(stackableClass.fromArray(values, stackableClass).head)
|
|
105
|
-
return new Stack(list)
|
|
106
|
-
}
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.Stack = void 0
|
|
7
|
+
var _Stackable = require('./Stackable')
|
|
8
|
+
var _LinkedList = require('../linked-list/LinkedList')
|
|
9
|
+
/**
|
|
10
|
+
* @file stack.
|
|
11
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
12
|
+
* @version 1.0.0
|
|
13
|
+
* @memberOf module:collect-your-stuff
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Store a collection of items which can only be inserted and removed from the top.
|
|
18
|
+
*/
|
|
19
|
+
class Stack {
|
|
20
|
+
/**
|
|
21
|
+
* Instantiate the state with the starter stacked list.
|
|
22
|
+
* @param {Iterable|LinkedList} stackedList
|
|
23
|
+
* @param {IsArrayable} listClass
|
|
24
|
+
* @param {Stackable} stackableClass
|
|
25
|
+
*/
|
|
26
|
+
constructor (stackedList = null, listClass = _LinkedList.LinkedList, stackableClass = _Stackable.Stackable) {
|
|
27
|
+
this.listClass = listClass
|
|
28
|
+
this.stackableClass = stackableClass
|
|
29
|
+
if (stackedList === null) {
|
|
30
|
+
stackedList = new listClass(stackableClass)
|
|
31
|
+
}
|
|
32
|
+
this.stackedList = stackedList
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Return true if the stack is empty (there are no tasks in the stacked list)
|
|
37
|
+
* @return {boolean}
|
|
38
|
+
*/
|
|
39
|
+
empty () {
|
|
40
|
+
return this.size() <= 0
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Take a look at the next stacked task
|
|
45
|
+
* @return {Stackable}
|
|
46
|
+
*/
|
|
47
|
+
top () {
|
|
48
|
+
return this.stackedList.first
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Remove the next stacked task and return it.
|
|
53
|
+
* @return {Stackable|null}
|
|
54
|
+
*/
|
|
55
|
+
pop () {
|
|
56
|
+
const next = this.remove()
|
|
57
|
+
if (!next) {
|
|
58
|
+
return {
|
|
59
|
+
success: 'No more stackable tasks in the stack',
|
|
60
|
+
error: false,
|
|
61
|
+
context: this.stackedList
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return next.run()
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Push a stackable task to the top of the stack.
|
|
69
|
+
* @param {Stackable|*} stackable Add a new stackable to the top of the stack
|
|
70
|
+
*/
|
|
71
|
+
push (stackable) {
|
|
72
|
+
this.stackedList.prepend(stackable)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Remove the next stacked task and return it.
|
|
77
|
+
* @return {Stackable|null}
|
|
78
|
+
*/
|
|
79
|
+
remove () {
|
|
80
|
+
if (this.empty()) {
|
|
81
|
+
return null
|
|
82
|
+
}
|
|
83
|
+
return this.stackedList.remove(this.stackedList.first)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Get the size of the current stack.
|
|
88
|
+
* @return {number}
|
|
89
|
+
*/
|
|
90
|
+
size () {
|
|
91
|
+
return this.stackedList.length
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Convert an array to a Stack.
|
|
96
|
+
* @param {Array} values An array of values which will be converted to stackables in this queue
|
|
97
|
+
* @param {Stackable} stackableClass The class to use for each stackable
|
|
98
|
+
* @param {Stack|Iterable} listClass The class to use to manage the stackables
|
|
99
|
+
* @returns {Stack}
|
|
100
|
+
*/
|
|
101
|
+
exports.Stack = Stack
|
|
102
|
+
Stack.fromArray = (values = [], stackableClass = _Stackable.Stackable, listClass = _LinkedList.LinkedList) => {
|
|
103
|
+
const list = new listClass(stackableClass)
|
|
104
|
+
list.initialize(stackableClass.fromArray(values, stackableClass).head)
|
|
105
|
+
return new Stack(list)
|
|
106
|
+
}
|
|
@@ -1,56 +1,56 @@
|
|
|
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
|
-
readonly classType: typeof Stackable;
|
|
15
|
-
data: any;
|
|
16
|
-
next: Stackable | null;
|
|
17
|
-
/**
|
|
18
|
-
* Create a stackable item that can be used in a stack.
|
|
19
|
-
* @param {Object} [stackData={}]
|
|
20
|
-
* @param {*} [stackData.task=null] The data to be stored in this stackable
|
|
21
|
-
* @param {Stackable|null} [stackData.next=null] The reference to the next stackable if any
|
|
22
|
-
* @param {boolean|Function} [stackData.ready=false] Indicate if the stackable is ready to run
|
|
23
|
-
*/
|
|
24
|
-
constructor({ task, next, ready }?: {
|
|
25
|
-
task?: any;
|
|
26
|
-
next?: Stackable | null;
|
|
27
|
-
ready?: boolean;
|
|
28
|
-
});
|
|
29
|
-
/**
|
|
30
|
-
* Retrieve the data which should be formed as a task.
|
|
31
|
-
* @return {*}
|
|
32
|
-
*/
|
|
33
|
-
get task(): any;
|
|
34
|
-
/**
|
|
35
|
-
* Run the stacked task.
|
|
36
|
-
* @return {*}
|
|
37
|
-
*/
|
|
38
|
-
run(): any;
|
|
39
|
-
/**
|
|
40
|
-
* Make a new Stackable from the data given if it is not already a valid Stackable.
|
|
41
|
-
* @param {Stackable|*} stackable Return a valid Stackable instance from given data, or even an already valid one.
|
|
42
|
-
* @param {IsLinker} [classType=Stackable] Provide the type of IsLinker to use.
|
|
43
|
-
* @return {Stackable}
|
|
44
|
-
*/
|
|
45
|
-
static make: (stackable: Stackable | any, classType?: any) => Stackable;
|
|
46
|
-
/**
|
|
47
|
-
* Convert an array into Stackable instances, return the head and tail Stackables.
|
|
48
|
-
* @param {Array} [values=[]] Provide an array of data that will be converted to a chain of stackable linkers.
|
|
49
|
-
* @param {IsLinker} [classType=Stackable] Provide the type of IsLinker to use.
|
|
50
|
-
* @returns {{head: Stackable, tail: Stackable}}
|
|
51
|
-
*/
|
|
52
|
-
static fromArray: (values?: Array<any>, classType?: any) => {
|
|
53
|
-
head: IsLinker;
|
|
54
|
-
tail: IsLinker;
|
|
55
|
-
};
|
|
56
|
-
}
|
|
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
|
+
readonly classType: typeof Stackable;
|
|
15
|
+
data: any;
|
|
16
|
+
next: Stackable | null;
|
|
17
|
+
/**
|
|
18
|
+
* Create a stackable item that can be used in a stack.
|
|
19
|
+
* @param {Object} [stackData={}]
|
|
20
|
+
* @param {*} [stackData.task=null] The data to be stored in this stackable
|
|
21
|
+
* @param {Stackable|null} [stackData.next=null] The reference to the next stackable if any
|
|
22
|
+
* @param {boolean|Function} [stackData.ready=false] Indicate if the stackable is ready to run
|
|
23
|
+
*/
|
|
24
|
+
constructor({ task, next, ready }?: {
|
|
25
|
+
task?: any;
|
|
26
|
+
next?: Stackable | null;
|
|
27
|
+
ready?: boolean;
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* Retrieve the data which should be formed as a task.
|
|
31
|
+
* @return {*}
|
|
32
|
+
*/
|
|
33
|
+
get task(): any;
|
|
34
|
+
/**
|
|
35
|
+
* Run the stacked task.
|
|
36
|
+
* @return {*}
|
|
37
|
+
*/
|
|
38
|
+
run(): any;
|
|
39
|
+
/**
|
|
40
|
+
* Make a new Stackable from the data given if it is not already a valid Stackable.
|
|
41
|
+
* @param {Stackable|*} stackable Return a valid Stackable instance from given data, or even an already valid one.
|
|
42
|
+
* @param {IsLinker} [classType=Stackable] Provide the type of IsLinker to use.
|
|
43
|
+
* @return {Stackable}
|
|
44
|
+
*/
|
|
45
|
+
static make: (stackable: Stackable | any, classType?: any) => Stackable;
|
|
46
|
+
/**
|
|
47
|
+
* Convert an array into Stackable instances, return the head and tail Stackables.
|
|
48
|
+
* @param {Array} [values=[]] Provide an array of data that will be converted to a chain of stackable linkers.
|
|
49
|
+
* @param {IsLinker} [classType=Stackable] Provide the type of IsLinker to use.
|
|
50
|
+
* @returns {{head: Stackable, tail: Stackable}}
|
|
51
|
+
*/
|
|
52
|
+
static fromArray: (values?: Array<any>, classType?: any) => {
|
|
53
|
+
head: IsLinker;
|
|
54
|
+
tail: IsLinker;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.Stackable = void 0
|
|
7
|
-
var _Linker = require('../linked-list/Linker')
|
|
8
|
-
/**
|
|
9
|
-
* Stackable represents a runnable entry in stack.
|
|
10
|
-
* @extends Linker
|
|
11
|
-
*/
|
|
12
|
-
class Stackable {
|
|
13
|
-
/**
|
|
14
|
-
* Create a stackable item that can be used in a stack.
|
|
15
|
-
* @param {Object} [stackData={}]
|
|
16
|
-
* @param {*} [stackData.task=null] The data to be stored in this stackable
|
|
17
|
-
* @param {Stackable|null} [stackData.next=null] The reference to the next stackable if any
|
|
18
|
-
* @param {boolean|Function} [stackData.ready=false] Indicate if the stackable is ready to run
|
|
19
|
-
*/
|
|
20
|
-
constructor ({
|
|
21
|
-
task = null,
|
|
22
|
-
next = null,
|
|
23
|
-
ready = false
|
|
24
|
-
} = {}) {
|
|
25
|
-
this.data = null
|
|
26
|
-
this.next = null
|
|
27
|
-
this.classType = Stackable
|
|
28
|
-
this.data = task
|
|
29
|
-
this.next = next
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Retrieve the data which should be formed as a task.
|
|
34
|
-
* @return {*}
|
|
35
|
-
*/
|
|
36
|
-
get task () {
|
|
37
|
-
if (typeof this.data === 'function') {
|
|
38
|
-
return this.data
|
|
39
|
-
}
|
|
40
|
-
return () => this.data
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Run the stacked task.
|
|
45
|
-
* @return {*}
|
|
46
|
-
*/
|
|
47
|
-
run () {
|
|
48
|
-
return this.task()
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Make a new Stackable from the data given if it is not already a valid Stackable.
|
|
53
|
-
* @param {Stackable|*} stackable Return a valid Stackable instance from given data, or even an already valid one.
|
|
54
|
-
* @param {IsLinker} [classType=Stackable] Provide the type of IsLinker to use.
|
|
55
|
-
* @return {Stackable}
|
|
56
|
-
*/
|
|
57
|
-
exports.Stackable = Stackable
|
|
58
|
-
Stackable.make = (stackable, classType = Stackable) => {
|
|
59
|
-
if (typeof stackable !== 'object') {
|
|
60
|
-
// It is not an object, so instantiate the Stackable with stackable as the data
|
|
61
|
-
return new classType({
|
|
62
|
-
task: stackable
|
|
63
|
-
})
|
|
64
|
-
}
|
|
65
|
-
if (stackable.classType) {
|
|
66
|
-
// Already valid Stackable, return as-is
|
|
67
|
-
return stackable
|
|
68
|
-
}
|
|
69
|
-
if (!stackable.task) {
|
|
70
|
-
stackable = {
|
|
71
|
-
task: stackable
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
// Create the new node as the configured stackableClass
|
|
75
|
-
return new Stackable(stackable)
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Convert an array into Stackable instances, return the head and tail Stackables.
|
|
79
|
-
* @param {Array} [values=[]] Provide an array of data that will be converted to a chain of stackable linkers.
|
|
80
|
-
* @param {IsLinker} [classType=Stackable] Provide the type of IsLinker to use.
|
|
81
|
-
* @returns {{head: Stackable, tail: Stackable}}
|
|
82
|
-
*/
|
|
83
|
-
Stackable.fromArray = (values = [], classType = Stackable) => _Linker.Linker.fromArray(values, classType)
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.Stackable = void 0
|
|
7
|
+
var _Linker = require('../linked-list/Linker')
|
|
8
|
+
/**
|
|
9
|
+
* Stackable represents a runnable entry in stack.
|
|
10
|
+
* @extends Linker
|
|
11
|
+
*/
|
|
12
|
+
class Stackable {
|
|
13
|
+
/**
|
|
14
|
+
* Create a stackable item that can be used in a stack.
|
|
15
|
+
* @param {Object} [stackData={}]
|
|
16
|
+
* @param {*} [stackData.task=null] The data to be stored in this stackable
|
|
17
|
+
* @param {Stackable|null} [stackData.next=null] The reference to the next stackable if any
|
|
18
|
+
* @param {boolean|Function} [stackData.ready=false] Indicate if the stackable is ready to run
|
|
19
|
+
*/
|
|
20
|
+
constructor ({
|
|
21
|
+
task = null,
|
|
22
|
+
next = null,
|
|
23
|
+
ready = false
|
|
24
|
+
} = {}) {
|
|
25
|
+
this.data = null
|
|
26
|
+
this.next = null
|
|
27
|
+
this.classType = Stackable
|
|
28
|
+
this.data = task
|
|
29
|
+
this.next = next
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Retrieve the data which should be formed as a task.
|
|
34
|
+
* @return {*}
|
|
35
|
+
*/
|
|
36
|
+
get task () {
|
|
37
|
+
if (typeof this.data === 'function') {
|
|
38
|
+
return this.data
|
|
39
|
+
}
|
|
40
|
+
return () => this.data
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Run the stacked task.
|
|
45
|
+
* @return {*}
|
|
46
|
+
*/
|
|
47
|
+
run () {
|
|
48
|
+
return this.task()
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Make a new Stackable from the data given if it is not already a valid Stackable.
|
|
53
|
+
* @param {Stackable|*} stackable Return a valid Stackable instance from given data, or even an already valid one.
|
|
54
|
+
* @param {IsLinker} [classType=Stackable] Provide the type of IsLinker to use.
|
|
55
|
+
* @return {Stackable}
|
|
56
|
+
*/
|
|
57
|
+
exports.Stackable = Stackable
|
|
58
|
+
Stackable.make = (stackable, classType = Stackable) => {
|
|
59
|
+
if (typeof stackable !== 'object') {
|
|
60
|
+
// It is not an object, so instantiate the Stackable with stackable as the data
|
|
61
|
+
return new classType({
|
|
62
|
+
task: stackable
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
if (stackable.classType) {
|
|
66
|
+
// Already valid Stackable, return as-is
|
|
67
|
+
return stackable
|
|
68
|
+
}
|
|
69
|
+
if (!stackable.task) {
|
|
70
|
+
stackable = {
|
|
71
|
+
task: stackable
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// Create the new node as the configured stackableClass
|
|
75
|
+
return new Stackable(stackable)
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Convert an array into Stackable instances, return the head and tail Stackables.
|
|
79
|
+
* @param {Array} [values=[]] Provide an array of data that will be converted to a chain of stackable linkers.
|
|
80
|
+
* @param {IsLinker} [classType=Stackable] Provide the type of IsLinker to use.
|
|
81
|
+
* @returns {{head: Stackable, tail: Stackable}}
|
|
82
|
+
*/
|
|
83
|
+
Stackable.fromArray = (values = [], classType = Stackable) => _Linker.Linker.fromArray(values, classType)
|
package/dist/main.d.ts
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* All of the collections available.
|
|
3
|
-
* @file
|
|
4
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
5
|
-
* @version 1.0.0
|
|
6
|
-
* @module collect-your-stuff
|
|
7
|
-
*/
|
|
8
|
-
import 'core-js/stable';
|
|
9
|
-
import { Arrayable } from './collections/arrayable/Arrayable';
|
|
10
|
-
import { DoublyLinkedList } from './collections/doubly-linked-list/DoublyLinkedList';
|
|
11
|
-
import { LinkedList } from './collections/linked-list/LinkedList';
|
|
12
|
-
import { LinkedTreeList } from './collections/linked-tree-list/LinkedTreeList';
|
|
13
|
-
import { Queue } from './collections/queue/Queue';
|
|
14
|
-
import { Stack } from './collections/stack/Stack';
|
|
15
|
-
/**
|
|
16
|
-
* TODO:
|
|
17
|
-
* 1. Create binary tree. Use the tree, but it has a limit of only two children per parent, and when adding / removing sort is applied. Add sort function in fromArray
|
|
18
|
-
* 2. Create a heap (both min and max heap variants) which is similar to binary tree in structure, but tree having its min / max value as root. and it must insert on the left-most lowest level, and removes from root. Be able to easily swap nodes to ensure min / max ordering.
|
|
19
|
-
* 3. Create a graph type which can have directional and undirectional variants for linking nodes
|
|
20
|
-
*/
|
|
21
|
-
/**
|
|
22
|
-
* All methods exported from this module are encapsulated within collect-your-stuff.
|
|
23
|
-
*/
|
|
24
|
-
declare const collectYourStuff: {
|
|
25
|
-
Arrayable: typeof Arrayable;
|
|
26
|
-
DoublyLinkedList: typeof DoublyLinkedList;
|
|
27
|
-
LinkedList: typeof LinkedList;
|
|
28
|
-
LinkedTreeList: typeof LinkedTreeList;
|
|
29
|
-
Queue: typeof Queue;
|
|
30
|
-
Stack: typeof Stack;
|
|
31
|
-
recipes: {
|
|
32
|
-
ArrayIterator: typeof import("./recipes/ArrayIterator").ArrayIterator;
|
|
33
|
-
Runnable: typeof import("./recipes/Runnable").Runnable;
|
|
34
|
-
};
|
|
35
|
-
services: {
|
|
36
|
-
parseTree: (tree: import("./recipes/IsTree").IsTree, callback: import("./recipes/IsArrayable").forEachCallback) => import("./recipes/IsTree").IsTree;
|
|
37
|
-
parseTreeNext: (treeNode: import("./recipes/IsTreeNode").IsTreeNode) => import("./recipes/IsTreeNode").IsTreeNode | null;
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
export default collectYourStuff;
|
|
1
|
+
/**
|
|
2
|
+
* All of the collections available.
|
|
3
|
+
* @file
|
|
4
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
5
|
+
* @version 1.0.0
|
|
6
|
+
* @module collect-your-stuff
|
|
7
|
+
*/
|
|
8
|
+
import 'core-js/stable';
|
|
9
|
+
import { Arrayable } from './collections/arrayable/Arrayable';
|
|
10
|
+
import { DoublyLinkedList } from './collections/doubly-linked-list/DoublyLinkedList';
|
|
11
|
+
import { LinkedList } from './collections/linked-list/LinkedList';
|
|
12
|
+
import { LinkedTreeList } from './collections/linked-tree-list/LinkedTreeList';
|
|
13
|
+
import { Queue } from './collections/queue/Queue';
|
|
14
|
+
import { Stack } from './collections/stack/Stack';
|
|
15
|
+
/**
|
|
16
|
+
* TODO:
|
|
17
|
+
* 1. Create binary tree. Use the tree, but it has a limit of only two children per parent, and when adding / removing sort is applied. Add sort function in fromArray
|
|
18
|
+
* 2. Create a heap (both min and max heap variants) which is similar to binary tree in structure, but tree having its min / max value as root. and it must insert on the left-most lowest level, and removes from root. Be able to easily swap nodes to ensure min / max ordering.
|
|
19
|
+
* 3. Create a graph type which can have directional and undirectional variants for linking nodes
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* All methods exported from this module are encapsulated within collect-your-stuff.
|
|
23
|
+
*/
|
|
24
|
+
declare const collectYourStuff: {
|
|
25
|
+
Arrayable: typeof Arrayable;
|
|
26
|
+
DoublyLinkedList: typeof DoublyLinkedList;
|
|
27
|
+
LinkedList: typeof LinkedList;
|
|
28
|
+
LinkedTreeList: typeof LinkedTreeList;
|
|
29
|
+
Queue: typeof Queue;
|
|
30
|
+
Stack: typeof Stack;
|
|
31
|
+
recipes: {
|
|
32
|
+
ArrayIterator: typeof import("./recipes/ArrayIterator").ArrayIterator;
|
|
33
|
+
Runnable: typeof import("./recipes/Runnable").Runnable;
|
|
34
|
+
};
|
|
35
|
+
services: {
|
|
36
|
+
parseTree: (tree: import("./recipes/IsTree").IsTree, callback: import("./recipes/IsArrayable").forEachCallback) => import("./recipes/IsTree").IsTree;
|
|
37
|
+
parseTreeNext: (treeNode: import("./recipes/IsTreeNode").IsTreeNode) => import("./recipes/IsTreeNode").IsTreeNode | null;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export default collectYourStuff;
|