qtools-functional-library 1.1.12 → 1.1.13

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
@@ -1,29 +1,78 @@
1
- **qtools-functional-library**
2
-
3
- This is a collection of tools that allow chained operations on various Javascript datatypes. In each case, the primary operand is `this`. In most cases, the function takes parameteers to guide the operation. In all cases, `this` is returned for use by the next function in the chain.
4
-
5
- Most of the functions included in this library (except, eg, qt.log()) are implemented on the prototype of the data type in question. For example, almost any element can take the .qtDump() function.
6
-
7
- - qtools-clone: Does a deep clone of an object or array.
8
- - qtools-get-by-property: Operates on an array of objects. Retrieves one or more elements based on the value of an object property specified by a dotted path.
9
- - qtools-includes-regex: Operations on a simple array of strings. Retrieves one or more elements based on an regEx match.
10
- - qtools-log-output: Substitutes properties into a <!template!> string and send to log. (Note to self, verify array operation)
11
- - qtools-merge: Deep merge of two objects including array propterties.
12
- - qtools-number-iterator: Operates on a number. EG, (5).qtStart(7).qtIncrement(3).qtIterate(item=>item*100)
13
- - qtools-number-keys-to-array: Converts an object with properties that are numbers to an array, including subordinate properties.
14
- - qtools-object-sure-path: Gets or Sets the value of a property based on a dotted string path. No crash if intermediate elements are missing. Provides default. Predates and is prettier to use than optional chaining and supports setting the value.
15
- - qtools-pass-through: 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.
16
- - qtools-pop: Pops the last value off an array. If a default is supplied and there is nothing left on the list, that will be returned. Really good for ArrayOfObjects.qtPop({}).
17
- - qtools-qtLast: Delivers the element that would have been pop'd but does not change the array.
18
- - qtoolspush: Pushes a value onto an array and returns the array (unlike normal .push() which returns the length of the array)
19
- - qtools-print-debug
20
- - qtools-template-replace
21
- - qtools-to-key-value-array
22
- - qtools-to-string
23
-
24
- NEW:
25
-
26
- - qtools-select-properties
27
- - qtools-map-properties
1
+ ## **qtools-functional-library**
2
+
3
+ This is a collection of tools that allow chained operations on various Javascript datatypes.
4
+
5
+ In each case, the primary operand is `this`. In most cases, the function takes an argument with parameters to guide the operation.
6
+
7
+ **EG,**
8
+
9
+ ```
10
+ const qt=require('qtools-functional-library');
11
+
12
+ qt.help(); // this information and more
13
+
14
+ const demo=({a:{b:"Hi from b"}})
15
+
16
+ const one=demo
17
+     .qtGetSurePath('a.b')
18
+     .qtDump();//produces 'Hi from b [thisFilename.js]'
19
+
20
+ console.log(one); //produces 'Hi from b'
21
+ ```
22
+
23
+ ### **Non-chain utilities:**
24
+
25
+ - **qt.help**: Shows this information and more.
26
+ - **qt.log**: Writes log entry with suffix identifying the file that generated the output. (See qtLog below for chained version.)
27
+
28
+ ### **Get/Set values from an Array:**
29
+
30
+ - **qtGetByProperty**: Operates on an array of objects. Retrieves one or more elements based on the value of an object property specified by a dotted path.
31
+
32
+ - **qtPop**: Pops the last value off an array. If a default is supplied and there is nothing left on the list, that will be returned. Really good for ArrayOfObjects.qtPop({}).
33
+
34
+ - **qtPush**: Pushes a value onto an array and returns the array (unlike normal .push() which returns the length of the array)
35
+
36
+ - **qtLast**: Delivers the element that would have been pop'd but does not change the array. Default if none exists.
37
+
38
+ - **qtFirst**: Delivers the element zero if it exists but does not change the array. Default if none exists.
39
+
40
+ - **qtIncludesRegex**: Operations on a simple array of strings. Retrieves one or more elements based on an regEx match.
41
+
42
+ ### **Get/Set values in an Object (or array of Objects)**
43
+
44
+ - **qtGetSurePath**: Gets the value of a property based on a dotted string path. No crash if intermediate elements are missing. Provides default. Predates and is prettier to use than optional chaining and supports setting the value.
45
+
46
+ - **qtSetSurePath** Sets the value of a property based on a dotted string path. Creates intermediate elements if they are missing.
47
+
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.
49
+
50
+ - **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
+
52
+ ### **Array/Object Conversions:**
53
+
54
+ - **qtClone**: Does a deep clone of an object or array.- qtNumberKeysToArray: Converts an object with properties that are numbers to an array, including subordinate properties.
55
+
56
+ - **qtToKeyValueArray**: Converts an object to an array of objects of the form, ie, `{["1"]:'one', ["2"]:'two'} => ['one', 'two']`
57
+
58
+ - **qtMerge**: Deep merge of two objects including array propterties.
59
+
60
+ - **qtToString**: Joins an array with prefix, suffix and separator. Pretty much the same as .join().
61
+
62
+ ### **Array/Object Template Replacement:**
63
+
64
+ - **qtTemplateReplace**: Takes Object and a `<!template!>` String ()either can be 'this' or the argument). Substitutes from the object properties into the string. If the 'this' is an array of Objects, it does it to all of them.
65
+
66
+ ### **Output:**
67
+
68
+ - **qtDump**: Prints 'this' and returns it. Good for debugging complicated chains.
69
+
70
+ - **qtLog**: Logs message by applying 'this' into the argument which is a <!template!> string. Appends calling file name.
71
+
72
+ ### **Misc:**
73
+
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.
75
+
76
+ - **qtIterate**: Operates on a number. EG, (5).qtStart(7).qtIncrement(3).qtIterate(item=>item*100)
28
77
 
29
78
  DESCRIPTION
@@ -8,7 +8,6 @@ var moduleFunction = function(args = {}) {
8
8
 
9
9
  const baseReplacementFunction = (replaceObject, template, options) => {
10
10
  const { transformations = {}, leaveUnmatchedTagsIntact = true } = options;
11
-
12
11
  replaceObject = replaceObject.qtClone().qtMerge(transformations);
13
12
 
14
13
  const tmp = template.match(/<!.*?!>/g);
@@ -45,6 +44,8 @@ var moduleFunction = function(args = {}) {
45
44
  // prettier-ignore
46
45
  const stringCallsObject = (item, arg) => arg instanceof Object && typeof item == 'string';
47
46
  // prettier-ignore
47
+ const stringCallsArrayOfObjects = (item, arg) => arg instanceof Array && typeof item == 'string';
48
+ // prettier-ignore
48
49
  const arrayOfStringsCallsObject = (item, arg) => arg instanceof Object && item instanceof Array && item.filter(item => typeof item == 'string').qtPop(false) ? true : false;
49
50
 
50
51
  //first method definition function ==========================
@@ -69,6 +70,8 @@ var moduleFunction = function(args = {}) {
69
70
  return this.map(item => baseReplacementFunction(item, arg, options));
70
71
  } else if (objectCallsString(this, arg)) {
71
72
  return baseReplacementFunction(this, arg, options);
73
+ } else if (stringCallsArrayOfObjects(this, arg)) {
74
+ return arg.map(item => baseReplacementFunction(item, this, options));
72
75
  } else if (stringCallsObject(this, arg)) {
73
76
  return baseReplacementFunction(arg, this, options);
74
77
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qtools-functional-library",
3
- "version": "1.1.12",
3
+ "version": "1.1.13",
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": {
@@ -19,7 +19,7 @@ const commonFunctions = {
19
19
  methods.push(methodName);
20
20
  documentation.push({
21
21
  name: methodName,
22
- description: `${methodName}: ${functionItem.description}`,
22
+ description: `${functionItem.description}`,
23
23
  supportedTypeList
24
24
  });
25
25
 
@@ -226,21 +226,32 @@ const addMorePrototypes = () => {
226
226
 
227
227
  addMorePrototypes();
228
228
 
229
- const helpActual = docList => (queryString = '') => {
230
- //someday turn this into a report instead of a JSON dump, add support for item.suppressHelpListing for qtLog_AddCallableMethods
231
- let outList;
229
+ const helpActual = docList => (options={}) => {
230
+
231
+ const {printOutput=true, sendJson=false, queryString='.*'}=options;
232
+
233
+ let rawList;
232
234
  if (!queryString) {
233
- outList = docList;
235
+ rawList = docList;
234
236
  } else {
235
- outList = docList.filter(item => {
237
+ rawList = docList.filter(item => {
236
238
  const regex = new RegExp(queryString, 'i');
237
239
  const result = JSON.stringify(item).match(regex);
238
240
  return result;
239
241
  });
240
242
  }
241
- // const util=require('util');
242
- // util.inspect(docList, { depth: null, maxArrayLength: null }).qtDump('qtFuncionalLib Documentation');
243
- return outList;
243
+
244
+ let outArray=[];
245
+ rawList.forEach(item=>{
246
+ outArray=outArray.concat(item);
247
+ });
248
+
249
+ const outString='<!name!>: <!description!> (<!supportedTypeList!>) '.qtTemplateReplace(outArray).join('\n');
250
+
251
+ if (printOutput){
252
+ console.log(outString);
253
+ }
254
+ return outString;
244
255
  };
245
256
 
246
257
  const testActual = testList => (args={}) => {