@osimatic/helpers-js 1.1.24 → 1.1.25

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/contact_details.js +37 -8
  2. package/package.json +1 -1
@@ -56,7 +56,14 @@ class TelephoneNumber {
56
56
 
57
57
  static getCountryIsoCode(phoneNumber, localCountryIsoCode) {
58
58
  localCountryIsoCode = (typeof localCountryIsoCode != 'undefined' ? localCountryIsoCode.toUpperCase() : serviceCountry);
59
- return libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode).country || '';
59
+ try {
60
+ const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode);
61
+ return number != null ? number.country : null;
62
+ } catch (error) {
63
+ console.error(error);
64
+ }
65
+ return null;
66
+ //return libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode).country || '';
60
67
  }
61
68
  static getCountryName(phoneNumber, localCountryIsoCode) {
62
69
  return Country.getCountryName(this.getCountryIsoCode(phoneNumber, localCountryIsoCode));
@@ -66,11 +73,25 @@ class TelephoneNumber {
66
73
  }
67
74
  static formatNational(phoneNumber, localCountryIsoCode) {
68
75
  localCountryIsoCode = (typeof localCountryIsoCode != 'undefined' ? localCountryIsoCode.toUpperCase() : serviceCountry);
69
- return libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode).formatNational();
76
+ try {
77
+ const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode);
78
+ return number != null ? number.formatNational() : '';
79
+ } catch (error) {
80
+ console.error(error);
81
+ }
82
+ return '';
83
+ //return libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode).formatNational();
70
84
  }
71
85
  static formatInternational(phoneNumber, localCountryIsoCode) {
72
86
  localCountryIsoCode = (typeof localCountryIsoCode != 'undefined' ? localCountryIsoCode.toUpperCase() : serviceCountry);
73
- return libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode).formatInternational();
87
+ try {
88
+ const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode);
89
+ return number != null ? number.formatInternational() : '';
90
+ } catch (error) {
91
+ console.error(error);
92
+ }
93
+ return '';
94
+ //return libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode).formatInternational();
74
95
  }
75
96
  static formatInternationalWithTelLink(phoneNumber, localCountryIsoCode) {
76
97
  return '<a href="tel:'+phoneNumber+'">'+TelephoneNumber.formatInternational(phoneNumber, localCountryIsoCode)+'</a>';
@@ -90,13 +111,16 @@ class TelephoneNumber {
90
111
  } catch (error) {
91
112
  console.error(error);
92
113
  }
93
- return '';
114
+ return null;
94
115
  }
95
116
 
96
117
  static check(phoneNumber, localCountryIsoCode) {
97
118
  localCountryIsoCode = (typeof localCountryIsoCode != 'undefined' ? localCountryIsoCode.toUpperCase() : serviceCountry);
98
- const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode);
99
- return number != null ? number.isValid() : false;
119
+ try {
120
+ const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode);
121
+ return number != null ? number.isValid() : false;
122
+ } catch (error) { }
123
+ return false;
100
124
  //var numberObject = libphonenumber.parse(phoneNumber, localCountryIsoCode);
101
125
  //return (typeof numberObject.country !== 'undefined');
102
126
  }
@@ -117,8 +141,13 @@ class TelephoneNumber {
117
141
  return 'MASKED';
118
142
  }
119
143
 
120
- let number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode);
121
- return number != null ? number.getType() : null;
144
+ try {
145
+ const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode);
146
+ return number != null ? number.getType() : null;
147
+ } catch (error) {
148
+ console.error(error);
149
+ }
150
+ return null;
122
151
  }
123
152
 
124
153
  static getTypeLabelList() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.1.24",
3
+ "version": "1.1.25",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"