qtools-library-dot-d 1.0.12 → 1.0.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/LICENSE +21 -0
- package/README.md +1 -0
- package/package.json +2 -2
- package/libDotD_Working_Example/README.md +0 -234
- package/libDotD_Working_Example/demoModules_DotD/demo1.js +0 -46
- package/libDotD_Working_Example/demoModules_DotD/demo2.js +0 -48
- package/libDotD_Working_Example/index.js +0 -133
- package/libDotD_Working_Example/node_modules/.package-lock.json +0 -29
- package/libDotD_Working_Example/node_modules/qtools-asynchronous-pipe-plus/README.md +0 -213
- package/libDotD_Working_Example/node_modules/qtools-asynchronous-pipe-plus/package.json +0 -20
- package/libDotD_Working_Example/node_modules/qtools-asynchronous-pipe-plus/qtools-asynchronous-pipe-plus.js +0 -278
- package/libDotD_Working_Example/node_modules/qtools-asynchronous-pipe-plus/test.js +0 -79
- package/libDotD_Working_Example/node_modules/qtools-functional-library/README.md +0 -110
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-clone/package.json +0 -11
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-clone/qtools-clone.js +0 -103
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-clone/test.js +0 -78
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-get-by-property/package.json +0 -11
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-get-by-property/qtools-get-by-property.js +0 -73
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-get-by-property/test.js +0 -129
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-includes-regex/package.json +0 -11
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-includes-regex/qtools-includes-regex.js +0 -54
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-includes-regex/test.js +0 -76
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-log-output/package.json +0 -11
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-log-output/qtools-log-output.js +0 -114
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-log-output/test.js +0 -130
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-map-properties/package.json +0 -11
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-map-properties/qtools-map-properties.js +0 -99
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-map-properties/test.js +0 -118
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-merge/package.json +0 -11
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-merge/qtools-merge.js +0 -147
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-merge/test.js +0 -214
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-new-method-template/package.json +0 -11
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-new-method-template/qtools-new-method-template.js +0 -70
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-new-method-template/test.js +0 -66
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-number-iterator/package.json +0 -11
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-number-iterator/qtools-number-iterator.js +0 -137
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-number-iterator/test.js +0 -68
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-number-keys-to-array/package.json +0 -11
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-number-keys-to-array/qtools-number-keys-to-array.js +0 -131
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-number-keys-to-array/test.js +0 -181
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-object-sure-path/package.json +0 -11
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-object-sure-path/qtools-object-sure-path.js +0 -204
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-object-sure-path/test.js +0 -345
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-pass-through/package.json +0 -11
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-pass-through/qtools-pass-through.js +0 -58
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-pass-through/test.js +0 -66
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-pop/package.json +0 -11
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-pop/qtools-pop.js +0 -175
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-pop/test.js +0 -118
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-print-debug/package.json +0 -11
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-print-debug/qtools-print-debug.js +0 -352
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-print-debug/test.js +0 -77
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-select-properties/package.json +0 -11
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-select-properties/qtools-select-properties.js +0 -132
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-select-properties/test.js +0 -156
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-template-replace/README.md +0 -3
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-template-replace/package.json +0 -11
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-template-replace/qtools-template-replace.js +0 -106
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-template-replace/test.js +0 -168
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-to-key-value-array/package.json +0 -11
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-to-key-value-array/qtools-to-key-value-array.js +0 -83
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-to-key-value-array/test.js +0 -68
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-to-string/package.json +0 -11
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-to-string/qtools-to-string.js +0 -84
- package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-to-string/test.js +0 -63
- package/libDotD_Working_Example/node_modules/qtools-functional-library/package.json +0 -37
- package/libDotD_Working_Example/node_modules/qtools-functional-library/qtFunctionalDemo.js +0 -297
- package/libDotD_Working_Example/node_modules/qtools-functional-library/qtools-functional-library.js +0 -271
- package/libDotD_Working_Example/node_modules/qtools-functional-library/test.js +0 -47
- package/libDotD_Working_Example/node_modules/qtools-library-dot-d/README.md +0 -208
- package/libDotD_Working_Example/node_modules/qtools-library-dot-d/package.json +0 -15
- package/libDotD_Working_Example/node_modules/qtools-library-dot-d/qtools-library-dot-d.js +0 -239
- package/libDotD_Working_Example/package-lock.json +0 -37
- package/libDotD_Working_Example/package.json +0 -23
|
@@ -1,131 +0,0 @@
|
|
|
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 = 'qtNumberKeysToArray';
|
|
14
|
-
const description = `object.${methodName}({collapseHoles=true, omitNonNumeric=false, throwErrorIfNonNumeric=false})`;
|
|
15
|
-
const supportedTypeList = [Object];
|
|
16
|
-
|
|
17
|
-
const baseConversion=function(inData, args={}) {
|
|
18
|
-
const { collapseHoles = true, omitNonNumeric = false, throwErrorIfNonNumeric=false } = args;
|
|
19
|
-
if (typeof inData.length != 'undefined') {
|
|
20
|
-
return inData;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
var outArray = [];
|
|
24
|
-
var workingArray = [];
|
|
25
|
-
const extraElements = [];
|
|
26
|
-
let maxIndex = 0;
|
|
27
|
-
|
|
28
|
-
let naturalIndex = 0;
|
|
29
|
-
|
|
30
|
-
for (var i in inData) {
|
|
31
|
-
if (!inData.hasOwnProperty(i)) {
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
var element = inData[i];
|
|
36
|
-
|
|
37
|
-
if (isNaN(+i)) {
|
|
38
|
-
extraElements.push({
|
|
39
|
-
key: i,
|
|
40
|
-
value: element
|
|
41
|
-
});
|
|
42
|
-
if(throwErrorIfNonNumeric){
|
|
43
|
-
throw `throwErrorIfNonNumeric set true, non-numeric key '${i}' not allowed`;
|
|
44
|
-
}
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (collapseHoles) {
|
|
49
|
-
workingArray[naturalIndex] = element;
|
|
50
|
-
naturalIndex++;
|
|
51
|
-
} else {
|
|
52
|
-
workingArray[i] = element;
|
|
53
|
-
maxIndex = Math.max(maxIndex, i);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (!collapseHoles) {
|
|
59
|
-
|
|
60
|
-
for (var i = 0; i < maxIndex + 1; i++) {
|
|
61
|
-
outArray.push(
|
|
62
|
-
typeof workingArray[i] != 'undefined' ? workingArray[i] : void ''
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
} else {
|
|
67
|
-
outArray = workingArray;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (!omitNonNumeric) {
|
|
71
|
-
for (var i = 0, len = extraElements.length; i < len; i++) {
|
|
72
|
-
outArray.push(extraElements[i]);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return outArray;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const method = () => function(args={}){
|
|
80
|
-
if (args.shallow){
|
|
81
|
-
return baseConversion(this, args)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (
|
|
85
|
-
typeof this != 'object' ||
|
|
86
|
-
typeof this.length != 'undefined' ||
|
|
87
|
-
this == null
|
|
88
|
-
) {
|
|
89
|
-
return this;
|
|
90
|
-
}
|
|
91
|
-
const keys = Object.keys(this);
|
|
92
|
-
for (var i in this) {
|
|
93
|
-
if (!this.hasOwnProperty(i)) {
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
this[i] = this[i].qtNumberKeysToArray(args);
|
|
97
|
-
}
|
|
98
|
-
const isNumeric = keys.filter(item => !isNaN(+item)).length ? true : false;
|
|
99
|
-
if (!isNumeric) {
|
|
100
|
-
return this;
|
|
101
|
-
}
|
|
102
|
-
return baseConversion(this, args)
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const functionObject = new Map(); // prettier-ignore
|
|
109
|
-
functionObject.set(methodName, {
|
|
110
|
-
description,
|
|
111
|
-
supportedTypeList,
|
|
112
|
-
method,
|
|
113
|
-
test: args => {
|
|
114
|
-
return require('./test.js')({
|
|
115
|
-
...args,
|
|
116
|
-
...{
|
|
117
|
-
moduleName: module.id.replace(module.path, '')
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
return functionObject;
|
|
123
|
-
};
|
|
124
|
-
this.addToPrototype = addToPrototypeActual(
|
|
125
|
-
firstMethodFunction(commonFunctions)
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
};
|
|
129
|
-
//END OF moduleFunction() ============================================================
|
|
130
|
-
module.exports = moduleFunction;
|
|
131
|
-
//module.exports = new moduleFunction();
|
|
@@ -1,181 +0,0 @@
|
|
|
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 = ({
|
|
9
|
-
verbose = false,
|
|
10
|
-
logErrors = false,
|
|
11
|
-
moduleName
|
|
12
|
-
}) => (methodName, thisStepMessage, thisStepResult, thisStepEvalFunction) => {
|
|
13
|
-
const thisStepPass = thisStepEvalFunction(thisStepResult);
|
|
14
|
-
|
|
15
|
-
if (logErrors && !thisStepPass) {
|
|
16
|
-
console.log(`FAIL TEST: ${thisStepMessage} in ...${moduleName}`);
|
|
17
|
-
}
|
|
18
|
-
if (verbose) {
|
|
19
|
-
console.log(
|
|
20
|
-
`Result for: ${methodName} (${thisStepPass ? 'PASS' : 'FAIL'}):`
|
|
21
|
-
);
|
|
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
|
-
|
|
42
|
-
const testArray = {
|
|
43
|
-
['0']: 'zero',
|
|
44
|
-
['1']: 'one',
|
|
45
|
-
['4']: 'four',
|
|
46
|
-
a: 'b'
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const testArray2 = {
|
|
52
|
-
['0']: 'zero',
|
|
53
|
-
['1']: 'one',
|
|
54
|
-
['4']: 'four',
|
|
55
|
-
a: 'b',
|
|
56
|
-
subArray: {
|
|
57
|
-
['0']: 'zeroX',
|
|
58
|
-
['1']: 'oneX',
|
|
59
|
-
['4']: 'fourX'
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const emptyArray = {};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
//TEST ITEM ------------------------------------------------------
|
|
67
|
-
methodName = 'qtNumberKeysToArray';
|
|
68
|
-
thisStepMessage = 'test #1, result is wrong, holes or length are wrong';
|
|
69
|
-
thisStepResult = testArray[methodName]({
|
|
70
|
-
collapseHoles: false,
|
|
71
|
-
omitNonNumeric: true
|
|
72
|
-
});
|
|
73
|
-
thisStepEvalFunction = item =>
|
|
74
|
-
(item =
|
|
75
|
-
item.length == 5 &&
|
|
76
|
-
typeof item[2] == 'undefined' &&
|
|
77
|
-
typeof item[3] == 'undefined');
|
|
78
|
-
passingTests =
|
|
79
|
-
completeStep(
|
|
80
|
-
methodName,
|
|
81
|
-
thisStepMessage,
|
|
82
|
-
thisStepResult,
|
|
83
|
-
thisStepEvalFunction
|
|
84
|
-
) && passingTests;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
//TEST ITEM ------------------------------------------------------
|
|
88
|
-
methodName = 'qtNumberKeysToArray';
|
|
89
|
-
thisStepMessage = 'test #2, result is wrong, has holes or length is wrong';
|
|
90
|
-
thisStepResult = testArray[methodName]({
|
|
91
|
-
collapseHoles: true,
|
|
92
|
-
omitNonNumeric: true
|
|
93
|
-
});
|
|
94
|
-
thisStepEvalFunction = item =>
|
|
95
|
-
(item =
|
|
96
|
-
item.length == 3 &&
|
|
97
|
-
item.reduce(
|
|
98
|
-
(item, result) => typeof (item != 'undefined') && result,
|
|
99
|
-
true
|
|
100
|
-
));
|
|
101
|
-
passingTests =
|
|
102
|
-
completeStep(
|
|
103
|
-
methodName,
|
|
104
|
-
thisStepMessage,
|
|
105
|
-
thisStepResult,
|
|
106
|
-
thisStepEvalFunction
|
|
107
|
-
) && passingTests;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
//TEST ITEM ------------------------------------------------------
|
|
113
|
-
methodName = 'qtNumberKeysToArray';
|
|
114
|
-
thisStepMessage =
|
|
115
|
-
'test #3, result is wrong, non-numeric element is missing or length is wrong';
|
|
116
|
-
thisStepResult = testArray[methodName]({
|
|
117
|
-
collapseHoles: true,
|
|
118
|
-
omitNonNumeric: false
|
|
119
|
-
});
|
|
120
|
-
thisStepEvalFunction = item =>
|
|
121
|
-
(item = item.length == 4 && typeof item[3] == 'object');
|
|
122
|
-
passingTests =
|
|
123
|
-
completeStep(
|
|
124
|
-
methodName,
|
|
125
|
-
thisStepMessage,
|
|
126
|
-
thisStepResult,
|
|
127
|
-
thisStepEvalFunction
|
|
128
|
-
) && passingTests;
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
//TEST ITEM ------------------------------------------------------
|
|
135
|
-
methodName = 'qtNumberKeysToArray';
|
|
136
|
-
thisStepMessage = 'test #4, subordinate element was not converted properly';
|
|
137
|
-
thisStepResult = testArray2[methodName]({
|
|
138
|
-
collapseHoles: true,
|
|
139
|
-
omitNonNumeric: false
|
|
140
|
-
});
|
|
141
|
-
thisStepEvalFunction = item =>
|
|
142
|
-
(item =
|
|
143
|
-
item.length == 5 &&
|
|
144
|
-
typeof item[4] == 'object' &&
|
|
145
|
-
item[4].value.length == 3);
|
|
146
|
-
passingTests =
|
|
147
|
-
completeStep(
|
|
148
|
-
methodName,
|
|
149
|
-
thisStepMessage,
|
|
150
|
-
thisStepResult,
|
|
151
|
-
thisStepEvalFunction
|
|
152
|
-
) && passingTests;
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
//TEST ITEM ------------------------------------------------------
|
|
156
|
-
methodName = 'qtNumberKeysToArray';
|
|
157
|
-
thisStepMessage = 'test #5, empty object returns empty array';
|
|
158
|
-
thisStepResult = emptyArray[methodName]({
|
|
159
|
-
collapseHoles: true,
|
|
160
|
-
omitNonNumeric: false
|
|
161
|
-
});
|
|
162
|
-
thisStepEvalFunction = item => (item = item.length === 0);
|
|
163
|
-
passingTests =
|
|
164
|
-
completeStep(
|
|
165
|
-
methodName,
|
|
166
|
-
thisStepMessage,
|
|
167
|
-
thisStepResult,
|
|
168
|
-
thisStepEvalFunction
|
|
169
|
-
) && passingTests;
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
return passingTests;
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
//END OF moduleFunction() ============================================================
|
|
178
|
-
|
|
179
|
-
module.exports = moduleFunction;
|
|
180
|
-
//module.exports = new moduleFunction();
|
|
181
|
-
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "qtools-object-sure-path",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "mutate properties in an object based on a dotted path",
|
|
5
|
-
"main": "qtools-object-sure-path.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
-
},
|
|
9
|
-
"author": "TQ White II",
|
|
10
|
-
"license": "ISC"
|
|
11
|
-
}
|
|
@@ -1,204 +0,0 @@
|
|
|
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
|
-
let getDottedPathLastProgressiveString = ''; //needed for recursive function
|
|
11
|
-
let putDottedPathLastProgressiveString=''; //needed for recursive function
|
|
12
|
-
|
|
13
|
-
function qtGetSurePath(dottedPathString, defaultReturn) {
|
|
14
|
-
var baseObj = this;
|
|
15
|
-
var target = this;
|
|
16
|
-
var elements;
|
|
17
|
-
|
|
18
|
-
if (typeof(dottedPathString)!='string'){
|
|
19
|
-
console.trace();
|
|
20
|
-
throw `qtGetSurePath() says, dottedPathString argument is ${typeof(dottedPathString)}, must be of type string`;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (dottedPathString==''){
|
|
24
|
-
return defaultReturn;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (baseObj == null) {
|
|
28
|
-
if (
|
|
29
|
-
typeof defaultReturn != 'undefined' &&
|
|
30
|
-
typeof target == 'undefined'
|
|
31
|
-
) {
|
|
32
|
-
return defaultReturn;
|
|
33
|
-
} else {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
if (dottedPathString.toString().match(/\.|\[/)) {
|
|
38
|
-
var elements = dottedPathString.split(/\.|\[(.*?)]/);
|
|
39
|
-
} else {
|
|
40
|
-
var elements = [];
|
|
41
|
-
elements.push(dottedPathString);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (!dottedPathString) {
|
|
45
|
-
return baseObj;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (elements.length < 2) {
|
|
49
|
-
if (
|
|
50
|
-
typeof defaultReturn != 'undefined' &&
|
|
51
|
-
typeof baseObj[dottedPathString] == 'undefined'
|
|
52
|
-
) {
|
|
53
|
-
return defaultReturn;
|
|
54
|
-
}
|
|
55
|
-
return baseObj[dottedPathString];
|
|
56
|
-
} else {
|
|
57
|
-
for (var i = 0, len = elements.length; i < len; i++) {
|
|
58
|
-
if (elements[i]) {
|
|
59
|
-
//mainly eliminates trailing periods but would also eliminates double periods and other regex anomalies
|
|
60
|
-
target = target?target[elements[i]]:undefined;
|
|
61
|
-
|
|
62
|
-
getDottedPathLastProgressiveString += elements[i] + '.';
|
|
63
|
-
if (typeof target == 'undefined' || target === '') {
|
|
64
|
-
if (
|
|
65
|
-
typeof defaultReturn != 'undefined' &&
|
|
66
|
-
(typeof target == 'undefined' || target === '')
|
|
67
|
-
) {
|
|
68
|
-
return defaultReturn;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return target;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function qtPutSurePath(dottedPathString, value, preserveExisting) {
|
|
81
|
-
var baseObj = this;
|
|
82
|
-
var elements;
|
|
83
|
-
var intermediate;
|
|
84
|
-
var propName;
|
|
85
|
-
putDottedPathLastProgressiveString = '';
|
|
86
|
-
|
|
87
|
-
preserveExisting =
|
|
88
|
-
typeof preserveExisting != 'undefined' ? preserveExisting : false;
|
|
89
|
-
|
|
90
|
-
if (baseObj == null) {
|
|
91
|
-
throw 'qtGetDottedPath() says, baseObj cannot be nullx ' +
|
|
92
|
-
dottedPathString;
|
|
93
|
-
}
|
|
94
|
-
if (dottedPathString.toString().match(/\.|\[/)) {
|
|
95
|
-
var elements = dottedPathString.split(/\.|(\[.*?)]/);
|
|
96
|
-
} else {
|
|
97
|
-
var elements = [];
|
|
98
|
-
elements.push(dottedPathString);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (!dottedPathString) {
|
|
102
|
-
return baseObj;
|
|
103
|
-
}
|
|
104
|
-
if (dottedPathString.match(/(__proto__|constructor|prototype)/)){
|
|
105
|
-
return baseObj; //avoid prototype pollution
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (elements.length < 2) {
|
|
109
|
-
baseObj[dottedPathString] = value;
|
|
110
|
-
} else {
|
|
111
|
-
intermediate = baseObj;
|
|
112
|
-
for (var i = 0, len = elements.length; i < len; i++) {
|
|
113
|
-
if (elements[i]) {
|
|
114
|
-
//mainly eliminates trailing periods but would also eliminates double periods and other regex anomalies
|
|
115
|
-
propName = elements[i];
|
|
116
|
-
|
|
117
|
-
if (elements[i + 1] && elements[i + 1].replace(/^\[/)) {
|
|
118
|
-
elements[i + 1] = elements[i + 1].replace(/^\[/, '');
|
|
119
|
-
var nextElement = [];
|
|
120
|
-
var nextElementType = 'array';
|
|
121
|
-
} else {
|
|
122
|
-
var nextElement = {};
|
|
123
|
-
var nextElementType = 'object';
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (propName) {
|
|
127
|
-
//ignore trailing and redundant dots
|
|
128
|
-
if (
|
|
129
|
-
commonFunctions.toType(intermediate[propName]) !=
|
|
130
|
-
nextElementType
|
|
131
|
-
) {
|
|
132
|
-
intermediate[propName] = nextElement;
|
|
133
|
-
} else if (preserveExisting) {
|
|
134
|
-
throw "'preserveExisting' flag is set, found non-object in path: " +
|
|
135
|
-
propName +
|
|
136
|
-
' in ' +
|
|
137
|
-
dottedPathString;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
intermediate = intermediate[propName];
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
intermediate = baseObj;
|
|
146
|
-
for (var i = 0, len = elements.length; i < len - 1; i++) {
|
|
147
|
-
if (elements[i]) {
|
|
148
|
-
//mainly eliminates trailing periods but would also eliminate double periods
|
|
149
|
-
propName = elements[i];
|
|
150
|
-
intermediate = intermediate[propName];
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
intermediate[elements[len - 1]] = value;
|
|
155
|
-
}
|
|
156
|
-
return baseObj;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
//first method definition function ==========================
|
|
163
|
-
const firstMethodFunction = commonFunctions => {
|
|
164
|
-
const functionObject = new Map(); // prettier-ignore
|
|
165
|
-
|
|
166
|
-
functionObject.set('qtGetSurePath', {
|
|
167
|
-
description: `({}).qtGetSurePath('path.to.something', defaultValue) retrieves the value at the end of the dotted path. It does not crash in an intermediate path element is undefined. If it is, qtGetSurePath() returns either undefined or defaultValue`,
|
|
168
|
-
supportedTypeList: [Object],
|
|
169
|
-
method: () => qtGetSurePath,
|
|
170
|
-
test: args => {
|
|
171
|
-
return require('./test.js')({
|
|
172
|
-
...args,
|
|
173
|
-
...{
|
|
174
|
-
moduleName: module.id.replace(module.path, '')
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
functionObject.set('qtPutSurePath', {
|
|
181
|
-
description: `({}).qtPutSurePath('path.to'value', valueToBePut, preserveExisting) injects a value into an object by creating, if necessary, any intermediary objects to complete the path. If preserveExisting==true, nothing is placed if a value is already present.`,
|
|
182
|
-
supportedTypeList: [Object],
|
|
183
|
-
method: () => qtPutSurePath,
|
|
184
|
-
test: args => {
|
|
185
|
-
return require('./test.js')({
|
|
186
|
-
...args,
|
|
187
|
-
...{
|
|
188
|
-
moduleName: module.id.replace(module.path, '')
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
return functionObject;
|
|
196
|
-
};
|
|
197
|
-
this.addToPrototype = addToPrototypeActual(
|
|
198
|
-
firstMethodFunction(commonFunctions)
|
|
199
|
-
);
|
|
200
|
-
|
|
201
|
-
};
|
|
202
|
-
//END OF moduleFunction() ============================================================
|
|
203
|
-
module.exports = moduleFunction;
|
|
204
|
-
//module.exports = new moduleFunction();
|