intl-tel-input 25.0.1 → 25.1.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intl-tel-input",
3
- "version": "25.0.1",
3
+ "version": "25.1.0",
4
4
  "description": "A JavaScript plugin for entering and validating international telephone numbers",
5
5
  "keywords": [
6
6
  "international",
package/react/README.md CHANGED
@@ -28,7 +28,7 @@ import "intl-tel-input/styles";
28
28
 
29
29
  See the [Validation demo](https://github.com/jackocnr/intl-tel-input/blob/master/react/demo/validation/ValidationApp.tsx) for a more fleshed-out example of how to handle validation.
30
30
 
31
- A note on the utils script (~260KB): if you're lazy loading the IntlTelInput chunk (and so less worried about filesize) then you can just import IntlTelInput from `"intl-tel-input/reactWithUtils"`, to include the utils script. Alternatively, if you use the main `"intl-tel-input/react"` import, then you should couple this with the `loadUtils` initialisation option - you will need to host the [utils.js](https://github.com/jackocnr/intl-tel-input/blob/master/build/js/utils.js) file, and then set the `loadUtils` option to that URL, or alternatively just point it to a CDN hosted version e.g. `"https://cdn.jsdelivr.net/npm/intl-tel-input@25.0.1/build/js/utils.js"`.
31
+ A note on the utils script (~260KB): if you're lazy loading the IntlTelInput chunk (and so less worried about filesize) then you can just import IntlTelInput from `"intl-tel-input/reactWithUtils"`, to include the utils script. Alternatively, if you use the main `"intl-tel-input/react"` import, then you should couple this with the `loadUtils` initialisation option - you will need to host the [utils.js](https://github.com/jackocnr/intl-tel-input/blob/master/build/js/utils.js) file, and then set the `loadUtils` option to that URL, or alternatively just point it to a CDN hosted version e.g. `"https://cdn.jsdelivr.net/npm/intl-tel-input@25.1.0/build/js/utils.js"`.
32
32
 
33
33
  ## Props
34
34
  Here's a list of all of the current props you can pass to the IntlTelInput React component.
@@ -45,8 +45,7 @@ var rawCountryData = [
45
45
  "ax",
46
46
  // Åland Islands
47
47
  "358",
48
- 1,
49
- ["18"]
48
+ 1
50
49
  ],
51
50
  [
52
51
  "al",
@@ -113,7 +112,9 @@ var rawCountryData = [
113
112
  "au",
114
113
  // Australia
115
114
  "61",
116
- 0
115
+ 0,
116
+ null,
117
+ "0"
117
118
  ],
118
119
  [
119
120
  "at",
@@ -294,14 +295,16 @@ var rawCountryData = [
294
295
  // Christmas Island
295
296
  "61",
296
297
  2,
297
- ["89164"]
298
+ ["89164"],
299
+ "0"
298
300
  ],
299
301
  [
300
302
  "cc",
301
303
  // Cocos (Keeling) Islands
302
304
  "61",
303
305
  1,
304
- ["89162"]
306
+ ["89162"],
307
+ "0"
305
308
  ],
306
309
  [
307
310
  "co",
@@ -534,7 +537,8 @@ var rawCountryData = [
534
537
  // Guernsey
535
538
  "44",
536
539
  1,
537
- ["1481", "7781", "7839", "7911"]
540
+ ["1481", "7781", "7839", "7911"],
541
+ "0"
538
542
  ],
539
543
  [
540
544
  "gn",
@@ -606,7 +610,8 @@ var rawCountryData = [
606
610
  // Isle of Man
607
611
  "44",
608
612
  2,
609
- ["1624", "74576", "7524", "7924", "7624"]
613
+ ["1624", "74576", "7524", "7924", "7624"],
614
+ "0"
610
615
  ],
611
616
  [
612
617
  "il",
@@ -636,7 +641,8 @@ var rawCountryData = [
636
641
  // Jersey
637
642
  "44",
638
643
  3,
639
- ["1534", "7509", "7700", "7797", "7829", "7937"]
644
+ ["1534", "7509", "7700", "7797", "7829", "7937"],
645
+ "0"
640
646
  ],
641
647
  [
642
648
  "jo",
@@ -648,7 +654,8 @@ var rawCountryData = [
648
654
  // Kazakhstan
649
655
  "7",
650
656
  1,
651
- ["33", "7"]
657
+ ["33", "7"],
658
+ "8"
652
659
  ],
653
660
  [
654
661
  "ke",
@@ -780,7 +787,8 @@ var rawCountryData = [
780
787
  // Mayotte
781
788
  "262",
782
789
  1,
783
- ["269", "639"]
790
+ ["269", "639"],
791
+ "0"
784
792
  ],
785
793
  [
786
794
  "mx",
@@ -823,7 +831,9 @@ var rawCountryData = [
823
831
  "ma",
824
832
  // Morocco
825
833
  "212",
826
- 0
834
+ 0,
835
+ null,
836
+ "0"
827
837
  ],
828
838
  [
829
839
  "mz",
@@ -984,7 +994,9 @@ var rawCountryData = [
984
994
  "re",
985
995
  // Réunion
986
996
  "262",
987
- 0
997
+ 0,
998
+ null,
999
+ "0"
988
1000
  ],
989
1001
  [
990
1002
  "ro",
@@ -995,7 +1007,9 @@ var rawCountryData = [
995
1007
  "ru",
996
1008
  // Russia
997
1009
  "7",
998
- 0
1010
+ 0,
1011
+ null,
1012
+ "8"
999
1013
  ],
1000
1014
  [
1001
1015
  "rw",
@@ -1267,7 +1281,9 @@ var rawCountryData = [
1267
1281
  "gb",
1268
1282
  // United Kingdom
1269
1283
  "44",
1270
- 0
1284
+ 0,
1285
+ null,
1286
+ "0"
1271
1287
  ],
1272
1288
  [
1273
1289
  "us",
@@ -1324,7 +1340,8 @@ var rawCountryData = [
1324
1340
  // Western Sahara
1325
1341
  "212",
1326
1342
  1,
1327
- ["5288", "5289"]
1343
+ ["5288", "5289"],
1344
+ "0"
1328
1345
  ],
1329
1346
  [
1330
1347
  "ye",
@@ -1352,7 +1369,8 @@ for (let i = 0; i < rawCountryData.length; i++) {
1352
1369
  dialCode: c[1],
1353
1370
  priority: c[2] || 0,
1354
1371
  areaCodes: c[3] || null,
1355
- nodeById: {}
1372
+ nodeById: {},
1373
+ nationalPrefix: c[4] || null
1356
1374
  };
1357
1375
  }
1358
1376
  var data_default = allCountries;
@@ -1895,7 +1913,8 @@ var Iti = class {
1895
1913
  for (let j = 0; j < c.areaCodes.length; j++) {
1896
1914
  const areaCode = c.areaCodes[j];
1897
1915
  for (let k = 1; k < areaCode.length; k++) {
1898
- const partialDialCode = c.dialCode + areaCode.substr(0, k);
1916
+ const partialAreaCode = areaCode.substr(0, k);
1917
+ const partialDialCode = c.dialCode + partialAreaCode;
1899
1918
  this._addToDialCodeMap(rootIso2Code, partialDialCode);
1900
1919
  this._addToDialCodeMap(c.iso2, partialDialCode);
1901
1920
  }
@@ -2555,25 +2574,35 @@ var Iti = class {
2555
2574
  }
2556
2575
  return false;
2557
2576
  }
2577
+ _ensureHasDialCode(number) {
2578
+ const { dialCode, nationalPrefix } = this.selectedCountryData;
2579
+ const alreadyHasPlus = number.charAt(0) === "+";
2580
+ if (alreadyHasPlus || !dialCode) {
2581
+ return number;
2582
+ }
2583
+ const hasPrefix = nationalPrefix && number.charAt(0) === nationalPrefix && !this.options.separateDialCode;
2584
+ const cleanNumber = hasPrefix ? number.substring(1) : number;
2585
+ return `+${dialCode}${cleanNumber}`;
2586
+ }
2558
2587
  _getCountryFromNumber(fullNumber) {
2559
2588
  const plusIndex = fullNumber.indexOf("+");
2560
2589
  let number = plusIndex ? fullNumber.substring(plusIndex) : fullNumber;
2590
+ const selectedIso2 = this.selectedCountryData.iso2;
2561
2591
  const selectedDialCode = this.selectedCountryData.dialCode;
2562
- const isNanp = selectedDialCode === "1";
2563
- if (number && isNanp && number.charAt(0) !== "+") {
2564
- if (number.charAt(0) !== "1") {
2565
- number = `1${number}`;
2566
- }
2567
- number = `+${number}`;
2568
- }
2569
- if (this.options.separateDialCode && selectedDialCode && number.charAt(0) !== "+") {
2570
- number = `+${selectedDialCode}${number}`;
2592
+ number = this._ensureHasDialCode(number);
2593
+ const dialCodeMatch = this._getDialCode(number, true);
2594
+ if (dialCodeMatch && dialCodeMatch === this.prevDialCodeMatch) {
2595
+ return null;
2571
2596
  }
2572
- const dialCode = this._getDialCode(number, true);
2597
+ this.prevDialCodeMatch = dialCodeMatch;
2573
2598
  const numeric = getNumeric(number);
2574
- if (dialCode) {
2575
- const iso2Codes = this.dialCodeToIso2Map[getNumeric(dialCode)];
2576
- const alreadySelected = iso2Codes.indexOf(this.selectedCountryData.iso2) !== -1 && numeric.length <= dialCode.length - 1;
2599
+ if (dialCodeMatch) {
2600
+ const dialCodeMatchNumeric = getNumeric(dialCodeMatch);
2601
+ const iso2Codes = this.dialCodeToIso2Map[dialCodeMatchNumeric];
2602
+ if (!selectedIso2 && this.defaultCountry && iso2Codes.includes(this.defaultCountry)) {
2603
+ return this.defaultCountry;
2604
+ }
2605
+ const alreadySelected = selectedIso2 && iso2Codes.includes(selectedIso2) && numeric.length === dialCodeMatchNumeric.length;
2577
2606
  const isRegionlessNanpNumber = selectedDialCode === "1" && isRegionlessNanp(numeric);
2578
2607
  if (!isRegionlessNanpNumber && !alreadySelected) {
2579
2608
  for (let j = 0; j < iso2Codes.length; j++) {
@@ -3139,7 +3168,7 @@ var intlTelInput = Object.assign(
3139
3168
  attachUtils,
3140
3169
  startedLoadingUtilsScript: false,
3141
3170
  startedLoadingAutoCountry: false,
3142
- version: "25.0.1"
3171
+ version: "25.1.0"
3143
3172
  }
3144
3173
  );
3145
3174
  var intl_tel_input_default = intlTelInput;
@@ -6,6 +6,7 @@ declare module "intl-tel-input/data" {
6
6
  priority: number;
7
7
  areaCodes: string[] | null;
8
8
  nodeById: object;
9
+ nationalPrefix: string | null;
9
10
  };
10
11
  const allCountries: Country[];
11
12
  export default allCountries;
@@ -324,10 +325,12 @@ declare module "intl-tel-input" {
324
325
  numberType: object;
325
326
  };
326
327
  type NumberType = "FIXED_LINE_OR_MOBILE" | "FIXED_LINE" | "MOBILE" | "PAGER" | "PERSONAL_NUMBER" | "PREMIUM_RATE" | "SHARED_COST" | "TOLL_FREE" | "UAN" | "UNKNOWN" | "VOICEMAIL" | "VOIP";
327
- type SelectedCountryData = Country | {
328
+ type SelectedCountryData = {
328
329
  name?: string;
329
330
  iso2?: string;
330
331
  dialCode?: string;
332
+ areaCodes?: string[];
333
+ nationalPrefix?: string;
331
334
  };
332
335
  interface AllOptions {
333
336
  allowDropdown: boolean;
@@ -391,6 +394,7 @@ declare module "intl-tel-input" {
391
394
  private defaultCountry;
392
395
  private originalPaddingRight;
393
396
  private originalPaddingLeft;
397
+ private prevDialCodeMatch;
394
398
  private _handleHiddenInputSubmit;
395
399
  private _handleLabelClick;
396
400
  private _handleClickSelectedCountry;
@@ -438,6 +442,7 @@ declare module "intl-tel-input" {
438
442
  private _handleEnterKey;
439
443
  private _updateValFromNumber;
440
444
  private _updateCountryFromNumber;
445
+ private _ensureHasDialCode;
441
446
  private _getCountryFromNumber;
442
447
  private _highlightListItem;
443
448
  private _getCountryData;
@@ -9,8 +9,7 @@ var rawCountryData = [
9
9
  "ax",
10
10
  // Åland Islands
11
11
  "358",
12
- 1,
13
- ["18"]
12
+ 1
14
13
  ],
15
14
  [
16
15
  "al",
@@ -77,7 +76,9 @@ var rawCountryData = [
77
76
  "au",
78
77
  // Australia
79
78
  "61",
80
- 0
79
+ 0,
80
+ null,
81
+ "0"
81
82
  ],
82
83
  [
83
84
  "at",
@@ -258,14 +259,16 @@ var rawCountryData = [
258
259
  // Christmas Island
259
260
  "61",
260
261
  2,
261
- ["89164"]
262
+ ["89164"],
263
+ "0"
262
264
  ],
263
265
  [
264
266
  "cc",
265
267
  // Cocos (Keeling) Islands
266
268
  "61",
267
269
  1,
268
- ["89162"]
270
+ ["89162"],
271
+ "0"
269
272
  ],
270
273
  [
271
274
  "co",
@@ -498,7 +501,8 @@ var rawCountryData = [
498
501
  // Guernsey
499
502
  "44",
500
503
  1,
501
- ["1481", "7781", "7839", "7911"]
504
+ ["1481", "7781", "7839", "7911"],
505
+ "0"
502
506
  ],
503
507
  [
504
508
  "gn",
@@ -570,7 +574,8 @@ var rawCountryData = [
570
574
  // Isle of Man
571
575
  "44",
572
576
  2,
573
- ["1624", "74576", "7524", "7924", "7624"]
577
+ ["1624", "74576", "7524", "7924", "7624"],
578
+ "0"
574
579
  ],
575
580
  [
576
581
  "il",
@@ -600,7 +605,8 @@ var rawCountryData = [
600
605
  // Jersey
601
606
  "44",
602
607
  3,
603
- ["1534", "7509", "7700", "7797", "7829", "7937"]
608
+ ["1534", "7509", "7700", "7797", "7829", "7937"],
609
+ "0"
604
610
  ],
605
611
  [
606
612
  "jo",
@@ -612,7 +618,8 @@ var rawCountryData = [
612
618
  // Kazakhstan
613
619
  "7",
614
620
  1,
615
- ["33", "7"]
621
+ ["33", "7"],
622
+ "8"
616
623
  ],
617
624
  [
618
625
  "ke",
@@ -744,7 +751,8 @@ var rawCountryData = [
744
751
  // Mayotte
745
752
  "262",
746
753
  1,
747
- ["269", "639"]
754
+ ["269", "639"],
755
+ "0"
748
756
  ],
749
757
  [
750
758
  "mx",
@@ -787,7 +795,9 @@ var rawCountryData = [
787
795
  "ma",
788
796
  // Morocco
789
797
  "212",
790
- 0
798
+ 0,
799
+ null,
800
+ "0"
791
801
  ],
792
802
  [
793
803
  "mz",
@@ -948,7 +958,9 @@ var rawCountryData = [
948
958
  "re",
949
959
  // Réunion
950
960
  "262",
951
- 0
961
+ 0,
962
+ null,
963
+ "0"
952
964
  ],
953
965
  [
954
966
  "ro",
@@ -959,7 +971,9 @@ var rawCountryData = [
959
971
  "ru",
960
972
  // Russia
961
973
  "7",
962
- 0
974
+ 0,
975
+ null,
976
+ "8"
963
977
  ],
964
978
  [
965
979
  "rw",
@@ -1231,7 +1245,9 @@ var rawCountryData = [
1231
1245
  "gb",
1232
1246
  // United Kingdom
1233
1247
  "44",
1234
- 0
1248
+ 0,
1249
+ null,
1250
+ "0"
1235
1251
  ],
1236
1252
  [
1237
1253
  "us",
@@ -1288,7 +1304,8 @@ var rawCountryData = [
1288
1304
  // Western Sahara
1289
1305
  "212",
1290
1306
  1,
1291
- ["5288", "5289"]
1307
+ ["5288", "5289"],
1308
+ "0"
1292
1309
  ],
1293
1310
  [
1294
1311
  "ye",
@@ -1316,7 +1333,8 @@ for (let i = 0; i < rawCountryData.length; i++) {
1316
1333
  dialCode: c[1],
1317
1334
  priority: c[2] || 0,
1318
1335
  areaCodes: c[3] || null,
1319
- nodeById: {}
1336
+ nodeById: {},
1337
+ nationalPrefix: c[4] || null
1320
1338
  };
1321
1339
  }
1322
1340
  var data_default = allCountries;
@@ -1859,7 +1877,8 @@ var Iti = class {
1859
1877
  for (let j = 0; j < c.areaCodes.length; j++) {
1860
1878
  const areaCode = c.areaCodes[j];
1861
1879
  for (let k = 1; k < areaCode.length; k++) {
1862
- const partialDialCode = c.dialCode + areaCode.substr(0, k);
1880
+ const partialAreaCode = areaCode.substr(0, k);
1881
+ const partialDialCode = c.dialCode + partialAreaCode;
1863
1882
  this._addToDialCodeMap(rootIso2Code, partialDialCode);
1864
1883
  this._addToDialCodeMap(c.iso2, partialDialCode);
1865
1884
  }
@@ -2519,25 +2538,35 @@ var Iti = class {
2519
2538
  }
2520
2539
  return false;
2521
2540
  }
2541
+ _ensureHasDialCode(number) {
2542
+ const { dialCode, nationalPrefix } = this.selectedCountryData;
2543
+ const alreadyHasPlus = number.charAt(0) === "+";
2544
+ if (alreadyHasPlus || !dialCode) {
2545
+ return number;
2546
+ }
2547
+ const hasPrefix = nationalPrefix && number.charAt(0) === nationalPrefix && !this.options.separateDialCode;
2548
+ const cleanNumber = hasPrefix ? number.substring(1) : number;
2549
+ return `+${dialCode}${cleanNumber}`;
2550
+ }
2522
2551
  _getCountryFromNumber(fullNumber) {
2523
2552
  const plusIndex = fullNumber.indexOf("+");
2524
2553
  let number = plusIndex ? fullNumber.substring(plusIndex) : fullNumber;
2554
+ const selectedIso2 = this.selectedCountryData.iso2;
2525
2555
  const selectedDialCode = this.selectedCountryData.dialCode;
2526
- const isNanp = selectedDialCode === "1";
2527
- if (number && isNanp && number.charAt(0) !== "+") {
2528
- if (number.charAt(0) !== "1") {
2529
- number = `1${number}`;
2530
- }
2531
- number = `+${number}`;
2532
- }
2533
- if (this.options.separateDialCode && selectedDialCode && number.charAt(0) !== "+") {
2534
- number = `+${selectedDialCode}${number}`;
2556
+ number = this._ensureHasDialCode(number);
2557
+ const dialCodeMatch = this._getDialCode(number, true);
2558
+ if (dialCodeMatch && dialCodeMatch === this.prevDialCodeMatch) {
2559
+ return null;
2535
2560
  }
2536
- const dialCode = this._getDialCode(number, true);
2561
+ this.prevDialCodeMatch = dialCodeMatch;
2537
2562
  const numeric = getNumeric(number);
2538
- if (dialCode) {
2539
- const iso2Codes = this.dialCodeToIso2Map[getNumeric(dialCode)];
2540
- const alreadySelected = iso2Codes.indexOf(this.selectedCountryData.iso2) !== -1 && numeric.length <= dialCode.length - 1;
2563
+ if (dialCodeMatch) {
2564
+ const dialCodeMatchNumeric = getNumeric(dialCodeMatch);
2565
+ const iso2Codes = this.dialCodeToIso2Map[dialCodeMatchNumeric];
2566
+ if (!selectedIso2 && this.defaultCountry && iso2Codes.includes(this.defaultCountry)) {
2567
+ return this.defaultCountry;
2568
+ }
2569
+ const alreadySelected = selectedIso2 && iso2Codes.includes(selectedIso2) && numeric.length === dialCodeMatchNumeric.length;
2541
2570
  const isRegionlessNanpNumber = selectedDialCode === "1" && isRegionlessNanp(numeric);
2542
2571
  if (!isRegionlessNanpNumber && !alreadySelected) {
2543
2572
  for (let j = 0; j < iso2Codes.length; j++) {
@@ -3103,7 +3132,7 @@ var intlTelInput = Object.assign(
3103
3132
  attachUtils,
3104
3133
  startedLoadingUtilsScript: false,
3105
3134
  startedLoadingAutoCountry: false,
3106
- version: "25.0.1"
3135
+ version: "25.1.0"
3107
3136
  }
3108
3137
  );
3109
3138
  var intl_tel_input_default = intlTelInput;