fable 3.1.45 → 3.1.47

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.45",
3
+ "version": "3.1.47",
4
4
  "description": "A service dependency injection, configuration and logging library.",
5
5
  "main": "source/Fable.js",
6
6
  "scripts": {
@@ -59,7 +59,7 @@
59
59
  "cachetrax": "^1.0.4",
60
60
  "cookie": "^1.0.2",
61
61
  "data-arithmatic": "^1.0.7",
62
- "dayjs": "^1.11.18",
62
+ "dayjs": "^1.11.19",
63
63
  "fable-log": "^3.0.16",
64
64
  "fable-serviceproviderbase": "^3.0.15",
65
65
  "fable-settings": "^3.0.12",
@@ -70,22 +70,23 @@ class ExpressionParserValueMarshal extends libExpressionParserOperationBase
70
70
  {
71
71
  tmpResults.ExpressionParserLog.push(`INFO: ExpressionParser.substituteValuesInTokenizedObjects found a value [${tmpValue}] for the state address ${tmpToken.Token} at index ${i}`);
72
72
  if (this.LogNoisiness > 1) this.log.info(tmpResults.ExpressionParserLog[tmpResults.ExpressionParserLog.length-1]);
73
- try
73
+ if (typeof tmpValue === 'object') // this encapsulates POJOs and arrays
74
74
  {
75
- let tmpValueParsed = new this.fable.Utility.bigNumber(tmpValue);
75
+ // this must be checked first, which works around an edge case where bigNumber turns single-element arrays into numbers, which we never want
76
76
  tmpToken.Resolved = true;
77
- tmpToken.Value = tmpValueParsed.toString();
77
+ tmpToken.Value = tmpValue;
78
78
  }
79
- catch(pError)
79
+ else
80
80
  {
81
- // TODO: Should we allow this to be a function? Good god the complexity and beauty of that...
82
- if (Array.isArray(tmpValue) || (typeof(tmpValue) === 'object'))
81
+ try
83
82
  {
83
+ const tmpValueParsed = new this.fable.Utility.bigNumber(tmpValue);
84
84
  tmpToken.Resolved = true;
85
- tmpToken.Value = tmpValue;
85
+ tmpToken.Value = tmpValueParsed.toString();
86
86
  }
87
- else
87
+ catch(pError)
88
88
  {
89
+ // TODO: Should we allow this to be a function? Good god the complexity and beauty of that...
89
90
  tmpToken.Resolved = true;
90
91
  tmpToken.Value = tmpValue;
91
92
  tmpResults.ExpressionParserLog.push(`INFO: ExpressionParser.substituteValuesInTokenizedObjects found a non-numeric value for the state address ${tmpToken.Token} at index ${i}; using raw value.`);
@@ -25,6 +25,7 @@ class FableServiceMath extends libFableServiceBase
25
25
  this.pi = '3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679';
26
26
  // From NASA: https://apod.nasa.gov/htmltest/gifcity/e.2mil
27
27
  this.euler = '2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664';
28
+ this.errorReturnValue = NaN;
28
29
 
29
30
  // this.manifest = this.fable.newManyfest();
30
31
  this.bigNumber = this.fable.Utility.bigNumber;
@@ -146,9 +147,16 @@ class FableServiceMath extends libFableServiceBase
146
147
  let tmpDecimals = isNaN(pDecimals) ? 0 : parseInt(pDecimals, 10);
147
148
  let tmpRoundingMethod = (typeof (pRoundingMethod) === 'undefined') ? this.roundHalfUp : parseInt(pRoundingMethod, 10);
148
149
 
149
- let tmpArbitraryValue = new this.bigNumber(tmpValue);
150
- let tmpResult = tmpArbitraryValue.round(tmpDecimals, tmpRoundingMethod);
151
- return tmpResult.toString();
150
+ try
151
+ {
152
+ let tmpArbitraryValue = new this.bigNumber(tmpValue);
153
+ let tmpResult = tmpArbitraryValue.round(tmpDecimals, tmpRoundingMethod);
154
+ return tmpResult.toString();
155
+ }
156
+ catch
157
+ {
158
+ return this.errorReturnValue;
159
+ }
152
160
  }
153
161
 
154
162
  /**
@@ -165,10 +173,16 @@ class FableServiceMath extends libFableServiceBase
165
173
  let tmpDecimals = isNaN(pDecimals) ? 0 : parseInt(pDecimals, 10);
166
174
  let tmpRoundingMethod = (typeof (pRoundingMethod) === 'undefined') ? this.roundHalfUp : pRoundingMethod;
167
175
 
168
- let tmpArbitraryValue = new this.bigNumber(tmpValue);
169
- let tmpResult = tmpArbitraryValue.toFixed(tmpDecimals, tmpRoundingMethod);
170
-
171
- return tmpResult.toString();
176
+ try
177
+ {
178
+ let tmpArbitraryValue = new this.bigNumber(tmpValue);
179
+ let tmpResult = tmpArbitraryValue.toFixed(tmpDecimals, tmpRoundingMethod);
180
+ return tmpResult.toString();
181
+ }
182
+ catch
183
+ {
184
+ return this.errorReturnValue;
185
+ }
172
186
  }
173
187
 
174
188
  /**
@@ -145,6 +145,41 @@ suite
145
145
  }
146
146
  );
147
147
  test
148
+ (
149
+ 'Capture array -> number bug',
150
+ (fDone) =>
151
+ {
152
+ let _Parser = getExpressionParser();
153
+
154
+ let tmpResultObject = {};
155
+ let tmpDataObject = { W: ['3', '4', '5'], X: ['5'], Y: 3, Z: 75, Depth: 3, Width: 2 };
156
+ let tmpDestinationObject = {};
157
+
158
+ let tmpArea = _Parser.solve('Area = X * Y * Z', tmpDataObject, tmpResultObject, false, tmpDestinationObject);
159
+
160
+ Expect(tmpArea).to.equal("1125");
161
+
162
+ let tmpSliced = _Parser.solve('SlicedSingleElementArray = SLICE(X, 0, 1)', tmpDataObject, tmpResultObject, false, tmpDestinationObject);
163
+
164
+ Expect(tmpSliced).to.be.an('array');
165
+ Expect(tmpSliced.length).to.equal(1);
166
+ Expect(tmpSliced[0]).to.equal('5');
167
+
168
+ let tmpNonNumberTreatedAsZero = _Parser.solve('NonNumberTreatedAsZero = W + 3.456', tmpDataObject, tmpResultObject, false, tmpDestinationObject);
169
+
170
+ Expect(tmpNonNumberTreatedAsZero).to.equal('3.456');
171
+
172
+ let tmpLargerSlice = _Parser.solve('SLICE(W, 1, 3)', tmpDataObject, tmpResultObject, false, tmpDestinationObject);
173
+
174
+ Expect(tmpLargerSlice).to.be.an('array');
175
+ Expect(tmpLargerSlice.length).to.equal(2);
176
+ Expect(tmpLargerSlice[0]).to.equal('4');
177
+ Expect(tmpLargerSlice[1]).to.equal('5');
178
+
179
+ return fDone();
180
+ }
181
+ );
182
+ test
148
183
  (
149
184
  'Exercise Marshaling to Value at a Hashed Address',
150
185
  (fDone) =>