forked from albeebe/phoneformat.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclosure.txt
463 lines (422 loc) · 16.6 KB
/
closure.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
// ==ClosureCompiler==
// @compilation_level SIMPLE_OPTIMIZATIONS
// @output_file_name phoneformat.js
// @use_closure_library true
// @code_url https://libphonenumber.googlecode.com/svn/trunk/javascript/i18n/phonenumbers/asyoutypeformatter.js
// @code_url https://libphonenumber.googlecode.com/svn/trunk/javascript/i18n/phonenumbers/phonenumberutil.js
// @code_url https://libphonenumber.googlecode.com/svn/trunk/javascript/i18n/phonenumbers/regioncodefortesting.js
// @code_url https://libphonenumber.googlecode.com/svn/trunk/javascript/i18n/phonenumbers/phonemetadata.pb.js
// @code_url https://libphonenumber.googlecode.com/svn/trunk/javascript/i18n/phonenumbers/metadata.js
// @code_url https://libphonenumber.googlecode.com/svn/trunk/javascript/i18n/phonenumbers/phonenumber.pb.js
// ==/ClosureCompiler==
goog.require('goog.dom');
goog.require('goog.json');
goog.require('goog.proto2.ObjectSerializer');
goog.require('goog.string.StringBuffer');
goog.require('i18n.phonenumbers.AsYouTypeFormatter');
goog.require('i18n.phonenumbers.PhoneNumberFormat');
goog.require('i18n.phonenumbers.PhoneNumberType');
goog.require('i18n.phonenumbers.PhoneNumberUtil');
goog.require('i18n.phonenumbers.PhoneNumberUtil.ValidationResult');
/**
* @license
* Copyright (C) Alan Beebe ([email protected]).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// -------------------------------------------------------------------------
function countryForE164Number(phone) {
/*
Return the country code for an e164 formatted number
phone (String) phone number in e164 format to return the country code for
*/
try {
var phone = cleanPhone(phone);
var phoneUtil = i18n.phonenumbers.PhoneNumberUtil.getInstance();
var number = phoneUtil.parseAndKeepRawInput(phone);
var output = new goog.string.StringBuffer();
output = phoneUtil.getRegionCodeForNumber(number);
return output.toString();
} catch (e) {
return "";
}
}
// -------------------------------------------------------------------------
function formatNumberForMobileDialing(country, phone) {
/*
Returns a number formatted in such a way that it can be dialed from a mobile
phone in a specific region. If the number cannot be reached from the region
(e.g. some countries block toll-free numbers from being called outside of the
country), the method returns an empty string.
*/
try {
var phone = cleanPhone(phone);
var phoneUtil = i18n.phonenumbers.PhoneNumberUtil.getInstance();
var number = phoneUtil.parseAndKeepRawInput(phone, country);
var output = new goog.string.StringBuffer();
output = phoneUtil.formatNumberForMobileDialing(number, country, true);
return output.toString();
} catch (e) {
return "";
}
}
// -------------------------------------------------------------------------
function isValidNumber(phone, country) {
/*
Tests whether a phone number matches a valid pattern. Note this doesn't
verify the number is actually in use, which is impossible to tell by just
looking at a number itself.
*/
try {
var phone = cleanPhone(phone);
var phoneUtil = i18n.phonenumbers.PhoneNumberUtil.getInstance();
var number = phoneUtil.parseAndKeepRawInput(phone, country);
return phoneUtil.isValidNumber(number);
} catch (e) {
return false;
}
}
// -------------------------------------------------------------------------
function formatE164(country, phone) {
/*
Return the phone number in e164 format
country (String) 2 digit country code
phone (String) phone number to format
*/
try {
var phone = cleanPhone(phone);
var phoneUtil = i18n.phonenumbers.PhoneNumberUtil.getInstance();
var number = phoneUtil.parseAndKeepRawInput(phone, country);
var PNF = i18n.phonenumbers.PhoneNumberFormat;
var output = new goog.string.StringBuffer();
output = phoneUtil.format(number, PNF.E164);
return output.toString();
} catch (e) {
return phone
}
}
// -------------------------------------------------------------------------
function formatInternational(country, phone) {
/*
Return the phone number in international format
country (String) 2 digit country code
phone (String) phone number to format
*/
try {
var phone = cleanPhone(phone);
var formatter = new i18n.phonenumbers.AsYouTypeFormatter(country);
var output = new goog.string.StringBuffer();
for (var i = 0; i < phone.length; ++i) {
var inputChar = phone.charAt(i);
output = (formatter.inputDigit(inputChar));
}
return output.toString();
} catch (e) {
return phone;
}
}
// -------------------------------------------------------------------------
function formatLocal(country, phone) {
/*
Return the phone number in the format local to the user
country (String) 2 digit country code
phone (String) phone number to format
*/
try {
var phone = cleanPhone(phone);
var phoneUtil = i18n.phonenumbers.PhoneNumberUtil.getInstance();
var number = phoneUtil.parseAndKeepRawInput(phone, country);
if (phoneUtil.isValidNumberForRegion(number, country)) {
var PNF = i18n.phonenumbers.PhoneNumberFormat;
var output = new goog.string.StringBuffer();
output = phoneUtil.format(number, PNF.NATIONAL);
return output.toString();
} else {
return formatInternational(country, phone);
}
} catch (e) {
return formatInternational(country, phone);
}
}
// -------------------------------------------------------------------------
function cleanPhone(phone) {
/*
Remove any non numeric characters from the phone number but leave any plus sign at the beginning
phone (String) phone number to clean
*/
phone = phone.replace(/[^\d\+]/g,'');
if (phone.substr(0, 1) == "+") {
phone = "+" + phone.replace(/[^\d]/g,'');
} else {
phone = phone.replace(/[^\d]/g,'');
}
return phone;
}
// -------------------------------------------------------------------------
function countryCodeToName(countryCode) {
/*
Convert the country code to a name
country (String) 2 digit country code
*/
var arrCountry = new Array();
arrCountry['AF'] = "Afghanistan";
arrCountry['AL'] = "Albania";
arrCountry['DZ'] = "Algeria";
arrCountry['AS'] = "American Samoa";
arrCountry['AD'] = "Andorra";
arrCountry['AO'] = "Angola";
arrCountry['AI'] = "Anguilla";
arrCountry['AQ'] = "Antarctica";
arrCountry['AG'] = "Antigua And Barbuda";
arrCountry['AR'] = "Argentina";
arrCountry['AM'] = "Armenia";
arrCountry['AW'] = "Aruba";
arrCountry['AC'] = "Ascension Island";
arrCountry['AU'] = "Australia";
arrCountry['AT'] = "Austria";
arrCountry['AZ'] = "Azerbaijan";
arrCountry['BS'] = "Bahamas";
arrCountry['BH'] = "Bahrain";
arrCountry['BD'] = "Bangladesh";
arrCountry['BB'] = "Barbados";
arrCountry['BY'] = "Belarus";
arrCountry['BE'] = "Belgium";
arrCountry['BZ'] = "Belize";
arrCountry['BJ'] = "Benin";
arrCountry['BM'] = "Bermuda";
arrCountry['BT'] = "Bhutan";
arrCountry['BO'] = "Bolivia";
arrCountry['BA'] = "Bosnia And Herzegovina";
arrCountry['BW'] = "Botswana";
arrCountry['BV'] = "Bouvet Island";
arrCountry['BR'] = "Brazil";
arrCountry['IO'] = "British Indian Ocean Territory";
arrCountry['BN'] = "Brunei";
arrCountry['BG'] = "Bulgaria";
arrCountry['BF'] = "Burkina Faso";
arrCountry['BI'] = "Burundi";
arrCountry['KH'] = "Cambodia";
arrCountry['CM'] = "Cameroon";
arrCountry['CA'] = "Canada";
arrCountry['CV'] = "Cape Verde";
arrCountry['KY'] = "Cayman Islands";
arrCountry['CF'] = "Central African Republic";
arrCountry['TD'] = "Chad";
arrCountry['CL'] = "Chile";
arrCountry['CN'] = "China";
arrCountry['CX'] = "Christmas Island";
arrCountry['CC'] = "Cocos (Keeling) Islands";
arrCountry['CO'] = "Columbia";
arrCountry['KM'] = "Comoros";
arrCountry['CG'] = "Congo";
arrCountry['CK'] = "Cook Islands";
arrCountry['CR'] = "Costa Rica";
arrCountry['CI'] = "Cote D'Ivorie (Ivory Coast)";
arrCountry['HR'] = "Croatia (Hrvatska)";
arrCountry['CU'] = "Cuba";
arrCountry['CY'] = "Cyprus";
arrCountry['CZ'] = "Czech Republic";
arrCountry['CD'] = "Democratic Republic Of Congo (Zaire)";
arrCountry['DK'] = "Denmark";
arrCountry['DJ'] = "Djibouti";
arrCountry['DM'] = "Dominica";
arrCountry['DO'] = "Dominican Republic";
arrCountry['TL'] = "East Timor";
arrCountry['EC'] = "Ecuador";
arrCountry['EG'] = "Egypt";
arrCountry['SV'] = "El Salvador";
arrCountry['GQ'] = "Equatorial Guinea";
arrCountry['ER'] = "Eritrea";
arrCountry['EE'] = "Estonia";
arrCountry['ET'] = "Ethiopia";
arrCountry['FK'] = "Falkland Islands (Malvinas)";
arrCountry['FO'] = "Faroe Islands";
arrCountry['FJ'] = "Fiji";
arrCountry['FI'] = "Finland";
arrCountry['FR'] = "France";
arrCountry['FX'] = "France, Metropolitan";
arrCountry['GF'] = "French Guinea";
arrCountry['PF'] = "French Polynesia";
arrCountry['TF'] = "French Southern Territories";
arrCountry['GA'] = "Gabon";
arrCountry['GM'] = "Gambia";
arrCountry['GE'] = "Georgia";
arrCountry['DE'] = "Germany";
arrCountry['GH'] = "Ghana";
arrCountry['GI'] = "Gibraltar";
arrCountry['GR'] = "Greece";
arrCountry['GL'] = "Greenland";
arrCountry['GD'] = "Grenada";
arrCountry['GP'] = "Guadeloupe";
arrCountry['GU'] = "Guam";
arrCountry['GT'] = "Guatemala";
arrCountry['GN'] = "Guinea";
arrCountry['GW'] = "Guinea-Bissau";
arrCountry['GY'] = "Guyana";
arrCountry['HT'] = "Haiti";
arrCountry['HM'] = "Heard And McDonald Islands";
arrCountry['HN'] = "Honduras";
arrCountry['HK'] = "Hong Kong";
arrCountry['HU'] = "Hungary";
arrCountry['IS'] = "Iceland";
arrCountry['IN'] = "India";
arrCountry['ID'] = "Indonesia";
arrCountry['IR'] = "Iran";
arrCountry['IQ'] = "Iraq";
arrCountry['IE'] = "Ireland";
arrCountry['IM'] = "Isle of Man";
arrCountry['IL'] = "Israel";
arrCountry['IT'] = "Italy";
arrCountry['JM'] = "Jamaica";
arrCountry['JP'] = "Japan";
arrCountry['JO'] = "Jordan";
arrCountry['KZ'] = "Kazakhstan";
arrCountry['KE'] = "Kenya";
arrCountry['KI'] = "Kiribati";
arrCountry['KW'] = "Kuwait";
arrCountry['KG'] = "Kyrgyzstan";
arrCountry['LA'] = "Laos";
arrCountry['LV'] = "Latvia";
arrCountry['LB'] = "Lebanon";
arrCountry['LS'] = "Lesotho";
arrCountry['LR'] = "Liberia";
arrCountry['LY'] = "Libya";
arrCountry['LI'] = "Liechtenstein";
arrCountry['LT'] = "Lithuania";
arrCountry['LU'] = "Luxembourg";
arrCountry['MO'] = "Macau";
arrCountry['MK'] = "Macedonia";
arrCountry['MG'] = "Madagascar";
arrCountry['MW'] = "Malawi";
arrCountry['MY'] = "Malaysia";
arrCountry['MV'] = "Maldives";
arrCountry['ML'] = "Mali";
arrCountry['MT'] = "Malta";
arrCountry['MH'] = "Marshall Islands";
arrCountry['MQ'] = "Martinique";
arrCountry['MR'] = "Mauritania";
arrCountry['MU'] = "Mauritius";
arrCountry['YT'] = "Mayotte";
arrCountry['MX'] = "Mexico";
arrCountry['FM'] = "Micronesia";
arrCountry['MD'] = "Moldova";
arrCountry['MC'] = "Monaco";
arrCountry['MN'] = "Mongolia";
arrCountry['ME'] = "Montenegro";
arrCountry['MS'] = "Montserrat";
arrCountry['MA'] = "Morocco";
arrCountry['MZ'] = "Mozambique";
arrCountry['MM'] = "Myanmar (Burma)";
arrCountry['NA'] = "Namibia";
arrCountry['NR'] = "Nauru";
arrCountry['NP'] = "Nepal";
arrCountry['NL'] = "Netherlands";
arrCountry['AN'] = "Netherlands Antilles";
arrCountry['NC'] = "New Caledonia";
arrCountry['NZ'] = "New Zealand";
arrCountry['NI'] = "Nicaragua";
arrCountry['NE'] = "Niger";
arrCountry['NG'] = "Nigeria";
arrCountry['NU'] = "Niue";
arrCountry['NF'] = "Norfolk Island";
arrCountry['KP'] = "North Korea";
arrCountry['MP'] = "Northern Mariana Islands";
arrCountry['NO'] = "Norway";
arrCountry['OM'] = "Oman";
arrCountry['PK'] = "Pakistan";
arrCountry['PW'] = "Palau";
arrCountry['PS'] = "Palestine";
arrCountry['PA'] = "Panama";
arrCountry['PG'] = "Papua New Guinea";
arrCountry['PY'] = "Paraguay";
arrCountry['PE'] = "Peru";
arrCountry['PH'] = "Philippines";
arrCountry['PN'] = "Pitcairn";
arrCountry['PL'] = "Poland";
arrCountry['PT'] = "Portugal";
arrCountry['PR'] = "Puerto Rico";
arrCountry['QA'] = "Qatar";
arrCountry['RE'] = "Reunion";
arrCountry['RO'] = "Romania";
arrCountry['RU'] = "Russia";
arrCountry['RW'] = "Rwanda";
arrCountry['SH'] = "Saint Helena";
arrCountry['KN'] = "Saint Kitts And Nevis";
arrCountry['LC'] = "Saint Lucia";
arrCountry['PM'] = "Saint Pierre And Miquelon";
arrCountry['VC'] = "Saint Vincent And The Grenadines";
arrCountry['SM'] = "San Marino";
arrCountry['ST'] = "Sao Tome And Principe";
arrCountry['SA'] = "Saudi Arabia";
arrCountry['SN'] = "Senegal";
arrCountry['RS'] = "Serbia";
arrCountry['SC'] = "Seychelles";
arrCountry['SL'] = "Sierra Leone";
arrCountry['SG'] = "Singapore";
arrCountry['SK'] = "Slovak Republic";
arrCountry['SI'] = "Slovenia";
arrCountry['SB'] = "Solomon Islands";
arrCountry['SO'] = "Somalia";
arrCountry['ZA'] = "South Africa";
arrCountry['GS'] = "South Georgia And South Sandwich Islands";
arrCountry['KR'] = "South Korea";
arrCountry['ES'] = "Spain";
arrCountry['LK'] = "Sri Lanka";
arrCountry['SD'] = "Sudan";
arrCountry['SR'] = "Suriname";
arrCountry['SJ'] = "Svalbard And Jan Mayen";
arrCountry['SZ'] = "Swaziland";
arrCountry['SE'] = "Sweden";
arrCountry['CH'] = "Switzerland";
arrCountry['SY'] = "Syria";
arrCountry['TW'] = "Taiwan";
arrCountry['TJ'] = "Tajikistan";
arrCountry['TZ'] = "Tanzania";
arrCountry['TH'] = "Thailand";
arrCountry['TG'] = "Togo";
arrCountry['TK'] = "Tokelau";
arrCountry['TO'] = "Tonga";
arrCountry['TT'] = "Trinidad And Tobago";
arrCountry['TN'] = "Tunisia";
arrCountry['TR'] = "Turkey";
arrCountry['TM'] = "Turkmenistan";
arrCountry['TC'] = "Turks And Caicos Islands";
arrCountry['TV'] = "Tuvalu";
arrCountry['UG'] = "Uganda";
arrCountry['UA'] = "Ukraine";
arrCountry['AE'] = "United Arab Emirates";
arrCountry['GB'] = "United Kingdom";
arrCountry['US'] = "United States";
arrCountry['UM'] = "United States Minor Outlying Islands";
arrCountry['UY'] = "Uruguay";
arrCountry['UZ'] = "Uzbekistan";
arrCountry['VU'] = "Vanuatu";
arrCountry['VA'] = "Vatican City (Holy See)";
arrCountry['VE'] = "Venezuela";
arrCountry['VN'] = "Vietnam";
arrCountry['VG'] = "Virgin Islands (British)";
arrCountry['VI'] = "Virgin Islands (US)";
arrCountry['WF'] = "Wallis And Futuna Islands";
arrCountry['EH'] = "Western Sahara";
arrCountry['WS'] = "Western Samoa";
arrCountry['YE'] = "Yemen";
arrCountry['YU'] = "Yugoslavia";
arrCountry['ZM'] = "Zambia";
arrCountry['ZW'] = "Zimbabwe";
var name = arrCountry[countryCode.toUpperCase()];
if (name === undefined) {
return "";
} else {
return name;
}
}