@osimatic/helpers-js 1.0.107 → 1.0.109

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 (2) hide show
  1. package/network.js +29 -40
  2. package/package.json +1 -1
package/network.js CHANGED
@@ -29,7 +29,18 @@ class Cookie {
29
29
 
30
30
  class UrlAndQueryString {
31
31
  static displayUrl(url, withLink) {
32
- return '<a href="'+url+'">'+UrlAndQueryString.getHost(url, false)+'</a>';
32
+ withLink = typeof withLink == 'undefined' ? true : withLink;
33
+ return (withLink ? '<a href="' + url + '">' : '') + UrlAndQueryString.getHost(url, false) + (withLink ? '</a>' : '');
34
+ }
35
+
36
+ static displayUrlAndPath(url, withLink, displayPathIfEmpty) {
37
+ withLink = typeof withLink == 'undefined' ? true : withLink;
38
+ displayPathIfEmpty = typeof displayPathIfEmpty == 'undefined' ? false : displayPathIfEmpty;
39
+ let formattedUrl = UrlAndQueryString.getHostAndPath(url, false);
40
+ if (!displayPathIfEmpty && UrlAndQueryString.getPath(url) === '/') {
41
+ formattedUrl = formattedUrl.slice(-1) === '/' ? formattedUrl.slice(0, -1) : formattedUrl;
42
+ }
43
+ return (withLink ? '<a href="' + url + '">' : '') + formattedUrl + (withLink ? '</a>' : '');
33
44
  }
34
45
 
35
46
  static getHost(url, withProtocol) {
@@ -38,7 +49,7 @@ class UrlAndQueryString {
38
49
  return withProtocol ? window.location.origin : window.location.host;
39
50
  }
40
51
  url = new URL(url);
41
- return (withProtocol?url.protocol+'//':'') + url.host;
52
+ return (withProtocol ? url.protocol + '//' : '') + url.host;
42
53
  }
43
54
 
44
55
  static getPath(url) {
@@ -83,6 +94,7 @@ class UrlAndQueryString {
83
94
  params[name] = value;
84
95
  return decodeURI($.param(params));
85
96
  }
97
+
86
98
  static setParamOfUrl(name, value, url) {
87
99
  let queryString = UrlAndQueryString.setParam(UrlAndQueryString.getQueryString(url), name, value);
88
100
  return UrlAndQueryString.getHostAndPath(url) + '?' + queryString;
@@ -97,10 +109,12 @@ class UrlAndQueryString {
97
109
  //params[name] = null;
98
110
  //return $.param(params);
99
111
  }
112
+
100
113
  static deleteParamOfUrl(name, url) {
101
114
  let queryString = UrlAndQueryString.deleteParam(UrlAndQueryString.getQueryString(url), name);
102
115
  return UrlAndQueryString.getHostAndPath(url) + '?' + queryString;
103
116
  }
117
+
104
118
  static deleteParamsOfUrl(names, url) {
105
119
  let queryString = UrlAndQueryString.getQueryString(url);
106
120
  names.forEach((name => queryString = UrlAndQueryString.deleteParam(queryString, name)));
@@ -232,23 +246,6 @@ class UrlAndQueryString {
232
246
  }
233
247
 
234
248
 
235
-
236
-
237
-
238
-
239
-
240
-
241
-
242
-
243
-
244
-
245
-
246
-
247
-
248
-
249
-
250
-
251
-
252
249
  // deprecated
253
250
 
254
251
  /** @deprecated **/
@@ -309,6 +306,7 @@ class UrlAndQueryString {
309
306
  }
310
307
 
311
308
  }
309
+
312
310
  /** @deprecated */
313
311
  class HTTPRequest {
314
312
  static init() {
@@ -377,13 +375,11 @@ class HTTPRequest {
377
375
  root = root || '';
378
376
  if (data instanceof File) {
379
377
  formData.append(root, data);
380
- }
381
- else if (Array.isArray(data)) {
378
+ } else if (Array.isArray(data)) {
382
379
  for (var i = 0; i < data.length; i++) {
383
380
  appendFormData(data[i], root + '[' + i + ']');
384
381
  }
385
- }
386
- else if (typeof data === 'object' && data) {
382
+ } else if (typeof data === 'object' && data) {
387
383
  for (var key in data) {
388
384
  if (data.hasOwnProperty(key)) {
389
385
  if (root === '') {
@@ -393,8 +389,7 @@ class HTTPRequest {
393
389
  }
394
390
  }
395
391
  }
396
- }
397
- else {
392
+ } else {
398
393
  if (data !== null && typeof data !== 'undefined') {
399
394
  formData.append(root, data);
400
395
  }
@@ -427,11 +422,11 @@ class HTTPRequest {
427
422
  }
428
423
 
429
424
  static logRequestFailure(response, json) {
430
- console.error('Request failure. Status: '+response.statusText+' ; HTTP Code : '+response.status, json);
425
+ console.error('Request failure. Status: ' + response.statusText + ' ; HTTP Code : ' + response.status, json);
431
426
  }
432
427
 
433
428
  static logJqueryRequestFailure(jqxhr, status, errorThrown) {
434
- console.error('Request failure. Status: '+status+' ; HTTP Code: '+jqxhr.status+(null!=errorThrown && ''!==errorThrown ? ' ; Error message: '+errorThrown : ''), jqxhr.responseJSON);
429
+ console.error('Request failure. Status: ' + status + ' ; HTTP Code: ' + jqxhr.status + (null != errorThrown && '' !== errorThrown ? ' ; Error message: ' + errorThrown : ''), jqxhr.responseJSON);
435
430
  }
436
431
 
437
432
  static isExpiredToken(response, json) {
@@ -474,8 +469,7 @@ class HTTPRequest {
474
469
  successCallback(jsonData, response);
475
470
  return;
476
471
  }
477
- }
478
- catch (e) {
472
+ } catch (e) {
479
473
  console.error(e);
480
474
  if (typeof errorCallback != 'undefined' && errorCallback != null) {
481
475
  errorCallback(response);
@@ -547,15 +541,13 @@ class HTTPRequest {
547
541
  if (response.ok) {
548
542
  const blobData = await response.blob();
549
543
  File.download(blobData, response.headers.get('content-type'), response.headers.get('content-disposition'));
550
- }
551
- else {
544
+ } else {
552
545
  HTTPRequest.logRequestFailure(response, null);
553
546
  if (typeof errorCallback != 'undefined' && errorCallback != null) {
554
547
  errorCallback(response);
555
548
  }
556
549
  }
557
- }
558
- catch (e) {
550
+ } catch (e) {
559
551
  console.error(e);
560
552
  if (typeof errorCallback != 'undefined' && errorCallback != null) {
561
553
  errorCallback(response);
@@ -640,8 +632,7 @@ class HTTPRequest {
640
632
  formErrorCallback(jsonData, response);
641
633
  return;
642
634
  }
643
- }
644
- catch (e) {
635
+ } catch (e) {
645
636
  console.error(e);
646
637
  if (typeof errorCallback != 'undefined' && errorCallback != null) {
647
638
  errorCallback(response);
@@ -742,8 +733,7 @@ class HTTPRequest {
742
733
  let data;
743
734
  if (formatRetour == 'xml') {
744
735
  data = xhr.responseXML;
745
- }
746
- else {
736
+ } else {
747
737
  data = eval('(' + xhr.responseText + ')');
748
738
  }
749
739
  callback(data);
@@ -753,8 +743,7 @@ class HTTPRequest {
753
743
  if (methode === 'POST') {
754
744
  xhr.open('POST', url, true);
755
745
  xhr.send();
756
- }
757
- else {
746
+ } else {
758
747
  xhr.open('GET', url + '?' + strParam, true);
759
748
  xhr.send(null);
760
749
  }
@@ -762,4 +751,4 @@ class HTTPRequest {
762
751
  }
763
752
  }
764
753
 
765
- module.exports = { HTTPRequest, Cookie, UrlAndQueryString };
754
+ module.exports = {HTTPRequest, Cookie, UrlAndQueryString};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.0.107",
3
+ "version": "1.0.109",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"