@osimatic/helpers-js 1.4.23 → 1.4.25
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/.claude/settings.local.json +13 -0
- package/CHANGELOG +2 -1
- package/array.js +2 -2
- package/bank.js +3 -3
- package/chartjs.js +1 -1
- package/contact_details.js +2 -2
- package/date_time.js +25 -16
- package/draw.js +3 -2
- package/duration.js +12 -15
- package/event_bus.js +2 -2
- package/file.js +1 -1
- package/form_helper.js +1 -1
- package/http_client.js +2 -0
- package/jwt.js +18 -6
- package/location.js +6 -2
- package/media.js +1 -1
- package/number.js +2 -3
- package/package.json +28 -2
- package/social_network.js +5 -0
- package/string.js +11 -2
- package/tests/array.test.js +458 -0
- package/tests/bank.test.js +158 -0
- package/tests/chartjs.test.js +273 -0
- package/tests/contact_details.test.js +391 -0
- package/tests/date_time/DatePeriod.test.js +179 -0
- package/tests/date_time/DateTime.test.js +492 -0
- package/tests/date_time/SqlDate.test.js +205 -0
- package/tests/date_time/SqlDateTime.test.js +326 -0
- package/tests/date_time/SqlTime.test.js +162 -0
- package/tests/date_time/TimestampUnix.test.js +262 -0
- package/tests/draw.test.js +271 -0
- package/tests/duration.test.js +365 -0
- package/tests/event_bus.test.js +268 -0
- package/tests/file.test.js +358 -0
- package/tests/form_date.test.js +417 -0
- package/tests/form_helper.test.js +415 -0
- package/tests/http_client.test.js +570 -0
- package/tests/jwt.test.js +804 -0
- package/tests/location.test.js +509 -0
- package/tests/media.test.js +458 -0
- package/tests/network.test.js +489 -0
- package/tests/number.test.js +448 -0
- package/tests/open_street_map.test.js +388 -0
- package/tests/shopping_cart.test.js +355 -0
- package/tests/social_network.test.js +333 -0
- package/tests/string.test.js +473 -0
- package/tests/user.test.js +204 -0
- package/tests/util.test.js +99 -0
- package/tests/visitor.test.js +508 -0
- package/tmpclaude-00a6-cwd +1 -0
- package/tmpclaude-0526-cwd +1 -0
- package/tmpclaude-0973-cwd +1 -0
- package/tmpclaude-0b61-cwd +1 -0
- package/tmpclaude-0fa4-cwd +1 -0
- package/tmpclaude-104f-cwd +1 -0
- package/tmpclaude-1468-cwd +1 -0
- package/tmpclaude-146f-cwd +1 -0
- package/tmpclaude-223d-cwd +1 -0
- package/tmpclaude-2330-cwd +1 -0
- package/tmpclaude-282a-cwd +1 -0
- package/tmpclaude-2846-cwd +1 -0
- package/tmpclaude-28a6-cwd +1 -0
- package/tmpclaude-2b5a-cwd +1 -0
- package/tmpclaude-2def-cwd +1 -0
- package/tmpclaude-324b-cwd +1 -0
- package/tmpclaude-35d3-cwd +1 -0
- package/tmpclaude-3906-cwd +1 -0
- package/tmpclaude-3b32-cwd +1 -0
- package/tmpclaude-3da9-cwd +1 -0
- package/tmpclaude-3dc3-cwd +1 -0
- package/tmpclaude-3e3b-cwd +1 -0
- package/tmpclaude-43b6-cwd +1 -0
- package/tmpclaude-4495-cwd +1 -0
- package/tmpclaude-462f-cwd +1 -0
- package/tmpclaude-4aa8-cwd +1 -0
- package/tmpclaude-4b29-cwd +1 -0
- package/tmpclaude-4db5-cwd +1 -0
- package/tmpclaude-4e01-cwd +1 -0
- package/tmpclaude-5101-cwd +1 -0
- package/tmpclaude-524f-cwd +1 -0
- package/tmpclaude-5636-cwd +1 -0
- package/tmpclaude-5cdd-cwd +1 -0
- package/tmpclaude-5f1f-cwd +1 -0
- package/tmpclaude-6078-cwd +1 -0
- package/tmpclaude-622e-cwd +1 -0
- package/tmpclaude-6802-cwd +1 -0
- package/tmpclaude-6e36-cwd +1 -0
- package/tmpclaude-7793-cwd +1 -0
- package/tmpclaude-7f96-cwd +1 -0
- package/tmpclaude-8566-cwd +1 -0
- package/tmpclaude-8874-cwd +1 -0
- package/tmpclaude-8915-cwd +1 -0
- package/tmpclaude-8c8b-cwd +1 -0
- package/tmpclaude-94df-cwd +1 -0
- package/tmpclaude-9859-cwd +1 -0
- package/tmpclaude-9ac5-cwd +1 -0
- package/tmpclaude-9f18-cwd +1 -0
- package/tmpclaude-a202-cwd +1 -0
- package/tmpclaude-a741-cwd +1 -0
- package/tmpclaude-ab5f-cwd +1 -0
- package/tmpclaude-b008-cwd +1 -0
- package/tmpclaude-b0a1-cwd +1 -0
- package/tmpclaude-b63d-cwd +1 -0
- package/tmpclaude-b681-cwd +1 -0
- package/tmpclaude-b72d-cwd +1 -0
- package/tmpclaude-b92f-cwd +1 -0
- package/tmpclaude-bc49-cwd +1 -0
- package/tmpclaude-bc50-cwd +1 -0
- package/tmpclaude-bccf-cwd +1 -0
- package/tmpclaude-be55-cwd +1 -0
- package/tmpclaude-c228-cwd +1 -0
- package/tmpclaude-c717-cwd +1 -0
- package/tmpclaude-c7ce-cwd +1 -0
- package/tmpclaude-cf3e-cwd +1 -0
- package/tmpclaude-d142-cwd +1 -0
- package/tmpclaude-d5bc-cwd +1 -0
- package/tmpclaude-d6ae-cwd +1 -0
- package/tmpclaude-d77a-cwd +1 -0
- package/tmpclaude-d8da-cwd +1 -0
- package/tmpclaude-dbdb-cwd +1 -0
- package/tmpclaude-de61-cwd +1 -0
- package/tmpclaude-de81-cwd +1 -0
- package/tmpclaude-df9d-cwd +1 -0
- package/tmpclaude-e786-cwd +1 -0
- package/tmpclaude-f01d-cwd +1 -0
- package/tmpclaude-f2a9-cwd +1 -0
- package/tmpclaude-fc36-cwd +1 -0
- package/tmpclaude-ffef-cwd +1 -0
- package/visitor.js +2 -2
package/CHANGELOG
CHANGED
|
@@ -79,4 +79,5 @@ PostalAddress.setAutocomplete(input, onChange(formatted_address)) -> PostalAddre
|
|
|
79
79
|
|
|
80
80
|
1.4.0
|
|
81
81
|
new OpenStreetMap(id) -> new OpenStreetMap(element)
|
|
82
|
-
OpenStreetMap.centerOnFrance -> OpenStreetMap.centerMapOnCountry('FR')
|
|
82
|
+
OpenStreetMap.centerOnFrance -> OpenStreetMap.centerMapOnCountry('FR')
|
|
83
|
+
const flagsPath = 'xxx'; -> Country.setFlagsPath('xxx');
|
package/array.js
CHANGED
|
@@ -31,7 +31,7 @@ Array.prototype.unique = function() {
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
Array.prototype.removeEmptyValues = function() {
|
|
34
|
-
return this.filter(val => val
|
|
34
|
+
return this.filter(val => val !== '');
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
Array.prototype.hasOwnIndex = function(prop) {
|
|
@@ -64,7 +64,7 @@ Array.generate = ({from = 0, to, step = 1, length = Math.ceil((to - from) / step
|
|
|
64
64
|
|
|
65
65
|
Array.getValuesByKeyInArrayOfArrays = function(array, key) {
|
|
66
66
|
let listeValues = [];
|
|
67
|
-
for (let i
|
|
67
|
+
for (let i = 0; i < array.length; i++) {
|
|
68
68
|
let subArray = array[i];
|
|
69
69
|
if (typeof(subArray[key]) != 'undefined') {
|
|
70
70
|
listeValues.push(subArray[key]);
|
package/bank.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
class IBAN {
|
|
2
2
|
static format(iban) {
|
|
3
|
-
return iban.replace(/[^\dA-Z]/g, '').replace(/(.{4})/g, '$1 ').trim();
|
|
3
|
+
return iban.toUpperCase().replace(/[^\dA-Z]/g, '').replace(/(.{4})/g, '$1 ').trim();
|
|
4
4
|
}
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
class BankCard {
|
|
8
|
-
static formatCardNumber(cardNumber) {
|
|
8
|
+
static formatCardNumber(cardNumber, hiddenChar='*') {
|
|
9
9
|
if (cardNumber.length === 16) {
|
|
10
10
|
cardNumber = cardNumber.substring(0, 4)+'-'+cardNumber.substring(4, 8)+'-'+cardNumber.substring(8, 12)+'-'+cardNumber.substring(12, 16);
|
|
11
|
-
cardNumber = cardNumber.replace(/
|
|
11
|
+
cardNumber = cardNumber.replace(/[*X]/gi, hiddenChar);
|
|
12
12
|
}
|
|
13
13
|
return cardNumber;
|
|
14
14
|
}
|
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/contact_details.js
CHANGED
|
@@ -4,10 +4,10 @@ class PersonName {
|
|
|
4
4
|
static format(firstName, lastName) {
|
|
5
5
|
let str = '';
|
|
6
6
|
if (firstName != null && firstName !== '') {
|
|
7
|
-
str += ' '+firstName;
|
|
7
|
+
str += ' '+firstName.trim();
|
|
8
8
|
}
|
|
9
9
|
if (lastName != null && lastName !== '') {
|
|
10
|
-
str += ' '+lastName;
|
|
10
|
+
str += ' '+lastName.trim();
|
|
11
11
|
}
|
|
12
12
|
return str.trim();
|
|
13
13
|
}
|
package/date_time.js
CHANGED
|
@@ -206,9 +206,7 @@ class DateTime {
|
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
static getLastDayOfYear(date) {
|
|
209
|
-
date.
|
|
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,
|
|
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 (!
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
@@ -72,30 +72,24 @@ class Duration {
|
|
|
72
72
|
if (withMinutes) {
|
|
73
73
|
let nbMinutes = this.getNbMinutesRemainingOfDurationInSeconds(durationInSeconds);
|
|
74
74
|
strMinute += ' ';
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
strMinute += 'min';
|
|
83
|
-
}
|
|
75
|
+
if (fullLabel) {
|
|
76
|
+
strMinute += nbMinutes.toString()+(withMinuteLabel ? ' minute'+(nbMinutes>1?'s':'') : '');
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
strMinute += nbMinutes.toString().padStart(2, '0')+(withMinuteLabel ? 'min' : '');
|
|
84
80
|
}
|
|
85
81
|
}
|
|
86
|
-
|
|
82
|
+
|
|
87
83
|
// Secondes
|
|
88
84
|
let strSeconde = '';
|
|
89
85
|
if (withSeconds) {
|
|
90
86
|
let nbSecondes = this.getNbSecondsRemainingOfDurationInSeconds(durationInSeconds);
|
|
91
87
|
strSeconde += ' ';
|
|
92
|
-
//strSeconde += sprintf('%02d', nbSecondes);
|
|
93
|
-
strSeconde += nbSecondes.toString().padStart(2, '0');
|
|
94
88
|
if (fullLabel) {
|
|
95
|
-
strSeconde += ' seconde'+(nbSecondes>1?'s':'');
|
|
89
|
+
strSeconde += nbSecondes.toString()+' seconde'+(nbSecondes>1?'s':'');
|
|
96
90
|
}
|
|
97
91
|
else {
|
|
98
|
-
strSeconde += 's';
|
|
92
|
+
strSeconde += nbSecondes.toString().padStart(2, '0')+'s';
|
|
99
93
|
}
|
|
100
94
|
}
|
|
101
95
|
|
|
@@ -191,7 +185,10 @@ class Duration {
|
|
|
191
185
|
}
|
|
192
186
|
|
|
193
187
|
static getNbMinutesOfHundredthOfAnHour(durationAsHundredthOfAnHour) {
|
|
194
|
-
|
|
188
|
+
// Extraire la partie décimale et convertir en minutes
|
|
189
|
+
// Ex: 1.5h -> 0.5 * 60 = 30 minutes
|
|
190
|
+
const decimalPart = durationAsHundredthOfAnHour - Math.floor(durationAsHundredthOfAnHour);
|
|
191
|
+
return Math.floor(decimalPart * 60);
|
|
195
192
|
}
|
|
196
193
|
|
|
197
194
|
|
package/event_bus.js
CHANGED
package/file.js
CHANGED
|
@@ -52,7 +52,7 @@ class File {
|
|
|
52
52
|
fileSizeInBytes = fileSizeInBytes / 1024;
|
|
53
53
|
i++;
|
|
54
54
|
}
|
|
55
|
-
while (fileSizeInBytes
|
|
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, {
|
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/http_client.js
CHANGED
package/jwt.js
CHANGED
|
@@ -2,9 +2,15 @@ class JwtToken {
|
|
|
2
2
|
static parseJwt (token) {
|
|
3
3
|
let base64Url = token.split('.')[1];
|
|
4
4
|
let base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
|
|
5
|
-
let jsonPayload
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
let jsonPayload;
|
|
6
|
+
try {
|
|
7
|
+
jsonPayload = decodeURIComponent(atob(base64).split('').map(function(c) {
|
|
8
|
+
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
|
9
|
+
}).join(''));
|
|
10
|
+
} catch (e) {
|
|
11
|
+
// Fallback for characters that can't be decoded
|
|
12
|
+
jsonPayload = atob(base64);
|
|
13
|
+
}
|
|
8
14
|
|
|
9
15
|
return JSON.parse(jsonPayload);
|
|
10
16
|
}
|
|
@@ -75,7 +81,9 @@ class JwtSession {
|
|
|
75
81
|
static login(data, redirectUrl, onComplete) {
|
|
76
82
|
console.log('JwtSession.login()');
|
|
77
83
|
JwtSession.setToken(data['access_token'] || data['token']);
|
|
78
|
-
|
|
84
|
+
if (data['refresh_token'] != null) {
|
|
85
|
+
JwtSession.setRefreshToken(data['refresh_token']);
|
|
86
|
+
}
|
|
79
87
|
|
|
80
88
|
JwtSession.removeItemInStorage('real_users');
|
|
81
89
|
|
|
@@ -191,7 +199,9 @@ class JwtSession {
|
|
|
191
199
|
|
|
192
200
|
// on enregistre la session de l'utilisateur simulé
|
|
193
201
|
JwtSession.setToken(loginData['access_token'] || loginData['token']);
|
|
194
|
-
|
|
202
|
+
if (loginData['refresh_token'] != null) {
|
|
203
|
+
JwtSession.setRefreshToken(loginData['refresh_token']);
|
|
204
|
+
}
|
|
195
205
|
|
|
196
206
|
if (typeof onComplete == 'function') {
|
|
197
207
|
onComplete();
|
|
@@ -216,7 +226,9 @@ class JwtSession {
|
|
|
216
226
|
JwtSession.setItemInStorage('real_users', JSON.stringify(realUsers));
|
|
217
227
|
|
|
218
228
|
JwtSession.setToken(loginData['access_token'] || loginData['token']);
|
|
219
|
-
|
|
229
|
+
if (loginData['refresh_token'] != null) {
|
|
230
|
+
JwtSession.setRefreshToken(loginData['refresh_token']);
|
|
231
|
+
}
|
|
220
232
|
|
|
221
233
|
if (typeof onComplete == 'function') {
|
|
222
234
|
onComplete();
|
package/location.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
|
|
2
2
|
class Country {
|
|
3
|
+
static setFlagsPath(flagsPath) {
|
|
4
|
+
Country.flagsPath = flagsPath;
|
|
5
|
+
}
|
|
6
|
+
|
|
3
7
|
static getFlagPath(countryCode) {
|
|
4
|
-
return flagsPath+countryCode.toLowerCase()+'.png';
|
|
8
|
+
return (typeof Country.flagsPath != 'undefined' ? Country.flagsPath : '/')+countryCode.toLowerCase()+'.png';
|
|
5
9
|
}
|
|
6
10
|
static getFlagImg(countryCode) {
|
|
7
11
|
return '<span><img src="'+Country.getFlagPath(countryCode)+'" alt="" title="'+Country.getCountryName(countryCode)+'" class="flag" /></span>'
|
|
@@ -613,7 +617,7 @@ class GeographicCoordinates {
|
|
|
613
617
|
return null;
|
|
614
618
|
}
|
|
615
619
|
|
|
616
|
-
return asString ?
|
|
620
|
+
return asString ? lat+','+long : [lat, long];
|
|
617
621
|
}
|
|
618
622
|
|
|
619
623
|
static toFixed(latOrLong, fractionDigit=6) {
|
package/media.js
CHANGED
|
@@ -137,7 +137,7 @@ class VideoMedia {
|
|
|
137
137
|
//Source : https://www.npmjs.com/package/mic-check
|
|
138
138
|
class UserMedia {
|
|
139
139
|
static hasGetUserMedia() {
|
|
140
|
-
return !!(navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia);
|
|
140
|
+
return !!(typeof navigator !== 'undefined' && (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia));
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
/** SystemPermissionDenied => (macOS) browser does not have permission to access cam/mic */
|
package/number.js
CHANGED
|
@@ -78,11 +78,10 @@ Number.padLeft2 = Number.padLeft2 || function(n) {
|
|
|
78
78
|
return n > 9 ? "" + n : "0" + n;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
Number.prototype.roundDecimal = Number.prototype.roundDecimal || function(precision) {
|
|
81
|
+
Number.prototype.roundDecimal = Number.prototype.roundDecimal || function(precision=2) {
|
|
82
82
|
return Number.roundDecimal(this, precision);
|
|
83
83
|
}
|
|
84
|
-
Number.roundDecimal = Number.roundDecimal || function(number, precision) {
|
|
85
|
-
precision = precision || 2;
|
|
84
|
+
Number.roundDecimal = Number.roundDecimal || function(number, precision=2) {
|
|
86
85
|
let tmp = Math.pow(10, precision);
|
|
87
86
|
return Math.round(number*tmp) / tmp;
|
|
88
87
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@osimatic/helpers-js",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.25",
|
|
4
4
|
"main": "main.js",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"test": "
|
|
6
|
+
"test": "jest",
|
|
7
|
+
"test:watch": "jest --watch",
|
|
8
|
+
"test:coverage": "jest --coverage",
|
|
9
|
+
"test:verbose": "jest --verbose"
|
|
7
10
|
},
|
|
8
11
|
"keywords": [],
|
|
9
12
|
"author": "",
|
|
@@ -11,5 +14,28 @@
|
|
|
11
14
|
"description": "",
|
|
12
15
|
"dependencies": {
|
|
13
16
|
"ilib": "^14.16.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"jest": "^30.2.0",
|
|
20
|
+
"whatwg-fetch": "^3.6.20"
|
|
21
|
+
},
|
|
22
|
+
"jest": {
|
|
23
|
+
"testEnvironment": "node",
|
|
24
|
+
"testMatch": [
|
|
25
|
+
"**/tests/**/*.test.js"
|
|
26
|
+
],
|
|
27
|
+
"collectCoverageFrom": [
|
|
28
|
+
"*.js",
|
|
29
|
+
"!main.js",
|
|
30
|
+
"!index.js",
|
|
31
|
+
"!node_modules/**",
|
|
32
|
+
"!tests/**"
|
|
33
|
+
],
|
|
34
|
+
"coverageDirectory": "coverage",
|
|
35
|
+
"coverageReporters": [
|
|
36
|
+
"text",
|
|
37
|
+
"lcov",
|
|
38
|
+
"html"
|
|
39
|
+
]
|
|
14
40
|
}
|
|
15
41
|
}
|
package/social_network.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require('./string');
|
|
2
|
+
|
|
1
3
|
class SocialNetwork {
|
|
2
4
|
|
|
3
5
|
// ---------- Facebook ----------
|
|
@@ -40,6 +42,9 @@ class SocialNetwork {
|
|
|
40
42
|
/*
|
|
41
43
|
<a target="_blank" title="Twitter" href="https://twitter.com/share?url=<?php the_permalink(); ?>&text=<?php the_title(); ?>&via=korben" rel="nofollow" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=400,width=700');return false;"><img src="http://korben.info/wp-content/themes/korben2013/hab/twitter_icon.png" alt="Twitter" /></a>
|
|
42
44
|
*/
|
|
45
|
+
if (typeof text === 'string' && typeof text.escapeHtml === 'function') {
|
|
46
|
+
text = text.escapeHtml();
|
|
47
|
+
}
|
|
43
48
|
return ''
|
|
44
49
|
+'<a href="https://twitter.com/share" class="twitter-share-button" data-url="'+url+'" data-text="'+text+'" data-lang="'+lang+'" data-hashtags="'+hashtags+'">Tweeter</a>'
|
|
45
50
|
+'<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>'
|
package/string.js
CHANGED
|
@@ -31,7 +31,7 @@ String.prototype.reverseString = String.prototype.reverseString || function() {
|
|
|
31
31
|
|
|
32
32
|
String.prototype.truncateOnWord = String.prototype.truncateOnWord || function(limit, fromLeft) {
|
|
33
33
|
if (fromLeft) {
|
|
34
|
-
return this.reverseString(
|
|
34
|
+
return this.reverseString().truncateOnWord(limit, false).reverseString();
|
|
35
35
|
}
|
|
36
36
|
let TRIM_CHARS = '\u0009\u000A\u000B\u000C\u000D\u0020\u00A0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u2028\u2029\u3000\uFEFF';
|
|
37
37
|
let words = this.split(RegExp('(?=['+TRIM_CHARS+'])'));
|
|
@@ -62,15 +62,24 @@ String.prototype.truncateString = String.prototype.truncateString || function(le
|
|
|
62
62
|
switch(from) {
|
|
63
63
|
case 'left':
|
|
64
64
|
str2 = split ? this.truncateOnWord(length, true) : this.slice(this.length - length);
|
|
65
|
+
if (split) {
|
|
66
|
+
str2 = str2.trimStart();
|
|
67
|
+
return ellipsis + ' ' + str2;
|
|
68
|
+
}
|
|
65
69
|
return ellipsis + str2;
|
|
66
70
|
case 'middle':
|
|
67
71
|
len1 = Math.ceil(length / 2);
|
|
68
72
|
len2 = Math.floor(length / 2);
|
|
69
73
|
str1 = split ? this.truncateOnWord(len1) : this.slice(0, len1);
|
|
70
74
|
str2 = split ? this.truncateOnWord(len2, true) : this.slice(this.length - len2);
|
|
71
|
-
|
|
75
|
+
// Enlever les espaces de fin de str1 et de début de str2 pour éviter les doubles espaces
|
|
76
|
+
return str1.trimEnd() + ' ' + ellipsis + ' ' + str2.trimStart();
|
|
72
77
|
default:
|
|
73
78
|
str1 = split ? this.truncateOnWord(length) : this.slice(0, length);
|
|
79
|
+
if (split) {
|
|
80
|
+
str1 = str1.trimEnd();
|
|
81
|
+
return str1 + ' ' + ellipsis;
|
|
82
|
+
}
|
|
74
83
|
return str1 + ellipsis;
|
|
75
84
|
}
|
|
76
85
|
};
|