@takentrade/takentrade-libs 4.0.6 → 4.0.7
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.
|
@@ -158,16 +158,21 @@ function toSmsSafeNigerianPhone(phone) {
|
|
|
158
158
|
let digits = `${phone}`.replace(/\D/g, '').trim();
|
|
159
159
|
if (digits === '')
|
|
160
160
|
return '';
|
|
161
|
-
// If already 234... and correct length, return as is
|
|
162
161
|
if (digits.startsWith('234') && digits.length === 13) {
|
|
163
162
|
return digits;
|
|
164
163
|
}
|
|
165
|
-
// If starts with 0 and length is 11 (e.g. 0803...), strip the 0
|
|
166
164
|
if (digits.startsWith('0') && digits.length === 11) {
|
|
167
|
-
|
|
165
|
+
return '234' + digits.slice(1);
|
|
168
166
|
}
|
|
169
|
-
|
|
170
|
-
|
|
167
|
+
if (digits.length === 10 && /^[789]/.test(digits)) {
|
|
168
|
+
return '234' + digits;
|
|
169
|
+
}
|
|
170
|
+
if (digits.length >= 11 &&
|
|
171
|
+
!digits.startsWith('0') &&
|
|
172
|
+
!digits.startsWith('234')) {
|
|
173
|
+
return digits;
|
|
174
|
+
}
|
|
175
|
+
return digits.startsWith('234') ? digits : '234' + digits;
|
|
171
176
|
}
|
|
172
177
|
const formatTransactionStatus = (status) => {
|
|
173
178
|
const statusMap = {
|
|
@@ -92,6 +92,8 @@ const sanitizePhoneNumber = (phone, withPlus = false) => {
|
|
|
92
92
|
if (!phone)
|
|
93
93
|
return '';
|
|
94
94
|
const digits = phone.replace(/\D/g, '');
|
|
95
|
+
if (digits === '')
|
|
96
|
+
return '';
|
|
95
97
|
if (digits.startsWith('234') && digits.length >= 13) {
|
|
96
98
|
return withPlus ? '+' + digits : digits;
|
|
97
99
|
}
|
|
@@ -106,9 +108,14 @@ const sanitizePhoneNumber = (phone, withPlus = false) => {
|
|
|
106
108
|
if (digits.startsWith('234')) {
|
|
107
109
|
return withPlus ? '+' + digits : digits;
|
|
108
110
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
111
|
+
if (phone.trim().startsWith('+') || digits.length >= 11) {
|
|
112
|
+
return withPlus ? '+' + digits : digits;
|
|
113
|
+
}
|
|
114
|
+
if (digits.length === 10) {
|
|
115
|
+
const result = '234' + digits;
|
|
116
|
+
return withPlus ? '+' + result : result;
|
|
117
|
+
}
|
|
118
|
+
return withPlus && phone.trim().startsWith('+') ? '+' + digits : digits;
|
|
112
119
|
};
|
|
113
120
|
exports.sanitizePhoneNumber = sanitizePhoneNumber;
|
|
114
121
|
/**
|