collect-your-stuff 1.3.0 → 1.3.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.
Files changed (46) hide show
  1. package/README.md +802 -77
  2. package/dist/collections/arrayable/ArrayElement.d.ts +2 -0
  3. package/dist/collections/arrayable/ArrayElement.js +4 -2
  4. package/dist/collections/arrayable/ArrayElement.min.js +1 -1
  5. package/dist/collections/arrayable/Arrayable.d.ts +25 -11
  6. package/dist/collections/arrayable/Arrayable.js +37 -12
  7. package/dist/collections/arrayable/Arrayable.min.js +1 -1
  8. package/dist/collections/doubly-linked-list/DoubleLinker.d.ts +5 -1
  9. package/dist/collections/doubly-linked-list/DoubleLinker.js +5 -1
  10. package/dist/collections/doubly-linked-list/DoublyLinkedList.d.ts +11 -5
  11. package/dist/collections/doubly-linked-list/DoublyLinkedList.js +43 -25
  12. package/dist/collections/doubly-linked-list/DoublyLinkedList.min.js +1 -1
  13. package/dist/collections/linked-list/LinkedList.d.ts +13 -7
  14. package/dist/collections/linked-list/LinkedList.js +42 -23
  15. package/dist/collections/linked-list/LinkedList.min.js +1 -1
  16. package/dist/collections/linked-list/Linker.d.ts +5 -2
  17. package/dist/collections/linked-list/Linker.js +9 -5
  18. package/dist/collections/linked-list/Linker.min.js +1 -1
  19. package/dist/collections/linked-tree-list/LinkedTreeList.d.ts +7 -1
  20. package/dist/collections/linked-tree-list/LinkedTreeList.js +6 -1
  21. package/dist/collections/linked-tree-list/TreeLinker.d.ts +7 -1
  22. package/dist/collections/linked-tree-list/TreeLinker.js +7 -1
  23. package/dist/collections/queue/Queue.d.ts +6 -3
  24. package/dist/collections/queue/Queue.js +23 -18
  25. package/dist/collections/queue/Queue.min.js +1 -1
  26. package/dist/collections/queue/Queueable.d.ts +10 -4
  27. package/dist/collections/queue/Queueable.js +11 -6
  28. package/dist/collections/queue/Queueable.min.js +1 -1
  29. package/dist/collections/stack/Stack.d.ts +4 -3
  30. package/dist/collections/stack/Stack.js +4 -4
  31. package/dist/collections/stack/Stack.min.js +1 -1
  32. package/dist/collections/stack/Stackable.d.ts +4 -1
  33. package/dist/collections/stack/Stackable.js +7 -5
  34. package/dist/collections/stack/Stackable.min.js +1 -1
  35. package/dist/main.d.ts +2 -2
  36. package/dist/recipes/ArrayIterator.d.ts +10 -0
  37. package/dist/recipes/ArrayIterator.js +10 -0
  38. package/dist/recipes/DoubleLinkerIterator.d.ts +9 -0
  39. package/dist/recipes/DoubleLinkerIterator.js +9 -0
  40. package/dist/recipes/LinkerIterator.d.ts +9 -0
  41. package/dist/recipes/LinkerIterator.js +9 -0
  42. package/dist/recipes/Runnable.d.ts +3 -2
  43. package/dist/recipes/Runnable.js +3 -2
  44. package/dist/recipes/TreeLinkerIterator.d.ts +9 -0
  45. package/dist/recipes/TreeLinkerIterator.js +9 -0
  46. package/package.json +2 -1
@@ -12,7 +12,7 @@ var _Linker = require('../linked-list/Linker')
12
12
  class Stackable {
13
13
  /**
14
14
  * Create a stackable item that can be used in a stack.
15
- * @param {Object} [stackData={}]
15
+ * @param {Object} [stackData={}] The settings for the new stackable.
16
16
  * @param {*} [stackData.task=null] The data to be stored in this stackable
17
17
  * @param {Stackable|null} [stackData.next=null] The reference to the next stackable if any
18
18
  * @param {boolean|Function} [stackData.ready=false] Indicate if the stackable is ready to run
@@ -22,7 +22,9 @@ class Stackable {
22
22
  next = null,
23
23
  ready = false
24
24
  } = {}) {
25
+ /** The task (or data) this stackable holds. */
25
26
  this.data = null
27
+ /** The stackable below this one, or null when this is the bottom. */
26
28
  this.next = null
27
29
  this.classType = Stackable
28
30
  this.data = task
@@ -56,8 +58,8 @@ class Stackable {
56
58
  */
57
59
  exports.Stackable = Stackable
58
60
  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
+ 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
61
63
  return new classType({
62
64
  task: stackable
63
65
  })
@@ -66,13 +68,13 @@ Stackable.make = (stackable, classType = Stackable) => {
66
68
  // Already valid Stackable, return as-is
67
69
  return stackable
68
70
  }
69
- if (!stackable.task) {
71
+ if (!('task' in stackable)) {
70
72
  stackable = {
71
73
  task: stackable
72
74
  }
73
75
  }
74
76
  // Create the new node as the configured stackableClass
75
- return new Stackable(stackable)
77
+ return new classType(stackable)
76
78
  }
77
79
  /**
78
80
  * Convert an array into Stackable instances, return the head and tail Stackables.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Stackable=void 0;var _Linker=require("../linked-list/Linker");class Stackable{constructor({task:t=null,next:a=null,ready:e=!1}={}){this.data=null,this.next=null,this.classType=Stackable,this.data=t,this.next=a}get task(){return"function"==typeof this.data?this.data:()=>this.data}run(){return this.task()}}exports.Stackable=Stackable,Stackable.make=(t,a=Stackable)=>"object"!=typeof t?new a({task:t}):t.classType?t:(t.task||(t={task:t}),new Stackable(t)),Stackable.fromArray=(t=[],a=Stackable)=>_Linker.Linker.fromArray(t,a);
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Stackable=void 0;var _Linker=require("../linked-list/Linker");class Stackable{constructor({task:t=null,next:a=null,ready:e=!1}={}){this.data=null,this.next=null,this.classType=Stackable,this.data=t,this.next=a}get task(){return"function"==typeof this.data?this.data:()=>this.data}run(){return this.task()}}exports.Stackable=Stackable,Stackable.make=(t,a=Stackable)=>null===t||"object"!=typeof t?new a({task:t}):t.classType?t:("task"in t||(t={task:t}),new a(t)),Stackable.fromArray=(t=[],a=Stackable)=>_Linker.Linker.fromArray(t,a);
package/dist/main.d.ts CHANGED
@@ -56,8 +56,8 @@ declare const collectYourStuff: {
56
56
  Runnable: typeof import("./recipes/Runnable").Runnable;
57
57
  };
58
58
  services: {
59
- parseTree: (tree: import("./recipes/IsTree").IsTree, callback: import("./recipes/IsArrayable").forEachCallback) => import("./recipes/IsTree").IsTree;
60
- parseTreeNext: (treeNode: import("./recipes/IsTreeNode").IsTreeNode) => import("./recipes/IsTreeNode").IsTreeNode | null;
59
+ parseTree: (tree: import("./main").IsTree, callback: import("./main").forEachCallback) => import("./main").IsTree;
60
+ parseTreeNext: (treeNode: import("./main").IsTreeNode) => import("./main").IsTreeNode | null;
61
61
  };
62
62
  };
63
63
  export default collectYourStuff;
@@ -5,6 +5,16 @@ import { IsElement } from './IsElement';
5
5
  export declare class ArrayIterator implements Iterator<IsElement> {
6
6
  private readonly innerList;
7
7
  private index;
8
+ /**
9
+ * Create an iterator over the given array.
10
+ * @param {Array<IsElement>} innerList The elements to iterate over.
11
+ * @param {number} [index=0] The position to start from.
12
+ */
8
13
  constructor(innerList: Array<IsElement>, index?: number);
14
+ /**
15
+ * Get the next element, moving the iterator forward.
16
+ * @param {*} [value] Not used, present to match the Iterator interface.
17
+ * @return {IteratorResult<IsElement>} The next element, or done when there are no more.
18
+ */
9
19
  next(value?: any): IteratorResult<IsElement>;
10
20
  }
@@ -8,11 +8,21 @@ exports.ArrayIterator = void 0
8
8
  * Class ArrayIterator returns the next value when using elements of array type list.
9
9
  */
10
10
  class ArrayIterator {
11
+ /**
12
+ * Create an iterator over the given array.
13
+ * @param {Array<IsElement>} innerList The elements to iterate over.
14
+ * @param {number} [index=0] The position to start from.
15
+ */
11
16
  constructor (innerList, index = 0) {
12
17
  this.innerList = innerList
13
18
  this.index = index
14
19
  }
15
20
 
21
+ /**
22
+ * Get the next element, moving the iterator forward.
23
+ * @param {*} [value] Not used, present to match the Iterator interface.
24
+ * @return {IteratorResult<IsElement>} The next element, or done when there are no more.
25
+ */
16
26
  next (value) {
17
27
  if (this.index < this.innerList.length) {
18
28
  return {
@@ -4,6 +4,15 @@ import { IsDoubleLinker } from './IsDoubleLinker';
4
4
  */
5
5
  export declare class DoubleLinkerIterator implements Iterator<IsDoubleLinker> {
6
6
  private current;
7
+ /**
8
+ * Create an iterator starting at the given item.
9
+ * @param {IsDoubleLinker} current The item to start from.
10
+ */
7
11
  constructor(current: IsDoubleLinker);
12
+ /**
13
+ * Get the current item and move on to the following one.
14
+ * @param {*} [value] Not used, present to match the Iterator interface.
15
+ * @return {IteratorResult<IsDoubleLinker>} The current item, or done when there are no more.
16
+ */
8
17
  next(value?: any): IteratorResult<IsDoubleLinker>;
9
18
  }
@@ -8,10 +8,19 @@ exports.DoubleLinkerIterator = void 0
8
8
  * Class DoubleLinkerIterator returns the next value when using linkers of linked type lists.
9
9
  */
10
10
  class DoubleLinkerIterator {
11
+ /**
12
+ * Create an iterator starting at the given item.
13
+ * @param {IsDoubleLinker} current The item to start from.
14
+ */
11
15
  constructor (current) {
12
16
  this.current = current
13
17
  }
14
18
 
19
+ /**
20
+ * Get the current item and move on to the following one.
21
+ * @param {*} [value] Not used, present to match the Iterator interface.
22
+ * @return {IteratorResult<IsDoubleLinker>} The current item, or done when there are no more.
23
+ */
15
24
  next (value) {
16
25
  const result = {
17
26
  value: this.current,
@@ -4,6 +4,15 @@ import { IsLinker } from './IsLinker';
4
4
  */
5
5
  export declare class LinkerIterator implements Iterator<IsLinker> {
6
6
  private current;
7
+ /**
8
+ * Create an iterator starting at the given item.
9
+ * @param {IsLinker} current The item to start from.
10
+ */
7
11
  constructor(current: IsLinker);
12
+ /**
13
+ * Get the current item and move on to the following one.
14
+ * @param {*} [value] Not used, present to match the Iterator interface.
15
+ * @return {IteratorResult<IsLinker>} The current item, or done when there are no more.
16
+ */
8
17
  next(value?: any): IteratorResult<IsLinker>;
9
18
  }
@@ -8,10 +8,19 @@ exports.LinkerIterator = void 0
8
8
  * Class LinkerIterator returns the next value when using linkers of linked type lists.
9
9
  */
10
10
  class LinkerIterator {
11
+ /**
12
+ * Create an iterator starting at the given item.
13
+ * @param {IsLinker} current The item to start from.
14
+ */
11
15
  constructor (current) {
12
16
  this.current = current
13
17
  }
14
18
 
19
+ /**
20
+ * Get the current item and move on to the following one.
21
+ * @param {*} [value] Not used, present to match the Iterator interface.
22
+ * @return {IteratorResult<IsLinker>} The current item, or done when there are no more.
23
+ */
15
24
  next (value) {
16
25
  const result = {
17
26
  value: this.current,
@@ -28,10 +28,11 @@ export interface IsRunnable {
28
28
  * Identify a class that can be run.
29
29
  */
30
30
  export declare class Runnable implements IsRunnable {
31
+ /** The task (or data) this runnable holds. */
31
32
  data: any;
32
33
  /**
33
34
  * Instantiate a Runnable class.
34
- * @param {*} data
35
+ * @param {*} [data=null] The task (a function) or the data which the task returns.
35
36
  */
36
37
  constructor(data?: any);
37
38
  /**
@@ -47,7 +48,7 @@ export declare class Runnable implements IsRunnable {
47
48
  /**
48
49
  * Check if a given thing is Runnable
49
50
  * @memberof Runnable
50
- * @param {*} thing
51
+ * @param {*} thing The value to check, or nothing to check whether this class is Runnable.
51
52
  * @return {boolean}
52
53
  */
53
54
  static isRunnable(thing: any): boolean;
@@ -16,9 +16,10 @@ exports.Runnable = void 0
16
16
  class Runnable {
17
17
  /**
18
18
  * Instantiate a Runnable class.
19
- * @param {*} data
19
+ * @param {*} [data=null] The task (a function) or the data which the task returns.
20
20
  */
21
21
  constructor (data = null) {
22
+ /** The task (or data) this runnable holds. */
22
23
  this.data = null
23
24
  this.data = data
24
25
  }
@@ -45,7 +46,7 @@ class Runnable {
45
46
  /**
46
47
  * Check if a given thing is Runnable
47
48
  * @memberof Runnable
48
- * @param {*} thing
49
+ * @param {*} thing The value to check, or nothing to check whether this class is Runnable.
49
50
  * @return {boolean}
50
51
  */
51
52
  static isRunnable (thing) {
@@ -4,6 +4,15 @@ import { IsTreeNode } from './IsTreeNode';
4
4
  */
5
5
  export declare class TreeLinkerIterator implements Iterator<IsTreeNode> {
6
6
  private current;
7
+ /**
8
+ * Create an iterator starting at the given item.
9
+ * @param {IsTreeNode} current The item to start from.
10
+ */
7
11
  constructor(current: IsTreeNode);
12
+ /**
13
+ * Get the current item and move on to the following one (left-first, down each branch).
14
+ * @param {*} [value] Not used, present to match the Iterator interface.
15
+ * @return {IteratorResult<IsTreeNode>} The current item, or done when there are no more.
16
+ */
8
17
  next(value?: any): IteratorResult<IsTreeNode>;
9
18
  }
@@ -9,10 +9,19 @@ var _parseTreeNext = require('../services/parseTreeNext')
9
9
  * Class TreeLinkerIterator returns the next value taking a left-first approach down a tree.
10
10
  */
11
11
  class TreeLinkerIterator {
12
+ /**
13
+ * Create an iterator starting at the given item.
14
+ * @param {IsTreeNode} current The item to start from.
15
+ */
12
16
  constructor (current) {
13
17
  this.current = current
14
18
  }
15
19
 
20
+ /**
21
+ * Get the current item and move on to the following one (left-first, down each branch).
22
+ * @param {*} [value] Not used, present to match the Iterator interface.
23
+ * @return {IteratorResult<IsTreeNode>} The current item, or done when there are no more.
24
+ */
16
25
  next (value) {
17
26
  const result = {
18
27
  value: this.current,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "collect-your-stuff",
3
3
  "description": "Use a variety of collections to collect your stuff when building code.",
4
- "version": "1.3.0",
4
+ "version": "1.3.2",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",
7
7
  "author": "Joshua Heagle",
@@ -19,6 +19,7 @@
19
19
  "htmldocs": "jsdoc -R MAIN.md -c ./.jsdoc.conf.js -d docs",
20
20
  "readme": "gulp readme",
21
21
  "test": "gulp testFull",
22
+ "typecheck": "tsc --noEmit -p tsconfig.json",
22
23
  "test:quick": "gulp testQuick",
23
24
  "watch": "gulp watchFull",
24
25
  "watch:test": "gulp watchTest"