{"version":3,"sources":["../../source/tools/generate.js"],"names":["parseString","DIGIT_PLACEHOLDER","phone_number_types","input","version","included_countries","extended","included_phone_number_types","_type","indexOf","Promise","reject","parseStringPromisified","then","xml","country_calling_code_to_countries","countries","nonGeographic","territory","country_code","$","id","has","nationalPrefixOptionalWhenFormatting","Error","country","phone_code","countryCode","idd_prefix","internationalPrefix","default_idd_prefix","preferredInternationalPrefix","ext","preferredExtnPrefix","leading_digits","leadingDigits","national_number_pattern","generalDesc","nationalNumberPattern","replace","national_prefix","nationalPrefix","national_prefix_for_parsing","nationalPrefixForParsing","undefined","national_prefix_transform_rule","nationalPrefixTransformRule","national_prefix_formatting_rule","getNationalPrefixFormattingRule","nationalPrefixFormattingRule","types","get_phone_number_types","examples","get_phone_number_examples","availableFormats","formats","numberFormat","map","number_format","pattern","leading_digits_patterns","national_prefix_is_optional_when_formatting","Boolean","format","international_format","intlFormat","filter","populateNumberingPlanPossibleLengths","mainCountryForCode","unshift","push","phoneNumberMetadata","territories","Object","keys","main_country_for_region_code","visited_countries","country_calling_code","country_codes","possible_lengths","length","all_types_required","fixed_line","mobile","country_calling_codes","rule","reduce","output","type","camel_cased_type","underscoreToCamelCase","possibleLengths","national","possible_lengths_local","localOnly","example","exampleNumber","string","match","toUpperCase","parse_possible_lengths","possible_length_string","TypeError","lengths","Set","split","min_max","slice","_","parseInt","min","max","i","add","arrays_are_equal","a1","a2","every","metadata","type_possible_lengths","Array","from","type_possible_lengths_local","sort","a","b","size","resolve","error","result"],"mappings":";;;;;;;;AAAA,SAASA,WAAT,QAA4B,QAA5B;AAEA,SAASC,iBAAT,QAAkC,cAAlC,C,CACA;;AAEA,IAAMC,kBAAkB,GACxB,CACC,cADD,EAEC,WAFD,EAGC,aAHD,EAIC,MAJD,EAKC,iBALD,EAMC,OAND,EAOC,KAPD,EAQC,YARD,EASC,YATD,EAUC,QAVD,CADA,C,CAcA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,UAASC,KAAT,EAAgBC,OAAhB,EAAyBC,kBAAzB,EAA6CC,QAA7C,EAAuDC,2BAAvD,EACf;AACC;AACA,MAAIA,2BAAJ,EACA;AACC,yBAAoBA,2BAApB,kHACA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA,UADWC,KACX;;AACC,UAAIN,kBAAkB,CAACO,OAAnB,CAA2BD,KAA3B,IAAoC,CAAxC,EACA;AACC,eAAOE,OAAO,CAACC,MAAR,sCAA6CH,KAA7C,EAAP;AACA;AACD;AACD,GAXF,CAaC;AACA;;;AACA,SAAOI,sBAAsB,CAACT,KAAD,CAAtB,CAA8BU,IAA9B,CAAmC,UAACC,GAAD,EAC1C;AACC;AACA;AACA;AACA;AAEA,QAAMC,iCAAiC,GAAG,EAA1C;AACA,QAAMC,SAAS,GAAG,EAAlB;AACA,QAAMC,aAAa,GAAG,EAAtB;;AARD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA,UAUYC,SAVZ;AAYE;AACA,UAA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QAAI7B,KAAK,CAAC1C,MAAD,CAAL,CAAaqF,sBAAb,IAAuCyB,QAAQ,CAACzB,sBAAhD,IACHqB,gBAAgB,CAAChE,KAAK,CAAC1C,MAAD,CAAL,CAAaqF,sBAAd,EAAsCyB,QAAQ,CAACzB,sBAA/C,CADjB,EAEA;AACC,aAAO3C,KAAK,CAAC1C,MAAD,CAAL,CAAaqF,sBAApB;AACA;AACD;AACD;;AAED,SAASjF,sBAAT,CAAgCT,KAAhC,EAAuC;AACtC,SAAO,IAAIO,OAAJ,CAAY,UAACqH,OAAD,EAAUpH,MAAV,EAAqB;AACvCX,IAAAA,WAAW,CAACG,KAAD,EAAQ,UAAC6H,KAAD,EAAQC,MAAR,EAAmB;AACrC,UAAID,KAAJ,EAAW;AACV,eAAOrH,MAAM,CAACqH,KAAD,CAAb;AACA;;AACDD,MAAAA,OAAO,CAACE,MAAD,CAAP;AACA,KALU,CAAX;AAMA,GAPM,CAAP;AAQA","sourcesContent":["import { parseString } from 'xml2js'\r\n\r\nimport { DIGIT_PLACEHOLDER } from '../AsYouType'\r\n// import { isSingleIDDPrefix } from '../IDD'\r\n\r\nconst phone_number_types =\r\n[\r\n\t'premium_rate',\r\n\t'toll_free',\r\n\t'shared_cost',\r\n\t'voip',\r\n\t'personal_number',\r\n\t'pager',\r\n\t'uan',\r\n\t'voice_mail',\r\n\t'fixed_line',\r\n\t'mobile'\r\n]\r\n\r\n// Excessive fields from \"PhoneNumberMetadata.xml\"\r\n// aren't included to reduce code complexity and size:\r\n//\r\n// * `` — a link to ITU (International Telecommunication Union)\r\n// document describing phone numbering plan for a country\r\n//\r\n// * `` — who needs to input non-internationally-dialable phones\r\n//\r\n// * `` — we aren't in the XXth century,\r\n// it's a globalized world, so write your\r\n// phone numbers with area codes.\r\n//\r\n// * ``, ``, ``,\r\n// ``, ``,\r\n// ``, ``,\r\n// ``, ``, `` — who needs that in the XXIst century.\r\n// just go mobile and stop talking nonsense.\r\n//\r\n// * `internationalPrefix`,\r\n// `preferredInternationalPrefix` — who needs to parse (or format) those weird\r\n// \"internationally dialed\" phone numbers\r\n// like \"011 ...\" in the USA.\r\n// this isn't XXth century, just use mobile phones.\r\n//\r\n// * `preferredExtnPrefix` — Localized \" ext. \". E.g. \", доб. \" instead of \" ext. \" for Russia.\r\n//\r\n// * `leadingZeroPossible` — (aka \"italian leading zero\")\r\n// who needs to parse a phone number into an integer.\r\n// just keep it as a string.\r\n//\r\n// * `carrierCodeFormattingRule` — only used in Brazil and Colombia\r\n// when dialing from within those countries\r\n// from mobile phones to fixed line phone numbers.\r\n// i guess brazilians and colombians\r\n// already know when to add those carrier codes\r\n// by themselves (and when not to add them)\r\n//\r\n// * `mobileNumberPortableRegion` — is only used to disable phone number type detection\r\n//\r\n// * `` — is a redundant field to speed up testing of\r\n// whether a phone number format can be used to format\r\n// a particular national (significant) phone number.\r\n//\r\n// `libphonenumber/BuildMetadataFromXml.java` was used as a reference.\r\n// https://github.com/googlei18n/libphonenumber/blob/master/tools/java/common/src/com/google/i18n/phonenumbers/BuildMetadataFromXml.java\r\n//\r\n// There are three Xml metadata files in Google's `libphonenumber`:\r\n//\r\n// * PhoneNumberMetadata.xml — core data, used both for parse/format and \"as you type\"\r\n//\r\n// * PhoneNumberAlternateFormats.xml — alternative phone number formats.\r\n// is presumably used for parsing phone numbers\r\n// written in \"alternative\" formats.\r\n// is not used by \"as you type\"\r\n// presumably because of formats ambiguity\r\n// when combined with the core data.\r\n// this metadata is not used in this library\r\n// as there's no clear description on what to do with it\r\n// and how it works in the original `libphonenumber` code.\r\n//\r\n// * ShortNumberMetadata.xml — emergency numbers, etc. not used in this library.\r\n//\r\n// @returns\r\n//\r\n// {\r\n// \tcountry_calling_codes:\r\n// \t{\r\n// \t\t'7': ['RU', 'KZ', ...],\r\n// \t\t...\r\n// \t},\r\n// \tcountries:\r\n// \t{\r\n// \t\tRU:\r\n// \t\t{\r\n// \t\t\tphone_code: \"7\",\r\n// \t\t\tnational_number_pattern: \"[347-9]\\\\d{9}\",\r\n// \t\t\tnational_prefix: \"8\",\r\n// \t\t\tnational_prefix_formatting_rule: \"8 ($1)\",\r\n// \t\t\tnational_prefix_is_optional_when_formatting: true,\r\n// \t\t\ttypes:\r\n// \t\t\t{\r\n// \t\t\t\tfixed_line: \"(?:3(?:0[12]|4[1-35-79]|5[1-3]|65|8[1-58]|9[0145])|4(?:01|1[1356]|2[13467]|7[1-5]|8[1-7]|9[1-689])|8(?:1[1-8]|2[01]|3[13-6]|4[0-8]|5[15]|6[1-35-79]|7[1-37-9]))\\\\d{7}\",\r\n// \t\t\t\tmobile: \"9\\\\d{9}\",\r\n// \t\t\t\t...\r\n// \t\t\t},\r\n// \t\t\texamples:\r\n// \t\t\t{\r\n// \t\t\t\tfixed_line: '4955553535',\r\n// \t\t\t\tmobile: '9991234567',\r\n// \t\t\t\t...\r\n// \t\t\t},\r\n// \t\t\tformats:\r\n// \t\t\t[{\r\n// \t\t\t\tpattern: \"([3489]\\\\d{2})(\\\\d{3})(\\\\d{2})(\\\\d{2})\",\r\n// \t\t\t\tleading_digits_patterns: [\"[3489]\"],\r\n// \t\t\t\tformat: \"$1 $2-$3-$4\"\r\n// \t\t\t},\r\n// \t\t\t...]\r\n// \t\t},\r\n// \t\t...\r\n// \t}\r\n// }\r\n//\r\n// `country_calling_codes` map is kinda redundant.\r\n// Not sure why did I choose to place country phone codes\r\n// into a separate structure inside metadata instead of generating it in runtime.\r\n// One extra feature it gives though is it tells what's the\r\n// \"default\" country for a given country phone code.\r\n// E.g. for country phone code `1` the \"default\" country is \"US\"\r\n// and therefore \"US\" is the first country code in the\r\n// `country_calling_codes[\"1\"]` list.\r\n// The \"default\" country is the one other countries\r\n// with the same country phone code inherit phone number formatting rules from.\r\n// For example, \"CA\" (Canada) inhertis phone number formatting rules from \"US\".\r\n//\r\n// `country_calling_codes` data takes about 3 KiloBytes\r\n// so it could kinda make sense to drop it from the metadata file\r\n// replacing it with a \"default\" country flag (something like `1` for \"yes\").\r\n// In that scenario `country_calling_codes` would be generated on startup.\r\n// It would have to also provide an exported `getCountryPhoneCodes()` function\r\n// which would take `metadata` and return `country_calling_codes` map\r\n// because some people use that `country_calling_codes` map in their projects.\r\n//\r\n// On the other hand, having `country_calling_codes`\r\n// prepopulated yields more elegance to the exports\r\n// because if `country_calling_codes` wasn't part of metadata\r\n// it would have to be computed somewhere in global scope\r\n// therefore the modules wouldn't be strictly \"pure\"\r\n// so maybe `country_calling_codes` stays as part of metadata.\r\n//\r\nexport default function(input, version, included_countries, extended, included_phone_number_types)\r\n{\r\n\t// Validate `included_phone_number_types`\r\n\tif (included_phone_number_types)\r\n\t{\r\n\t\tfor (const _type of included_phone_number_types)\r\n\t\t{\r\n\t\t\tif (phone_number_types.indexOf(_type) < 0)\r\n\t\t\t{\r\n\t\t\t\treturn Promise.reject(`Unknown phone number type: ${_type}`)\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// Parse the XML metadata.\r\n\t// See: https://gitlab.com/catamphetamine/libphonenumber-js/blob/master/METADATA.md\r\n\treturn parseStringPromisified(input).then((xml) =>\r\n\t{\r\n\t\t// https://github.com/googlei18n/libphonenumber/blob/master/resources/PhoneNumberMetadata.xml\r\n\t\t// https://github.com/googlei18n/libphonenumber/blob/master/resources/phonemetadata.proto\r\n\t\t// https://github.com/googlei18n/libphonenumber/blob/master/javascript/i18n/phonenumbers/phonenumberutil.js\r\n\t\t// https://github.com/googlei18n/libphonenumber/blob/master/javascript/i18n/phonenumbers/asyoutypeformatter.js\r\n\r\n\t\tconst country_calling_code_to_countries = {}\r\n\t\tconst countries = {}\r\n\t\tconst nonGeographic = {}\r\n\r\n\t\tfor (const territory of xml.phoneNumberMetadata.territories[0].territory)\r\n\t\t{\r\n\t\t\t// A two-letter country code\r\n\t\t\tconst country_code = territory.$.id\r\n\r\n\t\t\t// Skip this country if it has not been explicitly included\r\n\t\t\tif (included_countries && !included_countries.has(country_code)) {\r\n\t\t\t\tcontinue\r\n\t\t\t}\r\n\r\n\t\t\tif (territory.$.nationalPrefixOptionalWhenFormatting) {\r\n\t\t\t\tthrow new Error('`nationalPrefixOptionalWhenFormatting` encountered on a country level: uncomment the relevant code part below.')\r\n\t\t\t}\r\n\r\n\t\t\t// Country metadata\r\n\t\t\tconst country =\r\n\t\t\t{\r\n\t\t\t\t// Phone code related fields:\r\n\r\n\t\t\t\t// Phone code for phone numbers in this country.\r\n\t\t\t\t//\r\n\t\t\t\t// E.g. `1` for both USA and Canada.\r\n\t\t\t\t//\r\n\t\t\t\tphone_code: territory.$.countryCode,\r\n\r\n\t\t\t\t// International Direct Dialing prefix.\r\n\t\t\t\tidd_prefix: territory.$.internationalPrefix,\r\n\t\t\t\tdefault_idd_prefix: territory.$.preferredInternationalPrefix,\r\n\r\n\t\t\t\t// Localized \" ext. \" prefix.\r\n\t\t\t\text: territory.$.preferredExtnPrefix,\r\n\r\n\t\t\t\t// In case of several countries\r\n\t\t\t\t// having the same country phone code,\r\n\t\t\t\t// these leading digits are the means\r\n\t\t\t\t// of classifying an international phone number\r\n\t\t\t\t// whether it belongs to a certain country.\r\n\t\t\t\t//\r\n\t\t\t\t// E.g. for Antigua and Barbuda\r\n\t\t\t\t// country phone code is `1` (same as USA)\r\n\t\t\t\t// and leading digits are `268`.\r\n\t\t\t\t//\r\n\t\t\t\tleading_digits: territory.$.leadingDigits,\r\n\r\n\t\t\t\t// The regular expression of all possible\r\n\t\t\t\t// national (significant) numbers for this country.\r\n\t\t\t\tnational_number_pattern: territory.generalDesc[0].nationalNumberPattern[0].replace(/\\s/g, ''),\r\n\r\n\t\t\t\t// National prefix related fields:\r\n\r\n\t\t\t\t// aka \"trunk code\".\r\n\t\t\t\t// This is the prefix prepended to a\r\n\t\t\t\t// national (significant) phone number\r\n\t\t\t\t// when dialed from within the country.\r\n\t\t\t\t// E.g. `0` for UK.\r\n\t\t\t\tnational_prefix: territory.$.nationalPrefix,\r\n\r\n\t\t\t\t// In some (many) countries the national prefix\r\n\t\t\t\t// is not just a constant digit (like `0` in UK)\r\n\t\t\t\t// but can be different depending on the phone number\r\n\t\t\t\t// (and can be also absent for some phone numbers).\r\n\t\t\t\t//\r\n\t\t\t\t// So `national_prefix_for_parsing` is used when parsing\r\n\t\t\t\t// a national-prefixed (local) phone number\r\n\t\t\t\t// into a national significant phone number\r\n\t\t\t\t// extracting that possible national prefix out of it.\r\n\t\t\t\t//\r\n\t\t\t\tnational_prefix_for_parsing : territory.$.nationalPrefixForParsing ? territory.$.nationalPrefixForParsing.replace(/\\s/g, '') : undefined,\r\n\r\n\t\t\t\t// If `national_prefix_for_parsing` regular expression\r\n\t\t\t\t// contains \"captured groups\", then `national_prefix_transform_rule`\r\n\t\t\t\t// defines how the national-prefixed (local) phone number is\r\n\t\t\t\t// parsed into a national significant phone number.\r\n\t\t\t\t//\r\n\t\t\t\t// Pseudocode:\r\n\t\t\t\t//\r\n\t\t\t\t// national_prefix_pattern = regular_expression('^(?:' + national_prefix_for_parsing + ')')\r\n\t\t\t\t// national_significant_number = all_digits.replace(national_prefix_pattern, national_prefix_transform_rule)\r\n\t\t\t\t//\r\n\t\t\t\t// E.g. if a country's national numbers are 6-digit\r\n\t\t\t\t// and national prefix is always `0`,\r\n\t\t\t\t// then `national_prefix_for_parsing` could be `0(\\d{6})`\r\n\t\t\t\t// and the corresponding `national_prefix_transform_rule` would be `$1`\r\n\t\t\t\t// (which is the default behaviour).\r\n\t\t\t\t//\r\n\t\t\t\t// Currently this feature is only used in\r\n\t\t\t\t// Argentina, Brazil, Mexico and San Marino\r\n\t\t\t\t// due to their messy telephone numbering plans.\r\n\t\t\t\t//\r\n\t\t\t\t// For example, mobile numbers in Argentina are written in two completely\r\n\t\t\t\t// different ways when dialed in-country and out-of-country\r\n\t\t\t\t// (e.g. 0343 15-555-1212 is exactly the same number as +54 9 3435 55 1212).\r\n\t\t\t\t// Therefore for Argentina `national_prefix_transform_rule` is `9$1`.\r\n\t\t\t\t//\r\n\t\t\t\tnational_prefix_transform_rule: territory.$.nationalPrefixTransformRule,\r\n\r\n\t\t\t\t// Controls how national prefix is written\r\n\t\t\t\t// in a formatted local phone number.\r\n\t\t\t\t//\r\n\t\t\t\t// E.g. in Armenia national prefix is `0`\r\n\t\t\t\t// and `national_prefix_formatting_rule` is `($NP$FG)`\r\n\t\t\t\t// which means that a national significant phone number `xxxxxxxx`\r\n\t\t\t\t// matching phone number pattern `(\\d{2})(\\d{6})` with format `$1 $2`\r\n\t\t\t\t// is written as a local phone number `(0xx) xxxxxx`.\r\n\t\t\t\t//\r\n\t\t\t\t// Can be `undefined`.\r\n\t\t\t\t//\r\n\t\t\t\tnational_prefix_formatting_rule: getNationalPrefixFormattingRule(territory.$.nationalPrefixFormattingRule, territory.$.nationalPrefix),\r\n\r\n\t\t\t\t// Is it possible that a national (significant)\r\n\t\t\t\t// phone number has leading zeroes?\r\n\t\t\t\t//\r\n\t\t\t\t// E.g. in Gabon some numbers start with a `0`\r\n\t\t\t\t// while the national prefix is also `0`\r\n\t\t\t\t// which is optional for mobile numbers.\r\n\t\t\t\t//\r\n\t\t\t\t// This seems to only be used for validating\r\n\t\t\t\t// possible formats in AsYouType formatter.\r\n\t\t\t\t//\r\n\t\t\t\t// national_prefix_is_optional_when_formatting: territory.$.nationalPrefixOptionalWhenFormatting ? Boolean(territory.$.nationalPrefixOptionalWhenFormatting) : undefined,\r\n\r\n\t\t\t\t// I suppose carrier codes can be omitted.\r\n\t\t\t\t// They are required only for Brazil and Columbia,\r\n\t\t\t\t// and only when calling to fixed line numbers\r\n\t\t\t\t// from mobile phones within those countries.\r\n\t\t\t\t// I guess people living in those countries\r\n\t\t\t\t// would know that they need to add carrier codes.\r\n\t\t\t\t// Other people don't need to know that.\r\n\t\t\t\t// Anyway, if someone sends a Pull Request\r\n\t\t\t\t// implementing carrier codes as Google's `libphonenumber` does\r\n\t\t\t\t// then such Pull Request will likely be merged.\r\n\t\t\t\t//\r\n\t\t\t\t// // In some countries carrier code is required\r\n\t\t\t\t// // to dial certain phone numbers.\r\n\t\t\t\t// //\r\n\t\t\t\t// // E.g. in Colombia calling to fixed line numbers\r\n\t\t\t\t// // from mobile phones requires a carrier code when called within Colombia.\r\n\t\t\t\t// // Or, for example, Brazilian fixed line and mobile numbers\r\n\t\t\t\t// // need to be dialed with a carrier code when called within Brazil.\r\n\t\t\t\t// // Without that, most of the carriers won't connect the call.\r\n\t\t\t\t// // These are the only two cases when \"carrier codes\" are required.\r\n\t\t\t\t// //\r\n\t\t\t\t// carrier_code_formatting_rule: territory.$.carrierCodeFormattingRule,\r\n\r\n\t\t\t\t// These `types` will be purged later,\r\n\t\t\t\t// if they're not needed (which is most likely).\r\n\t\t\t\t// See `country_calling_code_to_countries` ambiguity for more info.\r\n\t\t\t\t//\r\n\t\t\t\ttypes: get_phone_number_types(territory),\r\n\r\n\t\t\t\t// Will be filtered out during compression phase\r\n\t\t\t\texamples: get_phone_number_examples(territory)\r\n\t\t\t}\r\n\r\n\t\t\t// Check that national (significant) phone number pattern\r\n\t\t\t// is set for this country (no \"default\" value here)\r\n\t\t\tif (!country.national_number_pattern)\r\n\t\t\t{\r\n\t\t\t\tthrow new Error(`\"generalDesc.nationalNumberPattern\" is missing for country ${country_code} metadata`)\r\n\t\t\t}\r\n\r\n\t\t\t// Check that an IDD prefix is always defined.\r\n\t\t\tif (country_code !== '001' && !country.idd_prefix)\r\n\t\t\t{\r\n\t\t\t\tthrow new Error(`\"generalDesc.internationalPrefix\" is missing for country ${country_code} metadata`)\r\n\t\t\t}\r\n\r\n\t\t\t// // Check that a preferred IDD prefix is always defined if IDD prefix is a pattern.\r\n\t\t\t// if (country_code !== '001' && !isSingleIDDPrefix(country.idd_prefix) && !country.default_idd_prefix)\r\n\t\t\t// {\r\n\t\t\t// \tthrow new Error(`\"generalDesc.preferredInternationalPrefix\" is missing for country ${country_code} metadata`)\r\n\t\t\t// }\r\n\r\n\t\t\t// Some countries don't have `availableFormats` specified,\r\n\t\t\t// because those formats are inherited from the \"main country for region\":\r\n\t\t\t// all non-\"main\" countries inherit their formats from the \"main\" country for that region.\r\n\t\t\tif (territory.availableFormats)\r\n\t\t\t{\r\n\t\t\t\tcountry.formats = territory.availableFormats[0].numberFormat.map((number_format) =>\r\n\t\t\t\t({\r\n\t\t\t\t\tpattern: number_format.$.pattern,\r\n\t\t\t\t\tleading_digits_patterns: number_format.leadingDigits ? number_format.leadingDigits.map(leading_digits => leading_digits.replace(/\\s/g, '')) : undefined,\r\n\t\t\t\t\tnational_prefix_formatting_rule: getNationalPrefixFormattingRule(number_format.$.nationalPrefixFormattingRule, territory.$.nationalPrefix),\r\n\t\t\t\t\tnational_prefix_is_optional_when_formatting: number_format.$.nationalPrefixOptionalWhenFormatting ? Boolean(number_format.$.nationalPrefixOptionalWhenFormatting) : undefined,\r\n\t\t\t\t\tformat: number_format.format[0],\r\n\t\t\t\t\tinternational_format: number_format.intlFormat ? number_format.intlFormat[0] : undefined\r\n\t\t\t\t}))\r\n\t\t\t\t// Screw local-only formats\r\n\t\t\t\t.filter(format => format.international_format !== 'NA')\r\n\r\n\t\t\t\t// Sanity check (using no \"default\" for this field)\r\n\t\t\t\tfor (const format of country.formats)\r\n\t\t\t\t{\r\n\t\t\t\t\t// Never happens\r\n\t\t\t\t\tif (!format.format)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tthrow new Error(`No phone number format \"format\" supplied for pattern ${format.pattern} for ${country_code}`)\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\t// Never happens\r\n\t\t\t\t\tif (format.format.indexOf(DIGIT_PLACEHOLDER) >= 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tthrow new Error(`Phone number format \"${format.format}\" contains a reserved \"${DIGIT_PLACEHOLDER}\" symbol for pattern ${format.pattern} for ${country_code}`)\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (country_code === '001') {\r\n\t\t\t\tnonGeographic[country.phone_code] = country\r\n\t\t\t\t// Populate numbering plan possible lengths.\r\n\t\t\t\tpopulateNumberingPlanPossibleLengths(country)\r\n\t\t\t} else {\r\n\t\t\t\t// Add this country's metadata\r\n\t\t\t\t// to the metadata map.\r\n\t\t\t\tcountries[country_code] = country\r\n\r\n\t\t\t\t// Register this country's \"country phone code\"\r\n\t\t\t\tif (!country_calling_code_to_countries[country.phone_code]) {\r\n\t\t\t\t\tcountry_calling_code_to_countries[country.phone_code] = []\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// In case of several countries\r\n\t\t\t\t// having the same country phone code.\r\n\t\t\t\t//\r\n\t\t\t\t// E.g. for USA and Canada, USA is the\r\n\t\t\t\t// \"main country for phone code 1\".\r\n\t\t\t\t//\r\n\t\t\t\t// (maybe this field is not used at all\r\n\t\t\t\t// in which case this field is to be removed)\r\n\t\t\t\t//\r\n\t\t\t\tif (territory.$.mainCountryForCode === \"true\") {\r\n\t\t\t\t\tcountry_calling_code_to_countries[country.phone_code].unshift(country_code)\r\n\t\t\t\t} else {\r\n\t\t\t\t\tcountry_calling_code_to_countries[country.phone_code].push(country_code)\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Some countries don't have `availableFormats` specified,\r\n\t\t// because those formats are meant to be copied from the \"main country for region\":\r\n\t\t// all non-\"main\" countries inherit their formats from the \"main\" country for that region.\r\n\t\t// If that's the case then `nationalPrefixFormattingRule` and\r\n\t\t// `nationalPrefixOptionalWhenFormatting` are also copied from the \"main\" region.\r\n\t\t// `nationalPrefix` itself though seems to be always present\r\n\t\t// even if it's the same for the \"main\" region.\r\n\t\t// Examples: \"RU\" and \"KZ\", \"US\" and \"CA\".\r\n\t\tfor (const country_code of Object.keys(countries))\r\n\t\t{\r\n\t\t\tconst country = countries[country_code]\r\n\r\n\t\t\tconst main_country_for_region_code = country_calling_code_to_countries[country.phone_code][0]\r\n\r\n\t\t\tif (main_country_for_region_code === country_code)\r\n\t\t\t{\r\n\t\t\t\t// Some countries like Saint Helena and Falkland Islands\r\n\t\t\t\t// ('AC', 'FK', 'KI', 'NU', 'SH', 'TA', ...)\r\n\t\t\t\t// don't have any phone number formats defined\r\n\t\t\t\t// and phone numbers are not formatted in those countries.\r\n\t\t\t\tif (!country.formats)\r\n\t\t\t\t{\r\n\t\t\t\t\tcountry.formats = []\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (country.formats !== undefined) {\r\n\t\t\t\t\tthrow new Error(`Country \"${country_code}\" is supposed to inherit formats from \"${main_country_for_region_code}\" but has its own formats defined.`)\r\n\t\t\t\t}\r\n\t\t\t\tif (country.national_prefix_formatting_rule !== undefined) {\r\n\t\t\t\t\tthrow new Error(`Country \"${country_code}\" is supposed to inherit \"national_prefix_formatting_rule\" from \"${main_country_for_region_code}\" but has its own \"national_prefix_formatting_rule\" defined.`)\r\n\t\t\t\t}\r\n\t\t\t\tif (country.national_prefix_is_optional_when_formatting !== undefined) {\r\n\t\t\t\t\tthrow new Error(`Country \"${country_code}\" is supposed to inherit \"national_prefix_is_optional_when_formatting\" from \"${main_country_for_region_code}\" but has its own \"national_prefix_is_optional_when_formatting\" defined.`)\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Turns out that ``\r\n\t\t// is not preemptive at all: it's too unspecific for the cases\r\n\t\t// when several countries correspond to the same country phone code\r\n\t\t// (e.g. NANPA: US, Canada, etc — all correspond to the same `1` country phone code).\r\n\t\t// For these cases all those bulky ``, ``, etc\r\n\t\t// patterns are required. Therefore retain them for these rare cases.\r\n\t\t//\r\n\t\t// This increases metadata size by 5 KiloBytes.\r\n\t\t//\r\n\t\tconst visited_countries = {}\r\n\t\tfor (const country_calling_code of Object.keys(country_calling_code_to_countries))\r\n\t\t{\r\n\t\t\tconst country_codes = country_calling_code_to_countries[country_calling_code]\r\n\r\n\t\t\tfor (const country_code of country_codes)\r\n\t\t\t{\r\n\t\t\t\tif (visited_countries[country_code])\r\n\t\t\t\t{\r\n\t\t\t\t\tcontinue\r\n\t\t\t\t}\r\n\r\n\t\t\t\tvisited_countries[country_code] = true\r\n\r\n\t\t\t\t// Populate numbering plan possible lengths.\r\n\t\t\t\tpopulateNumberingPlanPossibleLengths(countries[country_code])\r\n\r\n\t\t\t\tif (countries[country_code].possible_lengths.length === 0) {\r\n\t\t\t\t\tthrow new Error(`No \"possibleLengths\" set for country \"${country_code}\". \"react-phone-number-input\" relies on \"possibleLengths\" being always present.`)\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t// Purge `types` regular expressions (they are huge)\r\n\t\t\t// when they're not needed for resolving country phone code\r\n\t\t\t// to country phone number matching.\r\n\t\t\t// E.g. when there's a one-to-one correspondence\r\n\t\t\t// between a country phone code and a country code\r\n\t\t\tconst all_types_required = country_codes.length > 1\r\n\r\n\t\t\tif (!extended && !included_phone_number_types && !all_types_required)\r\n\t\t\t{\r\n\t\t\t\tdelete countries[country_codes[0]].types\r\n\t\t\t\tcontinue\r\n\t\t\t}\r\n\r\n\t\t\tfor (const country_code of country_codes)\r\n\t\t\t{\r\n\t\t\t\t// Leading digits for a country are sufficient\r\n\t\t\t\t// to resolve country phone code ambiguity.\r\n\t\t\t\t// So retaining all phone number type regular expressions\r\n\t\t\t\t// is not required in this case.\r\n\t\t\t\tif (!extended && !included_phone_number_types)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (countries[country_code].leading_digits)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdelete countries[country_code].types\r\n\t\t\t\t\t\tcontinue\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tconst types = countries[country_code].types\r\n\r\n\t\t\t\t// Find duplicate regular expressions for types\r\n\t\t\t\t// and just discard such duplicate types\r\n\t\t\t\t// to reduce metadata size (by 5 KiloBytes).\r\n\t\t\t\t// Or retain regular expressions just for the\r\n\t\t\t\t// specified phone number types (if configured).\r\n\t\t\t\tfor (const _type of phone_number_types)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (!types[_type])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tcontinue\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\t// Retain regular expressions just for the\r\n\t\t\t\t\t// specified phone number types (if configured).\r\n\t\t\t\t\tif (included_phone_number_types)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!all_types_required && !included_phone_number_types.has(_type))\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tdelete types[_type]\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\t// Remove redundant types\r\n\t\t\t\t\t// (other types having the same regular expressions as this one)\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t// Sometimes fixed line pattern is the same as for mobile.\r\n\t\t\t\t\t\tif (types.fixed_line && types.mobile &&\r\n\t\t\t\t\t\t\ttypes.fixed_line.pattern === types.mobile.pattern)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\ttypes.mobile.pattern = ''\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn {\r\n\t\t\tversion,\r\n\t\t\tcountries,\r\n\t\t\tcountry_calling_codes: country_calling_code_to_countries,\r\n\t\t\tnonGeographic\r\n\t\t}\r\n\t})\r\n}\r\n\r\n// Replaces $NP with national prefix and $FG with the first group ($1)\r\nfunction getNationalPrefixFormattingRule(rule, national_prefix) {\r\n\tif (!rule) {\r\n\t\treturn\r\n\t}\r\n\t// Replace $NP with national prefix and $FG with the first group ($1)\r\n\treturn rule\r\n\t\t.replace('$NP', national_prefix)\r\n\t\t.replace('$FG', '$1')\r\n}\r\n\r\n// Extracts various phone number type patterns from country XML metadata\r\nfunction get_phone_number_types(territory)\r\n{\r\n\treturn phone_number_types.reduce((output, type) =>\r\n\t{\r\n\t\tconst camel_cased_type = underscoreToCamelCase(type)\r\n\t\tconst pattern = territory[camel_cased_type] && territory[camel_cased_type][0].nationalNumberPattern[0].replace(/\\s/g, '')\r\n\t\tconst possible_lengths = territory[camel_cased_type] && territory[camel_cased_type][0].possibleLengths[0].$.national\r\n\t\tconst possible_lengths_local = territory[camel_cased_type] && territory[camel_cased_type][0].possibleLengths[0].$.localOnly\r\n\r\n\t\tif (pattern)\r\n\t\t{\r\n\t\t\toutput[type] =\r\n\t\t\t{\r\n\t\t\t\tpattern,\r\n\t\t\t\tpossible_lengths,\r\n\t\t\t\t// possible_lengths_local\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn output\r\n\t},\r\n\t{})\r\n}\r\n\r\n// Extracts various phone number type examples from country XML metadata\r\nfunction get_phone_number_examples(territory) {\r\n\treturn phone_number_types.reduce((output, type) => {\r\n\t\tconst camel_cased_type = underscoreToCamelCase(type)\r\n\t\tconst example = territory[camel_cased_type] && territory[camel_cased_type][0].exampleNumber[0]\r\n\t\tif (example) {\r\n\t\t\toutput[type] = example\r\n\t\t}\r\n\t\treturn output\r\n\t}, {})\r\n}\r\n\r\nfunction underscoreToCamelCase(string) {\r\n\treturn string.replace(/(\\_\\w)/g, match => match[1].toUpperCase())\r\n}\r\n\r\n/**\r\n* Parses a possible length string into a set of the integers that are covered.\r\n*\r\n* @param {string} possible_length_string - A string specifying the possible lengths of phone numbers. Follows\r\n* this syntax: ranges or elements are separated by commas, and ranges are specified in\r\n* [min-max] notation, inclusive. For example, [3-5],7,9,[11-14] should be parsed to\r\n* 3,4,5,7,9,11,12,13,14.\r\n* @return {Set}\r\n*/\r\nfunction parse_possible_lengths(possible_length_string)\r\n{\r\n\tif (possible_length_string.length === 0)\r\n\t{\r\n\t\tthrow new TypeError('Empty possibleLength string found.')\r\n\t}\r\n\r\n\tconst lengths = new Set()\r\n\r\n\tfor (const length of possible_length_string.split(','))\r\n\t{\r\n\t\tif (length.length == 0)\r\n\t\t{\r\n\t\t\tthrow new TypeError(`Leading, trailing or adjacent commas in possible length string ${length}, these should only separate numbers or ranges.`)\r\n\t\t}\r\n\r\n\t\tif (length[0] === '[')\r\n\t\t{\r\n\t\t\tif (length[length.length - 1] !== ']')\r\n\t\t\t{\r\n\t\t\t\tthrow new TypeError(`Missing end of range character in possible length string ${length}.`)\r\n\t\t\t}\r\n\r\n\t\t\t// Strip the leading and trailing [], and split on the -.\r\n\t\t\tconst min_max = length.slice(1, length.length - 1).split('-').map(_ => parseInt(_))\r\n\r\n\t\t\tif (min_max.length !== 2)\r\n\t\t\t{\r\n\t\t\t\tthrow new TypeError(`Ranges must have exactly one - character: missing for ${length}.`)\r\n\t\t\t}\r\n\r\n\t\t\tconst [min, max] = min_max\r\n\r\n\t\t\t// We don't even accept [6-7] since we prefer the shorter 6,7 variant;\r\n\t\t\t// for a range to be in use the hyphen needs to replace at least one digit.\r\n\t\t\tif (max - min < 2)\r\n\t\t\t{\r\n\t\t\t\tthrow new TypeError(`The first number in a range should be two or more digits lower than the second. Culprit possibleLength string: ${length}`)\r\n\t\t\t}\r\n\r\n\t\t\tfor (let i = min; i <= max; i++)\r\n\t\t\t{\r\n\t\t\t\tif (lengths.has(i))\r\n\t\t\t\t{\r\n\t\t\t\t\tthrow new TypeError(`Duplicate length element found (${i}) in possibleLength string ${length}.`)\r\n\t\t\t\t}\r\n\r\n\t\t\t\tlengths.add(i)\r\n\t\t\t}\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tconst i = parseInt(length)\r\n\r\n\t\t\tif (lengths.has(i))\r\n\t\t\t{\r\n\t\t\t\tthrow new TypeError(`Duplicate length element found (${i}) in possibleLength string ${length}.`)\r\n\t\t\t}\r\n\r\n\t\t\tlengths.add(i)\r\n\t\t}\r\n\t}\r\n\r\n\treturn lengths\r\n}\r\n\r\nconst arrays_are_equal = (a1, a2) => a1.length === a2.length && a1.every((_, i) => _ === a2[i])\r\n\r\n/**\r\n * Sets `metadata.possible_lengths` to a combination of `possible_length`s\r\n * of all types present in the numbering plan metadata.\r\n * @param {object} metadata\r\n */\r\nfunction populateNumberingPlanPossibleLengths(metadata)\r\n{\r\n\tconst types = metadata.types\r\n\r\n\tconst possible_lengths = new Set()\r\n\tconst possible_lengths_local = new Set()\r\n\r\n\tfor (const _type of Object.keys(types))\r\n\t{\r\n\t\tconst type_possible_lengths = parse_possible_lengths(types[_type].possible_lengths)\r\n\r\n\t\tfor (const i of type_possible_lengths)\r\n\t\t{\r\n\t\t\tpossible_lengths.add(i)\r\n\t\t}\r\n\r\n\t\ttypes[_type].possible_lengths = Array.from(type_possible_lengths)\r\n\r\n\t\tif (types[_type].possible_lengths_local)\r\n\t\t{\r\n\t\t\tconst type_possible_lengths_local = parse_possible_lengths(types[_type].possible_lengths_local)\r\n\r\n\t\t\tfor (const i of type_possible_lengths_local)\r\n\t\t\t{\r\n\t\t\t\tpossible_lengths_local.add(i)\r\n\t\t\t}\r\n\r\n\t\t\ttypes[_type].possible_lengths_local = Array.from(type_possible_lengths_local)\r\n\t\t}\r\n\t}\r\n\r\n\tfor (const i of possible_lengths_local)\r\n\t{\r\n\t\tif (possible_lengths.has(i))\r\n\t\t{\r\n\t\t\tpossible_lengths_local.delete(i)\r\n\t\t}\r\n\t}\r\n\r\n\tmetadata.possible_lengths = Array.from(possible_lengths)\r\n\tmetadata.possible_lengths.sort((a, b) => a - b)\r\n\r\n\tif (possible_lengths_local.size > 0)\r\n\t{\r\n\t\tmetadata.possible_lengths_local = Array.from(possible_lengths_local)\r\n\t\tmetadata.possible_lengths_local.sort((a, b) => a - b)\r\n\t}\r\n\r\n\t// Remove duplicates.\r\n\tfor (const _type of Object.keys(types))\r\n\t{\r\n\t\tif (arrays_are_equal(types[_type].possible_lengths, metadata.possible_lengths))\r\n\t\t{\r\n\t\t\tdelete types[_type].possible_lengths\r\n\t\t}\r\n\r\n\t\tif (types[_type].possible_lengths_local && metadata.possible_lengths_local &&\r\n\t\t\tarrays_are_equal(types[_type].possible_lengths_local, metadata.possible_lengths_local))\r\n\t\t{\r\n\t\t\tdelete types[_type].possible_lengths_local\r\n\t\t}\r\n\t}\r\n}\r\n\r\nfunction parseStringPromisified(input) {\r\n\treturn new Promise((resolve, reject) => {\r\n\t\tparseString(input, (error, result) => {\r\n\t\t\tif (error) {\r\n\t\t\t\treturn reject(error)\r\n\t\t\t}\r\n\t\t\tresolve(result)\r\n\t\t})\r\n\t})\r\n}"],"file":"generate.js"}