@tiquo/dom-package 1.2.0 → 1.3.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/README.md +166 -2
- package/dist/index.d.mts +174 -2
- package/dist/index.d.ts +174 -2
- package/dist/index.js +527 -3
- package/dist/index.mjs +526 -3
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -134,6 +134,485 @@ async function trackCustomerPresence(organizationId) {
|
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
+
// src/phone-utils.ts
|
|
138
|
+
var COUNTRIES = [
|
|
139
|
+
// ── North America (NANP +1) ──
|
|
140
|
+
{ code: "US", name: "United States", dialCode: "+1", format: "(XXX) XXX-XXXX", flag: "\u{1F1FA}\u{1F1F8}" },
|
|
141
|
+
{ code: "CA", name: "Canada", dialCode: "+1", format: "(XXX) XXX-XXXX", flag: "\u{1F1E8}\u{1F1E6}" },
|
|
142
|
+
{ code: "AG", name: "Antigua and Barbuda", dialCode: "+1268", format: "XXX-XXXX", flag: "\u{1F1E6}\u{1F1EC}" },
|
|
143
|
+
{ code: "AI", name: "Anguilla", dialCode: "+1264", format: "XXX-XXXX", flag: "\u{1F1E6}\u{1F1EE}" },
|
|
144
|
+
{ code: "AS", name: "American Samoa", dialCode: "+1684", format: "XXX-XXXX", flag: "\u{1F1E6}\u{1F1F8}" },
|
|
145
|
+
{ code: "BB", name: "Barbados", dialCode: "+1246", format: "XXX-XXXX", flag: "\u{1F1E7}\u{1F1E7}" },
|
|
146
|
+
{ code: "BM", name: "Bermuda", dialCode: "+1441", format: "XXX-XXXX", flag: "\u{1F1E7}\u{1F1F2}" },
|
|
147
|
+
{ code: "BS", name: "Bahamas", dialCode: "+1242", format: "XXX-XXXX", flag: "\u{1F1E7}\u{1F1F8}" },
|
|
148
|
+
{ code: "DM", name: "Dominica", dialCode: "+1767", format: "XXX-XXXX", flag: "\u{1F1E9}\u{1F1F2}" },
|
|
149
|
+
{ code: "DO", name: "Dominican Republic", dialCode: "+1809", format: "XXX-XXXX", flag: "\u{1F1E9}\u{1F1F4}" },
|
|
150
|
+
{ code: "GD", name: "Grenada", dialCode: "+1473", format: "XXX-XXXX", flag: "\u{1F1EC}\u{1F1E9}" },
|
|
151
|
+
{ code: "GU", name: "Guam", dialCode: "+1671", format: "XXX-XXXX", flag: "\u{1F1EC}\u{1F1FA}" },
|
|
152
|
+
{ code: "JM", name: "Jamaica", dialCode: "+1876", format: "XXX-XXXX", flag: "\u{1F1EF}\u{1F1F2}" },
|
|
153
|
+
{ code: "KN", name: "Saint Kitts and Nevis", dialCode: "+1869", format: "XXX-XXXX", flag: "\u{1F1F0}\u{1F1F3}" },
|
|
154
|
+
{ code: "KY", name: "Cayman Islands", dialCode: "+1345", format: "XXX-XXXX", flag: "\u{1F1F0}\u{1F1FE}" },
|
|
155
|
+
{ code: "LC", name: "Saint Lucia", dialCode: "+1758", format: "XXX-XXXX", flag: "\u{1F1F1}\u{1F1E8}" },
|
|
156
|
+
{ code: "MP", name: "Northern Mariana Islands", dialCode: "+1670", format: "XXX-XXXX", flag: "\u{1F1F2}\u{1F1F5}" },
|
|
157
|
+
{ code: "MS", name: "Montserrat", dialCode: "+1664", format: "XXX-XXXX", flag: "\u{1F1F2}\u{1F1F8}" },
|
|
158
|
+
{ code: "PR", name: "Puerto Rico", dialCode: "+1787", format: "XXX-XXXX", flag: "\u{1F1F5}\u{1F1F7}" },
|
|
159
|
+
{ code: "SX", name: "Sint Maarten", dialCode: "+1721", format: "XXX-XXXX", flag: "\u{1F1F8}\u{1F1FD}" },
|
|
160
|
+
{ code: "TC", name: "Turks and Caicos Islands", dialCode: "+1649", format: "XXX-XXXX", flag: "\u{1F1F9}\u{1F1E8}" },
|
|
161
|
+
{ code: "TT", name: "Trinidad and Tobago", dialCode: "+1868", format: "XXX-XXXX", flag: "\u{1F1F9}\u{1F1F9}" },
|
|
162
|
+
{ code: "VC", name: "Saint Vincent and the Grenadines", dialCode: "+1784", format: "XXX-XXXX", flag: "\u{1F1FB}\u{1F1E8}" },
|
|
163
|
+
{ code: "VG", name: "British Virgin Islands", dialCode: "+1284", format: "XXX-XXXX", flag: "\u{1F1FB}\u{1F1EC}" },
|
|
164
|
+
{ code: "VI", name: "US Virgin Islands", dialCode: "+1340", format: "XXX-XXXX", flag: "\u{1F1FB}\u{1F1EE}" },
|
|
165
|
+
// ── Europe ──
|
|
166
|
+
{ code: "GB", name: "United Kingdom", dialCode: "+44", format: "XXXX XXXXXX", flag: "\u{1F1EC}\u{1F1E7}" },
|
|
167
|
+
{ code: "IE", name: "Ireland", dialCode: "+353", format: "XX XXX XXXX", flag: "\u{1F1EE}\u{1F1EA}" },
|
|
168
|
+
{ code: "FR", name: "France", dialCode: "+33", format: "X XX XX XX XX", flag: "\u{1F1EB}\u{1F1F7}" },
|
|
169
|
+
{ code: "DE", name: "Germany", dialCode: "+49", format: "XXX XXXXXXX", flag: "\u{1F1E9}\u{1F1EA}" },
|
|
170
|
+
{ code: "IT", name: "Italy", dialCode: "+39", format: "XXX XXX XXXX", flag: "\u{1F1EE}\u{1F1F9}" },
|
|
171
|
+
{ code: "ES", name: "Spain", dialCode: "+34", format: "XXX XXX XXX", flag: "\u{1F1EA}\u{1F1F8}" },
|
|
172
|
+
{ code: "PT", name: "Portugal", dialCode: "+351", format: "XXX XXX XXX", flag: "\u{1F1F5}\u{1F1F9}" },
|
|
173
|
+
{ code: "NL", name: "Netherlands", dialCode: "+31", format: "X XXXX XXXX", flag: "\u{1F1F3}\u{1F1F1}" },
|
|
174
|
+
{ code: "BE", name: "Belgium", dialCode: "+32", format: "XXX XX XX XX", flag: "\u{1F1E7}\u{1F1EA}" },
|
|
175
|
+
{ code: "LU", name: "Luxembourg", dialCode: "+352", format: "XXX XXX XXX", flag: "\u{1F1F1}\u{1F1FA}" },
|
|
176
|
+
{ code: "CH", name: "Switzerland", dialCode: "+41", format: "XX XXX XX XX", flag: "\u{1F1E8}\u{1F1ED}" },
|
|
177
|
+
{ code: "AT", name: "Austria", dialCode: "+43", format: "XXX XXXXXXX", flag: "\u{1F1E6}\u{1F1F9}" },
|
|
178
|
+
{ code: "SE", name: "Sweden", dialCode: "+46", format: "XX XXX XX XX", flag: "\u{1F1F8}\u{1F1EA}" },
|
|
179
|
+
{ code: "NO", name: "Norway", dialCode: "+47", format: "XXX XX XXX", flag: "\u{1F1F3}\u{1F1F4}" },
|
|
180
|
+
{ code: "DK", name: "Denmark", dialCode: "+45", format: "XX XX XX XX", flag: "\u{1F1E9}\u{1F1F0}" },
|
|
181
|
+
{ code: "FI", name: "Finland", dialCode: "+358", format: "XX XXX XXXX", flag: "\u{1F1EB}\u{1F1EE}" },
|
|
182
|
+
{ code: "IS", name: "Iceland", dialCode: "+354", format: "XXX XXXX", flag: "\u{1F1EE}\u{1F1F8}" },
|
|
183
|
+
{ code: "PL", name: "Poland", dialCode: "+48", format: "XXX XXX XXX", flag: "\u{1F1F5}\u{1F1F1}" },
|
|
184
|
+
{ code: "CZ", name: "Czech Republic", dialCode: "+420", format: "XXX XXX XXX", flag: "\u{1F1E8}\u{1F1FF}" },
|
|
185
|
+
{ code: "SK", name: "Slovakia", dialCode: "+421", format: "XXX XXX XXX", flag: "\u{1F1F8}\u{1F1F0}" },
|
|
186
|
+
{ code: "HU", name: "Hungary", dialCode: "+36", format: "XX XXX XXXX", flag: "\u{1F1ED}\u{1F1FA}" },
|
|
187
|
+
{ code: "RO", name: "Romania", dialCode: "+40", format: "XXX XXX XXX", flag: "\u{1F1F7}\u{1F1F4}" },
|
|
188
|
+
{ code: "BG", name: "Bulgaria", dialCode: "+359", format: "XX XXX XXXX", flag: "\u{1F1E7}\u{1F1EC}" },
|
|
189
|
+
{ code: "HR", name: "Croatia", dialCode: "+385", format: "XX XXX XXXX", flag: "\u{1F1ED}\u{1F1F7}" },
|
|
190
|
+
{ code: "SI", name: "Slovenia", dialCode: "+386", format: "XX XXX XXX", flag: "\u{1F1F8}\u{1F1EE}" },
|
|
191
|
+
{ code: "RS", name: "Serbia", dialCode: "+381", format: "XX XXX XXXX", flag: "\u{1F1F7}\u{1F1F8}" },
|
|
192
|
+
{ code: "BA", name: "Bosnia and Herzegovina", dialCode: "+387", format: "XX XXX XXX", flag: "\u{1F1E7}\u{1F1E6}" },
|
|
193
|
+
{ code: "ME", name: "Montenegro", dialCode: "+382", format: "XX XXX XXX", flag: "\u{1F1F2}\u{1F1EA}" },
|
|
194
|
+
{ code: "MK", name: "North Macedonia", dialCode: "+389", format: "XX XXX XXX", flag: "\u{1F1F2}\u{1F1F0}" },
|
|
195
|
+
{ code: "AL", name: "Albania", dialCode: "+355", format: "XX XXX XXXX", flag: "\u{1F1E6}\u{1F1F1}" },
|
|
196
|
+
{ code: "XK", name: "Kosovo", dialCode: "+383", format: "XX XXX XXX", flag: "\u{1F1FD}\u{1F1F0}" },
|
|
197
|
+
{ code: "GR", name: "Greece", dialCode: "+30", format: "XXX XXX XXXX", flag: "\u{1F1EC}\u{1F1F7}" },
|
|
198
|
+
{ code: "CY", name: "Cyprus", dialCode: "+357", format: "XX XXXXXX", flag: "\u{1F1E8}\u{1F1FE}" },
|
|
199
|
+
{ code: "MT", name: "Malta", dialCode: "+356", format: "XXXX XXXX", flag: "\u{1F1F2}\u{1F1F9}" },
|
|
200
|
+
{ code: "TR", name: "Turkey", dialCode: "+90", format: "XXX XXX XXXX", flag: "\u{1F1F9}\u{1F1F7}" },
|
|
201
|
+
{ code: "LT", name: "Lithuania", dialCode: "+370", format: "XXX XXXXX", flag: "\u{1F1F1}\u{1F1F9}" },
|
|
202
|
+
{ code: "LV", name: "Latvia", dialCode: "+371", format: "XXXX XXXX", flag: "\u{1F1F1}\u{1F1FB}" },
|
|
203
|
+
{ code: "EE", name: "Estonia", dialCode: "+372", format: "XXXX XXXX", flag: "\u{1F1EA}\u{1F1EA}" },
|
|
204
|
+
{ code: "MD", name: "Moldova", dialCode: "+373", format: "XX XXX XXX", flag: "\u{1F1F2}\u{1F1E9}" },
|
|
205
|
+
{ code: "UA", name: "Ukraine", dialCode: "+380", format: "XX XXX XX XX", flag: "\u{1F1FA}\u{1F1E6}" },
|
|
206
|
+
{ code: "BY", name: "Belarus", dialCode: "+375", format: "XX XXX XX XX", flag: "\u{1F1E7}\u{1F1FE}" },
|
|
207
|
+
{ code: "RU", name: "Russia", dialCode: "+7", format: "XXX XXX-XX-XX", flag: "\u{1F1F7}\u{1F1FA}" },
|
|
208
|
+
{ code: "GE", name: "Georgia", dialCode: "+995", format: "XXX XX XX XX", flag: "\u{1F1EC}\u{1F1EA}" },
|
|
209
|
+
{ code: "AM", name: "Armenia", dialCode: "+374", format: "XX XXXXXX", flag: "\u{1F1E6}\u{1F1F2}" },
|
|
210
|
+
{ code: "AZ", name: "Azerbaijan", dialCode: "+994", format: "XX XXX XX XX", flag: "\u{1F1E6}\u{1F1FF}" },
|
|
211
|
+
{ code: "MC", name: "Monaco", dialCode: "+377", format: "XX XX XX XX", flag: "\u{1F1F2}\u{1F1E8}" },
|
|
212
|
+
{ code: "AD", name: "Andorra", dialCode: "+376", format: "XXX XXX", flag: "\u{1F1E6}\u{1F1E9}" },
|
|
213
|
+
{ code: "SM", name: "San Marino", dialCode: "+378", format: "XXXX XXXXXX", flag: "\u{1F1F8}\u{1F1F2}" },
|
|
214
|
+
{ code: "LI", name: "Liechtenstein", dialCode: "+423", format: "XXX XX XX", flag: "\u{1F1F1}\u{1F1EE}" },
|
|
215
|
+
{ code: "VA", name: "Vatican City", dialCode: "+379", format: "XXXX XXXX", flag: "\u{1F1FB}\u{1F1E6}" },
|
|
216
|
+
{ code: "GI", name: "Gibraltar", dialCode: "+350", format: "XXXX XXXX", flag: "\u{1F1EC}\u{1F1EE}" },
|
|
217
|
+
{ code: "FO", name: "Faroe Islands", dialCode: "+298", format: "XXXXXX", flag: "\u{1F1EB}\u{1F1F4}" },
|
|
218
|
+
{ code: "GL", name: "Greenland", dialCode: "+299", format: "XX XX XX", flag: "\u{1F1EC}\u{1F1F1}" },
|
|
219
|
+
// ── Asia ──
|
|
220
|
+
{ code: "CN", name: "China", dialCode: "+86", format: "XXX XXXX XXXX", flag: "\u{1F1E8}\u{1F1F3}" },
|
|
221
|
+
{ code: "JP", name: "Japan", dialCode: "+81", format: "XX XXXX XXXX", flag: "\u{1F1EF}\u{1F1F5}" },
|
|
222
|
+
{ code: "KR", name: "South Korea", dialCode: "+82", format: "XX XXXX XXXX", flag: "\u{1F1F0}\u{1F1F7}" },
|
|
223
|
+
{ code: "KP", name: "North Korea", dialCode: "+850", format: "XXX XXX XXXX", flag: "\u{1F1F0}\u{1F1F5}" },
|
|
224
|
+
{ code: "IN", name: "India", dialCode: "+91", format: "XXXXX XXXXX", flag: "\u{1F1EE}\u{1F1F3}" },
|
|
225
|
+
{ code: "PK", name: "Pakistan", dialCode: "+92", format: "XXX XXXXXXX", flag: "\u{1F1F5}\u{1F1F0}" },
|
|
226
|
+
{ code: "BD", name: "Bangladesh", dialCode: "+880", format: "XXXX XXXXXX", flag: "\u{1F1E7}\u{1F1E9}" },
|
|
227
|
+
{ code: "LK", name: "Sri Lanka", dialCode: "+94", format: "XX XXX XXXX", flag: "\u{1F1F1}\u{1F1F0}" },
|
|
228
|
+
{ code: "NP", name: "Nepal", dialCode: "+977", format: "XXX XXXXXXX", flag: "\u{1F1F3}\u{1F1F5}" },
|
|
229
|
+
{ code: "AF", name: "Afghanistan", dialCode: "+93", format: "XX XXX XXXX", flag: "\u{1F1E6}\u{1F1EB}" },
|
|
230
|
+
{ code: "MM", name: "Myanmar", dialCode: "+95", format: "X XXX XXXX", flag: "\u{1F1F2}\u{1F1F2}" },
|
|
231
|
+
{ code: "TH", name: "Thailand", dialCode: "+66", format: "XX XXX XXXX", flag: "\u{1F1F9}\u{1F1ED}" },
|
|
232
|
+
{ code: "VN", name: "Vietnam", dialCode: "+84", format: "XX XXX XX XX", flag: "\u{1F1FB}\u{1F1F3}" },
|
|
233
|
+
{ code: "KH", name: "Cambodia", dialCode: "+855", format: "XX XXX XXX", flag: "\u{1F1F0}\u{1F1ED}" },
|
|
234
|
+
{ code: "LA", name: "Laos", dialCode: "+856", format: "XX XX XXX XXX", flag: "\u{1F1F1}\u{1F1E6}" },
|
|
235
|
+
{ code: "MY", name: "Malaysia", dialCode: "+60", format: "XX XXXX XXXX", flag: "\u{1F1F2}\u{1F1FE}" },
|
|
236
|
+
{ code: "SG", name: "Singapore", dialCode: "+65", format: "XXXX XXXX", flag: "\u{1F1F8}\u{1F1EC}" },
|
|
237
|
+
{ code: "ID", name: "Indonesia", dialCode: "+62", format: "XXX XXXX XXXX", flag: "\u{1F1EE}\u{1F1E9}" },
|
|
238
|
+
{ code: "PH", name: "Philippines", dialCode: "+63", format: "XXX XXX XXXX", flag: "\u{1F1F5}\u{1F1ED}" },
|
|
239
|
+
{ code: "BN", name: "Brunei", dialCode: "+673", format: "XXX XXXX", flag: "\u{1F1E7}\u{1F1F3}" },
|
|
240
|
+
{ code: "TL", name: "Timor-Leste", dialCode: "+670", format: "XXXX XXXX", flag: "\u{1F1F9}\u{1F1F1}" },
|
|
241
|
+
{ code: "TW", name: "Taiwan", dialCode: "+886", format: "XXX XXX XXX", flag: "\u{1F1F9}\u{1F1FC}" },
|
|
242
|
+
{ code: "HK", name: "Hong Kong", dialCode: "+852", format: "XXXX XXXX", flag: "\u{1F1ED}\u{1F1F0}" },
|
|
243
|
+
{ code: "MO", name: "Macau", dialCode: "+853", format: "XXXX XXXX", flag: "\u{1F1F2}\u{1F1F4}" },
|
|
244
|
+
{ code: "MN", name: "Mongolia", dialCode: "+976", format: "XXXX XXXX", flag: "\u{1F1F2}\u{1F1F3}" },
|
|
245
|
+
{ code: "KZ", name: "Kazakhstan", dialCode: "+7", format: "XXX XXX XX XX", flag: "\u{1F1F0}\u{1F1FF}" },
|
|
246
|
+
{ code: "UZ", name: "Uzbekistan", dialCode: "+998", format: "XX XXX XX XX", flag: "\u{1F1FA}\u{1F1FF}" },
|
|
247
|
+
{ code: "TM", name: "Turkmenistan", dialCode: "+993", format: "XX XXXXXX", flag: "\u{1F1F9}\u{1F1F2}" },
|
|
248
|
+
{ code: "KG", name: "Kyrgyzstan", dialCode: "+996", format: "XXX XXX XXX", flag: "\u{1F1F0}\u{1F1EC}" },
|
|
249
|
+
{ code: "TJ", name: "Tajikistan", dialCode: "+992", format: "XX XXX XXXX", flag: "\u{1F1F9}\u{1F1EF}" },
|
|
250
|
+
{ code: "MV", name: "Maldives", dialCode: "+960", format: "XXX XXXX", flag: "\u{1F1F2}\u{1F1FB}" },
|
|
251
|
+
{ code: "BT", name: "Bhutan", dialCode: "+975", format: "XX XXX XXX", flag: "\u{1F1E7}\u{1F1F9}" },
|
|
252
|
+
// ── Middle East ──
|
|
253
|
+
{ code: "AE", name: "United Arab Emirates", dialCode: "+971", format: "XX XXX XXXX", flag: "\u{1F1E6}\u{1F1EA}" },
|
|
254
|
+
{ code: "SA", name: "Saudi Arabia", dialCode: "+966", format: "XX XXX XXXX", flag: "\u{1F1F8}\u{1F1E6}" },
|
|
255
|
+
{ code: "QA", name: "Qatar", dialCode: "+974", format: "XXXX XXXX", flag: "\u{1F1F6}\u{1F1E6}" },
|
|
256
|
+
{ code: "KW", name: "Kuwait", dialCode: "+965", format: "XXXX XXXX", flag: "\u{1F1F0}\u{1F1FC}" },
|
|
257
|
+
{ code: "BH", name: "Bahrain", dialCode: "+973", format: "XXXX XXXX", flag: "\u{1F1E7}\u{1F1ED}" },
|
|
258
|
+
{ code: "OM", name: "Oman", dialCode: "+968", format: "XXXX XXXX", flag: "\u{1F1F4}\u{1F1F2}" },
|
|
259
|
+
{ code: "YE", name: "Yemen", dialCode: "+967", format: "XXX XXX XXX", flag: "\u{1F1FE}\u{1F1EA}" },
|
|
260
|
+
{ code: "IR", name: "Iran", dialCode: "+98", format: "XXX XXX XXXX", flag: "\u{1F1EE}\u{1F1F7}" },
|
|
261
|
+
{ code: "IQ", name: "Iraq", dialCode: "+964", format: "XXX XXX XXXX", flag: "\u{1F1EE}\u{1F1F6}" },
|
|
262
|
+
{ code: "JO", name: "Jordan", dialCode: "+962", format: "X XXXX XXXX", flag: "\u{1F1EF}\u{1F1F4}" },
|
|
263
|
+
{ code: "LB", name: "Lebanon", dialCode: "+961", format: "XX XXX XXX", flag: "\u{1F1F1}\u{1F1E7}" },
|
|
264
|
+
{ code: "SY", name: "Syria", dialCode: "+963", format: "XXX XXX XXX", flag: "\u{1F1F8}\u{1F1FE}" },
|
|
265
|
+
{ code: "IL", name: "Israel", dialCode: "+972", format: "XX XXX XXXX", flag: "\u{1F1EE}\u{1F1F1}" },
|
|
266
|
+
{ code: "PS", name: "Palestine", dialCode: "+970", format: "XX XXX XXXX", flag: "\u{1F1F5}\u{1F1F8}" },
|
|
267
|
+
// ── Africa ──
|
|
268
|
+
{ code: "ZA", name: "South Africa", dialCode: "+27", format: "XX XXX XXXX", flag: "\u{1F1FF}\u{1F1E6}" },
|
|
269
|
+
{ code: "NG", name: "Nigeria", dialCode: "+234", format: "XXX XXX XXXX", flag: "\u{1F1F3}\u{1F1EC}" },
|
|
270
|
+
{ code: "KE", name: "Kenya", dialCode: "+254", format: "XXX XXXXXX", flag: "\u{1F1F0}\u{1F1EA}" },
|
|
271
|
+
{ code: "GH", name: "Ghana", dialCode: "+233", format: "XX XXX XXXX", flag: "\u{1F1EC}\u{1F1ED}" },
|
|
272
|
+
{ code: "EG", name: "Egypt", dialCode: "+20", format: "XX XXXX XXXX", flag: "\u{1F1EA}\u{1F1EC}" },
|
|
273
|
+
{ code: "MA", name: "Morocco", dialCode: "+212", format: "XX XXXX XXX", flag: "\u{1F1F2}\u{1F1E6}" },
|
|
274
|
+
{ code: "DZ", name: "Algeria", dialCode: "+213", format: "XXX XX XX XX", flag: "\u{1F1E9}\u{1F1FF}" },
|
|
275
|
+
{ code: "TN", name: "Tunisia", dialCode: "+216", format: "XX XXX XXX", flag: "\u{1F1F9}\u{1F1F3}" },
|
|
276
|
+
{ code: "LY", name: "Libya", dialCode: "+218", format: "XX XXX XXXX", flag: "\u{1F1F1}\u{1F1FE}" },
|
|
277
|
+
{ code: "ET", name: "Ethiopia", dialCode: "+251", format: "XX XXX XXXX", flag: "\u{1F1EA}\u{1F1F9}" },
|
|
278
|
+
{ code: "TZ", name: "Tanzania", dialCode: "+255", format: "XXX XXX XXX", flag: "\u{1F1F9}\u{1F1FF}" },
|
|
279
|
+
{ code: "UG", name: "Uganda", dialCode: "+256", format: "XXX XXXXXX", flag: "\u{1F1FA}\u{1F1EC}" },
|
|
280
|
+
{ code: "RW", name: "Rwanda", dialCode: "+250", format: "XXX XXX XXX", flag: "\u{1F1F7}\u{1F1FC}" },
|
|
281
|
+
{ code: "CD", name: "DR Congo", dialCode: "+243", format: "XXX XXX XXX", flag: "\u{1F1E8}\u{1F1E9}" },
|
|
282
|
+
{ code: "CG", name: "Congo", dialCode: "+242", format: "XX XXX XXXX", flag: "\u{1F1E8}\u{1F1EC}" },
|
|
283
|
+
{ code: "CI", name: "C\xF4te d'Ivoire", dialCode: "+225", format: "XX XX XX XXXX", flag: "\u{1F1E8}\u{1F1EE}" },
|
|
284
|
+
{ code: "SN", name: "Senegal", dialCode: "+221", format: "XX XXX XX XX", flag: "\u{1F1F8}\u{1F1F3}" },
|
|
285
|
+
{ code: "CM", name: "Cameroon", dialCode: "+237", format: "XXXX XXXX", flag: "\u{1F1E8}\u{1F1F2}" },
|
|
286
|
+
{ code: "MZ", name: "Mozambique", dialCode: "+258", format: "XX XXX XXXX", flag: "\u{1F1F2}\u{1F1FF}" },
|
|
287
|
+
{ code: "AO", name: "Angola", dialCode: "+244", format: "XXX XXX XXX", flag: "\u{1F1E6}\u{1F1F4}" },
|
|
288
|
+
{ code: "ZW", name: "Zimbabwe", dialCode: "+263", format: "XX XXX XXXX", flag: "\u{1F1FF}\u{1F1FC}" },
|
|
289
|
+
{ code: "ZM", name: "Zambia", dialCode: "+260", format: "XX XXXXXXX", flag: "\u{1F1FF}\u{1F1F2}" },
|
|
290
|
+
{ code: "BW", name: "Botswana", dialCode: "+267", format: "XX XXX XXX", flag: "\u{1F1E7}\u{1F1FC}" },
|
|
291
|
+
{ code: "NA", name: "Namibia", dialCode: "+264", format: "XX XXX XXXX", flag: "\u{1F1F3}\u{1F1E6}" },
|
|
292
|
+
{ code: "MU", name: "Mauritius", dialCode: "+230", format: "XXXX XXXX", flag: "\u{1F1F2}\u{1F1FA}" },
|
|
293
|
+
{ code: "MG", name: "Madagascar", dialCode: "+261", format: "XX XX XXX XX", flag: "\u{1F1F2}\u{1F1EC}" },
|
|
294
|
+
{ code: "MW", name: "Malawi", dialCode: "+265", format: "X XXXX XXXX", flag: "\u{1F1F2}\u{1F1FC}" },
|
|
295
|
+
{ code: "ML", name: "Mali", dialCode: "+223", format: "XXXX XXXX", flag: "\u{1F1F2}\u{1F1F1}" },
|
|
296
|
+
{ code: "BF", name: "Burkina Faso", dialCode: "+226", format: "XX XX XX XX", flag: "\u{1F1E7}\u{1F1EB}" },
|
|
297
|
+
{ code: "NE", name: "Niger", dialCode: "+227", format: "XX XX XX XX", flag: "\u{1F1F3}\u{1F1EA}" },
|
|
298
|
+
{ code: "TD", name: "Chad", dialCode: "+235", format: "XX XX XX XX", flag: "\u{1F1F9}\u{1F1E9}" },
|
|
299
|
+
{ code: "SD", name: "Sudan", dialCode: "+249", format: "XX XXX XXXX", flag: "\u{1F1F8}\u{1F1E9}" },
|
|
300
|
+
{ code: "SS", name: "South Sudan", dialCode: "+211", format: "XX XXX XXXX", flag: "\u{1F1F8}\u{1F1F8}" },
|
|
301
|
+
{ code: "SO", name: "Somalia", dialCode: "+252", format: "XX XXX XXX", flag: "\u{1F1F8}\u{1F1F4}" },
|
|
302
|
+
{ code: "DJ", name: "Djibouti", dialCode: "+253", format: "XX XX XX XX", flag: "\u{1F1E9}\u{1F1EF}" },
|
|
303
|
+
{ code: "ER", name: "Eritrea", dialCode: "+291", format: "X XXX XXX", flag: "\u{1F1EA}\u{1F1F7}" },
|
|
304
|
+
{ code: "GM", name: "Gambia", dialCode: "+220", format: "XXX XXXX", flag: "\u{1F1EC}\u{1F1F2}" },
|
|
305
|
+
{ code: "GN", name: "Guinea", dialCode: "+224", format: "XXX XX XX XX", flag: "\u{1F1EC}\u{1F1F3}" },
|
|
306
|
+
{ code: "GW", name: "Guinea-Bissau", dialCode: "+245", format: "XXX XXXX", flag: "\u{1F1EC}\u{1F1FC}" },
|
|
307
|
+
{ code: "LR", name: "Liberia", dialCode: "+231", format: "XX XXX XXXX", flag: "\u{1F1F1}\u{1F1F7}" },
|
|
308
|
+
{ code: "SL", name: "Sierra Leone", dialCode: "+232", format: "XX XXXXXX", flag: "\u{1F1F8}\u{1F1F1}" },
|
|
309
|
+
{ code: "TG", name: "Togo", dialCode: "+228", format: "XX XXX XXX", flag: "\u{1F1F9}\u{1F1EC}" },
|
|
310
|
+
{ code: "BJ", name: "Benin", dialCode: "+229", format: "XX XX XXXX", flag: "\u{1F1E7}\u{1F1EF}" },
|
|
311
|
+
{ code: "GA", name: "Gabon", dialCode: "+241", format: "X XX XX XX", flag: "\u{1F1EC}\u{1F1E6}" },
|
|
312
|
+
{ code: "GQ", name: "Equatorial Guinea", dialCode: "+240", format: "XXX XXX XXX", flag: "\u{1F1EC}\u{1F1F6}" },
|
|
313
|
+
{ code: "ST", name: "S\xE3o Tom\xE9 and Pr\xEDncipe", dialCode: "+239", format: "XXX XXXX", flag: "\u{1F1F8}\u{1F1F9}" },
|
|
314
|
+
{ code: "CF", name: "Central African Republic", dialCode: "+236", format: "XX XX XX XX", flag: "\u{1F1E8}\u{1F1EB}" },
|
|
315
|
+
{ code: "CV", name: "Cape Verde", dialCode: "+238", format: "XXX XX XX", flag: "\u{1F1E8}\u{1F1FB}" },
|
|
316
|
+
{ code: "MR", name: "Mauritania", dialCode: "+222", format: "XXXX XXXX", flag: "\u{1F1F2}\u{1F1F7}" },
|
|
317
|
+
{ code: "BI", name: "Burundi", dialCode: "+257", format: "XX XX XXXX", flag: "\u{1F1E7}\u{1F1EE}" },
|
|
318
|
+
{ code: "LS", name: "Lesotho", dialCode: "+266", format: "XXXX XXXX", flag: "\u{1F1F1}\u{1F1F8}" },
|
|
319
|
+
{ code: "SZ", name: "Eswatini", dialCode: "+268", format: "XXXX XXXX", flag: "\u{1F1F8}\u{1F1FF}" },
|
|
320
|
+
{ code: "KM", name: "Comoros", dialCode: "+269", format: "XXX XX XX", flag: "\u{1F1F0}\u{1F1F2}" },
|
|
321
|
+
{ code: "SC", name: "Seychelles", dialCode: "+248", format: "X XXX XXX", flag: "\u{1F1F8}\u{1F1E8}" },
|
|
322
|
+
{ code: "RE", name: "R\xE9union", dialCode: "+262", format: "XXX XX XX XX", flag: "\u{1F1F7}\u{1F1EA}" },
|
|
323
|
+
{ code: "YT", name: "Mayotte", dialCode: "+262", format: "XXX XX XX XX", flag: "\u{1F1FE}\u{1F1F9}" },
|
|
324
|
+
// ── Americas (non-NANP) ──
|
|
325
|
+
{ code: "MX", name: "Mexico", dialCode: "+52", format: "XXX XXX XXXX", flag: "\u{1F1F2}\u{1F1FD}" },
|
|
326
|
+
{ code: "BR", name: "Brazil", dialCode: "+55", format: "XX XXXXX XXXX", flag: "\u{1F1E7}\u{1F1F7}" },
|
|
327
|
+
{ code: "AR", name: "Argentina", dialCode: "+54", format: "XX XXXX XXXX", flag: "\u{1F1E6}\u{1F1F7}" },
|
|
328
|
+
{ code: "CO", name: "Colombia", dialCode: "+57", format: "XXX XXX XXXX", flag: "\u{1F1E8}\u{1F1F4}" },
|
|
329
|
+
{ code: "CL", name: "Chile", dialCode: "+56", format: "X XXXX XXXX", flag: "\u{1F1E8}\u{1F1F1}" },
|
|
330
|
+
{ code: "PE", name: "Peru", dialCode: "+51", format: "XXX XXX XXX", flag: "\u{1F1F5}\u{1F1EA}" },
|
|
331
|
+
{ code: "VE", name: "Venezuela", dialCode: "+58", format: "XXX XXX XXXX", flag: "\u{1F1FB}\u{1F1EA}" },
|
|
332
|
+
{ code: "EC", name: "Ecuador", dialCode: "+593", format: "XX XXX XXXX", flag: "\u{1F1EA}\u{1F1E8}" },
|
|
333
|
+
{ code: "UY", name: "Uruguay", dialCode: "+598", format: "X XXX XX XX", flag: "\u{1F1FA}\u{1F1FE}" },
|
|
334
|
+
{ code: "PY", name: "Paraguay", dialCode: "+595", format: "XXX XXX XXX", flag: "\u{1F1F5}\u{1F1FE}" },
|
|
335
|
+
{ code: "BO", name: "Bolivia", dialCode: "+591", format: "X XXX XXXX", flag: "\u{1F1E7}\u{1F1F4}" },
|
|
336
|
+
{ code: "GY", name: "Guyana", dialCode: "+592", format: "XXX XXXX", flag: "\u{1F1EC}\u{1F1FE}" },
|
|
337
|
+
{ code: "SR", name: "Suriname", dialCode: "+597", format: "XXX XXXX", flag: "\u{1F1F8}\u{1F1F7}" },
|
|
338
|
+
{ code: "GF", name: "French Guiana", dialCode: "+594", format: "XXX XX XX XX", flag: "\u{1F1EC}\u{1F1EB}" },
|
|
339
|
+
{ code: "FK", name: "Falkland Islands", dialCode: "+500", format: "XXXXX", flag: "\u{1F1EB}\u{1F1F0}" },
|
|
340
|
+
{ code: "CR", name: "Costa Rica", dialCode: "+506", format: "XXXX XXXX", flag: "\u{1F1E8}\u{1F1F7}" },
|
|
341
|
+
{ code: "PA", name: "Panama", dialCode: "+507", format: "XXXX XXXX", flag: "\u{1F1F5}\u{1F1E6}" },
|
|
342
|
+
{ code: "GT", name: "Guatemala", dialCode: "+502", format: "XXXX XXXX", flag: "\u{1F1EC}\u{1F1F9}" },
|
|
343
|
+
{ code: "HN", name: "Honduras", dialCode: "+504", format: "XXXX XXXX", flag: "\u{1F1ED}\u{1F1F3}" },
|
|
344
|
+
{ code: "SV", name: "El Salvador", dialCode: "+503", format: "XXXX XXXX", flag: "\u{1F1F8}\u{1F1FB}" },
|
|
345
|
+
{ code: "NI", name: "Nicaragua", dialCode: "+505", format: "XXXX XXXX", flag: "\u{1F1F3}\u{1F1EE}" },
|
|
346
|
+
{ code: "BZ", name: "Belize", dialCode: "+501", format: "XXX XXXX", flag: "\u{1F1E7}\u{1F1FF}" },
|
|
347
|
+
{ code: "CU", name: "Cuba", dialCode: "+53", format: "X XXX XXXX", flag: "\u{1F1E8}\u{1F1FA}" },
|
|
348
|
+
{ code: "HT", name: "Haiti", dialCode: "+509", format: "XX XX XXXX", flag: "\u{1F1ED}\u{1F1F9}" },
|
|
349
|
+
{ code: "GP", name: "Guadeloupe", dialCode: "+590", format: "XXX XX XX XX", flag: "\u{1F1EC}\u{1F1F5}" },
|
|
350
|
+
{ code: "MQ", name: "Martinique", dialCode: "+596", format: "XXX XX XX XX", flag: "\u{1F1F2}\u{1F1F6}" },
|
|
351
|
+
{ code: "PM", name: "Saint Pierre and Miquelon", dialCode: "+508", format: "XX XX XX", flag: "\u{1F1F5}\u{1F1F2}" },
|
|
352
|
+
// ── Oceania ──
|
|
353
|
+
{ code: "AU", name: "Australia", dialCode: "+61", format: "XXX XXX XXX", flag: "\u{1F1E6}\u{1F1FA}" },
|
|
354
|
+
{ code: "NZ", name: "New Zealand", dialCode: "+64", format: "XX XXX XXXX", flag: "\u{1F1F3}\u{1F1FF}" },
|
|
355
|
+
{ code: "FJ", name: "Fiji", dialCode: "+679", format: "XXX XXXX", flag: "\u{1F1EB}\u{1F1EF}" },
|
|
356
|
+
{ code: "PG", name: "Papua New Guinea", dialCode: "+675", format: "XXX XXXX", flag: "\u{1F1F5}\u{1F1EC}" },
|
|
357
|
+
{ code: "WS", name: "Samoa", dialCode: "+685", format: "XX XXXXX", flag: "\u{1F1FC}\u{1F1F8}" },
|
|
358
|
+
{ code: "TO", name: "Tonga", dialCode: "+676", format: "XXX XXXX", flag: "\u{1F1F9}\u{1F1F4}" },
|
|
359
|
+
{ code: "VU", name: "Vanuatu", dialCode: "+678", format: "XXX XXXX", flag: "\u{1F1FB}\u{1F1FA}" },
|
|
360
|
+
{ code: "SB", name: "Solomon Islands", dialCode: "+677", format: "XXXXX", flag: "\u{1F1F8}\u{1F1E7}" },
|
|
361
|
+
{ code: "NC", name: "New Caledonia", dialCode: "+687", format: "XX XX XX", flag: "\u{1F1F3}\u{1F1E8}" },
|
|
362
|
+
{ code: "PF", name: "French Polynesia", dialCode: "+689", format: "XX XX XX XX", flag: "\u{1F1F5}\u{1F1EB}" },
|
|
363
|
+
{ code: "CK", name: "Cook Islands", dialCode: "+682", format: "XX XXX", flag: "\u{1F1E8}\u{1F1F0}" },
|
|
364
|
+
{ code: "NU", name: "Niue", dialCode: "+683", format: "XXXX", flag: "\u{1F1F3}\u{1F1FA}" },
|
|
365
|
+
{ code: "NR", name: "Nauru", dialCode: "+674", format: "XXX XXXX", flag: "\u{1F1F3}\u{1F1F7}" },
|
|
366
|
+
{ code: "TV", name: "Tuvalu", dialCode: "+688", format: "XXXXX", flag: "\u{1F1F9}\u{1F1FB}" },
|
|
367
|
+
{ code: "KI", name: "Kiribati", dialCode: "+686", format: "XXXX XXXX", flag: "\u{1F1F0}\u{1F1EE}" },
|
|
368
|
+
{ code: "MH", name: "Marshall Islands", dialCode: "+692", format: "XXX XXXX", flag: "\u{1F1F2}\u{1F1ED}" },
|
|
369
|
+
{ code: "FM", name: "Micronesia", dialCode: "+691", format: "XXX XXXX", flag: "\u{1F1EB}\u{1F1F2}" },
|
|
370
|
+
{ code: "PW", name: "Palau", dialCode: "+680", format: "XXX XXXX", flag: "\u{1F1F5}\u{1F1FC}" }
|
|
371
|
+
];
|
|
372
|
+
var SORTED_DIAL_CODES = (() => {
|
|
373
|
+
const entries = [];
|
|
374
|
+
const seen = /* @__PURE__ */ new Set();
|
|
375
|
+
for (const c of COUNTRIES) {
|
|
376
|
+
const dc = c.dialCode.replace("+", "");
|
|
377
|
+
const key = `${dc}-${c.code}`;
|
|
378
|
+
if (!seen.has(key)) {
|
|
379
|
+
seen.add(key);
|
|
380
|
+
entries.push({ dialCode: dc, code: c.code });
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
return entries.sort((a, b) => b.dialCode.length - a.dialCode.length);
|
|
384
|
+
})();
|
|
385
|
+
var TWO_DIGIT_CC = /* @__PURE__ */ new Set([
|
|
386
|
+
"20",
|
|
387
|
+
"27",
|
|
388
|
+
"30",
|
|
389
|
+
"31",
|
|
390
|
+
"32",
|
|
391
|
+
"33",
|
|
392
|
+
"34",
|
|
393
|
+
"36",
|
|
394
|
+
"39",
|
|
395
|
+
"40",
|
|
396
|
+
"41",
|
|
397
|
+
"43",
|
|
398
|
+
"44",
|
|
399
|
+
"45",
|
|
400
|
+
"46",
|
|
401
|
+
"47",
|
|
402
|
+
"48",
|
|
403
|
+
"49",
|
|
404
|
+
"51",
|
|
405
|
+
"52",
|
|
406
|
+
"53",
|
|
407
|
+
"54",
|
|
408
|
+
"55",
|
|
409
|
+
"56",
|
|
410
|
+
"57",
|
|
411
|
+
"58",
|
|
412
|
+
"60",
|
|
413
|
+
"61",
|
|
414
|
+
"62",
|
|
415
|
+
"63",
|
|
416
|
+
"64",
|
|
417
|
+
"65",
|
|
418
|
+
"66",
|
|
419
|
+
"81",
|
|
420
|
+
"82",
|
|
421
|
+
"84",
|
|
422
|
+
"86",
|
|
423
|
+
"90",
|
|
424
|
+
"91",
|
|
425
|
+
"92",
|
|
426
|
+
"93",
|
|
427
|
+
"94",
|
|
428
|
+
"95",
|
|
429
|
+
"98"
|
|
430
|
+
]);
|
|
431
|
+
function getCountryCodeLength(digits) {
|
|
432
|
+
if (!digits || digits.length === 0) return 0;
|
|
433
|
+
const first = digits[0];
|
|
434
|
+
if (first === "1" || first === "7") return 1;
|
|
435
|
+
if (digits.length >= 2 && TWO_DIGIT_CC.has(digits.substring(0, 2))) return 2;
|
|
436
|
+
return 3;
|
|
437
|
+
}
|
|
438
|
+
function normalizePhone(phone) {
|
|
439
|
+
if (!phone) return "";
|
|
440
|
+
let input = phone.replace(
|
|
441
|
+
/[\u200B-\u200F\u202A-\u202E\u2060-\u2069\uFEFF\u00AD\u2028\u2029\u061C\u180E]/g,
|
|
442
|
+
""
|
|
443
|
+
).trim();
|
|
444
|
+
if (!input) return "";
|
|
445
|
+
input = input.replace(/\(0\)/g, "");
|
|
446
|
+
let hasPlus = false;
|
|
447
|
+
let digits = "";
|
|
448
|
+
for (let i = 0; i < input.length; i++) {
|
|
449
|
+
const ch = input[i];
|
|
450
|
+
if (ch === "+" && digits.length === 0 && !hasPlus) {
|
|
451
|
+
hasPlus = true;
|
|
452
|
+
} else if (ch >= "0" && ch <= "9") {
|
|
453
|
+
digits += ch;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
if (!digits) return "";
|
|
457
|
+
if (!hasPlus && digits.startsWith("00") && digits.length > 9) {
|
|
458
|
+
hasPlus = true;
|
|
459
|
+
digits = digits.substring(2);
|
|
460
|
+
}
|
|
461
|
+
if (hasPlus) {
|
|
462
|
+
const ccLen = getCountryCodeLength(digits);
|
|
463
|
+
if (ccLen > 0 && digits.length > ccLen && digits[ccLen] === "0") {
|
|
464
|
+
const withoutZero = digits.substring(0, ccLen) + digits.substring(ccLen + 1);
|
|
465
|
+
if (withoutZero.length >= 7 && withoutZero.length <= 15) {
|
|
466
|
+
digits = withoutZero;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return "+" + digits;
|
|
470
|
+
}
|
|
471
|
+
return "+" + digits;
|
|
472
|
+
}
|
|
473
|
+
function validatePhone(phone) {
|
|
474
|
+
if (!phone || !phone.trim()) {
|
|
475
|
+
return { valid: false, reason: "Phone number is required" };
|
|
476
|
+
}
|
|
477
|
+
const normalized = normalizePhone(phone);
|
|
478
|
+
if (!normalized || normalized === "+") {
|
|
479
|
+
return { valid: false, reason: "Phone number contains no valid digits" };
|
|
480
|
+
}
|
|
481
|
+
const digits = normalized.substring(1);
|
|
482
|
+
if (digits.length < 7) {
|
|
483
|
+
return {
|
|
484
|
+
valid: false,
|
|
485
|
+
reason: `Phone number is too short (${digits.length} digits). International numbers need at least 7 digits including the country code`
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
if (digits.length > 15) {
|
|
489
|
+
return {
|
|
490
|
+
valid: false,
|
|
491
|
+
reason: `Phone number is too long (${digits.length} digits). E.164 standard allows at most 15 digits`
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
const trimmedInput = phone.trim();
|
|
495
|
+
const hasInternationalPrefix = trimmedInput.startsWith("+") || trimmedInput.startsWith("00") || trimmedInput.replace(/[^\d]/g, "").startsWith("00");
|
|
496
|
+
if (!hasInternationalPrefix) {
|
|
497
|
+
return {
|
|
498
|
+
valid: false,
|
|
499
|
+
reason: "Phone number must include a country code (e.g., +1 for US/Canada, +44 for UK, +33 for France). Use the format: +[country code][number]"
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
let detectedCountry;
|
|
503
|
+
for (const { dialCode, code } of SORTED_DIAL_CODES) {
|
|
504
|
+
if (digits.startsWith(dialCode)) {
|
|
505
|
+
detectedCountry = code;
|
|
506
|
+
break;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
if (!detectedCountry) {
|
|
510
|
+
return {
|
|
511
|
+
valid: false,
|
|
512
|
+
reason: "Unrecognized country calling code. Please verify the number includes a valid international dialing code"
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
return {
|
|
516
|
+
valid: true,
|
|
517
|
+
normalized,
|
|
518
|
+
countryCode: detectedCountry
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
function detectCountry(phone) {
|
|
522
|
+
const normalized = normalizePhone(phone);
|
|
523
|
+
if (!normalized || normalized.length < 2) return null;
|
|
524
|
+
const digits = normalized.substring(1);
|
|
525
|
+
for (const { dialCode, code } of SORTED_DIAL_CODES) {
|
|
526
|
+
if (digits.startsWith(dialCode)) {
|
|
527
|
+
return code;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
return null;
|
|
531
|
+
}
|
|
532
|
+
function formatPhone(phone) {
|
|
533
|
+
const normalized = normalizePhone(phone);
|
|
534
|
+
if (!normalized || normalized.length < 2) return phone;
|
|
535
|
+
const digits = normalized.substring(1);
|
|
536
|
+
const usMatch = digits.match(/^1(\d{3})(\d{3})(\d{4})$/);
|
|
537
|
+
if (usMatch) return `+1 (${usMatch[1]}) ${usMatch[2]}-${usMatch[3]}`;
|
|
538
|
+
const uk1 = digits.match(/^44(\d{4})(\d{6})$/);
|
|
539
|
+
if (uk1) return `+44 ${uk1[1]} ${uk1[2]}`;
|
|
540
|
+
const uk2 = digits.match(/^44(\d{3})(\d{4})(\d{4})$/);
|
|
541
|
+
if (uk2) return `+44 ${uk2[1]} ${uk2[2]} ${uk2[3]}`;
|
|
542
|
+
const fr = digits.match(/^33(\d{1})(\d{2})(\d{2})(\d{2})(\d{2})$/);
|
|
543
|
+
if (fr) return `+33 ${fr[1]} ${fr[2]} ${fr[3]} ${fr[4]} ${fr[5]}`;
|
|
544
|
+
const de1 = digits.match(/^49(\d{3})(\d{7,8})$/);
|
|
545
|
+
if (de1) return `+49 ${de1[1]} ${de1[2]}`;
|
|
546
|
+
const de2 = digits.match(/^49(\d{4})(\d{6,7})$/);
|
|
547
|
+
if (de2) return `+49 ${de2[1]} ${de2[2]}`;
|
|
548
|
+
const it = digits.match(/^39(\d{3})(\d{3})(\d{3,4})$/);
|
|
549
|
+
if (it) return `+39 ${it[1]} ${it[2]} ${it[3]}`;
|
|
550
|
+
const es = digits.match(/^34(\d{3})(\d{3})(\d{3})$/);
|
|
551
|
+
if (es) return `+34 ${es[1]} ${es[2]} ${es[3]}`;
|
|
552
|
+
const nl = digits.match(/^31(\d{1})(\d{4})(\d{4})$/);
|
|
553
|
+
if (nl) return `+31 ${nl[1]} ${nl[2]} ${nl[3]}`;
|
|
554
|
+
const au = digits.match(/^61(\d{3})(\d{3})(\d{3})$/);
|
|
555
|
+
if (au) return `+61 ${au[1]} ${au[2]} ${au[3]}`;
|
|
556
|
+
const ind = digits.match(/^91(\d{5})(\d{5})$/);
|
|
557
|
+
if (ind) return `+91 ${ind[1]} ${ind[2]}`;
|
|
558
|
+
const jp = digits.match(/^81(\d{2})(\d{4})(\d{4})$/);
|
|
559
|
+
if (jp) return `+81 ${jp[1]} ${jp[2]} ${jp[3]}`;
|
|
560
|
+
const cn = digits.match(/^86(\d{3})(\d{4})(\d{4})$/);
|
|
561
|
+
if (cn) return `+86 ${cn[1]} ${cn[2]} ${cn[3]}`;
|
|
562
|
+
const kr = digits.match(/^82(\d{2})(\d{4})(\d{4})$/);
|
|
563
|
+
if (kr) return `+82 ${kr[1]} ${kr[2]} ${kr[3]}`;
|
|
564
|
+
const br = digits.match(/^55(\d{2})(\d{4,5})(\d{4})$/);
|
|
565
|
+
if (br) return `+55 ${br[1]} ${br[2]} ${br[3]}`;
|
|
566
|
+
const mx = digits.match(/^52(\d{3})(\d{3})(\d{4})$/);
|
|
567
|
+
if (mx) return `+52 ${mx[1]} ${mx[2]} ${mx[3]}`;
|
|
568
|
+
const ru = digits.match(/^7(\d{3})(\d{3})(\d{2})(\d{2})$/);
|
|
569
|
+
if (ru) return `+7 ${ru[1]} ${ru[2]}-${ru[3]}-${ru[4]}`;
|
|
570
|
+
const ae = digits.match(/^971(\d{2})(\d{3})(\d{4})$/);
|
|
571
|
+
if (ae) return `+971 ${ae[1]} ${ae[2]} ${ae[3]}`;
|
|
572
|
+
const sa = digits.match(/^966(\d{2})(\d{3})(\d{4})$/);
|
|
573
|
+
if (sa) return `+966 ${sa[1]} ${sa[2]} ${sa[3]}`;
|
|
574
|
+
const za = digits.match(/^27(\d{2})(\d{3})(\d{4})$/);
|
|
575
|
+
if (za) return `+27 ${za[1]} ${za[2]} ${za[3]}`;
|
|
576
|
+
const ng = digits.match(/^234(\d{3})(\d{3})(\d{4})$/);
|
|
577
|
+
if (ng) return `+234 ${ng[1]} ${ng[2]} ${ng[3]}`;
|
|
578
|
+
const ccLen = getCountryCodeLength(digits);
|
|
579
|
+
if (ccLen > 0 && digits.length > ccLen) {
|
|
580
|
+
const cc = digits.substring(0, ccLen);
|
|
581
|
+
const national = digits.substring(ccLen);
|
|
582
|
+
const groups = [];
|
|
583
|
+
let i = 0;
|
|
584
|
+
while (i < national.length) {
|
|
585
|
+
const remaining = national.length - i;
|
|
586
|
+
const chunkSize = remaining > 4 ? remaining % 3 === 0 ? 3 : remaining % 4 === 0 ? 4 : 3 : remaining;
|
|
587
|
+
groups.push(national.substring(i, i + chunkSize));
|
|
588
|
+
i += chunkSize;
|
|
589
|
+
}
|
|
590
|
+
return `+${cc} ${groups.join(" ")}`;
|
|
591
|
+
}
|
|
592
|
+
return normalized;
|
|
593
|
+
}
|
|
594
|
+
function getCountries() {
|
|
595
|
+
return [...COUNTRIES].sort((a, b) => a.name.localeCompare(b.name));
|
|
596
|
+
}
|
|
597
|
+
function getDialCode(countryCode) {
|
|
598
|
+
const country = COUNTRIES.find((c) => c.code === countryCode.toUpperCase());
|
|
599
|
+
return country?.dialCode ?? null;
|
|
600
|
+
}
|
|
601
|
+
function buildPhone(countryCode, nationalNumber) {
|
|
602
|
+
const dialCode = getDialCode(countryCode);
|
|
603
|
+
if (!dialCode) return null;
|
|
604
|
+
const dc = dialCode.replace("+", "");
|
|
605
|
+
let digits = nationalNumber.replace(/[^\d]/g, "");
|
|
606
|
+
if (!digits) return null;
|
|
607
|
+
if (digits.startsWith("0")) {
|
|
608
|
+
digits = digits.substring(1);
|
|
609
|
+
}
|
|
610
|
+
if (digits.startsWith(dc)) {
|
|
611
|
+
return normalizePhone("+" + digits);
|
|
612
|
+
}
|
|
613
|
+
return normalizePhone("+" + dc + digits);
|
|
614
|
+
}
|
|
615
|
+
|
|
137
616
|
// src/index.ts
|
|
138
617
|
var TiquoAuthError = class extends Error {
|
|
139
618
|
constructor(message, code, statusCode) {
|
|
@@ -280,14 +759,41 @@ var TiquoAuth = class {
|
|
|
280
759
|
}
|
|
281
760
|
/**
|
|
282
761
|
* Update the authenticated customer's profile
|
|
283
|
-
* Only allows updating the logged-in customer's own data
|
|
762
|
+
* Only allows updating the logged-in customer's own data.
|
|
763
|
+
*
|
|
764
|
+
* Phone numbers are automatically normalized to E.164 format (+digits).
|
|
765
|
+
* For best results, include a country code: "+1 (555) 456-7890" or "+44 7911 123456".
|
|
766
|
+
* Use TiquoPhone.validate() to check before submitting, or TiquoPhone.buildPhone()
|
|
767
|
+
* to construct from a country selector and national number.
|
|
284
768
|
*/
|
|
285
769
|
async updateProfile(updates) {
|
|
286
770
|
await this.ensureValidToken();
|
|
287
|
-
|
|
771
|
+
const normalizedUpdates = { ...updates };
|
|
772
|
+
if (normalizedUpdates.phone !== void 0 && normalizedUpdates.phone !== "") {
|
|
773
|
+
const normalized = normalizePhone(normalizedUpdates.phone);
|
|
774
|
+
const validation = validatePhone(normalizedUpdates.phone);
|
|
775
|
+
if (!validation.valid) {
|
|
776
|
+
this.log("\u26A0\uFE0F Phone validation warning:", validation.reason, "- Original:", normalizedUpdates.phone);
|
|
777
|
+
} else {
|
|
778
|
+
this.log("Phone normalized:", normalizedUpdates.phone, "\u2192", normalized);
|
|
779
|
+
}
|
|
780
|
+
normalizedUpdates.phone = normalized || normalizedUpdates.phone;
|
|
781
|
+
}
|
|
782
|
+
if (normalizedUpdates.phones) {
|
|
783
|
+
normalizedUpdates.phones = normalizedUpdates.phones.map((p) => {
|
|
784
|
+
if (!p.number) return p;
|
|
785
|
+
const normalized = normalizePhone(p.number);
|
|
786
|
+
const validation = validatePhone(p.number);
|
|
787
|
+
if (!validation.valid) {
|
|
788
|
+
this.log("\u26A0\uFE0F Phone validation warning:", validation.reason, "- Original:", p.number);
|
|
789
|
+
}
|
|
790
|
+
return { ...p, number: normalized || p.number };
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
this.log("Updating customer profile:", normalizedUpdates);
|
|
288
794
|
const response = await this.request("/api/client/v1/profile", {
|
|
289
795
|
method: "PATCH",
|
|
290
|
-
body: JSON.stringify(
|
|
796
|
+
body: JSON.stringify(normalizedUpdates)
|
|
291
797
|
});
|
|
292
798
|
if (!response.ok) {
|
|
293
799
|
const error = await response.json().catch(() => ({ error: "Failed to update profile" }));
|
|
@@ -905,10 +1411,27 @@ function useTiquoAuth(auth) {
|
|
|
905
1411
|
onAuthStateChange: (cb) => auth.onAuthStateChange(cb)
|
|
906
1412
|
};
|
|
907
1413
|
}
|
|
1414
|
+
var TiquoPhone = class {
|
|
1415
|
+
};
|
|
1416
|
+
/** Normalize a phone number to E.164 format (+digits). */
|
|
1417
|
+
TiquoPhone.normalize = normalizePhone;
|
|
1418
|
+
/** Validate a phone number with detailed result. */
|
|
1419
|
+
TiquoPhone.validate = validatePhone;
|
|
1420
|
+
/** Detect the country from a phone number's calling code. */
|
|
1421
|
+
TiquoPhone.detectCountry = detectCountry;
|
|
1422
|
+
/** Format a phone number for display using country-specific patterns. */
|
|
1423
|
+
TiquoPhone.format = formatPhone;
|
|
1424
|
+
/** Get the full list of countries with phone info for building UI selectors. */
|
|
1425
|
+
TiquoPhone.getCountries = getCountries;
|
|
1426
|
+
/** Get the dial code for a specific country (e.g. "US" → "+1"). */
|
|
1427
|
+
TiquoPhone.getDialCode = getDialCode;
|
|
1428
|
+
/** Build an E.164 phone number from a country code and national number. */
|
|
1429
|
+
TiquoPhone.buildPhone = buildPhone;
|
|
908
1430
|
var index_default = TiquoAuth;
|
|
909
1431
|
export {
|
|
910
1432
|
TiquoAuth,
|
|
911
1433
|
TiquoAuthError,
|
|
1434
|
+
TiquoPhone,
|
|
912
1435
|
addCustomerUserId,
|
|
913
1436
|
clearCachedEmail,
|
|
914
1437
|
index_default as default,
|
package/package.json
CHANGED