fable 3.1.2 → 3.1.4
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/debug/Harness.js +20 -3
- package/dist/fable.js +86 -8
- package/dist/fable.js.map +1 -1
- package/dist/fable.min.js +2 -2
- package/dist/fable.min.js.map +1 -1
- package/package.json +2 -2
- package/source/services/Fable-Service-DateManipulation.js +84 -0
- package/source/services/Fable-Service-ExpressionParser/Fable-Service-ExpressionParser-FunctionMap.json +63 -1
- package/source/services/Fable-Service-Math.js +42 -0
- package/source/services/Fable-Service-Utility.js +65 -1
- package/test/DataFormat-StringDateFormatting_tests.js +57 -1
- package/test/ExpressionParser_tests.js +5 -0
- package/test/Math_test.js +13 -0
- package/test/RestClient_test.js +2 -2
- package/test/Utility_tests.js +68 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fable",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.4",
|
|
4
4
|
"description": "A service dependency injection, configuration and logging library.",
|
|
5
5
|
"main": "source/Fable.js",
|
|
6
6
|
"scripts": {
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
},
|
|
51
51
|
"homepage": "https://github.com/stevenvelozo/fable",
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"quackage": "^1.0.
|
|
53
|
+
"quackage": "^1.0.41"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"async.eachlimit": "^0.5.2",
|
|
@@ -41,6 +41,90 @@ class DateManipulation extends libFableServiceProviderBase
|
|
|
41
41
|
// const localeDE = require('dayjs/locale/de');
|
|
42
42
|
// _Fable.Dates.dayJS.locale('de');
|
|
43
43
|
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Calculates the difference in days between two dates.
|
|
47
|
+
*
|
|
48
|
+
* @param {string|Date|number} pDateStart - The start date. Can be a string, Date object, or timestamp.
|
|
49
|
+
* @param {string|Date|number} pDateEnd - The end date. Can be a string, Date object, or timestamp. Defaults to the current date if not provided.
|
|
50
|
+
* @returns {number} The difference in days between the start and end dates. Returns NaN if the start date is invalid.
|
|
51
|
+
*/
|
|
52
|
+
dateDayDifference(pDateStart, pDateEnd)
|
|
53
|
+
{
|
|
54
|
+
// If there is not a valid start date, return NaN
|
|
55
|
+
if ((pDateStart === undefined) || (pDateStart === null) || (pDateStart === ''))
|
|
56
|
+
{
|
|
57
|
+
return NaN;
|
|
58
|
+
}
|
|
59
|
+
let tmpStartDate = this.dayJS(pDateStart);
|
|
60
|
+
// Without a valid end date, dayJS defaults to the current date
|
|
61
|
+
let tmpEndDate = this.dayJS(pDateEnd);
|
|
62
|
+
// Returns the difference in days between two dates
|
|
63
|
+
return tmpEndDate.diff(tmpStartDate, 'day');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Calculates the difference in weeks between two dates.
|
|
68
|
+
*
|
|
69
|
+
* @param {string|Date|number} pDateStart - The start date. Can be a string, Date object, or timestamp.
|
|
70
|
+
* @param {string|Date|number} pDateEnd - The end date. Can be a string, Date object, or timestamp. Defaults to the current date if not provided.
|
|
71
|
+
* @returns {number} The difference in weeks between the two dates. Returns NaN if the start date is invalid.
|
|
72
|
+
*/
|
|
73
|
+
dateWeekDifference(pDateStart, pDateEnd)
|
|
74
|
+
{
|
|
75
|
+
// If there is not a valid start date, return NaN
|
|
76
|
+
if ((pDateStart === undefined) || (pDateStart === null) || (pDateStart === ''))
|
|
77
|
+
{
|
|
78
|
+
return NaN;
|
|
79
|
+
}
|
|
80
|
+
let tmpStartDate = this.dayJS(pDateStart);
|
|
81
|
+
// Without a valid end date, dayJS defaults to the current date
|
|
82
|
+
let tmpEndDate = this.dayJS(pDateEnd);
|
|
83
|
+
// Returns the difference in weeks between two dates
|
|
84
|
+
return tmpEndDate.diff(tmpStartDate, 'week');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Calculates the difference in months between two dates.
|
|
89
|
+
*
|
|
90
|
+
* @param {string|Date|number} pDateStart - The start date. Can be a string, Date object, or timestamp.
|
|
91
|
+
* @param {string|Date|number} pDateEnd - The end date. Can be a string, Date object, or timestamp. Defaults to the current date if not provided.
|
|
92
|
+
* @returns {number} The difference in months between the two dates. Returns NaN if the start date is invalid.
|
|
93
|
+
*/
|
|
94
|
+
dateMonthDifference(pDateStart, pDateEnd)
|
|
95
|
+
{
|
|
96
|
+
// If there is not a valid start date, return NaN
|
|
97
|
+
if ((pDateStart === undefined) || (pDateStart === null) || (pDateStart === ''))
|
|
98
|
+
{
|
|
99
|
+
return NaN;
|
|
100
|
+
}
|
|
101
|
+
let tmpStartDate = this.dayJS(pDateStart);
|
|
102
|
+
// Without a valid end date, dayJS defaults to the current date
|
|
103
|
+
let tmpEndDate = this.dayJS(pDateEnd);
|
|
104
|
+
// Returns the difference in months between two dates
|
|
105
|
+
return tmpEndDate.diff(tmpStartDate, 'month');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Calculates the difference in years between two dates.
|
|
110
|
+
*
|
|
111
|
+
* @param {string|Date|number} pDateStart - The start date. Can be a string, Date object, or timestamp.
|
|
112
|
+
* @param {string|Date|number} pDateEnd - The end date. Can be a string, Date object, or timestamp. Defaults to the current date if not provided.
|
|
113
|
+
* @returns {number} The difference in years between the two dates. Returns NaN if the start date is invalid.
|
|
114
|
+
*/
|
|
115
|
+
dateYearDifference(pDateStart, pDateEnd)
|
|
116
|
+
{
|
|
117
|
+
// If there is not a valid start date, return NaN
|
|
118
|
+
if ((pDateStart === undefined) || (pDateStart === null) || (pDateStart === ''))
|
|
119
|
+
{
|
|
120
|
+
return NaN;
|
|
121
|
+
}
|
|
122
|
+
let tmpStartDate = this.dayJS(pDateStart);
|
|
123
|
+
// Without a valid end date, dayJS defaults to the current date
|
|
124
|
+
let tmpEndDate = this.dayJS(pDateEnd);
|
|
125
|
+
// Returns the difference in years between two dates
|
|
126
|
+
return tmpEndDate.diff(tmpStartDate, 'year');
|
|
127
|
+
}
|
|
44
128
|
}
|
|
45
129
|
|
|
46
130
|
module.exports = DateManipulation;
|
|
@@ -4,6 +4,16 @@
|
|
|
4
4
|
"Address": "fable.Math.sqrtPrecise"
|
|
5
5
|
},
|
|
6
6
|
|
|
7
|
+
"percent": {
|
|
8
|
+
"Name": "Compute Percent (in IS over OF format)",
|
|
9
|
+
"Address": "fable.Math.percentagePrecise"
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
"compare": {
|
|
13
|
+
"Name": "Compare",
|
|
14
|
+
"Address": "fable.Math.comparePrecise"
|
|
15
|
+
},
|
|
16
|
+
|
|
7
17
|
"abs": {
|
|
8
18
|
"Name": "Absolute Value",
|
|
9
19
|
"Address": "fable.Math.absPrecise"
|
|
@@ -26,6 +36,11 @@
|
|
|
26
36
|
"Name": "Pi",
|
|
27
37
|
"Address": "fable.Math.piPrecise"
|
|
28
38
|
},
|
|
39
|
+
"euler": {
|
|
40
|
+
"Name": "Euler",
|
|
41
|
+
"Address": "fable.Math.eulerPrecise"
|
|
42
|
+
},
|
|
43
|
+
|
|
29
44
|
"sin": {
|
|
30
45
|
"Name": "Sine",
|
|
31
46
|
"Address": "fable.Math.sin"
|
|
@@ -43,7 +58,10 @@
|
|
|
43
58
|
"Name": "Count Set Elements",
|
|
44
59
|
"Address": "fable.Math.countSetElements"
|
|
45
60
|
},
|
|
46
|
-
|
|
61
|
+
"countset": {
|
|
62
|
+
"Name": "Count Set Elements",
|
|
63
|
+
"Address": "fable.Math.countSetElements"
|
|
64
|
+
},
|
|
47
65
|
"sortset": {
|
|
48
66
|
"Name": "Sort Set",
|
|
49
67
|
"Address": "fable.Math.sortSetPrecise"
|
|
@@ -91,6 +109,10 @@
|
|
|
91
109
|
"Name": "Round",
|
|
92
110
|
"Address": "fable.Math.roundPrecise"
|
|
93
111
|
},
|
|
112
|
+
"tofixed": {
|
|
113
|
+
"Name": "To Fixed",
|
|
114
|
+
"Address": "fable.Math.toFixedPrecise"
|
|
115
|
+
},
|
|
94
116
|
|
|
95
117
|
"cumulativesummation": {
|
|
96
118
|
"Name": "Count Set Elements in a Histogram or Value Map",
|
|
@@ -107,6 +129,19 @@
|
|
|
107
129
|
"Address": "fable.Utility.getInternalValueByHash"
|
|
108
130
|
},
|
|
109
131
|
|
|
132
|
+
"entryinset": {
|
|
133
|
+
"Name": "Entry in Set",
|
|
134
|
+
"Address": "fable.Math.entryInSet"
|
|
135
|
+
},
|
|
136
|
+
"smallestInSet": {
|
|
137
|
+
"Name": "Smallest in Set",
|
|
138
|
+
"Address": "fable.Math.smallestInSet"
|
|
139
|
+
},
|
|
140
|
+
"largestInSet": {
|
|
141
|
+
"Name": "Largest in Set",
|
|
142
|
+
"Address": "fable.Math.largestInSet"
|
|
143
|
+
},
|
|
144
|
+
|
|
110
145
|
"aggregationhistogram": {
|
|
111
146
|
"Name": "Generate a Histogram by Exact Value Aggregation",
|
|
112
147
|
"Address": "fable.Math.histogramAggregationByExactValueFromInternalState"
|
|
@@ -116,6 +151,11 @@
|
|
|
116
151
|
"Address": "fable.Math.histogramDistributionByExactValueFromInternalState"
|
|
117
152
|
},
|
|
118
153
|
|
|
154
|
+
"setconcatenate": {
|
|
155
|
+
"Name": "Set Concatenate",
|
|
156
|
+
"Address": "fable.Math.setConcatenate"
|
|
157
|
+
},
|
|
158
|
+
|
|
119
159
|
"getvaluearray": {
|
|
120
160
|
"Name": "Get Value Array from Application State or Services (AppData, etc.)",
|
|
121
161
|
"Address": "fable.Utility.createValueArrayByHashParametersFromInternal"
|
|
@@ -157,5 +197,27 @@
|
|
|
157
197
|
"randomfloatupto": {
|
|
158
198
|
"Name": "Random Float",
|
|
159
199
|
"Address": "fable.DataGeneration.randomFloatUpTo"
|
|
200
|
+
},
|
|
201
|
+
|
|
202
|
+
"datedaydifference": {
|
|
203
|
+
"Name": "Date Difference in Days",
|
|
204
|
+
"Address": "fable.Dates.dateDayDifference"
|
|
205
|
+
},
|
|
206
|
+
"dateweekdifference": {
|
|
207
|
+
"Name": "Date Difference in Weeks",
|
|
208
|
+
"Address": "fable.Dates.dateWeekDifference"
|
|
209
|
+
},
|
|
210
|
+
"datemonthdifference": {
|
|
211
|
+
"Name": "Date Difference in Months",
|
|
212
|
+
"Address": "fable.Dates.dateMonthDifference"
|
|
213
|
+
},
|
|
214
|
+
"dateyeardifference": {
|
|
215
|
+
"Name": "Date Difference in Years",
|
|
216
|
+
"Address": "fable.Dates.dateYearDifference"
|
|
217
|
+
},
|
|
218
|
+
|
|
219
|
+
"createValueObjectByHashes": {
|
|
220
|
+
"Name": "Create Value Object by Hashes",
|
|
221
|
+
"Address": "fable.Utility.createValueObjectByHashes"
|
|
160
222
|
}
|
|
161
223
|
}
|
|
@@ -22,6 +22,8 @@ class FableServiceMath extends libFableServiceBase
|
|
|
22
22
|
this.serviceType = 'Math';
|
|
23
23
|
|
|
24
24
|
this.pi = '3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679';
|
|
25
|
+
// From NASA: https://apod.nasa.gov/htmltest/gifcity/e.2mil
|
|
26
|
+
this.euler = '2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664';
|
|
25
27
|
|
|
26
28
|
// this.manifest = this.fable.newManyfest();
|
|
27
29
|
}
|
|
@@ -428,6 +430,24 @@ class FableServiceMath extends libFableServiceBase
|
|
|
428
430
|
}
|
|
429
431
|
}
|
|
430
432
|
|
|
433
|
+
/**
|
|
434
|
+
* Calculates the value of euler with the specified precision.
|
|
435
|
+
*
|
|
436
|
+
* @param {number} [pPrecision] - The precision to use for calculating E.
|
|
437
|
+
* @returns {number} - The calculated value of E.
|
|
438
|
+
*/
|
|
439
|
+
eulerPrecise(pPrecision)
|
|
440
|
+
{
|
|
441
|
+
if (typeof (pPrecision) === 'undefined')
|
|
442
|
+
{
|
|
443
|
+
return this.euler;
|
|
444
|
+
}
|
|
445
|
+
else
|
|
446
|
+
{
|
|
447
|
+
return this.roundPrecise(this.euler, pPrecision);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
431
451
|
/**
|
|
432
452
|
* Calculates the sine of the given angle in radians.
|
|
433
453
|
*
|
|
@@ -729,6 +749,14 @@ class FableServiceMath extends libFableServiceBase
|
|
|
729
749
|
return tmpHistogram;
|
|
730
750
|
}
|
|
731
751
|
|
|
752
|
+
/**
|
|
753
|
+
* Aggregates a histogram by exact value from an internal state object.
|
|
754
|
+
*
|
|
755
|
+
* @param {string} pValueObjectSetAddress - The address of the internal value object set.
|
|
756
|
+
* @param {string} pValueAddress - The address of the value to aggregate by.
|
|
757
|
+
* @param {string} pValueAmountAddress - The address of the amount to aggregate.
|
|
758
|
+
* @returns {Object} The aggregated histogram object. Returns an empty object if the value object set address is not provided.
|
|
759
|
+
*/
|
|
732
760
|
histogramAggregationByExactValueFromInternalState(pValueObjectSetAddress, pValueAddress, pValueAmountAddress)
|
|
733
761
|
{
|
|
734
762
|
if (!pValueObjectSetAddress)
|
|
@@ -769,11 +797,25 @@ class FableServiceMath extends libFableServiceBase
|
|
|
769
797
|
return tmpValueArray[tmpIndex];
|
|
770
798
|
}
|
|
771
799
|
|
|
800
|
+
/**
|
|
801
|
+
* Finds the smallest value in a set of objects based on a specified value address.
|
|
802
|
+
*
|
|
803
|
+
* @param {Object[]} pValueObjectSet - An array of objects to search through.
|
|
804
|
+
* @param {string} pValueAddress - The key or path used to access the value within each object.
|
|
805
|
+
* @returns {*} The smallest value found in the set at the specified value address.
|
|
806
|
+
*/
|
|
772
807
|
smallestInSet(pValueObjectSet, pValueAddress)
|
|
773
808
|
{
|
|
774
809
|
return this.entryInSet(pValueObjectSet, pValueAddress, 0);
|
|
775
810
|
}
|
|
776
811
|
|
|
812
|
+
/**
|
|
813
|
+
* Finds the largest value in a set of objects based on a specified value address.
|
|
814
|
+
*
|
|
815
|
+
* @param {Object[]} pValueObjectSet - An array of objects to search through.
|
|
816
|
+
* @param {string} pValueAddress - The address (key or path) within each object to compare values.
|
|
817
|
+
* @returns {*} The largest value found at the specified address in the set of objects.
|
|
818
|
+
*/
|
|
777
819
|
largestInSet(pValueObjectSet, pValueAddress)
|
|
778
820
|
{
|
|
779
821
|
return this.entryInSet(pValueObjectSet, pValueAddress, -1);
|
|
@@ -217,7 +217,7 @@ class FableServiceUtility extends libFableServiceBase
|
|
|
217
217
|
* @param {object} pObject - The object to get the value from
|
|
218
218
|
* @param {string} pValueAddress - The manyfest hash/address of the value to get
|
|
219
219
|
* @param {object} [pManifest] - The manyfest object to use; constructs one inline if not provided
|
|
220
|
-
* @returns {
|
|
220
|
+
* @returns {object} - The value object built from the hash list
|
|
221
221
|
*/
|
|
222
222
|
createValueObjectByHashes(pObject, pValueHashes, pManifest)
|
|
223
223
|
{
|
|
@@ -338,6 +338,70 @@ class FableServiceUtility extends libFableServiceBase
|
|
|
338
338
|
return false;
|
|
339
339
|
}
|
|
340
340
|
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Find the first value in an object that contains a specific value
|
|
344
|
+
* @param {array} pObjectArray - The array of objects to search
|
|
345
|
+
* @param {string} pValueToMatchAddress - The manyfest hash/address of the value to match
|
|
346
|
+
* @param {string} pValueToMatch - The value to match
|
|
347
|
+
* @param {string} pValueAddress - The manyfest hash/address of the value to return
|
|
348
|
+
* @returns {any} - The value from the object
|
|
349
|
+
*/
|
|
350
|
+
findFirstValueByStringIncludes(pObjectArray, pValueToMatchAddress, pValueToMatch, pValueAddress)
|
|
351
|
+
{
|
|
352
|
+
// Lazily create a manifest if it doesn't exist
|
|
353
|
+
if (!this.manifest)
|
|
354
|
+
{
|
|
355
|
+
this.manifest = this.fable.newManyfest();
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if (!Array.isArray(pObjectArray))
|
|
359
|
+
{
|
|
360
|
+
return undefined;
|
|
361
|
+
}
|
|
362
|
+
for (let i = 0; i < pObjectArray.length; i++)
|
|
363
|
+
{
|
|
364
|
+
let tmpValueToMatch = this.manifest.getValueByHash(pObjectArray[i], pValueToMatchAddress);
|
|
365
|
+
if (tmpValueToMatch && (tmpValueToMatch.includes(pValueToMatch)))
|
|
366
|
+
{
|
|
367
|
+
return this.manifest.getValueByHash(pObjectArray[i], pValueAddress);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
return undefined;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Find the first value in an object that contains a specific value
|
|
376
|
+
* @param {array} pObjectArray - The array of objects to search
|
|
377
|
+
* @param {string} pValueToMatchAddress - The manyfest hash/address of the value to match
|
|
378
|
+
* @param {string} pValueToMatch - The value to match
|
|
379
|
+
* @param {string} pValueAddress - The manyfest hash/address of the value to return
|
|
380
|
+
* @returns {any} - The value from the object
|
|
381
|
+
*/
|
|
382
|
+
findFirstValueByExactMatch(pObjectArray, pValueToMatchAddress, pValueToMatch, pValueAddress)
|
|
383
|
+
{
|
|
384
|
+
// Lazily create a manifest if it doesn't exist
|
|
385
|
+
if (!this.manifest)
|
|
386
|
+
{
|
|
387
|
+
this.manifest = this.fable.newManyfest();
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
if (!Array.isArray(pObjectArray))
|
|
391
|
+
{
|
|
392
|
+
return undefined;
|
|
393
|
+
}
|
|
394
|
+
for (let i = 0; i < pObjectArray.length; i++)
|
|
395
|
+
{
|
|
396
|
+
let tmpValueToMatch = this.manifest.getValueByHash(pObjectArray[i], pValueToMatchAddress);
|
|
397
|
+
if (tmpValueToMatch && (tmpValueToMatch == pValueToMatch))
|
|
398
|
+
{
|
|
399
|
+
return this.manifest.getValueByHash(pObjectArray[i], pValueAddress);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
return undefined;
|
|
404
|
+
}
|
|
341
405
|
}
|
|
342
406
|
|
|
343
407
|
module.exports = FableServiceUtility;
|
|
@@ -20,9 +20,65 @@ suite
|
|
|
20
20
|
|
|
21
21
|
suite
|
|
22
22
|
(
|
|
23
|
-
'Format Dates and Times',
|
|
23
|
+
'Format and Calculate Dates and Times',
|
|
24
24
|
()=>
|
|
25
25
|
{
|
|
26
|
+
test
|
|
27
|
+
(
|
|
28
|
+
'Calculate the difference in days between two dates',
|
|
29
|
+
(fTestComplete)=>
|
|
30
|
+
{
|
|
31
|
+
let testFable = new libFable({LogStreams: false});
|
|
32
|
+
Expect(testFable.Dates.dateDayDifference('2021-03-12', '2023-09-01'))
|
|
33
|
+
.to.equal(903);
|
|
34
|
+
Expect(testFable.Dates.dateDayDifference('2023-08-01', '2023-09-01'))
|
|
35
|
+
.to.equal(31);
|
|
36
|
+
Expect(testFable.Dates.dateDayDifference('2023-09-01', '2023-10-01'))
|
|
37
|
+
.to.equal(30);
|
|
38
|
+
Expect(testFable.Dates.dateDayDifference('2023-9-1', '2023-10-01'))
|
|
39
|
+
.to.equal(30);
|
|
40
|
+
Expect(testFable.Dates.dateWeekDifference('2023-9-1', '2023-10-01'))
|
|
41
|
+
.to.equal(4);
|
|
42
|
+
Expect(testFable.Dates.dateMonthDifference('1986-10-01', '2023-09-01'))
|
|
43
|
+
.to.equal(443);
|
|
44
|
+
Expect(testFable.Dates.dateYearDifference('1986-10-01', '2023-09-01'))
|
|
45
|
+
.to.equal(36);
|
|
46
|
+
Expect(testFable.Dates.dateYearDifference('1986-08-01', '2023-09-01'))
|
|
47
|
+
.to.equal(37);
|
|
48
|
+
Expect(testFable.Dates.dateYearDifference('1986-08-31', '2023-09-01'))
|
|
49
|
+
.to.equal(37);
|
|
50
|
+
let tmpValue = testFable.Dates.dateDayDifference('BadDatesIncoming', '2023-09-01');
|
|
51
|
+
Expect(tmpValue)
|
|
52
|
+
.to.be.NaN;
|
|
53
|
+
|
|
54
|
+
tmpValue = testFable.Dates.dateDayDifference();
|
|
55
|
+
Expect(tmpValue)
|
|
56
|
+
.to.be.NaN;
|
|
57
|
+
return fTestComplete();
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
test
|
|
61
|
+
(
|
|
62
|
+
'Format a time span in milliseconds to a human readable string',
|
|
63
|
+
(fTestComplete)=>
|
|
64
|
+
{
|
|
65
|
+
let testFable = new libFable({LogStreams: false});
|
|
66
|
+
let _DataFormat = testFable.services.DataFormat;
|
|
67
|
+
Expect(_DataFormat
|
|
68
|
+
.formatTimeSpan(1000))
|
|
69
|
+
.to.equal('00:00:01.000');
|
|
70
|
+
Expect(_DataFormat
|
|
71
|
+
.formatTimeSpan(100243231))
|
|
72
|
+
.to.equal('27:50:43.231');
|
|
73
|
+
Expect(_DataFormat
|
|
74
|
+
.formatTimeSpan(100299211))
|
|
75
|
+
.to.equal('27:51:39.211');
|
|
76
|
+
Expect(_DataFormat
|
|
77
|
+
.formatTimeSpan())
|
|
78
|
+
.to.equal('');
|
|
79
|
+
return fTestComplete();
|
|
80
|
+
}
|
|
81
|
+
);
|
|
26
82
|
test
|
|
27
83
|
(
|
|
28
84
|
'Format a time span in milliseconds to a human readable string',
|
|
@@ -256,6 +256,11 @@ suite
|
|
|
256
256
|
Expect(tmpResult).to.equal("1545");
|
|
257
257
|
tmpResult = _Parser.solve('Area = ROUND(X * Y * Z, 3, 3)', tmpDataObject, tmpSolveResults);
|
|
258
258
|
Expect(tmpResult).to.equal("1545.2");
|
|
259
|
+
// Test the getvaluarray function]
|
|
260
|
+
// TODO: Fix the return values for these expression return functions
|
|
261
|
+
//tmpResult = _Parser.solve('NewSet = GETVALUEARRAY(X, Y, Z)', tmpDataObject, tmpSolveResults);
|
|
262
|
+
//tmpResult = _Parser.solve('NewSetAverage = SUM(NewSet)', tmpDataObject, tmpSolveResults);
|
|
263
|
+
//Expect(tmpResult).to.equal("84.115923423");
|
|
259
264
|
return fDone();
|
|
260
265
|
}
|
|
261
266
|
);
|
package/test/Math_test.js
CHANGED
|
@@ -116,6 +116,7 @@ suite
|
|
|
116
116
|
return fDone();
|
|
117
117
|
}
|
|
118
118
|
);
|
|
119
|
+
|
|
119
120
|
test
|
|
120
121
|
(
|
|
121
122
|
'Parse Numbers',
|
|
@@ -132,6 +133,18 @@ suite
|
|
|
132
133
|
}
|
|
133
134
|
);
|
|
134
135
|
|
|
136
|
+
test
|
|
137
|
+
(
|
|
138
|
+
'Eulers Number',
|
|
139
|
+
function(fDone)
|
|
140
|
+
{
|
|
141
|
+
let testFable = new libFable();
|
|
142
|
+
|
|
143
|
+
Expect(testFable.Math.eulerPrecise()).to.equal('2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664');
|
|
144
|
+
return fDone();
|
|
145
|
+
}
|
|
146
|
+
);
|
|
147
|
+
|
|
135
148
|
test
|
|
136
149
|
(
|
|
137
150
|
'Histograms by Count',
|
package/test/RestClient_test.js
CHANGED
|
@@ -35,10 +35,10 @@ suite
|
|
|
35
35
|
{
|
|
36
36
|
let testFable = new libFable();
|
|
37
37
|
// Instantiate the RestClient Service Provider
|
|
38
|
-
|
|
38
|
+
testFable.instantiateServiceProvider('RestClient', { TraceLog: true });
|
|
39
39
|
|
|
40
40
|
// Download the wiktionary entry for dog!
|
|
41
|
-
|
|
41
|
+
testFable.RestClient.getJSON('http://localhost:8086/1.0/Author/1',
|
|
42
42
|
(pError, pResponse, pBody) =>
|
|
43
43
|
{
|
|
44
44
|
Expect(pBody).to.be.an('object');
|
package/test/Utility_tests.js
CHANGED
|
@@ -343,6 +343,74 @@ suite
|
|
|
343
343
|
})
|
|
344
344
|
}
|
|
345
345
|
);
|
|
346
|
+
test
|
|
347
|
+
(
|
|
348
|
+
'findFirstValueByStringIncludes returns values from an array of objects',
|
|
349
|
+
function(fDone)
|
|
350
|
+
{
|
|
351
|
+
testFable = new libFable();
|
|
352
|
+
|
|
353
|
+
let tmpState = [
|
|
354
|
+
{ "Name":"The Pixies", "Type":"Band", "AlbumCount":5, "SongCount": 103, "MarketValue":"83500011.24", "Studios": { "Primary": { "Name":"Swamp Record Studios", "Location":"Boston"} } },
|
|
355
|
+
{ "Name":"The Beatles", "Type":"Band", "AlbumCount":35, "SongCount": 876, "MarketValue":"183942892.24", "Studios": { "Primary": { "Name":"Swamp Record Studios", "Location":"Boston"} } },
|
|
356
|
+
{ "Name":"Modest Mouse", "Type":"Band", "AlbumCount":9, "SongCount": 299, "MarketValue":"332432324.99", "Studios": { "Primary": { "Name":"Swamp Record Studios", "Location":"Boston"} } },
|
|
357
|
+
{ "Name":"The Doors", "Type":"Band", "AlbumCount":6, "SongCount": 133, "MarketValue":"324783294732.32", "Studios": { "Primary": { "Name":"Swamp Record Studios", "Location":"Boston"} } },
|
|
358
|
+
{ "Name":"The Who", "Type":"Band", "AlbumCount":7, "SongCount": 110, "MarketValue":"7500.30", "Studios": { "Primary": { "Name":"Swamp Record Studios", "Location":"Boston"} } },
|
|
359
|
+
{ "Name":"The Cure", "Type":"Band", "AlbumCount":13, "SongCount": 213, "MarketValue":"34230.10", "Studios": { "Primary": { "Name":"Swamp Record Studios", "Location":"Boston"} } }
|
|
360
|
+
];
|
|
361
|
+
let tmpResult = testFable.services.Utility.findFirstValueByStringIncludes(tmpState, 'Name', 'The', 'SongCount');
|
|
362
|
+
Expect(tmpResult).to.be.a('number');
|
|
363
|
+
Expect(tmpResult).to.equal(103);
|
|
364
|
+
|
|
365
|
+
tmpResult = testFable.services.Utility.findFirstValueByStringIncludes(tmpState, 'Name', 'The Cure', 'SongCount');
|
|
366
|
+
Expect(tmpResult).to.be.a('number');
|
|
367
|
+
Expect(tmpResult).to.equal(213);
|
|
368
|
+
|
|
369
|
+
// Missing Key
|
|
370
|
+
tmpResult = testFable.services.Utility.findFirstValueByStringIncludes(tmpState, 'Name', 'The Fleet Foxes', 'SongCount');
|
|
371
|
+
Expect(tmpResult).to.be.a('undefined');
|
|
372
|
+
|
|
373
|
+
// Missing Value
|
|
374
|
+
tmpResult = testFable.services.Utility.findFirstValueByStringIncludes(tmpState, 'Name', 'The Cure', 'No good Value');
|
|
375
|
+
Expect(tmpResult).to.be.a('undefined');
|
|
376
|
+
|
|
377
|
+
return fDone();
|
|
378
|
+
}
|
|
379
|
+
);
|
|
380
|
+
test
|
|
381
|
+
(
|
|
382
|
+
'findFirstValueByExactMatch returns values from an array of objects',
|
|
383
|
+
function(fDone)
|
|
384
|
+
{
|
|
385
|
+
testFable = new libFable();
|
|
386
|
+
|
|
387
|
+
let tmpState = [
|
|
388
|
+
{ "Name":"The Pixies", "Type":"Band", "AlbumCount":5, "SongCount": 103, "MarketValue":"83500011.24", "Studios": { "Primary": { "Name":"Swamp Record Studios", "Location":"Boston"} } },
|
|
389
|
+
{ "Name":"The Beatles", "Type":"Band", "AlbumCount":35, "SongCount": 876, "MarketValue":"183942892.24", "Studios": { "Primary": { "Name":"Swamp Record Studios", "Location":"Boston"} } },
|
|
390
|
+
{ "Name":"Modest Mouse", "Type":"Band", "AlbumCount":9, "SongCount": 299, "MarketValue":"332432324.99", "Studios": { "Primary": { "Name":"Swamp Record Studios", "Location":"Boston"} } },
|
|
391
|
+
{ "Name":"The Doors", "Type":"Band", "AlbumCount":6, "SongCount": 133, "MarketValue":"324783294732.32", "Studios": { "Primary": { "Name":"Swamp Record Studios", "Location":"Boston"} } },
|
|
392
|
+
{ "Name":"The Who", "Type":"Band", "AlbumCount":7, "SongCount": 110, "MarketValue":"7500.30", "Studios": { "Primary": { "Name":"Swamp Record Studios", "Location":"Boston"} } },
|
|
393
|
+
{ "Name":"The Cure", "Type":"Band", "AlbumCount":13, "SongCount": 213, "MarketValue":"34230.10", "Studios": { "Primary": { "Name":"Swamp Record Studios", "Location":"Boston"} } }
|
|
394
|
+
];
|
|
395
|
+
let tmpResult = testFable.services.Utility.findFirstValueByExactMatch(tmpState, 'Name', 'The Who', 'SongCount');
|
|
396
|
+
Expect(tmpResult).to.be.a('number');
|
|
397
|
+
Expect(tmpResult).to.equal(110);
|
|
398
|
+
|
|
399
|
+
tmpResult = testFable.services.Utility.findFirstValueByExactMatch(tmpState, 'SongCount', 133, 'MarketValue');
|
|
400
|
+
Expect(tmpResult).to.be.a('string');
|
|
401
|
+
Expect(tmpResult).to.equal('324783294732.32');
|
|
402
|
+
|
|
403
|
+
// Missing Key
|
|
404
|
+
tmpResult = testFable.services.Utility.findFirstValueByExactMatch(tmpState, 'Name', 'The Fleet Foxes', 'SongCount');
|
|
405
|
+
Expect(tmpResult).to.be.a('undefined');
|
|
406
|
+
|
|
407
|
+
// Missing Value
|
|
408
|
+
tmpResult = testFable.services.Utility.findFirstValueByExactMatch(tmpState, 'Name', 'The Cure', 'No good Value');
|
|
409
|
+
Expect(tmpResult).to.be.a('undefined');
|
|
410
|
+
|
|
411
|
+
return fDone();
|
|
412
|
+
}
|
|
413
|
+
);
|
|
346
414
|
}
|
|
347
415
|
);
|
|
348
416
|
}
|