qtools-functional-library 1.1.15 → 2.0.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.
package/README.md CHANGED
@@ -4,6 +4,8 @@ This is a collection of tools that allow chained operations on various Javascrip
4
4
 
5
5
  In each case, the primary operand is `this`. In most cases, the function takes an argument with parameters to guide the operation.
6
6
 
7
+ Everything else remains compatible.
8
+
7
9
  **EG,**
8
10
 
9
11
  ```
@@ -20,6 +22,19 @@ const one=demo
20
22
  console.log(one); //produces '[object Object]'
21
23
  ```
22
24
 
25
+ ### **Version 2:**
26
+
27
+ qtPassThrough <u>no longer</u> *always* returns the inbound 'this'. If the supplied function
28
+ returns a value, that is passed on. This way, any ad hoc function can affect the result chain.
29
+
30
+ EG,
31
+
32
+ ```
33
+ 'xxx'
34
+ .qtPassThrough(item=>item.toUpperCase())
35
+ .qtDump(); // -> 'XXX'
36
+ ```
37
+
23
38
  ### **Non-chain utilities:**
24
39
 
25
40
  - **qt.help**: Shows this information and more.
@@ -45,7 +60,7 @@ console.log(one); //produces '[object Object]'
45
60
 
46
61
  - **qtSetSurePath** Sets the value of a property based on a dotted string path. Creates intermediate elements if they are missing.
47
62
 
48
- - **qtSelectProperties**: Given an Object and an Array of Strings, filters the properties into a new Object with defaults for missing elements. Does the same for an Array of Objects.
63
+ - **qtSelectProperties**: Given an Object and an Array of Strings, filters the properties into a new Object with defaults "[{}].qtSelectProperties(outFileDefinition, {moreDefaultValues:{Value:"xxx"}}))" for missing elements. Does the same for an Array of Objects.
49
64
 
50
65
  - **qtMapProperties**: Given an Object and a one level Object whose properties are functions, applies each function to the corresponding element. Does the same for an array of Objects.
51
66
 
@@ -71,8 +86,22 @@ console.log(one); //produces '[object Object]'
71
86
 
72
87
  ### **Misc:**
73
88
 
74
- - **qtPassThrough**: Sits in a declarative chain and executes an arbitrary function. It returns 'this' regardless of what the function does. 'this' is available to the function.
89
+ - **qtPassThrough**: Sits in a declarative chain and executes an arbitrary function. Returns function result if not undefined, 'this' otherwise. 'this' is available to the function.
75
90
 
76
91
  - **qtIterate**: Operates on a number. EG, (5).qtStart(7).qtIncrement(3).qtIterate(item=>item*100)
77
92
 
78
- DESCRIPTION
93
+ ### **Output:**
94
+
95
+ 1.1.16 - fixed bug where intermediate path element could be undefined and cause a crash.
96
+
97
+ ### **Other Cool Qtools**
98
+
99
+ [qtools-asynchronous-pipe-plus](https://www.npmjs.com/package/qtools-asynchronous-pipe-plus)
100
+ [qtools-config-file-processor](https://www.npmjs.com/package/qtools-config-file-processor)
101
+ [qtools-format-columns](https://www.npmjs.com/package/qtools-format-columns)
102
+ [qtools-functional-library](https://www.npmjs.com/package/qtools-functional-library)
103
+ [qtools-object-flattener](https://www.npmjs.com/package/qtools-object-flattener)
104
+ [qtools-parse-command-line](https://www.npmjs.com/package/qtools-parse-command-line)
105
+ [qtools-secure-container](https://www.npmjs.com/package/qtools-secure-container)
106
+ [qtools-template-replace-for-files](https://www.npmjs.com/package/qtools-template-replace-for-files)
107
+ [qtools-transform-text](https://www.npmjs.com/package/qtools-transform-text)
@@ -57,7 +57,7 @@ var moduleFunction = function(args = {}) {
57
57
  for (var i = 0, len = elements.length; i < len; i++) {
58
58
  if (elements[i]) {
59
59
  //mainly eliminates trailing periods but would also eliminates double periods and other regex anomalies
60
- target = target[elements[i]];
60
+ target = target?target[elements[i]]:undefined;
61
61
 
62
62
  getDottedPathLastProgressiveString += elements[i] + '.';
63
63
  if (typeof target == 'undefined' || target === '') {
@@ -1,23 +1,21 @@
1
1
  'use strict';
2
2
  //START OF moduleFunction() ============================================================
3
- var moduleFunction = function(args = {}) {
3
+ var moduleFunction = function (args = {}) {
4
4
  const { commonFunctions } = args;
5
-
6
- const addToPrototypeActual = functionObject => () =>
5
+
6
+ const addToPrototypeActual = (functionObject) => () =>
7
7
  commonFunctions.universalAddToPrototype(commonFunctions, functionObject);
8
-
9
-
10
-
8
+
11
9
  //first method definition function ==========================
12
- const firstMethodFunction = commonFunctions => {
10
+ const firstMethodFunction = (commonFunctions) => {
13
11
  const functionObject = new Map(); // prettier-ignore
14
-
12
+
15
13
  const methodName = 'qtPassThrough';
16
- const description = `executes a supplied function; 'this' is the only parameter; objects may be changed but that is not the point; no return value is passed on.`;
14
+ const description = `executes a supplied function; 'this' is the only parameter; if supplied function returns a value, it is returned, else 'this' is returned.`;
17
15
  const supportedTypeList = [Object, Array, String, Number, Boolean, Date];
18
16
 
19
17
  const method = () =>
20
- function(utilityFunction) {
18
+ function (utilityFunction) {
21
19
  //if one of the supportedTypeList elements is Object, basically all data types will have this method and type checking is important.
22
20
  if (!commonFunctions.isSupportedType(this, supportedTypeList)) {
23
21
  // prettier-ignore
@@ -25,32 +23,35 @@ var moduleFunction = function(args = {}) {
25
23
  `${methodName}(): unsupported data type: '${commonFunctions.toType(this)}' (${methodName} supports ${supportedTypeList.map(item=>item.toString().replace(/.*function (.*?)\(\).*/, '$1')).join(', ')})`
26
24
  );
27
25
  }
28
-
29
- utilityFunction(this);
30
26
 
31
- return this;
27
+ const utilityResult = utilityFunction(this);
28
+ if (utilityResult!=undefined) {
29
+ return utilityResult;
30
+ } else {
31
+ return this;
32
+ }
32
33
  };
33
34
 
34
35
  functionObject.set(methodName, {
35
36
  description,
36
37
  supportedTypeList,
37
38
  method,
38
- test: (args) =>
39
- {
40
- return require('./test.js')({...args, ...{
41
- moduleName: module.id.replace(module.path, '')
42
- }})
43
- }
39
+ test: (args) => {
40
+ return require('./test.js')({
41
+ ...args,
42
+ ...{
43
+ moduleName: module.id.replace(module.path, ''),
44
+ },
45
+ });
46
+ },
44
47
  });
45
-
46
-
47
-
48
+
48
49
  return functionObject;
49
- };
50
- this.addToPrototype = addToPrototypeActual(
51
- firstMethodFunction(commonFunctions)
50
+ };
51
+ this.addToPrototype = addToPrototypeActual(
52
+ firstMethodFunction(commonFunctions),
52
53
  );
53
-
54
+
54
55
  };
55
56
  //END OF moduleFunction() ============================================================
56
57
  module.exports = moduleFunction;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qtools-functional-library",
3
- "version": "1.1.15",
3
+ "version": "2.0.0",
4
4
  "description": "Useful additions to JS prototypes to facilliate chainable, functional (mostly) style. Also make life more convenient.\"",
5
5
  "main": "qtools-functional-library.js",
6
6
  "scripts": {