fable 3.1.0 → 3.1.2
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/dist/fable.js +16 -4
- package/dist/fable.js.map +1 -0
- package/dist/fable.min.js +2 -2
- package/dist/fable.min.js.map +1 -1
- package/package.json +1 -1
- package/source/services/Fable-Service-ExpressionParser/Fable-Service-ExpressionParser-FunctionMap.json +8 -0
- package/source/services/Fable-Service-FilePersistence.js +36 -6
- package/source/services/Fable-Service-Math.js +28 -0
- package/source/services/Fable-Service-Operation-DefaultSettings.js +1 -1
- package/test/CSVParser_tests.js +20 -0
- package/test/Math_test.js +6 -0
package/package.json
CHANGED
|
@@ -8,6 +8,14 @@
|
|
|
8
8
|
"Name": "Absolute Value",
|
|
9
9
|
"Address": "fable.Math.absPrecise"
|
|
10
10
|
},
|
|
11
|
+
"floor": {
|
|
12
|
+
"Name": "Floor Value",
|
|
13
|
+
"Address": "fable.Math.floorPrecise"
|
|
14
|
+
},
|
|
15
|
+
"ceil": {
|
|
16
|
+
"Name": "Ceiling Value",
|
|
17
|
+
"Address": "fable.Math.ceilPrecise"
|
|
18
|
+
},
|
|
11
19
|
|
|
12
20
|
"rad": {
|
|
13
21
|
"Name": "Degrees to Radians",
|
|
@@ -46,12 +46,6 @@ class FableServiceFilePersistence extends libFableServiceBase
|
|
|
46
46
|
return fCallback(null, tmpFileExists);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
appendFileSync(pFileName, pAppendContent, pOptions)
|
|
50
|
-
{
|
|
51
|
-
let tmpOptions = (typeof(pOptions) === 'undefined') ? 'utf8' : pOptions;
|
|
52
|
-
return libFS.appendFileSync(pFileName, pAppendContent, tmpOptions);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
49
|
deleteFileSync(pFileName)
|
|
56
50
|
{
|
|
57
51
|
return libFS.unlinkSync(pFileName);
|
|
@@ -74,6 +68,42 @@ class FableServiceFilePersistence extends libFableServiceBase
|
|
|
74
68
|
return libFS.readFile(pFilePath, tmpOptions, fCallback);
|
|
75
69
|
}
|
|
76
70
|
|
|
71
|
+
readFileCSV(pFilePath, pOptions, fRecordFunction, fCompleteFunction, fErrorFunction)
|
|
72
|
+
{
|
|
73
|
+
let tmpCSVParser = this.fable.instantiateServiceProviderWithoutRegistration('CSVParser', pOptions);
|
|
74
|
+
let tmpRecordFunction = (typeof(fRecordFunction) === 'function') ? fRecordFunction :
|
|
75
|
+
(pRecord) =>
|
|
76
|
+
{
|
|
77
|
+
this.fable.log(`CSV Reader received line ${pRecord}`);
|
|
78
|
+
};
|
|
79
|
+
let tmpCompleteFunction = (typeof(fCompleteFunction) === 'function') ? fCompleteFunction :
|
|
80
|
+
() =>
|
|
81
|
+
{
|
|
82
|
+
this.fable.log(`CSV Read of ${pFilePath} complete.`);
|
|
83
|
+
};
|
|
84
|
+
let tmpErrorFunction = (typeof(fErrorFunction) === 'function') ? fErrorFunction :
|
|
85
|
+
(pError) =>
|
|
86
|
+
{
|
|
87
|
+
this.fable.log(`CSV Read of ${pFilePath} Error: ${pError}`, pError);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
return this.lineReaderFactory(pFilePath,
|
|
91
|
+
(pLine) =>
|
|
92
|
+
{
|
|
93
|
+
let tmpRecord = tmpCSVParser.parseCSVLine(pLine);
|
|
94
|
+
if (tmpRecord)
|
|
95
|
+
{
|
|
96
|
+
tmpRecordFunction(tmpRecord, pLine);
|
|
97
|
+
}
|
|
98
|
+
}, tmpCompleteFunction, tmpErrorFunction);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
appendFileSync(pFileName, pAppendContent, pOptions)
|
|
102
|
+
{
|
|
103
|
+
let tmpOptions = (typeof(pOptions) === 'undefined') ? 'utf8' : pOptions;
|
|
104
|
+
return libFS.appendFileSync(pFileName, pAppendContent, tmpOptions);
|
|
105
|
+
}
|
|
106
|
+
|
|
77
107
|
writeFileSync(pFileName, pFileContent, pOptions)
|
|
78
108
|
{
|
|
79
109
|
let tmpOptions = (typeof(pOptions) === 'undefined') ? 'utf8' : pOptions;
|
|
@@ -284,6 +284,34 @@ class FableServiceMath extends libFableServiceBase
|
|
|
284
284
|
return tmpResult.toString();
|
|
285
285
|
}
|
|
286
286
|
|
|
287
|
+
/**
|
|
288
|
+
* Calculates the floor of a number precisely.
|
|
289
|
+
*
|
|
290
|
+
* @param {number} pValue - The number to calculate the floor value of.
|
|
291
|
+
* @returns {string} The floor value of the input number as a string.
|
|
292
|
+
*/
|
|
293
|
+
floorPrecise(pValue)
|
|
294
|
+
{
|
|
295
|
+
let tmpValue = isNaN(pValue) ? 0 : pValue;
|
|
296
|
+
|
|
297
|
+
let tmpResult = Math.floor(tmpValue);
|
|
298
|
+
return tmpResult.toString();
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Calculates the ceiling of a number precisely.
|
|
303
|
+
*
|
|
304
|
+
* @param {number} pValue - The number to calculate the ceiling value of.
|
|
305
|
+
* @returns {string} The ceiling value of the input number as a string.
|
|
306
|
+
*/
|
|
307
|
+
ceilPrecise(pValue)
|
|
308
|
+
{
|
|
309
|
+
let tmpValue = isNaN(pValue) ? 0 : pValue;
|
|
310
|
+
|
|
311
|
+
let tmpResult = Math.ceil(tmpValue);
|
|
312
|
+
return tmpResult.toString();
|
|
313
|
+
}
|
|
314
|
+
|
|
287
315
|
/**
|
|
288
316
|
* Compares two values precisely.
|
|
289
317
|
*
|
package/test/CSVParser_tests.js
CHANGED
|
@@ -60,6 +60,26 @@ suite
|
|
|
60
60
|
|
|
61
61
|
}
|
|
62
62
|
);
|
|
63
|
+
test
|
|
64
|
+
(
|
|
65
|
+
'Pull CSV Data with the Wrapped reader',
|
|
66
|
+
function(fDone)
|
|
67
|
+
{
|
|
68
|
+
let testFable = new libFable();
|
|
69
|
+
testFable.instantiateServiceProvider('FilePersistence');
|
|
70
|
+
let tmpRowCount = 0;
|
|
71
|
+
testFable.FilePersistence.readFileCSV(`${__dirname}/data/books.csv`, {},
|
|
72
|
+
(pRecord) =>
|
|
73
|
+
{
|
|
74
|
+
if (pRecord)
|
|
75
|
+
{
|
|
76
|
+
Expect(pRecord).to.be.an('object');
|
|
77
|
+
Expect(pRecord).to.have.property('authors');
|
|
78
|
+
}
|
|
79
|
+
}, fDone);
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
);
|
|
63
83
|
}
|
|
64
84
|
);
|
|
65
85
|
}
|
package/test/Math_test.js
CHANGED
|
@@ -70,6 +70,12 @@ suite
|
|
|
70
70
|
Expect(testFable.Math.ltePrecise('0.000000000000000000000000000000001', '0.00000000000000000000000000000000099')).to.equal(false);
|
|
71
71
|
Expect(testFable.Math.ltPrecise(4, 5)).to.equal(true);
|
|
72
72
|
|
|
73
|
+
Expect(testFable.Math.floorPrecise(4.939323)).to.equal('4');
|
|
74
|
+
Expect(testFable.Math.ceilPrecise(-4.939323)).to.equal('-4');
|
|
75
|
+
Expect(testFable.Math.ceilPrecise(4.939323)).to.equal('5');
|
|
76
|
+
Expect(testFable.Math.ceilPrecise('BARF')).to.equal('0');
|
|
77
|
+
Expect(testFable.Math.ceilPrecise(undefined)).to.equal('0');
|
|
78
|
+
|
|
73
79
|
Expect(testFable.Math.comparePrecise(4, 5)).to.equal(-1);
|
|
74
80
|
|
|
75
81
|
Expect(testFable.Math.modPrecise(4.939323, 4)).to.equal('0.939323');
|