@osimatic/helpers-js 1.1.26 → 1.1.27

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/CHANGELOG CHANGED
@@ -60,3 +60,6 @@ HTTPRequest -> HTTPClient
60
60
 
61
61
  1.0.106
62
62
  UrlAndQueryString.getPath() -> UrlAndQueryString.getHostAndPath()
63
+
64
+ 1.1.27
65
+ var serviceCountry = 'XX' -> TelephoneNumber.setLocalCountryCode('XX')
@@ -3,10 +3,10 @@ class PersonName {
3
3
 
4
4
  static format(firstName, lastName) {
5
5
  let str = '';
6
- if (firstName != null && firstName != '') {
6
+ if (firstName != null && firstName !== '') {
7
7
  str += ' '+firstName;
8
8
  }
9
- if (lastName != null && lastName != '') {
9
+ if (lastName != null && lastName !== '') {
10
10
  str += ' '+lastName;
11
11
  }
12
12
  return str.trim();
@@ -50,42 +50,43 @@ class Email {
50
50
  class TelephoneNumber {
51
51
  //this class works with libphonenumber-max.min.js
52
52
 
53
+ static setLocalCountryCode(countryCode) {
54
+ TelephoneNumber.localCountryCode = countryCode;
55
+ }
56
+
53
57
  static setIntlTelInputUtilsPath(path) {
54
58
  TelephoneNumber.intlTelInputUtilsPath = path;
55
59
  }
56
60
 
57
- static getCountryIsoCode(phoneNumber, localCountryIsoCode) {
58
- localCountryIsoCode = (typeof localCountryIsoCode != 'undefined' ? localCountryIsoCode.toUpperCase() : serviceCountry);
61
+ static getCountryIsoCode(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
59
62
  try {
60
- const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode);
63
+ const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode.toUpperCase());
61
64
  return number != null ? number.country : null;
62
65
  } catch (error) {
63
66
  console.error(error);
64
67
  }
65
68
  return null;
66
- //return libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode).country || '';
69
+ //return libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode.toUpperCase()).country || '';
67
70
  }
68
- static getCountryName(phoneNumber, localCountryIsoCode) {
71
+ static getCountryName(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
69
72
  return Country.getCountryName(this.getCountryIsoCode(phoneNumber, localCountryIsoCode));
70
73
  }
71
- static getFlagImg(phoneNumber, localCountryIsoCode) {
74
+ static getFlagImg(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
72
75
  return Country.getFlagImg(this.getCountryIsoCode(phoneNumber, localCountryIsoCode));
73
76
  }
74
- static formatNational(phoneNumber, localCountryIsoCode) {
75
- localCountryIsoCode = (typeof localCountryIsoCode != 'undefined' ? localCountryIsoCode.toUpperCase() : serviceCountry);
77
+ static formatNational(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
76
78
  try {
77
- const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode);
79
+ const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode.toUpperCase());
78
80
  return number != null ? number.formatNational() : '';
79
81
  } catch (error) {
80
82
  console.error(error);
81
83
  }
82
84
  return '';
83
- //return libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode).formatNational();
85
+ //return libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode.toUpperCase()).formatNational();
84
86
  }
85
- static formatInternational(phoneNumber, localCountryIsoCode) {
86
- localCountryIsoCode = (typeof localCountryIsoCode != 'undefined' ? localCountryIsoCode.toUpperCase() : serviceCountry);
87
+ static formatInternational(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
87
88
  try {
88
- const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode);
89
+ const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode.toUpperCase());
89
90
  return number != null ? number.formatInternational() : '';
90
91
  } catch (error) {
91
92
  console.error(error);
@@ -93,20 +94,19 @@ class TelephoneNumber {
93
94
  return '';
94
95
  //return libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode).formatInternational();
95
96
  }
96
- static formatInternationalWithTelLink(phoneNumber, localCountryIsoCode) {
97
+ static formatInternationalWithTelLink(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
97
98
  return '<a href="tel:'+phoneNumber+'">'+TelephoneNumber.formatInternational(phoneNumber, localCountryIsoCode)+'</a>';
98
99
  }
99
- static formatNationalWithFlagImg(phoneNumber, localCountryIsoCode) {
100
+ static formatNationalWithFlagImg(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
100
101
  return TelephoneNumber.getFlagImg(phoneNumber, localCountryIsoCode)+'&nbsp;'+TelephoneNumber.formatNational(phoneNumber, localCountryIsoCode);
101
102
  }
102
- static formatNationalWithFlagImgAndTelLink(phoneNumber, localCountryIsoCode) {
103
+ static formatNationalWithFlagImgAndTelLink(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
103
104
  return TelephoneNumber.getFlagImg(phoneNumber, localCountryIsoCode)+'&nbsp;<a href="tel:'+phoneNumber+'">'+TelephoneNumber.formatNational(phoneNumber, localCountryIsoCode)+'</a>';
104
105
  }
105
106
 
106
- static parse(phoneNumber, localCountryIsoCode) {
107
- localCountryIsoCode = (typeof localCountryIsoCode != 'undefined' ? localCountryIsoCode.toUpperCase() : serviceCountry);
107
+ static parse(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
108
108
  try {
109
- const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode);
109
+ const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode.toUpperCase());
110
110
  return number != null ? number.formatInternational() : null;
111
111
  } catch (error) {
112
112
  console.error(error);
@@ -114,14 +114,13 @@ class TelephoneNumber {
114
114
  return null;
115
115
  }
116
116
 
117
- static check(phoneNumber, localCountryIsoCode) {
118
- localCountryIsoCode = (typeof localCountryIsoCode != 'undefined' ? localCountryIsoCode.toUpperCase() : serviceCountry);
117
+ static check(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
119
118
  try {
120
- const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode);
119
+ const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode.toUpperCase());
121
120
  return number != null ? number.isValid() : false;
122
121
  } catch (error) { }
123
122
  return false;
124
- //var numberObject = libphonenumber.parse(phoneNumber, localCountryIsoCode);
123
+ //var numberObject = libphonenumber.parse(phoneNumber, localCountryIsoCode.toUpperCase());
125
124
  //return (typeof numberObject.country !== 'undefined');
126
125
  }
127
126
 
@@ -134,15 +133,13 @@ class TelephoneNumber {
134
133
  return verifPhoneInt.exec(phoneNumber) != null;
135
134
  }
136
135
 
137
- static getType(phoneNumber, localCountryIsoCode) {
138
- localCountryIsoCode = (typeof localCountryIsoCode != 'undefined' ? localCountryIsoCode.toUpperCase() : serviceCountry);
139
-
136
+ static getType(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
140
137
  if (phoneNumber == null || phoneNumber.length === 0) {
141
138
  return 'MASKED';
142
139
  }
143
140
 
144
141
  try {
145
- const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode);
142
+ const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode.toUpperCase());
146
143
  return number != null ? number.getType() : null;
147
144
  } catch (error) {
148
145
  console.error(error);
@@ -173,7 +170,7 @@ class TelephoneNumber {
173
170
 
174
171
  static setIntlTelInput(input, placeholderNumberType) {
175
172
  return window.intlTelInput(input[0], {
176
- initialCountry: serviceCountry,
173
+ initialCountry: TelephoneNumber.localCountryCode,
177
174
  placeholderNumberType: placeholderNumberType || 'FIXED_LINE_OR_MOBILE',
178
175
  utilsScript: typeof TelephoneNumber.intlTelInputUtilsPath != 'undefined' ? TelephoneNumber.intlTelInputUtilsPath : null
179
176
  });
package/duration.js CHANGED
@@ -1,8 +1,7 @@
1
1
 
2
2
  class Duration {
3
3
 
4
- static formatNbDays(nbDays, locale) {
5
- locale = (typeof locale != 'undefined'?locale:'fr-FR');
4
+ static formatNbDays(nbDays, locale='fr-FR') {
6
5
  return new Intl.NumberFormat(locale, {
7
6
  minimumFractionDigits: 2,
8
7
  maximumFractionDigits: 2
@@ -29,9 +28,7 @@ class Duration {
29
28
  return Duration.convertToDurationInHourChronoDisplay(Math.abs(durationInSeconds), 'input_time');
30
29
  }
31
30
 
32
- static convertToDurationInHourChronoDisplay(durationInSeconds, displayMode) {
33
- displayMode = typeof displayMode != 'undefined' ? displayMode : 'chrono';
34
-
31
+ static convertToDurationInHourChronoDisplay(durationInSeconds, displayMode='chrono') {
35
32
  let durationInSecondsOriginal = durationInSeconds;
36
33
  durationInSeconds = Math.abs(durationInSeconds);
37
34
  let seconds = ( durationInSeconds % 60 );
@@ -47,12 +44,7 @@ class Duration {
47
44
  return (durationInSecondsOriginal < 0 ? '- ' : '')+hours+':'+minutes+(displayMode==='input_time'?':':'.')+seconds;
48
45
  }
49
46
 
50
- static convertToDurationInHourStringDisplay(durationInSeconds, withSecondes, withMinutes, withLibelleMinute, libelleEntier) {
51
- if (withSecondes == null) withSecondes = true;
52
- if (withMinutes == null) withMinutes = true;
53
- if (withLibelleMinute == null) withLibelleMinute = true;
54
- if (libelleEntier == null) libelleEntier = false;
55
-
47
+ static convertToDurationInHourStringDisplay(durationInSeconds, withSecondes=true, withMinutes=true, withLibelleMinute=true, libelleEntier=false) {
56
48
  // Heures
57
49
  let strHeure = '';
58
50
  let nbHeures = this.getNbHoursOfDurationInSeconds(durationInSeconds);
@@ -100,7 +92,7 @@ class Duration {
100
92
  return (strHeure+strMinute+strSeconde).trim();
101
93
  }
102
94
 
103
- static roundNbSeconds(durationInSeconds, roundPrecision, roundMode) {
95
+ static roundNbSeconds(durationInSeconds, roundPrecision, roundMode='close') {
104
96
  let hours = Math.floor(durationInSeconds / 3600);
105
97
  let minutes = Math.floor((durationInSeconds % 3600) / 60);
106
98
  let seconds = durationInSeconds % 60;
package/file.js CHANGED
@@ -1,19 +1,18 @@
1
1
 
2
2
  class File {
3
3
  static download(data, contentType, contentDisposition) {
4
- var filename = "";
5
- var disposition = contentDisposition;
4
+ let filename = "";
5
+ let disposition = contentDisposition;
6
6
  if (disposition && (disposition.indexOf('inline') !== -1 || disposition.indexOf('attachment') !== -1)) {
7
- var filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
8
- var matches = filenameRegex.exec(disposition);
7
+ let filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
8
+ let matches = filenameRegex.exec(disposition);
9
9
  if (matches != null && matches[1]) {
10
10
  filename = matches[1].replace(/['"]/g, '');
11
11
  }
12
12
  }
13
- var type = contentType;
14
13
 
15
- var blob = new Blob([data], {
16
- type: type
14
+ let blob = new Blob([data], {
15
+ type: contentType
17
16
  });
18
17
 
19
18
  //console.log('disposition: '+disposition+' ; filename: '+filename+' ; type: '+type);
@@ -23,10 +22,10 @@ class File {
23
22
  // IE workaround for "HTML7007: One or more blob URLs were revoked by closing the blob for which they were created. These URLs will no longer resolve as the data backing the URL has been freed."
24
23
  window.navigator.msSaveBlob(blob, filename);
25
24
  } else {
26
- var URL = window.URL || window.webkitURL;
27
- var downloadUrl = URL.createObjectURL(blob);
25
+ let URL = window.URL || window.webkitURL;
26
+ let downloadUrl = URL.createObjectURL(blob);
28
27
 
29
- var a = document.createElement("a");
28
+ let a = document.createElement("a");
30
29
  // safari doesn't support this yet
31
30
  if (typeof a.download === 'undefined') {
32
31
  window.location = downloadUrl;
@@ -43,10 +42,9 @@ class File {
43
42
  }
44
43
  }
45
44
 
46
- static formatFileSize(fileSizeInBytes, fractionDigits, locale) {
47
- fractionDigits = (typeof fractionDigits != 'undefined' ? fractionDigits : 2);
48
- var i = -1;
49
- var byteUnits = ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
45
+ static formatFileSize(fileSizeInBytes, fractionDigits=2, locale='fr-FR') {
46
+ let i = -1;
47
+ let byteUnits = ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
50
48
  if (fileSizeInBytes === 0) {
51
49
  return '0 ' + byteUnits[0];
52
50
  }
@@ -56,7 +54,7 @@ class File {
56
54
  }
57
55
  while (fileSizeInBytes > 1024);
58
56
  //var size = Math.max(fileSizeInBytes, 0.1).toFixed(fractionDigits);
59
- var size = Math.max(fileSizeInBytes, 0.1);
57
+ let size = Math.max(fileSizeInBytes, 0.1);
60
58
  return (new Intl.NumberFormat(locale, {
61
59
  maximumFractionDigits: fractionDigits
62
60
  }).format(size)) + ' ' + byteUnits[i];
@@ -93,13 +91,13 @@ class CSV {
93
91
 
94
92
  class Img {
95
93
  static compress(oData) {
96
- var a = [];
97
- var len = oData.length;
98
- var p = -1;
99
- for (var i=0;i<len;i+=4) {
94
+ let a = [];
95
+ let len = oData.length;
96
+ let p = -1;
97
+ for (let i=0;i<len;i+=4) {
100
98
  if (oData[i] > 0)
101
99
  a[++p] = String.fromCharCode(oData[i]);
102
- };
100
+ }
103
101
  return a.join("");
104
102
  }
105
103
 
@@ -128,7 +126,7 @@ class Img {
128
126
  static setBlobToImg(img, blob) {
129
127
  // img.attr('src', btoa(unescape(encodeURIComponent(data))));
130
128
  // img.attr('src', 'data:image/png;base64, '+btoa(unescape(encodeURIComponent(data))));
131
- var urlCreator = window.URL || window.webkitURL;
129
+ let urlCreator = window.URL || window.webkitURL;
132
130
  img.attr('src', urlCreator.createObjectURL(blob));
133
131
  }
134
132
 
package/flash_message.js CHANGED
@@ -1,21 +1,20 @@
1
1
  class FlashMessage {
2
- static displaySuccess(message, reload, modal) {
2
+ static displaySuccess(message, reload, modal=null) {
3
3
  this.display('success', message, reload, modal);
4
4
  }
5
- static displayWarning(message, modal) {
5
+ static displayWarning(message, modal=null) {
6
6
  this.display('warning', message, false, modal);
7
7
  }
8
- static displayError(message, modal) {
8
+ static displayError(message, modal=null) {
9
9
  this.display('danger', message, false, modal);
10
10
  }
11
11
 
12
- static display(type, message, reload, modal) {
13
- if ('undefined' !== typeof modal) {
12
+ static display(type, message, reload, modal=null) {
13
+ if (null !== modal) {
14
14
  modal.modal('hide');
15
15
  }
16
- if ($('div.snackbar').length !== 0) {
17
- $('div.snackbar').remove();
18
- }
16
+
17
+ $('div.snackbar').remove();
19
18
  let snackbar = $('<div class="snackbar '+type+'"></div>');
20
19
  $('html body').append(snackbar);
21
20
  snackbar.html(message);
package/form_helper.js CHANGED
@@ -1,7 +1,7 @@
1
1
  class FormHelper {
2
- static init(form, onSubmitCallback, submitButton) {
2
+ static init(form, onSubmitCallback, submitButton=null) {
3
3
  FormHelper.reset(form, submitButton);
4
- submitButton = typeof submitButton != 'undefined' && null != submitButton ? submitButton : form.find('button[name="validate"]');
4
+ submitButton = null != submitButton ? submitButton : form.find('button[name="validate"]');
5
5
  submitButton.off('click').click(function(e) {
6
6
  e.preventDefault();
7
7
  FormHelper.buttonLoader($(this), 'loading');
@@ -13,8 +13,8 @@ class FormHelper {
13
13
  return form;
14
14
  }
15
15
 
16
- static reset(form, submitButton) {
17
- submitButton = typeof submitButton != 'undefined' && null != submitButton ? submitButton : form.find('button[name="validate"]');
16
+ static reset(form, submitButton=null) {
17
+ submitButton = null != submitButton ? submitButton : form.find('button[name="validate"]');
18
18
  form.find('input[name]:not([type="checkbox"], [type="radio"]), select:not(.selectpicker), textarea').each((idx, el) => $(el).val('')).off('change');
19
19
  form.find('select.selectpicker').each((idx, el) => $(el).val(''));
20
20
  FormHelper.buttonLoader(submitButton, 'reset');
@@ -31,7 +31,7 @@ class FormHelper {
31
31
  }
32
32
 
33
33
  if (typeof value == 'object') {
34
- var select = form.find('[name="'+key+'[]"]');
34
+ let select = form.find('[name="'+key+'[]"]');
35
35
  select.find('option').prop('selected', false);
36
36
  select.data('default_id', value.join(','));
37
37
  $.each(value, function(key, val) {
@@ -40,7 +40,7 @@ class FormHelper {
40
40
  return;
41
41
  }
42
42
 
43
- var input = form.find('[name="'+key+'"]');
43
+ let input = form.find('[name="'+key+'"]');
44
44
 
45
45
  if (input.prop('type') === 'radio' || input.prop('type') === 'checkbox') {
46
46
  input.prop('checked', false);
@@ -60,7 +60,7 @@ class FormHelper {
60
60
  }
61
61
 
62
62
  static getDataFromFormData(formData) {
63
- var data = {};
63
+ let data = {};
64
64
  for(let pair of formData.entries()) {
65
65
  //console.log(pair[0]+ ', '+ pair[1]);
66
66
  data[pair[0]] = pair[1];
@@ -100,15 +100,14 @@ class FormHelper {
100
100
  return textarea.val().replace(/(\r\n|\n|\r)/g, "\n").split("\n").filter(word => word.length > 0);
101
101
  }
102
102
 
103
- static setOnInputChange(input, callback, doneTypingInterval) {
103
+ static setOnInputChange(input, callback, doneTypingInterval=700) {
104
104
  // setup before functions
105
105
  let typingTimer; // timer identifier
106
- doneTypingInterval = typeof doneTypingInterval != 'undefined' && null !== doneTypingInterval ? doneTypingInterval : 700; // time in ms
107
106
 
108
107
  // on keyup, start the countdown
109
108
  input.on('keyup', function () {
110
109
  clearTimeout(typingTimer);
111
- typingTimer = setTimeout(callback, doneTypingInterval);
110
+ typingTimer = setTimeout(callback, doneTypingInterval); // time in ms
112
111
  });
113
112
 
114
113
  // on keydown, clear the countdown
@@ -338,10 +337,10 @@ class FormHelper {
338
337
  button.data('btn-text', button.html());
339
338
  //let text = '<span class="spinner"><i class=\'fa fa-circle-notch fa-spin\'></i></span>Traitement en cours…';
340
339
  let text = '<i class=\'fa fa-circle-notch fa-spin\'></i> Traitement en cours…';
341
- if (button.data('load-text') != undefined && button.data('load-text') != null && button.data('load-text') != '') {
340
+ if (button.data('load-text') != null && button.data('load-text') !== '') {
342
341
  text = button.data('load-text');
343
342
  }
344
- if (button.data('loading-text') != undefined && button.data('loading-text') != null && button.data('loading-text') != '') {
343
+ if (button.data('loading-text') != null && button.data('loading-text') !== '') {
345
344
  text = button.data('loading-text');
346
345
  }
347
346
  button.html(text);
package/network.js CHANGED
@@ -28,14 +28,11 @@ class Cookie {
28
28
  }
29
29
 
30
30
  class UrlAndQueryString {
31
- static displayUrl(url, withLink) {
32
- withLink = typeof withLink == 'undefined' ? true : withLink;
31
+ static displayUrl(url, withLink=true) {
33
32
  return (withLink ? '<a href="' + url + '">' : '') + UrlAndQueryString.getHost(url, false) + (withLink ? '</a>' : '');
34
33
  }
35
34
 
36
- static displayUrlAndPath(url, withLink, displayPathIfEmpty) {
37
- withLink = typeof withLink == 'undefined' ? true : withLink;
38
- displayPathIfEmpty = typeof displayPathIfEmpty == 'undefined' ? false : displayPathIfEmpty;
35
+ static displayUrlAndPath(url, withLink=true, displayPathIfEmpty=false) {
39
36
  let formattedUrl = UrlAndQueryString.getHostAndPath(url, false);
40
37
  if (!displayPathIfEmpty && UrlAndQueryString.getPath(url) === '/') {
41
38
  formattedUrl = formattedUrl.slice(-1) === '/' ? formattedUrl.slice(0, -1) : formattedUrl;
@@ -43,8 +40,7 @@ class UrlAndQueryString {
43
40
  return (withLink ? '<a href="' + url + '">' : '') + formattedUrl + (withLink ? '</a>' : '');
44
41
  }
45
42
 
46
- static getHost(url, withProtocol) {
47
- withProtocol = typeof withProtocol == 'undefined' ? true : withProtocol;
43
+ static getHost(url, withProtocol=true) {
48
44
  if (typeof url == 'undefined') {
49
45
  return withProtocol ? window.location.origin : window.location.host;
50
46
  }
@@ -68,7 +64,7 @@ class UrlAndQueryString {
68
64
  return url.search;
69
65
  }
70
66
 
71
- static getHostAndPath(url, withProtocol) {
67
+ static getHostAndPath(url, withProtocol=true) {
72
68
  return UrlAndQueryString.getHost(url, withProtocol) + UrlAndQueryString.getPath(url);
73
69
 
74
70
  //let strpos = url.indexOf('?');
package/number.js CHANGED
@@ -27,30 +27,30 @@ class NumberFormatter {
27
27
  }
28
28
  }
29
29
 
30
- Number.prototype.format = Number.prototype.format || function(nbDecimal, locale) {
30
+ Number.prototype.format = Number.prototype.format || function(nbDecimal=2, locale='fr-FR') {
31
31
  return Number.format(this, nbDecimal, locale);
32
32
  }
33
33
 
34
34
  if (!Number.format) {
35
- Number.format = function(number, nbDecimal, locale) {
36
- return NumberFormatter.getDecimalFormatter(locale, (typeof nbDecimal != 'undefined' ? nbDecimal : 2)).format(number);
35
+ Number.format = function(number, nbDecimal=2, locale='fr-FR') {
36
+ return NumberFormatter.getDecimalFormatter(locale, nbDecimal).format(number);
37
37
  };
38
38
  }
39
39
 
40
- Number.prototype.formatCurrency = Number.prototype.formatCurrency || function(currency, nbDecimal, locale) {
40
+ Number.prototype.formatCurrency = Number.prototype.formatCurrency || function(currency, nbDecimal=2, locale='fr-FR') {
41
41
  return Number.formatCurrency(this, currency, nbDecimal, locale);
42
42
  }
43
43
 
44
- Number.formatCurrency = Number.formatCurrency || function(number, currency, nbDecimal, locale) {
45
- return NumberFormatter.getCurrencyFormatter(locale, currency, (typeof nbDecimal != 'undefined' ? nbDecimal : 2)).format(number);
44
+ Number.formatCurrency = Number.formatCurrency || function(number, currency, nbDecimal=2, locale='fr-FR') {
45
+ return NumberFormatter.getCurrencyFormatter(locale, currency, nbDecimal).format(number);
46
46
  }
47
47
 
48
- Number.prototype.formatPercent = Number.prototype.formatPercent || function(nbDecimal, locale) {
48
+ Number.prototype.formatPercent = Number.prototype.formatPercent || function(nbDecimal=2, locale='fr-FR') {
49
49
  return Number.formatPercent(this, nbDecimal, locale);
50
50
  }
51
51
 
52
- Number.formatPercent = Number.formatPercent || function(number, nbDecimal, locale) {
53
- return NumberFormatter.getPercentFormatter(locale, (typeof nbDecimal != 'undefined'?nbDecimal:2)).format(number);
52
+ Number.formatPercent = Number.formatPercent || function(number, nbDecimal=2, locale='fr-FR') {
53
+ return NumberFormatter.getPercentFormatter(locale, nbDecimal).format(number);
54
54
  }
55
55
 
56
56
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.1.26",
3
+ "version": "1.1.27",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
package/paging.js CHANGED
@@ -144,9 +144,7 @@ class Navigation {
144
144
  tab.show();
145
145
  }
146
146
 
147
- static addTabInHistory(tabId, queryStringKey, replace) {
148
- queryStringKey = typeof queryStringKey != 'undefined' && null !== queryStringKey ? queryStringKey : 'tab';
149
- replace = typeof replace != 'undefined' && null !== replace ? replace : true;
147
+ static addTabInHistory(tabId, queryStringKey='tab', replace=true) {
150
148
  let url = window.location.href;
151
149
  url = UrlAndQueryString.setParamOfUrl(queryStringKey, tabId, url);
152
150
  if (replace) {
package/string.js CHANGED
@@ -54,12 +54,11 @@ String.prototype.truncateOnWord = String.prototype.truncateOnWord || function(li
54
54
  }).join('');
55
55
  }
56
56
 
57
- String.prototype.truncateString = String.prototype.truncateString || function(length, from, ellipsis, split) {
57
+ String.prototype.truncateString = String.prototype.truncateString || function(length, from, ellipsis='…', split=false) {
58
58
  let str1, str2, len1, len2;
59
59
  if (this.length <= length) {
60
60
  return this.toString();
61
61
  }
62
- ellipsis = typeof ellipsis === 'undefined' ? '…' : ellipsis;
63
62
  switch(from) {
64
63
  case 'left':
65
64
  str2 = split ? this.truncateOnWord(length, true) : this.slice(this.length - length);