fable 3.0.20 → 3.0.21

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.0.20",
3
+ "version": "3.0.21",
4
4
  "description": "An entity behavior management and API bundling library.",
5
5
  "main": "source/Fable.js",
6
6
  "scripts": {
@@ -63,6 +63,7 @@
63
63
  "dependencies": {
64
64
  "async.eachlimit": "^0.5.2",
65
65
  "async.waterfall": "^0.5.2",
66
+ "data-arithmatic": "^1.0.3",
66
67
  "fable-log": "^3.0.6",
67
68
  "fable-settings": "^3.0.3",
68
69
  "fable-uuid": "^3.0.2"
@@ -0,0 +1,16 @@
1
+ const libFableServiceBase = require('./Fable-ServiceProviderBase.js');
2
+ const libDataArithmatic = require('data-arithmatic');
3
+
4
+ class FableServiceDataArithmatic extends libFableServiceBase
5
+ {
6
+ constructor(pFable, pOptions, pServiceHash)
7
+ {
8
+ super(pFable, pOptions, pServiceHash);
9
+
10
+ this.serviceType = 'DataArithmatic';
11
+
12
+ this._DataArithmaticLibrary = new libDataArithmatic();
13
+ }
14
+ }
15
+
16
+ module.exports = FableServiceDataArithmatic;
@@ -1,12 +1,24 @@
1
+ const libFableServiceBase = require('./Fable-ServiceProviderBase.js');
2
+
3
+
1
4
  // TODO: These are still pretty big -- consider the smaller polyfills
2
5
  const libAsyncWaterfall = require('async.waterfall');
3
6
  const libAsyncEachLimit = require('async.eachlimit');
4
7
 
5
- class FableUtility
8
+ class FableServiceUtility extends libFableServiceBase
6
9
  {
7
- constructor(pFable)
10
+ // Underscore and lodash have a behavior, _.template, which compiles a
11
+ // string-based template with code snippets into simple executable pieces,
12
+ // with the added twist of returning a precompiled function ready to go.
13
+ //
14
+ // NOTE: This does not implement underscore escape expressions
15
+ // NOTE: This does not implement underscore magic browser variable assignment
16
+ //
17
+ // This is an implementation of that.
18
+ // TODO: Make this use precedent, add configuration, add debugging.
19
+ constructor(pFable, pOptions, pServiceHash)
8
20
  {
9
- this.fable = pFable;
21
+ super(pFable, pOptions, pServiceHash);
10
22
 
11
23
  this.templates = {};
12
24
 
@@ -68,4 +80,4 @@ class FableUtility
68
80
  }
69
81
  }
70
82
 
71
- module.exports = FableUtility;
83
+ module.exports = FableServiceUtility;
package/source/Fable.js CHANGED
@@ -7,10 +7,11 @@ const libFableSettings = require('fable-settings');
7
7
  const libFableUUID = require('fable-uuid');
8
8
  const libFableLog = require('fable-log');
9
9
 
10
- const libFableUtility = require('./Fable-Utility.js');
11
10
  const libFableServiceManager = require('./Fable-ServiceManager.js');
12
11
 
12
+ const libFableServiceDataArithmatic = require('./Fable-Service-DataArithmatic.js');
13
13
  const libFableServiceTemplate = require('./Fable-Service-Template.js');
14
+ const libFableServiceUtility = require('./Fable-Service-Utility.js');
14
15
 
15
16
  const libFableOperation = require('./Fable-Operation.js');
16
17
 
@@ -28,9 +29,6 @@ class Fable
28
29
  this.log = new libFableLog(this.settingsManager.settings);
29
30
  this.log.initialize();
30
31
 
31
- // Built-in utility belt functions
32
- this.Utility = new libFableUtility(this);
33
-
34
32
  // Built-in dependencies
35
33
  this.Dependencies = (
36
34
  {
@@ -42,8 +40,20 @@ class Fable
42
40
 
43
41
  this.serviceManager = new libFableServiceManager(this);
44
42
 
43
+ // Initialize and instantiate the default baked-in Data Arithmatic service
44
+ this.serviceManager.addServiceType('DataArithmatic', libFableServiceDataArithmatic);
45
+ this.fable.serviceManager.instantiateServiceProvider('DataArithmatic', {}, 'Default-Service-DataArithmatic');
46
+ // This service is passing through the data arithmatic library
47
+ this.DataArithmatic = this.serviceManager.defaultServices.DataArithmatic._DataArithmaticLibrary;
48
+
49
+ // Initialize the template service
45
50
  this.serviceManager.addServiceType('Template', libFableServiceTemplate);
46
51
 
52
+ // Initialize and instantiate the default baked-in Utility service
53
+ this.serviceManager.addServiceType('Utility', libFableServiceUtility)
54
+ this.fable.serviceManager.instantiateServiceProvider('Utility', {}, 'Default-Service-Utility');
55
+ this.Utility = this.serviceManager.defaultServices.Utility;
56
+
47
57
  this.services = this.serviceManager.services;
48
58
  this.defaultServices = this.serviceManager.defaultServices;
49
59
  }
@@ -0,0 +1,223 @@
1
+ /**
2
+ * Unit tests for Fable's DataArithmatic service
3
+ *
4
+ * @license MIT
5
+ *
6
+ * @author Steven Velozo <steven@velozo.com>
7
+ */
8
+
9
+ var libFable = require('../source/Fable.js');
10
+
11
+ var Chai = require("chai");
12
+ var Expect = Chai.expect;
13
+
14
+ suite
15
+ (
16
+ 'DataArithmatic String',
17
+ function()
18
+ {
19
+ setup (()=> {} );
20
+
21
+ suite
22
+ (
23
+ 'Manipulate Strings',
24
+ ()=>
25
+ {
26
+ test
27
+ (
28
+ 'Reverse a String',
29
+ (fTestComplete)=>
30
+ {
31
+ let testFable = new libFable({LogStreams: false});
32
+ let _DataArithmatic = testFable.DataArithmatic;
33
+ Expect(_DataArithmatic
34
+ .stringReverse('Dogs'))
35
+ .to.equal('sgoD');
36
+ Expect(_DataArithmatic
37
+ .stringReverse('Florence and the Machine'))
38
+ .to.equal('enihcaM eht dna ecnerolF');
39
+ return fTestComplete();
40
+ }
41
+ )
42
+ test
43
+ (
44
+ 'Insecure String Hash',
45
+ (fTestComplete)=>
46
+ {
47
+ let testFable = new libFable({LogStreams: false});
48
+ let _DataArithmatic = testFable.DataArithmatic;
49
+ Expect(_DataArithmatic
50
+ .insecureStringHash('Dogs'))
51
+ .to.equal('HSH2135767');
52
+ Expect(_DataArithmatic
53
+ .insecureStringHash('Dogs1'))
54
+ .to.equal('HSH66208826');
55
+ Expect(_DataArithmatic
56
+ .insecureStringHash('This string is longer'))
57
+ .to.equal('HSH53260210');
58
+ // This repeat is intentional, to ensure stable hash generation after multiple runs.
59
+ Expect(_DataArithmatic
60
+ .insecureStringHash('Dogs'))
61
+ .to.equal('HSH2135767');
62
+ return fTestComplete();
63
+ }
64
+ )
65
+ test
66
+ (
67
+ 'Clean wrapping characters from a valid enclosure.',
68
+ (fTestComplete)=>
69
+ {
70
+ let testFable = new libFable({LogStreams: false});
71
+ let _DataArithmatic = testFable.DataArithmatic;
72
+ // Test the enclosure cleaning function
73
+ Expect(_DataArithmatic
74
+ .cleanEnclosureWrapCharacters('`', '`Dogs`'))
75
+ .to.equal('Dogs');
76
+ // Tests a cleaning where the enclosure is not wrapped with the expected character
77
+ Expect(_DataArithmatic
78
+ .cleanEnclosureWrapCharacters('"', '`Cats`'))
79
+ .to.equal('`Cats`');
80
+ // Tests a cleaning where the enclosure is not wrapped with the expected character
81
+ Expect(_DataArithmatic
82
+ .cleanEnclosureWrapCharacters('"', '"Dogs"'))
83
+ .to.equal('Dogs');
84
+ // Test cleaning an enclosure with multiple enclosures of the same type which are expected to stay intact
85
+ Expect(_DataArithmatic
86
+ .cleanEnclosureWrapCharacters('[', '[Array[with]weird other] Dogs in it['))
87
+ .to.equal('Array[with]weird other] Dogs in it');
88
+ // Test cleaning a string where the enclosure character is on one side but not the other
89
+ Expect(_DataArithmatic
90
+ .cleanEnclosureWrapCharacters('"', '"Dogs'))
91
+ .to.equal('"Dogs');
92
+ // Test cleaning a string where the enclosure character is on one side but not the other
93
+ Expect(_DataArithmatic
94
+ .cleanEnclosureWrapCharacters('"', 'Dogs"'))
95
+ .to.equal('Dogs"');
96
+ return fTestComplete();
97
+ }
98
+ );
99
+ test
100
+ (
101
+ 'Test if a string starts with a given substring - Javascript Engine startsWith',
102
+ (fTestComplete)=>
103
+ {
104
+ let testFable = new libFable({LogStreams: false});
105
+ let _DataArithmatic = testFable.DataArithmatic;
106
+ Expect(_DataArithmatic
107
+ .stringStartsWith('Dogs', 'Do'))
108
+ .to.equal(true);
109
+ Expect(_DataArithmatic
110
+ .stringStartsWith('Bats', 'Bats'))
111
+ .to.equal(true);
112
+ Expect(_DataArithmatic
113
+ .stringStartsWith('Dogs', 'Dogs are cool'))
114
+ .to.equal(false);
115
+ Expect(_DataArithmatic
116
+ .stringStartsWith('Dogs', 'Cats'))
117
+ .to.equal(false);
118
+ return fTestComplete();
119
+ }
120
+ );
121
+ test
122
+ (
123
+ 'Test if a string starts with a given substring - Internal startsWith',
124
+ (fTestComplete)=>
125
+ {
126
+ let testFable = new libFable({LogStreams: false});
127
+ let _DataArithmatic = testFable.DataArithmatic;
128
+ _DataArithmatic._UseEngineStringStartsWith = false;
129
+ Expect(_DataArithmatic
130
+ .stringStartsWith('Dogs', 'Do'))
131
+ .to.equal(true);
132
+ Expect(_DataArithmatic
133
+ .stringStartsWith('Bats', 'Bats'))
134
+ .to.equal(true);
135
+ Expect(_DataArithmatic
136
+ .stringStartsWith('Dogs', 'Dogs are cool'))
137
+ .to.equal(false);
138
+ Expect(_DataArithmatic
139
+ .stringStartsWith('Dogs', 'Cats'))
140
+ .to.equal(false);
141
+ return fTestComplete();
142
+ }
143
+ );
144
+ test
145
+ (
146
+ 'Test if a string ends with a given substring - Javascript Engine endsWith',
147
+ (fTestComplete)=>
148
+ {
149
+ let testFable = new libFable({LogStreams: false});
150
+ let _DataArithmatic = testFable.DataArithmatic;
151
+ Expect(_DataArithmatic
152
+ .stringEndsWith('Dogs', 'gs'))
153
+ .to.equal(true);
154
+ Expect(_DataArithmatic
155
+ .stringEndsWith('Bats', 'Bats'))
156
+ .to.equal(true);
157
+ Expect(_DataArithmatic
158
+ .stringEndsWith('Dogs', 'Dogs are cool'))
159
+ .to.equal(false);
160
+ Expect(_DataArithmatic
161
+ .stringEndsWith('Dogs', 'Cats'))
162
+ .to.equal(false);
163
+ return fTestComplete();
164
+ }
165
+ );
166
+ test
167
+ (
168
+ 'Test if a string ends with a given substring - Internal endsWith',
169
+ (fTestComplete)=>
170
+ {
171
+ let testFable = new libFable({LogStreams: false});
172
+ let _DataArithmatic = testFable.DataArithmatic;
173
+ _DataArithmatic._UseEngineStringEndsWith = false;
174
+ Expect(_DataArithmatic
175
+ .stringEndsWith('Dogs', 'gs'))
176
+ .to.equal(true);
177
+ Expect(_DataArithmatic
178
+ .stringEndsWith('Bats', 'Bats'))
179
+ .to.equal(true);
180
+ Expect(_DataArithmatic
181
+ .stringEndsWith('Dogs', 'Dogs are cool'))
182
+ .to.equal(false);
183
+ // We should be able to tell it a midpoint to "end" the string at
184
+ Expect(_DataArithmatic
185
+ .stringEndsWith('Start from a median point', 'median', 19))
186
+ .to.equal(true);
187
+ Expect(_DataArithmatic
188
+ .stringEndsWith('Start from a median point', 'median', 20))
189
+ .to.equal(false);
190
+ Expect(_DataArithmatic
191
+ .stringEndsWith('Dogs', 'Cats'))
192
+ .to.equal(false);
193
+ return fTestComplete();
194
+ }
195
+ );
196
+ test
197
+ (
198
+ 'Test cleaning nonalpha characters from a string',
199
+ (fTestComplete)=>
200
+ {
201
+ let testFable = new libFable({LogStreams: false});
202
+ let _DataArithmatic = testFable.DataArithmatic;
203
+ Expect(_DataArithmatic
204
+ .cleanNonAlphaCharacters('Dogs'))
205
+ .to.equal('Dogs');
206
+ Expect(_DataArithmatic
207
+ .cleanNonAlphaCharacters('Dogs are cool'))
208
+ .to.equal('Dogs_are_cool');
209
+ Expect(_DataArithmatic
210
+ .cleanNonAlphaCharacters('Dogs are cool!'))
211
+ .to.equal('Dogs_are_cool_');
212
+ // Test cleaning with no character
213
+ _DataArithmatic._Value_Clean_formatterCleanNonAlpha = '';
214
+ Expect(_DataArithmatic
215
+ .cleanNonAlphaCharacters('Dogs are cool!'))
216
+ .to.equal('Dogsarecool');
217
+ return fTestComplete();
218
+ }
219
+ );
220
+ }
221
+ );
222
+ }
223
+ );
@@ -10,7 +10,6 @@ var libFable = require('../source/Fable.js');
10
10
 
11
11
  var Chai = require("chai");
12
12
  var Expect = Chai.expect;
13
- var Assert = Chai.assert;
14
13
 
15
14
  suite
16
15
  (