@dra2020/baseclient 1.0.130 → 1.0.131
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 +62 -65
- package/dist/baseclient.js.map +1 -1
- package/dist/detail/detail.d.ts +3 -8
- package/lib/detail/detail.ts +74 -81
- package/package.json +1 -1
package/dist/baseclient.js
CHANGED
|
@@ -1168,14 +1168,13 @@ __exportStar(__webpack_require__(/*! ./detail */ "./lib/detail/detail.ts"), expo
|
|
|
1168
1168
|
|
|
1169
1169
|
|
|
1170
1170
|
//
|
|
1171
|
-
// FormatDetail will take
|
|
1172
|
-
// Given an object with a set of integer properties, it will evaluate the
|
|
1173
|
-
//
|
|
1171
|
+
// FormatDetail will take an expression that specifies a format detail lines.
|
|
1172
|
+
// Given an object with a set of integer properties, it will evaluate the expression and produce
|
|
1173
|
+
// a result { k: string, n: number, v: string } results for displaying the contents of the object.
|
|
1174
1174
|
//
|
|
1175
|
-
// The formatting string
|
|
1176
|
-
//
|
|
1177
|
-
//
|
|
1178
|
-
// Expr can be an arithmetic expression using +-/*() as operators and variables are the field
|
|
1175
|
+
// The formatting string is a statement of the form:
|
|
1176
|
+
// =expr
|
|
1177
|
+
// Expr can be an arithmetic expression using +-/*()?: as operators and variables are the field
|
|
1179
1178
|
// names of properties on the object passed in. The special field name _tot represents the
|
|
1180
1179
|
// total of all properties. The expression may also include double-quoted strings that are
|
|
1181
1180
|
// passed through (e.g. for use as labels = area" sqm")
|
|
@@ -1242,74 +1241,72 @@ class Evaluator {
|
|
|
1242
1241
|
}
|
|
1243
1242
|
}
|
|
1244
1243
|
const reInvalidChars = /[\.\[\]\\]/;
|
|
1244
|
+
const reExpr = /^=(.*)$/;
|
|
1245
1245
|
class FormatDetail {
|
|
1246
1246
|
constructor(pattern) {
|
|
1247
1247
|
this.valid = true;
|
|
1248
|
-
this.pattern = pattern;
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
if (subexpr.length) {
|
|
1264
|
-
// Don't allow unsafe actions
|
|
1265
|
-
if (reInvalidChars.test(subexpr))
|
|
1266
|
-
items.push({ text: subexpr });
|
|
1267
|
-
else
|
|
1268
|
-
items.push({ expr: subexpr });
|
|
1269
|
-
}
|
|
1270
|
-
state = 'text';
|
|
1271
|
-
}
|
|
1272
|
-
else // state === 'text'
|
|
1273
|
-
{
|
|
1274
|
-
if (subexpr.length)
|
|
1275
|
-
items.push({ text: subexpr });
|
|
1276
|
-
state = 'expr';
|
|
1248
|
+
this.pattern = pattern.trim();
|
|
1249
|
+
let a = reExpr.exec(pattern);
|
|
1250
|
+
if (a && a.length == 2) {
|
|
1251
|
+
this.items = [];
|
|
1252
|
+
const expr = a[1];
|
|
1253
|
+
const parse = expr.split('"');
|
|
1254
|
+
let state = 'expr';
|
|
1255
|
+
parse.forEach(subexpr => {
|
|
1256
|
+
if (state === 'expr') {
|
|
1257
|
+
if (subexpr.length) {
|
|
1258
|
+
// Don't allow unsafe actions
|
|
1259
|
+
if (reInvalidChars.test(subexpr))
|
|
1260
|
+
this.items.push({ text: subexpr });
|
|
1261
|
+
else
|
|
1262
|
+
this.items.push({ expr: subexpr });
|
|
1277
1263
|
}
|
|
1264
|
+
state = 'text';
|
|
1265
|
+
}
|
|
1266
|
+
else // state === 'text'
|
|
1267
|
+
{
|
|
1268
|
+
if (subexpr.length)
|
|
1269
|
+
this.items.push({ text: subexpr });
|
|
1270
|
+
state = 'expr';
|
|
1271
|
+
}
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1274
|
+
else {
|
|
1275
|
+
this.valid = false;
|
|
1276
|
+
this.items = [{ text: 'invalid' }];
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
prepare(o) {
|
|
1280
|
+
if (o) {
|
|
1281
|
+
// Make sure there is a total field
|
|
1282
|
+
o = Util.deepCopy(o);
|
|
1283
|
+
if (o['Tot'] !== undefined)
|
|
1284
|
+
o['_tot'] = o['Tot'];
|
|
1285
|
+
else {
|
|
1286
|
+
let t = 0;
|
|
1287
|
+
Object.values(o).forEach((v) => {
|
|
1288
|
+
if (!isNaN(v) && typeof v === 'number')
|
|
1289
|
+
t += v;
|
|
1278
1290
|
});
|
|
1279
|
-
|
|
1291
|
+
o['_tot'] = t;
|
|
1280
1292
|
}
|
|
1281
|
-
}
|
|
1293
|
+
}
|
|
1294
|
+
return o;
|
|
1282
1295
|
}
|
|
1283
1296
|
format(o) {
|
|
1284
1297
|
if (!o)
|
|
1285
|
-
return
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
});
|
|
1296
|
-
o['_tot'] = t;
|
|
1297
|
-
}
|
|
1298
|
-
let result = [];
|
|
1299
|
-
this.lines.forEach(line => {
|
|
1300
|
-
let n;
|
|
1301
|
-
let av = line.items.map(di => {
|
|
1302
|
-
if (di.text)
|
|
1303
|
-
return di.text;
|
|
1304
|
-
else {
|
|
1305
|
-
let e = new Evaluator(di.expr);
|
|
1306
|
-
n = e.eval(o);
|
|
1307
|
-
return Util.precisionRound(n, 0).toLocaleString();
|
|
1308
|
-
}
|
|
1309
|
-
});
|
|
1310
|
-
result.push({ k: line.label, n, v: av.join('') });
|
|
1298
|
+
return { n: 0, v: '' };
|
|
1299
|
+
let n;
|
|
1300
|
+
let av = this.items.map(di => {
|
|
1301
|
+
if (di.text)
|
|
1302
|
+
return di.text;
|
|
1303
|
+
else {
|
|
1304
|
+
let e = new Evaluator(di.expr);
|
|
1305
|
+
n = e.eval(o);
|
|
1306
|
+
return Util.precisionRound(n, 0).toLocaleString();
|
|
1307
|
+
}
|
|
1311
1308
|
});
|
|
1312
|
-
return
|
|
1309
|
+
return { n, v: av.join('') };
|
|
1313
1310
|
}
|
|
1314
1311
|
}
|
|
1315
1312
|
exports.FormatDetail = FormatDetail;
|