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,119 +1,114 @@
1
- 'use strict'
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true
5
- })
6
- exports.Queue = 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 queue
13
- * @author Joshua Heagle <joshuaheagle@gmail.com>
14
- * @version 2.0.0
15
- * @memberOf module:collect-your-stuff
16
- */
17
-
18
- /**
19
- * A first-in-first-out collection: items are added to the back with enqueue and taken from the front with dequeue.
20
- * Any value can be queued (it is stored as it is, whether it is a function, an object or null), and adding and taking
21
- * are constant time. To queue tasks which are run as they are taken use TaskQueue.
22
- */
23
- class Queue {
24
- /**
25
- * Instantiate the queue, optionally with a list of items to start from.
26
- * @param {IsArrayable|null} [queuedList=null] The list of linkers to start in this queue (the first is the front)
27
- * @param {IsArrayable} [listClass=LinkedList] The type of list to create when no queued list is given
28
- * @param {Linker} [linkerClass=Linker] The class used to hold each queued item
29
- */
30
- constructor (queuedList = null, listClass = _LinkedList.LinkedList, linkerClass = _Linker.Linker) {
31
- this.linkerClass = linkerClass
32
- this.queuedList = queuedList === null ? new listClass(linkerClass) : queuedList
33
- }
34
-
35
- /**
36
- * Take the item from the front of the queue.
37
- * @return {*|null} The item, or null when the queue is empty
38
- */
39
- dequeue () {
40
- const front = this.queuedList.first
41
- if (front === null || typeof front === 'undefined') {
42
- return null
43
- }
44
- this.queuedList.remove(front)
45
- return front.data
46
- }
47
-
48
- /**
49
- * Check whether the queue has no items.
50
- * @return {boolean}
51
- */
52
- empty () {
53
- return this.size() <= 0
54
- }
55
-
56
- /**
57
- * Add an item to the back of the queue.
58
- * @param {*} data The item to add
59
- * @return {Queue} This queue, so that adding can be chained
60
- */
61
- enqueue (data) {
62
- // The item is wrapped here rather than left to the list, since the list treats objects that look like a linker's
63
- // settings (they have a data property) as such, and a queue must give back exactly what it was given
64
- this.queuedList.append(new this.linkerClass({
65
- data
66
- }))
67
- return this
68
- }
69
-
70
- /**
71
- * Look at the item at the front of the queue, without removing it.
72
- * @return {*|null} The item, or null when the queue is empty
73
- */
74
- peek () {
75
- const front = this.queuedList.first
76
- return front === null || typeof front === 'undefined' ? null : front.data
77
- }
78
-
79
- /**
80
- * Count the items in the queue.
81
- * @return {number}
82
- */
83
- size () {
84
- return this.queuedList.length
85
- }
86
-
87
- /**
88
- * Iterate over the items from the front of the queue to the back, without removing them.
89
- * @return {Iterator}
90
- */
91
- [Symbol.iterator] () {
92
- const linkers = this.queuedList[Symbol.iterator]()
93
- return {
94
- next: () => {
95
- const result = linkers.next()
96
- return result.done ? {
97
- done: true,
98
- value: undefined
99
- } : {
100
- done: false,
101
- value: result.value.data
102
- }
103
- }
104
- }
105
- }
106
- }
107
- /**
108
- * Convert an array to a Queue, the first value is at the front.
109
- * @param {Array} [values=[]] The items to queue
110
- * @param {IsArrayable} [listClass=LinkedList] The type of list used to store the items
111
- * @param {Linker} [linkerClass=Linker] The class used to hold each queued item
112
- * @returns {Queue}
113
- */
114
- exports.Queue = Queue
115
- Queue.fromArray = (values = [], listClass = _LinkedList.LinkedList, linkerClass = _Linker.Linker) => {
116
- const queue = new Queue(null, listClass, linkerClass)
117
- values.forEach(value => queue.enqueue(value))
118
- return queue
119
- }
1
+ 'use strict'
2
+
3
+ Object.defineProperty(exports, '__esModule', {
4
+ value: true
5
+ })
6
+ exports.Queue = 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
+ * queue
13
+ */
14
+
15
+ /**
16
+ * A first-in-first-out collection: items are added to the back with enqueue and taken from the front with dequeue.
17
+ * Any value can be queued (it is stored as it is, whether it is a function, an object or null), and adding and taking
18
+ * are constant time. To queue tasks which are run as they are taken use TaskQueue.
19
+ */
20
+ class Queue {
21
+ /**
22
+ * Instantiate the queue, optionally with a list of items to start from.
23
+ * @param queuedList The list of linkers to start in this queue (the first is the front)
24
+ * @param listClass The type of list to create when no queued list is given
25
+ * @param linkerClass The class used to hold each queued item
26
+ */
27
+ constructor (queuedList = null, listClass = _LinkedList.LinkedList, linkerClass = _Linker.Linker) {
28
+ this.linkerClass = linkerClass
29
+ this.queuedList = queuedList === null ? new listClass(linkerClass) : queuedList
30
+ }
31
+
32
+ /**
33
+ * Take the item from the front of the queue.
34
+ * @returns The item, or null when the queue is empty
35
+ */
36
+ dequeue () {
37
+ const front = this.queuedList.first
38
+ if (front === null || typeof front === 'undefined') {
39
+ return null
40
+ }
41
+ this.queuedList.remove(front)
42
+ return front.data
43
+ }
44
+
45
+ /**
46
+ * Check whether the queue has no items.
47
+ */
48
+ empty () {
49
+ return this.size() <= 0
50
+ }
51
+
52
+ /**
53
+ * Add an item to the back of the queue.
54
+ * @param data The item to add
55
+ * @returns This queue, so that adding can be chained
56
+ */
57
+ enqueue (data) {
58
+ // The item is wrapped here rather than left to the list, since the list treats objects that look like a linker's
59
+ // settings (they have a data property) as such, and a queue must give back exactly what it was given
60
+ this.queuedList.append(new this.linkerClass({
61
+ data
62
+ }))
63
+ return this
64
+ }
65
+
66
+ /**
67
+ * Look at the item at the front of the queue, without removing it.
68
+ * @returns The item, or null when the queue is empty
69
+ */
70
+ peek () {
71
+ const front = this.queuedList.first
72
+ return front === null || typeof front === 'undefined' ? null : front.data
73
+ }
74
+
75
+ /**
76
+ * Count the items in the queue.
77
+ */
78
+ size () {
79
+ return this.queuedList.length
80
+ }
81
+
82
+ /**
83
+ * Iterate over the items from the front of the queue to the back, without removing them.
84
+ */
85
+ [Symbol.iterator] () {
86
+ const linkers = this.queuedList[Symbol.iterator]()
87
+ return {
88
+ next: () => {
89
+ const result = linkers.next()
90
+ return result.done
91
+ ? {
92
+ done: true,
93
+ value: undefined
94
+ }
95
+ : {
96
+ done: false,
97
+ value: result.value.data
98
+ }
99
+ }
100
+ }
101
+ }
102
+ }
103
+ /**
104
+ * Convert an array to a Queue, the first value is at the front.
105
+ * @param values The items to queue
106
+ * @param listClass The type of list used to store the items
107
+ * @param linkerClass The class used to hold each queued item
108
+ */
109
+ exports.Queue = Queue
110
+ Queue.fromArray = (values = [], listClass = _LinkedList.LinkedList, linkerClass = _Linker.Linker) => {
111
+ const queue = new Queue(null, listClass, linkerClass)
112
+ values.forEach(value => queue.enqueue(value))
113
+ return queue
114
+ }
@@ -1,83 +1,74 @@
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
+ * queueable item.
3
+ */
4
+ import { completeResponse, IsRunnable } from '../../recipes/Runnable';
5
+ import { IsLinker } from '../../recipes/IsLinker';
6
+ /**
7
+ * Queueable represents a runnable entry in a queue.
8
+ * @extends Linker
9
+ */
10
+ export declare class Queueable 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 Queueable;
13
+ /** The task (or data) this queueable holds. */
14
+ data: any;
15
+ /** The queueable after this one, or null when this is the last. */
16
+ next: Queueable | null;
17
+ /** Whether this queueable has been run to completion. */
18
+ complete: boolean;
19
+ /** Whether this queueable may run, or a function which answers that when asked. */
20
+ ready: Function | boolean;
21
+ /** Whether this queueable is running right now. */
22
+ running: boolean;
23
+ /**
24
+ * Create a queueable item that can be used in a queue.
25
+ * @param queueableData The settings for the new queueable.
26
+ * @param queueableData.task The data to be stored in this queueable
27
+ * @param queueableData.next The reference to the next queueable if any
28
+ * @param queueableData.ready Indicate if the queueable is ready to run
29
+ */
30
+ constructor({ task, next, ready }?: {
31
+ task?: any;
32
+ next?: Queueable | null;
33
+ ready?: boolean | Function;
34
+ });
35
+ /**
36
+ * Check ready state.
37
+ */
38
+ get isReady(): boolean;
39
+ /**
40
+ * Retrieve the data which should be formed as a task.
41
+ */
42
+ get task(): any;
43
+ /**
44
+ * Set this queueable as completed.
45
+ * @param completeResponse The result to report for the task.
46
+ * @param completeResponse.success Indicate when the task failed (use false) or give a success message
47
+ * @param completeResponse.error Indicate a task was error-free (use false) or give an error message
48
+ * @param completeResponse.context Provide additional data in the response
49
+ */
50
+ markCompleted({ success, error, context }?: {
51
+ success?: any;
52
+ error?: any;
53
+ context?: any;
54
+ }): completeResponse;
55
+ /**
56
+ * Intend to run the queued task when it is ready. If ready, mark this task as running and run the task.
57
+ */
58
+ run(): completeResponse;
59
+ /**
60
+ * Make a new Queueable from the data given if it is not already a valid Queueable.
61
+ * @param queueable Return a valid Queueable instance from given data, or even an already valid one.
62
+ * @param classType Provide the type of IsLinker to use.
63
+ */
64
+ static make: (queueable: Queueable | any, classType?: any) => IsLinker;
65
+ /**
66
+ * Convert an array into Queueable instances, return the head and tail Queueables.
67
+ * @param values Provide an array of data that will be converted to a chain of queueable linkers.
68
+ * @param classType Provide the type of IsLinker to use.
69
+ */
70
+ static fromArray: (values?: Array<any>, classType?: any) => {
71
+ head: IsLinker;
72
+ tail: IsLinker;
73
+ };
74
+ }