@dra2020/baseclient 1.0.132 → 1.0.134
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/baseclient.js +28 -6
- package/dist/baseclient.js.map +1 -1
- package/dist/detail/detail.d.ts +7 -2
- package/lib/detail/detail.ts +45 -7
- package/package.json +1 -1
package/dist/baseclient.js
CHANGED
|
@@ -1203,11 +1203,18 @@ exports.FormatDetail = void 0;
|
|
|
1203
1203
|
const Util = __importStar(__webpack_require__(/*! ../util/all */ "./lib/util/all.ts"));
|
|
1204
1204
|
const reIdentifier = /\b[a-zA-Z_$][a-zA-Z0-9_$]*\b/g;
|
|
1205
1205
|
const reParam = /^__\d+$/;
|
|
1206
|
+
function defaultNumberFormat(n) {
|
|
1207
|
+
return Util.precisionRound(n, 0).toLocaleString();
|
|
1208
|
+
}
|
|
1209
|
+
const DefaultDetailOptions = { numberFormat: defaultNumberFormat };
|
|
1206
1210
|
class Evaluator {
|
|
1207
1211
|
constructor(expr) {
|
|
1208
1212
|
this.expr = expr;
|
|
1213
|
+
this._error = false;
|
|
1209
1214
|
}
|
|
1215
|
+
get error() { return this._error; }
|
|
1210
1216
|
eval(o) {
|
|
1217
|
+
this._error = false;
|
|
1211
1218
|
try {
|
|
1212
1219
|
// Convert property names to valid Javascript to ensure expression safety
|
|
1213
1220
|
o = Util.shallowCopy(o);
|
|
@@ -1227,7 +1234,15 @@ class Evaluator {
|
|
|
1227
1234
|
safeexpr = safeexpr.replace(n, namemap[n]);
|
|
1228
1235
|
});
|
|
1229
1236
|
// Remove any identifiers that aren't the simple parameters to prevent out-of-sandbox execution
|
|
1230
|
-
safeexpr = safeexpr.replace(reIdentifier, (match) => {
|
|
1237
|
+
safeexpr = safeexpr.replace(reIdentifier, (match) => {
|
|
1238
|
+
let valid = reParam.test(match);
|
|
1239
|
+
if (valid)
|
|
1240
|
+
return match;
|
|
1241
|
+
else {
|
|
1242
|
+
this._error = true;
|
|
1243
|
+
return 'invalid';
|
|
1244
|
+
}
|
|
1245
|
+
});
|
|
1231
1246
|
// Create a new function that accepts the variables as parameters
|
|
1232
1247
|
// and evaluates the expression
|
|
1233
1248
|
const func = new Function(...safenames, `return ${safeexpr};`);
|
|
@@ -1236,6 +1251,7 @@ class Evaluator {
|
|
|
1236
1251
|
return isNaN(r) ? 0 : r;
|
|
1237
1252
|
}
|
|
1238
1253
|
catch (err) {
|
|
1254
|
+
this._error = true;
|
|
1239
1255
|
return 0;
|
|
1240
1256
|
}
|
|
1241
1257
|
}
|
|
@@ -1243,8 +1259,9 @@ class Evaluator {
|
|
|
1243
1259
|
const reInvalidChars = /[\.\[\]\\]/;
|
|
1244
1260
|
const reExpr = /^=(.*)$/;
|
|
1245
1261
|
class FormatDetail {
|
|
1246
|
-
constructor(pattern) {
|
|
1247
|
-
this.
|
|
1262
|
+
constructor(pattern, options) {
|
|
1263
|
+
this.options = Util.shallowAssignImmutable(DefaultDetailOptions, options);
|
|
1264
|
+
this._error = false;
|
|
1248
1265
|
this.pattern = pattern.trim();
|
|
1249
1266
|
let a = reExpr.exec(pattern);
|
|
1250
1267
|
if (a && a.length == 2) {
|
|
@@ -1272,10 +1289,11 @@ class FormatDetail {
|
|
|
1272
1289
|
});
|
|
1273
1290
|
}
|
|
1274
1291
|
else {
|
|
1275
|
-
this.
|
|
1292
|
+
this._error = true;
|
|
1276
1293
|
this.items = [{ text: 'invalid' }];
|
|
1277
1294
|
}
|
|
1278
1295
|
}
|
|
1296
|
+
get error() { return this._error; }
|
|
1279
1297
|
static prepare(o) {
|
|
1280
1298
|
if (o) {
|
|
1281
1299
|
// Make sure there is a total field
|
|
@@ -1294,8 +1312,10 @@ class FormatDetail {
|
|
|
1294
1312
|
return o;
|
|
1295
1313
|
}
|
|
1296
1314
|
format(o) {
|
|
1297
|
-
if (!o)
|
|
1315
|
+
if (!o) {
|
|
1316
|
+
this._error = true;
|
|
1298
1317
|
return { n: 0, v: '' };
|
|
1318
|
+
}
|
|
1299
1319
|
let n;
|
|
1300
1320
|
let av = this.items.map(di => {
|
|
1301
1321
|
if (di.text)
|
|
@@ -1303,7 +1323,9 @@ class FormatDetail {
|
|
|
1303
1323
|
else {
|
|
1304
1324
|
let e = new Evaluator(di.expr);
|
|
1305
1325
|
n = e.eval(o);
|
|
1306
|
-
|
|
1326
|
+
if (!this._error)
|
|
1327
|
+
this._error = e.error;
|
|
1328
|
+
return this.options.numberFormat(n);
|
|
1307
1329
|
}
|
|
1308
1330
|
});
|
|
1309
1331
|
return { n, v: av.join('') };
|