@ejfdelgado/ejflab-common 1.16.0 → 1.16.2

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,15 +1,16 @@
1
1
  {
2
2
  "name": "@ejfdelgado/ejflab-common",
3
3
  "type": "commonjs",
4
- "version": "1.16.0",
4
+ "version": "1.16.2",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/ejfdelgado/ejflab-common.git"
8
8
  },
9
9
  "description": "",
10
10
  "scripts": {
11
+ "bip": "ffplay /sound/finish.mp3 -nodisp -nostats -hide_banner -autoexit",
11
12
  "mylogin": "npm login",
12
- "mypublish": "npm publish --access=public",
13
+ "mypublish": "npm publish --access=public && npm run bip",
13
14
  "clean": "rm -rf node_modules && npm cache clean --force && rm package-lock.json && npm install"
14
15
  },
15
16
  "engines": {
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();
@@ -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" });
package/src/MyThrottle.js CHANGED
@@ -13,6 +13,8 @@ function debounce(fn, delay) {
13
13
  }
14
14
 
15
15
  /*
16
+ IMPORTANT, the throttled function MUST be an async function, otherwise it will not work!
17
+
16
18
  const GAP_ms = 500;
17
19
  Si quieres tener en cuenta solo la primera invocación e ignorar las repetidas invocaciones con intervalos de menos de gap:
18
20
  new MyThrottle(GAP_ms, true);
@@ -29,7 +31,7 @@ class MyThrottle {
29
31
  this.isIgnoring = false;
30
32
  }
31
33
 
32
- throttle(promisedFunction) {
34
+ throttle(promisedFunction, args = []) {
33
35
  const afterGap = () => {
34
36
  if (this.useFirst) {
35
37
  if (calledTime == this.lastCalledTime) {
@@ -59,7 +61,7 @@ class MyThrottle {
59
61
  // Use first
60
62
  this.isCalling = true;
61
63
  this.isIgnoring = true;
62
- promisedFunction().finally(afterCall);
64
+ promisedFunction(...args).finally(afterCall);
63
65
  setTimeout(afterGap, this.timeGap);
64
66
  } else {
65
67
  // Use last
@@ -67,7 +69,7 @@ class MyThrottle {
67
69
  if (calledTime == this.lastCalledTime) {
68
70
  // Call!
69
71
  this.isCalling = true;
70
- promisedFunction().finally(afterCall);
72
+ promisedFunction(...args).finally(afterCall);
71
73
  } else {
72
74
  console.log("Ignoring...");
73
75
  }