diff --git a/javascript/i18n/phonenumbers/demo-compiled.js b/javascript/i18n/phonenumbers/demo-compiled.js index b7ae6a033..9daa265b9 100644 --- a/javascript/i18n/phonenumbers/demo-compiled.js +++ b/javascript/i18n/phonenumbers/demo-compiled.js @@ -1,15 +1,16 @@ -(function(){for(var aa="function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,c){if(c.get||c.set)throw new TypeError("ES3 does not support getters and setters.");a!=Array.prototype&&a!=Object.prototype&&(a[b]=c.value)},k="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this,l=["String","prototype","repeat"],ba=0;baa||1342177279>>=1)b+=b;return c};fa!=ea&&null!=fa&&aa(k,da,{configurable:!0,writable:!0,value:fa}); -function ga(a){var b=typeof a;if("object"==b)if(a){if(a instanceof Array)return"array";if(a instanceof Object)return b;var c=Object.prototype.toString.call(a);if("[object Window]"==c)return"object";if("[object Array]"==c||"number"==typeof a.length&&"undefined"!=typeof a.splice&&"undefined"!=typeof a.propertyIsEnumerable&&!a.propertyIsEnumerable("splice"))return"array";if("[object Function]"==c||"undefined"!=typeof a.call&&"undefined"!=typeof a.propertyIsEnumerable&&!a.propertyIsEnumerable("call"))return"function"}else return"null"; -else if("function"==b&&"undefined"==typeof a.call)return"object";return b}function n(a){return"string"==typeof a}function p(a,b){function c(){}c.prototype=b.prototype;a.ha=b.prototype;a.prototype=new c;a.prototype.constructor=a;a.ma=function(a,c,f){for(var d=Array(arguments.length-2),e=2;ec?Math.max(0,a.length+c):c;if(n(a))return n(b)&&1==b.length?a.indexOf(b,c):-1;for(;cb?1:aa||1342177279>>=1)b+=b;return d}});ca("Math.sign",function(a){return a?a:function(a){a=Number(a);return!a||isNaN(a)?a:0c?Math.max(0,a.length+c):c;if(k(a))return k(b)&&1==b.length?a.indexOf(b,c):-1;for(;cb?1:aa.length?!1:N(eb,a)}function nb(a){return N(cb,a)?O(a,Wa):O(a,L)}function ob(a){var b=nb(a.toString());C(a);a.a(b)}function O(a,b){for(var c=new B,d,e=a.length,f=0;f=e)a=c;else if(d=d.substring(0,e),d=O(d,L),d.length)if(g=g.clone(),La(g,4),d=[g],g=x(b,1),c=R(b),g in J){a=T(a,g,U(g));if(e=wb(d,c))d=e.clone(),e=x(e,4),0e?2:c[c.length-1]=f&&f<=e;++f)if(d=parseInt(c.substring(0,f),10),d in J)return b.a(c.substring(f)),d;return 0} -function Gb(a,b,c,d,e){if(!a.length)return 0;a=new B(a);var f;b&&(f=u(b,11));null==f&&(f="NonMatch");var g=a.toString();if(g.length)if(M.test(g))g=g.replace(M,""),C(a),a.a(nb(g)),f=1;else{g=new RegExp(f);ob(a);f=a.toString();if(f.search(g))f=!1;else{var g=f.match(g)[0].length,h=f.substring(g).match(Za);h&&null!=h[1]&&0=a.b.length)throw"Phone number too short after IDD";if(c=Fb(a,c))return v(e, -1,c),c;throw"Invalid country calling code";}if(b&&(f=x(b,10),g=""+f,h=a.toString(),!h.lastIndexOf(g,0))){var m=new B(h.substring(g.length)),g=u(b,1),h=new RegExp(x(g,2));Hb(m,b,null);b=m.toString();if(!N(h,a.toString())&&N(h,b)||3==Db(a.toString(),g))return c.a(b),d&&v(e,6,10),v(e,1,f),f}v(e,1,0);return 0} -function Hb(a,b,c){var d=a.toString(),e=d.length,f=u(b,15);if(e&&null!=f&&f.length){var g=new RegExp("^(?:"+f+")");if(e=g.exec(d)){var f=new RegExp(x(u(b,1),2)),h=N(f,d),m=e.length-1;b=u(b,16);if(null!=b&&b.length&&null!=e[m]&&e[m].length){if(d=d.replace(g,b),!h||N(f,d))c&&0g.b.length)throw"The string supplied is too short to be a phone number";b&&(a=new B,c=new B(g.toString()),Hb(c,b,a),2!=Db(c.toString(),u(b,1))&&(g=c,d&&0a)throw"The string supplied is too short to be a phone number";if(17a.length?!1:N($a,a)}function ib(a){return N(Ya,a)?O(a,Ra):O(a,L)}function jb(a){var b=ib(a.toString());C(a);a.a(b)}function O(a,b){for(var c=new B,d,e=a.length,f=0;f=e)a=c;else if(d=d.substring(0,e),d=O(d,L),d.length)if(g=g.clone(),Ga(g,4),d=[g],g=x(b,1),c=R(b),g in J){a=T(a,g,U(g));if(e=rb(d,c))d=e.clone(),e=x(e,4),0e?2:c[c.length-1]=f&&f<=e;++f)if(d=parseInt(c.substring(0,f),10),d in J)return b.a(c.substring(f)),d;return 0} +function Bb(a,b,c,d,e){if(!a.length)return 0;a=new B(a);var f;b&&(f=u(b,11));null==f&&(f="NonMatch");var g=a.toString();if(g.length)if(M.test(g))g=g.replace(M,""),C(a),a.a(ib(g)),f=1;else{g=new RegExp(f);jb(a);f=a.toString();if(f.search(g))f=!1;else{var g=f.match(g)[0].length,h=f.substring(g).match(Ua);h&&null!=h[1]&&0=a.b.length)throw Error("Phone number too short after IDD");if(c=Ab(a, +c))return v(e,1,c),c;throw Error("Invalid country calling code");}if(b&&(f=x(b,10),g=""+f,h=a.toString(),!h.lastIndexOf(g,0))){var m=new B(h.substring(g.length)),g=u(b,1),h=new RegExp(x(g,2));Cb(m,b,null);b=m.toString();if(!N(h,a.toString())&&N(h,b)||3==yb(a.toString(),g))return c.a(b),d&&v(e,6,10),v(e,1,f),f}v(e,1,0);return 0} +function Cb(a,b,c){var d=a.toString(),e=d.length,f=u(b,15);if(e&&null!=f&&f.length){var g=new RegExp("^(?:"+f+")");if(e=g.exec(d)){var f=new RegExp(x(u(b,1),2)),h=N(f,d),m=e.length-1;b=u(b,16);if(null!=b&&b.length&&null!=e[m]&&e[m].length){if(d=d.replace(g,b),!h||N(f,d))c&&0g.b.length)throw Error("The string supplied is too short to be a phone number");b&&(a=new B,c=new B(g.toString()),Cb(c,b,a),2!=yb(c.toString(),u(b,1))&&(g=c,d&&0a)throw Error("The string supplied is too short to be a phone number");if(17 0 && numberToParse.charAt(0) != i18n.phonenumbers.PhoneNumberUtil.PLUS_SIGN) { - throw i18n.phonenumbers.Error.INVALID_COUNTRY_CODE; + throw new Error(i18n.phonenumbers.Error.INVALID_COUNTRY_CODE); } } return this.parseHelper_(numberToParse, defaultRegion, true, true); @@ -3814,17 +3814,17 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.setItalianLeadingZerosForPhoneNumber * the default coregion to be null or unknown ('ZZ'). * @return {i18n.phonenumbers.PhoneNumber} a phone number proto buffer filled * with the parsed number. - * @throws {i18n.phonenumbers.Error} + * @throws {Error} * @private */ i18n.phonenumbers.PhoneNumberUtil.prototype.parseHelper_ = function(numberToParse, defaultRegion, keepRawInput, checkRegion) { if (numberToParse == null) { - throw i18n.phonenumbers.Error.NOT_A_NUMBER; + throw new Error(i18n.phonenumbers.Error.NOT_A_NUMBER); } else if (numberToParse.length > i18n.phonenumbers.PhoneNumberUtil.MAX_INPUT_STRING_LENGTH_) { - throw i18n.phonenumbers.Error.TOO_LONG; + throw new Error(i18n.phonenumbers.Error.TOO_LONG); } /** @type {!goog.string.StringBuffer} */ @@ -3833,14 +3833,14 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.parseHelper_ = if (!i18n.phonenumbers.PhoneNumberUtil.isViablePhoneNumber( nationalNumber.toString())) { - throw i18n.phonenumbers.Error.NOT_A_NUMBER; + throw new Error(i18n.phonenumbers.Error.NOT_A_NUMBER); } // Check the region supplied is valid, or that the extracted number starts // with some sort of + sign so the number's region can be determined. if (checkRegion && !this.checkRegionForParsing_(nationalNumber.toString(), defaultRegion)) { - throw i18n.phonenumbers.Error.INVALID_COUNTRY_CODE; + throw new Error(i18n.phonenumbers.Error.INVALID_COUNTRY_CODE); } /** @type {i18n.phonenumbers.PhoneNumber} */ @@ -3870,7 +3870,7 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.parseHelper_ = countryCode = this.maybeExtractCountryCode(nationalNumberStr, regionMetadata, normalizedNationalNumber, keepRawInput, phoneNumber); } catch (e) { - if (e == i18n.phonenumbers.Error.INVALID_COUNTRY_CODE && + if (e.message == i18n.phonenumbers.Error.INVALID_COUNTRY_CODE && i18n.phonenumbers.PhoneNumberUtil.LEADING_PLUS_CHARS_PATTERN_ .test(nationalNumberStr)) { // Strip the plus-char, and try again. @@ -3908,7 +3908,7 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.parseHelper_ = } if (normalizedNationalNumber.getLength() < i18n.phonenumbers.PhoneNumberUtil.MIN_LENGTH_FOR_NSN_) { - throw i18n.phonenumbers.Error.TOO_SHORT_NSN; + throw new Error(i18n.phonenumbers.Error.TOO_SHORT_NSN); } if (regionMetadata != null) { @@ -3938,11 +3938,11 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.parseHelper_ = var lengthOfNationalNumber = normalizedNationalNumberStr.length; if (lengthOfNationalNumber < i18n.phonenumbers.PhoneNumberUtil.MIN_LENGTH_FOR_NSN_) { - throw i18n.phonenumbers.Error.TOO_SHORT_NSN; + throw new Error(i18n.phonenumbers.Error.TOO_SHORT_NSN); } if (lengthOfNationalNumber > i18n.phonenumbers.PhoneNumberUtil.MAX_LENGTH_FOR_NSN_) { - throw i18n.phonenumbers.Error.TOO_LONG; + throw new Error(i18n.phonenumbers.Error.TOO_LONG); } this.setItalianLeadingZerosForPhoneNumber_( normalizedNationalNumberStr, phoneNumber); @@ -4066,7 +4066,7 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.isNumberMatch = firstNumber = this.parse( firstNumberIn, i18n.phonenumbers.PhoneNumberUtil.UNKNOWN_REGION_); } catch (e) { - if (e != i18n.phonenumbers.Error.INVALID_COUNTRY_CODE) { + if (e.message != i18n.phonenumbers.Error.INVALID_COUNTRY_CODE) { return i18n.phonenumbers.PhoneNumberUtil.MatchType.NOT_A_NUMBER; } // The first number has no country calling code. EXACT_MATCH is no longer @@ -4110,7 +4110,7 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.isNumberMatch = secondNumberIn, i18n.phonenumbers.PhoneNumberUtil.UNKNOWN_REGION_); return this.isNumberMatch(firstNumberIn, secondNumber); } catch (e) { - if (e != i18n.phonenumbers.Error.INVALID_COUNTRY_CODE) { + if (e.message != i18n.phonenumbers.Error.INVALID_COUNTRY_CODE) { return i18n.phonenumbers.PhoneNumberUtil.MatchType.NOT_A_NUMBER; } return this.isNumberMatch(secondNumberIn, firstNumber); diff --git a/javascript/i18n/phonenumbers/phonenumberutil_test.js b/javascript/i18n/phonenumbers/phonenumberutil_test.js index 5a3938ba5..bf2134792 100644 --- a/javascript/i18n/phonenumbers/phonenumberutil_test.js +++ b/javascript/i18n/phonenumbers/phonenumberutil_test.js @@ -254,7 +254,7 @@ function testGetInstanceLoadUSMetadata() { assertEquals('$1 $2 $3', metadata.getNumberFormat(1).getFormat()); assertEquals('[13-689]\\d{9}|2[0-35-9]\\d{8}', metadata.getGeneralDesc().getNationalNumberPattern()); - assertEquals("[13-689]\\d{9}|2[0-35-9]\\d{8}", + assertEquals('[13-689]\\d{9}|2[0-35-9]\\d{8}', metadata.getFixedLine().getNationalNumberPattern()); assertEquals('900\\d{7}', metadata.getPremiumRate().getNationalNumberPattern()); @@ -966,7 +966,7 @@ function testFormatWithPreferredCarrierCode() { // When the preferred_domestic_carrier_code is present (even when it is just a // space), use it instead of the default carrier code passed in. arNumber.setPreferredDomesticCarrierCode(' '); - assertEquals("01234 12-5678", + assertEquals('01234 12-5678', phoneUtil.formatNationalNumberWithPreferredCarrierCode(arNumber, '15')); // When the preferred_domestic_carrier_code is present but empty, treat it as // unset and use instead the default carrier code passed in. @@ -2151,7 +2151,7 @@ function testMaybeExtractCountryCode() { // Expected. assertEquals('Wrong error type stored in exception.', i18n.phonenumbers.Error.INVALID_COUNTRY_CODE, - e); + e.message); } number = new i18n.phonenumbers.PhoneNumber(); try { @@ -2354,7 +2354,7 @@ function testParseMaliciousInput() { // Expected this exception. assertEquals('Wrong error type stored in exception.', i18n.phonenumbers.Error.TOO_LONG, - e); + e.message); } /** @type {!goog.string.StringBuffer} */ var maliciousNumberWithAlmostExt = new goog.string.StringBuffer(); @@ -2370,7 +2370,7 @@ function testParseMaliciousInput() { // Expected this exception. assertEquals('Wrong error type stored in exception.', i18n.phonenumbers.Error.TOO_LONG, - e); + e.message); } } @@ -2540,7 +2540,7 @@ function testFailedParseOnInvalidNumbers() { // Expected this exception. assertEquals('Wrong error type stored in exception.', i18n.phonenumbers.Error.NOT_A_NUMBER, - e); + e.message); } try { sentencePhoneNumber = '1 Still not a number'; @@ -2551,7 +2551,7 @@ function testFailedParseOnInvalidNumbers() { // Expected this exception. assertEquals('Wrong error type stored in exception.', i18n.phonenumbers.Error.NOT_A_NUMBER, - e); + e.message); } try { sentencePhoneNumber = '1 MICROSOFT'; @@ -2562,7 +2562,7 @@ function testFailedParseOnInvalidNumbers() { // Expected this exception. assertEquals('Wrong error type stored in exception.', i18n.phonenumbers.Error.NOT_A_NUMBER, - e); + e.message); } try { sentencePhoneNumber = '12 MICROSOFT'; @@ -2573,7 +2573,7 @@ function testFailedParseOnInvalidNumbers() { // Expected this exception. assertEquals('Wrong error type stored in exception.', i18n.phonenumbers.Error.NOT_A_NUMBER, - e); + e.message); } try { /** @type {string} */ @@ -2585,7 +2585,7 @@ function testFailedParseOnInvalidNumbers() { // Expected this exception. assertEquals('Wrong error type stored in exception.', i18n.phonenumbers.Error.TOO_LONG, - e); + e.message); } try { /** @type {string} */ @@ -2597,7 +2597,7 @@ function testFailedParseOnInvalidNumbers() { // Expected this exception. assertEquals('Wrong error type stored in exception.', i18n.phonenumbers.Error.NOT_A_NUMBER, - e); + e.message); } try { /** @type {string} */ @@ -2608,7 +2608,7 @@ function testFailedParseOnInvalidNumbers() { // Expected this exception. assertEquals('Wrong error type stored in exception.', i18n.phonenumbers.Error.NOT_A_NUMBER, - e); + e.message); } try { /** @type {string} */ @@ -2620,7 +2620,7 @@ function testFailedParseOnInvalidNumbers() { // Expected this exception. assertEquals('Wrong error type stored in exception.', i18n.phonenumbers.Error.NOT_A_NUMBER, - e); + e.message); } try { /** @type {string} */ @@ -2632,7 +2632,7 @@ function testFailedParseOnInvalidNumbers() { // Expected this exception. assertEquals('Wrong error type stored in exception.', i18n.phonenumbers.Error.TOO_SHORT_NSN, - e); + e.message); } try { /** @type {string} */ @@ -2644,7 +2644,7 @@ function testFailedParseOnInvalidNumbers() { // Expected this exception. assertEquals('Wrong error type stored in exception.', i18n.phonenumbers.Error.INVALID_COUNTRY_CODE, - e); + e.message); } try { /** @type {string} */ @@ -2656,7 +2656,7 @@ function testFailedParseOnInvalidNumbers() { // country code. assertEquals('Wrong error type stored in exception.', i18n.phonenumbers.Error.INVALID_COUNTRY_CODE, - e); + e.message); } try { /** @type {string} */ @@ -2667,7 +2667,7 @@ function testFailedParseOnInvalidNumbers() { // Expected this exception. assertEquals('Wrong error type stored in exception.', i18n.phonenumbers.Error.INVALID_COUNTRY_CODE, - e); + e.message); } try { someNumber = '123 456 7890'; @@ -2677,7 +2677,7 @@ function testFailedParseOnInvalidNumbers() { // Expected this exception. assertEquals('Wrong error type stored in exception.', i18n.phonenumbers.Error.INVALID_COUNTRY_CODE, - e); + e.message); } try { someNumber = '123 456 7890'; @@ -2687,7 +2687,7 @@ function testFailedParseOnInvalidNumbers() { // Expected this exception. assertEquals('Wrong error type stored in exception.', i18n.phonenumbers.Error.INVALID_COUNTRY_CODE, - e); + e.message); } try { someNumber = '0044------'; @@ -2697,7 +2697,7 @@ function testFailedParseOnInvalidNumbers() { // Expected this exception. assertEquals('Wrong error type stored in exception.', i18n.phonenumbers.Error.TOO_SHORT_AFTER_IDD, - e); + e.message); } try { someNumber = '0044'; @@ -2707,7 +2707,7 @@ function testFailedParseOnInvalidNumbers() { // Expected this exception. assertEquals('Wrong error type stored in exception.', i18n.phonenumbers.Error.TOO_SHORT_AFTER_IDD, - e); + e.message); } try { someNumber = '011'; @@ -2717,7 +2717,7 @@ function testFailedParseOnInvalidNumbers() { // Expected this exception. assertEquals('Wrong error type stored in exception.', i18n.phonenumbers.Error.TOO_SHORT_AFTER_IDD, - e); + e.message); } try { someNumber = '0119'; @@ -2727,7 +2727,7 @@ function testFailedParseOnInvalidNumbers() { // Expected this exception. assertEquals('Wrong error type stored in exception.', i18n.phonenumbers.Error.TOO_SHORT_AFTER_IDD, - e); + e.message); } try { /** @type {string} */ @@ -2739,7 +2739,7 @@ function testFailedParseOnInvalidNumbers() { // Expected this exception. assertEquals('Wrong error type stored in exception.', i18n.phonenumbers.Error.NOT_A_NUMBER, - e); + e.message); } try { // Invalid region. @@ -2749,7 +2749,7 @@ function testFailedParseOnInvalidNumbers() { // Expected this exception. assertEquals('Wrong error type stored in exception.', i18n.phonenumbers.Error.NOT_A_NUMBER, - e); + e.message); } try { phoneUtil.parse(null, RegionCode.US); @@ -2758,7 +2758,7 @@ function testFailedParseOnInvalidNumbers() { // Expected this exception. assertEquals('Wrong error type stored in exception.', i18n.phonenumbers.Error.NOT_A_NUMBER, - e); + e.message); } try { /** @type {string} */ @@ -2769,7 +2769,7 @@ function testFailedParseOnInvalidNumbers() { // Expected this exception. assertEquals('Wrong error type stored in exception.', i18n.phonenumbers.Error.INVALID_COUNTRY_CODE, - e); + e.message); } try { // This is invalid because no '+' sign is present as part of phone-context. @@ -2782,7 +2782,7 @@ function testFailedParseOnInvalidNumbers() { // Expected this exception. assertEquals('Wrong error type stored in exception.', i18n.phonenumbers.Error.INVALID_COUNTRY_CODE, - e); + e.message); } } @@ -3007,7 +3007,7 @@ function testParseAndKeepRaw() { // Expected this exception. assertEquals('Wrong error type stored in exception.', i18n.phonenumbers.Error.INVALID_COUNTRY_CODE, - e); + e.message); } /** @type {i18n.phonenumbers.PhoneNumber} */