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,127 +1,122 @@
1
- 'use strict'
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true
5
- })
6
- exports.Stack = void 0
7
- require('core-js/modules/esnext.iterator.constructor.js')
8
- require('core-js/modules/esnext.iterator.for-each.js')
9
- var _LinkedList = require('../linked-list/LinkedList')
10
- var _Linker = require('../linked-list/Linker')
11
- /**
12
- * @file stack.
13
- * @author Joshua Heagle <joshuaheagle@gmail.com>
14
- * @version 2.0.0
15
- * @memberOf module:collect-your-stuff
16
- */
17
-
18
- /**
19
- * A last-in-first-out collection: items are added to the top with push and taken from the top with pop. Any value can
20
- * be stacked (it is stored as it is, whether it is a function, an object or null), and adding and taking are constant
21
- * time. To stack tasks which are run as they are taken use TaskStack.
22
- */
23
- class Stack {
24
- /**
25
- * Instantiate the stack, optionally with a list of items to start from.
26
- * @param {IsArrayable|null} [stackedList=null] The list of linkers to start in this stack (the first is the top)
27
- * @param {IsArrayable} [listClass=LinkedList] The type of list to create when no stacked list is given
28
- * @param {Linker} [linkerClass=Linker] The class used to hold each stacked item
29
- */
30
- constructor (stackedList = null, listClass = _LinkedList.LinkedList, linkerClass = _Linker.Linker) {
31
- this.linkerClass = linkerClass
32
- this.stackedList = stackedList === null ? new listClass(linkerClass) : stackedList
33
- }
34
-
35
- /**
36
- * Check whether the stack has no items.
37
- * @return {boolean}
38
- */
39
- empty () {
40
- return this.size() <= 0
41
- }
42
-
43
- /**
44
- * Look at the item on the top of the stack, without removing it.
45
- * @return {*|null} The item, or null when the stack is empty
46
- */
47
- peek () {
48
- const top = this.stackedList.first
49
- return top === null || typeof top === 'undefined' ? null : top.data
50
- }
51
-
52
- /**
53
- * Take the item from the top of the stack.
54
- * @return {*|null} The item, or null when the stack is empty
55
- */
56
- pop () {
57
- const top = this.stackedList.first
58
- if (top === null || typeof top === 'undefined') {
59
- return null
60
- }
61
- this.stackedList.remove(top)
62
- return top.data
63
- }
64
-
65
- /**
66
- * Add an item to the top of the stack.
67
- * @param {*} data The item to add
68
- * @return {Stack} This stack, so that adding can be chained
69
- */
70
- push (data) {
71
- // The item is wrapped here rather than left to the list, since the list treats objects that look like a linker's
72
- // settings (they have a data property) as such, and a stack must give back exactly what it was given
73
- this.stackedList.prepend(new this.linkerClass({
74
- data
75
- }))
76
- return this
77
- }
78
-
79
- /**
80
- * Count the items in the stack.
81
- * @return {number}
82
- */
83
- size () {
84
- return this.stackedList.length
85
- }
86
-
87
- /**
88
- * The item on the top of the stack (the same as peek).
89
- * @return {*|null} The item, or null when the stack is empty
90
- */
91
- top () {
92
- return this.peek()
93
- }
94
-
95
- /**
96
- * Iterate over the items from the top of the stack to the bottom, without removing them.
97
- * @return {Iterator}
98
- */
99
- [Symbol.iterator] () {
100
- const linkers = this.stackedList[Symbol.iterator]()
101
- return {
102
- next: () => {
103
- const result = linkers.next()
104
- return result.done ? {
105
- done: true,
106
- value: undefined
107
- } : {
108
- done: false,
109
- value: result.value.data
110
- }
111
- }
112
- }
113
- }
114
- }
115
- /**
116
- * Convert an array to a Stack by pushing each value in turn, so the last value is on the top.
117
- * @param {Array} [values=[]] The items to stack
118
- * @param {IsArrayable} [listClass=LinkedList] The type of list used to store the items
119
- * @param {Linker} [linkerClass=Linker] The class used to hold each stacked item
120
- * @returns {Stack}
121
- */
122
- exports.Stack = Stack
123
- Stack.fromArray = (values = [], listClass = _LinkedList.LinkedList, linkerClass = _Linker.Linker) => {
124
- const stack = new Stack(null, listClass, linkerClass)
125
- values.forEach(value => stack.push(value))
126
- return stack
127
- }
1
+ 'use strict'
2
+
3
+ Object.defineProperty(exports, '__esModule', {
4
+ value: true
5
+ })
6
+ exports.Stack = void 0
7
+ require('core-js/modules/esnext.iterator.constructor.js')
8
+ require('core-js/modules/esnext.iterator.for-each.js')
9
+ const _LinkedList = require('../linked-list/LinkedList')
10
+ const _Linker = require('../linked-list/Linker')
11
+ /**
12
+ * stack.
13
+ */
14
+
15
+ /**
16
+ * A last-in-first-out collection: items are added to the top with push and taken from the top with pop. Any value can
17
+ * be stacked (it is stored as it is, whether it is a function, an object or null), and adding and taking are constant
18
+ * time. To stack tasks which are run as they are taken use TaskStack.
19
+ */
20
+ class Stack {
21
+ /**
22
+ * Instantiate the stack, optionally with a list of items to start from.
23
+ * @param stackedList The list of linkers to start in this stack (the first is the top)
24
+ * @param listClass The type of list to create when no stacked list is given
25
+ * @param linkerClass The class used to hold each stacked item
26
+ */
27
+ constructor (stackedList = null, listClass = _LinkedList.LinkedList, linkerClass = _Linker.Linker) {
28
+ this.linkerClass = linkerClass
29
+ this.stackedList = stackedList === null ? new listClass(linkerClass) : stackedList
30
+ }
31
+
32
+ /**
33
+ * Check whether the stack has no items.
34
+ */
35
+ empty () {
36
+ return this.size() <= 0
37
+ }
38
+
39
+ /**
40
+ * Look at the item on the top of the stack, without removing it.
41
+ * @returns The item, or null when the stack is empty
42
+ */
43
+ peek () {
44
+ const top = this.stackedList.first
45
+ return top === null || typeof top === 'undefined' ? null : top.data
46
+ }
47
+
48
+ /**
49
+ * Take the item from the top of the stack.
50
+ * @returns The item, or null when the stack is empty
51
+ */
52
+ pop () {
53
+ const top = this.stackedList.first
54
+ if (top === null || typeof top === 'undefined') {
55
+ return null
56
+ }
57
+ this.stackedList.remove(top)
58
+ return top.data
59
+ }
60
+
61
+ /**
62
+ * Add an item to the top of the stack.
63
+ * @param data The item to add
64
+ * @returns This stack, so that adding can be chained
65
+ */
66
+ push (data) {
67
+ // The item is wrapped here rather than left to the list, since the list treats objects that look like a linker's
68
+ // settings (they have a data property) as such, and a stack must give back exactly what it was given
69
+ this.stackedList.prepend(new this.linkerClass({
70
+ data
71
+ }))
72
+ return this
73
+ }
74
+
75
+ /**
76
+ * Count the items in the stack.
77
+ */
78
+ size () {
79
+ return this.stackedList.length
80
+ }
81
+
82
+ /**
83
+ * The item on the top of the stack (the same as peek).
84
+ * @returns The item, or null when the stack is empty
85
+ */
86
+ top () {
87
+ return this.peek()
88
+ }
89
+
90
+ /**
91
+ * Iterate over the items from the top of the stack to the bottom, without removing them.
92
+ */
93
+ [Symbol.iterator] () {
94
+ const linkers = this.stackedList[Symbol.iterator]()
95
+ return {
96
+ next: () => {
97
+ const result = linkers.next()
98
+ return result.done
99
+ ? {
100
+ done: true,
101
+ value: undefined
102
+ }
103
+ : {
104
+ done: false,
105
+ value: result.value.data
106
+ }
107
+ }
108
+ }
109
+ }
110
+ }
111
+ /**
112
+ * Convert an array to a Stack by pushing each value in turn, so the last value is on the top.
113
+ * @param values The items to stack
114
+ * @param listClass The type of list used to store the items
115
+ * @param linkerClass The class used to hold each stacked item
116
+ */
117
+ exports.Stack = Stack
118
+ Stack.fromArray = (values = [], listClass = _LinkedList.LinkedList, linkerClass = _Linker.Linker) => {
119
+ const stack = new Stack(null, listClass, linkerClass)
120
+ values.forEach(value => stack.push(value))
121
+ return stack
122
+ }
@@ -1,59 +1,52 @@
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
+ * stack.
3
+ */
4
+ import { IsRunnable } from '../../recipes/Runnable';
5
+ import { IsLinker } from '../../recipes/IsLinker';
6
+ /**
7
+ * Stackable represents a runnable entry in stack.
8
+ * @extends Linker
9
+ */
10
+ export declare class Stackable implements IsLinker, IsRunnable {
11
+ /** The class used to create this instance, so that it can be recognized as valid without an instanceof check. */
12
+ readonly classType: typeof Stackable;
13
+ /** The task (or data) this stackable holds. */
14
+ data: any;
15
+ /** The stackable below this one, or null when this is the bottom. */
16
+ next: Stackable | null;
17
+ /**
18
+ * Create a stackable item that can be used in a stack.
19
+ * @param stackData The settings for the new stackable.
20
+ * @param stackData.task The data to be stored in this stackable
21
+ * @param stackData.next The reference to the next stackable if any
22
+ * @param stackData.ready 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
+ */
32
+ get task(): any;
33
+ /**
34
+ * Run the stacked task.
35
+ */
36
+ run(): any;
37
+ /**
38
+ * Make a new Stackable from the data given if it is not already a valid Stackable.
39
+ * @param stackable Return a valid Stackable instance from given data, or even an already valid one.
40
+ * @param classType Provide the type of IsLinker to use.
41
+ */
42
+ static make: (stackable: Stackable | any, classType?: any) => Stackable;
43
+ /**
44
+ * Convert an array into Stackable instances, return the head and tail Stackables.
45
+ * @param values Provide an array of data that will be converted to a chain of stackable linkers.
46
+ * @param classType Provide the type of IsLinker to use.
47
+ */
48
+ static fromArray: (values?: Array<any>, classType?: any) => {
49
+ head: IsLinker;
50
+ tail: IsLinker;
51
+ };
52
+ }
@@ -1,85 +1,81 @@
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={}] The settings for the new stackable.
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
- /** The task (or data) this stackable holds. */
26
- this.data = null
27
- /** The stackable below this one, or null when this is the bottom. */
28
- this.next = null
29
- this.classType = Stackable
30
- this.data = task
31
- this.next = next
32
- }
33
-
34
- /**
35
- * Retrieve the data which should be formed as a task.
36
- * @return {*}
37
- */
38
- get task () {
39
- if (typeof this.data === 'function') {
40
- return this.data
41
- }
42
- return () => this.data
43
- }
44
-
45
- /**
46
- * Run the stacked task.
47
- * @return {*}
48
- */
49
- run () {
50
- return this.task()
51
- }
52
- }
53
- /**
54
- * Make a new Stackable from the data given if it is not already a valid Stackable.
55
- * @param {Stackable|*} stackable Return a valid Stackable instance from given data, or even an already valid one.
56
- * @param {IsLinker} [classType=Stackable] Provide the type of IsLinker to use.
57
- * @return {Stackable}
58
- */
59
- exports.Stackable = Stackable
60
- Stackable.make = (stackable, classType = Stackable) => {
61
- if (stackable === null || typeof stackable !== 'object') {
62
- // It is not an object (or it is null), so instantiate the Stackable with stackable as the data
63
- return new classType({
64
- task: stackable
65
- })
66
- }
67
- if (stackable.classType) {
68
- // Already valid Stackable, return as-is
69
- return stackable
70
- }
71
- if (!('task' in stackable)) {
72
- stackable = {
73
- task: stackable
74
- }
75
- }
76
- // Create the new node as the configured stackableClass
77
- return new classType(stackable)
78
- }
79
- /**
80
- * Convert an array into Stackable instances, return the head and tail Stackables.
81
- * @param {Array} [values=[]] Provide an array of data that will be converted to a chain of stackable linkers.
82
- * @param {IsLinker} [classType=Stackable] Provide the type of IsLinker to use.
83
- * @returns {{head: Stackable, tail: Stackable}}
84
- */
85
- 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
+ const _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 stackData The settings for the new stackable.
16
+ * @param stackData.task The data to be stored in this stackable
17
+ * @param stackData.next The reference to the next stackable if any
18
+ * @param stackData.ready Indicate if the stackable is ready to run
19
+ */
20
+ constructor ({
21
+ task = null,
22
+ next = null,
23
+ ready = false
24
+ } = {}) {
25
+ /** The task (or data) this stackable holds. */
26
+ this.data = null
27
+ /** The stackable below this one, or null when this is the bottom. */
28
+ this.next = null
29
+ this.classType = Stackable
30
+ this.data = task
31
+ this.next = next
32
+ }
33
+
34
+ /**
35
+ * Retrieve the data which should be formed as a task.
36
+ */
37
+ get task () {
38
+ if (typeof this.data === 'function') {
39
+ return this.data
40
+ }
41
+ return () => this.data
42
+ }
43
+
44
+ /**
45
+ * Run the stacked task.
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 Return a valid Stackable instance from given data, or even an already valid one.
54
+ * @param classType Provide the type of IsLinker to use.
55
+ */
56
+ exports.Stackable = Stackable
57
+ Stackable.make = (stackable, classType = Stackable) => {
58
+ if (stackable === null || typeof stackable !== 'object') {
59
+ // It is not an object (or it is null), so instantiate the Stackable with stackable as the data
60
+ return new classType({
61
+ task: stackable
62
+ })
63
+ }
64
+ if (stackable.classType) {
65
+ // Already valid Stackable, return as-is
66
+ return stackable
67
+ }
68
+ if (!('task' in stackable)) {
69
+ stackable = {
70
+ task: stackable
71
+ }
72
+ }
73
+ // Create the new node as the configured stackableClass
74
+ return new classType(stackable)
75
+ }
76
+ /**
77
+ * Convert an array into Stackable instances, return the head and tail Stackables.
78
+ * @param values Provide an array of data that will be converted to a chain of stackable linkers.
79
+ * @param classType Provide the type of IsLinker to use.
80
+ */
81
+ Stackable.fromArray = (values = [], classType = Stackable) => _Linker.Linker.fromArray(values, classType)