@osimatic/helpers-js 1.0.8 → 1.0.11

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.
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="WEB_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$" />
5
+ <orderEntry type="inheritedJdk" />
6
+ <orderEntry type="sourceFolder" forTests="false" />
7
+ </component>
8
+ </module>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/helpers-js.iml" filepath="$PROJECT_DIR$/.idea/helpers-js.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
package/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
package/README ADDED
@@ -0,0 +1 @@
1
+ npm install @osimatic/helpers-js
package/array.js CHANGED
@@ -42,7 +42,7 @@ Array.prototype.filterUnique = function() {
42
42
  return this.filter((v, i, a) => a.indexOf(v) === i);
43
43
  };
44
44
 
45
- function getValuesByKeyInArrayOfArrays(array, key) {
45
+ Array.getValuesByKeyInArrayOfArrays = function(array, key) {
46
46
  let listeValues = [];
47
47
  for (let i in array) {
48
48
  let subArray = array[i];
@@ -63,7 +63,7 @@ Object.filter = (obj, predicate) => {
63
63
  .reduce( (res, key) => (res[key] = obj[key], res), {} );
64
64
  };
65
65
 
66
- function renameKeys(obj, keysMap) {
66
+ Object.renameKeys = function(obj, keysMap) {
67
67
  return Object.keys(obj).reduce(
68
68
  (acc, key) => ({
69
69
  ...acc,
@@ -71,9 +71,9 @@ function renameKeys(obj, keysMap) {
71
71
  }),
72
72
  {}
73
73
  );
74
- }
74
+ };
75
75
 
76
- function renameKeysByCallback(obj, callback) {
76
+ Object.renameKeysByCallback = function(obj, callback) {
77
77
  return Object.keys(obj).reduce(
78
78
  (acc, key) => ({
79
79
  ...acc,
@@ -82,5 +82,3 @@ function renameKeysByCallback(obj, callback) {
82
82
  {}
83
83
  );
84
84
  }
85
-
86
- module.exports = { getValuesByKeyInArrayOfArrays, renameKeys, renameKeysByCallback };
package/changelog.txt ADDED
@@ -0,0 +1,28 @@
1
+
2
+ 1.0.9 :
3
+ copierTexte(str) -> str.copyToClipboard()
4
+ truncateString(str, ...) -> str.truncateString(...)
5
+
6
+ NumberValue.isNumeric(str) -> str.isNumeric()
7
+ NumberValue.format(number, nbDecimal, locale) -> number.format(nbDecimal, locale) OU Number.format(number, nbDecimal, locale)
8
+ NumberValue.formatCurrency(montant, currency, nbDecimal, locale) -> montant.formatCurrency(currency, nbDecimal, locale)
9
+ NumberValue.formatPercent(number, nbDecimal, locale) -> number.formatPercent(nbDecimal, locale)
10
+ NumberValue.random(min, max) -> Number.random(min, max)
11
+ NumberValue.padLeft2(n) -> n.padLeft2()
12
+ NumberValue.roundDecimal(nombre, precision) -> nombre.roundDecimal(precision)
13
+
14
+ nombre.formatAsString(locale, minimumFractionDigits) -> nombre.format(nbDecimal, locale)
15
+ montant.formatAsCurrency(locale, currency, nbFractionDigits) -> montant.formatCurrency(currency, nbDecimal, locale)
16
+ number.formatAsPercent(locale, minimumFractionDigits) -> number.formatPercent(nbDecimal, locale)
17
+
18
+ constante COUNTRIES_LIST -> Country.getCountryList()
19
+ activateTab(...) -> Navigation.activateTab(...)
20
+
21
+ renameKeys(...) -> Object.renameKeys(...)
22
+ renameKeysByCallback(...) -> Object.renameKeysByCallback(...)
23
+ getValuesByKeyInArrayOfArrays(...) -> Array.getValuesByKeyInArrayOfArrays(...)
24
+ getValuesByKeyInArrayOfArrays(array, ...) -> array.getValuesByKeyInArrayOfArrays(...)
25
+
26
+ hasGetUserMedia() -> non remplacé
27
+
28
+ paginationAsList(...) -> Pagination.paginate(...)
package/duration.js CHANGED
@@ -1,8 +1,12 @@
1
1
 
2
2
  class Duration {
3
3
 
4
- static formatNbDays(nbDays) {
5
- return NumberValue.format(nbDays, 2, locale);
4
+ static formatNbDays(nbDays, locale) {
5
+ locale = (typeof locale != 'undefined'?locale:'fr-FR');
6
+ return new Intl.NumberFormat(locale, {
7
+ minimumFractionDigits: 2,
8
+ maximumFractionDigits: 2
9
+ }).format(nbDays);
6
10
  }
7
11
  static formatNbDaysIfPositive(nbDays) {
8
12
  return nbDays < 0 ? '-' : this.formatNbDays(nbDays);
@@ -12,11 +16,11 @@ class Duration {
12
16
  }
13
17
 
14
18
  static convertToDurationAsCentieme(durationInSeconds) {
15
- var hour = Math.floor(durationInSeconds / 3600);
16
- var minutes = durationInSeconds % 3600;
19
+ let hour = Math.floor(durationInSeconds / 3600);
20
+ let minutes = durationInSeconds % 3600;
17
21
  minutes = Math.floor(minutes / 60);
18
22
  // minutes = minutes - (minutes % 60);
19
- var minCentieme = Math.round( (minutes / 60 ) * 100 );
23
+ let minCentieme = Math.round( (minutes / 60 ) * 100 );
20
24
  return parseFloat(hour+'.'+minCentieme);
21
25
  }
22
26
 
@@ -27,17 +31,17 @@ class Duration {
27
31
  static convertToDurationInHourChronoDisplay(durationInSeconds, displayMode) {
28
32
  displayMode = typeof displayMode != 'undefined' ? displayMode : 'chrono';
29
33
 
30
- var durationInSecondsOriginal = durationInSeconds;
34
+ let durationInSecondsOriginal = durationInSeconds;
31
35
  durationInSeconds = Math.abs(durationInSeconds);
32
- var seconds = ( durationInSeconds % 60 );
33
- var remander = ( durationInSeconds % 3600 ) - seconds;
34
- var minutes = ( remander / 60 );
36
+ let seconds = ( durationInSeconds % 60 );
37
+ let remander = ( durationInSeconds % 3600 ) - seconds;
38
+ let minutes = ( remander / 60 );
35
39
  remander = ( durationInSeconds ) - ( durationInSeconds % 3600 );
36
- var hours = ( remander / 3600 );
40
+ let hours = ( remander / 3600 );
37
41
  if(hours.toString().length < 2) hours = '0'+hours;
38
- if(hours.toString().charAt(0) == "-") hours[0] = '0';
42
+ if(hours.toString().charAt(0) === "-") hours[0] = '0';
39
43
  if(minutes.toString().length < 2) minutes = '0'+minutes;
40
- if(minutes.toString().charAt(0) == "-") minutes[0] = '0';
44
+ if(minutes.toString().charAt(0) === "-") minutes[0] = '0';
41
45
  if(seconds.toString().length < 2) seconds = '0'+seconds;
42
46
  return (durationInSecondsOriginal < 0 ? '- ' : '')+hours+':'+minutes+(displayMode==='input_time'?':':'.')+seconds;
43
47
  }
@@ -49,8 +53,8 @@ class Duration {
49
53
  if (libelleEntier == null) libelleEntier = false;
50
54
 
51
55
  // Heures
52
- var strHeure = '';
53
- var nbHeures = this.getNbHoursOfDurationInSeconds(durationInSeconds);
56
+ let strHeure = '';
57
+ let nbHeures = this.getNbHoursOfDurationInSeconds(durationInSeconds);
54
58
  strHeure += nbHeures;
55
59
  if (libelleEntier) {
56
60
  strHeure += ' heure'+(nbHeures>1?'s':'');
@@ -60,8 +64,8 @@ class Duration {
60
64
  }
61
65
 
62
66
  // Minutes
63
- var strMinute = '';
64
- var nbMinutes = 0;
67
+ let strMinute = '';
68
+ let nbMinutes = 0;
65
69
  if (withMinutes) {
66
70
  nbMinutes = this.getNbMinutesRemainingOfDurationInSeconds(durationInSeconds);
67
71
  strMinute += ' ';
@@ -78,9 +82,9 @@ class Duration {
78
82
  }
79
83
 
80
84
  // Secondes
81
- var strSeconde = '';
85
+ let strSeconde = '';
82
86
  if (withSecondes) {
83
- var nbSecondes = this.getNbSecondsRemainingOfDurationInSeconds(durationInSeconds);
87
+ let nbSecondes = this.getNbSecondsRemainingOfDurationInSeconds(durationInSeconds);
84
88
  strSeconde += ' ';
85
89
  //strSeconde += sprintf('%02d', nbSecondes);
86
90
  strSeconde += nbSecondes.toString().padStart(2, '0');
@@ -96,25 +100,25 @@ class Duration {
96
100
  }
97
101
 
98
102
  static roundNbSeconds(durationInSeconds, roundPrecision, roundMode) {
99
- var hours = Math.floor(durationInSeconds / 3600);
100
- var minutes = Math.floor((durationInSeconds % 3600) / 60);
101
- var seconds = durationInSeconds % 60;
103
+ let hours = Math.floor(durationInSeconds / 3600);
104
+ let minutes = Math.floor((durationInSeconds % 3600) / 60);
105
+ let seconds = durationInSeconds % 60;
102
106
 
103
- var hoursRounded = hours;
104
- var minutesRounded = minutes;
105
- var secondsRounded = seconds;
107
+ let hoursRounded = hours;
108
+ let minutesRounded = minutes;
109
+ let secondsRounded = seconds;
106
110
 
107
111
  if (roundPrecision > 0) {
108
- var minutesRemaining = minutes % roundPrecision;
109
- var minutesRemainingAndSecondsAsCentieme = minutesRemaining + seconds/60;
110
- if (minutesRemainingAndSecondsAsCentieme == 0) {
112
+ let minutesRemaining = minutes % roundPrecision;
113
+ let minutesRemainingAndSecondsAsCentieme = minutesRemaining + seconds/60;
114
+ if (minutesRemainingAndSecondsAsCentieme === 0) {
111
115
  // pas d'arrondissement
112
116
  }
113
117
  else {
114
118
  var halfRoundPrecision = roundPrecision / 2;
115
119
  hoursRounded = hours;
116
120
  secondsRounded = 0;
117
- if (roundMode == 'up' || (roundMode == 'close' && minutesRemainingAndSecondsAsCentieme > halfRoundPrecision)) {
121
+ if (roundMode === 'up' || (roundMode === 'close' && minutesRemainingAndSecondsAsCentieme > halfRoundPrecision)) {
118
122
  // Arrondissement au dessus
119
123
  if (minutes > (60-roundPrecision)) {
120
124
  minutesRounded = 0;
package/flash_message.js CHANGED
@@ -1,8 +1,7 @@
1
1
  class FlashMessage {
2
-
3
2
  static displayRequestFailure(status, exception, modal) {
4
3
  console.log('request failure. Status: ', status, ' Exception: ', exception);
5
- this.display('danger', "Une erreur s'est produite.", false, modal);
4
+ this.display('danger', typeof labelErrorOccured != 'undefined' ? labelErrorOccured : "Une erreur s'est produite.", false, modal);
6
5
  }
7
6
 
8
7
  static displaySuccess(message, reload, modal) {
package/form_helper.js CHANGED
@@ -161,6 +161,26 @@ class FormHelper {
161
161
  // Messages
162
162
  // ------------------------------------------------------------
163
163
 
164
+ static extractErrorKeyOfJson(json, onlyIfUniqueError) {
165
+ if (typeof json == 'undefined' || json == null) {
166
+ return null;
167
+ }
168
+
169
+ if (typeof json.error != 'undefined') {
170
+ return json.error;
171
+ }
172
+
173
+ if (typeof onlyIfUniqueError != 'undefined' && onlyIfUniqueError && !json.length || json.length > 1) {
174
+ return null;
175
+ }
176
+
177
+ if (typeof json[0] != 'undefined' && typeof json[0].error != 'undefined') {
178
+ return json[0].error;
179
+ }
180
+
181
+ return null;
182
+ }
183
+
164
184
  static hideFormErrors(form) {
165
185
  form.find('div.form_errors').remove();
166
186
  return form;
package/google_maps.js CHANGED
@@ -19,7 +19,7 @@ class GoogleMap {
19
19
  }
20
20
 
21
21
  static getUrl(latitude, longitude) {
22
- return 'http://maps.google.com/?q='+latitude+','+longitude+'';
22
+ return 'https://maps.google.com/?q='+latitude+','+longitude+'';
23
23
  }
24
24
 
25
25
  static getUrlFromCoordinates(locationCoordinates) {
@@ -0,0 +1,78 @@
1
+ class GoogleRecaptcha {
2
+ static onLoad() {
3
+ console.log('GoogleRecaptcha.onLoad');
4
+ if (typeof grecaptcha == 'undefined' || typeof grecaptcha.render != 'function') {
5
+ console.log('var grecaptcha undefined');
6
+ return;
7
+ }
8
+
9
+ if (typeof GoogleRecaptcha.googleCaptchaRendersCallback == 'undefined') {
10
+ GoogleRecaptcha.googleCaptchaRendersCallback = [];
11
+ }
12
+
13
+ GoogleRecaptcha.googleCaptchaRendersCallback.forEach(callback => callback());
14
+ GoogleRecaptcha.googleCaptchaRendersCallback = [];
15
+
16
+ /*document.querySelectorAll('.grecaptcha').forEach(element => {
17
+ try {
18
+ console.log(element.id);
19
+ //grecaptchaWidgets[element.id] = grecaptcha.render(element.id, googleReCaptchaDatas);
20
+ }
21
+ catch (e) {
22
+ console.log('Exception during grecaptcha.render', e);
23
+ }
24
+ });*/
25
+ }
26
+
27
+ static addRenderCallback(callback) {
28
+ if (typeof GoogleRecaptcha.googleCaptchaRendersCallback == 'undefined') {
29
+ GoogleRecaptcha.googleCaptchaRendersCallback = [];
30
+ }
31
+
32
+ GoogleRecaptcha.googleCaptchaRendersCallback.push(callback);
33
+ console.log('GoogleRecaptcha.addRenderCallback');
34
+ GoogleRecaptcha.onLoad();
35
+ }
36
+
37
+ static reset(id) {
38
+ if (typeof grecaptcha == 'undefined' || typeof grecaptcha.render != 'function') {
39
+ console.log('var grecaptcha.render undefined');
40
+ return;
41
+ }
42
+
43
+ if (typeof GoogleRecaptcha.grecaptchaWidgets == 'undefined') {
44
+ GoogleRecaptcha.grecaptchaWidgets = [];
45
+ }
46
+
47
+ if (typeof GoogleRecaptcha.grecaptchaWidgets[id] == 'undefined') {
48
+ try {
49
+ GoogleRecaptcha.grecaptchaWidgets[id] = grecaptcha.render(id, googleReCaptchaDatas);
50
+ }
51
+ catch (e) {
52
+ console.log('Exception during grecaptcha.render', e);
53
+ }
54
+ }
55
+ else {
56
+ grecaptcha.reset(GoogleRecaptcha.grecaptchaWidgets[id]);
57
+ }
58
+ }
59
+ }
60
+
61
+ module.exports = { GoogleRecaptcha };
62
+
63
+ /*
64
+ var grecaptchaWidgets = [];
65
+
66
+ function grecaptchaOnload () {
67
+ if (typeof grecaptcha == 'undefined') {
68
+ console.log('var grecaptcha undefined');
69
+ return;
70
+ }
71
+ document.querySelectorAll('.grecaptcha').forEach(element => {
72
+ grecaptchaWidgets[element.id] = grecaptcha.render(element.id, googleReCaptchaDatas);
73
+ });
74
+ //$('.grecaptcha').each(function(idx, el) {
75
+ // grecaptchaWidgets[$(el).attr('id')] = grecaptcha.render($(el).attr('id'), googleReCaptchaDatas);
76
+ //});
77
+ }
78
+ */
package/index.js CHANGED
@@ -1,37 +1,47 @@
1
1
  //A noter : les réécritures de prototypes définies dans certains fichiers n'ont pas besoin d'être exportés depuis le module en question (exemple Array / Object dans array.js).
2
2
  //Il faut uniquement appeler require() (sans récupérer le retour) et ajouter la/les classe(s) concernée(s) dans l'export ci-dessous (l'appel de require() applique l'extension).
3
3
 
4
+ // rien à exporter (que des extensions d'objet natif)
5
+ require('./string');
6
+ require('./array');
7
+
8
+ // exports d'ojets non natif
4
9
  const { HTTPRequest, Cookie, UrlAndQueryString } = require('./network');
5
10
  const { IBAN } = require('./bank');
6
11
  const { AudioMedia } = require('./media');
7
12
  const { PersonName, Email, TelephoneNumber } = require('./contact_details');
8
- const { CountDown } = require('./count_down');
9
- const { DataTable } = require('./data_table');
10
13
  const { DateTime, TimestampUnix, SqlDate, SqlTime, SqlDateTime, InputPeriod } = require('./date_time');
11
- const { DetailsSubArray } = require('./details_sub_array');
12
14
  const { Duration } = require('./duration');
13
15
  const { File, CSV, Img } = require('./file');
14
- const { FlashMessage } = require('./flash_message');
15
16
  const { FormHelper } = require('./form_helper');
16
- const { GoogleMap } = require('./google_maps');
17
+ const { Country, PostalAddress, Location } = require('./location');
18
+ const { SocialNetwork } = require('./social_network');
19
+ const { sleep, refresh } = require('./util');
20
+ const { chr, ord, trim, empty } = require('./php.min');
21
+
22
+ // exports plugins "maison"
23
+ const { DataTable } = require('./data_table');
24
+ const { Pagination, Navigation } = require('./paging');
25
+ const { FlashMessage } = require('./flash_message');
26
+ const { CountDown } = require('./count_down');
27
+ const { DetailsSubArray } = require('./details_sub_array');
17
28
  const { ImportFromCsv } = require('./import_from_csv');
18
29
  const { JwtToken, JwtSession } = require('./jwt');
19
30
  const { ListBox } = require('./list_box');
20
- const { COUNTRIES_LIST, Country, PostalAddress, Location } = require('./location');
21
- const { SocialNetwork } = require('./social_network');
22
- const { getValuesByKeyInArrayOfArrays, renameKeys, renameKeysByCallback } = require('./array');
23
- const { NumberValue } = require('./number');
24
- const { selectionnerContenuNode, copierTexte, truncateString } = require('./string');
25
- const { addBookmark, sleep, refresh } = require('./util');
26
- const { chr, ord, trim, empty } = require('./php.min');
27
- const { Pagination, activateTab } = require('./paging');
31
+
32
+ // exports surcouche lib externe
28
33
  const { GoogleCharts } = require('./google_charts');
34
+ const { GoogleRecaptcha } = require('./google_recaptcha');
35
+ const { GoogleMap } = require('./google_maps');
36
+ const { OpenStreetMap } = require('./open_street_map');
37
+
38
+ // deprecated
39
+ const { NumberValue } = require('./number');
29
40
 
30
41
  module.exports = {
31
- HTTPRequest, Cookie, UrlAndQueryString, IBAN, AudioMedia, PersonName, Email, TelephoneNumber, CountDown, DataTable,
32
- DateTime, TimestampUnix, SqlDate, SqlTime, SqlDateTime, InputPeriod, DetailsSubArray, Duration, File, CSV, Img,
33
- FlashMessage, FormHelper, GoogleMap, ImportFromCsv, JwtToken, JwtSession, ListBox, COUNTRIES_LIST, Country, PostalAddress,
34
- Location, SocialNetwork, Array, Object, getValuesByKeyInArrayOfArrays, renameKeys, renameKeysByCallback, Number, NumberValue,
35
- String, selectionnerContenuNode, copierTexte, truncateString, addBookmark, sleep, refresh, chr, ord, trim, empty, Pagination,
36
- activateTab, GoogleCharts
42
+ Array, Object, Number, String,
43
+ HTTPRequest, Cookie, UrlAndQueryString, IBAN, AudioMedia, PersonName, Email, TelephoneNumber, DateTime, TimestampUnix, SqlDate, SqlTime, SqlDateTime, InputPeriod, Duration, File, CSV, Img, FormHelper, Country, PostalAddress, Location, SocialNetwork, NumberValue,
44
+ DataTable, Pagination, Navigation, FlashMessage, CountDown, DetailsSubArray, ImportFromCsv, JwtToken, JwtSession, ListBox,
45
+ sleep, refresh, chr, ord, trim, empty,
46
+ GoogleCharts, GoogleRecaptcha, GoogleMap, OpenStreetMap
37
47
  };