@xuda.io/xuda-get-cast-util-module 1.0.124 → 1.0.126
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/index.mjs +5 -10
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -4,11 +4,6 @@ export const cast = function (
|
|
|
4
4
|
report_conversion_error_callback,
|
|
5
5
|
report_conversion_warn_callback
|
|
6
6
|
) {
|
|
7
|
-
if (typeof _ === "undefined") {
|
|
8
|
-
console.error("error: _ library not defined in cast");
|
|
9
|
-
return valP;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
7
|
var ret = valP;
|
|
13
8
|
|
|
14
9
|
const report_conversion_error = function (res) {
|
|
@@ -26,12 +21,12 @@ export const cast = function (
|
|
|
26
21
|
case "bool":
|
|
27
22
|
const true_bool_opt = ["Y", 1, true, "TRUE", "ON", "YES", "1"];
|
|
28
23
|
const false_bool_opt = ["N", 0, false, "FALSE", "OFF", "NO", "0"];
|
|
29
|
-
if (true_bool_opt.includes(
|
|
24
|
+
if (true_bool_opt.includes(String(valP).toUpperCase())) {
|
|
30
25
|
ret = true;
|
|
31
26
|
break;
|
|
32
27
|
}
|
|
33
28
|
|
|
34
|
-
if (false_bool_opt.includes(
|
|
29
|
+
if (false_bool_opt.includes(String(valP).toUpperCase()) || !valP) {
|
|
35
30
|
ret = false;
|
|
36
31
|
}
|
|
37
32
|
|
|
@@ -50,7 +45,7 @@ export const cast = function (
|
|
|
50
45
|
if (typeof valP === "boolean") {
|
|
51
46
|
ret = valP ? 1 : 0;
|
|
52
47
|
} else {
|
|
53
|
-
ret =
|
|
48
|
+
ret = Number(valP);
|
|
54
49
|
}
|
|
55
50
|
// normal behavior studio always store values as string
|
|
56
51
|
// report_conversion_warn();
|
|
@@ -71,7 +66,7 @@ export const cast = function (
|
|
|
71
66
|
} else {
|
|
72
67
|
if (typeof valP !== "string") {
|
|
73
68
|
try {
|
|
74
|
-
ret =
|
|
69
|
+
ret = String(valP);
|
|
75
70
|
report_conversion_warn();
|
|
76
71
|
} catch (e) {
|
|
77
72
|
ret = "";
|
|
@@ -117,7 +112,7 @@ export const cast = function (
|
|
|
117
112
|
} else {
|
|
118
113
|
if (!Array.isArray(valP)) {
|
|
119
114
|
try {
|
|
120
|
-
ret =
|
|
115
|
+
ret = Array.from(eval(valP));
|
|
121
116
|
} catch (e) {
|
|
122
117
|
ret = [];
|
|
123
118
|
report_conversion_error("[]");
|