qtools-library-dot-d 1.0.8 → 1.0.10

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 (74) hide show
  1. package/README.md +2 -0
  2. package/libDotD_Working_Example/README.md +234 -0
  3. package/libDotD_Working_Example/demoModules_DotD/demo1.js +46 -0
  4. package/libDotD_Working_Example/demoModules_DotD/demo2.js +48 -0
  5. package/libDotD_Working_Example/index.js +133 -0
  6. package/libDotD_Working_Example/node_modules/.package-lock.json +29 -0
  7. package/libDotD_Working_Example/node_modules/qtools-asynchronous-pipe-plus/README.md +213 -0
  8. package/libDotD_Working_Example/node_modules/qtools-asynchronous-pipe-plus/package.json +20 -0
  9. package/libDotD_Working_Example/node_modules/qtools-asynchronous-pipe-plus/qtools-asynchronous-pipe-plus.js +278 -0
  10. package/libDotD_Working_Example/node_modules/qtools-asynchronous-pipe-plus/test.js +79 -0
  11. package/libDotD_Working_Example/node_modules/qtools-functional-library/README.md +110 -0
  12. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-clone/package.json +11 -0
  13. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-clone/qtools-clone.js +103 -0
  14. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-clone/test.js +78 -0
  15. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-get-by-property/package.json +11 -0
  16. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-get-by-property/qtools-get-by-property.js +73 -0
  17. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-get-by-property/test.js +129 -0
  18. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-includes-regex/package.json +11 -0
  19. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-includes-regex/qtools-includes-regex.js +54 -0
  20. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-includes-regex/test.js +76 -0
  21. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-log-output/package.json +11 -0
  22. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-log-output/qtools-log-output.js +114 -0
  23. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-log-output/test.js +130 -0
  24. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-map-properties/package.json +11 -0
  25. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-map-properties/qtools-map-properties.js +99 -0
  26. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-map-properties/test.js +118 -0
  27. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-merge/package.json +11 -0
  28. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-merge/qtools-merge.js +147 -0
  29. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-merge/test.js +214 -0
  30. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-new-method-template/package.json +11 -0
  31. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-new-method-template/qtools-new-method-template.js +70 -0
  32. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-new-method-template/test.js +66 -0
  33. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-number-iterator/package.json +11 -0
  34. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-number-iterator/qtools-number-iterator.js +137 -0
  35. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-number-iterator/test.js +68 -0
  36. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-number-keys-to-array/package.json +11 -0
  37. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-number-keys-to-array/qtools-number-keys-to-array.js +131 -0
  38. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-number-keys-to-array/test.js +181 -0
  39. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-object-sure-path/package.json +11 -0
  40. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-object-sure-path/qtools-object-sure-path.js +204 -0
  41. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-object-sure-path/test.js +345 -0
  42. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-pass-through/package.json +11 -0
  43. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-pass-through/qtools-pass-through.js +58 -0
  44. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-pass-through/test.js +66 -0
  45. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-pop/package.json +11 -0
  46. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-pop/qtools-pop.js +175 -0
  47. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-pop/test.js +118 -0
  48. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-print-debug/package.json +11 -0
  49. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-print-debug/qtools-print-debug.js +352 -0
  50. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-print-debug/test.js +77 -0
  51. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-select-properties/package.json +11 -0
  52. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-select-properties/qtools-select-properties.js +132 -0
  53. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-select-properties/test.js +156 -0
  54. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-template-replace/README.md +3 -0
  55. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-template-replace/package.json +11 -0
  56. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-template-replace/qtools-template-replace.js +106 -0
  57. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-template-replace/test.js +168 -0
  58. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-to-key-value-array/package.json +11 -0
  59. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-to-key-value-array/qtools-to-key-value-array.js +83 -0
  60. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-to-key-value-array/test.js +68 -0
  61. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-to-string/package.json +11 -0
  62. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-to-string/qtools-to-string.js +84 -0
  63. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-to-string/test.js +63 -0
  64. package/libDotD_Working_Example/node_modules/qtools-functional-library/package.json +37 -0
  65. package/libDotD_Working_Example/node_modules/qtools-functional-library/qtFunctionalDemo.js +297 -0
  66. package/libDotD_Working_Example/node_modules/qtools-functional-library/qtools-functional-library.js +271 -0
  67. package/libDotD_Working_Example/node_modules/qtools-functional-library/test.js +47 -0
  68. package/libDotD_Working_Example/node_modules/qtools-library-dot-d/README.md +208 -0
  69. package/libDotD_Working_Example/node_modules/qtools-library-dot-d/package.json +15 -0
  70. package/libDotD_Working_Example/node_modules/qtools-library-dot-d/qtools-library-dot-d.js +239 -0
  71. package/libDotD_Working_Example/package-lock.json +37 -0
  72. package/libDotD_Working_Example/package.json +23 -0
  73. package/package.json +1 -1
  74. package/qtools-library-dot-d.js +5 -12
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "qtools-clone",
3
+ "version": "1.0.0",
4
+ "description": "Deep clone of a javascript object, returns new object.",
5
+ "main": "qtools-clone.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "author": "TQ White II",
10
+ "license": "ISC"
11
+ }
@@ -0,0 +1,103 @@
1
+ 'use strict';
2
+ //START OF moduleFunction() ============================================================
3
+ var moduleFunction = function(args = {}) {
4
+ const { commonFunctions } = args;
5
+
6
+ const addToPrototypeActual = functionObject => () =>
7
+ commonFunctions.universalAddToPrototype(commonFunctions, functionObject);
8
+
9
+ const cloneObject=function(func) {
10
+ const inObj=this;
11
+ let convertFunction =
12
+ typeof func == 'function'
13
+ ? func
14
+ : function(inData) {
15
+ return inData;
16
+ };
17
+
18
+ if (
19
+ ['string', 'number', 'boolean', 'undefined'].indexOf(typeof inObj) > -1 ||
20
+ inObj === null
21
+ ) {
22
+ return convertFunction(inObj);
23
+ }
24
+
25
+ if (commonFunctions.toType(inObj) == 'null') {
26
+ return convertFunction(inObj);
27
+ }
28
+
29
+ if (!newObj) {
30
+ if (commonFunctions.toType(inObj) == 'array') {
31
+ var newObj = [];
32
+ } else {
33
+ var newObj = {};
34
+ }
35
+ }
36
+
37
+ if (commonFunctions.toType(inObj) != 'array') {
38
+ for (var i in inObj) {
39
+ //I rescinded the numericToArray() prototype function that required this.
40
+ // if (typeof(inObj.hasOwnProperty)=='function' && !inObj.hasOwnProperty(i)){
41
+ // continue;
42
+ // }
43
+ if (inObj[i] !== null && typeof inObj[i] == 'object') {
44
+ switch (inObj[i].constructor) {
45
+ case Date:
46
+ newObj[i] = convertFunction(new Date(inObj[i].toString()));
47
+ break;
48
+ default:
49
+ newObj[i] = inObj[i].qtClone(func);
50
+ break;
51
+ }
52
+ } else {
53
+ newObj[i] = convertFunction(inObj[i]);
54
+ //console.log("OO inObj[i]="+inObj[i]);
55
+ }
56
+ }
57
+ } else {
58
+ for (var i = 0, len = inObj.length; i < len; i++) {
59
+ if (commonFunctions.toType(inObj[i]) == 'object') {
60
+ newObj[i] = inObj[i].qtClone(func);
61
+ } else {
62
+ newObj[i] = convertFunction(inObj[i]);
63
+ //console.log("AA inObj[i]="+inObj[i]);
64
+ }
65
+ }
66
+ }
67
+
68
+ return newObj;
69
+ };
70
+
71
+ //first method definition function ==========================
72
+ const firstMethodFunction = commonFunctions => {
73
+ const functionObject = new Map(); // prettier-ignore
74
+
75
+ const methodName = 'qtClone';
76
+ const description = `Deep clone of JS object for pass by value`;
77
+ const supportedTypeList = [Object, Array];
78
+
79
+ const method = () =>cloneObject;
80
+
81
+ functionObject.set(methodName, {
82
+ description,
83
+ supportedTypeList,
84
+ method,
85
+ test: (args) =>
86
+ {
87
+ return require('./test.js')({...args, ...{
88
+ moduleName: module.id.replace(module.path, '')
89
+ }})
90
+ }
91
+ });
92
+
93
+
94
+ return functionObject;
95
+ };
96
+ this.addToPrototype = addToPrototypeActual(
97
+ firstMethodFunction(commonFunctions)
98
+ );
99
+
100
+ };
101
+ //END OF moduleFunction() ============================================================
102
+ module.exports = moduleFunction;
103
+ //module.exports = new moduleFunction();
@@ -0,0 +1,78 @@
1
+ 'use strict';
2
+
3
+ //START OF moduleFunction() ============================================================
4
+
5
+ const moduleFunction = function(args) {
6
+ //this module is initialized with parameters spec'd in the main function module
7
+
8
+ const completeStepActual = ({verbose=false, logErrors=false, moduleName}) => (
9
+ methodName,
10
+ thisStepMessage,
11
+ thisStepResult,
12
+ thisStepEvalFunction
13
+ ) => {
14
+
15
+ const thisStepPass = thisStepEvalFunction(thisStepResult);
16
+
17
+ if (logErrors && !thisStepPass) {
18
+ console.log(`FAIL TEST: ${thisStepMessage} in ...${moduleName}`);
19
+ }
20
+ if (verbose) {
21
+ console.log(`Result for: ${methodName} (${thisStepPass?'PASS':'FAIL'}):`);
22
+ console.dir(thisStepResult);
23
+ console.log('\n\n');
24
+ }
25
+
26
+ return passingTests && thisStepPass;
27
+ };
28
+
29
+ const completeStep = completeStepActual(args);
30
+
31
+ let passingTests = true;
32
+
33
+ let thisStepMessage;
34
+ let thisStepResult;
35
+ let thisStepEvalFunction;
36
+ let methodName;
37
+
38
+ //TESTS ============================================================
39
+
40
+ const referencedObject={
41
+ string:'hello',
42
+ object:{
43
+ hello:'goodbye'
44
+ },
45
+ array:[
46
+ {
47
+ a:'b',
48
+ c:'d'
49
+ }
50
+ ]
51
+ }
52
+
53
+ const testArray = referencedObject;
54
+
55
+
56
+ //TEST ITEM ------------------------------------------------------
57
+ methodName='qtClone'
58
+ thisStepMessage = "not yet implemented";
59
+ thisStepResult = testArray[methodName]();
60
+ thisStepEvalFunction = item => {
61
+ item.string='hola'
62
+ return referencedObject.string!='hola'
63
+ };
64
+ passingTests =
65
+ completeStep(methodName, thisStepMessage, thisStepResult, thisStepEvalFunction) &&
66
+ passingTests;
67
+
68
+
69
+
70
+
71
+ return passingTests;
72
+ };
73
+
74
+ //END OF moduleFunction() ============================================================
75
+
76
+ module.exports = moduleFunction;
77
+ //module.exports = new moduleFunction();
78
+
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "qtools-get-by-property",
3
+ "version": "1.0.0",
4
+ "description": "method of array that contains objects, parameters are a dotted string representing the path to the value for comparison and a match value, returns the object with a mathcing property\"",
5
+ "main": "qtools-get-by-property.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "author": "TQ White II",
10
+ "license": "ISC"
11
+ }
@@ -0,0 +1,73 @@
1
+ 'use strict';
2
+ //START OF moduleFunction() ============================================================
3
+ var moduleFunction = function(args = {}) {
4
+ const { commonFunctions } = args;
5
+
6
+ const addToPrototypeActual = functionObject => () =>
7
+ commonFunctions.universalAddToPrototype(commonFunctions, functionObject);
8
+
9
+
10
+
11
+ //first method definition function ==========================
12
+ const firstMethodFunction = commonFunctions => {
13
+ const methodName = 'qtGetByProperty';
14
+ const description = `objectArray.getByProperty('path.into.objects[3].property', 'matchValue', 'optionalDefault') returns array of elements with path value==match value or default`;
15
+ const supportedTypeList = [Object];
16
+
17
+ const method = () =>
18
+ function(
19
+ propertyName,
20
+ propertyValue,
21
+ defaultValue
22
+ ) {
23
+
24
+ const inData=this;
25
+ const isRegExp = propertyValue instanceof RegExp;
26
+ let outList = [];
27
+ if (inData.length) {
28
+ var len = inData.length;
29
+ var inx = 0;
30
+ for (inx = 0; inx < len; inx++) {
31
+ const item = inData[inx].qtGetSurePath(propertyName);
32
+ if (item == propertyValue || (isRegExp && item.match(propertyValue))) {
33
+ outList.push(inData[inx]);
34
+ }
35
+ }
36
+ } else if (typeof inData == 'object') {
37
+ for (var inx in inData) {
38
+ const item = inData[inx].qtGetSurePath(propertyName);
39
+ if (item == propertyValue || (isRegExp && item.match(propertyValue))) {
40
+ outList.push(inData[inx]);
41
+ }
42
+ }
43
+ }
44
+
45
+ if (defaultValue && outList.length===0){
46
+ outList=defaultValue;
47
+ }
48
+
49
+ return outList;
50
+ };
51
+
52
+ const functionObject = new Map(); // prettier-ignore
53
+ functionObject.set(methodName, {
54
+ description,
55
+ supportedTypeList,
56
+ method,
57
+ test: (args) =>
58
+ {
59
+ return require('./test.js')({...args, ...{
60
+ moduleName: module.id.replace(module.path, '')
61
+ }})
62
+ }
63
+ });
64
+ return functionObject;
65
+ };
66
+ this.addToPrototype = addToPrototypeActual(
67
+ firstMethodFunction(commonFunctions)
68
+ );
69
+
70
+ };
71
+ //END OF moduleFunction() ============================================================
72
+ module.exports = moduleFunction;
73
+ //module.exports = new moduleFunction();
@@ -0,0 +1,129 @@
1
+ 'use strict';
2
+
3
+ //START OF moduleFunction() ============================================================
4
+
5
+ const moduleFunction = function(args) {
6
+ //this module is initialized with parameters spec'd in the main function module
7
+
8
+ const completeStepActual = ({verbose=false, logErrors=false, moduleName}) => (
9
+ methodName,
10
+ thisStepMessage,
11
+ thisStepResult,
12
+ thisStepEvalFunction
13
+ ) => {
14
+
15
+ const thisStepPass = thisStepEvalFunction(thisStepResult);
16
+
17
+ if (logErrors && !thisStepPass) {
18
+ console.log(`FAIL TEST: ${thisStepMessage} in ...${moduleName}`);
19
+ }
20
+ if (verbose) {
21
+ console.log(`Result for: ${methodName} (${thisStepPass?'PASS':'FAIL'}):`);
22
+ console.dir(thisStepResult);
23
+ console.log('\n\n');
24
+ }
25
+
26
+ return passingTests && thisStepPass;
27
+ };
28
+
29
+ const completeStep = completeStepActual(args);
30
+
31
+ let passingTests = true;
32
+
33
+ let thisStepMessage;
34
+ let thisStepResult;
35
+ let thisStepEvalFunction;
36
+ let methodName;
37
+
38
+ //TESTS ============================================================
39
+
40
+
41
+ const testArray = [
42
+ {
43
+ a: {
44
+ animal: 'fish',
45
+ eatsWith: 'straw',
46
+ color: 'red'
47
+ }
48
+ },
49
+ {
50
+ a: {
51
+ animal: 'snake',
52
+ eatsWith: 'straw',
53
+ color: 'blue'
54
+ }
55
+ },
56
+ {
57
+ a: {
58
+ animal: 'bird',
59
+ eatsWith: 'teeth',
60
+ color: 'red'
61
+ }
62
+ },
63
+ {
64
+ a: {
65
+ animal: 'bird',
66
+ eatsWith: 'chopsticks',
67
+ color: 'red'
68
+ }
69
+ },
70
+ {
71
+ a: {
72
+ animal: 'bird',
73
+ eatsWith: 'teeth',
74
+ color: 'red'
75
+ }
76
+ }
77
+ ];
78
+
79
+
80
+ methodName='qtGetByProperty'
81
+
82
+ //TEST ITEM ------------------------------------------------------
83
+ thisStepMessage = "couldn't find all red ones";
84
+ thisStepResult = testArray[methodName]('a.color', 'red');
85
+ thisStepEvalFunction = item => item.length == 4;
86
+ passingTests =
87
+ completeStep(methodName, thisStepMessage, thisStepResult, thisStepEvalFunction) &&
88
+ passingTests;
89
+
90
+ //TEST ITEM ------------------------------------------------------
91
+ thisStepMessage = "did not get default value when search value was not presesnt";
92
+ thisStepResult = testArray[methodName]('a.color', 'snake', 'pumpkins');
93
+ thisStepEvalFunction = item => item == 'pumpkins';
94
+ passingTests =
95
+ completeStep(methodName, thisStepMessage, thisStepResult, thisStepEvalFunction) &&
96
+ passingTests;
97
+
98
+ //TEST ITEM ------------------------------------------------------
99
+ thisStepMessage = 'did not find correct object with dotted path criterion';
100
+ thisStepResult = testArray[methodName]('a.color', 'blue', 'pumpkins');
101
+ thisStepEvalFunction = item =>
102
+ item.length == 1 &&
103
+ item[0].a.animal == 'snake' &&
104
+ item[0].a.eatsWith == 'straw' &&
105
+ item[0].a.color == 'blue';
106
+ passingTests =
107
+ completeStep(methodName, thisStepMessage, thisStepResult, thisStepEvalFunction) &&
108
+ passingTests;
109
+
110
+ //TEST ITEM ------------------------------------------------------
111
+ thisStepMessage =
112
+ 'did not return empty array when search value was present and there was no default';
113
+ thisStepResult = testArray[methodName]('a.color', 'monkee');
114
+ thisStepEvalFunction = item => item.length === 0;
115
+ passingTests =
116
+ completeStep(methodName, thisStepMessage, thisStepResult, thisStepEvalFunction) &&
117
+ passingTests;
118
+
119
+
120
+
121
+
122
+ return passingTests;
123
+ };
124
+
125
+ //END OF moduleFunction() ============================================================
126
+
127
+ module.exports = moduleFunction;
128
+ //module.exports = new moduleFunction();
129
+
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "qtools-includes-regex",
3
+ "version": "1.0.0",
4
+ "description": "array prototype enhancment treats string values as regular express",
5
+ "main": "qtools-includes-regex.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "author": "TQ White II",
10
+ "license": "ISC"
11
+ }
@@ -0,0 +1,54 @@
1
+ 'use strict';
2
+ //START OF moduleFunction() ============================================================
3
+ var moduleFunction = function(args = {}) {
4
+ const { commonFunctions } = args;
5
+
6
+ const addToPrototypeActual = functionObject => () =>
7
+ commonFunctions.universalAddToPrototype(commonFunctions, functionObject);
8
+
9
+
10
+
11
+ //first method definition function ==========================
12
+ const firstMethodFunction = commonFunctions => {
13
+ const methodName = 'qtIncludesRegex';
14
+ const description = `qtIncludesRegex(RegExp): returns true if element.match(RegExp)==true for any element`;
15
+ const supportedTypeList = [Object];
16
+
17
+ const method = () =>
18
+ function(needle) {
19
+ if (needle instanceof RegExp) {
20
+ const haystack = this;
21
+ let found = false;
22
+ haystack.forEach(item => {
23
+ found = found || item.match(needle) ? true : false;
24
+ });
25
+ return found;
26
+ } else {
27
+ return haystack.includes(needle);
28
+ }
29
+ };
30
+
31
+ const functionObject = new Map(); // prettier-ignore
32
+ functionObject.set(methodName, {
33
+ description,
34
+ supportedTypeList,
35
+ method,
36
+ test: args => {
37
+ return require('./test.js')({
38
+ ...args,
39
+ ...{
40
+ moduleName: module.id.replace(module.path, '')
41
+ }
42
+ });
43
+ }
44
+ });
45
+ return functionObject;
46
+ };
47
+ this.addToPrototype = addToPrototypeActual(
48
+ firstMethodFunction(commonFunctions)
49
+ );
50
+
51
+ };
52
+ //END OF moduleFunction() ============================================================
53
+ module.exports = moduleFunction;
54
+ //module.exports = new moduleFunction();
@@ -0,0 +1,76 @@
1
+ 'use strict';
2
+
3
+ //START OF moduleFunction() ============================================================
4
+
5
+ const moduleFunction = function(args) {
6
+ //this module is initialized with parameters spec'd in the main function module
7
+
8
+ const completeStepActual = ({verbose=false, logErrors=false, moduleName}) => (
9
+ methodName,
10
+ thisStepMessage,
11
+ thisStepResult,
12
+ thisStepEvalFunction
13
+ ) => {
14
+
15
+ const thisStepPass = thisStepEvalFunction(thisStepResult);
16
+
17
+ if (logErrors && !thisStepPass) {
18
+ console.log(`FAIL TEST: ${thisStepMessage} in ...${moduleName}`);
19
+ }
20
+ if (verbose) {
21
+ console.log(`Result for: ${methodName} (${thisStepPass?'PASS':'FAIL'}):`);
22
+ console.dir(thisStepResult);
23
+ console.log('\n\n');
24
+ }
25
+
26
+ return passingTests && thisStepPass;
27
+ };
28
+
29
+ const completeStep = completeStepActual(args);
30
+
31
+ let passingTests = true;
32
+
33
+ let thisStepMessage;
34
+ let thisStepResult;
35
+ let thisStepEvalFunction;
36
+ let methodName;
37
+
38
+ //TESTS ============================================================
39
+
40
+
41
+ const testArray = [
42
+ 'allocute',
43
+ 'Hello'
44
+ ];
45
+
46
+ methodName='qtIncludesRegex'
47
+
48
+ //TEST ITEM ------------------------------------------------------
49
+ thisStepMessage = "Did not find correct element";
50
+ thisStepMessage = "not yet implemented";
51
+ thisStepResult = testArray[methodName](/^H/);
52
+ thisStepEvalFunction = item => 'allocute';
53
+ passingTests =
54
+ completeStep(methodName, thisStepMessage, thisStepResult, thisStepEvalFunction) &&
55
+ passingTests;
56
+
57
+
58
+ //TEST ITEM ------------------------------------------------------
59
+ thisStepMessage = "found element that it should not have";
60
+ thisStepResult = testArray[methodName](/H.ll./);
61
+ thisStepEvalFunction = item => 'Hello';
62
+ passingTests =
63
+ completeStep(methodName, thisStepMessage, thisStepResult, thisStepEvalFunction) &&
64
+ passingTests;
65
+
66
+
67
+
68
+
69
+ return passingTests;
70
+ };
71
+
72
+ //END OF moduleFunction() ============================================================
73
+
74
+ module.exports = moduleFunction;
75
+ //module.exports = new moduleFunction();
76
+
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "qtools-log-output",
3
+ "version": "1.0.0",
4
+ "description": "operates stdin and stderr for logging and output",
5
+ "main": "qtools-log-output.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "author": "TQ White II",
10
+ "license": "ISC"
11
+ }
@@ -0,0 +1,114 @@
1
+ 'use strict';
2
+ //START OF moduleFunction() ============================================================
3
+ var moduleFunction = function(args = {}) {
4
+ const { commonFunctions } = args;
5
+
6
+ //qtAddCallableMethods ============================================================
7
+ const qtLog_AddCallableMethods = {
8
+ description: `internal function not for civilian use`,
9
+ suppressHelpListing: true,
10
+ supportedTypeList: [Object],
11
+ test: args => {
12
+ return require('./test.js')({
13
+ ...args,
14
+ ...{
15
+ moduleName: module.id.replace(module.path, '')
16
+ }
17
+ });
18
+ },
19
+
20
+ method: commonFunctions =>
21
+ function(permissionValue = '') {
22
+ if (
23
+ permissionValue != "what part of 'not for civilian use' is unclear?"
24
+ ) {
25
+ return;
26
+ }
27
+
28
+ this.log = function(message, options = {}) {
29
+ options.suffixCallStackDepth = options.suffixCallStackDepth?options.suffixCallStackDepth:4;
30
+ return ({}.qtLog(message, options));
31
+ };
32
+
33
+ return this;
34
+ }
35
+ };
36
+
37
+ //qtLog ============================================================
38
+ const qtLog = {
39
+ description: `[ANY TYPE].qtLog() outputs to stderr (console.error()) or stdout (console.log())`,
40
+ supportedTypeList: [
41
+ Object,
42
+ String,
43
+ Number,
44
+ Set,
45
+ Map,
46
+ Boolean,
47
+ Symbol,
48
+ Function,
49
+ BigInt,
50
+ BigInt64Array
51
+ ],
52
+ test: args => {
53
+ return require('./test.js')({
54
+ ...args,
55
+ ...{
56
+ moduleName: module.id.replace(module.path, '')
57
+ }
58
+ });
59
+ },
60
+
61
+ method: commonFunctions =>
62
+ function(message, options = {}) {
63
+ const inData = this;
64
+ const {
65
+ noSuffix = false,
66
+ label = '',
67
+ substitutions = {},
68
+ destination = 'stderr',
69
+ removeFromSuffix,
70
+ replacementForSuffix='...'
71
+ } = options;
72
+
73
+ const callerName = commonFunctions.callerName(true, options);
74
+
75
+ const showLabel = label.replace(/\n/g, '');
76
+ let suffix = noSuffix ? '' : ` [${callerName}]`;
77
+
78
+ if (removeFromSuffix){
79
+ suffix=suffix.replace(new RegExp(removeFromSuffix), replacementForSuffix);
80
+ }
81
+
82
+
83
+ const outputMessage =
84
+ message
85
+ .qtTemplateReplace(typeof this == 'object' ? this : {})
86
+ .qtTemplateReplace(substitutions) + suffix;
87
+
88
+ if (['stderr'].includes(destination)) {
89
+ console.error(outputMessage);
90
+ } else if (['stdout'].includes(destination)) {
91
+ console.log(outputMessage);
92
+ } else if (['returnString'].includes(destination)) {
93
+ return outputMessage;
94
+ }
95
+
96
+ return this;
97
+ }
98
+ };
99
+
100
+ //intitialize context ============================================================
101
+
102
+ const functionObject = new Map();
103
+
104
+ functionObject.set('qtLog_AddCallableMethods', qtLog_AddCallableMethods);
105
+ functionObject.set('qtLog', qtLog);
106
+
107
+ //this has commonFunctions twice because I don't want new thing() or to have an extra function to make it available.
108
+ const addToPrototypeActual = functionObject => () =>
109
+ commonFunctions.universalAddToPrototype(commonFunctions, functionObject);
110
+ this.addToPrototype = addToPrototypeActual(functionObject);
111
+ };
112
+ //END OF moduleFunction() ============================================================
113
+ module.exports = moduleFunction;
114
+ //module.exports = new moduleFunction();