collect-your-stuff 1.2.6 → 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 -22859
- 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 -70
- package/dist/collections/arrayable/ArrayElement.min.js +1 -1
- package/dist/collections/arrayable/Arrayable.d.ts +108 -108
- package/dist/collections/arrayable/Arrayable.js +188 -196
- package/dist/collections/arrayable/Arrayable.min.js +1 -1
- package/dist/collections/doubly-linked-list/DoubleLinker.d.ts +46 -46
- package/dist/collections/doubly-linked-list/DoubleLinker.js +69 -77
- package/dist/collections/doubly-linked-list/DoubleLinker.min.js +1 -1
- package/dist/collections/doubly-linked-list/DoublyLinkedList.d.ts +113 -113
- package/dist/collections/doubly-linked-list/DoublyLinkedList.js +274 -277
- 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 -241
- package/dist/collections/linked-list/LinkedList.min.js +1 -1
- package/dist/collections/linked-list/Linker.d.ts +43 -43
- package/dist/collections/linked-list/Linker.js +80 -86
- package/dist/collections/linked-list/Linker.min.js +1 -1
- package/dist/collections/linked-tree-list/LinkedTreeList.d.ts +135 -135
- package/dist/collections/linked-tree-list/LinkedTreeList.js +252 -261
- package/dist/collections/linked-tree-list/LinkedTreeList.min.js +1 -1
- package/dist/collections/linked-tree-list/TreeLinker.d.ts +63 -63
- package/dist/collections/linked-tree-list/TreeLinker.js +79 -92
- package/dist/collections/linked-tree-list/TreeLinker.min.js +1 -1
- package/dist/collections/queue/Queue.d.ts +63 -63
- package/dist/collections/queue/Queue.js +130 -136
- package/dist/collections/queue/Queue.min.js +1 -1
- package/dist/collections/queue/Queueable.d.ts +77 -77
- package/dist/collections/queue/Queueable.js +141 -151
- package/dist/collections/queue/Queueable.min.js +1 -1
- package/dist/collections/stack/Stack.d.ts +63 -63
- package/dist/collections/stack/Stack.js +106 -112
- package/dist/collections/stack/Stack.min.js +1 -1
- package/dist/collections/stack/Stackable.d.ts +56 -56
- package/dist/collections/stack/Stackable.js +83 -91
- package/dist/collections/stack/Stackable.min.js +1 -1
- 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 -30
- package/dist/recipes/ArrayIterator.min.js +1 -1
- 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 -69
- package/dist/recipes/Runnable.min.js +1 -1
- 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 +2 -2
package/dist/recipes/Runnable.js
CHANGED
|
@@ -1,69 +1,68 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.Runnable = void 0
|
|
7
|
-
/**
|
|
8
|
-
* @file Runnable class recipe.
|
|
9
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
10
|
-
* @version 1.0.0
|
|
11
|
-
* @memberOf module:collect-your-stuff
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* Identify a class that can be run.
|
|
15
|
-
*/
|
|
16
|
-
class Runnable {
|
|
17
|
-
/**
|
|
18
|
-
* Instantiate a Runnable class.
|
|
19
|
-
* @param {*} data
|
|
20
|
-
*/
|
|
21
|
-
constructor () {
|
|
22
|
-
|
|
23
|
-
this.data =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
*
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
*
|
|
48
|
-
* @
|
|
49
|
-
* @
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
exports.Runnable = Runnable
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.Runnable = void 0
|
|
7
|
+
/**
|
|
8
|
+
* @file Runnable class recipe.
|
|
9
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
10
|
+
* @version 1.0.0
|
|
11
|
+
* @memberOf module:collect-your-stuff
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Identify a class that can be run.
|
|
15
|
+
*/
|
|
16
|
+
class Runnable {
|
|
17
|
+
/**
|
|
18
|
+
* Instantiate a Runnable class.
|
|
19
|
+
* @param {*} data
|
|
20
|
+
*/
|
|
21
|
+
constructor (data = null) {
|
|
22
|
+
this.data = null
|
|
23
|
+
this.data = data
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Retrieve the data which should be formed as a task.
|
|
28
|
+
* @return {Function}
|
|
29
|
+
*/
|
|
30
|
+
get task () {
|
|
31
|
+
if (typeof this.data === 'function') {
|
|
32
|
+
return this.data
|
|
33
|
+
}
|
|
34
|
+
return () => this.data
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Run the runnable task.
|
|
39
|
+
* @return {*}
|
|
40
|
+
*/
|
|
41
|
+
run () {
|
|
42
|
+
return this.task()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Check if a given thing is Runnable
|
|
47
|
+
* @memberof Runnable
|
|
48
|
+
* @param {*} thing
|
|
49
|
+
* @return {boolean}
|
|
50
|
+
*/
|
|
51
|
+
static isRunnable (thing) {
|
|
52
|
+
if (typeof thing === 'undefined') {
|
|
53
|
+
// No argument past, this class is runnable
|
|
54
|
+
return this instanceof Runnable
|
|
55
|
+
}
|
|
56
|
+
if (typeof thing !== 'object') {
|
|
57
|
+
// It is not even an object, so cannot be a class instance
|
|
58
|
+
return false
|
|
59
|
+
}
|
|
60
|
+
if (typeof thing.task !== 'function') {
|
|
61
|
+
// It does not have a task getter that returns a function
|
|
62
|
+
return false
|
|
63
|
+
}
|
|
64
|
+
// Finally, it has a runnable 'run' method. This method should return the result of running the task.
|
|
65
|
+
return typeof thing.run === 'function'
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.Runnable = Runnable
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Runnable=void 0;class Runnable{constructor(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Runnable=void 0;class Runnable{constructor(t=null){this.data=null,this.data=t}get task(){return"function"==typeof this.data?this.data:()=>this.data}run(){return this.task()}static isRunnable(t){return void 0===t?this instanceof Runnable:"object"==typeof t&&("function"==typeof t.task&&"function"==typeof t.run)}}exports.Runnable=Runnable;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { IsTreeNode } from './IsTreeNode';
|
|
2
|
-
/**
|
|
3
|
-
* Class TreeLinkerIterator returns the next value taking a left-first approach down a tree.
|
|
4
|
-
*/
|
|
5
|
-
export declare class TreeLinkerIterator implements Iterator<IsTreeNode> {
|
|
6
|
-
private current;
|
|
7
|
-
constructor(current: IsTreeNode);
|
|
8
|
-
next(value?: any): IteratorResult<IsTreeNode>;
|
|
9
|
-
}
|
|
1
|
+
import { IsTreeNode } from './IsTreeNode';
|
|
2
|
+
/**
|
|
3
|
+
* Class TreeLinkerIterator returns the next value taking a left-first approach down a tree.
|
|
4
|
+
*/
|
|
5
|
+
export declare class TreeLinkerIterator implements Iterator<IsTreeNode> {
|
|
6
|
+
private current;
|
|
7
|
+
constructor(current: IsTreeNode);
|
|
8
|
+
next(value?: any): IteratorResult<IsTreeNode>;
|
|
9
|
+
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.TreeLinkerIterator = void 0
|
|
7
|
-
var _parseTreeNext = require('../services/parseTreeNext')
|
|
8
|
-
/**
|
|
9
|
-
* Class TreeLinkerIterator returns the next value taking a left-first approach down a tree.
|
|
10
|
-
*/
|
|
11
|
-
class TreeLinkerIterator {
|
|
12
|
-
constructor (current) {
|
|
13
|
-
this.current = current
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
next (value) {
|
|
17
|
-
const result = {
|
|
18
|
-
value: this.current,
|
|
19
|
-
done: !this.current
|
|
20
|
-
}
|
|
21
|
-
this.current = (0, _parseTreeNext.parseTreeNext)(this.current)
|
|
22
|
-
return result
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.TreeLinkerIterator = TreeLinkerIterator
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.TreeLinkerIterator = void 0
|
|
7
|
+
var _parseTreeNext = require('../services/parseTreeNext')
|
|
8
|
+
/**
|
|
9
|
+
* Class TreeLinkerIterator returns the next value taking a left-first approach down a tree.
|
|
10
|
+
*/
|
|
11
|
+
class TreeLinkerIterator {
|
|
12
|
+
constructor (current) {
|
|
13
|
+
this.current = current
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
next (value) {
|
|
17
|
+
const result = {
|
|
18
|
+
value: this.current,
|
|
19
|
+
done: !this.current
|
|
20
|
+
}
|
|
21
|
+
this.current = (0, _parseTreeNext.parseTreeNext)(this.current)
|
|
22
|
+
return result
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.TreeLinkerIterator = TreeLinkerIterator
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file sample classes which follow a pattern (have certain members or methods).
|
|
3
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
-
* @version 1.0.0
|
|
5
|
-
* @memberOf module:collect-your-stuff
|
|
6
|
-
*/
|
|
7
|
-
import { ArrayIterator } from './ArrayIterator';
|
|
8
|
-
import { Runnable } from './Runnable';
|
|
9
|
-
/**
|
|
10
|
-
* List of class declarations that can be used to specify attributes for a style of object / class.
|
|
11
|
-
*/
|
|
12
|
-
export declare const recipes: {
|
|
13
|
-
ArrayIterator: typeof ArrayIterator;
|
|
14
|
-
Runnable: typeof Runnable;
|
|
15
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* @file sample classes which follow a pattern (have certain members or methods).
|
|
3
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
* @memberOf module:collect-your-stuff
|
|
6
|
+
*/
|
|
7
|
+
import { ArrayIterator } from './ArrayIterator';
|
|
8
|
+
import { Runnable } from './Runnable';
|
|
9
|
+
/**
|
|
10
|
+
* List of class declarations that can be used to specify attributes for a style of object / class.
|
|
11
|
+
*/
|
|
12
|
+
export declare const recipes: {
|
|
13
|
+
ArrayIterator: typeof ArrayIterator;
|
|
14
|
+
Runnable: typeof Runnable;
|
|
15
|
+
};
|
package/dist/recipes/recipes.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.recipes = void 0
|
|
7
|
-
var _ArrayIterator = require('./ArrayIterator')
|
|
8
|
-
var _Runnable = require('./Runnable')
|
|
9
|
-
/**
|
|
10
|
-
* @file sample classes which follow a pattern (have certain members or methods).
|
|
11
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
12
|
-
* @version 1.0.0
|
|
13
|
-
* @memberOf module:collect-your-stuff
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* List of class declarations that can be used to specify attributes for a style of object / class.
|
|
18
|
-
*/
|
|
19
|
-
const recipes = exports.recipes = {
|
|
20
|
-
ArrayIterator: _ArrayIterator.ArrayIterator,
|
|
21
|
-
Runnable: _Runnable.Runnable
|
|
22
|
-
}
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.recipes = void 0
|
|
7
|
+
var _ArrayIterator = require('./ArrayIterator')
|
|
8
|
+
var _Runnable = require('./Runnable')
|
|
9
|
+
/**
|
|
10
|
+
* @file sample classes which follow a pattern (have certain members or methods).
|
|
11
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
12
|
+
* @version 1.0.0
|
|
13
|
+
* @memberOf module:collect-your-stuff
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* List of class declarations that can be used to specify attributes for a style of object / class.
|
|
18
|
+
*/
|
|
19
|
+
const recipes = exports.recipes = {
|
|
20
|
+
ArrayIterator: _ArrayIterator.ArrayIterator,
|
|
21
|
+
Runnable: _Runnable.Runnable
|
|
22
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { forEachCallback } from '../recipes/IsArrayable';
|
|
2
|
-
import { IsTree } from '../recipes/IsTree';
|
|
3
|
-
/**
|
|
4
|
-
* Loop over all the nodes in a tree starting from left and apply a callback for each
|
|
5
|
-
* @param {IsArrayable<IsTreeNode>} tree
|
|
6
|
-
* @param {forEachCallback} callback
|
|
7
|
-
* @returns {IsArrayable<IsTreeNode>}
|
|
8
|
-
*/
|
|
9
|
-
export declare const parseTree: (tree: IsTree, callback: forEachCallback) => IsTree;
|
|
1
|
+
import { forEachCallback } from '../recipes/IsArrayable';
|
|
2
|
+
import { IsTree } from '../recipes/IsTree';
|
|
3
|
+
/**
|
|
4
|
+
* Loop over all the nodes in a tree starting from left and apply a callback for each
|
|
5
|
+
* @param {IsArrayable<IsTreeNode>} tree
|
|
6
|
+
* @param {forEachCallback} callback
|
|
7
|
+
* @returns {IsArrayable<IsTreeNode>}
|
|
8
|
+
*/
|
|
9
|
+
export declare const parseTree: (tree: IsTree, callback: forEachCallback) => IsTree;
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.parseTree = void 0
|
|
7
|
-
var _parseTreeNext = require('./parseTreeNext')
|
|
8
|
-
/**
|
|
9
|
-
* Loop over all the nodes in a tree starting from left and apply a callback for each
|
|
10
|
-
* @param {IsArrayable<IsTreeNode>} tree
|
|
11
|
-
* @param {forEachCallback} callback
|
|
12
|
-
* @returns {IsArrayable<IsTreeNode>}
|
|
13
|
-
*/
|
|
14
|
-
const parseTree = (tree, callback) => {
|
|
15
|
-
let index = 0
|
|
16
|
-
let current = tree.rootParent
|
|
17
|
-
while (current !== null) {
|
|
18
|
-
callback(current, index, tree)
|
|
19
|
-
current = (0, _parseTreeNext.parseTreeNext)(current)
|
|
20
|
-
++index
|
|
21
|
-
}
|
|
22
|
-
return tree
|
|
23
|
-
}
|
|
24
|
-
exports.parseTree = parseTree
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.parseTree = void 0
|
|
7
|
+
var _parseTreeNext = require('./parseTreeNext')
|
|
8
|
+
/**
|
|
9
|
+
* Loop over all the nodes in a tree starting from left and apply a callback for each
|
|
10
|
+
* @param {IsArrayable<IsTreeNode>} tree
|
|
11
|
+
* @param {forEachCallback} callback
|
|
12
|
+
* @returns {IsArrayable<IsTreeNode>}
|
|
13
|
+
*/
|
|
14
|
+
const parseTree = (tree, callback) => {
|
|
15
|
+
let index = 0
|
|
16
|
+
let current = tree.rootParent
|
|
17
|
+
while (current !== null) {
|
|
18
|
+
callback(current, index, tree)
|
|
19
|
+
current = (0, _parseTreeNext.parseTreeNext)(current)
|
|
20
|
+
++index
|
|
21
|
+
}
|
|
22
|
+
return tree
|
|
23
|
+
}
|
|
24
|
+
exports.parseTree = parseTree
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { IsTreeNode } from '../recipes/IsTreeNode';
|
|
2
|
-
/**
|
|
3
|
-
* Be able to parse over every node in a tree.
|
|
4
|
-
* 1. Start at root (get root parent)
|
|
5
|
-
* 2. Get first child (repeat until no children)
|
|
6
|
-
* 3. Check next child
|
|
7
|
-
* 4. Repeat 2
|
|
8
|
-
* 5. Repeat 3
|
|
9
|
-
* 6. If no next child, return to parent and repeat 3
|
|
10
|
-
* 7. Stop at root (next is null and parent is null
|
|
11
|
-
* @param {IsTreeNode} treeNode Provide a node in a tree and get the next node (left-first approach)
|
|
12
|
-
* @returns {IsTreeNode|null}
|
|
13
|
-
*/
|
|
14
|
-
export declare const parseTreeNext: (treeNode: IsTreeNode) => IsTreeNode | null;
|
|
1
|
+
import { IsTreeNode } from '../recipes/IsTreeNode';
|
|
2
|
+
/**
|
|
3
|
+
* Be able to parse over every node in a tree.
|
|
4
|
+
* 1. Start at root (get root parent)
|
|
5
|
+
* 2. Get first child (repeat until no children)
|
|
6
|
+
* 3. Check next child
|
|
7
|
+
* 4. Repeat 2
|
|
8
|
+
* 5. Repeat 3
|
|
9
|
+
* 6. If no next child, return to parent and repeat 3
|
|
10
|
+
* 7. Stop at root (next is null and parent is null
|
|
11
|
+
* @param {IsTreeNode} treeNode Provide a node in a tree and get the next node (left-first approach)
|
|
12
|
+
* @returns {IsTreeNode|null}
|
|
13
|
+
*/
|
|
14
|
+
export declare const parseTreeNext: (treeNode: IsTreeNode) => IsTreeNode | null;
|
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.parseTreeNext = void 0
|
|
7
|
-
/**
|
|
8
|
-
* Be able to parse over every node in a tree.
|
|
9
|
-
* 1. Start at root (get root parent)
|
|
10
|
-
* 2. Get first child (repeat until no children)
|
|
11
|
-
* 3. Check next child
|
|
12
|
-
* 4. Repeat 2
|
|
13
|
-
* 5. Repeat 3
|
|
14
|
-
* 6. If no next child, return to parent and repeat 3
|
|
15
|
-
* 7. Stop at root (next is null and parent is null
|
|
16
|
-
* @param {IsTreeNode} treeNode Provide a node in a tree and get the next node (left-first approach)
|
|
17
|
-
* @returns {IsTreeNode|null}
|
|
18
|
-
*/
|
|
19
|
-
const parseTreeNext = treeNode => {
|
|
20
|
-
if (!treeNode) {
|
|
21
|
-
return null
|
|
22
|
-
}
|
|
23
|
-
let test = null
|
|
24
|
-
if (treeNode.children && treeNode.children.length) {
|
|
25
|
-
// Go down the left side of the tree
|
|
26
|
-
test = treeNode.children.first
|
|
27
|
-
}
|
|
28
|
-
if (!test) {
|
|
29
|
-
// Reached the bottom, go the next node on the right
|
|
30
|
-
test = treeNode.next
|
|
31
|
-
}
|
|
32
|
-
if (!test && treeNode.parent) {
|
|
33
|
-
// No more child nodes, return to parent and check parent sibling on the right
|
|
34
|
-
let parentNext = treeNode.parent.next
|
|
35
|
-
let parent = treeNode.parent
|
|
36
|
-
while (parent && !parentNext) {
|
|
37
|
-
parentNext = parent.next
|
|
38
|
-
// Keep checking parent next, until there are no more parents, or we find the parent sibling
|
|
39
|
-
parent = parent.parent
|
|
40
|
-
}
|
|
41
|
-
// This may be the parent sibling, or it could be null indicating we are done
|
|
42
|
-
test = parentNext
|
|
43
|
-
}
|
|
44
|
-
// Finally, either use the node we found, or it may be null
|
|
45
|
-
return test
|
|
46
|
-
}
|
|
47
|
-
exports.parseTreeNext = parseTreeNext
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.parseTreeNext = void 0
|
|
7
|
+
/**
|
|
8
|
+
* Be able to parse over every node in a tree.
|
|
9
|
+
* 1. Start at root (get root parent)
|
|
10
|
+
* 2. Get first child (repeat until no children)
|
|
11
|
+
* 3. Check next child
|
|
12
|
+
* 4. Repeat 2
|
|
13
|
+
* 5. Repeat 3
|
|
14
|
+
* 6. If no next child, return to parent and repeat 3
|
|
15
|
+
* 7. Stop at root (next is null and parent is null
|
|
16
|
+
* @param {IsTreeNode} treeNode Provide a node in a tree and get the next node (left-first approach)
|
|
17
|
+
* @returns {IsTreeNode|null}
|
|
18
|
+
*/
|
|
19
|
+
const parseTreeNext = treeNode => {
|
|
20
|
+
if (!treeNode) {
|
|
21
|
+
return null
|
|
22
|
+
}
|
|
23
|
+
let test = null
|
|
24
|
+
if (treeNode.children && treeNode.children.length) {
|
|
25
|
+
// Go down the left side of the tree
|
|
26
|
+
test = treeNode.children.first
|
|
27
|
+
}
|
|
28
|
+
if (!test) {
|
|
29
|
+
// Reached the bottom, go the next node on the right
|
|
30
|
+
test = treeNode.next
|
|
31
|
+
}
|
|
32
|
+
if (!test && treeNode.parent) {
|
|
33
|
+
// No more child nodes, return to parent and check parent sibling on the right
|
|
34
|
+
let parentNext = treeNode.parent.next
|
|
35
|
+
let parent = treeNode.parent
|
|
36
|
+
while (parent && !parentNext) {
|
|
37
|
+
parentNext = parent.next
|
|
38
|
+
// Keep checking parent next, until there are no more parents, or we find the parent sibling
|
|
39
|
+
parent = parent.parent
|
|
40
|
+
}
|
|
41
|
+
// This may be the parent sibling, or it could be null indicating we are done
|
|
42
|
+
test = parentNext
|
|
43
|
+
}
|
|
44
|
+
// Finally, either use the node we found, or it may be null
|
|
45
|
+
return test
|
|
46
|
+
}
|
|
47
|
+
exports.parseTreeNext = parseTreeNext
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file some useful resources when working with collections.
|
|
3
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
-
* @version 1.1.0
|
|
5
|
-
* @memberOf module:collect-your-stuff
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* List helpful functions when dealing with collections.
|
|
9
|
-
*/
|
|
10
|
-
export declare const services: {
|
|
11
|
-
parseTree: (tree: import("../recipes/IsTree").IsTree, callback: import("../recipes/IsArrayable").forEachCallback) => import("../recipes/IsTree").IsTree;
|
|
12
|
-
parseTreeNext: (treeNode: import("../recipes/IsTreeNode").IsTreeNode) => import("../recipes/IsTreeNode").IsTreeNode;
|
|
13
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* @file some useful resources when working with collections.
|
|
3
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
+
* @version 1.1.0
|
|
5
|
+
* @memberOf module:collect-your-stuff
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* List helpful functions when dealing with collections.
|
|
9
|
+
*/
|
|
10
|
+
export declare const services: {
|
|
11
|
+
parseTree: (tree: import("../recipes/IsTree").IsTree, callback: import("../recipes/IsArrayable").forEachCallback) => import("../recipes/IsTree").IsTree;
|
|
12
|
+
parseTreeNext: (treeNode: import("../recipes/IsTreeNode").IsTreeNode) => import("../recipes/IsTreeNode").IsTreeNode | null;
|
|
13
|
+
};
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.services = void 0
|
|
7
|
-
var _parseTree = require('./parseTree')
|
|
8
|
-
var _parseTreeNext = require('./parseTreeNext')
|
|
9
|
-
/**
|
|
10
|
-
* @file some useful resources when working with collections.
|
|
11
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
12
|
-
* @version 1.1.0
|
|
13
|
-
* @memberOf module:collect-your-stuff
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* List helpful functions when dealing with collections.
|
|
18
|
-
*/
|
|
19
|
-
const services = exports.services = {
|
|
20
|
-
parseTree: _parseTree.parseTree,
|
|
21
|
-
parseTreeNext: _parseTreeNext.parseTreeNext
|
|
22
|
-
}
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.services = void 0
|
|
7
|
+
var _parseTree = require('./parseTree')
|
|
8
|
+
var _parseTreeNext = require('./parseTreeNext')
|
|
9
|
+
/**
|
|
10
|
+
* @file some useful resources when working with collections.
|
|
11
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
12
|
+
* @version 1.1.0
|
|
13
|
+
* @memberOf module:collect-your-stuff
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* List helpful functions when dealing with collections.
|
|
18
|
+
*/
|
|
19
|
+
const services = exports.services = {
|
|
20
|
+
parseTree: _parseTree.parseTree,
|
|
21
|
+
parseTreeNext: _parseTreeNext.parseTreeNext
|
|
22
|
+
}
|
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.2.
|
|
4
|
+
"version": "1.2.8",
|
|
5
5
|
"main": "dist/main.js",
|
|
6
6
|
"types": "dist/main.d.ts",
|
|
7
7
|
"author": "Joshua Heagle",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"watch:test": "gulp watchTest"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"js-build-tools": "^4.
|
|
27
|
+
"js-build-tools": "^4.1.1"
|
|
28
28
|
},
|
|
29
29
|
"repository": {
|
|
30
30
|
"type": "git",
|