UNPKG

react-phone-number-input

Version:

Telephone number input React component

1 lines 166 kB
!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 y(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 g=function(t,r){var d=t.Component,i=t.name,o=t.defaultValue,$=t.shouldUnregister,l=t.control,m=t.rules,g=t.onChange,p=t.onBlur,v=y(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=y(t,s);e.useImperativeHandle(n,(function(){return{focus:function(){C.current.focus()}}}));var $=e.useCallback((function(t){void 0===t&&(t=null),r(t),g&&g(t)}),[r,g]),u=e.useCallback((function(t){i(t),p&&p(t)}),[i,p]);return a.default.createElement(d,c({},v,o,{ref:N,onChange:$,onBlur:u}))}(t.field||t)}})};(g=a.default.forwardRef(g)).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 p=g;function v(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}function N(t){return N="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},N(t)}function P(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function O(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,w(r.key),r)}}function S(t,e,n){return e&&O(t.prototype,e),n&&O(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function w(t){var e=function(t,e){if("object"!=N(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=N(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==N(e)?e:e+""}var I=" ext. ",x=/^\d+$/,A=function(){return S((function t(e){P(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){if(t&&x.test(t)&&(e=t,t=null),t&&"001"!==t){if(!this.hasCountry(t))throw new Error("Unknown country: ".concat(t));this.numberingPlan=new E(this.getCountryMetadata(t),this)}else if(e){if(!this.hasCallingCode(e))throw new Error("Unknown calling code: ".concat(e));this.numberingPlan=new E(this.getNumberingPlanMetadata(e),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}}])}(),E=function(){return S((function t(e,n){P(this,t),this.globalMetadataObject=n,this.metadata=e,L.call(this,n.metadata)}),[{key:"callingCode",value:function(){return this.metadata[0]}},{key:"getDefaultCountryMetadataForRegion",value:function(){return this.globalMetadataObject.getNumberingPlanMetadata(this.callingCode())}},{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.getDefaultCountryMetadataForRegion())||[];return e.map((function(e){return new T(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.getDefaultCountryMetadataForRegion())}},{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.getDefaultCountryMetadataForRegion())}},{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?I:this.metadata[13]||I}}])}(),T=function(){return S((function t(e,n){P(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 S((function t(e,n){P(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 N(t)};function M(t,e){if((e=new A(e)).hasCountry(t))return e.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===v(e,"1.2.0")?this.v2=!0:-1===v(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,e,void 0,n)}function U(t,e,n,r){e&&(r=new A(r.metadata)).selectNumberingPlan(e);var d=r.type(n),a=d&&d.possibleLengths()||r.possibleLengths();if(!a)return"IS_POSSIBLE";if("FIXED_LINE_OR_MOBILE"===n){if(!r.type("FIXED_LINE"))return U(t,e,"MOBILE",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(n&&!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){if(void 0===e&&(e={}),n=new A(n),e.v2){if(!t.countryCallingCode)throw new Error("Invalid phone number object passed");n.selectNumberingPlan(t.countryCallingCode)}else{if(!t.phone)return!1;if(t.country){if(!n.hasCountry(t.country))throw new Error("Unknown country: ".concat(t.country));n.selectNumberingPlan(t.country)}else{if(!t.countryCallingCode)throw new Error("Invalid phone number object passed");n.selectNumberingPlan(t.countryCallingCode)}}if(n.possibleLengths())return function(t,e,n){if("IS_POSSIBLE"===G(t,e,n))return!0;return!1}(t.phone||t.nationalNumber,t.country,n);if(t.countryCallingCode&&n.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){(n=new A(n)).selectNumberingPlan(t.country,t.countryCallingCode);var r=e.v2?t.nationalNumber:t.phone;if(V(r,n.nationalNumberPattern())){if(Y(r,"FIXED_LINE",n))return n.type("MOBILE")&&""===n.type("MOBILE").pattern()?"FIXED_LINE_OR_MOBILE":n.type("MOBILE")?Y(r,"MOBILE",n)?"FIXED_LINE_OR_MOBILE":"FIXED_LINE":"FIXED_LINE_OR_MOBILE";for(var d,a=W(Z);!(d=a()).done;){var i=d.value;if(Y(r,i,n))return i}}}}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()))}function J(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);if(r.selectNumberingPlan(e),r.numberingPlan.possibleLengths().indexOf(t.length)>=0)return!0;return!1}(e,t,n)})):[]}var X="0-90-9٠-٩۰-۹",Q="".concat("-‐-―−ー-").concat("//").concat("..").concat("  ­​⁠ ").concat("()()[]\\[\\]").concat("~⁓∼~"),z=new RegExp("(["+X+"])");function tt(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(z);if(!(i&&null!=i[1]&&i[1].length>0&&"0"===i[1]))return t}}}function et(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 nt(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 rt(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)?rt(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 rt(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 dt(t,e){var n=e.countries,r=e.metadata;r=new A(r);for(var d,a=nt(n);!(d=a()).done;){var i=d.value;if(r.selectNumberingPlan(i),r.leadingDigits()){if(t&&0===t.search(r.leadingDigits()))return i}else if(q({phone:t,country:i},void 0,r.metadata))return i}}var at=!1;function it(t,e){var n=e.nationalNumber,r=e.metadata;if(at&&r.isNonGeographicCallingCode(t))return"001";var d=r.getCountryCodesForCallingCode(t);return d?1===d.length?d[0]:dt(n,{countries:d,metadata:r.metadata}):void 0}function ot(t,e,n){var r=et(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=it(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 $t(t,e,n,r,d){var a=e||n?M(e||n,d):r;if(0===t.indexOf(a)){(d=new A(d)).selectNumberingPlan(e||n,a);var i=t.slice(a.length),o=ot(i,e,d).nationalNumber,$=ot(t,e,d).nationalNumber;if(!V($,d.nationalNumberPattern())&&V(o,d.nationalNumberPattern())||"TOO_LONG"===G($,e,d))return{countryCallingCode:a,number:i}}return{number:t}}function ut(t,e,n,r,d){if(!t)return{};var a;if("+"!==t[0]){var i=tt(t,e||n,r,d);if(!i||i===t){if(e||n||r){var o=$t(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{};d=new A(d);for(var l=2;l-1<=3&&l<=t.length;){var f=t.slice(1,l);if(d.hasCallingCode(f))return d.selectNumberingPlan(f),{countryCallingCodeSource:a?"FROM_NUMBER_WITH_IDD":"FROM_NUMBER_WITH_PLUS_SIGN",countryCallingCode:f,number:t.slice(l)};l++}return{}}function lt(t){return t.replace(new RegExp("[".concat(Q,"]+"),"g")," ").trim()}var ft=/(\$\d)/;function st(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(ft,e.nationalPrefixFormattingRule()):e.format());return r?lt(a):a}var ct=/^[\d]+(?:[~\u2053\u223C\uFF5E][\d]+)?$/;var ht={formatExtension:function(t,e,n){return"".concat(t).concat(n.ext()).concat(e)}};function mt(t,e,n,r){if(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]}({},ht,n):ht,r=new A(r),t.country&&"001"!==t.country){if(!r.hasCountry(t.country))throw new Error("Unknown country: ".concat(t.country));r.selectNumberingPlan(t.country)}else{if(!t.countryCallingCode)return t.phone||"";r.selectNumberingPlan(t.countryCallingCode)}var d,a=r.countryCallingCode(),i=n.v2?t.nationalNumber:t.phone;switch(e){case"NATIONAL":return i?gt(d=yt(i,t.carrierCode,"NATIONAL",r,n),t.ext,r,n.formatExtension):"";case"INTERNATIONAL":return i?(d=yt(i,null,"INTERNATIONAL",r,n),gt(d="+".concat(a," ").concat(d),t.ext,r,n.formatExtension)):"+".concat(a);case"E.164":return"+".concat(a).concat(i);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(a).concat(i),ext:t.ext});case"IDD":if(!n.fromCountry)return;var o=function(t,e,n,r,d){var a=M(r,d.metadata);if(a===n){var i=yt(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():ct.test(r.IDDPrefix())?r.IDDPrefix():void 0}(r,void 0,d.metadata);if(o)return"".concat(o," ").concat(n," ").concat(yt(t,null,"INTERNATIONAL",d))}(i,t.carrierCode,a,n.fromCountry,r);if(!o)return;return gt(o,t.ext,r,n.formatExtension);default:throw new Error('Unknown "format" argument passed to "formatNumber()": "'.concat(e,'"'))}}function yt(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?st(t,o,{useInternationalFormat:"INTERNATIONAL"===n,withNationalPrefix:!o.nationalPrefixIsOptionalWhenFormattingInNationalFormat()||!d||!1!==d.nationalPrefix,carrierCode:e,metadata:r}):t}function gt(t,e,n,r){return e?r(t,e,n):t}function pt(t){return pt="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},pt(t)}function vt(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 bt(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?vt(Object(n),!0).forEach((function(e){Ct(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):vt(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function Ct(t,e,n){return(e=Pt(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Nt(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,Pt(r.key),r)}}function Pt(t){var e=function(t,e){if("object"!=pt(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=pt(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==pt(e)?e:e+""}var Ot=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(!wt.test(d))throw new Error('Invalid `number` argument passed: must consist of a "+" followed by digits');var a=ut(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=function(t,e){var n,r,d=new A(e);return St(t)?(n=t,d.selectNumberingPlan(n),r=d.countryCallingCode()):r=t,{country:n,countryCallingCode:r}}(e,r),o=i.country,$=i.countryCallingCode;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]:J(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){return e=e||{},(n=new A(n)).selectNumberingPlan(t.country,t.countryCallingCode),n.hasTypes()?void 0!==q(t,e,n.metadata):V(e.v2?t.nationalNumber:t.phone,n.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 mt(this,t,e?bt(bt({},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&&Nt(t.prototype,e),n&&Nt(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n}(),St=function(t){return/^[A-Z]{2}$/.test(t)};var wt=/^\+\d+$/;function It(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 xt(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)?xt(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 xt(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 At={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 At[t]}function Tt(t){for(var e,n="",r=It(t.split(""));!(e=r()).done;){var d=Et(e.value);d&&(n+=d)}return n}function Ft(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 kt(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)?kt(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 kt(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 jt(t,e,n){return"+"===t?e?void("function"==typeof n&&n("end")):"+":Et(t)}function Rt(t){return Rt="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},Rt(t)}function Dt(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,Mt(r.key),r)}}function Mt(t){var e=function(t,e){if("object"!=Rt(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=Rt(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==Rt(e)?e:e+""}var Lt=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}}])&&Dt(t.prototype,e),n&&Dt(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n}();function _t(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 Bt(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)?Bt(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 Bt(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 Gt="x",Ut=new RegExp(Gt);function Kt(t,e){if(e<1)return"";for(var n="";e>1;)1&e&&(n+=t),e>>=1,t+=t;return n+t}function Vt(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 Wt(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=Ht(t,e,{useNationalPrefixFormattingRule:!0,getSeparatorAfterNationalPrefix:a,metadata:r});if(i)return i}return Ht(t,e,{useNationalPrefixFormattingRule:!1,getSeparatorAfterNationalPrefix:a,metadata:r})}(t,e,{metadata:r,shouldTryNationalPrefixFormattingRule:d,getSeparatorAfterNationalPrefix:a})}function Ht(t,e,n){var r=n.metadata,d=n.useNationalPrefixFormattingRule,a=n.getSeparatorAfterNationalPrefix,i=st(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 Tt(t)===e.getNationalDigits()}(i,t))return i}function Zt(t){return Zt="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},Zt(t)}function qt(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,Yt(r.key),r)}}function Yt(t){var e=function(t,e){if("object"!=Zt(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=Zt(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==Zt(e)?e:e+""}var Jt=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([te(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(zt);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(te(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(te(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:Xt(r)});break;default:throw new Error("Unknown operator: ".concat(n))}d&&this.parsePattern(d)}else{if(Qt.test(t))throw new Error("Illegal characters found in a pattern: ".concat(t));this.getContext().instructions=this.getContext().instructions.concat(t.split(""))}}}])&&qt(t.prototype,e),n&&qt(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n}();function Xt(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 Qt=/[\(\)\[\]\?\:\|]/,zt=new RegExp("(\\||\\(\\?\\:|\\)|\\[|\\])");function te(t){return 1===t.length?t[0]:t}function ee(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 ne(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)?ne(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 ne(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 re(t){return re="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},re(t)}function de(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,ae(r.key),r)}}function ae(t){var e=function(t,e){if("object"!=re(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=re(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==re(e)?e:e+""}var ie=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 Jt).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=oe(t.split(""),this.matchTree,!0);if(n&&n.match&&delete n.matchedChars,!n||!n.overflow||e)return n}}],e&&de(t.prototype,e),n&&de(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n}();function oe(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=oe(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=ee(e.args);!($=u()).done;){var l=oe(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=ee(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 $e(t){return $e="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},$e(t)}function ue(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 le(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)?le(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 le(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 fe(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,se(r.key),r)}}function se(t){var e=function(t,e){if("object"!=$e(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=$e(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==$e(e)?e:e+""}var ce=Kt("9",15),he=/[- ]/,me=new RegExp("["+Q+"]*\\$1["+Q+"]*(\\$\\d["+Q+"]*)*$"),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,n){return"IS_POSSIBLE"===G(t,e,n)}(e.nationalSignificantNumber,e.country,this.metadata))for(var r,d=ue(this.matchingFormats);!(r=d()).done;){var a=r.value,i=Wt(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,Gt),e),this.populatedNationalNumberTemplate=i,this.populatedNationalNumberTemplatePosition=this.template.lastIndexOf(Gt),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 ie(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:me.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=ue(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()&&he.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(Gt,e+1),n++;return Vt(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,Gt)+Kt(Gt,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=ce.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(ft,t.nationalPrefixFormattingRule());if(Tt(t.nationalPrefixFormattingRule())===(d||"")+Tt("$1")&&(f=s,l=!0,d))for(var c=d.length;c>0;)f=f.replace(/\d/,Gt),c--}var h=o.replace(new RegExp(i),f).replace(new RegExp("9","g"),Gt);return l||(a?h=Kt(Gt,a.length)+" "+h:d&&(h=Kt(Gt,d.length)+this.getSeparatorAfterNationalPrefix(t)+h)),r&&(h=lt(h)),h}}},{key:"formatNextNationalNumberDigits",value:function(t){var e=function(t,e,n){for(var r,d=_t(n.split(""));!(r=d()).done;){var a=r.value;if(t.slice(e+1).search(Ut)<0)return;e=t.search(Ut),t=t.replace(Ut,a)}return[t,e]}(this.populatedNationalNumberTemplate,this.populatedNationalNumberTemplatePosition,t);if(e)return this.populatedNationalNumberTemplate=e[0],this.populatedNationalNumberTemplatePosition=e[1],Vt(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&&fe(t.prototype,e),n&&fe(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n}();function ge(t){return ge="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},ge(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)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)!=