fable 3.1.3 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fable",
3
- "version": "3.1.3",
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.38"
53
+ "quackage": "^1.0.41"
54
54
  },
55
55
  "dependencies": {
56
56
  "async.eachlimit": "^0.5.2",
@@ -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"
@@ -174,5 +214,10 @@
174
214
  "dateyeardifference": {
175
215
  "Name": "Date Difference in Years",
176
216
  "Address": "fable.Dates.dateYearDifference"
217
+ },
218
+
219
+ "createValueObjectByHashes": {
220
+ "Name": "Create Value Object by Hashes",
221
+ "Address": "fable.Utility.createValueObjectByHashes"
177
222
  }
178
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
  *
@@ -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 {Array} - The value object built from the hash list
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;
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',
@@ -35,10 +35,10 @@ suite
35
35
  {
36
36
  let testFable = new libFable();
37
37
  // Instantiate the RestClient Service Provider
38
- let tmpRestClient = testFable.instantiateServiceProvider('RestClient', { TraceLog: true }, 'RestClient-99');
38
+ testFable.instantiateServiceProvider('RestClient', { TraceLog: true });
39
39
 
40
40
  // Download the wiktionary entry for dog!
41
- tmpRestClient.getJSON('http://localhost:8086/1.0/Author/1',
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');
@@ -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
  }