fable 3.0.49 → 3.0.51
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/.browserslistrc +1 -1
- package/.config/configstore/update-notifier-npm.json +1 -1
- package/dist/fable.compatible.js +52 -41
- package/dist/fable.compatible.min.js +10 -18
- package/dist/fable.compatible.min.js.map +1 -1
- package/dist/fable.js +28 -17
- package/dist/fable.min.js +10 -18
- package/dist/fable.min.js.map +1 -1
- package/gulpfile.js +1 -164
- package/package.json +65 -78
- package/source/Fable.js +2 -0
- package/source/services/Fable-Service-Anticipate.js +87 -0
- package/source/services/Fable-Service-DataFormat.js +16 -3
- package/source/services/Fable-Service-DataGeneration-DefaultValues.json +55 -0
- package/source/services/Fable-Service-DataGeneration.js +66 -0
- package/source/services/Fable-Service-FilePersistence-Web.js +1 -0
- package/source/services/Fable-Service-FilePersistence.js +66 -1
- package/test/Anticipate_tests.js +91 -0
- package/test/DataFormat-StringManipulation_tests.js +35 -4
- package/test/DataGeneration_tests.js +109 -0
- package/gulpfile-config.json +0 -11
- package/gulpfile-config_compatible.json +0 -11
- package/gulpfile-config_default.json +0 -11
|
@@ -16,8 +16,16 @@ class FableServiceFilePersistence extends libFableServiceBase
|
|
|
16
16
|
{
|
|
17
17
|
this.options.Mode = parseInt('0777', 8) & ~process.umask();
|
|
18
18
|
}
|
|
19
|
+
|
|
20
|
+
this.currentInputFolder = `/tmp`;
|
|
21
|
+
this.currentOutputFolder = `/tmp`;
|
|
19
22
|
}
|
|
20
23
|
|
|
24
|
+
joinPath(pPathArray)
|
|
25
|
+
{
|
|
26
|
+
return libPath.resolve(...pPathArray);
|
|
27
|
+
}
|
|
28
|
+
|
|
21
29
|
existsSync(pPath)
|
|
22
30
|
{
|
|
23
31
|
return libFS.existsSync(pPath);
|
|
@@ -30,6 +38,63 @@ class FableServiceFilePersistence extends libFableServiceBase
|
|
|
30
38
|
return fCallback(null, tmpFileExists);
|
|
31
39
|
}
|
|
32
40
|
|
|
41
|
+
writeFileSync(pFileName, pFileContent, pOptions)
|
|
42
|
+
{
|
|
43
|
+
let tmpOptions = (typeof(pOptions) === 'undefined') ? 'utf8' : pOptions;
|
|
44
|
+
libFS.writeFileSync(pFileName, pFileContent, tmpOptions);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
appendFileSync(pFileName, pAppendContent, pOptions)
|
|
48
|
+
{
|
|
49
|
+
let tmpOptions = (typeof(pOptions) === 'undefined') ? 'utf8' : pOptions;
|
|
50
|
+
libFS.appendFileSync(pFileName, pAppendContent, tmpOptions);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
writeFileSyncFromObject(pFileName, pObject)
|
|
54
|
+
{
|
|
55
|
+
this.writeFileSync(pFileName, JSON.stringify(pObject, null, 4));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
writeFileSyncFromArray(pFileName, pFileArray)
|
|
59
|
+
{
|
|
60
|
+
if (!Array.isArray(pFileArray))
|
|
61
|
+
{
|
|
62
|
+
this.log.error(`File Persistence Service attempted to write ${pFileName} from array but the expected array was not an array (it was a ${typeof(pFileArray)}).`);
|
|
63
|
+
return Error('Attempted to write ${pFileName} from array but the expected array was not an array (it was a ${typeof(pFileArray)}).');
|
|
64
|
+
}
|
|
65
|
+
else
|
|
66
|
+
{
|
|
67
|
+
for (let i = 0; i < pFileArray.length; i++)
|
|
68
|
+
{
|
|
69
|
+
this.appendFileSync(pFileName, `${pFileArray[i]}\n`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Default folder behaviors
|
|
75
|
+
|
|
76
|
+
getDefaultOutputPath(pFileName)
|
|
77
|
+
{
|
|
78
|
+
return libPath.join(this.currentOutputFolder, pFileName);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
dataFolderWriteSync(pFileName, pFileContent)
|
|
82
|
+
{
|
|
83
|
+
return this.writeFileSync(this.getDefaultOutputPath(pFileName), pFileContent);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
dataFolderWriteSyncFromObject(pFileName, pObject)
|
|
87
|
+
{
|
|
88
|
+
return this.writeFileSyncFromObject(this.getDefaultOutputPath(pFileName), pObject);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
dataFolderWriteSyncFromArray(pFileName, pFileArray)
|
|
92
|
+
{
|
|
93
|
+
return this.writeFileSyncFromArray(this.getDefaultOutputPath(pFileName), pFileArray);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Folder management
|
|
97
|
+
|
|
33
98
|
makeFolderRecursive (pParameters, fCallback)
|
|
34
99
|
{
|
|
35
100
|
let tmpParameters = pParameters;
|
|
@@ -88,7 +153,7 @@ class FableServiceFilePersistence extends libFableServiceBase
|
|
|
88
153
|
return true;
|
|
89
154
|
}
|
|
90
155
|
|
|
91
|
-
// Check if the path exists
|
|
156
|
+
// Check if the path exists (and is a folder)
|
|
92
157
|
libFS.open(tmpParameters.CurrentPath + libPath.sep + tmpParameters.ActualPathParts[tmpParameters.CurrentPathIndex], 'r',
|
|
93
158
|
function(pError, pFileDescriptor)
|
|
94
159
|
{
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the Anticipate pattern
|
|
3
|
+
* @author Steven Velozo <steven@velozo.com>
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const libFable = require('../source/Fable.js');
|
|
7
|
+
|
|
8
|
+
const Chai = require("chai");
|
|
9
|
+
const Expect = Chai.expect;
|
|
10
|
+
|
|
11
|
+
suite
|
|
12
|
+
(
|
|
13
|
+
'Fable Anticipate',
|
|
14
|
+
() =>
|
|
15
|
+
{
|
|
16
|
+
setup(() => { });
|
|
17
|
+
|
|
18
|
+
suite
|
|
19
|
+
(
|
|
20
|
+
'Basic Asynchronous Operations',
|
|
21
|
+
function ()
|
|
22
|
+
{
|
|
23
|
+
test
|
|
24
|
+
(
|
|
25
|
+
'Setup some async calls and make sure they run',
|
|
26
|
+
function (fTestComplete)
|
|
27
|
+
{
|
|
28
|
+
let testFable = new libFable();
|
|
29
|
+
let tmpAnticipate = testFable.serviceManager.instantiateServiceProvider('Anticipate');
|
|
30
|
+
tmpAnticipate.anticipate(function (fCallback)
|
|
31
|
+
{
|
|
32
|
+
testFable.log.info('Operation First test timeout entered...');
|
|
33
|
+
setTimeout(function ()
|
|
34
|
+
{
|
|
35
|
+
testFable.log.info(`Operation First test timeout done!`);
|
|
36
|
+
fCallback();
|
|
37
|
+
}, 500);
|
|
38
|
+
});
|
|
39
|
+
tmpAnticipate.anticipate(function (fCallback)
|
|
40
|
+
{
|
|
41
|
+
testFable.log.info('Operation Second test timeout entered...');
|
|
42
|
+
setTimeout(function ()
|
|
43
|
+
{
|
|
44
|
+
testFable.log.info(`Operation Second test timeout done!`);
|
|
45
|
+
fCallback();
|
|
46
|
+
}, 50);
|
|
47
|
+
});
|
|
48
|
+
tmpAnticipate.wait(function (pError)
|
|
49
|
+
{
|
|
50
|
+
testFable.log.info(`Wait 1 completed: ${pError}`)
|
|
51
|
+
return fTestComplete();
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
test
|
|
56
|
+
(
|
|
57
|
+
'Setup some async calls to run together and make sure they run',
|
|
58
|
+
function (fTestComplete)
|
|
59
|
+
{
|
|
60
|
+
let testFable = new libFable();
|
|
61
|
+
let tmpAnticipate = testFable.serviceManager.instantiateServiceProvider('Anticipate');
|
|
62
|
+
tmpAnticipate.maxOperations = 2;
|
|
63
|
+
tmpAnticipate.anticipate(function (fCallback)
|
|
64
|
+
{
|
|
65
|
+
testFable.log.info('Operation First test timeout entered...');
|
|
66
|
+
setTimeout(function ()
|
|
67
|
+
{
|
|
68
|
+
testFable.log.info(`Operation First test timeout done!`);
|
|
69
|
+
fCallback();
|
|
70
|
+
}, 500);
|
|
71
|
+
});
|
|
72
|
+
tmpAnticipate.anticipate(function (fCallback)
|
|
73
|
+
{
|
|
74
|
+
testFable.log.info('Operation Second test timeout entered...');
|
|
75
|
+
setTimeout(function ()
|
|
76
|
+
{
|
|
77
|
+
testFable.log.info(`Operation Second test timeout done!`);
|
|
78
|
+
fCallback();
|
|
79
|
+
}, 50);
|
|
80
|
+
});
|
|
81
|
+
tmpAnticipate.wait(function (pError)
|
|
82
|
+
{
|
|
83
|
+
testFable.log.info(`Wait 1 completed: ${pError}`)
|
|
84
|
+
return fTestComplete();
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
);
|
|
@@ -62,6 +62,37 @@ suite
|
|
|
62
62
|
return fTestComplete();
|
|
63
63
|
}
|
|
64
64
|
)
|
|
65
|
+
test
|
|
66
|
+
(
|
|
67
|
+
'Remove non-alpha characters from a string',
|
|
68
|
+
(fTestComplete)=>
|
|
69
|
+
{
|
|
70
|
+
let testFable = new libFable({LogStreams: false});
|
|
71
|
+
let _DataFormat = testFable.defaultServices.DataFormat;
|
|
72
|
+
Expect(_DataFormat.cleanNonAlphaCharacters('Dogs'))
|
|
73
|
+
.to.equal('Dogs');
|
|
74
|
+
Expect(_DataFormat.cleanNonAlphaCharacters('Dogs1'))
|
|
75
|
+
.to.equal('Dogs');
|
|
76
|
+
Expect(_DataFormat.cleanNonAlphaCharacters('Dogs-with-guns 12321'))
|
|
77
|
+
.to.equal('Dogswithguns');
|
|
78
|
+
return fTestComplete();
|
|
79
|
+
}
|
|
80
|
+
)
|
|
81
|
+
test
|
|
82
|
+
(
|
|
83
|
+
'Capitalize each word in a string',
|
|
84
|
+
(fTestComplete)=>
|
|
85
|
+
{
|
|
86
|
+
let testFable = new libFable({LogStreams: false});
|
|
87
|
+
let _DataFormat = testFable.defaultServices.DataFormat;
|
|
88
|
+
Expect(_DataFormat.capitalizeEachWord('Dogs-with-guns 12321'))
|
|
89
|
+
.to.equal('Dogs-With-Guns 12321');
|
|
90
|
+
Expect(_DataFormat.cleanNonAlphaCharacters(_DataFormat.capitalizeEachWord('meadow-endpoints')))
|
|
91
|
+
.to.equal('MeadowEndpoints');
|
|
92
|
+
return fTestComplete();
|
|
93
|
+
}
|
|
94
|
+
)
|
|
95
|
+
|
|
65
96
|
test
|
|
66
97
|
(
|
|
67
98
|
'Clean wrapping characters from a valid enclosure.',
|
|
@@ -205,15 +236,15 @@ suite
|
|
|
205
236
|
.to.equal('Dogs');
|
|
206
237
|
Expect(_DataFormat
|
|
207
238
|
.cleanNonAlphaCharacters('Dogs are cool'))
|
|
208
|
-
.to.equal('
|
|
239
|
+
.to.equal('Dogsarecool');
|
|
209
240
|
Expect(_DataFormat
|
|
210
241
|
.cleanNonAlphaCharacters('Dogs are cool!'))
|
|
211
|
-
.to.equal('
|
|
242
|
+
.to.equal('Dogsarecool');
|
|
212
243
|
// Test cleaning with no character
|
|
213
|
-
_DataFormat._Value_Clean_formatterCleanNonAlpha = '';
|
|
244
|
+
_DataFormat._Value_Clean_formatterCleanNonAlpha = '_';
|
|
214
245
|
Expect(_DataFormat
|
|
215
246
|
.cleanNonAlphaCharacters('Dogs are cool!'))
|
|
216
|
-
.to.equal('
|
|
247
|
+
.to.equal('Dogs_are_cool_');
|
|
217
248
|
return fTestComplete();
|
|
218
249
|
}
|
|
219
250
|
);
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the Anticipate pattern
|
|
3
|
+
* @author Steven Velozo <steven@velozo.com>
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const libFable = require('../source/Fable.js');
|
|
7
|
+
|
|
8
|
+
const Chai = require("chai");
|
|
9
|
+
const Expect = Chai.expect;
|
|
10
|
+
|
|
11
|
+
suite
|
|
12
|
+
(
|
|
13
|
+
'Fable Data Generation',
|
|
14
|
+
() =>
|
|
15
|
+
{
|
|
16
|
+
setup(() => { });
|
|
17
|
+
|
|
18
|
+
suite
|
|
19
|
+
(
|
|
20
|
+
'Generate random numbers and strings',
|
|
21
|
+
function ()
|
|
22
|
+
{
|
|
23
|
+
test
|
|
24
|
+
(
|
|
25
|
+
'Just get me a random number',
|
|
26
|
+
function (fTestComplete)
|
|
27
|
+
{
|
|
28
|
+
let testFable = new libFable();
|
|
29
|
+
let tmpDataGeneration = testFable.serviceManager.instantiateServiceProvider('DataGeneration');
|
|
30
|
+
Expect(tmpDataGeneration.randomIntegerUpTo(100)).to.be.within(0, 99);
|
|
31
|
+
return fTestComplete();
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
test
|
|
35
|
+
(
|
|
36
|
+
'How about a random number string!',
|
|
37
|
+
function (fTestComplete)
|
|
38
|
+
{
|
|
39
|
+
let testFable = new libFable();
|
|
40
|
+
let tmpDataGeneration = testFable.serviceManager.instantiateServiceProvider('DataGeneration');
|
|
41
|
+
Expect(tmpDataGeneration.randomNumericString()).to.be.a('string');
|
|
42
|
+
Expect(tmpDataGeneration.randomNumericString().length).to.equal(10);
|
|
43
|
+
return fTestComplete();
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
test
|
|
47
|
+
(
|
|
48
|
+
'How about a random color?',
|
|
49
|
+
function (fTestComplete)
|
|
50
|
+
{
|
|
51
|
+
let testFable = new libFable();
|
|
52
|
+
let tmpDataGeneration = testFable.serviceManager.instantiateServiceProvider('DataGeneration');
|
|
53
|
+
testFable.log.info(`Random color: ${tmpDataGeneration.randomColor()}`);
|
|
54
|
+
Expect(tmpDataGeneration.randomColor()).to.be.a('string');
|
|
55
|
+
return fTestComplete();
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
test
|
|
59
|
+
(
|
|
60
|
+
'DayOfWeek',
|
|
61
|
+
function (fTestComplete)
|
|
62
|
+
{
|
|
63
|
+
let testFable = new libFable();
|
|
64
|
+
let tmpDataGeneration = testFable.serviceManager.instantiateServiceProvider('DataGeneration');
|
|
65
|
+
testFable.log.info(`Random Day of Week: ${tmpDataGeneration.randomDayOfWeek()}`);
|
|
66
|
+
Expect(tmpDataGeneration.randomDayOfWeek()).to.be.a('string');
|
|
67
|
+
return fTestComplete();
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
test
|
|
71
|
+
(
|
|
72
|
+
'Month',
|
|
73
|
+
function (fTestComplete)
|
|
74
|
+
{
|
|
75
|
+
let testFable = new libFable();
|
|
76
|
+
let tmpDataGeneration = testFable.serviceManager.instantiateServiceProvider('DataGeneration');
|
|
77
|
+
testFable.log.info(`Random Month: ${tmpDataGeneration.randomMonth()}`);
|
|
78
|
+
Expect(tmpDataGeneration.randomMonth()).to.be.a('string');
|
|
79
|
+
return fTestComplete();
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
test
|
|
83
|
+
(
|
|
84
|
+
'First name',
|
|
85
|
+
function (fTestComplete)
|
|
86
|
+
{
|
|
87
|
+
let testFable = new libFable();
|
|
88
|
+
let tmpDataGeneration = testFable.serviceManager.instantiateServiceProvider('DataGeneration');
|
|
89
|
+
testFable.log.info(`Random Name: ${tmpDataGeneration.randomName()}`);
|
|
90
|
+
Expect(tmpDataGeneration.randomName()).to.be.a('string');
|
|
91
|
+
return fTestComplete();
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
test
|
|
95
|
+
(
|
|
96
|
+
'Surname',
|
|
97
|
+
function (fTestComplete)
|
|
98
|
+
{
|
|
99
|
+
let testFable = new libFable();
|
|
100
|
+
let tmpDataGeneration = testFable.serviceManager.instantiateServiceProvider('DataGeneration');
|
|
101
|
+
testFable.log.info(`Random Surname: ${tmpDataGeneration.randomSurname()}`);
|
|
102
|
+
Expect(tmpDataGeneration.randomSurname()).to.be.a('string');
|
|
103
|
+
return fTestComplete();
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
);
|
package/gulpfile-config.json
DELETED