fable 3.1.10 → 3.1.12
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 +185 -166
- package/dist/fable.js.map +1 -1
- 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-DataFormat.js +110 -0
- package/source/services/Fable-Service-Math.js +3 -1
- package/test/DataFormat-StringManipulation_tests.js +53 -0
package/package.json
CHANGED
|
@@ -819,6 +819,116 @@ class DataFormat extends libFableServiceProviderBase
|
|
|
819
819
|
return tmpString;
|
|
820
820
|
}
|
|
821
821
|
|
|
822
|
+
/**
|
|
823
|
+
* Encodes a string using encodeURIComponent, returning the encoded string.
|
|
824
|
+
* If the input is not a string, returns the input unchanged.
|
|
825
|
+
*
|
|
826
|
+
* @param {string} pString - The string to encode.
|
|
827
|
+
* @returns {string|*} The encoded string, or the original input if it is not a string.
|
|
828
|
+
*/
|
|
829
|
+
stringEncodeURIComponent (pString)
|
|
830
|
+
{
|
|
831
|
+
if (typeof(pString) !== 'string')
|
|
832
|
+
{
|
|
833
|
+
return pString;
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
return encodeURIComponent(pString);
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
/**
|
|
840
|
+
* Safely decodes a URI component string using decodeURIComponent.
|
|
841
|
+
* If the input is not a string or decoding fails, returns the original input.
|
|
842
|
+
*
|
|
843
|
+
* @param {string} pString - The string to decode.
|
|
844
|
+
* @returns {string} The decoded string, or the original input if decoding fails.
|
|
845
|
+
*/
|
|
846
|
+
stringDecodeURIComponent (pString)
|
|
847
|
+
{
|
|
848
|
+
if (typeof(pString) !== 'string')
|
|
849
|
+
{
|
|
850
|
+
return pString;
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
try
|
|
854
|
+
{
|
|
855
|
+
return decodeURIComponent(pString);
|
|
856
|
+
}
|
|
857
|
+
catch (e)
|
|
858
|
+
{
|
|
859
|
+
this.fable.Log.error(`Failed to decode URI component: ${pString}`, e);
|
|
860
|
+
return pString; // Return the original string if decoding fails
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
/**
|
|
865
|
+
* Encodes a string so that it can be safely embedded in JavaScript code.
|
|
866
|
+
* Escapes special characters such as quotes, backslashes, and newlines.
|
|
867
|
+
*
|
|
868
|
+
* @param {string} pString - The input string to encode.
|
|
869
|
+
* @returns {string} The encoded string with special characters escaped.
|
|
870
|
+
*/
|
|
871
|
+
stringEncodeForJavascript (pString)
|
|
872
|
+
{
|
|
873
|
+
if (typeof(pString) !== 'string')
|
|
874
|
+
{
|
|
875
|
+
return pString;
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
return pString.replace(this._Regex_matcherJavascriptEncode, (pMatch) =>
|
|
879
|
+
{
|
|
880
|
+
switch (pMatch)
|
|
881
|
+
{
|
|
882
|
+
case '"':
|
|
883
|
+
return '\\"';
|
|
884
|
+
case '\'':
|
|
885
|
+
return '\\\'';
|
|
886
|
+
case '\\':
|
|
887
|
+
return '\\\\';
|
|
888
|
+
case '\n':
|
|
889
|
+
return '\\n';
|
|
890
|
+
case '\r':
|
|
891
|
+
return '\\r';
|
|
892
|
+
default:
|
|
893
|
+
return pMatch; // Return the original character if no encoding is needed
|
|
894
|
+
}
|
|
895
|
+
});
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
/**
|
|
899
|
+
* Decodes a JavaScript-escaped string by replacing common escape sequences
|
|
900
|
+
* (such as \" \\n \\r \\' and \\\\) with their actual character representations.
|
|
901
|
+
*
|
|
902
|
+
* @param {string} pString - The string to decode. If not a string, the input is returned as-is.
|
|
903
|
+
* @returns {string} The decoded string with escape sequences replaced, or the original input if not a string.
|
|
904
|
+
*/
|
|
905
|
+
stringDecodeForJavascript (pString)
|
|
906
|
+
{
|
|
907
|
+
if (typeof(pString) !== 'string')
|
|
908
|
+
{
|
|
909
|
+
return pString;
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
return pString.replace(this._Regex_matcherJavascriptDecode, (pMatch) =>
|
|
913
|
+
{
|
|
914
|
+
switch (pMatch)
|
|
915
|
+
{
|
|
916
|
+
case '\\"':
|
|
917
|
+
return '"';
|
|
918
|
+
case '\\\'':
|
|
919
|
+
return '\'';
|
|
920
|
+
case '\\\\':
|
|
921
|
+
return '\\';
|
|
922
|
+
case '\\n':
|
|
923
|
+
return '\n';
|
|
924
|
+
case '\\r':
|
|
925
|
+
return '\r';
|
|
926
|
+
default:
|
|
927
|
+
return pMatch; // Return the original character if no decoding is needed
|
|
928
|
+
}
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
|
|
822
932
|
/**
|
|
823
933
|
* Count the number of enclosures in a string based on the start and end characters.
|
|
824
934
|
*
|
|
@@ -61,7 +61,9 @@ class FableServiceMath extends libFableServiceBase
|
|
|
61
61
|
}
|
|
62
62
|
catch (pError)
|
|
63
63
|
{
|
|
64
|
-
|
|
64
|
+
// TODO: This seems more correct -- we can add a silent or noisy parameter if we want this to export.
|
|
65
|
+
// Reason: Currently this is absolutely obliterating logs in the data integrations from bad data sources.
|
|
66
|
+
//this.log.warn(`Error parsing number (type ${typeof (pValue)}): ${pError}`);
|
|
65
67
|
tmpNumber = (typeof (pNonNumberValue) === 'undefined') ? "0.0" : pNonNumberValue;
|
|
66
68
|
}
|
|
67
69
|
|
|
@@ -79,6 +79,59 @@ suite
|
|
|
79
79
|
}
|
|
80
80
|
)
|
|
81
81
|
test
|
|
82
|
+
(
|
|
83
|
+
'Encode and decode URI string components',
|
|
84
|
+
(fTestComplete)=>
|
|
85
|
+
{
|
|
86
|
+
let testFable = new libFable({LogStreams: false});
|
|
87
|
+
let _DataFormat = testFable.services.DataFormat;
|
|
88
|
+
Expect(_DataFormat.stringEncodeURIComponent('Dogs with guns'))
|
|
89
|
+
.to.equal('Dogs%20with%20guns');
|
|
90
|
+
Expect(_DataFormat.stringDecodeURIComponent('Dogs%20with%20guns'))
|
|
91
|
+
.to.equal('Dogs with guns');
|
|
92
|
+
Expect(_DataFormat.stringEncodeURIComponent('Dogs with guns & cats'))
|
|
93
|
+
.to.equal('Dogs%20with%20guns%20%26%20cats');
|
|
94
|
+
Expect(_DataFormat.stringDecodeURIComponent('Dogs%20with%20guns%20%26%20cats'))
|
|
95
|
+
.to.equal('Dogs with guns & cats');
|
|
96
|
+
Expect(_DataFormat.stringEncodeURIComponent('Dogs with guns & cats 12321'))
|
|
97
|
+
.to.equal('Dogs%20with%20guns%20%26%20cats%2012321');
|
|
98
|
+
Expect(_DataFormat.stringDecodeURIComponent('Dogs%20with%20guns%20%26%20cats%2012321'))
|
|
99
|
+
.to.equal('Dogs with guns & cats 12321');
|
|
100
|
+
Expect(_DataFormat.stringEncodeURIComponent('Dogs with guns & cats 12321!'))
|
|
101
|
+
.to.equal('Dogs%20with%20guns%20%26%20cats%2012321!');
|
|
102
|
+
Expect(_DataFormat.stringDecodeURIComponent('Dogs%20with%20guns%20%26%20cats%2012321%21'))
|
|
103
|
+
.to.equal('Dogs with guns & cats 12321!');
|
|
104
|
+
Expect(_DataFormat.stringDecodeURIComponent('Dogs%20with%20guns%20%26%20cats%2012321%21%40%23%24%25%5E%26*%28%29'))
|
|
105
|
+
.to.equal('Dogs with guns & cats 12321!@#$%^&*()');
|
|
106
|
+
return fTestComplete();
|
|
107
|
+
}
|
|
108
|
+
)
|
|
109
|
+
test
|
|
110
|
+
(
|
|
111
|
+
'Encode and decode javascript string components',
|
|
112
|
+
(fTestComplete)=>
|
|
113
|
+
{
|
|
114
|
+
let testFable = new libFable({LogStreams: false});
|
|
115
|
+
let _DataFormat = testFable.services.DataFormat;
|
|
116
|
+
Expect(_DataFormat.stringEncodeForJavascript('Dogs with guns'))
|
|
117
|
+
.to.equal('Dogs with guns');
|
|
118
|
+
Expect(_DataFormat.stringDecodeForJavascript('Dogs with guns'))
|
|
119
|
+
.to.equal('Dogs with guns');
|
|
120
|
+
Expect(_DataFormat.stringEncodeForJavascript('Dogs with guns & cats'))
|
|
121
|
+
.to.equal('Dogs with guns & cats');
|
|
122
|
+
Expect(_DataFormat.stringDecodeForJavascript('Dogs with guns & cats'))
|
|
123
|
+
.to.equal('Dogs with guns & cats');
|
|
124
|
+
Expect(_DataFormat.stringEncodeForJavascript(`Dogs with "guns" & \\\\cats 12321`))
|
|
125
|
+
.to.equal('Dogs with "guns" & \\\\cats 12321');
|
|
126
|
+
Expect(_DataFormat.stringDecodeForJavascript('Dogs with "guns" & cats 12321'))
|
|
127
|
+
.to.equal('Dogs with "guns" & \tcats 12321');
|
|
128
|
+
Expect(_DataFormat.stringEncodeForJavascript('Dogs with guns & \t cats 12321!'))
|
|
129
|
+
.to.equal('Dogs with guns & \t cats 12321!');
|
|
130
|
+
|
|
131
|
+
return fTestComplete();
|
|
132
|
+
}
|
|
133
|
+
)
|
|
134
|
+
test
|
|
82
135
|
(
|
|
83
136
|
'Capitalize each word in a string',
|
|
84
137
|
(fTestComplete)=>
|