@dra2020/baseclient 1.0.132 → 1.0.133

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.
@@ -1206,8 +1206,11 @@ const reParam = /^__\d+$/;
1206
1206
  class Evaluator {
1207
1207
  constructor(expr) {
1208
1208
  this.expr = expr;
1209
+ this._error = false;
1209
1210
  }
1211
+ get error() { return this._error; }
1210
1212
  eval(o) {
1213
+ this._error = false;
1211
1214
  try {
1212
1215
  // Convert property names to valid Javascript to ensure expression safety
1213
1216
  o = Util.shallowCopy(o);
@@ -1227,7 +1230,15 @@ class Evaluator {
1227
1230
  safeexpr = safeexpr.replace(n, namemap[n]);
1228
1231
  });
1229
1232
  // Remove any identifiers that aren't the simple parameters to prevent out-of-sandbox execution
1230
- safeexpr = safeexpr.replace(reIdentifier, (match) => { return reParam.test(match) ? match : "invalid"; });
1233
+ safeexpr = safeexpr.replace(reIdentifier, (match) => {
1234
+ let valid = reParam.test(match);
1235
+ if (valid)
1236
+ return match;
1237
+ else {
1238
+ this._error = true;
1239
+ return 'invalid';
1240
+ }
1241
+ });
1231
1242
  // Create a new function that accepts the variables as parameters
1232
1243
  // and evaluates the expression
1233
1244
  const func = new Function(...safenames, `return ${safeexpr};`);
@@ -1236,6 +1247,7 @@ class Evaluator {
1236
1247
  return isNaN(r) ? 0 : r;
1237
1248
  }
1238
1249
  catch (err) {
1250
+ this._error = true;
1239
1251
  return 0;
1240
1252
  }
1241
1253
  }
@@ -1244,7 +1256,7 @@ const reInvalidChars = /[\.\[\]\\]/;
1244
1256
  const reExpr = /^=(.*)$/;
1245
1257
  class FormatDetail {
1246
1258
  constructor(pattern) {
1247
- this.valid = true;
1259
+ this._error = false;
1248
1260
  this.pattern = pattern.trim();
1249
1261
  let a = reExpr.exec(pattern);
1250
1262
  if (a && a.length == 2) {
@@ -1272,10 +1284,11 @@ class FormatDetail {
1272
1284
  });
1273
1285
  }
1274
1286
  else {
1275
- this.valid = false;
1287
+ this._error = true;
1276
1288
  this.items = [{ text: 'invalid' }];
1277
1289
  }
1278
1290
  }
1291
+ get error() { return this._error; }
1279
1292
  static prepare(o) {
1280
1293
  if (o) {
1281
1294
  // Make sure there is a total field
@@ -1294,8 +1307,10 @@ class FormatDetail {
1294
1307
  return o;
1295
1308
  }
1296
1309
  format(o) {
1297
- if (!o)
1310
+ if (!o) {
1311
+ this._error = true;
1298
1312
  return { n: 0, v: '' };
1313
+ }
1299
1314
  let n;
1300
1315
  let av = this.items.map(di => {
1301
1316
  if (di.text)
@@ -1303,6 +1318,8 @@ class FormatDetail {
1303
1318
  else {
1304
1319
  let e = new Evaluator(di.expr);
1305
1320
  n = e.eval(o);
1321
+ if (!this._error)
1322
+ this._error = e.error;
1306
1323
  return Util.precisionRound(n, 0).toLocaleString();
1307
1324
  }
1308
1325
  });