@osimatic/helpers-js 1.5.27 β 1.5.29
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/bank.js +1 -1
- package/date_time.js +28 -28
- package/location.js +58 -255
- package/package.json +3 -1
- package/tests/location.test.js +45 -4
package/bank.js
CHANGED
|
@@ -15,7 +15,7 @@ class BankCard {
|
|
|
15
15
|
return cardNumber;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
static formatExpirationDate(expirationDate, locale=
|
|
18
|
+
static formatExpirationDate(expirationDate, locale='fr-FR') {
|
|
19
19
|
return SqlDateTime.getMonthName(expirationDate, locale)+' '+SqlDateTime.getYear(expirationDate);
|
|
20
20
|
}
|
|
21
21
|
}
|
package/date_time.js
CHANGED
|
@@ -100,27 +100,27 @@ class DateTime {
|
|
|
100
100
|
return Math.trunc(jsDate.getTime()/1000);
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
static getDateDigitalDisplay(jsDate, locale=
|
|
103
|
+
static getDateDigitalDisplay(jsDate, locale='fr-FR', timeZone="Europe/Paris") {
|
|
104
104
|
return DateTimeFormatter.getDateDigitalFormatter(locale, timeZone).format(jsDate);
|
|
105
105
|
//return jsDate.toLocaleDateString(locale, {year: 'numeric', month: 'numeric', day: 'numeric', timeZone: timeZone});
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
static getDateTextDisplay(jsDate, locale=
|
|
108
|
+
static getDateTextDisplay(jsDate, locale='fr-FR', timeZone="Europe/Paris") {
|
|
109
109
|
return DateTimeFormatter.getDateTextFormatter(locale, timeZone).format(jsDate);
|
|
110
110
|
//return jsDate.toLocaleDateString(locale, {weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', timeZone: timeZone});
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
static getTimeDisplay(jsDate, locale=
|
|
113
|
+
static getTimeDisplay(jsDate, locale='fr-FR', timeZone="Europe/Paris") {
|
|
114
114
|
return DateTimeFormatter.getTimeFormatter(locale, timeZone).format(jsDate);
|
|
115
115
|
//return jsDate.toLocaleTimeString(locale, {hour: 'numeric', minute: 'numeric', timeZone: timeZone});
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
static getTimeDigitalDisplay(jsDate, locale=
|
|
118
|
+
static getTimeDigitalDisplay(jsDate, locale='fr-FR', timeZone="Europe/Paris") {
|
|
119
119
|
return DateTimeFormatter.getTimeDigitalFormatter(locale, timeZone).format(jsDate);
|
|
120
120
|
//return jsDate.toLocaleTimeString(locale, {hour: '2-digit', minute: '2-digit', second: '2-digit', timeZone: timeZone});
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
static getTimeDisplayWithNbDays(jsDate, jsPreviousDate, locale=
|
|
123
|
+
static getTimeDisplayWithNbDays(jsDate, jsPreviousDate, locale='fr-FR', timeZone="Europe/Paris") {
|
|
124
124
|
let str = this.getTimeDisplay(jsDate, locale, timeZone);
|
|
125
125
|
if (jsPreviousDate !== 0 && jsPreviousDate != null) {
|
|
126
126
|
let nbDaysDiff = DatePeriod.getNbDayBetweenTwo(jsPreviousDate, jsDate, false);
|
|
@@ -131,7 +131,7 @@ class DateTime {
|
|
|
131
131
|
return str;
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
static getDateTimeDigitalDisplay(jsDate, locale=
|
|
134
|
+
static getDateTimeDigitalDisplay(jsDate, locale='fr-FR', timeZone="Europe/Paris") {
|
|
135
135
|
return DateTimeFormatter.getDateTimeFormatter(locale, timeZone).format(jsDate);
|
|
136
136
|
//return jsDate.toLocaleDateString(locale, {year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric', timeZone: timeZone});
|
|
137
137
|
}
|
|
@@ -142,7 +142,7 @@ class DateTime {
|
|
|
142
142
|
static getMonth(jsDate) {
|
|
143
143
|
return jsDate.getUTCMonth()+1;
|
|
144
144
|
}
|
|
145
|
-
static getMonthName(jsDate, locale=
|
|
145
|
+
static getMonthName(jsDate, locale='fr-FR', isShort=false) {
|
|
146
146
|
return jsDate.toLocaleDateString(locale, {month: (isShort?'short':'long')});
|
|
147
147
|
}
|
|
148
148
|
static getDay(jsDate) {
|
|
@@ -157,7 +157,7 @@ class DateTime {
|
|
|
157
157
|
return jsDate.getUTCDay();
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
static getDayName(jsDate, locale=
|
|
160
|
+
static getDayName(jsDate, locale='fr-FR', isShort=false) {
|
|
161
161
|
return jsDate.toLocaleDateString(locale, {weekday: (isShort?'short':'long')});
|
|
162
162
|
}
|
|
163
163
|
|
|
@@ -165,13 +165,13 @@ class DateTime {
|
|
|
165
165
|
return new Date(Date.UTC(year, month, 0)).getDate();
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
static getMonthNameByMonth(month, locale=
|
|
168
|
+
static getMonthNameByMonth(month, locale='fr-FR', isShort=false) {
|
|
169
169
|
let d = new Date();
|
|
170
170
|
d.setDate(1);
|
|
171
171
|
d.setMonth(month-1);
|
|
172
172
|
return this.getMonthName(d, locale, isShort);
|
|
173
173
|
}
|
|
174
|
-
static getDayNameByDayOfWeek(dayOfWeek, locale=
|
|
174
|
+
static getDayNameByDayOfWeek(dayOfWeek, locale='fr-FR', isShort=false) {
|
|
175
175
|
let d = new Date();
|
|
176
176
|
// d.setDate(d.getDate() + (1 + 7 - d.getDay()) % 7);
|
|
177
177
|
d.setDate(d.getDate() + (dayOfWeek - d.getDay()) % 7);
|
|
@@ -375,20 +375,20 @@ class TimestampUnix {
|
|
|
375
375
|
return parseInt(today.getTime() / 1000);
|
|
376
376
|
}
|
|
377
377
|
|
|
378
|
-
static getDateDigitalDisplay(timestamp, locale=
|
|
378
|
+
static getDateDigitalDisplay(timestamp, locale='fr-FR', timeZone="Europe/Paris") {
|
|
379
379
|
return DateTime.getDateDigitalDisplay(this.parse(timestamp), locale, timeZone);
|
|
380
380
|
}
|
|
381
|
-
static getDateTextDisplay(timestamp, locale=
|
|
381
|
+
static getDateTextDisplay(timestamp, locale='fr-FR', timeZone="Europe/Paris") {
|
|
382
382
|
return DateTime.getDateTextDisplay(this.parse(timestamp), locale, timeZone);
|
|
383
383
|
}
|
|
384
384
|
|
|
385
|
-
static getTimeDisplay(timestamp, locale=
|
|
385
|
+
static getTimeDisplay(timestamp, locale='fr-FR', timeZone="Europe/Paris") {
|
|
386
386
|
return DateTime.getTimeDisplay(this.parse(timestamp), locale, timeZone);
|
|
387
387
|
}
|
|
388
|
-
static getTimeDisplayWithNbDays(timestamp, previousTimestamp, locale=
|
|
388
|
+
static getTimeDisplayWithNbDays(timestamp, previousTimestamp, locale='fr-FR', timeZone="Europe/Paris") {
|
|
389
389
|
return DateTime.getTimeDisplayWithNbDays(this.parse(timestamp), this.parse(previousTimestamp), locale, timeZone);
|
|
390
390
|
}
|
|
391
|
-
static getTimeDigitalDisplay(timestamp, locale=
|
|
391
|
+
static getTimeDigitalDisplay(timestamp, locale='fr-FR', timeZone="Europe/Paris") {
|
|
392
392
|
return DateTime.getTimeDigitalDisplay(this.parse(timestamp), locale, timeZone);
|
|
393
393
|
}
|
|
394
394
|
|
|
@@ -477,10 +477,10 @@ class SqlDate {
|
|
|
477
477
|
return DateTime.getSqlDate(new Date());
|
|
478
478
|
}
|
|
479
479
|
|
|
480
|
-
static getDateDigitalDisplay(sqlDate, locale=
|
|
480
|
+
static getDateDigitalDisplay(sqlDate, locale='fr-FR', timeZone="Europe/Paris") {
|
|
481
481
|
return SqlDateTime.getDateDigitalDisplay(sqlDate+" 00:00:00", locale, timeZone);
|
|
482
482
|
}
|
|
483
|
-
static getDateTextDisplay(sqlDate, locale=
|
|
483
|
+
static getDateTextDisplay(sqlDate, locale='fr-FR', timeZone="Europe/Paris") {
|
|
484
484
|
return SqlDateTime.getDateTextDisplay(sqlDate+" 00:00:00", locale, timeZone);
|
|
485
485
|
}
|
|
486
486
|
|
|
@@ -498,7 +498,7 @@ class SqlDate {
|
|
|
498
498
|
static getMonth(sqlDate) {
|
|
499
499
|
return SqlDateTime.getMonth(sqlDate+" 00:00:00");
|
|
500
500
|
}
|
|
501
|
-
static getMonthName(sqlDate, locale=
|
|
501
|
+
static getMonthName(sqlDate, locale='fr-FR', isShort=false) {
|
|
502
502
|
return SqlDateTime.getMonthName(sqlDate+" 00:00:00", locale, isShort);
|
|
503
503
|
}
|
|
504
504
|
static getDay(sqlDate) {
|
|
@@ -539,13 +539,13 @@ class SqlTime {
|
|
|
539
539
|
return DateTime.getSqlTime(new Date());
|
|
540
540
|
}
|
|
541
541
|
|
|
542
|
-
static getTimeDisplay(sqlTime, locale=
|
|
542
|
+
static getTimeDisplay(sqlTime, locale='fr-FR', timeZone="Europe/Paris") {
|
|
543
543
|
return SqlDateTime.getTimeDisplay('1970-01-01 '+sqlTime, locale, timeZone);
|
|
544
544
|
}
|
|
545
|
-
static getTimeDigitalDisplay(sqlTime, locale=
|
|
545
|
+
static getTimeDigitalDisplay(sqlTime, locale='fr-FR', timeZone="Europe/Paris") {
|
|
546
546
|
return SqlDateTime.getTimeDigitalDisplay('1970-01-01 '+sqlTime, locale, timeZone);
|
|
547
547
|
}
|
|
548
|
-
static getTimeDisplayWithNbDays(sqlTime, previousSqlTime, locale=
|
|
548
|
+
static getTimeDisplayWithNbDays(sqlTime, previousSqlTime, locale='fr-FR', timeZone="Europe/Paris") {
|
|
549
549
|
return SqlDateTime.getTimeDisplayWithNbDays('1970-01-01 '+sqlTime, '1970-01-01 '+previousSqlTime, locale, timeZone);
|
|
550
550
|
}
|
|
551
551
|
|
|
@@ -588,24 +588,24 @@ class SqlDateTime {
|
|
|
588
588
|
return new Date(Date.UTC(sqlDateTime.substring(0, 4), sqlDateTime.substring(5, 7)-1, sqlDateTime.substring(8, 10), sqlDateTime.substring(11, 13), sqlDateTime.substring(14, 16), sqlDateTime.substring(17, 19)));
|
|
589
589
|
}
|
|
590
590
|
|
|
591
|
-
static getDateDigitalDisplay(sqlDateTime, locale=
|
|
591
|
+
static getDateDigitalDisplay(sqlDateTime, locale='fr-FR', timeZone="Europe/Paris") {
|
|
592
592
|
return DateTime.getDateDigitalDisplay(this.parse(sqlDateTime), locale, timeZone);
|
|
593
593
|
}
|
|
594
|
-
static getDateTextDisplay(sqlDateTime, locale=
|
|
594
|
+
static getDateTextDisplay(sqlDateTime, locale='fr-FR', timeZone="Europe/Paris") {
|
|
595
595
|
return DateTime.getDateTextDisplay(this.parse(sqlDateTime), locale, timeZone);
|
|
596
596
|
}
|
|
597
597
|
|
|
598
|
-
static getTimeDisplay(sqlDateTime, locale=
|
|
598
|
+
static getTimeDisplay(sqlDateTime, locale='fr-FR', timeZone="Europe/Paris") {
|
|
599
599
|
return DateTime.getTimeDisplay(this.parse(sqlDateTime), locale, timeZone);
|
|
600
600
|
}
|
|
601
|
-
static getTimeDisplayWithNbDays(sqlDateTime, previousSqlDateTime, locale=
|
|
601
|
+
static getTimeDisplayWithNbDays(sqlDateTime, previousSqlDateTime, locale='fr-FR', timeZone="Europe/Paris") {
|
|
602
602
|
return DateTime.getTimeDisplayWithNbDays(this.parse(sqlDateTime), this.parse(previousSqlDateTime), locale, timeZone);
|
|
603
603
|
}
|
|
604
|
-
static getTimeDigitalDisplay(sqlDateTime, locale=
|
|
604
|
+
static getTimeDigitalDisplay(sqlDateTime, locale='fr-FR', timeZone="Europe/Paris") {
|
|
605
605
|
return DateTime.getTimeDigitalDisplay(this.parse(sqlDateTime), locale, timeZone);
|
|
606
606
|
}
|
|
607
607
|
|
|
608
|
-
static getDateTimeDigitalDisplay(sqlDateTime, locale=
|
|
608
|
+
static getDateTimeDigitalDisplay(sqlDateTime, locale='fr-FR', timeZone="Europe/Paris") {
|
|
609
609
|
return DateTime.getDateTimeDigitalDisplay(this.parse(sqlDateTime), locale, timeZone);
|
|
610
610
|
}
|
|
611
611
|
|
|
@@ -622,7 +622,7 @@ class SqlDateTime {
|
|
|
622
622
|
static getMonth(sqlDateTime) {
|
|
623
623
|
return DateTime.getMonth(this.parse(sqlDateTime));
|
|
624
624
|
}
|
|
625
|
-
static getMonthName(sqlDateTime, locale=
|
|
625
|
+
static getMonthName(sqlDateTime, locale='fr-FR', isShort=false) {
|
|
626
626
|
return DateTime.getMonthName(this.parse(sqlDateTime), locale);
|
|
627
627
|
}
|
|
628
628
|
static getDay(sqlDateTime) {
|
package/location.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
const Address = require('ilib/lib/Address');
|
|
3
3
|
const AddressFmt = require('ilib/lib/AddressFmt');
|
|
4
4
|
const { toEl } = require('./util');
|
|
5
|
+
const isoCountries = require('i18n-iso-countries');
|
|
6
|
+
isoCountries.registerLocale(require('i18n-iso-countries/langs/en.json'));
|
|
5
7
|
|
|
6
8
|
class Country {
|
|
7
9
|
static setFlagsPath(flagsPath) {
|
|
@@ -14,8 +16,11 @@ class Country {
|
|
|
14
16
|
static getFlagImg(countryCode) {
|
|
15
17
|
return '<span><img src="'+Country.getFlagPath(countryCode)+'" alt="" title="'+Country.getCountryName(countryCode)+'" class="flag" /></span>'
|
|
16
18
|
}
|
|
19
|
+
static getFlagEmoji(countryCode) {
|
|
20
|
+
return [...countryCode.toUpperCase()].map(c => String.fromCodePoint(0x1F1E6 - 65 + c.charCodeAt(0))).join('');
|
|
21
|
+
}
|
|
17
22
|
|
|
18
|
-
static
|
|
23
|
+
static fillSelect(select, defaultValue=null, showFlags=false, countriesList=null, addNoneValue=false, noneLabel='- Aucun -', locale='fr-FR') {
|
|
19
24
|
select = toEl(select);
|
|
20
25
|
if (!select) {
|
|
21
26
|
return;
|
|
@@ -24,265 +29,45 @@ class Country {
|
|
|
24
29
|
if (addNoneValue) {
|
|
25
30
|
select.insertAdjacentHTML('beforeend', '<option value="">'+noneLabel+'</option>');
|
|
26
31
|
}
|
|
27
|
-
|
|
32
|
+
const allCountries = Country.getCountries(locale);
|
|
33
|
+
const entries = countriesList != null
|
|
34
|
+
? countriesList.map(code => [code, allCountries[code] || code])
|
|
35
|
+
: Object.entries(allCountries);
|
|
36
|
+
entries.forEach(([countryCode, countryName]) => {
|
|
37
|
+
let attrs = '';
|
|
38
|
+
if (showFlags) {
|
|
39
|
+
if (typeof Country.flagsPath !== 'undefined') {
|
|
40
|
+
attrs = ' data-thumbnail="' + Country.getFlagPath(countryCode) + '"';
|
|
41
|
+
} else {
|
|
42
|
+
attrs = ' data-content="<span class="fi fi-' + countryCode.toLowerCase() + '"></span> ' + countryName + '"';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
select.insertAdjacentHTML('beforeend', '<option value="' + countryCode + '"' + attrs + '>' + countryName + '</option>');
|
|
46
|
+
});
|
|
28
47
|
}
|
|
29
48
|
if (null != defaultValue) {
|
|
30
49
|
select.value = defaultValue;
|
|
31
50
|
}
|
|
32
51
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
return countryCode;
|
|
52
|
+
|
|
53
|
+
static fillSelectWithFlags(select, defaultValue=null, countriesList=null, addNoneValue=false, noneLabel='- Aucun -', locale='fr-FR') {
|
|
54
|
+
return Country.fillSelect(select, defaultValue, true, countriesList, addNoneValue, noneLabel, locale);
|
|
38
55
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
AU:'Australia',
|
|
55
|
-
AT:'Austria',
|
|
56
|
-
AZ:'Azerbaijan',
|
|
57
|
-
BS:'Bahamas',
|
|
58
|
-
BH:'Bahrain',
|
|
59
|
-
BD:'Bangladesh',
|
|
60
|
-
BB:'Barbados',
|
|
61
|
-
BY:'Belarus',
|
|
62
|
-
BE:'Belgium',
|
|
63
|
-
BZ:'Belize',
|
|
64
|
-
BJ:'Benin',
|
|
65
|
-
BM:'Bermuda',
|
|
66
|
-
BT:'Bhutan',
|
|
67
|
-
BO:'Bolivia',
|
|
68
|
-
BA:'Bosnia and Herzegovina',
|
|
69
|
-
BW:'Botswana',
|
|
70
|
-
BV:'Bouvet Island',
|
|
71
|
-
BR:'Brazil',
|
|
72
|
-
IO:'British Indian Ocean Territory',
|
|
73
|
-
BN:'Brunei Darussalam',
|
|
74
|
-
BG:'Bulgaria',
|
|
75
|
-
BF:'Burkina Faso',
|
|
76
|
-
BI:'Burundi',
|
|
77
|
-
KH:'Cambodia',
|
|
78
|
-
CM:'Cameroon',
|
|
79
|
-
CA:'Canada',
|
|
80
|
-
CV:'Cape Verde',
|
|
81
|
-
KY:'Cayman Islands',
|
|
82
|
-
CF:'Central African Republic',
|
|
83
|
-
TD:'Chad',
|
|
84
|
-
CL:'Chile',
|
|
85
|
-
CN:'China',
|
|
86
|
-
CX:'Christmas Island',
|
|
87
|
-
CC:'Cocos (Keeling) Islands',
|
|
88
|
-
CO:'Colombia',
|
|
89
|
-
KM:'Comoros',
|
|
90
|
-
CG:'Congo',
|
|
91
|
-
CD:'Congo, The Democratic Republic of The',
|
|
92
|
-
CK:'Cook Islands',
|
|
93
|
-
CR:'Costa Rica',
|
|
94
|
-
CI:'Cote dβIvoire',
|
|
95
|
-
HR:'Croatia',
|
|
96
|
-
CU:'Cuba',
|
|
97
|
-
CY:'Cyprus',
|
|
98
|
-
CZ:'Czechia',
|
|
99
|
-
DK:'Denmark',
|
|
100
|
-
DJ:'Djibouti',
|
|
101
|
-
DM:'Dominica',
|
|
102
|
-
DO:'Dominican Republic',
|
|
103
|
-
EC:'Ecuador',
|
|
104
|
-
EG:'Egypt',
|
|
105
|
-
SV:'El Salvador',
|
|
106
|
-
GQ:'Equatorial Guinea',
|
|
107
|
-
ER:'Eritrea',
|
|
108
|
-
EE:'Estonia',
|
|
109
|
-
ET:'Ethiopia',
|
|
110
|
-
FK:'Falkland Islands (Malvinas)',
|
|
111
|
-
FO:'Faroe Islands',
|
|
112
|
-
FJ:'Fiji',
|
|
113
|
-
FI:'Finland',
|
|
114
|
-
FR:'France',
|
|
115
|
-
GF:'French Guiana',
|
|
116
|
-
PF:'French Polynesia',
|
|
117
|
-
TF:'French Southern Territories',
|
|
118
|
-
GA:'Gabon',
|
|
119
|
-
GM:'Gambia',
|
|
120
|
-
GE:'Georgia',
|
|
121
|
-
DE:'Germany',
|
|
122
|
-
GH:'Ghana',
|
|
123
|
-
GI:'Gibraltar',
|
|
124
|
-
GR:'Greece',
|
|
125
|
-
GL:'Greenland',
|
|
126
|
-
GD:'Grenada',
|
|
127
|
-
GP:'Guadeloupe',
|
|
128
|
-
GU:'Guam',
|
|
129
|
-
GT:'Guatemala',
|
|
130
|
-
GG:'Guernsey',
|
|
131
|
-
GN:'Guinea',
|
|
132
|
-
GW:'Guinea-bissau',
|
|
133
|
-
GY:'Guyana',
|
|
134
|
-
HT:'Haiti',
|
|
135
|
-
HM:'Heard Island and Mcdonald Islands',
|
|
136
|
-
VA:'Holy See (Vatican City State)',
|
|
137
|
-
HN:'Honduras',
|
|
138
|
-
HK:'Hong Kong',
|
|
139
|
-
HU:'Hungary',
|
|
140
|
-
IS:'Iceland',
|
|
141
|
-
IN:'India',
|
|
142
|
-
ID:'Indonesia',
|
|
143
|
-
IR:'Iran, Islamic Republic of',
|
|
144
|
-
IQ:'Iraq',
|
|
145
|
-
IE:'Ireland',
|
|
146
|
-
IM:'Isle of Man',
|
|
147
|
-
IL:'Israel',
|
|
148
|
-
IT:'Italy',
|
|
149
|
-
JM:'Jamaica',
|
|
150
|
-
JP:'Japan',
|
|
151
|
-
JE:'Jersey',
|
|
152
|
-
JO:'Jordan',
|
|
153
|
-
KZ:'Kazakhstan',
|
|
154
|
-
KE:'Kenya',
|
|
155
|
-
KI:'Kiribati',
|
|
156
|
-
KP:'Korea, Democratic Peopleβs Republic of',
|
|
157
|
-
KR:'Korea, Republic of',
|
|
158
|
-
KW:'Kuwait',
|
|
159
|
-
KG:'Kyrgyzstan',
|
|
160
|
-
LA:'Lao Peopleβs Democratic Republic',
|
|
161
|
-
LV:'Latvia',
|
|
162
|
-
LB:'Lebanon',
|
|
163
|
-
LS:'Lesotho',
|
|
164
|
-
LR:'Liberia',
|
|
165
|
-
LY:'Libyan Arab Jamahiriya',
|
|
166
|
-
LI:'Liechtenstein',
|
|
167
|
-
LT:'Lithuania',
|
|
168
|
-
LU:'Luxembourg',
|
|
169
|
-
MO:'Macao',
|
|
170
|
-
MK:'Macedonia, The Former Yugoslav Republic of',
|
|
171
|
-
MG:'Madagascar',
|
|
172
|
-
MW:'Malawi',
|
|
173
|
-
MY:'Malaysia',
|
|
174
|
-
MV:'Maldives',
|
|
175
|
-
ML:'Mali',
|
|
176
|
-
MT:'Malta',
|
|
177
|
-
MH:'Marshall Islands',
|
|
178
|
-
MQ:'Martinique',
|
|
179
|
-
MR:'Mauritania',
|
|
180
|
-
MU:'Mauritius',
|
|
181
|
-
YT:'Mayotte',
|
|
182
|
-
MX:'Mexico',
|
|
183
|
-
FM:'Micronesia, Federated States of',
|
|
184
|
-
MD:'Moldova, Republic of',
|
|
185
|
-
MC:'Monaco',
|
|
186
|
-
MN:'Mongolia',
|
|
187
|
-
ME:'Montenegro',
|
|
188
|
-
MS:'Montserrat',
|
|
189
|
-
MA:'Morocco',
|
|
190
|
-
MZ:'Mozambique',
|
|
191
|
-
MM:'Myanmar',
|
|
192
|
-
NA:'Namibia',
|
|
193
|
-
NR:'Nauru',
|
|
194
|
-
NP:'Nepal',
|
|
195
|
-
NL:'Netherlands',
|
|
196
|
-
AN:'Netherlands Antilles',
|
|
197
|
-
NC:'New Caledonia',
|
|
198
|
-
NZ:'New Zealand',
|
|
199
|
-
NI:'Nicaragua',
|
|
200
|
-
NE:'Niger',
|
|
201
|
-
NG:'Nigeria',
|
|
202
|
-
NU:'Niue',
|
|
203
|
-
NF:'Norfolk Island',
|
|
204
|
-
MP:'Northern Mariana Islands',
|
|
205
|
-
NO:'Norway',
|
|
206
|
-
OM:'Oman',
|
|
207
|
-
PK:'Pakistan',
|
|
208
|
-
PW:'Palau',
|
|
209
|
-
PS:'Palestinian Territory, Occupied',
|
|
210
|
-
PA:'Panama',
|
|
211
|
-
PG:'Papua New Guinea',
|
|
212
|
-
PY:'Paraguay',
|
|
213
|
-
PE:'Peru',
|
|
214
|
-
PH:'Philippines',
|
|
215
|
-
PN:'Pitcairn',
|
|
216
|
-
PL:'Poland',
|
|
217
|
-
PT:'Portugal',
|
|
218
|
-
PR:'Puerto Rico',
|
|
219
|
-
QA:'Qatar',
|
|
220
|
-
RE:'Reunion',
|
|
221
|
-
RO:'Romania',
|
|
222
|
-
RU:'Russian Federation',
|
|
223
|
-
RW:'Rwanda',
|
|
224
|
-
SH:'Saint Helena',
|
|
225
|
-
KN:'Saint Kitts and Nevis',
|
|
226
|
-
LC:'Saint Lucia',
|
|
227
|
-
PM:'Saint Pierre and Miquelon',
|
|
228
|
-
VC:'Saint Vincent and The Grenadines',
|
|
229
|
-
WS:'Samoa',
|
|
230
|
-
SM:'San Marino',
|
|
231
|
-
ST:'Sao Tome and Principe',
|
|
232
|
-
SA:'Saudi Arabia',
|
|
233
|
-
SN:'Senegal',
|
|
234
|
-
RS:'Serbia',
|
|
235
|
-
SC:'Seychelles',
|
|
236
|
-
SL:'Sierra Leone',
|
|
237
|
-
SG:'Singapore',
|
|
238
|
-
SK:'Slovakia',
|
|
239
|
-
SI:'Slovenia',
|
|
240
|
-
SB:'Solomon Islands',
|
|
241
|
-
SO:'Somalia',
|
|
242
|
-
ZA:'South Africa',
|
|
243
|
-
GS:'South Georgia and The South Sandwich Islands',
|
|
244
|
-
ES:'Spain',
|
|
245
|
-
LK:'Sri Lanka',
|
|
246
|
-
SD:'Sudan',
|
|
247
|
-
SR:'Suriname',
|
|
248
|
-
SJ:'Svalbard and Jan Mayen',
|
|
249
|
-
SZ:'Swaziland',
|
|
250
|
-
SE:'Sweden',
|
|
251
|
-
CH:'Switzerland',
|
|
252
|
-
SY:'Syrian Arab Republic',
|
|
253
|
-
TW:'Taiwan, Province of China',
|
|
254
|
-
TJ:'Tajikistan',
|
|
255
|
-
TZ:'Tanzania, United Republic of',
|
|
256
|
-
TH:'Thailand',
|
|
257
|
-
TL:'Timor-leste',
|
|
258
|
-
TG:'Togo',
|
|
259
|
-
TK:'Tokelau',
|
|
260
|
-
TO:'Tonga',
|
|
261
|
-
TT:'Trinidad and Tobago',
|
|
262
|
-
TN:'Tunisia',
|
|
263
|
-
TR:'Turkey',
|
|
264
|
-
TM:'Turkmenistan',
|
|
265
|
-
TC:'Turks and Caicos Islands',
|
|
266
|
-
TV:'Tuvalu',
|
|
267
|
-
UG:'Uganda',
|
|
268
|
-
UA:'Ukraine',
|
|
269
|
-
AE:'United Arab Emirates',
|
|
270
|
-
GB:'United Kingdom',
|
|
271
|
-
US:'United States',
|
|
272
|
-
UM:'United States Minor Outlying Islands',
|
|
273
|
-
UY:'Uruguay',
|
|
274
|
-
UZ:'Uzbekistan',
|
|
275
|
-
VU:'Vanuatu',
|
|
276
|
-
VE:'Venezuela',
|
|
277
|
-
VN:'Viet Nam',
|
|
278
|
-
VG:'Virgin Islands, British',
|
|
279
|
-
VI:'Virgin Islands, U.S.',
|
|
280
|
-
WF:'Wallis and Futuna',
|
|
281
|
-
EH:'Western Sahara',
|
|
282
|
-
YE:'Yemen',
|
|
283
|
-
ZM:'Zambia',
|
|
284
|
-
ZW:'Zimbabwe',
|
|
285
|
-
};
|
|
56
|
+
|
|
57
|
+
static getCountryName(countryCode, locale='fr-FR') {
|
|
58
|
+
const name = isoCountries.getName(countryCode, locale);
|
|
59
|
+
return name || countryCode;
|
|
60
|
+
}
|
|
61
|
+
static getCountries(locale = 'en') {
|
|
62
|
+
const names = isoCountries.getNames(locale);
|
|
63
|
+
if (!names || Object.keys(names).length === 0) {
|
|
64
|
+
try {
|
|
65
|
+
isoCountries.registerLocale(require('i18n-iso-countries/langs/' + locale + '.json'));
|
|
66
|
+
} catch (e) {
|
|
67
|
+
// locale not available
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return isoCountries.getNames(locale);
|
|
286
71
|
}
|
|
287
72
|
|
|
288
73
|
static getContinents() {
|
|
@@ -297,10 +82,28 @@ class Country {
|
|
|
297
82
|
};
|
|
298
83
|
}
|
|
299
84
|
|
|
300
|
-
/** @deprecated **/
|
|
85
|
+
/** @deprecated Use getCountries instead **/
|
|
301
86
|
static getCountryList() {
|
|
302
87
|
return Country.getCountries();
|
|
303
88
|
}
|
|
89
|
+
/** @deprecated Use fillSelect instead **/
|
|
90
|
+
static fillCountrySelect(select, defaultValue=null, countriesList=null, addNoneValue=false, noneLabel='- Aucun -') {
|
|
91
|
+
select = toEl(select);
|
|
92
|
+
if (!select) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (select.children.length === 0) {
|
|
96
|
+
if (addNoneValue) {
|
|
97
|
+
select.insertAdjacentHTML('beforeend', '<option value="">'+noneLabel+'</option>');
|
|
98
|
+
}
|
|
99
|
+
Object.entries(null != countriesList ? countriesList : Country.getCountries()).forEach(([countryCode, countryName]) => {
|
|
100
|
+
select.insertAdjacentHTML('beforeend', '<option value="' + countryCode + '">' + countryName + '</option>');
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
if (null != defaultValue) {
|
|
104
|
+
select.value = defaultValue;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
304
107
|
}
|
|
305
108
|
|
|
306
109
|
class PostalAddress {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@osimatic/helpers-js",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.29",
|
|
4
4
|
"main": "main.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jest",
|
|
@@ -14,12 +14,14 @@
|
|
|
14
14
|
"description": "",
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"deepmerge": "^4.3.1",
|
|
17
|
+
"i18n-iso-countries": "^7.14.0",
|
|
17
18
|
"ilib": "^14.21",
|
|
18
19
|
"libphonenumber-js": "^1.12.39",
|
|
19
20
|
"ua-parser-js": "^2.0.9"
|
|
20
21
|
},
|
|
21
22
|
"peerDependencies": {
|
|
22
23
|
"datatables.net": ">=2.0",
|
|
24
|
+
"flag-icons": ">=7.0",
|
|
23
25
|
"intl-tel-input": ">=19.0",
|
|
24
26
|
"leaflet": ">=1.9",
|
|
25
27
|
"leaflet-draw": ">=1.0",
|
package/tests/location.test.js
CHANGED
|
@@ -13,7 +13,7 @@ describe('Country', () => {
|
|
|
13
13
|
test('should have correct country names', () => {
|
|
14
14
|
const countries = Country.getCountries();
|
|
15
15
|
expect(countries.FR).toBe('France');
|
|
16
|
-
expect(countries.US).toBe('United States');
|
|
16
|
+
expect(countries.US).toBe('United States of America');
|
|
17
17
|
expect(countries.GB).toBe('United Kingdom');
|
|
18
18
|
});
|
|
19
19
|
});
|
|
@@ -21,7 +21,7 @@ describe('Country', () => {
|
|
|
21
21
|
describe('getCountryName', () => {
|
|
22
22
|
test('should return country name for valid code', () => {
|
|
23
23
|
expect(Country.getCountryName('FR')).toBe('France');
|
|
24
|
-
expect(Country.getCountryName('US')).toBe('United States');
|
|
24
|
+
expect(Country.getCountryName('US')).toBe('United States of America');
|
|
25
25
|
expect(Country.getCountryName('CA')).toBe('Canada');
|
|
26
26
|
});
|
|
27
27
|
|
|
@@ -79,7 +79,7 @@ describe('Country', () => {
|
|
|
79
79
|
|
|
80
80
|
test('should include country name in title', () => {
|
|
81
81
|
const html = Country.getFlagImg('US');
|
|
82
|
-
expect(html).toContain('title="United States"');
|
|
82
|
+
expect(html).toContain('title="United States of America"');
|
|
83
83
|
});
|
|
84
84
|
|
|
85
85
|
test('should wrap img in span', () => {
|
|
@@ -96,6 +96,37 @@ describe('Country', () => {
|
|
|
96
96
|
expect(list).toEqual(countries);
|
|
97
97
|
});
|
|
98
98
|
});
|
|
99
|
+
|
|
100
|
+
describe('getFlagEmoji', () => {
|
|
101
|
+
test('should return emoji flag for country code', () => {
|
|
102
|
+
expect(Country.getFlagEmoji('FR')).toBe('π«π·');
|
|
103
|
+
expect(Country.getFlagEmoji('US')).toBe('πΊπΈ');
|
|
104
|
+
expect(Country.getFlagEmoji('GB')).toBe('π¬π§');
|
|
105
|
+
});
|
|
106
|
+
test('should handle lowercase country codes', () => {
|
|
107
|
+
expect(Country.getFlagEmoji('fr')).toBe('π«π·');
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe('getCountries with locale', () => {
|
|
112
|
+
test('should auto-register and return names for an unregistered locale', () => {
|
|
113
|
+
const countriesFr = Country.getCountries('fr');
|
|
114
|
+
expect(typeof countriesFr).toBe('object');
|
|
115
|
+
expect(countriesFr.FR).toBe('France');
|
|
116
|
+
expect(typeof countriesFr.US).toBe('string');
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('should return names for de locale', () => {
|
|
120
|
+
const countriesDe = Country.getCountries('de');
|
|
121
|
+
expect(typeof countriesDe).toBe('object');
|
|
122
|
+
expect(countriesDe.DE).toBeTruthy();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test('should return empty object for unknown locale', () => {
|
|
126
|
+
const result = Country.getCountries('xx');
|
|
127
|
+
expect(typeof result).toBe('object');
|
|
128
|
+
});
|
|
129
|
+
});
|
|
99
130
|
});
|
|
100
131
|
|
|
101
132
|
describe('GeographicCoordinates', () => {
|
|
@@ -717,11 +748,21 @@ describe('PostalAddress', () => {
|
|
|
717
748
|
expect(result.indexOf('75001')).toBeLessThan(result.indexOf('Paris'));
|
|
718
749
|
});
|
|
719
750
|
|
|
720
|
-
test('should place postalCode before locality for FR (locale parameter)', () => {
|
|
751
|
+
test('should place postalCode before locality for FR (locale parameter, no countryCode)', () => {
|
|
752
|
+
const result = PostalAddress.format({
|
|
753
|
+
streetAddress: '10 Rue de la Paix',
|
|
754
|
+
postalCode: '75001',
|
|
755
|
+
locality: 'Paris',
|
|
756
|
+
}, '\n', 'fr-FR');
|
|
757
|
+
expect(result.indexOf('75001')).toBeLessThan(result.indexOf('Paris'));
|
|
758
|
+
});
|
|
759
|
+
|
|
760
|
+
test('should place postalCode before locality for FR (locale parameter and countryCode)', () => {
|
|
721
761
|
const result = PostalAddress.format({
|
|
722
762
|
streetAddress: '10 Rue de la Paix',
|
|
723
763
|
postalCode: '75001',
|
|
724
764
|
locality: 'Paris',
|
|
765
|
+
countryCode: 'FR',
|
|
725
766
|
}, '\n', 'fr-FR');
|
|
726
767
|
expect(result.indexOf('75001')).toBeLessThan(result.indexOf('Paris'));
|
|
727
768
|
});
|