fable 3.0.120 → 3.0.123
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.compatible.js +337 -112
- package/dist/fable.compatible.min.js +2 -2
- package/dist/fable.compatible.min.js.map +1 -1
- package/dist/fable.js +327 -102
- package/dist/fable.min.js +2 -2
- package/dist/fable.min.js.map +1 -1
- package/package.json +2 -2
- package/source/services/Fable-Service-DataFormat.js +172 -0
- package/test/DataFormat-StringTokenization_tests.js +81 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fable",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.123",
|
|
4
4
|
"description": "Anentity behavior management and API bundling library.",
|
|
5
5
|
"main": "source/Fable.js",
|
|
6
6
|
"scripts": {
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"fable-serviceproviderbase": "^3.0.13",
|
|
65
65
|
"fable-settings": "^3.0.9",
|
|
66
66
|
"fable-uuid": "^3.0.6",
|
|
67
|
-
"manyfest": "^1.0.
|
|
67
|
+
"manyfest": "^1.0.31",
|
|
68
68
|
"simple-get": "^4.0.1"
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -481,6 +481,178 @@ class DataFormat extends libFableServiceProviderBase
|
|
|
481
481
|
return pString.substring(tmpStringSplitLocation + pMatch.length);
|
|
482
482
|
}
|
|
483
483
|
|
|
484
|
+
/**
|
|
485
|
+
* Count the number of segments in a string, respecting enclosures
|
|
486
|
+
*
|
|
487
|
+
* @param {string} pString
|
|
488
|
+
* @param {string} pSeparator
|
|
489
|
+
* @param {object} pEnclosureStartSymbolMap
|
|
490
|
+
* @param {object} pEnclosureEndSymbolMap
|
|
491
|
+
* @returns the count of segments in the string as a number
|
|
492
|
+
*/
|
|
493
|
+
stringCountSegments(pString, pSeparator, pEnclosureStartSymbolMap, pEnclosureEndSymbolMap)
|
|
494
|
+
{
|
|
495
|
+
let tmpString = (typeof(pString) == 'string') ? pString : '';
|
|
496
|
+
|
|
497
|
+
let tmpSeparator = (typeof(pSeparator) == 'string') ? pSeparator : '.';
|
|
498
|
+
|
|
499
|
+
let tmpEnclosureStartSymbolMap = (typeof(pEnclosureStartSymbolMap) == 'object') ? pEnclosureStart : { '{': 0, '[': 1, '(': 2 };
|
|
500
|
+
let tmpEnclosureEndSymbolMap = (typeof(pEnclosureEndSymbolMap) == 'object') ? pEnclosureEnd : { '}': 0, ']': 1, ')': 2 };
|
|
501
|
+
|
|
502
|
+
if (pString.length < 1)
|
|
503
|
+
{
|
|
504
|
+
return 0;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
let tmpSegmentCount = 1;
|
|
508
|
+
let tmpEnclosureStack = [];
|
|
509
|
+
|
|
510
|
+
for (let i = 0; i < tmpString.length; i++)
|
|
511
|
+
{
|
|
512
|
+
// IF This is the start of a segment
|
|
513
|
+
if ((tmpString[i] == tmpSeparator)
|
|
514
|
+
// AND we are not in a nested portion of the string
|
|
515
|
+
&& (tmpEnclosureStack.length == 0))
|
|
516
|
+
{
|
|
517
|
+
// Increment the segment count
|
|
518
|
+
tmpSegmentCount++;
|
|
519
|
+
}
|
|
520
|
+
// IF This is the start of an enclosure
|
|
521
|
+
else if (tmpEnclosureStartSymbolMap.hasOwnProperty(tmpString[i]))
|
|
522
|
+
{
|
|
523
|
+
// Add it to the stack!
|
|
524
|
+
tmpEnclosureStack.push(tmpEnclosureStartSymbolMap[tmpString[i]]);
|
|
525
|
+
}
|
|
526
|
+
// IF This is the end of an enclosure
|
|
527
|
+
else if (tmpEnclosureEndSymbolMap.hasOwnProperty(tmpString[i])
|
|
528
|
+
// AND it matches the current nest level symbol
|
|
529
|
+
&& tmpEnclosureEndSymbolMap[tmpString[i]] == tmpEnclosureStack[tmpEnclosureStack.length - 1])
|
|
530
|
+
{
|
|
531
|
+
// Pop it off the stack!
|
|
532
|
+
tmpEnclosureStack.pop();
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
return tmpSegmentCount;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Get all segments in a string, respecting enclosures
|
|
541
|
+
*
|
|
542
|
+
* @param {string} pString
|
|
543
|
+
* @param {string} pSeparator
|
|
544
|
+
* @param {object} pEnclosureStartSymbolMap
|
|
545
|
+
* @param {object} pEnclosureEndSymbolMap
|
|
546
|
+
* @returns the first segment in the string as a string
|
|
547
|
+
*/
|
|
548
|
+
stringGetSegments(pString, pSeparator, pEnclosureStartSymbolMap, pEnclosureEndSymbolMap)
|
|
549
|
+
{
|
|
550
|
+
let tmpString = (typeof(pString) == 'string') ? pString : '';
|
|
551
|
+
|
|
552
|
+
let tmpSeparator = (typeof(pSeparator) == 'string') ? pSeparator : '.';
|
|
553
|
+
|
|
554
|
+
let tmpEnclosureStartSymbolMap = (typeof(pEnclosureStartSymbolMap) == 'object') ? pEnclosureStart : { '{': 0, '[': 1, '(': 2 };
|
|
555
|
+
let tmpEnclosureEndSymbolMap = (typeof(pEnclosureEndSymbolMap) == 'object') ? pEnclosureEnd : { '}': 0, ']': 1, ')': 2 };
|
|
556
|
+
|
|
557
|
+
let tmpCurrentSegmentStart = 0;
|
|
558
|
+
let tmpSegmentList = [];
|
|
559
|
+
|
|
560
|
+
if (pString.length < 1)
|
|
561
|
+
{
|
|
562
|
+
return tmpSegmentList;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
let tmpEnclosureStack = [];
|
|
566
|
+
|
|
567
|
+
for (let i = 0; i < tmpString.length; i++)
|
|
568
|
+
{
|
|
569
|
+
// IF This is the start of a segment
|
|
570
|
+
if ((tmpString[i] == tmpSeparator)
|
|
571
|
+
// AND we are not in a nested portion of the string
|
|
572
|
+
&& (tmpEnclosureStack.length == 0))
|
|
573
|
+
{
|
|
574
|
+
// Return the segment
|
|
575
|
+
tmpSegmentList.push(tmpString.substring(tmpCurrentSegmentStart, i));
|
|
576
|
+
tmpCurrentSegmentStart = i+1;
|
|
577
|
+
}
|
|
578
|
+
// IF This is the start of an enclosure
|
|
579
|
+
else if (tmpEnclosureStartSymbolMap.hasOwnProperty(tmpString[i]))
|
|
580
|
+
{
|
|
581
|
+
// Add it to the stack!
|
|
582
|
+
tmpEnclosureStack.push(tmpEnclosureStartSymbolMap[tmpString[i]]);
|
|
583
|
+
}
|
|
584
|
+
// IF This is the end of an enclosure
|
|
585
|
+
else if (tmpEnclosureEndSymbolMap.hasOwnProperty(tmpString[i])
|
|
586
|
+
// AND it matches the current nest level symbol
|
|
587
|
+
&& tmpEnclosureEndSymbolMap[tmpString[i]] == tmpEnclosureStack[tmpEnclosureStack.length - 1])
|
|
588
|
+
{
|
|
589
|
+
// Pop it off the stack!
|
|
590
|
+
tmpEnclosureStack.pop();
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
if (tmpCurrentSegmentStart < tmpString.length)
|
|
595
|
+
{
|
|
596
|
+
tmpSegmentList.push(tmpString.substring(tmpCurrentSegmentStart));
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
return tmpSegmentList;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* Get the first segment in a string, respecting enclosures
|
|
604
|
+
*
|
|
605
|
+
* @param {string} pString
|
|
606
|
+
* @param {string} pSeparator
|
|
607
|
+
* @param {object} pEnclosureStartSymbolMap
|
|
608
|
+
* @param {object} pEnclosureEndSymbolMap
|
|
609
|
+
* @returns the first segment in the string as a string
|
|
610
|
+
*/
|
|
611
|
+
stringGetFirstSegment(pString, pSeparator, pEnclosureStartSymbolMap, pEnclosureEndSymbolMap)
|
|
612
|
+
{
|
|
613
|
+
let tmpString = (typeof(pString) == 'string') ? pString : '';
|
|
614
|
+
|
|
615
|
+
let tmpSeparator = (typeof(pSeparator) == 'string') ? pSeparator : '.';
|
|
616
|
+
|
|
617
|
+
let tmpEnclosureStartSymbolMap = (typeof(pEnclosureStartSymbolMap) == 'object') ? pEnclosureStart : { '{': 0, '[': 1, '(': 2 };
|
|
618
|
+
let tmpEnclosureEndSymbolMap = (typeof(pEnclosureEndSymbolMap) == 'object') ? pEnclosureEnd : { '}': 0, ']': 1, ')': 2 };
|
|
619
|
+
|
|
620
|
+
if (pString.length < 1)
|
|
621
|
+
{
|
|
622
|
+
return 0;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
let tmpEnclosureStack = [];
|
|
626
|
+
|
|
627
|
+
for (let i = 0; i < tmpString.length; i++)
|
|
628
|
+
{
|
|
629
|
+
// IF This is the start of a segment
|
|
630
|
+
if ((tmpString[i] == tmpSeparator)
|
|
631
|
+
// AND we are not in a nested portion of the string
|
|
632
|
+
&& (tmpEnclosureStack.length == 0))
|
|
633
|
+
{
|
|
634
|
+
// Return the segment
|
|
635
|
+
return tmpString.substring(0, i);
|
|
636
|
+
}
|
|
637
|
+
// IF This is the start of an enclosure
|
|
638
|
+
else if (tmpEnclosureStartSymbolMap.hasOwnProperty(tmpString[i]))
|
|
639
|
+
{
|
|
640
|
+
// Add it to the stack!
|
|
641
|
+
tmpEnclosureStack.push(tmpEnclosureStartSymbolMap[tmpString[i]]);
|
|
642
|
+
}
|
|
643
|
+
// IF This is the end of an enclosure
|
|
644
|
+
else if (tmpEnclosureEndSymbolMap.hasOwnProperty(tmpString[i])
|
|
645
|
+
// AND it matches the current nest level symbol
|
|
646
|
+
&& tmpEnclosureEndSymbolMap[tmpString[i]] == tmpEnclosureStack[tmpEnclosureStack.length - 1])
|
|
647
|
+
{
|
|
648
|
+
// Pop it off the stack!
|
|
649
|
+
tmpEnclosureStack.pop();
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
return tmpString;
|
|
654
|
+
}
|
|
655
|
+
|
|
484
656
|
/**
|
|
485
657
|
* Count the number of enclosures in a string based on the start and end characters.
|
|
486
658
|
*
|
|
@@ -126,6 +126,9 @@ suite
|
|
|
126
126
|
Expect(_DataFormat
|
|
127
127
|
.stringGetEnclosureValueByIndex('There [are (many) of these (things)', 0, '[', ']'))
|
|
128
128
|
.to.equal('are (many) of these (things)');
|
|
129
|
+
Expect(_DataFormat
|
|
130
|
+
.stringGetEnclosureValueByIndex('There (are (many) of these (things))', 0))
|
|
131
|
+
.to.equal('are (many) of these (things)');
|
|
129
132
|
return fTestComplete();
|
|
130
133
|
}
|
|
131
134
|
);
|
|
@@ -161,6 +164,84 @@ suite
|
|
|
161
164
|
return fTestComplete();
|
|
162
165
|
}
|
|
163
166
|
);
|
|
167
|
+
test
|
|
168
|
+
(
|
|
169
|
+
'Test counting segments and respecting enclosures',
|
|
170
|
+
(fTestComplete)=>
|
|
171
|
+
{
|
|
172
|
+
let testFable = new libFable({LogStreams: false});
|
|
173
|
+
let _DataFormat = testFable.services.DataFormat;
|
|
174
|
+
Expect(_DataFormat
|
|
175
|
+
.stringCountSegments('Dogs.are.cool'))
|
|
176
|
+
.to.equal(3);
|
|
177
|
+
Expect(_DataFormat
|
|
178
|
+
.stringCountSegments('Dogs.are.cool'))
|
|
179
|
+
.to.equal(3);
|
|
180
|
+
Expect(_DataFormat
|
|
181
|
+
.stringCountSegments('Dogs.are(.)cool'))
|
|
182
|
+
.to.equal(2);
|
|
183
|
+
Expect(_DataFormat
|
|
184
|
+
.stringCountSegments('Dogs.are(.[....])co.(.)ol'))
|
|
185
|
+
.to.equal(3);
|
|
186
|
+
Expect(_DataFormat
|
|
187
|
+
.stringCountSegments('Dogs.are(.[....]),co.(.)ol', ','))
|
|
188
|
+
.to.equal(2);
|
|
189
|
+
return fTestComplete();
|
|
190
|
+
}
|
|
191
|
+
);
|
|
192
|
+
test
|
|
193
|
+
(
|
|
194
|
+
'Get the first segment of a string',
|
|
195
|
+
(fTestComplete)=>
|
|
196
|
+
{
|
|
197
|
+
let testFable = new libFable({LogStreams: false});
|
|
198
|
+
let _DataFormat = testFable.services.DataFormat;
|
|
199
|
+
Expect(_DataFormat
|
|
200
|
+
.stringGetFirstSegment('Dogs.are.cool'))
|
|
201
|
+
.to.equal('Dogs');
|
|
202
|
+
Expect(_DataFormat
|
|
203
|
+
.stringGetFirstSegment('Dogs().are.cool'))
|
|
204
|
+
.to.equal('Dogs()');
|
|
205
|
+
Expect(_DataFormat
|
|
206
|
+
.stringGetFirstSegment('Dogs[This.That(),Equals(THEM)].are(.)cool'))
|
|
207
|
+
.to.equal('Dogs[This.That(),Equals(THEM)]');
|
|
208
|
+
Expect(_DataFormat
|
|
209
|
+
.stringGetFirstSegment('Dogs(.are(.[....])co.(.)ol'))
|
|
210
|
+
.to.equal('Dogs(.are(.[....])co.(.)ol');
|
|
211
|
+
Expect(_DataFormat
|
|
212
|
+
.stringGetFirstSegment('Dogs(.are(,[....])co.(.)ol', ','))
|
|
213
|
+
.to.equal('Dogs(.are(,[....])co.(.)ol');
|
|
214
|
+
Expect(_DataFormat
|
|
215
|
+
.stringGetFirstSegment('Dogs.are(,[....]),co.(.)ol', ','))
|
|
216
|
+
.to.equal('Dogs.are(,[....])');
|
|
217
|
+
return fTestComplete();
|
|
218
|
+
}
|
|
219
|
+
);
|
|
220
|
+
test
|
|
221
|
+
(
|
|
222
|
+
'Get all segments of a string',
|
|
223
|
+
(fTestComplete)=>
|
|
224
|
+
{
|
|
225
|
+
let testFable = new libFable({LogStreams: false});
|
|
226
|
+
let _DataFormat = testFable.services.DataFormat;
|
|
227
|
+
Expect(_DataFormat
|
|
228
|
+
.stringGetSegments('Dogs.are.cool')[1])
|
|
229
|
+
.to.equal('are');
|
|
230
|
+
Expect(_DataFormat
|
|
231
|
+
.stringGetSegments('Dogs().are.cool'))
|
|
232
|
+
.to.deep.equal(['Dogs()', 'are', 'cool']);
|
|
233
|
+
Expect(_DataFormat
|
|
234
|
+
.stringGetSegments('Dogs[This.That(),Equals(THEM)].are(.)cool'))
|
|
235
|
+
.to.deep.equal(['Dogs[This.That(),Equals(THEM)]', 'are(.)cool']);
|
|
236
|
+
Expect(_DataFormat
|
|
237
|
+
.stringGetSegments('Dogs(.are(.[....])co.(.)ol')[0])
|
|
238
|
+
.to.equal('Dogs(.are(.[....])co.(.)ol');
|
|
239
|
+
Expect(_DataFormat
|
|
240
|
+
.stringGetSegments('..Dogs.are(,[....]),co.(.)ol'))
|
|
241
|
+
.to.deep.equal(['','','Dogs','are(,[....]),co','(.)ol']);
|
|
242
|
+
return fTestComplete();
|
|
243
|
+
}
|
|
244
|
+
);
|
|
164
245
|
}
|
|
165
246
|
);
|
|
166
247
|
}
|