fable 3.1.30 → 3.1.31
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/package.json
CHANGED
|
@@ -161,6 +161,10 @@
|
|
|
161
161
|
"Name": "Get Array of an Object's values",
|
|
162
162
|
"Address": "fable.Utility.objectValuesToArray"
|
|
163
163
|
},
|
|
164
|
+
"generatearrayofobjectsfromsets": {
|
|
165
|
+
"Name": "Generate Array of Objects from Sets",
|
|
166
|
+
"Address": "fable.Utility.generateArrayOfObjectsFromSets"
|
|
167
|
+
},
|
|
164
168
|
"objectvaluessortbyexternalobjectarray": {
|
|
165
169
|
"Name": "Get Array of an Object's values sorted by an external array",
|
|
166
170
|
"Address": "fable.Utility.objectValuesSortByExternalArray"
|
|
@@ -308,6 +308,10 @@ class FableServiceUtility extends libFableServiceBase
|
|
|
308
308
|
// Convert object values to an array of values
|
|
309
309
|
objectValuesToArray(pObject)
|
|
310
310
|
{
|
|
311
|
+
if ((typeof(pObject) !== 'object') || (pObject === null))
|
|
312
|
+
{
|
|
313
|
+
return [];
|
|
314
|
+
}
|
|
311
315
|
let tmpKeys = Object.keys(pObject);
|
|
312
316
|
let tmpValues = [];
|
|
313
317
|
|
|
@@ -551,6 +555,54 @@ class FableServiceUtility extends libFableServiceBase
|
|
|
551
555
|
return pInputArray.flatMap(tmpArrayFlattener);
|
|
552
556
|
}
|
|
553
557
|
|
|
558
|
+
generateArrayOfObjectsFromSets()
|
|
559
|
+
{
|
|
560
|
+
// For each argument pair, map data to an array of objects with the first parameter of the pairs as the property name and the second parameter as the array of values
|
|
561
|
+
let tmpResultArray = [];
|
|
562
|
+
if (arguments.length % 2 != 0)
|
|
563
|
+
{
|
|
564
|
+
// Must be pairs
|
|
565
|
+
return tmpResultArray;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
let tmpPropertyNames = [];
|
|
569
|
+
let tmpValueArrays = [];
|
|
570
|
+
|
|
571
|
+
for (let i = 0; i < arguments.length; i += 2)
|
|
572
|
+
{
|
|
573
|
+
tmpPropertyNames.push(arguments[i]);
|
|
574
|
+
tmpValueArrays.push(this.objectValuesToArray(arguments[i + 1]));
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
for (let h = 0; h < tmpValueArrays.length; h++)
|
|
578
|
+
{
|
|
579
|
+
let tmpValueArray = tmpValueArrays[h];
|
|
580
|
+
let tmpPropertyName = tmpPropertyNames[h];
|
|
581
|
+
if (!Array.isArray(tmpValueArray))
|
|
582
|
+
{
|
|
583
|
+
continue;
|
|
584
|
+
}
|
|
585
|
+
for (let i = 0; i < tmpValueArray.length; i++)
|
|
586
|
+
{
|
|
587
|
+
if (tmpResultArray.length <= i)
|
|
588
|
+
{
|
|
589
|
+
tmpResultArray.push({});
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
let tmpObject = tmpResultArray[i];
|
|
593
|
+
if (!tmpObject)
|
|
594
|
+
{
|
|
595
|
+
// This shouldn't be possible
|
|
596
|
+
continue;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
tmpObject[tmpPropertyName] = tmpValueArray[i];
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
return tmpResultArray;
|
|
604
|
+
}
|
|
605
|
+
|
|
554
606
|
/**
|
|
555
607
|
* Take a set of arbitrary parameters and build an array from them
|
|
556
608
|
* @returns {Array} - An array built from the absolute values of the parameters
|
package/test/Utility_tests.js
CHANGED
|
@@ -70,6 +70,54 @@ suite
|
|
|
70
70
|
Expect(tmpInternalValueArray[3]).to.equal(undefined);
|
|
71
71
|
Expect(tmpInternalValueArray[4]).to.equal(6.75);
|
|
72
72
|
|
|
73
|
+
let tmpTestObject1 = {'a': 1, 'b': 2, 'c': 3};
|
|
74
|
+
let tmpTestObject2 = {'d': 4, 'e': 5, 'f': 6};
|
|
75
|
+
let tmpTestObject3 = {'g': 7, 'h': 8};
|
|
76
|
+
let tmpObjectCoordinateMap = testFable.services.Utility.generateArrayOfObjectsFromSets('x', tmpTestObject1, 'y', tmpTestObject2);
|
|
77
|
+
Expect(tmpObjectCoordinateMap).to.be.an('array');
|
|
78
|
+
Expect(tmpObjectCoordinateMap.length).to.equal(3);
|
|
79
|
+
Expect(tmpObjectCoordinateMap[0]).to.have.property('x').that.equals(1);
|
|
80
|
+
Expect(tmpObjectCoordinateMap[0]).to.have.property('y').that.equals(4);
|
|
81
|
+
Expect(tmpObjectCoordinateMap[1]).to.have.property('x').that.equals(2);
|
|
82
|
+
Expect(tmpObjectCoordinateMap[1]).to.have.property('y').that.equals(5);
|
|
83
|
+
Expect(tmpObjectCoordinateMap[2]).to.have.property('x').that.equals(3);
|
|
84
|
+
Expect(tmpObjectCoordinateMap[2]).to.have.property('y').that.equals(6);
|
|
85
|
+
|
|
86
|
+
let tmpObjectCoordinateMapBadSet = testFable.services.Utility.generateArrayOfObjectsFromSets('x', tmpTestObject1, 'y', tmpTestObject2, 'z', null);
|
|
87
|
+
Expect(tmpObjectCoordinateMap).to.be.an('array');
|
|
88
|
+
Expect(tmpObjectCoordinateMap.length).to.equal(3);
|
|
89
|
+
Expect(tmpObjectCoordinateMap[0]).to.have.property('x').that.equals(1);
|
|
90
|
+
Expect(tmpObjectCoordinateMap[0]).to.have.property('y').that.equals(4);
|
|
91
|
+
Expect(tmpObjectCoordinateMap[1]).to.have.property('x').that.equals(2);
|
|
92
|
+
Expect(tmpObjectCoordinateMap[1]).to.have.property('y').that.equals(5);
|
|
93
|
+
Expect(tmpObjectCoordinateMap[2]).to.have.property('x').that.equals(3);
|
|
94
|
+
Expect(tmpObjectCoordinateMap[2]).to.have.property('y').that.equals(6);
|
|
95
|
+
|
|
96
|
+
let tmpSparseCoordinateMap = testFable.services.Utility.generateArrayOfObjectsFromSets('x', tmpTestObject1, 'y', tmpTestObject3);
|
|
97
|
+
Expect(tmpSparseCoordinateMap).to.be.an('array');
|
|
98
|
+
Expect(tmpSparseCoordinateMap.length).to.equal(3);
|
|
99
|
+
Expect(tmpSparseCoordinateMap[0]).to.have.property('x').that.equals(1);
|
|
100
|
+
Expect(tmpSparseCoordinateMap[0]).to.have.property('y').that.equals(7);
|
|
101
|
+
Expect(tmpSparseCoordinateMap[1]).to.have.property('x').that.equals(2);
|
|
102
|
+
Expect(tmpSparseCoordinateMap[1]).to.have.property('y').that.equals(8);
|
|
103
|
+
Expect(tmpSparseCoordinateMap[2]).to.have.property('x').that.equals(3);
|
|
104
|
+
Expect(tmpSparseCoordinateMap[2]).to.not.have.property('y');
|
|
105
|
+
// The third value in tmpTestObject1 has no corresponding value in tmpTestObject3
|
|
106
|
+
|
|
107
|
+
let tmpObjectCoordinateMapBigSet = testFable.services.Utility.generateArrayOfObjectsFromSets('x', tmpTestObject1, 'y', tmpTestObject2, 'z', tmpTestObject3);
|
|
108
|
+
Expect(tmpObjectCoordinateMapBigSet).to.be.an('array');
|
|
109
|
+
Expect(tmpObjectCoordinateMapBigSet.length).to.equal(3);
|
|
110
|
+
Expect(tmpObjectCoordinateMapBigSet[0]).to.have.property('x').that.equals(1);
|
|
111
|
+
Expect(tmpObjectCoordinateMapBigSet[0]).to.have.property('y').that.equals(4);
|
|
112
|
+
Expect(tmpObjectCoordinateMapBigSet[0]).to.have.property('z').that.equals(7);
|
|
113
|
+
Expect(tmpObjectCoordinateMapBigSet[1]).to.have.property('x').that.equals(2);
|
|
114
|
+
Expect(tmpObjectCoordinateMapBigSet[1]).to.have.property('y').that.equals(5);
|
|
115
|
+
Expect(tmpObjectCoordinateMapBigSet[1]).to.have.property('z').that.equals(8);
|
|
116
|
+
Expect(tmpObjectCoordinateMapBigSet[2]).to.have.property('x').that.equals(3);
|
|
117
|
+
Expect(tmpObjectCoordinateMapBigSet[2]).to.have.property('y').that.equals(6);
|
|
118
|
+
Expect(tmpObjectCoordinateMapBigSet[2]).to.not.have.property('z');
|
|
119
|
+
// The third value in tmpTestObject1 and tmpTestObject2 has no corresponding value in tmpTestObject3
|
|
120
|
+
|
|
73
121
|
let tmpValueObject = testFable.services.Utility.createValueObjectByHashes(tmpDataObject, ['Name', 'Age', 'Colors[2]', 'Nonce', 'Details.Height']);
|
|
74
122
|
Expect(tmpValueObject.Name).to.equal('Thee Tortoise and the Hare');
|
|
75
123
|
Expect(tmpValueObject.Age).to.equal(100);
|