@osimatic/helpers-js 1.4.24 → 1.4.26

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.
Files changed (68) hide show
  1. package/.claude/settings.local.json +2 -1
  2. package/chartjs.js +1 -1
  3. package/date_time.js +25 -16
  4. package/draw.js +3 -2
  5. package/duration.js +176 -130
  6. package/event_bus.js +2 -2
  7. package/file.js +20 -5
  8. package/form_helper.js +1 -1
  9. package/google_charts.js +2 -1
  10. package/http_client.js +2 -0
  11. package/jwt.js +18 -6
  12. package/location.js +5 -1
  13. package/media.js +7 -7
  14. package/multi_files_input.js +3 -1
  15. package/number.js +2 -3
  16. package/package.json +4 -2
  17. package/paging.js +2 -2
  18. package/social_network.js +5 -0
  19. package/string.js +11 -2
  20. package/tests/__mocks__/socket.io-client.js +13 -0
  21. package/tests/chartjs.test.js +273 -0
  22. package/tests/count_down.test.js +580 -0
  23. package/tests/date_time/DatePeriod.test.js +179 -0
  24. package/tests/date_time/DateTime.test.js +492 -0
  25. package/tests/date_time/SqlDate.test.js +205 -0
  26. package/tests/date_time/SqlDateTime.test.js +326 -0
  27. package/tests/date_time/SqlTime.test.js +162 -0
  28. package/tests/date_time/TimestampUnix.test.js +262 -0
  29. package/tests/details_sub_array.test.js +367 -0
  30. package/tests/draw.test.js +271 -0
  31. package/tests/duration.test.js +365 -0
  32. package/tests/event_bus.test.js +268 -0
  33. package/tests/file.test.js +568 -0
  34. package/tests/flash_message.test.js +297 -0
  35. package/tests/form_date.test.js +1559 -0
  36. package/tests/form_helper.test.js +1065 -0
  37. package/tests/google_charts.test.js +768 -0
  38. package/tests/google_maps.test.js +655 -0
  39. package/tests/google_recaptcha.test.js +441 -0
  40. package/tests/http_client.test.js +570 -0
  41. package/tests/import_from_csv.test.js +797 -0
  42. package/tests/jwt.test.js +804 -0
  43. package/tests/list_box.test.js +255 -0
  44. package/tests/location.test.js +86 -0
  45. package/tests/media.test.js +473 -0
  46. package/tests/multi_files_input.test.js +1015 -0
  47. package/tests/multiple_action_in_table.test.js +477 -0
  48. package/tests/network.test.js +489 -0
  49. package/tests/number.test.js +448 -0
  50. package/tests/open_street_map.test.js +388 -0
  51. package/tests/paging.test.js +646 -0
  52. package/tests/select_all.test.js +360 -0
  53. package/tests/shopping_cart.test.js +355 -0
  54. package/tests/social_network.test.js +333 -0
  55. package/tests/sortable_list.test.js +602 -0
  56. package/tests/string.test.js +489 -0
  57. package/tests/user.test.js +204 -0
  58. package/tests/util.test.js +99 -0
  59. package/tests/visitor.test.js +508 -0
  60. package/tests/web_rtc.test.js +458 -0
  61. package/tests/web_socket.test.js +538 -0
  62. package/visitor.js +2 -2
  63. package/tmpclaude-0fa4-cwd +0 -1
  64. package/tmpclaude-104f-cwd +0 -1
  65. package/tmpclaude-1468-cwd +0 -1
  66. package/tmpclaude-324b-cwd +0 -1
  67. package/tmpclaude-35d3-cwd +0 -1
  68. package/tmpclaude-4aa8-cwd +0 -1
@@ -6,7 +6,8 @@
6
6
  "Bash(npm run test:coverage:*)",
7
7
  "Bash(npm login)",
8
8
  "Bash(npm publish:*)",
9
- "Bash(npm logout:*)"
9
+ "Bash(npm logout:*)",
10
+ "Bash(node -e:*)"
10
11
  ]
11
12
  }
12
13
  }
package/chartjs.js CHANGED
@@ -298,7 +298,7 @@ class Chartjs {
298
298
  }
299
299
 
300
300
  static getAutoGranularity(data) {
301
- const dates = Object.keys(data);
301
+ const dates = Object.keys(data).sort();
302
302
  const days = (new Date(dates[dates.length - 1]) - new Date(dates[0])) / (1000 * 60 * 60 * 24);
303
303
  if (days > 90) return 'month';
304
304
  if (days > 30) return 'week';
package/date_time.js CHANGED
@@ -206,9 +206,7 @@ class DateTime {
206
206
  }
207
207
 
208
208
  static getLastDayOfYear(date) {
209
- date.setUTCDate(31);
210
- date.setUTCMonth(11);
211
- return new Date(date);
209
+ return new Date(Date.UTC(date.getUTCFullYear(), 11, 31));
212
210
  }
213
211
 
214
212
  static getFirstDayOfWeekAndYear(year, week) {
@@ -308,7 +306,7 @@ class DatePeriod {
308
306
  return partOfDay === DatePeriod.PART_OF_DAY_MORNING || partOfDay === DatePeriod.PART_OF_DAY_AFTERNOON;
309
307
  }
310
308
 
311
- static getNbDayBetweenTwo(jsDate1, jsDate2, asPeriod=false, timeZone="Europe/Paris") {
309
+ static getNbDayBetweenTwo(jsDate1, jsDate2, considerTime=false, timeZone="Europe/Paris", returnDecimal=false) {
312
310
  //jsDate1.set
313
311
  if (jsDate1 == null || jsDate2 == null) {
314
312
  return 0;
@@ -317,7 +315,7 @@ class DatePeriod {
317
315
  let timestamp1 = jsDate1.getTime() / 1000;
318
316
  let timestamp2 = jsDate2.getTime() / 1000;
319
317
 
320
- if (!asPeriod) {
318
+ if (!considerTime) {
321
319
  let jsMidnightDate1 = new Date(jsDate1.toLocaleDateString('en-US', {timeZone: timeZone})+' 00:00:00');
322
320
  let jsMidnightDate2 = new Date(jsDate2.toLocaleDateString('en-US', {timeZone: timeZone})+' 00:00:00');
323
321
  timestamp1 = jsMidnightDate1.getTime() / 1000;
@@ -327,7 +325,9 @@ class DatePeriod {
327
325
  //jsDate1.setUTCHours(0, 0, 0);
328
326
  //jsDate2.setUTCHours(0, 0, 0);
329
327
  }
330
- return parseInt(Math.round((timestamp2-timestamp1)/86400));
328
+
329
+ const daysDiff = (timestamp2-timestamp1)/86400;
330
+ return returnDecimal ? daysDiff : parseInt(Math.round(daysDiff));
331
331
  }
332
332
 
333
333
  static getPeriodLabels(data, period, locale = 'fr-FR', timeZone = 'Europe/Paris') {
@@ -392,23 +392,32 @@ class TimestampUnix {
392
392
  }
393
393
 
394
394
  static getYear(timestamp, timeZone="Europe/Paris") {
395
- return this.parse(timestamp).toLocaleDateString('fr-FR', {year: 'numeric', timeZone: timeZone});
395
+ //const sqlDate = this.getSqlDate(timestamp, timeZone);
396
+ //return parseInt(sqlDate.substring(0, 4));
397
+ return parseInt(this.parse(timestamp).toLocaleDateString('fr-FR', {year: 'numeric', timeZone: timeZone}));
396
398
  }
397
399
  static getMonth(timestamp, timeZone="Europe/Paris") {
398
- return this.parse(timestamp).toLocaleDateString('fr-FR', {month: 'numeric', timeZone: timeZone});
400
+ //const sqlDate = this.getSqlDate(timestamp, timeZone);
401
+ //return parseInt(sqlDate.substring(5, 7));
402
+ return parseInt(this.parse(timestamp).toLocaleDateString('fr-FR', {month: 'numeric', timeZone: timeZone}));
399
403
  }
400
404
  static getDayOfMonth(timestamp, timeZone="Europe/Paris") {
401
- return this.parse(timestamp).toLocaleDateString('fr-FR', {day: 'numeric', timeZone: timeZone});
405
+ //const sqlDate = this.getSqlDate(timestamp, timeZone);
406
+ //return parseInt(sqlDate.substring(8, 10));
407
+ return parseInt(this.parse(timestamp).toLocaleDateString('fr-FR', {day: 'numeric', timeZone: timeZone}));
402
408
  }
403
409
 
404
410
  static getHour(timestamp, timeZone="Europe/Paris") {
405
- return this.parse(timestamp).toLocaleTimeString('en-GB', {hour: 'numeric', timeZone: timeZone});
411
+ const sqlTime = this.getSqlTime(timestamp, timeZone);
412
+ return parseInt(sqlTime.substring(0, 2));
406
413
  }
407
414
  static getMinute(timestamp, timeZone="Europe/Paris") {
408
- return this.parse(timestamp).toLocaleTimeString('en-GB', {minute: 'numeric', timeZone: timeZone});
415
+ const sqlTime = this.getSqlTime(timestamp, timeZone);
416
+ return parseInt(sqlTime.substring(3, 5));
409
417
  }
410
418
  static getSecond(timestamp, timeZone="Europe/Paris") {
411
- return this.parse(timestamp).toLocaleTimeString('en-GB', {second: 'numeric', timeZone: timeZone});
419
+ const sqlTime = this.getSqlTime(timestamp, timeZone);
420
+ return parseInt(sqlTime.substring(6, 8));
412
421
  }
413
422
 
414
423
  static getSqlDateTime(timestamp, timeZone="Europe/Paris") {
@@ -556,18 +565,18 @@ class SqlDateTime {
556
565
  return DateTime.getSqlDateTime(new Date());
557
566
  }
558
567
 
559
- static getSqlDate(sqlDateTime) {
568
+ static getSqlDate(sqlDateTime, timeZone="UTC") {
560
569
  if (sqlDateTime == null) {
561
570
  return null;
562
571
  }
563
- return DateTime.getSqlDate(this.parse(sqlDateTime));
572
+ return DateTime.getSqlDate(this.parse(sqlDateTime), timeZone);
564
573
  }
565
574
 
566
- static getSqlTime(sqlDateTime) {
575
+ static getSqlTime(sqlDateTime, timeZone="UTC") {
567
576
  if (sqlDateTime == null) {
568
577
  return null;
569
578
  }
570
- return DateTime.getSqlTime(this.parse(sqlDateTime));
579
+ return DateTime.getSqlTime(this.parse(sqlDateTime), timeZone);
571
580
  }
572
581
 
573
582
  static parse(sqlDateTime) {
package/draw.js CHANGED
@@ -1,6 +1,7 @@
1
1
  class HexColor {
2
2
  static check(hexColor) {
3
- return hexColor.match(/^[0-9a-fA-F]{6}$/).length;
3
+ const match = hexColor.match(/^[0-9a-fA-F]{6}$/);
4
+ return match ? match.length > 0 : false;
4
5
  }
5
6
 
6
7
  static convertToRgb(hexColor) {
@@ -9,7 +10,7 @@ class HexColor {
9
10
  }
10
11
 
11
12
  if (hexColor.length === 3) {
12
- hexColor = hexColor+hexColor;
13
+ hexColor = hexColor[0]+hexColor[0]+hexColor[1]+hexColor[1]+hexColor[2]+hexColor[2];
13
14
  }
14
15
 
15
16
  if (!HexColor.check(hexColor)) {
package/duration.js CHANGED
@@ -1,199 +1,245 @@
1
1
 
2
2
  class Duration {
3
3
 
4
- // ---------- Nb jours ----------
4
+ // -------------------------------------------------------------------------
5
+ // Days formatting
6
+ // -------------------------------------------------------------------------
5
7
 
6
- static formatNbDays(nbDays, locale='fr-FR') {
8
+ static formatDays(days, locale = 'fr-FR') {
7
9
  return new Intl.NumberFormat(locale, {
8
10
  minimumFractionDigits: 2,
9
11
  maximumFractionDigits: 2
10
- }).format(nbDays);
12
+ }).format(days);
11
13
  }
12
- static formatNbDaysIfPositive(nbDays) {
13
- return nbDays < 0 ? '-' : this.formatNbDays(nbDays);
14
+
15
+ static formatDaysIfPositive(days) {
16
+ return days < 0 ? '-' : this.formatDays(days);
14
17
  }
15
- static formatNbDaysWithColor(nbDays) {
16
- return '<span class="text-'+(nbDays<0?'danger':'success')+'">'+this.formatNbDays(nbDays)+'</span>';
18
+
19
+ static formatDaysWithColor(days) {
20
+ return '<span class="text-' + (days < 0 ? 'danger' : 'success') + '">' + this.formatDays(days) + '</span>';
17
21
  }
18
22
 
19
- // ---------- Durée en seconde ----------
23
+ // -------------------------------------------------------------------------
24
+ // Seconds — conversion
25
+ // -------------------------------------------------------------------------
20
26
 
21
- static convertInputTimeValueToDuration(inputTimeValue) {
22
- if (null === inputTimeValue || -1 === inputTimeValue.indexOf(':')) {
27
+ static parseTimeInputToSeconds(timeInput) {
28
+ if (null === timeInput || -1 === timeInput.indexOf(':')) {
23
29
  return 0;
24
30
  }
25
- let arrayTime = inputTimeValue.split(':');
26
- const nbHours = typeof arrayTime[0] != 'undefined' ? parseInt(arrayTime[0]) || 0 : 0;
31
+ let arrayTime = timeInput.split(':');
32
+ const nbHours = typeof arrayTime[0] != 'undefined' ? parseInt(arrayTime[0]) || 0 : 0;
27
33
  const nbMinutes = typeof arrayTime[1] != 'undefined' ? parseInt(arrayTime[1]) || 0 : 0;
28
34
  const nbSeconds = typeof arrayTime[2] != 'undefined' ? parseInt(arrayTime[2]) || 0 : 0;
29
35
  return nbHours * 3600 + nbMinutes * 60 + nbSeconds;
30
36
  }
31
37
 
32
- static convertToDurationAsInputTimeValue(durationInSeconds) {
33
- return Duration.convertToDurationInHourChronoDisplay(Math.abs(durationInSeconds), 'input_time');
38
+ // -------------------------------------------------------------------------
39
+ // Seconds — formatting
40
+ // -------------------------------------------------------------------------
41
+
42
+ static formatSecondsAsTimeInput(seconds) {
43
+ return Duration.formatSecondsAsChrono(Math.abs(seconds), 'input_time');
34
44
  }
35
45
 
36
- static convertToDurationInHourChronoDisplay(durationInSeconds, displayMode='chrono') {
37
- durationInSeconds = Math.round(durationInSeconds);
46
+ static formatSecondsAsChrono(seconds, displayMode = 'chrono', withSeconds = true) {
47
+ seconds = Math.round(seconds);
48
+ const absoluteSeconds = Math.abs(seconds);
49
+
50
+ let secs = absoluteSeconds % 60;
51
+ let remainder = (absoluteSeconds % 3600) - secs;
52
+ let minutes = remainder / 60;
53
+ remainder = absoluteSeconds - (absoluteSeconds % 3600);
54
+ let hours = remainder / 3600;
55
+
56
+ hours = hours.toString().length < 2 ? '0' + hours : hours;
57
+ minutes = minutes.toString().length < 2 ? '0' + minutes : minutes;
38
58
 
39
- let durationInSecondsOriginal = durationInSeconds;
40
- durationInSeconds = Math.abs(durationInSeconds);
41
- let seconds = ( durationInSeconds % 60 );
42
- let remander = ( durationInSeconds % 3600 ) - seconds;
43
- let minutes = ( remander / 60 );
44
- remander = ( durationInSeconds ) - ( durationInSeconds % 3600 );
45
- let hours = ( remander / 3600 );
46
- if(hours.toString().length < 2) hours = '0'+hours;
47
- if(hours.toString().charAt(0) === "-") hours[0] = '0';
48
- if(minutes.toString().length < 2) minutes = '0'+minutes;
49
- if(minutes.toString().charAt(0) === "-") minutes[0] = '0';
50
- if(seconds.toString().length < 2) seconds = '0'+seconds;
51
- return (durationInSecondsOriginal < 0 ? '- ' : '')+hours+':'+minutes+(displayMode==='input_time'?':':'.')+seconds;
59
+ let result = (seconds < 0 ? '- ' : '') + hours + ':' + minutes;
60
+ if (withSeconds) {
61
+ secs = secs.toString().length < 2 ? '0' + secs : secs;
62
+ result += (displayMode === 'input_time' ? ':' : '.') + secs;
63
+ }
64
+ return result;
52
65
  }
53
66
 
54
- static convertToDurationInHourStringDisplay(durationInSeconds, withSeconds=true, withMinutes=true, withMinuteLabel=true, fullLabel=false, hideHourIfZeroHour=false) {
55
- durationInSeconds = Math.round(durationInSeconds);
67
+ static formatSecondsAsString(seconds, withSeconds = true, withMinutes = true, withMinuteLabel = true, fullLabel = false, hideHourIfZero = false) {
68
+ seconds = Math.round(seconds);
56
69
 
57
- // Heures
58
- let strHeure = '';
59
- let nbHeures = this.getNbHoursOfDurationInSeconds(durationInSeconds);
60
- if (!hideHourIfZeroHour || nbHeures > 0) {
61
- strHeure += nbHeures;
70
+ // Hours
71
+ let strHours = '';
72
+ let nbHours = this.totalHours(seconds);
73
+ if (!hideHourIfZero || nbHours > 0) {
74
+ strHours += nbHours;
62
75
  if (fullLabel) {
63
- strHeure += ' heure'+(nbHeures>1?'s':'');
64
- }
65
- else {
66
- strHeure += 'h';
76
+ strHours += ' heure' + (nbHours > 1 ? 's' : '');
77
+ } else {
78
+ strHours += 'h';
67
79
  }
68
80
  }
69
-
81
+
70
82
  // Minutes
71
- let strMinute = '';
83
+ let strMinutes = '';
72
84
  if (withMinutes) {
73
- let nbMinutes = this.getNbMinutesRemainingOfDurationInSeconds(durationInSeconds);
74
- strMinute += ' ';
75
- //strMinute += sprintf('%02d', nbMinutes);
76
- strMinute += nbMinutes.toString().padStart(2, '0');
77
- if (withMinuteLabel) {
78
- if (fullLabel) {
79
- strMinute += ' minute'+(nbMinutes>1?'s':'');
80
- }
81
- else {
82
- strMinute += 'min';
83
- }
85
+ let nbMinutes = this.remainingMinutes(seconds);
86
+ strMinutes += ' ';
87
+ if (fullLabel) {
88
+ strMinutes += nbMinutes.toString() + (withMinuteLabel ? ' minute' + (nbMinutes > 1 ? 's' : '') : '');
89
+ } else {
90
+ strMinutes += nbMinutes.toString().padStart(2, '0') + (withMinuteLabel ? 'min' : '');
84
91
  }
85
92
  }
86
-
87
- // Secondes
88
- let strSeconde = '';
93
+
94
+ // Seconds
95
+ let strSeconds = '';
89
96
  if (withSeconds) {
90
- let nbSecondes = this.getNbSecondsRemainingOfDurationInSeconds(durationInSeconds);
91
- strSeconde += ' ';
92
- //strSeconde += sprintf('%02d', nbSecondes);
93
- strSeconde += nbSecondes.toString().padStart(2, '0');
97
+ let nbSeconds = this.remainingSeconds(seconds);
98
+ strSeconds += ' ';
94
99
  if (fullLabel) {
95
- strSeconde += ' seconde'+(nbSecondes>1?'s':'');
96
- }
97
- else {
98
- strSeconde += 's';
100
+ strSeconds += nbSeconds.toString() + ' seconde' + (nbSeconds > 1 ? 's' : '');
101
+ } else {
102
+ strSeconds += nbSeconds.toString().padStart(2, '0') + 's';
99
103
  }
100
104
  }
101
-
102
- return (strHeure+strMinute+strSeconde).trim();
105
+
106
+ return (strHours + strMinutes + strSeconds).trim();
103
107
  }
104
108
 
105
- static roundNbSeconds(durationInSeconds, roundPrecision, roundMode='close') {
106
- let hours = Math.floor(durationInSeconds / 3600);
107
- let minutes = Math.floor((durationInSeconds % 3600) / 60);
108
- let seconds = durationInSeconds % 60;
109
+ // -------------------------------------------------------------------------
110
+ // Seconds rounding
111
+ // -------------------------------------------------------------------------
109
112
 
110
- let hoursRounded = hours;
111
- let minutesRounded = minutes;
112
- let secondsRounded = seconds;
113
+ static roundSeconds(seconds, precision, roundMode = 'close') {
114
+ let hours = Math.floor(seconds / 3600);
115
+ let minutes = Math.floor((seconds % 3600) / 60);
116
+ let secs = seconds % 60;
113
117
 
114
- if (roundPrecision > 0) {
115
- let minutesRemaining = minutes % roundPrecision;
116
- let minutesRemainingAndSecondsAsCentieme = minutesRemaining + seconds/60;
117
- if (minutesRemainingAndSecondsAsCentieme === 0) {
118
- // pas d'arrondissement
119
- }
120
- else {
121
- let halfRoundPrecision = roundPrecision / 2;
122
- hoursRounded = hours;
118
+ let hoursRounded = hours;
119
+ let minutesRounded = minutes;
120
+ let secondsRounded = secs;
121
+
122
+ if (precision > 0) {
123
+ let minutesRemaining = minutes % precision;
124
+ let minutesRemainingAndSecondsAsFraction = minutesRemaining + secs / 60;
125
+ if (minutesRemainingAndSecondsAsFraction === 0) {
126
+ // already aligned, no rounding needed
127
+ } else {
128
+ let halfPrecision = precision / 2;
129
+ hoursRounded = hours;
123
130
  secondsRounded = 0;
124
- if (roundMode === 'up' || (roundMode === 'close' && minutesRemainingAndSecondsAsCentieme > halfRoundPrecision)) {
125
- // Arrondissement au dessus
126
- if (minutes > (60-roundPrecision)) {
131
+ if (roundMode === 'up' || (roundMode === 'close' && minutesRemainingAndSecondsAsFraction > halfPrecision)) {
132
+ // Round up
133
+ if (minutes > (60 - precision)) {
127
134
  minutesRounded = 0;
128
135
  hoursRounded++;
136
+ } else {
137
+ minutesRounded = (minutes - minutesRemaining) + precision;
129
138
  }
130
- else {
131
- minutesRounded = (minutes-minutesRemaining)+roundPrecision;
132
- }
133
- }
134
- else {
135
- // Arrondissement au dessous
136
- minutesRounded = (minutes-minutesRemaining);
139
+ } else {
140
+ // Round down
141
+ minutesRounded = minutes - minutesRemaining;
137
142
  }
138
143
  }
139
144
  }
140
- // console.log(element.data('duration_default'), durationInSeconds, hours, minutes, seconds, '->', secondsTotalRounded, hoursRounded, minutesRounded, secondsRounded);
145
+
141
146
  return hoursRounded * 3600 + minutesRounded * 60 + secondsRounded;
142
147
  }
143
148
 
144
- static getNbDaysOfDurationInSeconds(durationInSeconds) {
145
- return Math.floor(durationInSeconds / 86400);
146
- }
147
- static getNbHoursOfDurationInSeconds(durationInSeconds) {
148
- return Math.floor(durationInSeconds / 3600);
149
- }
150
- static getNbMinutesOfDurationInSeconds(durationInSeconds) {
151
- return Math.floor(durationInSeconds / 60);
149
+ // -------------------------------------------------------------------------
150
+ // Seconds total extraction
151
+ // -------------------------------------------------------------------------
152
+
153
+ static totalDays(seconds) {
154
+ return Math.floor(seconds / 86400);
152
155
  }
153
156
 
154
- /*static getNbMinutesRemaining(durationInSeconds) {
155
- var remander = ( durationInSeconds % 3600 ) - ( durationInSeconds % 60 );
156
- return ( remander / 60 );
157
+ static totalHours(seconds) {
158
+ return Math.floor(seconds / 3600);
157
159
  }
158
- static getNbHoursOfDurationInSeconds(durationInSeconds) {
159
- // return (this.getNbDaysOfDurationInSeconds(durationInSeconds)*24)+this.getNbHoursRemainingOfDurationInSeconds(durationInSeconds);
160
- return (durationInSeconds - (durationInSeconds % 3600)) / 3600;
160
+
161
+ static totalMinutes(seconds) {
162
+ return Math.floor(seconds / 60);
161
163
  }
162
- static getNbMinutesOfDurationInSeconds(durationInSeconds) {
163
- // return (this.getNbDaysOfDurationInSeconds(durationInSeconds)*24*60)+(this.getNbHoursRemainingOfDurationInSeconds(durationInSeconds)*60)+this.getNbMinutesRemainingOfDurationInSeconds(durationInSeconds);
164
- return (durationInSeconds - (durationInSeconds % 60)) / 60;
165
- }*/
166
164
 
167
- static getNbHoursRemainingOfDurationInSeconds(durationInSeconds) {
168
- return this.getNbHoursOfDurationInSeconds(durationInSeconds % 86400);
165
+ // -------------------------------------------------------------------------
166
+ // Seconds remaining extraction
167
+ // -------------------------------------------------------------------------
168
+
169
+ static remainingHours(seconds) {
170
+ return this.totalHours(seconds % 86400);
169
171
  }
170
- static getNbMinutesRemainingOfDurationInSeconds(durationInSeconds) {
171
- return this.getNbMinutesOfDurationInSeconds(durationInSeconds % 3600);
172
+
173
+ static remainingMinutes(seconds) {
174
+ return this.totalMinutes(seconds % 3600);
172
175
  }
173
- static getNbSecondsRemainingOfDurationInSeconds(durationInSeconds) {
174
- return durationInSeconds % 60;
176
+
177
+ static remainingSeconds(seconds) {
178
+ return seconds % 60;
175
179
  }
176
180
 
177
- // ---------- Durée en centième d'heure ----------
181
+ // -------------------------------------------------------------------------
182
+ // Decimal hours (hundredth of an hour)
183
+ // -------------------------------------------------------------------------
178
184
 
179
- static convertToDurationAsHundredthOfAnHour(durationInSeconds) {
180
- let hour = Math.floor(durationInSeconds / 3600);
181
- let minutes = durationInSeconds % 3600;
182
- minutes = Math.floor(minutes / 60);
183
- // minutes = minutes - (minutes % 60);
184
- let minCentieme = Math.round( (minutes / 60 ) * 100 );
185
- return hour+(minCentieme/100);
186
- //return parseFloat(hour+'.'+minCentieme);
185
+ static toDecimalHours(seconds) {
186
+ let hour = Math.floor(seconds / 3600);
187
+ let minutes = Math.floor((seconds % 3600) / 60);
188
+ let centieme = Math.round((minutes / 60) * 100);
189
+ return hour + (centieme / 100);
187
190
  }
188
191
 
189
- static getNbHoursOfHundredthOfAnHour(durationAsHundredthOfAnHour) {
190
- return Math.trunc(durationAsHundredthOfAnHour);
192
+ static getHoursFromDecimal(decimalHours) {
193
+ return Math.trunc(decimalHours);
191
194
  }
192
195
 
193
- static getNbMinutesOfHundredthOfAnHour(durationAsHundredthOfAnHour) {
194
- return Math.floor(Math.getDecimals(Number.roundDecimal(durationAsHundredthOfAnHour, 2)) / 100 * 60);
196
+ static getMinutesFromDecimal(decimalHours) {
197
+ const decimal = decimalHours - Math.floor(decimalHours);
198
+ return Math.floor(decimal * 60);
195
199
  }
196
200
 
201
+ // -------------------------------------------------------------------------
202
+ // Deprecated aliases — kept for backwards compatibility
203
+ // -------------------------------------------------------------------------
204
+
205
+ /** @deprecated Use {@link formatDays} instead */
206
+ static formatNbDays(nbDays, locale = 'fr-FR') { return this.formatDays(nbDays, locale); }
207
+ /** @deprecated Use {@link formatDaysIfPositive} instead */
208
+ static formatNbDaysIfPositive(nbDays) { return this.formatDaysIfPositive(nbDays); }
209
+ /** @deprecated Use {@link formatDaysWithColor} instead */
210
+ static formatNbDaysWithColor(nbDays) { return this.formatDaysWithColor(nbDays); }
211
+
212
+ /** @deprecated Use {@link parseTimeInputToSeconds} instead */
213
+ static convertInputTimeValueToDuration(inputTimeValue) { return this.parseTimeInputToSeconds(inputTimeValue); }
214
+ /** @deprecated Use {@link formatSecondsAsTimeInput} instead */
215
+ static convertToDurationAsInputTimeValue(durationInSeconds) { return this.formatSecondsAsTimeInput(durationInSeconds); }
216
+ /** @deprecated Use {@link formatSecondsAsChrono} instead */
217
+ static convertToDurationInHourChronoDisplay(durationInSeconds, displayMode = 'chrono') { return this.formatSecondsAsChrono(durationInSeconds, displayMode); }
218
+ /** @deprecated Use {@link formatSecondsAsString} instead */
219
+ static convertToDurationInHourStringDisplay(durationInSeconds, withSeconds = true, withMinutes = true, withMinuteLabel = true, fullLabel = false, hideHourIfZeroHour = false) { return this.formatSecondsAsString(durationInSeconds, withSeconds, withMinutes, withMinuteLabel, fullLabel, hideHourIfZeroHour); }
220
+ /** @deprecated Use {@link roundSeconds} instead */
221
+ static roundNbSeconds(durationInSeconds, roundPrecision, roundMode = 'close') { return this.roundSeconds(durationInSeconds, roundPrecision, roundMode); }
222
+
223
+ /** @deprecated Use {@link totalDays} instead */
224
+ static getNbDaysOfDurationInSeconds(durationInSeconds) { return this.totalDays(durationInSeconds); }
225
+ /** @deprecated Use {@link totalHours} instead */
226
+ static getNbHoursOfDurationInSeconds(durationInSeconds) { return this.totalHours(durationInSeconds); }
227
+ /** @deprecated Use {@link totalMinutes} instead */
228
+ static getNbMinutesOfDurationInSeconds(durationInSeconds) { return this.totalMinutes(durationInSeconds); }
229
+
230
+ /** @deprecated Use {@link remainingHours} instead */
231
+ static getNbHoursRemainingOfDurationInSeconds(durationInSeconds) { return this.remainingHours(durationInSeconds); }
232
+ /** @deprecated Use {@link remainingMinutes} instead */
233
+ static getNbMinutesRemainingOfDurationInSeconds(durationInSeconds) { return this.remainingMinutes(durationInSeconds); }
234
+ /** @deprecated Use {@link remainingSeconds} instead */
235
+ static getNbSecondsRemainingOfDurationInSeconds(durationInSeconds) { return this.remainingSeconds(durationInSeconds); }
236
+
237
+ /** @deprecated Use {@link toDecimalHours} instead */
238
+ static convertToDurationAsHundredthOfAnHour(durationInSeconds) { return this.toDecimalHours(durationInSeconds); }
239
+ /** @deprecated Use {@link getHoursFromDecimal} instead */
240
+ static getNbHoursOfHundredthOfAnHour(durationAsHundredthOfAnHour) { return this.getHoursFromDecimal(durationAsHundredthOfAnHour); }
241
+ /** @deprecated Use {@link getMinutesFromDecimal} instead */
242
+ static getNbMinutesOfHundredthOfAnHour(durationAsHundredthOfAnHour) { return this.getMinutesFromDecimal(durationAsHundredthOfAnHour); }
197
243
 
198
244
  }
199
245
 
package/event_bus.js CHANGED
@@ -30,9 +30,9 @@ class EventBus {
30
30
 
31
31
  if (!!handlers === false) {
32
32
  return;
33
- }
33
+ }
34
34
 
35
- handlers.splice(handlers.indexOf(handler));
35
+ handlers.splice(handlers.indexOf(handler), 1);
36
36
  }
37
37
  }
38
38
 
package/file.js CHANGED
@@ -52,7 +52,7 @@ class File {
52
52
  fileSizeInBytes = fileSizeInBytes / 1024;
53
53
  i++;
54
54
  }
55
- while (fileSizeInBytes > 1024);
55
+ while (fileSizeInBytes >= 1024);
56
56
  //var size = Math.max(fileSizeInBytes, 0.1).toFixed(fractionDigits);
57
57
  let size = Math.max(fileSizeInBytes, 0.1);
58
58
  return (new Intl.NumberFormat(locale, {
@@ -124,10 +124,25 @@ class Img {
124
124
  }
125
125
 
126
126
  static setBlobToImg(img, blob) {
127
- // img.attr('src', btoa(unescape(encodeURIComponent(data))));
128
- // img.attr('src', 'data:image/png;base64, '+btoa(unescape(encodeURIComponent(data))));
129
- let urlCreator = window.URL || window.webkitURL;
130
- img.attr('src', urlCreator.createObjectURL(blob));
127
+ // Validation de l'élément img
128
+ if (!img || !img.length) {
129
+ console.error('Invalid img element provided to setBlobToImg');
130
+ return;
131
+ }
132
+
133
+ // Validation du blob
134
+ if (!blob || !(blob instanceof Blob) || blob.size === 0) {
135
+ console.error('Invalid blob provided to setBlobToImg', blob);
136
+ return;
137
+ }
138
+
139
+ try {
140
+ let urlCreator = window.URL || window.webkitURL;
141
+ let objectURL = urlCreator.createObjectURL(blob);
142
+ img.attr('src', objectURL);
143
+ } catch (error) {
144
+ console.error('Error creating object URL from blob:', error);
145
+ }
131
146
  }
132
147
 
133
148
  static async getBase64FromUrl(url) {
package/form_helper.js CHANGED
@@ -294,7 +294,7 @@ class FormHelper {
294
294
  if (typeof errors[property] == 'function') {
295
295
  continue;
296
296
  }
297
- if (typeof errors[property]['error_description'] !== 'undefined') {
297
+ if (errors[property] != null && typeof errors[property]['error_description'] !== 'undefined') {
298
298
  errorLabels.push(errors[property]['error_description']);
299
299
  continue;
300
300
  }
package/google_charts.js CHANGED
@@ -77,6 +77,7 @@ class GoogleCharts {
77
77
  }
78
78
 
79
79
  let data = null;
80
+ let nbCells = 0;
80
81
  if (typeGraph === 'pie_chart') {
81
82
  //data = google.visualization.arrayToDataTable(tabDataAbsParam);
82
83
 
@@ -101,7 +102,7 @@ class GoogleCharts {
101
102
  });
102
103
 
103
104
  // Remplissage des données
104
- let nbCells = 0;
105
+ nbCells = 0;
105
106
  let numRow = 0;
106
107
  $.each(tabDataAbsParam, function(idx, dataAbs) {
107
108
  // dataOrd = tabDataOrd[idx];
package/http_client.js CHANGED
@@ -1,3 +1,5 @@
1
+ const { JwtSession } = require('./jwt');
2
+ const { UrlAndQueryString } = require('./network');
1
3
 
2
4
  class HTTPClient {
3
5
  static setAuthorizationToken(authorizationToken) {