react-phone-number-input
Version:
Telephone number input React component
1 lines • 166 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("react-hook-form"),require("prop-types")):"function"==typeof define&&define.amd?define(["exports","react","react-hook-form","prop-types"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).PhoneInput={},t.React,t.ReactHookForm,t.PropTypes)}(this,(function(t,e,n,r){"use strict";function d(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var a=d(e),i=d(r);function o(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(!t)return;if("string"==typeof t)return $(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return $(t,e)}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function $(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function u(t){var n=e.useRef(),r=e.useCallback((function(e){!function(t,e){for(var n,r=o(t);!(n=r()).done;){var d=n.value;d&&l(d,e)}}([t,n],e)}),[t,n]);return[n,r]}function l(t,e){"function"==typeof t?t(e):t.current=e}var f=["Component","name","defaultValue","shouldUnregister","control","rules","onChange","onBlur"],s=["ref","onChange","onBlur"];function c(){return c=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},c.apply(this,arguments)}function h(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var r,d,a,i,o=[],$=!0,u=!1;try{if(a=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;$=!1}else for(;!($=(r=a.call(n)).done)&&(o.push(r.value),o.length!==e);$=!0);}catch(t){u=!0,d=t}finally{try{if(!$&&null!=n.return&&(i=n.return(),Object(i)!==i))return}finally{if(u)throw d}}return o}}(t,e)||function(t,e){if(!t)return;if("string"==typeof t)return m(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return m(t,e)}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function m(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function g(t,e){if(null==t)return{};var n,r,d=function(t,e){if(null==t)return{};var n,r,d={},a=Object.keys(t);for(r=0;r<a.length;r++)n=a[r],e.indexOf(n)>=0||(d[n]=t[n]);return d}(t,e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);for(r=0;r<a.length;r++)n=a[r],e.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(d[n]=t[n])}return d}var y=function(t,r){var d=t.Component,i=t.name,o=t.defaultValue,$=t.shouldUnregister,l=t.control,m=t.rules,y=t.onChange,v=t.onBlur,p=g(t,f),b=h(u(r),2),C=b[0],N=b[1];o=void 0===o?null:o;var P=e.useCallback((function(){C.current.focus()}),[]);return a.default.createElement(n.Controller,{control:l,name:i,defaultValue:o,shouldUnregister:$,rules:m,onFocus:P,render:function(t){return function(t){var n=t.ref,r=t.onChange,i=t.onBlur,o=g(t,s);e.useImperativeHandle(n,(function(){return{focus:function(){C.current.focus()}}}));var $=e.useCallback((function(t){void 0===t&&(t=null),r(t),y&&y(t)}),[r,y]),u=e.useCallback((function(t){i(t),v&&v(t)}),[i,v]);return a.default.createElement(d,c({},p,o,{ref:N,onChange:$,onBlur:u}))}(t.field||t)}})};(y=a.default.forwardRef(y)).propTypes={Component:i.default.elementType.isRequired,name:i.default.string.isRequired,defaultValue:i.default.string,shouldUnregister:i.default.bool,control:i.default.object,rules:i.default.object,onChange:i.default.func,onBlur:i.default.func};var v=y;function p(t,e){t=t.split("-"),e=e.split("-");for(var n=t[0].split("."),r=e[0].split("."),d=0;d<3;d++){var a=Number(n[d]),i=Number(r[d]);if(a>i)return 1;if(i>a)return-1;if(!isNaN(a)&&isNaN(i))return 1;if(isNaN(a)&&!isNaN(i))return-1}return t[1]&&e[1]?t[1]>e[1]?1:t[1]<e[1]?-1:0:!t[1]&&e[1]?1:t[1]&&!e[1]?-1:0}var b={}.constructor;function C(t){return null!=t&&t.constructor===b}var N=/^\d+$/;function P(t){return P="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},P(t)}function O(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function S(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,I(r.key),r)}}function w(t,e,n){return e&&S(t.prototype,e),n&&S(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function I(t){var e=function(t,e){if("object"!=P(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=P(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==P(e)?e:e+""}var x=" ext. ",A=function(){return w((function t(e){O(this,t),R(e),this.metadata=e,L.call(this,e)}),[{key:"getCountries",value:function(){return Object.keys(this.metadata.countries).filter((function(t){return"001"!==t}))}},{key:"getCountryMetadata",value:function(t){return this.metadata.countries[t]}},{key:"nonGeographic",value:function(){if(!(this.v1||this.v2||this.v3))return this.metadata.nonGeographic||this.metadata.nonGeographical}},{key:"hasCountry",value:function(t){return void 0!==this.getCountryMetadata(t)}},{key:"hasCallingCode",value:function(t){if(this.getCountryCodesForCallingCode(t))return!0;if(this.nonGeographic()){if(this.nonGeographic()[t])return!0}else{var e=this.countryCallingCodes()[t];if(e&&1===e.length&&"001"===e[0])return!0}}},{key:"isNonGeographicCallingCode",value:function(t){return this.nonGeographic()?!!this.nonGeographic()[t]:!this.getCountryCodesForCallingCode(t)}},{key:"country",value:function(t){return this.selectNumberingPlan(t)}},{key:"selectNumberingPlan",value:function(t,e){var n,r,d;if(t&&(d=t,N.test(d)?r=t:n=t),e&&(r=e),n&&"001"!==n){var a=this.getCountryMetadata(n);if(!a)throw new Error("Unknown country: ".concat(n));this.numberingPlan=new T(a,this)}else if(r){if(!this.hasCallingCode(r))throw new Error("Unknown calling code: ".concat(r));this.numberingPlan=new T(this.getNumberingPlanMetadata(r),this)}else this.numberingPlan=void 0;return this}},{key:"getCountryCodesForCallingCode",value:function(t){var e=this.countryCallingCodes()[t];if(e){if(1===e.length&&3===e[0].length)return;return e}}},{key:"getCountryCodeForCallingCode",value:function(t){var e=this.getCountryCodesForCallingCode(t);if(e)return e[0]}},{key:"getNumberingPlanMetadata",value:function(t){var e=this.getCountryCodeForCallingCode(t);if(e)return this.getCountryMetadata(e);if(this.nonGeographic()){var n=this.nonGeographic()[t];if(n)return n}else{var r=this.countryCallingCodes()[t];if(r&&1===r.length&&"001"===r[0])return this.metadata.countries["001"]}}},{key:"countryCallingCode",value:function(){return this.numberingPlan.callingCode()}},{key:"IDDPrefix",value:function(){return this.numberingPlan.IDDPrefix()}},{key:"defaultIDDPrefix",value:function(){return this.numberingPlan.defaultIDDPrefix()}},{key:"nationalNumberPattern",value:function(){return this.numberingPlan.nationalNumberPattern()}},{key:"possibleLengths",value:function(){return this.numberingPlan.possibleLengths()}},{key:"formats",value:function(){return this.numberingPlan.formats()}},{key:"nationalPrefixForParsing",value:function(){return this.numberingPlan.nationalPrefixForParsing()}},{key:"nationalPrefixTransformRule",value:function(){return this.numberingPlan.nationalPrefixTransformRule()}},{key:"leadingDigits",value:function(){return this.numberingPlan.leadingDigits()}},{key:"hasTypes",value:function(){return this.numberingPlan.hasTypes()}},{key:"type",value:function(t){return this.numberingPlan.type(t)}},{key:"ext",value:function(){return this.numberingPlan.ext()}},{key:"countryCallingCodes",value:function(){return this.v1?this.metadata.country_phone_code_to_countries:this.metadata.country_calling_codes}},{key:"chooseCountryByCountryCallingCode",value:function(t){return this.selectNumberingPlan(t)}},{key:"hasSelectedNumberingPlan",value:function(){return void 0!==this.numberingPlan}}])}(),T=function(){return w((function t(e,n){O(this,t),this.globalMetadataObject=n,this.metadata=e,L.call(this,n.metadata)}),[{key:"callingCode",value:function(){return this.metadata[0]}},{key:"_getDefaultCountryMetadataForThisCallingCode",value:function(){return this.globalMetadataObject.getNumberingPlanMetadata(this.callingCode())}},{key:"getDefaultCountryMetadataForRegion",value:function(){return this._getDefaultCountryMetadataForThisCallingCode()}},{key:"IDDPrefix",value:function(){if(!this.v1&&!this.v2)return this.metadata[1]}},{key:"defaultIDDPrefix",value:function(){if(!this.v1&&!this.v2)return this.metadata[12]}},{key:"nationalNumberPattern",value:function(){return this.v1||this.v2?this.metadata[1]:this.metadata[2]}},{key:"possibleLengths",value:function(){if(!this.v1)return this.metadata[this.v2?2:3]}},{key:"_getFormats",value:function(t){return t[this.v1?2:this.v2?3:4]}},{key:"formats",value:function(){var t=this,e=this._getFormats(this.metadata)||this._getFormats(this._getDefaultCountryMetadataForThisCallingCode())||[];return e.map((function(e){return new E(e,t)}))}},{key:"nationalPrefix",value:function(){return this.metadata[this.v1?3:this.v2?4:5]}},{key:"_getNationalPrefixFormattingRule",value:function(t){return t[this.v1?4:this.v2?5:6]}},{key:"nationalPrefixFormattingRule",value:function(){return this._getNationalPrefixFormattingRule(this.metadata)||this._getNationalPrefixFormattingRule(this._getDefaultCountryMetadataForThisCallingCode())}},{key:"_nationalPrefixForParsing",value:function(){return this.metadata[this.v1?5:this.v2?6:7]}},{key:"nationalPrefixForParsing",value:function(){return this._nationalPrefixForParsing()||this.nationalPrefix()}},{key:"nationalPrefixTransformRule",value:function(){return this.metadata[this.v1?6:this.v2?7:8]}},{key:"_getNationalPrefixIsOptionalWhenFormatting",value:function(){return!!this.metadata[this.v1?7:this.v2?8:9]}},{key:"nationalPrefixIsOptionalWhenFormattingInNationalFormat",value:function(){return this._getNationalPrefixIsOptionalWhenFormatting(this.metadata)||this._getNationalPrefixIsOptionalWhenFormatting(this._getDefaultCountryMetadataForThisCallingCode())}},{key:"leadingDigits",value:function(){return this.metadata[this.v1?8:this.v2?9:10]}},{key:"types",value:function(){return this.metadata[this.v1?9:this.v2?10:11]}},{key:"hasTypes",value:function(){return(!this.types()||0!==this.types().length)&&!!this.types()}},{key:"type",value:function(t){if(this.hasTypes()&&j(this.types(),t))return new k(j(this.types(),t),this)}},{key:"ext",value:function(){return this.v1||this.v2?x:this.metadata[13]||x}}])}(),E=function(){return w((function t(e,n){O(this,t),this._format=e,this.metadata=n}),[{key:"pattern",value:function(){return this._format[0]}},{key:"format",value:function(){return this._format[1]}},{key:"leadingDigitsPatterns",value:function(){return this._format[2]||[]}},{key:"nationalPrefixFormattingRule",value:function(){return this._format[3]||this.metadata.nationalPrefixFormattingRule()}},{key:"nationalPrefixIsOptionalWhenFormattingInNationalFormat",value:function(){return!!this._format[4]||this.metadata.nationalPrefixIsOptionalWhenFormattingInNationalFormat()}},{key:"nationalPrefixIsMandatoryWhenFormattingInNationalFormat",value:function(){return this.usesNationalPrefix()&&!this.nationalPrefixIsOptionalWhenFormattingInNationalFormat()}},{key:"usesNationalPrefix",value:function(){return!(!this.nationalPrefixFormattingRule()||F.test(this.nationalPrefixFormattingRule()))}},{key:"internationalFormat",value:function(){return this._format[5]||this.format()}}])}(),F=/^\(?\$1\)?$/,k=function(){return w((function t(e,n){O(this,t),this.type=e,this.metadata=n}),[{key:"pattern",value:function(){return this.metadata.v1?this.type:this.type[0]}},{key:"possibleLengths",value:function(){if(!this.metadata.v1)return this.type[1]||this.metadata.possibleLengths()}}])}();function j(t,e){switch(e){case"FIXED_LINE":return t[0];case"MOBILE":return t[1];case"TOLL_FREE":return t[2];case"PREMIUM_RATE":return t[3];case"PERSONAL_NUMBER":return t[4];case"VOICEMAIL":return t[5];case"UAN":return t[6];case"PAGER":return t[7];case"VOIP":return t[8];case"SHARED_COST":return t[9]}}function R(t){if(!t)throw new Error("[libphonenumber-js] `metadata` argument not passed. Check your arguments.");if(!C(t)||!C(t.countries))throw new Error("[libphonenumber-js] `metadata` argument was passed but it's not a valid metadata. Must be an object having `.countries` child object property. Got ".concat(C(t)?"an object of shape: { "+Object.keys(t).join(", ")+" }":"a "+D(t)+": "+t,"."))}var D=function(t){return P(t)};function M(t,e){var n=new A(e);if(n.hasCountry(t))return n.selectNumberingPlan(t).countryCallingCode();throw new Error("Unknown country: ".concat(t))}function L(t){var e=t.version;"number"==typeof e?(this.v1=1===e,this.v2=2===e,this.v3=3===e,this.v4=4===e):e?-1===p(e,"1.2.0")?this.v2=!0:-1===p(e,"1.7.35")?this.v3=!0:this.v4=!0:this.v1=!0}function _(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return B(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?B(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function B(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function G(t,e,n){return U(t,void 0,e,n)}function U(t,e,n,r){n&&(r=new A(r.metadata)).selectNumberingPlan(n);var d=r.type(e),a=d&&d.possibleLengths()||r.possibleLengths();if(!a)return"IS_POSSIBLE";if("FIXED_LINE_OR_MOBILE"===e){if(!r.type("FIXED_LINE"))return U(t,"MOBILE",n,r);var i=r.type("MOBILE");i&&(a=function(t,e){for(var n,r=t.slice(),d=_(e);!(n=d()).done;){var a=n.value;t.indexOf(a)<0&&r.push(a)}return r.sort((function(t,e){return t-e}))}(a,i.possibleLengths()))}else if(e&&!d)return"INVALID_LENGTH";var o=t.length,$=a[0];return $===o?"IS_POSSIBLE":$>o?"TOO_SHORT":a[a.length-1]<o?"TOO_LONG":a.indexOf(o,1)>=0?"IS_POSSIBLE":"INVALID_LENGTH"}function K(t,e,n){void 0===e&&(e={});var r=new A(n);if(e.v2){if(!t.countryCallingCode)throw new Error("Invalid phone number object passed");r.selectNumberingPlan(t.country||t.countryCallingCode)}else{if(!t.phone)return!1;if(t.country){if(!r.hasCountry(t.country))throw new Error("Unknown country: ".concat(t.country));r.selectNumberingPlan(t.country)}else{if(!t.countryCallingCode)throw new Error("Invalid phone number object passed");r.selectNumberingPlan(t.countryCallingCode)}}if(r.possibleLengths())return function(t,e){if("IS_POSSIBLE"===G(t,void 0,e))return!0;return!1}(t.phone||t.nationalNumber,r);if(t.countryCallingCode&&r.isNonGeographicCallingCode(t.countryCallingCode))return!0;throw new Error('Missing "possibleLengths" in metadata. Perhaps the metadata has been generated before v1.0.18.')}function V(t,e){return t=t||"",new RegExp("^(?:"+e+")$").test(t)}function W(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return H(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?H(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function H(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}var Z=["MOBILE","PREMIUM_RATE","TOLL_FREE","SHARED_COST","VOIP","PERSONAL_NUMBER","PAGER","UAN","VOICEMAIL"];function q(t,e,n){if(e=e||{},t.country||t.countryCallingCode){var r=new A(n);r.selectNumberingPlan(t.country||t.countryCallingCode);var d=e.v2?t.nationalNumber:t.phone;if(V(d,r.nationalNumberPattern())){if(Y(d,"FIXED_LINE",r))return r.type("MOBILE")&&""===r.type("MOBILE").pattern()?"FIXED_LINE_OR_MOBILE":r.type("MOBILE")?Y(d,"MOBILE",r)?"FIXED_LINE_OR_MOBILE":"FIXED_LINE":"FIXED_LINE_OR_MOBILE";for(var a,i=W(Z);!(a=i()).done;){var o=a.value;if(Y(d,o,r))return o}}}}function Y(t,e,n){var r=n.type(e);return!(!r||!r.pattern())&&(!(r.possibleLengths()&&r.possibleLengths().indexOf(t.length)<0)&&V(t,r.pattern()))}var J=/^[A-Z]{2}$/;function X(t,e){var n,r,d,a=new A(e);return d=t,J.test(d)?(n=t,a.selectNumberingPlan(n),r=a.countryCallingCode()):r=t,{country:n,callingCode:r}}function Q(t,e,n){var r=new A(n).getCountryCodesForCallingCode(t);return r?r.filter((function(t){return function(t,e,n){var r=new A(n);return r.selectNumberingPlan(e),r.numberingPlan.possibleLengths().indexOf(t.length)>=0}(e,t,n)})):[]}var z="0-90-9٠-٩۰-۹",tt="".concat("-‐-―−ー-").concat("//").concat("..").concat(" ").concat("()()[]\\[\\]").concat("~⁓∼~"),et=new RegExp("(["+z+"])");function nt(t,e,n,r){if(e){var d=new A(r);d.selectNumberingPlan(e||n);var a=new RegExp(d.IDDPrefix());if(0===t.search(a)){var i=(t=t.slice(t.match(a)[0].length)).match(et);if(!(i&&null!=i[1]&&i[1].length>0&&"0"===i[1]))return t}}}function rt(t,e){if(t&&e.numberingPlan.nationalPrefixForParsing()){var n=new RegExp("^(?:"+e.numberingPlan.nationalPrefixForParsing()+")"),r=n.exec(t);if(r){var d,a,i,o=r.length-1,$=o>0&&r[o];if(e.nationalPrefixTransformRule()&&$)d=t.replace(n,e.nationalPrefixTransformRule()),o>1&&(a=r[1]);else{var u=r[0];d=t.slice(u.length),$&&(a=r[1])}if($){var l=t.indexOf(r[1]);t.slice(0,l)===e.numberingPlan.nationalPrefix()&&(i=e.numberingPlan.nationalPrefix())}else i=r[0];return{nationalNumber:d,nationalPrefix:i,carrierCode:a}}}return{nationalNumber:t}}function dt(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return at(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?at(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function at(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function it(t,e,n){for(var r,d=new A(n),a=dt(e);!(r=a()).done;){var i=r.value;if(d.selectNumberingPlan(i),d.leadingDigits()){if(t&&0===t.search(d.leadingDigits()))return i}else if(q({phone:t,country:i},void 0,d.metadata))return i}}var ot=!1;function $t(t,e){var n=e.nationalNumber,r=e.metadata;if(ot&&r.isNonGeographicCallingCode(t))return"001";var d=r.getCountryCodesForCallingCode(t);return d?1===d.length?d[0]:it(n,d,r.metadata):void 0}function ut(t,e,n){var r=rt(t,n),d=r.carrierCode,a=r.nationalNumber;if(a!==t){if(!function(t,e,n){if(V(t,n.nationalNumberPattern())&&!V(e,n.nationalNumberPattern()))return!1;return!0}(t,a,n))return{nationalNumber:t};if(n.numberingPlan.possibleLengths()&&(e||(e=$t(n.numberingPlan.callingCode(),{nationalNumber:a,metadata:n})),!function(t,e,n){switch(G(t,e,n)){case"TOO_SHORT":case"INVALID_LENGTH":return!1;default:return!0}}(a,e,n)))return{nationalNumber:t}}return{nationalNumber:a,carrierCode:d}}function lt(t,e,n,r,d){if(!(e||n||r))return{number:t};var a=e||n?M(e||n,d):r;if(0===t.indexOf(a)){var i=new A(d);i.selectNumberingPlan(e||n||r);var o=t.slice(a.length),$=ut(o,void 0,i).nationalNumber,u=ut(t,void 0,i).nationalNumber;if(!V(u,i.nationalNumberPattern())&&V($,i.nationalNumberPattern())||"TOO_LONG"===G(u,void 0,i))return{countryCallingCode:a,number:o}}return{number:t}}function ft(t,e,n,r,d){if(!t)return{};var a;if("+"!==t[0]){var i=nt(t,e||n,r,d);if(!i||i===t){if(e||n||r){var o=lt(t,e,n,r,d),$=o.countryCallingCode,u=o.number;if($)return{countryCallingCodeSource:"FROM_NUMBER_WITHOUT_PLUS_SIGN",countryCallingCode:$,number:u}}return{number:t}}a=!0,t="+"+i}if("0"===t[1])return{};for(var l=new A(d),f=2;f-1<=3&&f<=t.length;){var s=t.slice(1,f);if(l.hasCallingCode(s))return l.selectNumberingPlan(s),{countryCallingCodeSource:a?"FROM_NUMBER_WITH_IDD":"FROM_NUMBER_WITH_PLUS_SIGN",countryCallingCode:s,number:t.slice(f)};f++}return{}}function st(t){return t.replace(new RegExp("[".concat(tt,"]+"),"g")," ").trim()}var ct=/(\$\d)/;function ht(t,e,n){var r=n.useInternationalFormat,d=n.withNationalPrefix;n.carrierCode,n.metadata;var a=t.replace(new RegExp(e.pattern()),r?e.internationalFormat():d&&e.nationalPrefixFormattingRule()?e.format().replace(ct,e.nationalPrefixFormattingRule()):e.format());return r?st(a):a}var mt=/^[\d]+(?:[~\u2053\u223C\uFF5E][\d]+)?$/;var gt={formatExtension:function(t,e,n){return"".concat(t).concat(n.ext()).concat(e)}};function yt(t,e,n,r){n=n?function(){for(var t=1,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];for(;t<n.length;){if(n[t])for(var d in n[t])n[0][d]=n[t][d];t++}return n[0]}({},gt,n):gt;var d=new A(r);if(t.country&&"001"!==t.country){if(!d.hasCountry(t.country))throw new Error("Unknown country: ".concat(t.country));d.selectNumberingPlan(t.country)}else{if(!t.countryCallingCode)return t.phone||"";d.selectNumberingPlan(t.countryCallingCode)}var a,i=d.countryCallingCode(),o=n.v2?t.nationalNumber:t.phone;switch(e){case"NATIONAL":return o?pt(a=vt(o,t.carrierCode,"NATIONAL",d,n),t.ext,d,n.formatExtension):"";case"INTERNATIONAL":return o?(a=vt(o,null,"INTERNATIONAL",d,n),pt(a="+".concat(i," ").concat(a),t.ext,d,n.formatExtension)):"+".concat(i);case"E.164":return"+".concat(i).concat(o);case"RFC3966":return function(t){var e=t.number,n=t.ext;if(!e)return"";if("+"!==e[0])throw new Error('"formatRFC3966()" expects "number" to be in E.164 format.');return"tel:".concat(e).concat(n?";ext="+n:"")}({number:"+".concat(i).concat(o),ext:t.ext});case"IDD":if(!n.fromCountry)return;var $=function(t,e,n,r,d){var a=M(r,d.metadata);if(a===n){var i=vt(t,e,"NATIONAL",d);return"1"===n?n+" "+i:i}var o=function(t,e,n){var r=new A(n);return r.selectNumberingPlan(t||e),r.defaultIDDPrefix()?r.defaultIDDPrefix():mt.test(r.IDDPrefix())?r.IDDPrefix():void 0}(r,void 0,d.metadata);if(o)return"".concat(o," ").concat(n," ").concat(vt(t,null,"INTERNATIONAL",d))}(o,t.carrierCode,i,n.fromCountry,d);if(!$)return;return pt($,t.ext,d,n.formatExtension);default:throw new Error('Unknown "format" argument passed to "formatNumber()": "'.concat(e,'"'))}}function vt(t,e,n,r,d){var a,i,o=(a=r.formats(),i=t,function(t,e){for(var n=0;n<t.length;){if(e(t[n]))return t[n];n++}}(a,(function(t){if(t.leadingDigitsPatterns().length>0){var e=t.leadingDigitsPatterns()[t.leadingDigitsPatterns().length-1];if(0!==i.search(e))return!1}return V(i,t.pattern())})));return o?ht(t,o,{useInternationalFormat:"INTERNATIONAL"===n,withNationalPrefix:!o.nationalPrefixIsOptionalWhenFormattingInNationalFormat()||!d||!1!==d.nationalPrefix,carrierCode:e,metadata:r}):t}function pt(t,e,n,r){return e?r(t,e,n):t}function bt(t){return bt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},bt(t)}function Ct(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function Nt(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Ct(Object(n),!0).forEach((function(e){Pt(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ct(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function Pt(t,e,n){return(e=St(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Ot(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,St(r.key),r)}}function St(t){var e=function(t,e){if("object"!=bt(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=bt(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==bt(e)?e:e+""}var wt=function(){return t=function t(e,n,r){if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),!e)throw new TypeError("First argument is required");if("string"!=typeof e)throw new TypeError("First argument must be a string");if("+"===e[0]&&!n)throw new TypeError("`metadata` argument not passed");if(C(n)&&C(n.countries)){r=n;var d=e;if(!It.test(d))throw new Error('Invalid `number` argument passed: must consist of a "+" followed by digits');var a=ft(d,void 0,void 0,void 0,r);if(e=a.countryCallingCode,!(n=a.number))throw new Error("Invalid `number` argument passed: too short")}if(!n)throw new TypeError("`nationalNumber` argument is required");if("string"!=typeof n)throw new TypeError("`nationalNumber` argument must be a string");R(r);var i=X(e,r),o=i.country,$=i.callingCode;this.country=o,this.countryCallingCode=$,this.nationalNumber=n,this.number="+"+this.countryCallingCode+this.nationalNumber,this.getMetadata=function(){return r}},e=[{key:"setExt",value:function(t){this.ext=t}},{key:"getPossibleCountries",value:function(){return this.country?[this.country]:Q(this.countryCallingCode,this.nationalNumber,this.getMetadata())}},{key:"isPossible",value:function(){return K(this,{v2:!0},this.getMetadata())}},{key:"isValid",value:function(){return function(t,e,n){e=e||{};var r=new A(n);return r.selectNumberingPlan(t.country||t.countryCallingCode),r.hasTypes()?void 0!==q(t,e,r.metadata):V(e.v2?t.nationalNumber:t.phone,r.nationalNumberPattern())}(this,{v2:!0},this.getMetadata())}},{key:"isNonGeographic",value:function(){return new A(this.getMetadata()).isNonGeographicCallingCode(this.countryCallingCode)}},{key:"isEqual",value:function(t){return this.number===t.number&&this.ext===t.ext}},{key:"getType",value:function(){return q(this,{v2:!0},this.getMetadata())}},{key:"format",value:function(t,e){return yt(this,t,e?Nt(Nt({},e),{},{v2:!0}):{v2:!0},this.getMetadata())}},{key:"formatNational",value:function(t){return this.format("NATIONAL",t)}},{key:"formatInternational",value:function(t){return this.format("INTERNATIONAL",t)}},{key:"getURI",value:function(t){return this.format("RFC3966",t)}}],e&&Ot(t.prototype,e),n&&Ot(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n}(),It=/^\+\d+$/;function xt(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return At(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?At(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function At(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}var Tt={0:"0",1:"1",2:"2",3:"3",4:"4",5:"5",6:"6",7:"7",8:"8",9:"9","0":"0","1":"1","2":"2","3":"3","4":"4","5":"5","6":"6","7":"7","8":"8","9":"9","٠":"0","١":"1","٢":"2","٣":"3","٤":"4","٥":"5","٦":"6","٧":"7","٨":"8","٩":"9","۰":"0","۱":"1","۲":"2","۳":"3","۴":"4","۵":"5","۶":"6","۷":"7","۸":"8","۹":"9"};function Et(t){return Tt[t]}function Ft(t){for(var e,n="",r=xt(t.split(""));!(e=r()).done;){var d=Et(e.value);d&&(n+=d)}return n}function kt(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return jt(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?jt(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function jt(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function Rt(t,e,n){return"+"===t?e?void("function"==typeof n&&n("end")):"+":Et(t)}function Dt(t){return Dt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Dt(t)}function Mt(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,Lt(r.key),r)}}function Lt(t){var e=function(t,e){if("object"!=Dt(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=Dt(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==Dt(e)?e:e+""}var _t=function(){return t=function t(e){var n=e.onCountryChange,r=e.onCallingCodeChange;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.onCountryChange=n,this.onCallingCodeChange=r},(e=[{key:"reset",value:function(t){var e=t.country,n=t.callingCode;this.international=!1,this.missingPlus=!1,this.IDDPrefix=void 0,this.callingCode=void 0,this.digits="",this.resetNationalSignificantNumber(),this.initCountryAndCallingCode(e,n)}},{key:"resetNationalSignificantNumber",value:function(){this.nationalSignificantNumber=this.getNationalDigits(),this.nationalSignificantNumberIsModified=!1,this.nationalPrefix=void 0,this.carrierCode=void 0,this.prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix=void 0}},{key:"update",value:function(t){for(var e=0,n=Object.keys(t);e<n.length;e++){var r=n[e];this[r]=t[r]}}},{key:"initCountryAndCallingCode",value:function(t,e){this.setCountry(t),this.setCallingCode(e)}},{key:"setCountry",value:function(t){this.country=t,this.onCountryChange(t)}},{key:"setCallingCode",value:function(t){this.callingCode=t,this.onCallingCodeChange(t,this.country)}},{key:"startInternationalNumber",value:function(t,e){this.international=!0,this.initCountryAndCallingCode(t,e)}},{key:"appendDigits",value:function(t){this.digits+=t}},{key:"appendNationalSignificantNumberDigits",value:function(t){this.nationalSignificantNumber+=t}},{key:"getNationalDigits",value:function(){return this.international?this.digits.slice((this.IDDPrefix?this.IDDPrefix.length:0)+(this.callingCode?this.callingCode.length:0)):this.digits}},{key:"getDigitsWithoutInternationalPrefix",value:function(){return this.international&&this.IDDPrefix?this.digits.slice(this.IDDPrefix.length):this.digits}}])&&Mt(t.prototype,e),n&&Mt(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n}();function Bt(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return Gt(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Gt(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function Gt(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}var Ut="x",Kt=new RegExp(Ut);function Vt(t,e){if(e<1)return"";for(var n="";e>1;)1&e&&(n+=t),e>>=1,t+=t;return n+t}function Wt(t,e){return")"===t[e]&&e++,function(t){var e=[],n=0;for(;n<t.length;)"("===t[n]?e.push(n):")"===t[n]&&e.pop(),n++;var r=0,d="";e.push(t.length);for(var a=0,i=e;a<i.length;a++){var o=i[a];d+=t.slice(r,o),r=o+1}return d}(t.slice(0,e))}function Ht(t,e,n){var r=n.metadata,d=n.shouldTryNationalPrefixFormattingRule,a=n.getSeparatorAfterNationalPrefix;if(new RegExp("^(?:".concat(e.pattern(),")$")).test(t.nationalSignificantNumber))return function(t,e,n){var r=n.metadata,d=n.shouldTryNationalPrefixFormattingRule,a=n.getSeparatorAfterNationalPrefix;if(t.nationalSignificantNumber,t.international,t.nationalPrefix,t.carrierCode,d(e)){var i=Zt(t,e,{useNationalPrefixFormattingRule:!0,getSeparatorAfterNationalPrefix:a,metadata:r});if(i)return i}return Zt(t,e,{useNationalPrefixFormattingRule:!1,getSeparatorAfterNationalPrefix:a,metadata:r})}(t,e,{metadata:r,shouldTryNationalPrefixFormattingRule:d,getSeparatorAfterNationalPrefix:a})}function Zt(t,e,n){var r=n.metadata,d=n.useNationalPrefixFormattingRule,a=n.getSeparatorAfterNationalPrefix,i=ht(t.nationalSignificantNumber,e,{carrierCode:t.carrierCode,useInternationalFormat:t.international,withNationalPrefix:d,metadata:r});if(d||(t.nationalPrefix?i=t.nationalPrefix+a(e)+i:t.prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix&&(i=t.prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix+" "+i)),function(t,e){return Ft(t)===e.getNationalDigits()}(i,t))return i}function qt(t){return qt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},qt(t)}function Yt(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,Jt(r.key),r)}}function Jt(t){var e=function(t,e){if("object"!=qt(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=qt(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==qt(e)?e:e+""}var Xt=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t)},(e=[{key:"parse",value:function(t){if(this.context=[{or:!0,instructions:[]}],this.parsePattern(t),1!==this.context.length)throw new Error("Non-finalized contexts left when pattern parse ended");var e=this.context[0],n=e.branches,r=e.instructions;if(n)return{op:"|",args:n.concat([ee(r)])};if(0===r.length)throw new Error("Pattern is required");return 1===r.length?r[0]:r}},{key:"startContext",value:function(t){this.context.push(t)}},{key:"endContext",value:function(){this.context.pop()}},{key:"getContext",value:function(){return this.context[this.context.length-1]}},{key:"parsePattern",value:function(t){if(!t)throw new Error("Pattern is required");var e=t.match(te);if(e){var n=e[1],r=t.slice(0,e.index),d=t.slice(e.index+n.length);switch(n){case"(?:":r&&this.parsePattern(r),this.startContext({or:!0,instructions:[],branches:[]});break;case")":if(!this.getContext().or)throw new Error('")" operator must be preceded by "(?:" operator');if(r&&this.parsePattern(r),0===this.getContext().instructions.length)throw new Error('No instructions found after "|" operator in an "or" group');var a=this.getContext().branches;a.push(ee(this.getContext().instructions)),this.endContext(),this.getContext().instructions.push({op:"|",args:a});break;case"|":if(!this.getContext().or)throw new Error('"|" operator can only be used inside "or" groups');if(r&&this.parsePattern(r),!this.getContext().branches){if(1!==this.context.length)throw new Error('"branches" not found in an "or" group context');this.getContext().branches=[]}this.getContext().branches.push(ee(this.getContext().instructions)),this.getContext().instructions=[];break;case"[":r&&this.parsePattern(r),this.startContext({oneOfSet:!0});break;case"]":if(!this.getContext().oneOfSet)throw new Error('"]" operator must be preceded by "[" operator');this.endContext(),this.getContext().instructions.push({op:"[]",args:Qt(r)});break;default:throw new Error("Unknown operator: ".concat(n))}d&&this.parsePattern(d)}else{if(zt.test(t))throw new Error("Illegal characters found in a pattern: ".concat(t));this.getContext().instructions=this.getContext().instructions.concat(t.split(""))}}}])&&Yt(t.prototype,e),n&&Yt(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n}();function Qt(t){for(var e=[],n=0;n<t.length;){if("-"===t[n]){if(0===n||n===t.length-1)throw new Error("Couldn't parse a one-of set pattern: ".concat(t));for(var r=t[n-1].charCodeAt(0)+1,d=t[n+1].charCodeAt(0)-1,a=r;a<=d;)e.push(String.fromCharCode(a)),a++}else e.push(t[n]);n++}return e}var zt=/[\(\)\[\]\?\:\|]/,te=new RegExp("(\\||\\(\\?\\:|\\)|\\[|\\])");function ee(t){return 1===t.length?t[0]:t}function ne(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return re(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?re(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function re(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function de(t){return de="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},de(t)}function ae(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,ie(r.key),r)}}function ie(t){var e=function(t,e){if("object"!=de(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=de(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==de(e)?e:e+""}var oe=function(){return t=function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.matchTree=(new Xt).parse(e)},e=[{key:"match",value:function(t){var e=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).allowOverflow;if(!t)throw new Error("String is required");var n=$e(t.split(""),this.matchTree,!0);if(n&&n.match&&delete n.matchedChars,!n||!n.overflow||e)return n}}],e&&ae(t.prototype,e),n&&ae(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n}();function $e(t,e,n){if("string"==typeof e){var r=t.join("");return 0===e.indexOf(r)?t.length===e.length?{match:!0,matchedChars:t}:{partialMatch:!0}:0===r.indexOf(e)?n&&t.length>e.length?{overflow:!0}:{match:!0,matchedChars:t.slice(0,e.length)}:void 0}if(Array.isArray(e)){for(var d=t.slice(),a=0;a<e.length;){var i=$e(d,e[a],n&&a===e.length-1);if(!i)return;if(i.overflow)return i;if(!i.match){if(i.partialMatch)return{partialMatch:!0};throw new Error("Unsupported match result:\n".concat(JSON.stringify(i,null,2)))}if(0===(d=d.slice(i.matchedChars.length)).length)return a===e.length-1?{match:!0,matchedChars:t}:{partialMatch:!0};a++}return n?{overflow:!0}:{match:!0,matchedChars:t.slice(0,t.length-d.length)}}switch(e.op){case"|":for(var o,$,u=ne(e.args);!($=u()).done;){var l=$e(t,$.value,n);if(l){if(l.overflow)return l;if(l.match)return{match:!0,matchedChars:l.matchedChars};if(!l.partialMatch)throw new Error("Unsupported match result:\n".concat(JSON.stringify(l,null,2)));o=!0}}return o?{partialMatch:!0}:void 0;case"[]":for(var f,s=ne(e.args);!(f=s()).done;){var c=f.value;if(t[0]===c)return 1===t.length?{match:!0,matchedChars:t}:n?{overflow:!0}:{match:!0,matchedChars:[c]}}return;default:throw new Error("Unsupported instruction tree: ".concat(e))}}function ue(t){return ue="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ue(t)}function le(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return fe(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?fe(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function fe(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function se(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,ce(r.key),r)}}function ce(t){var e=function(t,e){if("object"!=ue(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=ue(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==ue(e)?e:e+""}var he=Vt("9",15),me=/[- ]/,ge=new RegExp("["+tt+"]*\\$1["+tt+"]*(\\$\\d["+tt+"]*)*$"),ye=function(){return t=function t(e){e.state;var n=e.metadata;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.metadata=n,this.resetFormat()},e=[{key:"resetFormat",value:function(){this.chosenFormat=void 0,this.template=void 0,this.nationalNumberTemplate=void 0,this.populatedNationalNumberTemplate=void 0,this.populatedNationalNumberTemplatePosition=-1}},{key:"reset",value:function(t,e){this.resetFormat(),t?(this.isNANP="1"===t.callingCode(),this.matchingFormats=t.formats(),e.nationalSignificantNumber&&this.narrowDownMatchingFormats(e)):(this.isNANP=void 0,this.matchingFormats=[])}},{key:"format",value:function(t,e){var n=this;if(function(t,e){return"IS_POSSIBLE"===G(t,void 0,e)}(e.nationalSignificantNumber,this.metadata))for(var r,d=le(this.matchingFormats);!(r=d()).done;){var a=r.value,i=Ht(e,a,{metadata:this.metadata,shouldTryNationalPrefixFormattingRule:function(t){return n.shouldTryNationalPrefixFormattingRule(t,{international:e.international,nationalPrefix:e.nationalPrefix})},getSeparatorAfterNationalPrefix:function(t){return n.getSeparatorAfterNationalPrefix(t)}});if(i)return this.resetFormat(),this.chosenFormat=a,this.setNationalNumberTemplate(i.replace(/\d/g,Ut),e),this.populatedNationalNumberTemplate=i,this.populatedNationalNumberTemplatePosition=this.template.lastIndexOf(Ut),i}return this.formatNationalNumberWithNextDigits(t,e)}},{key:"formatNationalNumberWithNextDigits",value:function(t,e){var n=this.chosenFormat,r=this.chooseFormat(e);if(r)return r===n?this.formatNextNationalNumberDigits(t):this.formatNextNationalNumberDigits(e.getNationalDigits())}},{key:"narrowDownMatchingFormats",value:function(t){var e=this,n=t.nationalSignificantNumber,r=t.nationalPrefix,d=t.international,a=n,i=a.length-3;i<0&&(i=0),this.matchingFormats=this.matchingFormats.filter((function(t){return e.formatSuits(t,d,r)&&e.formatMatches(t,a,i)})),this.chosenFormat&&-1===this.matchingFormats.indexOf(this.chosenFormat)&&this.resetFormat()}},{key:"formatSuits",value:function(t,e,n){return!(n&&!t.usesNationalPrefix()&&!t.nationalPrefixIsOptionalWhenFormattingInNationalFormat()||!e&&!n&&t.nationalPrefixIsMandatoryWhenFormattingInNationalFormat())}},{key:"formatMatches",value:function(t,e,n){var r=t.leadingDigitsPatterns().length;if(0===r)return!0;n=Math.min(n,r-1);var d=t.leadingDigitsPatterns()[n];if(e.length<3)try{return void 0!==new oe(d).match(e,{allowOverflow:!0})}catch(t){return console.error(t),!0}return new RegExp("^(".concat(d,")")).test(e)}},{key:"getFormatFormat",value:function(t,e){return e?t.internationalFormat():t.format()}},{key:"chooseFormat",value:function(t){for(var e,n=this,r=function(){var r=e.value;return n.chosenFormat===r?0:ge.test(n.getFormatFormat(r,t.international))?n.createTemplateForFormat(r,t)?(n.chosenFormat=r,0):(n.matchingFormats=n.matchingFormats.filter((function(t){return t!==r})),1):1},d=le(this.matchingFormats.slice());!(e=d()).done&&0!==r(););return this.chosenFormat||this.resetFormat(),this.chosenFormat}},{key:"createTemplateForFormat",value:function(t,e){if(!(t.pattern().indexOf("|")>=0)){var n=this.getTemplateForFormat(t,e);return n?(this.setNationalNumberTemplate(n,e),!0):void 0}}},{key:"getSeparatorAfterNationalPrefix",value:function(t){return this.isNANP||t&&t.nationalPrefixFormattingRule()&&me.test(t.nationalPrefixFormattingRule())?" ":""}},{key:"getInternationalPrefixBeforeCountryCallingCode",value:function(t,e){var n=t.IDDPrefix,r=t.missingPlus;return n?e&&!1===e.spacing?n:n+" ":r?"":"+"}},{key:"getTemplate",value:function(t){if(this.template){for(var e=-1,n=0,r=t.international?this.getInternationalPrefixBeforeCountryCallingCode(t,{spacing:!1}):"";n<r.length+t.getDigitsWithoutInternationalPrefix().length;)e=this.template.indexOf(Ut,e+1),n++;return Wt(this.template,e+1)}}},{key:"setNationalNumberTemplate",value:function(t,e){this.nationalNumberTemplate=t,this.populatedNationalNumberTemplate=t,this.populatedNationalNumberTemplatePosition=-1,e.international?this.template=this.getInternationalPrefixBeforeCountryCallingCode(e).replace(/[\d\+]/g,Ut)+Vt(Ut,e.callingCode.length)+" "+t:this.template=t}},{key:"getTemplateForFormat",value:function(t,e){var n=e.nationalSignificantNumber,r=e.international,d=e.nationalPrefix,a=e.prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix,i=t.pattern();i=i.replace(/\[([^\[\]])*\]/g,"\\d").replace(/\d(?=[^,}][^,}])/g,"\\d");var o=he.match(i)[0];if(!(n.length>o.length)){var $=new RegExp("^"+i+"$"),u=n.replace(/\d/g,"9");$.test(u)&&(o=u);var l,f=this.getFormatFormat(t,r);if(this.shouldTryNationalPrefixFormattingRule(t,{international:r,nationalPrefix:d})){var s=f.replace(ct,t.nationalPrefixFormattingRule());if(Ft(t.nationalPrefixFormattingRule())===(d||"")+Ft("$1")&&(f=s,l=!0,d))for(var c=d.length;c>0;)f=f.replace(/\d/,Ut),c--}var h=o.replace(new RegExp(i),f).replace(new RegExp("9","g"),Ut);return l||(a?h=Vt(Ut,a.length)+" "+h:d&&(h=Vt(Ut,d.length)+this.getSeparatorAfterNationalPrefix(t)+h)),r&&(h=st(h)),h}}},{key:"formatNextNationalNumberDigits",value:function(t){var e=function(t,e,n){for(var r,d=Bt(n.split(""));!(r=d()).done;){var a=r.value;if(t.slice(e+1).search(Kt)<0)return;e=t.search(Kt),t=t.replace(Kt,a)}return[t,e]}(this.populatedNationalNumberTemplate,this.populatedNationalNumberTemplatePosition,t);if(e)return this.populatedNationalNumberTemplate=e[0],this.populatedNationalNumberTemplatePosition=e[1],Wt(this.populatedNationalNumberTemplate,this.populatedNationalNumberTemplatePosition+1);this.resetFormat()}},{key:"shouldTryNationalPrefixFormattingRule",value:function(t,e){var n=e.international,r=e.nationalPrefix;if(t.nationalPrefixFormattingRule()){var d=t.usesNationalPrefix();if(d&&r||!d&&!n)return!0}}}],e&&se(t.prototype,e),n&&se(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n}();function ve(t){return ve="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ve(t)}function pe(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var r,d,a,i,o=[],$=!0,u=!1;try{if(a=(n=n.call(t)).next,0===e){if(Object(n)!==n)ret