@osimatic/helpers-js 1.1.3 → 1.1.5

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/date_time.js CHANGED
@@ -1,59 +1,67 @@
1
1
 
2
2
  class DateTimeFormatter {
3
3
  static getDateDigitalFormatter(locale, timeZone) {
4
- if (this.dateDigitalFormatter == null) {
5
- this.dateDigitalFormatter = new Intl.DateTimeFormat(locale, { year: 'numeric', month: 'numeric', day: 'numeric', timeZone: timeZone });
4
+ this.dateDigitalFormatter = this.dateDigitalFormatter || {};
5
+ if (typeof this.dateDigitalFormatter[timeZone+locale] == 'undefined') {
6
+ this.dateDigitalFormatter[timeZone+locale] = new Intl.DateTimeFormat(locale, { year: 'numeric', month: 'numeric', day: 'numeric', timeZone: timeZone });
6
7
  }
7
8
 
8
- return this.dateDigitalFormatter;
9
+ return this.dateDigitalFormatter[timeZone+locale];
9
10
  }
10
11
 
11
12
  static getDateTextFormatter(locale, timeZone) {
12
- if (this.dateTextFormatter == null) {
13
- this.dateTextFormatter = new Intl.DateTimeFormat(locale, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', timeZone: timeZone });
13
+ this.dateTextFormatter = this.dateTextFormatter || {};
14
+ if (typeof this.dateTextFormatter[timeZone+locale] == 'undefined') {
15
+ this.dateTextFormatter[timeZone+locale] = new Intl.DateTimeFormat(locale, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', timeZone: timeZone });
14
16
  }
15
17
 
16
- return this.dateTextFormatter;
18
+ return this.dateTextFormatter[timeZone+locale];
17
19
  }
18
20
 
19
21
  static getDateTimeFormatter(locale, timeZone) {
20
- if (this.dateTimeFormatter == null) {
21
- this.dateTimeFormatter = new Intl.DateTimeFormat(locale, { year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric', timeZone: timeZone });
22
+ this.dateTimeFormatter = this.dateTimeFormatter || {};
23
+ if (typeof this.dateTimeFormatter[timeZone+locale] == 'undefined') {
24
+ this.dateTimeFormatter[timeZone+locale] = new Intl.DateTimeFormat(locale, { year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric', timeZone: timeZone });
22
25
  }
23
26
 
24
- return this.dateTimeFormatter;
27
+ return this.dateTimeFormatter[timeZone+locale];
25
28
  }
26
29
 
27
30
  static getDateSqlFormatter(timeZone) {
28
- if (this.dateSqlFormatter == null) {
29
- this.dateSqlFormatter = new Intl.DateTimeFormat('fr-CA', { year: 'numeric', month: '2-digit', day: '2-digit', timeZone: timeZone });
31
+ this.dateSqlFormatter = this.dateSqlFormatter || {};
32
+ if (typeof this.dateSqlFormatter[timeZone] == 'undefined') {
33
+ this.dateSqlFormatter[timeZone] = new Intl.DateTimeFormat('fr-CA', { year: 'numeric', month: '2-digit', day: '2-digit', timeZone: timeZone });
30
34
  }
31
35
 
32
- return this.dateSqlFormatter;
36
+ return this.dateSqlFormatter[timeZone];
33
37
  }
34
38
 
35
39
  static getTimeSqlFormatter(timeZone) {
36
- if (this.timeSqlFormatter == null) {
37
- this.timeSqlFormatter = new Intl.DateTimeFormat('en-GB', { hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: false, timeZone: timeZone }); //hour12: false = 24h format
40
+ this.timeSqlFormatter = this.timeSqlFormatter || {};
41
+ if (typeof this.timeSqlFormatter[timeZone] == 'undefined') {
42
+ console.log('init getTimeSqlFormatter avec timezone', timeZone);
43
+ this.timeSqlFormatter[timeZone] = new Intl.DateTimeFormat('en-GB', { hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: false, timeZone: timeZone }); //hour12: false = 24h format
38
44
  }
39
45
 
40
- return this.timeSqlFormatter;
46
+ return this.timeSqlFormatter[timeZone];
41
47
  }
42
48
 
43
49
  static getTimeFormatter(locale, timeZone) {
44
- if (this.timeFormatter == null) {
45
- this.timeFormatter = new Intl.DateTimeFormat(locale, { hour: 'numeric', minute: 'numeric', timeZone: timeZone });
50
+ this.timeFormatter = this.timeFormatter || {};
51
+ if (typeof this.timeFormatter[timeZone+locale] == 'undefined') {
52
+ this.timeFormatter[timeZone+locale] = new Intl.DateTimeFormat(locale, { hour: 'numeric', minute: 'numeric', timeZone: timeZone });
46
53
  }
47
54
 
48
- return this.timeFormatter;
55
+ return this.timeFormatter[timeZone+locale];
49
56
  }
50
57
 
51
58
  static getTimeDigitalFormatter(locale, timeZone) {
52
- if (this.timeDigitalFormatter == null) {
53
- this.timeDigitalFormatter = new Intl.DateTimeFormat(locale, { hour: '2-digit', minute: '2-digit', second: '2-digit', timeZone: timeZone });
59
+ this.timeDigitalFormatter = this.timeDigitalFormatter || {};
60
+ if (typeof this.timeDigitalFormatter[timeZone+locale] == 'undefined') {
61
+ this.timeDigitalFormatter[timeZone+locale] = new Intl.DateTimeFormat(locale, { hour: '2-digit', minute: '2-digit', second: '2-digit', timeZone: timeZone });
54
62
  }
55
63
 
56
- return this.timeDigitalFormatter;
64
+ return this.timeDigitalFormatter[timeZone+locale];
57
65
  }
58
66
  }
59
67
 
package/http_client.js CHANGED
@@ -184,8 +184,9 @@ class HTTPClient {
184
184
  let body = null;
185
185
  method = method.toUpperCase();
186
186
 
187
+ let headers = HTTPClient.getHeaders();
187
188
  if ('PATCH' === method) {
188
- HTTPClient.setHeader('Content-Type', 'application/x-www-form-urlencoded');
189
+ headers.append('Content-Type', 'application/x-www-form-urlencoded');
189
190
  body = new URLSearchParams(HTTPClient.formatFormData(data)).toString();
190
191
  }
191
192
  else if ('POST' === method) {
@@ -197,7 +198,7 @@ class HTTPClient {
197
198
  }
198
199
 
199
200
  const requestOptions = {
200
- headers: HTTPClient.getHeaders(),
201
+ headers: headers,
201
202
  mode: 'cors',
202
203
  cache: 'no-cache',
203
204
  method,
@@ -223,27 +224,27 @@ class HTTPClient {
223
224
  }
224
225
 
225
226
  if (response.ok) {
226
- if (typeof successCallback != 'undefined' && successCallback != null) {
227
+ if (typeof successCallback == 'function') {
227
228
  successCallback(jsonData, response);
228
229
  }
229
230
  return;
230
231
  }
231
232
 
232
- if (response.status === 400 && typeof formErrorCallback != 'undefined' && formErrorCallback != null) {
233
+ if (response.status === 400 && typeof formErrorCallback == 'function') {
233
234
  formErrorCallback(jsonData, response);
234
235
  return;
235
236
  }
236
237
  }
237
238
  catch (e) {
238
239
  console.error(e);
239
- if (typeof errorCallback != 'undefined' && errorCallback != null) {
240
+ if (typeof errorCallback == 'function') {
240
241
  errorCallback(response);
241
242
  }
242
243
  return;
243
244
  }
244
245
 
245
246
  HTTPClient.logRequestFailure(response, jsonData);
246
- if (typeof errorCallback != 'undefined' && errorCallback != null) {
247
+ if (typeof errorCallback == 'function') {
247
248
  errorCallback(response, jsonData);
248
249
  }
249
250
  }
@@ -264,8 +265,9 @@ class HTTPClient {
264
265
  let body = null;
265
266
  method = method.toUpperCase();
266
267
 
268
+ let headers = HTTPClient.getHeaders();
267
269
  if ('PATCH' === method) {
268
- HTTPClient.setHeader('Content-Type', 'application/x-www-form-urlencoded');
270
+ headers.append('Content-Type', 'application/x-www-form-urlencoded');
269
271
  body = new URLSearchParams(HTTPClient.formatFormData(data)).toString();
270
272
  }
271
273
  else if ('POST' === method) {
@@ -278,7 +280,7 @@ class HTTPClient {
278
280
 
279
281
  const requestOptions = {
280
282
  method: method,
281
- headers: HTTPClient.getHeaders(),
283
+ headers: headers,
282
284
  body: body,
283
285
  mode: 'cors',
284
286
  cache: 'no-cache'
@@ -298,24 +300,24 @@ class HTTPClient {
298
300
 
299
301
  if (response.ok) {
300
302
  const blobData = await response.blob();
301
- if (typeof successCallback != 'undefined' && successCallback != null) {
303
+ if (typeof successCallback == 'function') {
302
304
  successCallback(blobData, response);
303
305
  }
304
306
  }
305
307
  else {
306
308
  HTTPClient.logRequestFailure(response, null);
307
- if (typeof errorCallback != 'undefined' && errorCallback != null) {
309
+ if (typeof errorCallback == 'function') {
308
310
  errorCallback(response);
309
311
  }
310
312
  }
311
313
  }
312
314
  catch (e) {
313
315
  console.error(e);
314
- if (typeof errorCallback != 'undefined' && errorCallback != null) {
316
+ if (typeof errorCallback == 'function') {
315
317
  errorCallback(response);
316
318
  }
317
319
  }
318
- if (typeof completeCallback != 'undefined' && completeCallback != null) {
320
+ if (typeof completeCallback == 'function') {
319
321
  completeCallback(response);
320
322
  }
321
323
  }
@@ -366,7 +368,7 @@ class HTTPClient {
366
368
  },
367
369
  () => {
368
370
  JwtSession.expireSession(HTTPClient.onInvalidRefreshTokenRedirectUrl, HTTPClient.onInvalidRefreshTokenCallback);
369
- if (typeof errorCallback != 'undefined' && errorCallback != null) {
371
+ if (typeof errorCallback == 'function') {
370
372
  errorCallback();
371
373
  }
372
374
  }
@@ -394,7 +396,7 @@ class HTTPClient {
394
396
  xhr.onreadystatechange = function () {
395
397
  if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
396
398
  let data;
397
- if (formatRetour == 'xml') {
399
+ if (formatRetour === 'xml') {
398
400
  data = xhr.responseXML;
399
401
  }
400
402
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"