qtools-functional-library 1.1.4 → 1.1.9

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 ADDED
@@ -0,0 +1,23 @@
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
8
+ - qtools-get-by-property
9
+ - qtools-includes-regex
10
+ - qtools-log-output
11
+ - qtools-merge
12
+ - qtools-new-method-template
13
+ - qtools-number-iterator
14
+ - qtools-number-keys-to-array
15
+ - qtools-object-sure-path
16
+ - qtools-pass-through
17
+ - qtools-pop
18
+ - qtools-print-debug
19
+ - qtools-template-replace
20
+ - qtools-to-key-value-array
21
+ - qtools-to-string
22
+
23
+ DESCRIPTION
@@ -26,7 +26,7 @@ var moduleFunction = function(args = {}) {
26
26
  }
27
27
 
28
28
  this.log = function(message, options = {}) {
29
- options.suffixCallStackDepth = 4;
29
+ options.suffixCallStackDepth = options.suffixCallStackDepth?options.suffixCallStackDepth:4;
30
30
  return ({}.qtLog(message, options));
31
31
  };
32
32
 
@@ -65,13 +65,21 @@ var moduleFunction = function(args = {}) {
65
65
  noSuffix = false,
66
66
  label = '',
67
67
  substitutions = {},
68
- destination = 'stderr'
68
+ destination = 'stderr',
69
+ removeFromSuffix,
70
+ replacementForSuffix='...'
69
71
  } = options;
70
72
 
71
73
  const callerName = commonFunctions.callerName(true, options);
72
74
 
73
75
  const showLabel = label.replace(/\n/g, '');
74
- const suffix = noSuffix ? '' : ` [${callerName}]`;
76
+ let suffix = noSuffix ? '' : ` [${callerName}]`;
77
+
78
+ if (removeFromSuffix){
79
+ suffix=suffix.replace(new RegExp(removeFromSuffix), replacementForSuffix);
80
+ }
81
+
82
+
75
83
  const outputMessage =
76
84
  message
77
85
  .qtTemplateReplace(typeof this == 'object' ? this : {})
@@ -98,7 +98,7 @@ var moduleFunction = function(args = {}) {
98
98
  const firstMethodFunction = commonFunctions => {
99
99
  const functionObject = new Map(); // prettier-ignore
100
100
  functionObject.set('qtIterate', {
101
- description: `count.qtIterate((currentValue, count, startValue, incrementValue)=>{}`,
101
+ description: `eg, (5).qtStart(7).qtIncrement(3).qtIterate(item=>item*100)`,
102
102
  supportedTypeList: [Number],
103
103
  method: () => iterator
104
104
  });
@@ -101,6 +101,9 @@ var moduleFunction = function(args = {}) {
101
101
  if (!dottedPathString) {
102
102
  return baseObj;
103
103
  }
104
+ if (dottedPathString.match(/(__proto__|constructor|prototype)/)){
105
+ return baseObj; //avoid prototype pollution
106
+ }
104
107
 
105
108
  if (elements.length < 2) {
106
109
  baseObj[dottedPathString] = value;
@@ -16,7 +16,7 @@ const moduleFunction = function(args) {
16
16
  console.log(`FAIL TEST: ${thisStepMessage} in ...${moduleName}`);
17
17
  }
18
18
  if (verbose) {
19
- console.log(`Result for: ${methodName} (${thisStepPass?'PASS':'FAIL'}):`);
19
+ console.log(`Result for: ${methodName} ${thisStepMessage} (${thisStepPass?'PASS':'FAIL'}):`);
20
20
  console.dir(thisStepResult);
21
21
  console.log('\n\n');
22
22
  }
@@ -320,6 +320,20 @@ const moduleFunction = function(args) {
320
320
 
321
321
 
322
322
 
323
+ methodName = 'qtPutSurePath';
324
+ thisStepMessage = 'avoid prototype polution';
325
+ thisStepResult = testArray[methodName]('__proto__', 9999);
326
+ thisStepEvalFunction = item => item.qtGetSurePath('__proto__')!=9999;
327
+ passingTests =
328
+ completeStep(
329
+ methodName,
330
+ thisStepMessage,
331
+ thisStepResult,
332
+ thisStepEvalFunction
333
+ ) && passingTests;
334
+
335
+
336
+
323
337
 
324
338
  return passingTests;
325
339
  };
@@ -68,6 +68,40 @@ var moduleFunction = function(args = {}) {
68
68
  method
69
69
  };
70
70
  };
71
+ //third method definition function ==========================
72
+ const thirdMethodFunction = commonFunctions => {
73
+ const methodName = 'qtPush';
74
+ const description = `operand.qtPush(value) pushes to the array and returns the array`;
75
+ const supportedTypeList = [Array];
76
+
77
+ const method = () =>
78
+ function(value) {
79
+ const inData = this;
80
+ if (typeof inData.length == 'undefined') {
81
+ throw 'array.qtPush(defaultValue=undefined) works for Arrays only';
82
+ }
83
+
84
+ inData.push(value);
85
+ return inData;
86
+ };
87
+
88
+ const test = args => {
89
+ return require('./test.js')({
90
+ ...args,
91
+ ...{
92
+ moduleName: module.id.replace(module.path, '')
93
+ }
94
+ });
95
+ };
96
+
97
+ return {
98
+ methodName,
99
+ description,
100
+ supportedTypeList,
101
+ method,
102
+ test
103
+ };
104
+ };
71
105
 
72
106
  const functionObject = new Map(); // prettier-ignore
73
107
  const addFunction = definition => {
@@ -95,6 +129,7 @@ var moduleFunction = function(args = {}) {
95
129
 
96
130
  addFunction(firstMethodFunction());
97
131
  addFunction(secondMethodFunction());
132
+ addFunction(thirdMethodFunction());
98
133
 
99
134
  this.addToPrototype = addToPrototypeActual(functionObject);
100
135
 
@@ -87,6 +87,15 @@ const moduleFunction = function(args) {
87
87
  completeStep(methodName, thisStepMessage, thisStepResult, thisStepEvalFunction) &&
88
88
  passingTests;
89
89
 
90
+ //TEST ITEM ------------------------------------------------------
91
+ methodName='qtPush'
92
+ thisStepMessage = "element was not added";
93
+ thisStepResult = emptyArray[methodName]('test value');
94
+ thisStepEvalFunction = item => (item=>item.qtPop()=='test value');
95
+ passingTests =
96
+ completeStep(methodName, thisStepMessage, thisStepResult, thisStepEvalFunction) &&
97
+ passingTests;
98
+
90
99
 
91
100
 
92
101
 
@@ -19,6 +19,12 @@ var moduleFunction = function(args = {}) {
19
19
  let returnn = '';
20
20
  let showLabel = '';
21
21
  let suffix = '';
22
+ let cancelDump = args.cancelDump ? args.cancelDump : false;
23
+
24
+ if (cancelDump){
25
+ return this;
26
+ }
27
+
22
28
  const recursionDepth =
23
29
  typeof args.recursionDepth != 'undefined' ? args.recursionDepth : null;
24
30
  const addCliColors =
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qtools-functional-library",
3
- "version": "1.1.4",
3
+ "version": "1.1.9",
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": {
package/README DELETED
@@ -1,2 +0,0 @@
1
- qtools-functional-library
2
-