libphonenumber-js 1.10.22 → 1.10.23

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.
@@ -23,12 +23,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
23
23
  // Carriers codes aren't part of this library.
24
24
  // Send a PR if you want to add them.
25
25
  var REGION_CODE_FOR_NON_GEO_ENTITY = '001';
26
- /**
27
- * The prefix that needs to be inserted in front of a Colombian landline number
28
- * when dialed from a mobile phone in Colombia.
29
- */
30
-
31
- var COLOMBIA_MOBILE_TO_FIXED_LINE_PREFIX = '3';
32
26
  /**
33
27
  * Returns a number formatted in such a way that it can be dialed from a mobile
34
28
  * phone in a specific region. If the number cannot be reached from the region
@@ -62,9 +56,7 @@ function _default(number, from_country, with_formatting, metadata) {
62
56
  if (country === from_country) {
63
57
  var is_fixed_line_or_mobile = number_type === 'FIXED_LINE' || number_type === 'MOBILE' || number_type === 'FIXED_LINE_OR_MOBILE'; // Carrier codes may be needed in some countries. We handle this here.
64
58
 
65
- if (country === 'CO' && number_type === 'FIXED_LINE') {
66
- formatted_number = formatNationalNumberWithCarrierCode(number, COLOMBIA_MOBILE_TO_FIXED_LINE_PREFIX);
67
- } else if (country == 'BR' && is_fixed_line_or_mobile) {
59
+ if (country == 'BR' && is_fixed_line_or_mobile) {
68
60
  formatted_number = carrierCode ? formatNationalNumberWithPreferredCarrierCode(number) : // Brazilian fixed line and mobile numbers need to be dialed with a
69
61
  // carrier code when called within Brazil. Without that, most of the
70
62
  // carriers won't connect the call. Because of that, we return an
@@ -1 +1 @@
1
- {"version":3,"file":"formatPhoneNumberForMobileDialing.js","names":["REGION_CODE_FOR_NON_GEO_ENTITY","COLOMBIA_MOBILE_TO_FIXED_LINE_PREFIX","number","from_country","with_formatting","metadata","Metadata","hasCountry","Error","phone","country","number_type","getNumberType","undefined","is_valid_number","formatted_number","is_fixed_line_or_mobile","formatNationalNumberWithCarrierCode","carrierCode","formatNationalNumberWithPreferredCarrierCode","getCountryCallingCode","can_be_internationally_dialled","checkNumberLength","format","diallable_chars","DIALLABLE_CHARACTERS","result","i","length","character","getPreferredDomesticCarrierCodeOrDefault"],"sources":["../source/formatPhoneNumberForMobileDialing.js"],"sourcesContent":["// This function is copy-pasted from\r\n// https://github.com/googlei18n/libphonenumber/blob/master/javascript/i18n/phonenumbers/phonenumberutil.js\r\n// It hasn't been tested. It's not currently exported.\r\n// Carriers codes aren't part of this library.\r\n// Send a PR if you want to add them.\r\n\r\nimport Metadata from './metadata.js'\r\nimport format from './format.js'\r\nimport getNumberType from './helpers/getNumberType.js'\r\nimport checkNumberLength from './helpers/checkNumberLength.js'\r\nimport getCountryCallingCode from './getCountryCallingCode.js'\r\n\r\nconst REGION_CODE_FOR_NON_GEO_ENTITY = '001'\r\n\r\n/**\r\n * The prefix that needs to be inserted in front of a Colombian landline number\r\n * when dialed from a mobile phone in Colombia.\r\n */\r\nconst COLOMBIA_MOBILE_TO_FIXED_LINE_PREFIX = '3'\r\n\r\n/**\r\n * Returns a number formatted in such a way that it can be dialed from a mobile\r\n * phone in a specific region. If the number cannot be reached from the region\r\n * (e.g. some countries block toll-free numbers from being called outside of the\r\n * country), the method returns an empty string.\r\n *\r\n * @param {object} number - a `parse()`d phone number to be formatted.\r\n * @param {string} from_country - the region where the call is being placed.\r\n * @param {boolean} with_formatting - whether the number should be returned with\r\n * formatting symbols, such as spaces and dashes.\r\n * @return {string}\r\n */\r\nexport default function(number, from_country, with_formatting, metadata) {\r\n\tmetadata = new Metadata(metadata)\r\n\r\n\t// Validate `from_country`.\r\n\tif (!metadata.hasCountry(from_country)) {\r\n\t\tthrow new Error(`Unknown country: ${from_country}`)\r\n\t}\r\n\r\n\t// Not using the extension, as that part cannot normally be dialed\r\n\t// together with the main number.\r\n\tnumber = {\r\n\t\tphone: number.phone,\r\n\t\tcountry: number.country\r\n\t}\r\n\r\n\tconst number_type = getNumberType(number, undefined, metadata.metadata)\r\n\tconst is_valid_number = number_type === number\r\n\r\n\tlet formatted_number\r\n\r\n\tif (country === from_country) {\r\n\t\tconst is_fixed_line_or_mobile =\r\n\t\t\tnumber_type === 'FIXED_LINE' ||\r\n\t\t\tnumber_type === 'MOBILE' ||\r\n\t\t\tnumber_type === 'FIXED_LINE_OR_MOBILE'\r\n\r\n\t\t// Carrier codes may be needed in some countries. We handle this here.\r\n\t\tif (country === 'CO' && number_type === 'FIXED_LINE') {\r\n\t\t\tformatted_number = formatNationalNumberWithCarrierCode(\r\n\t\t\t\tnumber,\r\n\t\t\t\tCOLOMBIA_MOBILE_TO_FIXED_LINE_PREFIX\r\n\t\t\t)\r\n\t\t}\r\n\t\telse if (country == 'BR' && is_fixed_line_or_mobile) {\r\n\t\t\tformatted_number =\r\n\t\t\t\tcarrierCode ?\r\n\t\t\t\tformatNationalNumberWithPreferredCarrierCode(number) :\r\n\t\t\t\t// Brazilian fixed line and mobile numbers need to be dialed with a\r\n\t\t\t\t// carrier code when called within Brazil. Without that, most of the\r\n\t\t\t\t// carriers won't connect the call. Because of that, we return an\r\n\t\t\t\t// empty string here.\r\n\t\t\t\t''\r\n\t\t} else if (getCountryCallingCode(country, metadata.metadata) === '1') {\r\n\t\t\t// For NANPA countries, we output international format for numbers that\r\n\t\t\t// can be dialed internationally, since that always works, except for\r\n\t\t\t// numbers which might potentially be short numbers, which are always\r\n\t\t\t// dialled in national format.\r\n\r\n\t\t\t// Select country for `checkNumberLength()`.\r\n\t\t\tmetadata.country(country)\r\n\r\n\t\t\tif (can_be_internationally_dialled(number) &&\r\n\t\t\t\tcheckNumberLength(number.phone, metadata) !== 'TOO_SHORT') {\r\n\t\t\t\tformatted_number = format(number, 'INTERNATIONAL', metadata.metadata)\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tformatted_number = format(number, 'NATIONAL', metadata.metadata)\r\n\t\t\t}\r\n\t\t}\r\n\t\telse {\r\n\t\t\t// For non-geographic countries, Mexican and Chilean fixed line and\r\n\t\t\t// mobile numbers, we output international format for numbers that can be\r\n\t\t\t// dialed internationally, as that always works.\r\n\t\t\tif (\r\n\t\t\t\t(\r\n\t\t\t\t\tcountry === REGION_CODE_FOR_NON_GEO_ENTITY\r\n\t\t\t\t\t||\r\n\t\t\t\t\t// MX fixed line and mobile numbers should always be formatted in\r\n\t\t\t\t\t// international format, even when dialed within MX. For national\r\n\t\t\t\t\t// format to work, a carrier code needs to be used, and the correct\r\n\t\t\t\t\t// carrier code depends on if the caller and callee are from the\r\n\t\t\t\t\t// same local area. It is trickier to get that to work correctly than\r\n\t\t\t\t\t// using international format, which is tested to work fine on all\r\n\t\t\t\t\t// carriers.\r\n\t\t\t\t\t//\r\n\t\t\t\t\t// CL fixed line numbers need the national prefix when dialing in the\r\n\t\t\t\t\t// national format, but don't have it when used for display. The\r\n\t\t\t\t\t// reverse is true for mobile numbers. As a result, we output them in\r\n\t\t\t\t\t// the international format to make it work.\r\n\t\t\t\t\t//\r\n\t\t\t\t\t// UZ mobile and fixed-line numbers have to be formatted in\r\n\t\t\t\t\t// international format or prefixed with special codes like 03, 04\r\n\t\t\t\t\t// (for fixed-line) and 05 (for mobile) for dialling successfully\r\n\t\t\t\t\t// from mobile devices. As we do not have complete information on\r\n\t\t\t\t\t// special codes and to be consistent with formatting across all\r\n\t\t\t\t\t// phone types we return the number in international format here.\r\n\t\t\t\t\t//\r\n\t\t\t\t\t((country === 'MX' || country === 'CL' || country == 'UZ') && is_fixed_line_or_mobile)\r\n\t\t\t\t)\r\n\t\t\t\t&&\r\n\t\t\t\tcan_be_internationally_dialled(number)\r\n\t\t\t) {\r\n\t\t\t\tformatted_number = format(number, 'INTERNATIONAL')\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tformatted_number = format(number, 'NATIONAL')\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\telse if (is_valid_number && can_be_internationally_dialled(number)) {\r\n\t\t// We assume that short numbers are not diallable from outside their region,\r\n\t\t// so if a number is not a valid regular length phone number, we treat it as\r\n\t\t// if it cannot be internationally dialled.\r\n\t\treturn with_formatting ?\r\n\t\t\tformat(number, 'INTERNATIONAL', metadata.metadata) :\r\n\t\t\tformat(number, 'E.164', metadata.metadata)\r\n\t}\r\n\r\n\tif (!with_formatting) {\r\n\t\treturn diallable_chars(formatted_number)\r\n\t}\r\n\r\n\treturn formatted_number\r\n}\r\n\r\nfunction can_be_internationally_dialled(number) {\r\n\treturn true\r\n}\r\n\r\n/**\r\n * A map that contains characters that are essential when dialling. That means\r\n * any of the characters in this map must not be removed from a number when\r\n * dialling, otherwise the call will not reach the intended destination.\r\n */\r\nconst DIALLABLE_CHARACTERS = {\r\n\t'0': '0',\r\n\t'1': '1',\r\n\t'2': '2',\r\n\t'3': '3',\r\n\t'4': '4',\r\n\t'5': '5',\r\n\t'6': '6',\r\n\t'7': '7',\r\n\t'8': '8',\r\n\t'9': '9',\r\n\t'+': '+',\r\n\t'*': '*',\r\n\t'#': '#'\r\n}\r\n\r\nfunction diallable_chars(formatted_number) {\r\n\tlet result = ''\r\n\r\n\tlet i = 0\r\n\twhile (i < formatted_number.length) {\r\n\t\tconst character = formatted_number[i]\r\n\t\tif (DIALLABLE_CHARACTERS[character]) {\r\n\t\t\tresult += character\r\n\t\t}\r\n\t\ti++\r\n\t}\r\n\r\n\treturn result\r\n}\r\n\r\nfunction getPreferredDomesticCarrierCodeOrDefault() {\r\n\tthrow new Error('carrier codes are not part of this library')\r\n}\r\n\r\nfunction formatNationalNumberWithCarrierCode() {\r\n\tthrow new Error('carrier codes are not part of this library')\r\n}\r\n\r\n/**\r\n * Formats a phone number in national format for dialing using the carrier as\r\n * specified in the preferred_domestic_carrier_code field of the PhoneNumber\r\n * object passed in. If that is missing, use the {@code fallbackCarrierCode}\r\n * passed in instead. If there is no {@code preferred_domestic_carrier_code},\r\n * and the {@code fallbackCarrierCode} contains an empty string, return the\r\n * number in national format without any carrier code.\r\n *\r\n * <p>Use {@link #formatNationalNumberWithCarrierCode} instead if the carrier\r\n * code passed in should take precedence over the number's\r\n * {@code preferred_domestic_carrier_code} when formatting.\r\n *\r\n * @param {i18n.phonenumbers.PhoneNumber} number the phone number to be\r\n * formatted.\r\n * @param {string} fallbackCarrierCode the carrier selection code to be used, if\r\n * none is found in the phone number itself.\r\n * @return {string} the formatted phone number in national format for dialing\r\n * using the number's preferred_domestic_carrier_code, or the\r\n * {@code fallbackCarrierCode} passed in if none is found.\r\n */\r\nfunction formatNationalNumberWithPreferredCarrierCode(number) {\r\n\treturn formatNationalNumberWithCarrierCode(\r\n\t\tnumber,\r\n\t\tcarrierCode\r\n\t);\r\n}"],"mappings":";;;;;;;AAMA;;AACA;;AACA;;AACA;;AACA;;;;AAVA;AACA;AACA;AACA;AACA;AAQA,IAAMA,8BAA8B,GAAG,KAAvC;AAEA;AACA;AACA;AACA;;AACA,IAAMC,oCAAoC,GAAG,GAA7C;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACe,kBAASC,MAAT,EAAiBC,YAAjB,EAA+BC,eAA/B,EAAgDC,QAAhD,EAA0D;EACxEA,QAAQ,GAAG,IAAIC,oBAAJ,CAAaD,QAAb,CAAX,CADwE,CAGxE;;EACA,IAAI,CAACA,QAAQ,CAACE,UAAT,CAAoBJ,YAApB,CAAL,EAAwC;IACvC,MAAM,IAAIK,KAAJ,4BAA8BL,YAA9B,EAAN;EACA,CANuE,CAQxE;EACA;;;EACAD,MAAM,GAAG;IACRO,KAAK,EAAEP,MAAM,CAACO,KADN;IAERC,OAAO,EAAER,MAAM,CAACQ;EAFR,CAAT;EAKA,IAAMC,WAAW,GAAG,IAAAC,yBAAA,EAAcV,MAAd,EAAsBW,SAAtB,EAAiCR,QAAQ,CAACA,QAA1C,CAApB;EACA,IAAMS,eAAe,GAAGH,WAAW,KAAKT,MAAxC;EAEA,IAAIa,gBAAJ;;EAEA,IAAIL,OAAO,KAAKP,YAAhB,EAA8B;IAC7B,IAAMa,uBAAuB,GAC5BL,WAAW,KAAK,YAAhB,I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OD,MAAP;AACA;;AAED,SAASI,wCAAT,GAAoD;EACnD,MAAM,IAAItB,KAAJ,CAAU,4CAAV,CAAN;AACA;;AAED,SAASS,mCAAT,GAA+C;EAC9C,MAAM,IAAIT,KAAJ,CAAU,4CAAV,CAAN;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASW,4CAAT,CAAsDjB,MAAtD,EAA8D;EAC7D,OAAOe,mCAAmC,CACzCf,MADyC,EAEzCgB,WAFyC,CAA1C;AAIA"}
1
+ {"version":3,"file":"formatPhoneNumberForMobileDialing.js","names":["REGION_CODE_FOR_NON_GEO_ENTITY","number","from_country","with_formatting","metadata","Metadata","hasCountry","Error","phone","country","number_type","getNumberType","undefined","is_valid_number","formatted_number","is_fixed_line_or_mobile","carrierCode","formatNationalNumberWithPreferredCarrierCode","getCountryCallingCode","can_be_internationally_dialled","checkNumberLength","format","diallable_chars","DIALLABLE_CHARACTERS","result","i","length","character","getPreferredDomesticCarrierCodeOrDefault","formatNationalNumberWithCarrierCode"],"sources":["../source/formatPhoneNumberForMobileDialing.js"],"sourcesContent":["// This function is copy-pasted from\r\n// https://github.com/googlei18n/libphonenumber/blob/master/javascript/i18n/phonenumbers/phonenumberutil.js\r\n// It hasn't been tested. It's not currently exported.\r\n// Carriers codes aren't part of this library.\r\n// Send a PR if you want to add them.\r\n\r\nimport Metadata from './metadata.js'\r\nimport format from './format.js'\r\nimport getNumberType from './helpers/getNumberType.js'\r\nimport checkNumberLength from './helpers/checkNumberLength.js'\r\nimport getCountryCallingCode from './getCountryCallingCode.js'\r\n\r\nconst REGION_CODE_FOR_NON_GEO_ENTITY = '001'\r\n\r\n/**\r\n * Returns a number formatted in such a way that it can be dialed from a mobile\r\n * phone in a specific region. If the number cannot be reached from the region\r\n * (e.g. some countries block toll-free numbers from being called outside of the\r\n * country), the method returns an empty string.\r\n *\r\n * @param {object} number - a `parse()`d phone number to be formatted.\r\n * @param {string} from_country - the region where the call is being placed.\r\n * @param {boolean} with_formatting - whether the number should be returned with\r\n * formatting symbols, such as spaces and dashes.\r\n * @return {string}\r\n */\r\nexport default function(number, from_country, with_formatting, metadata) {\r\n\tmetadata = new Metadata(metadata)\r\n\r\n\t// Validate `from_country`.\r\n\tif (!metadata.hasCountry(from_country)) {\r\n\t\tthrow new Error(`Unknown country: ${from_country}`)\r\n\t}\r\n\r\n\t// Not using the extension, as that part cannot normally be dialed\r\n\t// together with the main number.\r\n\tnumber = {\r\n\t\tphone: number.phone,\r\n\t\tcountry: number.country\r\n\t}\r\n\r\n\tconst number_type = getNumberType(number, undefined, metadata.metadata)\r\n\tconst is_valid_number = number_type === number\r\n\r\n\tlet formatted_number\r\n\r\n\tif (country === from_country) {\r\n\t\tconst is_fixed_line_or_mobile =\r\n\t\t\tnumber_type === 'FIXED_LINE' ||\r\n\t\t\tnumber_type === 'MOBILE' ||\r\n\t\t\tnumber_type === 'FIXED_LINE_OR_MOBILE'\r\n\r\n\t\t// Carrier codes may be needed in some countries. We handle this here.\r\n\t\tif (country == 'BR' && is_fixed_line_or_mobile) {\r\n\t\t\tformatted_number =\r\n\t\t\t\tcarrierCode ?\r\n\t\t\t\tformatNationalNumberWithPreferredCarrierCode(number) :\r\n\t\t\t\t// Brazilian fixed line and mobile numbers need to be dialed with a\r\n\t\t\t\t// carrier code when called within Brazil. Without that, most of the\r\n\t\t\t\t// carriers won't connect the call. Because of that, we return an\r\n\t\t\t\t// empty string here.\r\n\t\t\t\t''\r\n\t\t} else if (getCountryCallingCode(country, metadata.metadata) === '1') {\r\n\t\t\t// For NANPA countries, we output international format for numbers that\r\n\t\t\t// can be dialed internationally, since that always works, except for\r\n\t\t\t// numbers which might potentially be short numbers, which are always\r\n\t\t\t// dialled in national format.\r\n\r\n\t\t\t// Select country for `checkNumberLength()`.\r\n\t\t\tmetadata.country(country)\r\n\r\n\t\t\tif (can_be_internationally_dialled(number) &&\r\n\t\t\t\tcheckNumberLength(number.phone, metadata) !== 'TOO_SHORT') {\r\n\t\t\t\tformatted_number = format(number, 'INTERNATIONAL', metadata.metadata)\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tformatted_number = format(number, 'NATIONAL', metadata.metadata)\r\n\t\t\t}\r\n\t\t}\r\n\t\telse {\r\n\t\t\t// For non-geographic countries, Mexican and Chilean fixed line and\r\n\t\t\t// mobile numbers, we output international format for numbers that can be\r\n\t\t\t// dialed internationally, as that always works.\r\n\t\t\tif (\r\n\t\t\t\t(\r\n\t\t\t\t\tcountry === REGION_CODE_FOR_NON_GEO_ENTITY\r\n\t\t\t\t\t||\r\n\t\t\t\t\t// MX fixed line and mobile numbers should always be formatted in\r\n\t\t\t\t\t// international format, even when dialed within MX. For national\r\n\t\t\t\t\t// format to work, a carrier code needs to be used, and the correct\r\n\t\t\t\t\t// carrier code depends on if the caller and callee are from the\r\n\t\t\t\t\t// same local area. It is trickier to get that to work correctly than\r\n\t\t\t\t\t// using international format, which is tested to work fine on all\r\n\t\t\t\t\t// carriers.\r\n\t\t\t\t\t//\r\n\t\t\t\t\t// CL fixed line numbers need the national prefix when dialing in the\r\n\t\t\t\t\t// national format, but don't have it when used for display. The\r\n\t\t\t\t\t// reverse is true for mobile numbers. As a result, we output them in\r\n\t\t\t\t\t// the international format to make it work.\r\n\t\t\t\t\t//\r\n\t\t\t\t\t// UZ mobile and fixed-line numbers have to be formatted in\r\n\t\t\t\t\t// international format or prefixed with special codes like 03, 04\r\n\t\t\t\t\t// (for fixed-line) and 05 (for mobile) for dialling successfully\r\n\t\t\t\t\t// from mobile devices. As we do not have complete information on\r\n\t\t\t\t\t// special codes and to be consistent with formatting across all\r\n\t\t\t\t\t// phone types we return the number in international format here.\r\n\t\t\t\t\t//\r\n\t\t\t\t\t((country === 'MX' || country === 'CL' || country == 'UZ') && is_fixed_line_or_mobile)\r\n\t\t\t\t)\r\n\t\t\t\t&&\r\n\t\t\t\tcan_be_internationally_dialled(number)\r\n\t\t\t) {\r\n\t\t\t\tformatted_number = format(number, 'INTERNATIONAL')\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tformatted_number = format(number, 'NATIONAL')\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\telse if (is_valid_number && can_be_internationally_dialled(number)) {\r\n\t\t// We assume that short numbers are not diallable from outside their region,\r\n\t\t// so if a number is not a valid regular length phone number, we treat it as\r\n\t\t// if it cannot be internationally dialled.\r\n\t\treturn with_formatting ?\r\n\t\t\tformat(number, 'INTERNATIONAL', metadata.metadata) :\r\n\t\t\tformat(number, 'E.164', metadata.metadata)\r\n\t}\r\n\r\n\tif (!with_formatting) {\r\n\t\treturn diallable_chars(formatted_number)\r\n\t}\r\n\r\n\treturn formatted_number\r\n}\r\n\r\nfunction can_be_internationally_dialled(number) {\r\n\treturn true\r\n}\r\n\r\n/**\r\n * A map that contains characters that are essential when dialling. That means\r\n * any of the characters in this map must not be removed from a number when\r\n * dialling, otherwise the call will not reach the intended destination.\r\n */\r\nconst DIALLABLE_CHARACTERS = {\r\n\t'0': '0',\r\n\t'1': '1',\r\n\t'2': '2',\r\n\t'3': '3',\r\n\t'4': '4',\r\n\t'5': '5',\r\n\t'6': '6',\r\n\t'7': '7',\r\n\t'8': '8',\r\n\t'9': '9',\r\n\t'+': '+',\r\n\t'*': '*',\r\n\t'#': '#'\r\n}\r\n\r\nfunction diallable_chars(formatted_number) {\r\n\tlet result = ''\r\n\r\n\tlet i = 0\r\n\twhile (i < formatted_number.length) {\r\n\t\tconst character = formatted_number[i]\r\n\t\tif (DIALLABLE_CHARACTERS[character]) {\r\n\t\t\tresult += character\r\n\t\t}\r\n\t\ti++\r\n\t}\r\n\r\n\treturn result\r\n}\r\n\r\nfunction getPreferredDomesticCarrierCodeOrDefault() {\r\n\tthrow new Error('carrier codes are not part of this library')\r\n}\r\n\r\nfunction formatNationalNumberWithCarrierCode() {\r\n\tthrow new Error('carrier codes are not part of this library')\r\n}\r\n\r\n/**\r\n * Formats a phone number in national format for dialing using the carrier as\r\n * specified in the preferred_domestic_carrier_code field of the PhoneNumber\r\n * object passed in. If that is missing, use the {@code fallbackCarrierCode}\r\n * passed in instead. If there is no {@code preferred_domestic_carrier_code},\r\n * and the {@code fallbackCarrierCode} contains an empty string, return the\r\n * number in national format without any carrier code.\r\n *\r\n * <p>Use {@link #formatNationalNumberWithCarrierCode} instead if the carrier\r\n * code passed in should take precedence over the number's\r\n * {@code preferred_domestic_carrier_code} when formatting.\r\n *\r\n * @param {i18n.phonenumbers.PhoneNumber} number the phone number to be\r\n * formatted.\r\n * @param {string} fallbackCarrierCode the carrier selection code to be used, if\r\n * none is found in the phone number itself.\r\n * @return {string} the formatted phone number in national format for dialing\r\n * using the number's preferred_domestic_carrier_code, or the\r\n * {@code fallbackCarrierCode} passed in if none is found.\r\n */\r\nfunction formatNationalNumberWithPreferredCarrierCode(number) {\r\n\treturn formatNationalNumberWithCarrierCode(\r\n\t\tnumber,\r\n\t\tcarrierCode\r\n\t);\r\n}"],"mappings":";;;;;;;AAMA;;AACA;;AACA;;AACA;;AACA;;;;AAVA;AACA;AACA;AACA;AACA;AAQA,IAAMA,8BAA8B,GAAG,KAAvC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACe,kBAASC,MAAT,EAAiBC,YAAjB,EAA+BC,eAA/B,EAAgDC,QAAhD,EAA0D;EACxEA,QAAQ,GAAG,IAAIC,oBAAJ,CAAaD,QAAb,CAAX,CADwE,CAGxE;;EACA,IAAI,CAACA,QAAQ,CAACE,UAAT,CAAoBJ,YAApB,CAAL,EAAwC;IACvC,MAAM,IAAIK,KAAJ,4BAA8BL,YAA9B,EAAN;EACA,CANuE,CAQxE;EACA;;;EACAD,MAAM,GAAG;IACRO,KAAK,EAAEP,MAAM,CAACO,KADN;IAERC,OAAO,EAAER,MAAM,CAACQ;EAFR,CAAT;EAKA,IAAMC,WAAW,GAAG,IAAAC,yBAAA,EAAcV,M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AqC;MACpCH,MAAM,IAAIG,SAAV;IACA;;IACDF,CAAC;EACD;;EAED,OAAOD,MAAP;AACA;;AAED,SAASI,wCAAT,GAAoD;EACnD,MAAM,IAAIrB,KAAJ,CAAU,4CAAV,CAAN;AACA;;AAED,SAASsB,mCAAT,GAA+C;EAC9C,MAAM,IAAItB,KAAJ,CAAU,4CAAV,CAAN;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASU,4CAAT,CAAsDhB,MAAtD,EAA8D;EAC7D,OAAO4B,mCAAmC,CACzC5B,MADyC,EAEzCe,WAFyC,CAA1C;AAIA"}
@@ -9,12 +9,6 @@ import getNumberType from './helpers/getNumberType.js';
9
9
  import checkNumberLength from './helpers/checkNumberLength.js';
10
10
  import getCountryCallingCode from './getCountryCallingCode.js';
11
11
  var REGION_CODE_FOR_NON_GEO_ENTITY = '001';
12
- /**
13
- * The prefix that needs to be inserted in front of a Colombian landline number
14
- * when dialed from a mobile phone in Colombia.
15
- */
16
-
17
- var COLOMBIA_MOBILE_TO_FIXED_LINE_PREFIX = '3';
18
12
  /**
19
13
  * Returns a number formatted in such a way that it can be dialed from a mobile
20
14
  * phone in a specific region. If the number cannot be reached from the region
@@ -48,9 +42,7 @@ export default function (number, from_country, with_formatting, metadata) {
48
42
  if (country === from_country) {
49
43
  var is_fixed_line_or_mobile = number_type === 'FIXED_LINE' || number_type === 'MOBILE' || number_type === 'FIXED_LINE_OR_MOBILE'; // Carrier codes may be needed in some countries. We handle this here.
50
44
 
51
- if (country === 'CO' && number_type === 'FIXED_LINE') {
52
- formatted_number = formatNationalNumberWithCarrierCode(number, COLOMBIA_MOBILE_TO_FIXED_LINE_PREFIX);
53
- } else if (country == 'BR' && is_fixed_line_or_mobile) {
45
+ if (country == 'BR' && is_fixed_line_or_mobile) {
54
46
  formatted_number = carrierCode ? formatNationalNumberWithPreferredCarrierCode(number) : // Brazilian fixed line and mobile numbers need to be dialed with a
55
47
  // carrier code when called within Brazil. Without that, most of the
56
48
  // carriers won't connect the call. Because of that, we return an
@@ -1 +1 @@
1
- {"version":3,"file":"formatPhoneNumberForMobileDialing.js","names":["Metadata","format","getNumberType","checkNumberLength","getCountryCallingCode","REGION_CODE_FOR_NON_GEO_ENTITY","COLOMBIA_MOBILE_TO_FIXED_LINE_PREFIX","number","from_country","with_formatting","metadata","hasCountry","Error","phone","country","number_type","undefined","is_valid_number","formatted_number","is_fixed_line_or_mobile","formatNationalNumberWithCarrierCode","carrierCode","formatNationalNumberWithPreferredCarrierCode","can_be_internationally_dialled","diallable_chars","DIALLABLE_CHARACTERS","result","i","length","character","getPreferredDomesticCarrierCodeOrDefault"],"sources":["../source/formatPhoneNumberForMobileDialing.js"],"sourcesContent":["// This function is copy-pasted from\r\n// https://github.com/googlei18n/libphonenumber/blob/master/javascript/i18n/phonenumbers/phonenumberutil.js\r\n// It hasn't been tested. It's not currently exported.\r\n// Carriers codes aren't part of this library.\r\n// Send a PR if you want to add them.\r\n\r\nimport Metadata from './metadata.js'\r\nimport format from './format.js'\r\nimport getNumberType from './helpers/getNumberType.js'\r\nimport checkNumberLength from './helpers/checkNumberLength.js'\r\nimport getCountryCallingCode from './getCountryCallingCode.js'\r\n\r\nconst REGION_CODE_FOR_NON_GEO_ENTITY = '001'\r\n\r\n/**\r\n * The prefix that needs to be inserted in front of a Colombian landline number\r\n * when dialed from a mobile phone in Colombia.\r\n */\r\nconst COLOMBIA_MOBILE_TO_FIXED_LINE_PREFIX = '3'\r\n\r\n/**\r\n * Returns a number formatted in such a way that it can be dialed from a mobile\r\n * phone in a specific region. If the number cannot be reached from the region\r\n * (e.g. some countries block toll-free numbers from being called outside of the\r\n * country), the method returns an empty string.\r\n *\r\n * @param {object} number - a `parse()`d phone number to be formatted.\r\n * @param {string} from_country - the region where the call is being placed.\r\n * @param {boolean} with_formatting - whether the number should be returned with\r\n * formatting symbols, such as spaces and dashes.\r\n * @return {string}\r\n */\r\nexport default function(number, from_country, with_formatting, metadata) {\r\n\tmetadata = new Metadata(metadata)\r\n\r\n\t// Validate `from_country`.\r\n\tif (!metadata.hasCountry(from_country)) {\r\n\t\tthrow new Error(`Unknown country: ${from_country}`)\r\n\t}\r\n\r\n\t// Not using the extension, as that part cannot normally be dialed\r\n\t// together with the main number.\r\n\tnumber = {\r\n\t\tphone: number.phone,\r\n\t\tcountry: number.country\r\n\t}\r\n\r\n\tconst number_type = getNumberType(number, undefined, metadata.metadata)\r\n\tconst is_valid_number = number_type === number\r\n\r\n\tlet formatted_number\r\n\r\n\tif (country === from_country) {\r\n\t\tconst is_fixed_line_or_mobile =\r\n\t\t\tnumber_type === 'FIXED_LINE' ||\r\n\t\t\tnumber_type === 'MOBILE' ||\r\n\t\t\tnumber_type === 'FIXED_LINE_OR_MOBILE'\r\n\r\n\t\t// Carrier codes may be needed in some countries. We handle this here.\r\n\t\tif (country === 'CO' && number_type === 'FIXED_LINE') {\r\n\t\t\tformatted_number = formatNationalNumberWithCarrierCode(\r\n\t\t\t\tnumber,\r\n\t\t\t\tCOLOMBIA_MOBILE_TO_FIXED_LINE_PREFIX\r\n\t\t\t)\r\n\t\t}\r\n\t\telse if (country == 'BR' && is_fixed_line_or_mobile) {\r\n\t\t\tformatted_number =\r\n\t\t\t\tcarrierCode ?\r\n\t\t\t\tformatNationalNumberWithPreferredCarrierCode(number) :\r\n\t\t\t\t// Brazilian fixed line and mobile numbers need to be dialed with a\r\n\t\t\t\t// carrier code when called within Brazil. Without that, most of the\r\n\t\t\t\t// carriers won't connect the call. Because of that, we return an\r\n\t\t\t\t// empty string here.\r\n\t\t\t\t''\r\n\t\t} else if (getCountryCallingCode(country, metadata.metadata) === '1') {\r\n\t\t\t// For NANPA countries, we output international format for numbers that\r\n\t\t\t// can be dialed internationally, since that always works, except for\r\n\t\t\t// numbers which might potentially be short numbers, which are always\r\n\t\t\t// dialled in national format.\r\n\r\n\t\t\t// Select country for `checkNumberLength()`.\r\n\t\t\tmetadata.country(country)\r\n\r\n\t\t\tif (can_be_internationally_dialled(number) &&\r\n\t\t\t\tcheckNumberLength(number.phone, metadata) !== 'TOO_SHORT') {\r\n\t\t\t\tformatted_number = format(number, 'INTERNATIONAL', metadata.metadata)\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tformatted_number = format(number, 'NATIONAL', metadata.metadata)\r\n\t\t\t}\r\n\t\t}\r\n\t\telse {\r\n\t\t\t// For non-geographic countries, Mexican and Chilean fixed line and\r\n\t\t\t// mobile numbers, we output international format for numbers that can be\r\n\t\t\t// dialed internationally, as that always works.\r\n\t\t\tif (\r\n\t\t\t\t(\r\n\t\t\t\t\tcountry === REGION_CODE_FOR_NON_GEO_ENTITY\r\n\t\t\t\t\t||\r\n\t\t\t\t\t// MX fixed line and mobile numbers should always be formatted in\r\n\t\t\t\t\t// international format, even when dialed within MX. For national\r\n\t\t\t\t\t// format to work, a carrier code needs to be used, and the correct\r\n\t\t\t\t\t// carrier code depends on if the caller and callee are from the\r\n\t\t\t\t\t// same local area. It is trickier to get that to work correctly than\r\n\t\t\t\t\t// using international format, which is tested to work fine on all\r\n\t\t\t\t\t// carriers.\r\n\t\t\t\t\t//\r\n\t\t\t\t\t// CL fixed line numbers need the national prefix when dialing in the\r\n\t\t\t\t\t// national format, but don't have it when used for display. The\r\n\t\t\t\t\t// reverse is true for mobile numbers. As a result, we output them in\r\n\t\t\t\t\t// the international format to make it work.\r\n\t\t\t\t\t//\r\n\t\t\t\t\t// UZ mobile and fixed-line numbers have to be formatted in\r\n\t\t\t\t\t// international format or prefixed with special codes like 03, 04\r\n\t\t\t\t\t// (for fixed-line) and 05 (for mobile) for dialling successfully\r\n\t\t\t\t\t// from mobile devices. As we do not have complete information on\r\n\t\t\t\t\t// special codes and to be consistent with formatting across all\r\n\t\t\t\t\t// phone types we return the number in international format here.\r\n\t\t\t\t\t//\r\n\t\t\t\t\t((country === 'MX' || country === 'CL' || country == 'UZ') && is_fixed_line_or_mobile)\r\n\t\t\t\t)\r\n\t\t\t\t&&\r\n\t\t\t\tcan_be_internationally_dialled(number)\r\n\t\t\t) {\r\n\t\t\t\tformatted_number = format(number, 'INTERNATIONAL')\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tformatted_number = format(number, 'NATIONAL')\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\telse if (is_valid_number && can_be_internationally_dialled(number)) {\r\n\t\t// We assume that short numbers are not diallable from outside their region,\r\n\t\t// so if a number is not a valid regular length phone number, we treat it as\r\n\t\t// if it cannot be internationally dialled.\r\n\t\treturn with_formatting ?\r\n\t\t\tformat(number, 'INTERNATIONAL', metadata.metadata) :\r\n\t\t\tformat(number, 'E.164', metadata.metadata)\r\n\t}\r\n\r\n\tif (!with_formatting) {\r\n\t\treturn diallable_chars(formatted_number)\r\n\t}\r\n\r\n\treturn formatted_number\r\n}\r\n\r\nfunction can_be_internationally_dialled(number) {\r\n\treturn true\r\n}\r\n\r\n/**\r\n * A map that contains characters that are essential when dialling. That means\r\n * any of the characters in this map must not be removed from a number when\r\n * dialling, otherwise the call will not reach the intended destination.\r\n */\r\nconst DIALLABLE_CHARACTERS = {\r\n\t'0': '0',\r\n\t'1': '1',\r\n\t'2': '2',\r\n\t'3': '3',\r\n\t'4': '4',\r\n\t'5': '5',\r\n\t'6': '6',\r\n\t'7': '7',\r\n\t'8': '8',\r\n\t'9': '9',\r\n\t'+': '+',\r\n\t'*': '*',\r\n\t'#': '#'\r\n}\r\n\r\nfunction diallable_chars(formatted_number) {\r\n\tlet result = ''\r\n\r\n\tlet i = 0\r\n\twhile (i < formatted_number.length) {\r\n\t\tconst character = formatted_number[i]\r\n\t\tif (DIALLABLE_CHARACTERS[character]) {\r\n\t\t\tresult += character\r\n\t\t}\r\n\t\ti++\r\n\t}\r\n\r\n\treturn result\r\n}\r\n\r\nfunction getPreferredDomesticCarrierCodeOrDefault() {\r\n\tthrow new Error('carrier codes are not part of this library')\r\n}\r\n\r\nfunction formatNationalNumberWithCarrierCode() {\r\n\tthrow new Error('carrier codes are not part of this library')\r\n}\r\n\r\n/**\r\n * Formats a phone number in national format for dialing using the carrier as\r\n * specified in the preferred_domestic_carrier_code field of the PhoneNumber\r\n * object passed in. If that is missing, use the {@code fallbackCarrierCode}\r\n * passed in instead. If there is no {@code preferred_domestic_carrier_code},\r\n * and the {@code fallbackCarrierCode} contains an empty string, return the\r\n * number in national format without any carrier code.\r\n *\r\n * <p>Use {@link #formatNationalNumberWithCarrierCode} instead if the carrier\r\n * code passed in should take precedence over the number's\r\n * {@code preferred_domestic_carrier_code} when formatting.\r\n *\r\n * @param {i18n.phonenumbers.PhoneNumber} number the phone number to be\r\n * formatted.\r\n * @param {string} fallbackCarrierCode the carrier selection code to be used, if\r\n * none is found in the phone number itself.\r\n * @return {string} the formatted phone number in national format for dialing\r\n * using the number's preferred_domestic_carrier_code, or the\r\n * {@code fallbackCarrierCode} passed in if none is found.\r\n */\r\nfunction formatNationalNumberWithPreferredCarrierCode(number) {\r\n\treturn formatNationalNumberWithCarrierCode(\r\n\t\tnumber,\r\n\t\tcarrierCode\r\n\t);\r\n}"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAEA,OAAOA,QAAP,MAAqB,eAArB;AACA,OAAOC,MAAP,MAAmB,aAAnB;AACA,OAAOC,aAAP,MAA0B,4BAA1B;AACA,OAAOC,iBAAP,MAA8B,gCAA9B;AACA,OAAOC,qBAAP,MAAkC,4BAAlC;AAEA,IAAMC,8BAA8B,GAAG,KAAvC;AAEA;AACA;AACA;AACA;;AACA,IAAMC,oCAAoC,GAAG,GAA7C;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,UAASC,MAAT,EAAiBC,YAAjB,EAA+BC,eAA/B,EAAgDC,QAAhD,EAA0D;EACxEA,QAAQ,GAAG,IAAIV,QAAJ,CAAaU,QAAb,CAAX,CADwE,CAGxE;;EACA,IAAI,CAACA,QAAQ,CAAC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EAW5B,KAAK,GAXuB;EAY5B,KAAK,GAZuB;EAa5B,KAAK;AAbuB,CAA7B;;AAgBA,SAASD,eAAT,CAAyBN,gBAAzB,EAA2C;EAC1C,IAAIQ,MAAM,GAAG,EAAb;EAEA,IAAIC,CAAC,GAAG,CAAR;;EACA,OAAOA,CAAC,GAAGT,gBAAgB,CAACU,MAA5B,EAAoC;IACnC,IAAMC,SAAS,GAAGX,gBAAgB,CAACS,CAAD,CAAlC;;IACA,IAAIF,oBAAoB,CAACI,SAAD,CAAxB,EAAqC;MACpCH,MAAM,IAAIG,SAAV;IACA;;IACDF,CAAC;EACD;;EAED,OAAOD,MAAP;AACA;;AAED,SAASI,wCAAT,GAAoD;EACnD,MAAM,IAAIlB,KAAJ,CAAU,4CAAV,CAAN;AACA;;AAED,SAASQ,mCAAT,GAA+C;EAC9C,MAAM,IAAIR,KAAJ,CAAU,4CAAV,CAAN;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASU,4CAAT,CAAsDf,MAAtD,EAA8D;EAC7D,OAAOa,mCAAmC,CACzCb,MADyC,EAEzCc,WAFyC,CAA1C;AAIA"}
1
+ {"version":3,"file":"formatPhoneNumberForMobileDialing.js","names":["Metadata","format","getNumberType","checkNumberLength","getCountryCallingCode","REGION_CODE_FOR_NON_GEO_ENTITY","number","from_country","with_formatting","metadata","hasCountry","Error","phone","country","number_type","undefined","is_valid_number","formatted_number","is_fixed_line_or_mobile","carrierCode","formatNationalNumberWithPreferredCarrierCode","can_be_internationally_dialled","diallable_chars","DIALLABLE_CHARACTERS","result","i","length","character","getPreferredDomesticCarrierCodeOrDefault","formatNationalNumberWithCarrierCode"],"sources":["../source/formatPhoneNumberForMobileDialing.js"],"sourcesContent":["// This function is copy-pasted from\r\n// https://github.com/googlei18n/libphonenumber/blob/master/javascript/i18n/phonenumbers/phonenumberutil.js\r\n// It hasn't been tested. It's not currently exported.\r\n// Carriers codes aren't part of this library.\r\n// Send a PR if you want to add them.\r\n\r\nimport Metadata from './metadata.js'\r\nimport format from './format.js'\r\nimport getNumberType from './helpers/getNumberType.js'\r\nimport checkNumberLength from './helpers/checkNumberLength.js'\r\nimport getCountryCallingCode from './getCountryCallingCode.js'\r\n\r\nconst REGION_CODE_FOR_NON_GEO_ENTITY = '001'\r\n\r\n/**\r\n * Returns a number formatted in such a way that it can be dialed from a mobile\r\n * phone in a specific region. If the number cannot be reached from the region\r\n * (e.g. some countries block toll-free numbers from being called outside of the\r\n * country), the method returns an empty string.\r\n *\r\n * @param {object} number - a `parse()`d phone number to be formatted.\r\n * @param {string} from_country - the region where the call is being placed.\r\n * @param {boolean} with_formatting - whether the number should be returned with\r\n * formatting symbols, such as spaces and dashes.\r\n * @return {string}\r\n */\r\nexport default function(number, from_country, with_formatting, metadata) {\r\n\tmetadata = new Metadata(metadata)\r\n\r\n\t// Validate `from_country`.\r\n\tif (!metadata.hasCountry(from_country)) {\r\n\t\tthrow new Error(`Unknown country: ${from_country}`)\r\n\t}\r\n\r\n\t// Not using the extension, as that part cannot normally be dialed\r\n\t// together with the main number.\r\n\tnumber = {\r\n\t\tphone: number.phone,\r\n\t\tcountry: number.country\r\n\t}\r\n\r\n\tconst number_type = getNumberType(number, undefined, metadata.metadata)\r\n\tconst is_valid_number = number_type === number\r\n\r\n\tlet formatted_number\r\n\r\n\tif (country === from_country) {\r\n\t\tconst is_fixed_line_or_mobile =\r\n\t\t\tnumber_type === 'FIXED_LINE' ||\r\n\t\t\tnumber_type === 'MOBILE' ||\r\n\t\t\tnumber_type === 'FIXED_LINE_OR_MOBILE'\r\n\r\n\t\t// Carrier codes may be needed in some countries. We handle this here.\r\n\t\tif (country == 'BR' && is_fixed_line_or_mobile) {\r\n\t\t\tformatted_number =\r\n\t\t\t\tcarrierCode ?\r\n\t\t\t\tformatNationalNumberWithPreferredCarrierCode(number) :\r\n\t\t\t\t// Brazilian fixed line and mobile numbers need to be dialed with a\r\n\t\t\t\t// carrier code when called within Brazil. Without that, most of the\r\n\t\t\t\t// carriers won't connect the call. Because of that, we return an\r\n\t\t\t\t// empty string here.\r\n\t\t\t\t''\r\n\t\t} else if (getCountryCallingCode(country, metadata.metadata) === '1') {\r\n\t\t\t// For NANPA countries, we output international format for numbers that\r\n\t\t\t// can be dialed internationally, since that always works, except for\r\n\t\t\t// numbers which might potentially be short numbers, which are always\r\n\t\t\t// dialled in national format.\r\n\r\n\t\t\t// Select country for `checkNumberLength()`.\r\n\t\t\tmetadata.country(country)\r\n\r\n\t\t\tif (can_be_internationally_dialled(number) &&\r\n\t\t\t\tcheckNumberLength(number.phone, metadata) !== 'TOO_SHORT') {\r\n\t\t\t\tformatted_number = format(number, 'INTERNATIONAL', metadata.metadata)\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tformatted_number = format(number, 'NATIONAL', metadata.metadata)\r\n\t\t\t}\r\n\t\t}\r\n\t\telse {\r\n\t\t\t// For non-geographic countries, Mexican and Chilean fixed line and\r\n\t\t\t// mobile numbers, we output international format for numbers that can be\r\n\t\t\t// dialed internationally, as that always works.\r\n\t\t\tif (\r\n\t\t\t\t(\r\n\t\t\t\t\tcountry === REGION_CODE_FOR_NON_GEO_ENTITY\r\n\t\t\t\t\t||\r\n\t\t\t\t\t// MX fixed line and mobile numbers should always be formatted in\r\n\t\t\t\t\t// international format, even when dialed within MX. For national\r\n\t\t\t\t\t// format to work, a carrier code needs to be used, and the correct\r\n\t\t\t\t\t// carrier code depends on if the caller and callee are from the\r\n\t\t\t\t\t// same local area. It is trickier to get that to work correctly than\r\n\t\t\t\t\t// using international format, which is tested to work fine on all\r\n\t\t\t\t\t// carriers.\r\n\t\t\t\t\t//\r\n\t\t\t\t\t// CL fixed line numbers need the national prefix when dialing in the\r\n\t\t\t\t\t// national format, but don't have it when used for display. The\r\n\t\t\t\t\t// reverse is true for mobile numbers. As a result, we output them in\r\n\t\t\t\t\t// the international format to make it work.\r\n\t\t\t\t\t//\r\n\t\t\t\t\t// UZ mobile and fixed-line numbers have to be formatted in\r\n\t\t\t\t\t// international format or prefixed with special codes like 03, 04\r\n\t\t\t\t\t// (for fixed-line) and 05 (for mobile) for dialling successfully\r\n\t\t\t\t\t// from mobile devices. As we do not have complete information on\r\n\t\t\t\t\t// special codes and to be consistent with formatting across all\r\n\t\t\t\t\t// phone types we return the number in international format here.\r\n\t\t\t\t\t//\r\n\t\t\t\t\t((country === 'MX' || country === 'CL' || country == 'UZ') && is_fixed_line_or_mobile)\r\n\t\t\t\t)\r\n\t\t\t\t&&\r\n\t\t\t\tcan_be_internationally_dialled(number)\r\n\t\t\t) {\r\n\t\t\t\tformatted_number = format(number, 'INTERNATIONAL')\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tformatted_number = format(number, 'NATIONAL')\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\telse if (is_valid_number && can_be_internationally_dialled(number)) {\r\n\t\t// We assume that short numbers are not diallable from outside their region,\r\n\t\t// so if a number is not a valid regular length phone number, we treat it as\r\n\t\t// if it cannot be internationally dialled.\r\n\t\treturn with_formatting ?\r\n\t\t\tformat(number, 'INTERNATIONAL', metadata.metadata) :\r\n\t\t\tformat(number, 'E.164', metadata.metadata)\r\n\t}\r\n\r\n\tif (!with_formatting) {\r\n\t\treturn diallable_chars(formatted_number)\r\n\t}\r\n\r\n\treturn formatted_number\r\n}\r\n\r\nfunction can_be_internationally_dialled(number) {\r\n\treturn true\r\n}\r\n\r\n/**\r\n * A map that contains characters that are essential when dialling. That means\r\n * any of the characters in this map must not be removed from a number when\r\n * dialling, otherwise the call will not reach the intended destination.\r\n */\r\nconst DIALLABLE_CHARACTERS = {\r\n\t'0': '0',\r\n\t'1': '1',\r\n\t'2': '2',\r\n\t'3': '3',\r\n\t'4': '4',\r\n\t'5': '5',\r\n\t'6': '6',\r\n\t'7': '7',\r\n\t'8': '8',\r\n\t'9': '9',\r\n\t'+': '+',\r\n\t'*': '*',\r\n\t'#': '#'\r\n}\r\n\r\nfunction diallable_chars(formatted_number) {\r\n\tlet result = ''\r\n\r\n\tlet i = 0\r\n\twhile (i < formatted_number.length) {\r\n\t\tconst character = formatted_number[i]\r\n\t\tif (DIALLABLE_CHARACTERS[character]) {\r\n\t\t\tresult += character\r\n\t\t}\r\n\t\ti++\r\n\t}\r\n\r\n\treturn result\r\n}\r\n\r\nfunction getPreferredDomesticCarrierCodeOrDefault() {\r\n\tthrow new Error('carrier codes are not part of this library')\r\n}\r\n\r\nfunction formatNationalNumberWithCarrierCode() {\r\n\tthrow new Error('carrier codes are not part of this library')\r\n}\r\n\r\n/**\r\n * Formats a phone number in national format for dialing using the carrier as\r\n * specified in the preferred_domestic_carrier_code field of the PhoneNumber\r\n * object passed in. If that is missing, use the {@code fallbackCarrierCode}\r\n * passed in instead. If there is no {@code preferred_domestic_carrier_code},\r\n * and the {@code fallbackCarrierCode} contains an empty string, return the\r\n * number in national format without any carrier code.\r\n *\r\n * <p>Use {@link #formatNationalNumberWithCarrierCode} instead if the carrier\r\n * code passed in should take precedence over the number's\r\n * {@code preferred_domestic_carrier_code} when formatting.\r\n *\r\n * @param {i18n.phonenumbers.PhoneNumber} number the phone number to be\r\n * formatted.\r\n * @param {string} fallbackCarrierCode the carrier selection code to be used, if\r\n * none is found in the phone number itself.\r\n * @return {string} the formatted phone number in national format for dialing\r\n * using the number's preferred_domestic_carrier_code, or the\r\n * {@code fallbackCarrierCode} passed in if none is found.\r\n */\r\nfunction formatNationalNumberWithPreferredCarrierCode(number) {\r\n\treturn formatNationalNumberWithCarrierCode(\r\n\t\tnumber,\r\n\t\tcarrierCode\r\n\t);\r\n}"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAEA,OAAOA,QAAP,MAAqB,eAArB;AACA,OAAOC,MAAP,MAAmB,aAAnB;AACA,OAAOC,aAAP,MAA0B,4BAA1B;AACA,OAAOC,iBAAP,MAA8B,gCAA9B;AACA,OAAOC,qBAAP,MAAkC,4BAAlC;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;EAK5B,KAAK,GALuB;EAM5B,KAAK,GANuB;EAO5B,KAAK,GAPuB;EAQ5B,KAAK,GARuB;EAS5B,KAAK,GATuB;EAU5B,KAAK,GAVuB;EAW5B,KAAK,GAXuB;EAY5B,KAAK,GAZuB;EAa5B,KAAK;AAbuB,CAA7B;;AAgBA,SAASD,eAAT,CAAyBL,gBAAzB,EAA2C;EAC1C,IAAIO,MAAM,GAAG,EAAb;EAEA,IAAIC,CAAC,GAAG,CAAR;;EACA,OAAOA,CAAC,GAAGR,gBAAgB,CAACS,MAA5B,EAAoC;IACnC,IAAMC,SAAS,GAAGV,gBAAgB,CAACQ,CAAD,CAAlC;;IACA,IAAIF,oBAAoB,CAACI,SAAD,CAAxB,EAAqC;MACpCH,MAAM,IAAIG,SAAV;IACA;;IACDF,CAAC;EACD;;EAED,OAAOD,MAAP;AACA;;AAED,SAASI,wCAAT,GAAoD;EACnD,MAAM,IAAIjB,KAAJ,CAAU,4CAAV,CAAN;AACA;;AAED,SAASkB,mCAAT,GAA+C;EAC9C,MAAM,IAAIlB,KAAJ,CAAU,4CAAV,CAAN;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASS,4CAAT,CAAsDd,MAAtD,EAA8D;EAC7D,OAAOuB,mCAAmC,CACzCvB,MADyC,EAEzCa,WAFyC,CAA1C;AAIA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libphonenumber-js",
3
- "version": "1.10.22",
3
+ "version": "1.10.23",
4
4
  "description": "A simpler (and smaller) rewrite of Google Android's libphonenumber library in javascript",
5
5
  "main": "index.cjs",
6
6
  "module": "index.js",
@@ -12,12 +12,6 @@ import getCountryCallingCode from './getCountryCallingCode.js'
12
12
 
13
13
  const REGION_CODE_FOR_NON_GEO_ENTITY = '001'
14
14
 
15
- /**
16
- * The prefix that needs to be inserted in front of a Colombian landline number
17
- * when dialed from a mobile phone in Colombia.
18
- */
19
- const COLOMBIA_MOBILE_TO_FIXED_LINE_PREFIX = '3'
20
-
21
15
  /**
22
16
  * Returns a number formatted in such a way that it can be dialed from a mobile
23
17
  * phone in a specific region. If the number cannot be reached from the region
@@ -57,13 +51,7 @@ export default function(number, from_country, with_formatting, metadata) {
57
51
  number_type === 'FIXED_LINE_OR_MOBILE'
58
52
 
59
53
  // Carrier codes may be needed in some countries. We handle this here.
60
- if (country === 'CO' && number_type === 'FIXED_LINE') {
61
- formatted_number = formatNationalNumberWithCarrierCode(
62
- number,
63
- COLOMBIA_MOBILE_TO_FIXED_LINE_PREFIX
64
- )
65
- }
66
- else if (country == 'BR' && is_fixed_line_or_mobile) {
54
+ if (country == 'BR' && is_fixed_line_or_mobile) {
67
55
  formatted_number =
68
56
  carrierCode ?
69
57
  formatNationalNumberWithPreferredCarrierCode(number) :
package/types.d.ts CHANGED
@@ -1,17 +1,18 @@
1
- import metadata from './metadata.min.json'
2
-
3
- // Reads the list of ISO country codes from the JSON file.
4
- // https://github.com/catamphetamine/libphonenumber-js/issues/405#issuecomment-1447027961
5
- const getObjectKeys = Object.keys as <T>(object: T) => Array<keyof T>
6
- const CountryCodes = getObjectKeys(metadata.countries)
7
-
8
1
  // The rationale for having a separate `CountryCode` type instead of just a `string`:
9
2
  // https://github.com/catamphetamine/libphonenumber-js/issues/170#issuecomment-363156068
10
- // export type CountryCode = 'AC' | 'AD' | 'AE' | 'AF' | 'AG' | 'AI' | 'AL' | 'AM' | 'AO' | 'AR' | 'AS' | 'AT' | 'AU' | 'AW' | 'AX' | 'AZ' | 'BA' | 'BB' | 'BD' | 'BE' | 'BF' | 'BG' | 'BH' | 'BI' | 'BJ' | 'BL' | 'BM' | 'BN' | 'BO' | 'BQ' | 'BR' | 'BS' | 'BT' | 'BW' | 'BY' | 'BZ' | 'CA' | 'CC' | 'CD' | 'CF' | 'CG' | 'CH' | 'CI' | 'CK' | 'CL' | 'CM' | 'CN' | 'CO' | 'CR' | 'CU' | 'CV' | 'CW' | 'CX' | 'CY' | 'CZ' | 'DE' | 'DJ' | 'DK' | 'DM' | 'DO' | 'DZ' | 'EC' | 'EE' | 'EG' | 'EH' | 'ER' | 'ES' | 'ET' | 'FI' | 'FJ' | 'FK' | 'FM' | 'FO' | 'FR' | 'GA' | 'GB' | 'GD' | 'GE' | 'GF' | 'GG' | 'GH' | 'GI' | 'GL' | 'GM' | 'GN' | 'GP' | 'GQ' | 'GR' | 'GT' | 'GU' | 'GW' | 'GY' | 'HK' | 'HN' | 'HR' | 'HT' | 'HU' | 'ID' | 'IE' | 'IL' | 'IM' | 'IN' | 'IO' | 'IQ' | 'IR' | 'IS' | 'IT' | 'JE' | 'JM' | 'JO' | 'JP' | 'KE' | 'KG' | 'KH' | 'KI' | 'KM' | 'KN' | 'KP' | 'KR' | 'KW' | 'KY' | 'KZ' | 'LA' | 'LB' | 'LC' | 'LI' | 'LK' | 'LR' | 'LS' | 'LT' | 'LU' | 'LV' | 'LY' | 'MA' | 'MC' | 'MD' | 'ME' | 'MF' | 'MG' | 'MH' | 'MK' | 'ML' | 'MM' | 'MN' | 'MO' | 'MP' | 'MQ' | 'MR' | 'MS' | 'MT' | 'MU' | 'MV' | 'MW' | 'MX' | 'MY' | 'MZ' | 'NA' | 'NC' | 'NE' | 'NF' | 'NG' | 'NI' | 'NL' | 'NO' | 'NP' | 'NR' | 'NU' | 'NZ' | 'OM' | 'PA' | 'PE' | 'PF' | 'PG' | 'PH' | 'PK' | 'PL' | 'PM' | 'PR' | 'PS' | 'PT' | 'PW' | 'PY' | 'QA' | 'RE' | 'RO' | 'RS' | 'RU' | 'RW' | 'SA' | 'SB' | 'SC' | 'SD' | 'SE' | 'SG' | 'SH' | 'SI' | 'SJ' | 'SK' | 'SL' | 'SM' | 'SN' | 'SO' | 'SR' | 'SS' | 'ST' | 'SV' | 'SX' | 'SY' | 'SZ' | 'TA' | 'TC' | 'TD' | 'TG' | 'TH' | 'TJ' | 'TK' | 'TL' | 'TM' | 'TN' | 'TO' | 'TR' | 'TT' | 'TV' | 'TW' | 'TZ' | 'UA' | 'UG' | 'US' | 'UY' | 'UZ' | 'VA' | 'VC' | 'VE' | 'VG' | 'VI' | 'VN' | 'VU' | 'WF' | 'WS' | 'XK' | 'YE' | 'YT' | 'ZA' | 'ZM' | 'ZW';
3
+ export type CountryCode = 'AC' | 'AD' | 'AE' | 'AF' | 'AG' | 'AI' | 'AL' | 'AM' | 'AO' | 'AR' | 'AS' | 'AT' | 'AU' | 'AW' | 'AX' | 'AZ' | 'BA' | 'BB' | 'BD' | 'BE' | 'BF' | 'BG' | 'BH' | 'BI' | 'BJ' | 'BL' | 'BM' | 'BN' | 'BO' | 'BQ' | 'BR' | 'BS' | 'BT' | 'BW' | 'BY' | 'BZ' | 'CA' | 'CC' | 'CD' | 'CF' | 'CG' | 'CH' | 'CI' | 'CK' | 'CL' | 'CM' | 'CN' | 'CO' | 'CR' | 'CU' | 'CV' | 'CW' | 'CX' | 'CY' | 'CZ' | 'DE' | 'DJ' | 'DK' | 'DM' | 'DO' | 'DZ' | 'EC' | 'EE' | 'EG' | 'EH' | 'ER' | 'ES' | 'ET' | 'FI' | 'FJ' | 'FK' | 'FM' | 'FO' | 'FR' | 'GA' | 'GB' | 'GD' | 'GE' | 'GF' | 'GG' | 'GH' | 'GI' | 'GL' | 'GM' | 'GN' | 'GP' | 'GQ' | 'GR' | 'GT' | 'GU' | 'GW' | 'GY' | 'HK' | 'HN' | 'HR' | 'HT' | 'HU' | 'ID' | 'IE' | 'IL' | 'IM' | 'IN' | 'IO' | 'IQ' | 'IR' | 'IS' | 'IT' | 'JE' | 'JM' | 'JO' | 'JP' | 'KE' | 'KG' | 'KH' | 'KI' | 'KM' | 'KN' | 'KP' | 'KR' | 'KW' | 'KY' | 'KZ' | 'LA' | 'LB' | 'LC' | 'LI' | 'LK' | 'LR' | 'LS' | 'LT' | 'LU' | 'LV' | 'LY' | 'MA' | 'MC' | 'MD' | 'ME' | 'MF' | 'MG' | 'MH' | 'MK' | 'ML' | 'MM' | 'MN' | 'MO' | 'MP' | 'MQ' | 'MR' | 'MS' | 'MT' | 'MU' | 'MV' | 'MW' | 'MX' | 'MY' | 'MZ' | 'NA' | 'NC' | 'NE' | 'NF' | 'NG' | 'NI' | 'NL' | 'NO' | 'NP' | 'NR' | 'NU' | 'NZ' | 'OM' | 'PA' | 'PE' | 'PF' | 'PG' | 'PH' | 'PK' | 'PL' | 'PM' | 'PR' | 'PS' | 'PT' | 'PW' | 'PY' | 'QA' | 'RE' | 'RO' | 'RS' | 'RU' | 'RW' | 'SA' | 'SB' | 'SC' | 'SD' | 'SE' | 'SG' | 'SH' | 'SI' | 'SJ' | 'SK' | 'SL' | 'SM' | 'SN' | 'SO' | 'SR' | 'SS' | 'ST' | 'SV' | 'SX' | 'SY' | 'SZ' | 'TA' | 'TC' | 'TD' | 'TG' | 'TH' | 'TJ' | 'TK' | 'TL' | 'TM' | 'TN' | 'TO' | 'TR' | 'TT' | 'TV' | 'TW' | 'TZ' | 'UA' | 'UG' | 'US' | 'UY' | 'UZ' | 'VA' | 'VC' | 'VE' | 'VG' | 'VI' | 'VN' | 'VU' | 'WF' | 'WS' | 'XK' | 'YE' | 'YT' | 'ZA' | 'ZM' | 'ZW';
4
+
5
+ // Seems like it doesn't work for some reason:
6
+ // https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/94
11
7
  //
12
- // The `CountryCode` type is generated from the list of `CountryCodes`.
13
- // https://github.com/catamphetamine/libphonenumber-js/issues/405
14
- export type CountryCode = typeof CountryCodes[number];
8
+ // import metadata from './metadata.min.json'
9
+ // // Reads the list of ISO country codes from the JSON file.
10
+ // // https://github.com/catamphetamine/libphonenumber-js/issues/405#issuecomment-1447027961
11
+ // const getObjectKeys = Object.keys as <T>(object: T) => Array<keyof T>
12
+ // const CountryCodes = getObjectKeys(metadata.countries)
13
+ // // The `CountryCode` type is generated from the list of `CountryCodes`.
14
+ // // https://github.com/catamphetamine/libphonenumber-js/issues/405
15
+ // export type CountryCode = typeof CountryCodes[number];
15
16
 
16
17
  export type CountryCallingCodes = {
17
18
  [countryCallingCode: string]: CountryCode[];