@ejfdelgado/ejflab-common 1.15.0 → 1.16.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ejfdelgado/ejflab-common",
3
3
  "type": "commonjs",
4
- "version": "1.15.0",
4
+ "version": "1.16.1",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/ejfdelgado/ejflab-common.git"
package/src/MyDates.js CHANGED
@@ -449,11 +449,14 @@ class MyDates {
449
449
  return hDisplay + mDisplay + sDisplay;
450
450
  }
451
451
 
452
- static age(dateMillis) {
452
+ static age(dateMillis, currentMillis = null) {
453
+ if (!(typeof currentMillis == "number")) {
454
+ currentMillis = new Date().getTime();
455
+ }
453
456
  if (typeof dateMillis == 'number' && !isNaN(dateMillis)) {
454
457
  const dateOfBirth = new Date(dateMillis);
455
458
  const dayOfBirth = dateOfBirth.getDate();
456
- const millisDifference = new Date().getTime() - dateOfBirth.getTime();
459
+ const millisDifference = currentMillis - dateOfBirth.getTime();
457
460
  const date = new Date(millisDifference);
458
461
  const years = date.getFullYear() - 1970;
459
462
  const months = date.getMonth();
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 = SimpleObj.getValue(data, response.id);
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 = SimpleObj.getValue(data, response.id);
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) {
@@ -94,6 +94,45 @@ function myTest() {
94
94
  exp: "My nada",
95
95
  skipUndefined: false,
96
96
  },
97
+ {
98
+ txt: ' $[for el1 in ${abuelo}] $[for el2 in ${el1.padre}] $[for el3 in ${el2.hijo}] ${el3.name} $[endfor] $[endfor] $[endfor] ',
99
+ data: {
100
+ abuelo: [
101
+ {
102
+ padre: [
103
+ {
104
+ hijo: [
105
+ {name: "Hugo"}
106
+ ]
107
+ },
108
+ {
109
+ hijo: [
110
+ {name: "Paco"}
111
+ ]
112
+ },
113
+ {
114
+ hijo: [
115
+ {name: "Luis"}
116
+ ]
117
+ },
118
+ ]
119
+ }
120
+ ]
121
+ },
122
+ exp: " Hugo Paco Luis ",
123
+ skipUndefined: false,
124
+ },
125
+ {
126
+ txt: "$[if ${choice_id} == null]NULL$[else]'${choice_id}'::uuid$[endif],",
127
+ data: {
128
+ choice_id: '3764d5b2-75ec-44fd-89e0-9414f12d5b60',
129
+ assessment_answered_id: '51b62095-b14b-42b2-931e-c8872ab72b6a',
130
+ question_id: 'a48dd6db-0243-4faf-bbbd-dd808e253025',
131
+ date_of_response: 1741050236700
132
+ },
133
+ exp: "'3764d5b2-75ec-44fd-89e0-9414f12d5b60'::uuid,",
134
+ skipUndefined: false,
135
+ },
97
136
  ];
98
137
 
99
138
  renderer.registerFunction("json", CsvFormatterFilters.json);
@@ -111,7 +150,7 @@ function myTest() {
111
150
  const actual = renderer.render(myCase.txt, myCase.data, myCase.skipUndefined === true);
112
151
  //console.log(actual);
113
152
  if (actual !== myCase.exp) {
114
- throw Error(`expected:\n${myCase.exp}\nactual:\n${actual}`);
153
+ throw Error(`expected:\n${JSON.stringify(myCase.exp)}\nactual:\n${JSON.stringify(actual)}`);
115
154
  } else {
116
155
  console.log(`case ${i + 1} OK!`);
117
156
  }
@@ -2,7 +2,7 @@ const { MyTensorflow } = require("./MyTensorflow");
2
2
  const tf = require('@tensorflow/tfjs');
3
3
  const fs = require('fs');
4
4
 
5
- const test = () => {
5
+ const test = async () => {
6
6
 
7
7
  const csvText = fs.readFileSync("./data/tensordata.csv", { encoding: "utf8" });
8
8
  const csvTestText = fs.readFileSync("./data/tensordata.test.csv", { encoding: "utf8" });