@ejfdelgado/ejflab-common 1.14.4 → 1.16.0
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/package.json +1 -1
- package/src/MyDates.js +22 -0
- package/src/MyTemplate.js +11 -2
package/package.json
CHANGED
package/src/MyDates.js
CHANGED
|
@@ -448,6 +448,28 @@ class MyDates {
|
|
|
448
448
|
var sDisplay = s > 0 ? s + (s == 1 ? " second" : " seconds") : "";
|
|
449
449
|
return hDisplay + mDisplay + sDisplay;
|
|
450
450
|
}
|
|
451
|
+
|
|
452
|
+
static age(dateMillis) {
|
|
453
|
+
if (typeof dateMillis == 'number' && !isNaN(dateMillis)) {
|
|
454
|
+
const dateOfBirth = new Date(dateMillis);
|
|
455
|
+
const dayOfBirth = dateOfBirth.getDate();
|
|
456
|
+
const millisDifference = new Date().getTime() - dateOfBirth.getTime();
|
|
457
|
+
const date = new Date(millisDifference);
|
|
458
|
+
const years = date.getFullYear() - 1970;
|
|
459
|
+
const months = date.getMonth();
|
|
460
|
+
let days = date.getDate();
|
|
461
|
+
if (days > dayOfBirth) {
|
|
462
|
+
days = date.getDate() - dayOfBirth;
|
|
463
|
+
}
|
|
464
|
+
const model = {
|
|
465
|
+
years,
|
|
466
|
+
months,
|
|
467
|
+
days
|
|
468
|
+
};
|
|
469
|
+
return model;
|
|
470
|
+
}
|
|
471
|
+
return null;
|
|
472
|
+
}
|
|
451
473
|
}
|
|
452
474
|
|
|
453
475
|
module.exports = {
|
package/src/MyTemplate.js
CHANGED
|
@@ -12,6 +12,15 @@ const pIfFin = "\\$\\s*\\[\\s*endif\\s*\\]";
|
|
|
12
12
|
const pElse = "\\$\\s*\\[\\s*else\\s*\\]";
|
|
13
13
|
|
|
14
14
|
class MyTemplate extends CsvWithFilters {
|
|
15
|
+
static localGetValue(data, key) {
|
|
16
|
+
// The key could be a JSON
|
|
17
|
+
let trimed = key.trim();
|
|
18
|
+
if (trimed.startsWith('"')) {
|
|
19
|
+
// treated as json string
|
|
20
|
+
return JSON.parse(key);
|
|
21
|
+
}
|
|
22
|
+
return SimpleObj.getValue(data, key);
|
|
23
|
+
}
|
|
15
24
|
static interpolate(text, model) {
|
|
16
25
|
const renderer = new MyTemplate();
|
|
17
26
|
return renderer.render(text, model);
|
|
@@ -217,7 +226,7 @@ class MyTemplate extends CsvWithFilters {
|
|
|
217
226
|
const myPattern2d = new RegExp("(\\$\\s*" + open + "[^$" + closeNoScape + "]+)\\$" + open + "([^" + closeNoScape + "]+)" + close + "([^" + closeNoScape + "]*" + close + ")", "g");
|
|
218
227
|
template = template.replace(myPattern2d, (match, g1, g2, g3) => {
|
|
219
228
|
const response = this.getColumnDescription(g2)[0];
|
|
220
|
-
const valor =
|
|
229
|
+
const valor = MyTemplate.localGetValue(data, response.id);
|
|
221
230
|
const temp = this.filterValue(valor, response, undefined, response.id);
|
|
222
231
|
if (temp === undefined) {
|
|
223
232
|
return match;
|
|
@@ -227,7 +236,7 @@ class MyTemplate extends CsvWithFilters {
|
|
|
227
236
|
});
|
|
228
237
|
template = template.replace(myPattern, (match, g1) => {
|
|
229
238
|
const response = this.getColumnDescription(g1)[0];
|
|
230
|
-
const valor =
|
|
239
|
+
const valor = MyTemplate.localGetValue(data, response.id);
|
|
231
240
|
if (!useStringify) {
|
|
232
241
|
const temp = this.filterValue(valor, response, undefined, response.id);
|
|
233
242
|
if (!skipUndefined) {
|