@fatehan/tsrp 1.3.43 → 1.3.45
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/system.io.d.ts.map +1 -1
- package/dist/system.io.js +98 -43
- package/package.json +1 -1
package/dist/system.io.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system.io.d.ts","sourceRoot":"","sources":["../src/system.io.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,QAAQ,EAET,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAEnD,QAAA,MAAM,YAAY,GAChB,UAAU,QAAQ,EAAE,EACpB,UAAU,QAAQ,EAAE,EACpB,MAAM,IAAI,KACT,OAAO,
|
|
1
|
+
{"version":3,"file":"system.io.d.ts","sourceRoot":"","sources":["../src/system.io.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,QAAQ,EAET,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAEnD,QAAA,MAAM,YAAY,GAChB,UAAU,QAAQ,EAAE,EACpB,UAAU,QAAQ,EAAE,EACpB,MAAM,IAAI,KACT,OAAO,EA4FT,CAAC;AA8IF,eAAe,YAAY,CAAC"}
|
package/dist/system.io.js
CHANGED
|
@@ -12,7 +12,7 @@ const SystemIoCast = (systemIo, deviceIo, data) => {
|
|
|
12
12
|
const tempSystemIo = [...systemIo, ...deviceIo].sort((a, b) => a.sord - b.sord);
|
|
13
13
|
tempSystemIo.forEach((io) => {
|
|
14
14
|
var _a;
|
|
15
|
-
const value =
|
|
15
|
+
const value = evalExpressionSafe(io.formula, data);
|
|
16
16
|
if (value !== null) {
|
|
17
17
|
let style = io.activeStyle;
|
|
18
18
|
if (io.type === devices_1.SystemIo_SystemIoType.BOOLEAN) {
|
|
@@ -90,54 +90,18 @@ function Separator(value, seprator) {
|
|
|
90
90
|
const formattedInt = intPart.replace(regex, ",");
|
|
91
91
|
return decimalPart ? `${formattedInt}.${decimalPart}` : formattedInt;
|
|
92
92
|
}
|
|
93
|
-
function getValueByPath(obj, path) {
|
|
94
|
-
const parts = path
|
|
95
|
-
.replace(/\[(\w+)\]/g, '.$1')
|
|
96
|
-
.split('.')
|
|
97
|
-
.filter(Boolean);
|
|
98
|
-
let current = obj;
|
|
99
|
-
for (const key of parts) {
|
|
100
|
-
if (current == null)
|
|
101
|
-
return undefined;
|
|
102
|
-
current = current[key];
|
|
103
|
-
}
|
|
104
|
-
return current;
|
|
105
|
-
}
|
|
106
|
-
function evalExpression(template, context) {
|
|
107
|
-
try {
|
|
108
|
-
const replaced = template.replace(/\$([A-Za-z0-9_.\[\]]+)/g, (_, expr) => {
|
|
109
|
-
const value = getValueByPath(context, expr);
|
|
110
|
-
if (value === undefined || value === null)
|
|
111
|
-
return "null";
|
|
112
|
-
if (typeof value === "string")
|
|
113
|
-
return JSON.stringify(value);
|
|
114
|
-
if (typeof value === "boolean")
|
|
115
|
-
return value ? "true" : "false";
|
|
116
|
-
return String(value);
|
|
117
|
-
});
|
|
118
|
-
if (!/^[0-9+\-*/ ().truefalsenull"']+$/.test(replaced)) {
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
const fn = new Function(`return (${replaced});`);
|
|
122
|
-
const result = fn();
|
|
123
|
-
if (result === undefined || result === null)
|
|
124
|
-
return null;
|
|
125
|
-
if (typeof result === "number" || typeof result === "boolean" || typeof result === "string")
|
|
126
|
-
return result;
|
|
127
|
-
return null;
|
|
128
|
-
}
|
|
129
|
-
catch {
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
93
|
function safeEvalFormula(formula, xValue) {
|
|
134
94
|
try {
|
|
135
95
|
const replaced = formula.replace(/x/g, String(xValue));
|
|
136
|
-
if (!/^[0-9+\-*/ ()
|
|
96
|
+
if (!/^[0-9+\-*/ ().><=!&|]+$/.test(replaced))
|
|
137
97
|
return null;
|
|
138
98
|
const fn = new Function(`return (${replaced});`);
|
|
139
99
|
const result = fn();
|
|
140
|
-
|
|
100
|
+
if (typeof result === "number" && !isNaN(result))
|
|
101
|
+
return result;
|
|
102
|
+
if (typeof result === "boolean")
|
|
103
|
+
return result;
|
|
104
|
+
return null;
|
|
141
105
|
}
|
|
142
106
|
catch {
|
|
143
107
|
return null;
|
|
@@ -164,4 +128,95 @@ function safeEvalCondition(formula, xValue) {
|
|
|
164
128
|
return null;
|
|
165
129
|
}
|
|
166
130
|
}
|
|
131
|
+
function isPlainObject(v) {
|
|
132
|
+
return v !== null && typeof v === "object" && !Array.isArray(v) && !(v instanceof Uint8Array);
|
|
133
|
+
}
|
|
134
|
+
function getValueByPathCaseInsensitive(obj, path) {
|
|
135
|
+
if (!path)
|
|
136
|
+
return undefined;
|
|
137
|
+
const parts = path.replace(/\[(\d+)\]/g, '.$1').split('.').filter(Boolean);
|
|
138
|
+
let cur = obj;
|
|
139
|
+
for (const rawPart of parts) {
|
|
140
|
+
if (cur == null)
|
|
141
|
+
return undefined;
|
|
142
|
+
if (/^\d+$/.test(rawPart)) {
|
|
143
|
+
const idx = Number(rawPart);
|
|
144
|
+
if (Array.isArray(cur) || cur instanceof Uint8Array) {
|
|
145
|
+
cur = cur[idx];
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (isPlainObject(cur)) {
|
|
153
|
+
const lower = rawPart.toLowerCase();
|
|
154
|
+
const foundKey = Object.keys(cur).find(k => k.toLowerCase() === lower);
|
|
155
|
+
if (foundKey !== undefined) {
|
|
156
|
+
cur = cur[foundKey];
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
return cur;
|
|
166
|
+
}
|
|
167
|
+
function evalExpressionSafe(template, context) {
|
|
168
|
+
try {
|
|
169
|
+
if (typeof template !== 'string')
|
|
170
|
+
return null;
|
|
171
|
+
const replaced = template.replace(/\$([A-Za-z0-9_.\[\]]+)/gi, (_m, expr) => {
|
|
172
|
+
const value = getValueByPathCaseInsensitive(context, expr);
|
|
173
|
+
if (value === undefined || value === null)
|
|
174
|
+
return "null";
|
|
175
|
+
if (typeof value === "number")
|
|
176
|
+
return String(value);
|
|
177
|
+
if (typeof value === "boolean")
|
|
178
|
+
return value ? "true" : "false";
|
|
179
|
+
if (typeof value === "string")
|
|
180
|
+
return JSON.stringify(value);
|
|
181
|
+
if (value instanceof Uint8Array)
|
|
182
|
+
return `[${Array.from(value).join(',')}]`;
|
|
183
|
+
if (Array.isArray(value)) {
|
|
184
|
+
return `[${value.map(v => (typeof v === 'string' ? JSON.stringify(v) : String(v))).join(',')}]`;
|
|
185
|
+
}
|
|
186
|
+
return "null";
|
|
187
|
+
});
|
|
188
|
+
if (replaced.includes("null")) {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
const cleaned = replaced
|
|
192
|
+
.replace(/;/g, ' ')
|
|
193
|
+
.replace(/`/g, ' ')
|
|
194
|
+
.replace(/\\/g, ' ')
|
|
195
|
+
.trim();
|
|
196
|
+
const allowedPattern = /^[0-9+\-*/ %().,<>=!&|"\[\]truefalsenull,':\s]*$/i;
|
|
197
|
+
if (!allowedPattern.test(cleaned))
|
|
198
|
+
return null;
|
|
199
|
+
const forbidden = [/constructor\b/i, /process\b/i, /require\b/i, /global\b/i, /__proto__\b/i];
|
|
200
|
+
if (forbidden.some(rx => rx.test(cleaned)))
|
|
201
|
+
return null;
|
|
202
|
+
if (cleaned.length === 0)
|
|
203
|
+
return null;
|
|
204
|
+
let result;
|
|
205
|
+
try {
|
|
206
|
+
const fn = new Function(`return (${cleaned});`);
|
|
207
|
+
result = fn();
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
if (result === undefined || result === null)
|
|
213
|
+
return null;
|
|
214
|
+
if (typeof result === "number" || typeof result === "boolean" || typeof result === "string")
|
|
215
|
+
return result;
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
167
222
|
exports.default = SystemIoCast;
|