AsYouTypeFormatter = function (a) {
this.DIGIT_PLACEHOLDER_ = "\u2008";
this.DIGIT_PATTERN_ = new RegExp(this.DIGIT_PLACEHOLDER_);
this.currentOutput_ = "";
this.formattingTemplate_ = new goog.string.StringBuffer;
this.currentFormattingPattern_ = "";
this.accruedInput_ = new goog.string.StringBuffer;
this.accruedInputWithoutFormatting_ = new goog.string.StringBuffer;
this.ableToFormat_ = !0;
this.isExpectingCountryCallingCode_ = this.isCompleteNumber_ = this.inputHasFormatting_ = !1;
this.phoneUtil_ = i18n.phonenumbers.PhoneNumberUtil.getInstance();
this.positionToRemember_ = this.originalPosition_ = this.lastMatchPosition_ = 0;
this.prefixBeforeNationalNumber_ = new goog.string.StringBuffer;
this.shouldAddSpaceAfterNationalPrefix_ = !1;
this.extractedNationalPrefix_ = "";
this.nationalNumber_ = new goog.string.StringBuffer;
this.possibleFormats_ = [];
this.defaultCountry_ = a;
this.defaultMetadata_ = this.currentMetadata_ = this.getMetadataForRegion_(this.defaultCountry_);
}n/a
NumberFormat = function () {
goog.proto2.Message.call(this);
}n/a
PhoneMetadata = function () {
goog.proto2.Message.call(this);
}n/a
PhoneMetadataCollection = function () {
goog.proto2.Message.call(this);
}n/a
PhoneNumber = function () {
goog.proto2.Message.call(this);
}n/a
PhoneNumberDesc = function () {
goog.proto2.Message.call(this);
}n/a
PhoneNumberUtil = function () {
this.regionToMetadataMap = {};
}n/a
AsYouTypeFormatter = function (a) {
this.DIGIT_PLACEHOLDER_ = "\u2008";
this.DIGIT_PATTERN_ = new RegExp(this.DIGIT_PLACEHOLDER_);
this.currentOutput_ = "";
this.formattingTemplate_ = new goog.string.StringBuffer;
this.currentFormattingPattern_ = "";
this.accruedInput_ = new goog.string.StringBuffer;
this.accruedInputWithoutFormatting_ = new goog.string.StringBuffer;
this.ableToFormat_ = !0;
this.isExpectingCountryCallingCode_ = this.isCompleteNumber_ = this.inputHasFormatting_ = !1;
this.phoneUtil_ = i18n.phonenumbers.PhoneNumberUtil.getInstance();
this.positionToRemember_ = this.originalPosition_ = this.lastMatchPosition_ = 0;
this.prefixBeforeNationalNumber_ = new goog.string.StringBuffer;
this.shouldAddSpaceAfterNationalPrefix_ = !1;
this.extractedNationalPrefix_ = "";
this.nationalNumber_ = new goog.string.StringBuffer;
this.possibleFormats_ = [];
this.defaultCountry_ = a;
this.defaultMetadata_ = this.currentMetadata_ = this.getMetadataForRegion_(this.defaultCountry_);
}n/a
ableToExtractLongerNdd_ = function () {
if (0 < this.extractedNationalPrefix_.length) {
var a = this.nationalNumber_.toString();
this.nationalNumber_.clear();
this.nationalNumber_.append(this.extractedNationalPrefix_);
this.nationalNumber_.append(a);
var a = this.prefixBeforeNationalNumber_.toString(), b = a.lastIndexOf(this.extractedNationalPrefix_);
this.prefixBeforeNationalNumber_.clear();
this.prefixBeforeNationalNumber_.append(a.substring(0, b));
}
return this.extractedNationalPrefix_ != this.removeNationalPrefixFromNationalNumber_();
}n/a
appendNationalNumber_ = function (a) {
var b = this.prefixBeforeNationalNumber_.getLength();
return this.shouldAddSpaceAfterNationalPrefix_ && 0 < b && this.prefixBeforeNationalNumber_.toString().charAt(b - 1) != i18n.phonenumbers
.AsYouTypeFormatter.SEPARATOR_BEFORE_NATIONAL_NUMBER_ ? this.prefixBeforeNationalNumber_ + i18n.phonenumbers.AsYouTypeFormatter.
SEPARATOR_BEFORE_NATIONAL_NUMBER_ + a : this.prefixBeforeNationalNumber_ + a;
}n/a
attemptToChooseFormattingPattern_ = function () {
var a = this.nationalNumber_.toString();
return a.length >= i18n.phonenumbers.AsYouTypeFormatter.MIN_LEADING_DIGITS_LENGTH_ ? (this.getAvailableFormats_(a), a = this.attemptToFormatAccruedDigits_
(), 0 < a.length ? a : this.maybeCreateNewTemplate_() ? this.inputAccruedNationalNumber_() : this.accruedInput_.toString()) : this
.appendNationalNumber_(a);
}n/a
attemptToChoosePatternWithPrefixExtracted_ = function () {
this.ableToFormat_ = !0;
this.isExpectingCountryCallingCode_ = !1;
this.possibleFormats_ = [];
this.lastMatchPosition_ = 0;
this.formattingTemplate_.clear();
this.currentFormattingPattern_ = "";
return this.attemptToChooseFormattingPattern_();
}n/a
attemptToExtractCountryCallingCode_ = function () {
if (0 == this.nationalNumber_.getLength()) {
return !1;
}
var a = new goog.string.StringBuffer, b = this.phoneUtil_.extractCountryCode(this.nationalNumber_, a);
if (0 == b) {
return !1;
}
this.nationalNumber_.clear();
this.nationalNumber_.append(a.toString());
a = this.phoneUtil_.getRegionCodeForCountryCode(b);
i18n.phonenumbers.PhoneNumberUtil.REGION_CODE_FOR_NON_GEO_ENTITY == a ? this.currentMetadata_ = this.phoneUtil_.getMetadataForNonGeographicalRegion
(b) : a != this.defaultCountry_ && (this.currentMetadata_ = this.getMetadataForRegion_(a));
this.prefixBeforeNationalNumber_.append("" + b).append(i18n.phonenumbers.AsYouTypeFormatter.SEPARATOR_BEFORE_NATIONAL_NUMBER_);
this.extractedNationalPrefix_ = "";
return !0;
}n/a
attemptToExtractIdd_ = function () {
var a = this.accruedInputWithoutFormatting_.toString(), b = new RegExp("^(?:\\" + i18n.phonenumbers.PhoneNumberUtil.PLUS_SIGN + "|" +
this.currentMetadata_.getInternationalPrefix() + ")"), b = a.match(b);
return null != b && null != b[0] && 0 < b[0].length ? (this.isCompleteNumber_ = !0, b = b[0].length, this.nationalNumber_.clear
(), this.nationalNumber_.append(a.substring(b)), this.prefixBeforeNationalNumber_.clear(), this.prefixBeforeNationalNumber_.append
(a.substring(0, b)), a.charAt(0) != i18n.phonenumbers.PhoneNumberUtil.PLUS_SIGN && this.prefixBeforeNationalNumber_.append(i18n.
phonenumbers.AsYouTypeFormatter.SEPARATOR_BEFORE_NATIONAL_NUMBER_), !0) : !1;
}n/a
attemptToFormatAccruedDigits_ = function () {
for (var a = this.nationalNumber_.toString(), b = this.possibleFormats_.length, c = 0;c < b;++c) {
var d = this.possibleFormats_[c], e = d.getPatternOrDefault();
if ((new RegExp("^(?:" + e + ")$")).test(a)) {
return this.shouldAddSpaceAfterNationalPrefix_ = i18n.phonenumbers.AsYouTypeFormatter.NATIONAL_PREFIX_SEPARATORS_PATTERN_.
test(d.getNationalPrefixFormattingRule()), a = a.replace(new RegExp(e, "g"), d.getFormat()), this.appendNationalNumber_(a);
}
}
return "";
}n/a
clear = function () {
this.currentOutput_ = "";
this.accruedInput_.clear();
this.accruedInputWithoutFormatting_.clear();
this.formattingTemplate_.clear();
this.lastMatchPosition_ = 0;
this.currentFormattingPattern_ = "";
this.prefixBeforeNationalNumber_.clear();
this.extractedNationalPrefix_ = "";
this.nationalNumber_.clear();
this.ableToFormat_ = !0;
this.inputHasFormatting_ = !1;
this.originalPosition_ = this.positionToRemember_ = 0;
this.isExpectingCountryCallingCode_ = this.isCompleteNumber_ = !1;
this.possibleFormats_ = [];
this.shouldAddSpaceAfterNationalPrefix_ = !1;
this.currentMetadata_ != this.defaultMetadata_ && (this.currentMetadata_ = this.getMetadataForRegion_(this.defaultCountry_));
}...
console.log(formatter.inputDigit('0')); // => 650
console.log(formatter.inputDigit('2')); // => 650-2
console.log(formatter.inputDigit('5')); // => 650-25
console.log(formatter.inputDigit('3')); // => 650-253
console.log(formatter.inputDigit('2')); // => 650-2532
console.log(formatter.inputDigit('2')); // => (650) 253-22
formatter.clear();
```
## Notes
### Differences from other forks
* All classes available from `libphonenumber` are exported as-is. No magic methods.
...createFormattingTemplate_ = function (a) {
var b = a.getPatternOrDefault();
if (-1 != b.indexOf("|")) {
return !1;
}
b = b.replace(i18n.phonenumbers.AsYouTypeFormatter.CHARACTER_CLASS_PATTERN_, "\\d");
b = b.replace(i18n.phonenumbers.AsYouTypeFormatter.STANDALONE_DIGIT_PATTERN_, "\\d");
this.formattingTemplate_.clear();
a = this.getFormattingTemplate_(b, a.getFormatOrDefault());
return 0 < a.length ? (this.formattingTemplate_.append(a), !0) : !1;
}n/a
getAvailableFormats_ = function (a) {
for (var b = this.isCompleteNumber_ && 0 < this.currentMetadata_.intlNumberFormatCount() ? this.currentMetadata_.intlNumberFormatArray
() : this.currentMetadata_.numberFormatArray(), c = b.length, d = 0;d < c;++d) {
var e = b[d];
(!this.currentMetadata_.hasNationalPrefix() || this.isCompleteNumber_ || e.getNationalPrefixOptionalWhenFormatting() || this
.phoneUtil_.formattingRuleHasFirstGroupOnly(e.getNationalPrefixFormattingRuleOrDefault())) && this.isFormatEligible_(e.getFormatOrDefault
()) && this.possibleFormats_.push(e);
}
this.narrowDownPossibleFormats_(a);
}n/a
getExtractedNationalPrefix_ = function () {
return this.extractedNationalPrefix_;
}n/a
getFormattingTemplate_ = function (a, b) {
var c = "999999999999999".match(a)[0];
if (c.length < this.nationalNumber_.getLength()) {
return "";
}
c = c.replace(new RegExp(a, "g"), b);
return c = c.replace(RegExp("9", "g"), this.DIGIT_PLACEHOLDER_);
}n/a
getMetadataForRegion_ = function (a) {
a = this.phoneUtil_.getCountryCodeForRegion(a);
a = this.phoneUtil_.getRegionCodeForCountryCode(a);
a = this.phoneUtil_.getMetadataForRegion(a);
return null != a ? a : i18n.phonenumbers.AsYouTypeFormatter.EMPTY_METADATA_;
}n/a
getRememberedPosition = function () {
if (!this.ableToFormat_) {
return this.originalPosition_;
}
for (var a = 0, b = 0, c = this.accruedInputWithoutFormatting_.toString(), d = this.currentOutput_.toString();a < this.positionToRemember_
&& b < d.length;) {
c.charAt(a) == d.charAt(b) && a++, b++;
}
return b;
}n/a
inputAccruedNationalNumber_ = function () {
var a = this.nationalNumber_.toString(), b = a.length;
if (0 < b) {
for (var c = "", d = 0;d < b;d++) {
c = this.inputDigitHelper_(a.charAt(d));
}
return this.ableToFormat_ ? this.appendNationalNumber_(c) : this.accruedInput_.toString();
}
return this.prefixBeforeNationalNumber_.toString();
}n/a
inputDigit = function (a) {
return this.currentOutput_ = this.inputDigitWithOptionToRememberPosition_(a, !1);
}...
#### Using the "As You Type" Formatter
```js
// Require `AsYouTypeFormatter`.
var AsYouTypeFormatter = require('google-libphonenumber').AsYouTypeFormatter;
var formatter = new AsYouTypeFormatter('US');
console.log(formatter.inputDigit('6')); // => 6
console.log(formatter.inputDigit('5')); // => 65
console.log(formatter.inputDigit('0')); // => 650
console.log(formatter.inputDigit('2')); // => 650-2
console.log(formatter.inputDigit('5')); // => 650-25
console.log(formatter.inputDigit('3')); // => 650-253
console.log(formatter.inputDigit('2')); // => 650-2532
console.log(formatter.inputDigit('2')); // => (650) 253-22
...inputDigitAndRememberPosition = function (a) {
return this.currentOutput_ = this.inputDigitWithOptionToRememberPosition_(a, !0);
}n/a
inputDigitHelper_ = function (a) {
var b = this.formattingTemplate_.toString();
if (0 <= b.substring(this.lastMatchPosition_).search(this.DIGIT_PATTERN_)) {
var c = b.search(this.DIGIT_PATTERN_);
a = b.replace(this.DIGIT_PATTERN_, a);
this.formattingTemplate_.clear();
this.formattingTemplate_.append(a);
this.lastMatchPosition_ = c;
return a.substring(0, this.lastMatchPosition_ + 1);
}
1 == this.possibleFormats_.length && (this.ableToFormat_ = !1);
this.currentFormattingPattern_ = "";
return this.accruedInput_.toString();
}n/a
inputDigitWithOptionToRememberPosition_ = function (a, b) {
this.accruedInput_.append(a);
b && (this.originalPosition_ = this.accruedInput_.getLength());
this.isDigitOrLeadingPlusSign_(a) ? a = this.normalizeAndAccrueDigitsAndPlusSign_(a, b) : (this.ableToFormat_ = !1, this.inputHasFormatting_
= !0);
if (!this.ableToFormat_) {
if (!this.inputHasFormatting_) {
if (this.attemptToExtractIdd_()) {
if (this.attemptToExtractCountryCallingCode_()) {
return this.attemptToChoosePatternWithPrefixExtracted_();
}
} else {
if (this.ableToExtractLongerNdd_()) {
return this.prefixBeforeNationalNumber_.append(i18n.phonenumbers.AsYouTypeFormatter.SEPARATOR_BEFORE_NATIONAL_NUMBER_),
this.attemptToChoosePatternWithPrefixExtracted_();
}
}
}
return this.accruedInput_.toString();
}
switch(this.accruedInputWithoutFormatting_.getLength()) {
case 0:
case 1:
case 2:
return this.accruedInput_.toString();
case 3:
if (this.attemptToExtractIdd_()) {
this.isExpectingCountryCallingCode_ = !0;
} else {
return this.extractedNationalPrefix_ = this.removeNationalPrefixFromNationalNumber_(), this.attemptToChooseFormattingPattern_
();
}
default:
if (this.isExpectingCountryCallingCode_) {
return this.attemptToExtractCountryCallingCode_() && (this.isExpectingCountryCallingCode_ = !1), this.prefixBeforeNationalNumber_
.toString() + this.nationalNumber_.toString();
}
if (0 < this.possibleFormats_.length) {
var c = this.inputDigitHelper_(a), d = this.attemptToFormatAccruedDigits_();
if (0 < d.length) {
return d;
}
this.narrowDownPossibleFormats_(this.nationalNumber_.toString());
return this.maybeCreateNewTemplate_() ? this.inputAccruedNationalNumber_() : this.ableToFormat_ ? this.appendNationalNumber_
(c) : this.accruedInput_.toString();
}
return this.attemptToChooseFormattingPattern_();
}
}n/a
isDigitOrLeadingPlusSign_ = function (a) {
return i18n.phonenumbers.PhoneNumberUtil.CAPTURING_DIGIT_PATTERN.test(a) || 1 == this.accruedInput_.getLength() && i18n.phonenumbers
.PhoneNumberUtil.PLUS_CHARS_PATTERN.test(a);
}n/a
isFormatEligible_ = function (a) {
return i18n.phonenumbers.AsYouTypeFormatter.ELIGIBLE_FORMAT_PATTERN_.test(a);
}n/a
isNanpaNumberWithNationalPrefix_ = function () {
if (1 != this.currentMetadata_.getCountryCode()) {
return !1;
}
var a = this.nationalNumber_.toString();
return "1" == a.charAt(0) && "0" != a.charAt(1) && "1" != a.charAt(1);
}n/a
maybeCreateNewTemplate_ = function () {
for (var a = this.possibleFormats_.length, b = 0;b < a;++b) {
var c = this.possibleFormats_[b], d = c.getPatternOrDefault();
if (this.currentFormattingPattern_ == d) {
return !1;
}
if (this.createFormattingTemplate_(c)) {
return this.currentFormattingPattern_ = d, this.shouldAddSpaceAfterNationalPrefix_ = i18n.phonenumbers.AsYouTypeFormatter.
NATIONAL_PREFIX_SEPARATORS_PATTERN_.test(c.getNationalPrefixFormattingRule()), this.lastMatchPosition_ = 0, !0;
}
}
return this.ableToFormat_ = !1;
}n/a
narrowDownPossibleFormats_ = function (a) {
for (var b = [], c = a.length - i18n.phonenumbers.AsYouTypeFormatter.MIN_LEADING_DIGITS_LENGTH_, d = this.possibleFormats_.length
, e = 0;e < d;++e) {
var f = this.possibleFormats_[e];
if (0 == f.leadingDigitsPatternCount()) {
b.push(this.possibleFormats_[e]);
} else {
var g = Math.min(c, f.leadingDigitsPatternCount() - 1), f = f.getLeadingDigitsPattern(g);
0 == a.search(f) && b.push(this.possibleFormats_[e]);
}
}
this.possibleFormats_ = b;
}n/a
normalizeAndAccrueDigitsAndPlusSign_ = function (a, b) {
var c;
a == i18n.phonenumbers.PhoneNumberUtil.PLUS_SIGN ? (c = a, this.accruedInputWithoutFormatting_.append(a)) : (c = i18n.phonenumbers
.PhoneNumberUtil.DIGIT_MAPPINGS[a], this.accruedInputWithoutFormatting_.append(c), this.nationalNumber_.append(c));
b && (this.positionToRemember_ = this.accruedInputWithoutFormatting_.getLength());
return c;
}n/a
removeNationalPrefixFromNationalNumber_ = function () {
var a = this.nationalNumber_.toString(), b = 0;
if (this.isNanpaNumberWithNationalPrefix_()) {
b = 1, this.prefixBeforeNationalNumber_.append("1").append(i18n.phonenumbers.AsYouTypeFormatter.SEPARATOR_BEFORE_NATIONAL_NUMBER_
), this.isCompleteNumber_ = !0;
} else {
if (this.currentMetadata_.hasNationalPrefixForParsing()) {
var c = new RegExp("^(?:" + this.currentMetadata_.getNationalPrefixForParsing() + ")"), c = a.match(c);
null != c && null != c[0] && 0 < c[0].length && (this.isCompleteNumber_ = !0, b = c[0].length, this.prefixBeforeNationalNumber_
.append(a.substring(0, b)));
}
}
this.nationalNumber_.clear();
this.nationalNumber_.append(a.substring(b));
return a.substring(0, b);
}n/a
NumberFormat = function () {
goog.proto2.Message.call(this);
}n/a
base = function (a, c, f) {
for (var d = Array(arguments.length - 2), e = 2;e < arguments.length;e++) {
d[e - 2] = arguments[e];
}
return b.prototype[c].apply(a, d);
}n/a
getDescriptor = function () {
var a = i18n.phonenumbers.NumberFormat.descriptor_;
a || (i18n.phonenumbers.NumberFormat.descriptor_ = a = goog.proto2.Message.createDescriptor(i18n.phonenumbers.NumberFormat, {0
:{name:"NumberFormat", fullName:"i18n.phonenumbers.NumberFormat"}, 1:{name:"pattern", required:!0, fieldType:goog.proto2.Message
.FieldType.STRING, type:String}, 2:{name:"format", required:!0, fieldType:goog.proto2.Message.FieldType.STRING, type:String}, 3:{
name:"leading_digits_pattern", repeated:!0, fieldType:goog.proto2.Message.FieldType.STRING, type:String}, 4:{name:"national_prefix_formatting_rule
",
fieldType:goog.proto2.Message.FieldType.STRING, type:String}, 6:{name:"national_prefix_optional_when_formatting", fieldType:goog
.proto2.Message.FieldType.BOOL, type:Boolean}, 5:{name:"domestic_carrier_code_formatting_rule", fieldType:goog.proto2.Message.FieldType
.STRING, type:String}}));
return a;
}n/a
addLeadingDigitsPattern = function (a) {
this.add$Value(3, a);
}n/a
clearDomesticCarrierCodeFormattingRule = function () {
this.clear$Field(5);
}n/a
clearFormat = function () {
this.clear$Field(2);
}n/a
clearLeadingDigitsPattern = function () {
this.clear$Field(3);
}n/a
clearNationalPrefixFormattingRule = function () {
this.clear$Field(4);
}n/a
clearNationalPrefixOptionalWhenFormatting = function () {
this.clear$Field(6);
}n/a
clearPattern = function () {
this.clear$Field(1);
}n/a
constructor = function () {
goog.proto2.Message.call(this);
}n/a
domesticCarrierCodeFormattingRuleCount = function () {
return this.count$Values(5);
}n/a
formatCount = function () {
return this.count$Values(2);
}n/a
getDescriptor = function () {
var a = i18n.phonenumbers.NumberFormat.descriptor_;
a || (i18n.phonenumbers.NumberFormat.descriptor_ = a = goog.proto2.Message.createDescriptor(i18n.phonenumbers.NumberFormat, {0
:{name:"NumberFormat", fullName:"i18n.phonenumbers.NumberFormat"}, 1:{name:"pattern", required:!0, fieldType:goog.proto2.Message
.FieldType.STRING, type:String}, 2:{name:"format", required:!0, fieldType:goog.proto2.Message.FieldType.STRING, type:String}, 3:{
name:"leading_digits_pattern", repeated:!0, fieldType:goog.proto2.Message.FieldType.STRING, type:String}, 4:{name:"national_prefix_formatting_rule
",
fieldType:goog.proto2.Message.FieldType.STRING, type:String}, 6:{name:"national_prefix_optional_when_formatting", fieldType:goog
.proto2.Message.FieldType.BOOL, type:Boolean}, 5:{name:"domestic_carrier_code_formatting_rule", fieldType:goog.proto2.Message.FieldType
.STRING, type:String}}));
return a;
}n/a
getDomesticCarrierCodeFormattingRule = function () {
return this.get$Value(5);
}n/a
getDomesticCarrierCodeFormattingRuleOrDefault = function () {
return this.get$ValueOrDefault(5);
}n/a
getFormat = function () {
return this.get$Value(2);
}n/a
getFormatOrDefault = function () {
return this.get$ValueOrDefault(2);
}n/a
getLeadingDigitsPattern = function (a) {
return this.get$Value(3, a);
}n/a
getLeadingDigitsPatternOrDefault = function (a) {
return this.get$ValueOrDefault(3, a);
}n/a
getNationalPrefixFormattingRule = function () {
return this.get$Value(4);
}n/a
getNationalPrefixFormattingRuleOrDefault = function () {
return this.get$ValueOrDefault(4);
}n/a
getNationalPrefixOptionalWhenFormatting = function () {
return this.get$Value(6);
}n/a
getNationalPrefixOptionalWhenFormattingOrDefault = function () {
return this.get$ValueOrDefault(6);
}n/a
getPattern = function () {
return this.get$Value(1);
}n/a
getPatternOrDefault = function () {
return this.get$ValueOrDefault(1);
}n/a
hasDomesticCarrierCodeFormattingRule = function () {
return this.has$Value(5);
}n/a
hasFormat = function () {
return this.has$Value(2);
}n/a
hasLeadingDigitsPattern = function () {
return this.has$Value(3);
}n/a
hasNationalPrefixFormattingRule = function () {
return this.has$Value(4);
}n/a
hasNationalPrefixOptionalWhenFormatting = function () {
return this.has$Value(6);
}n/a
hasPattern = function () {
return this.has$Value(1);
}n/a
leadingDigitsPatternArray = function () {
return this.array$Values(3);
}n/a
leadingDigitsPatternCount = function () {
return this.count$Values(3);
}n/a
nationalPrefixFormattingRuleCount = function () {
return this.count$Values(4);
}n/a
nationalPrefixOptionalWhenFormattingCount = function () {
return this.count$Values(6);
}n/a
patternCount = function () {
return this.count$Values(1);
}n/a
setDomesticCarrierCodeFormattingRule = function (a) {
this.set$Value(5, a);
}n/a
setFormat = function (a) {
this.set$Value(2, a);
}n/a
setNationalPrefixFormattingRule = function (a) {
this.set$Value(4, a);
}n/a
setNationalPrefixOptionalWhenFormatting = function (a) {
this.set$Value(6, a);
}n/a
setPattern = function (a) {
this.set$Value(1, a);
}n/a
add = function (a, b) {
goog.asserts.assert(a.getContainingType() == this.getDescriptor(), "The current message does not contain the given field");
this.add$Value(a.getTag(), b);
}n/a
arrayOf = function (a) {
goog.asserts.assert(a.getContainingType() == this.getDescriptor(), "The current message does not contain the given field");
return this.array$Values(a.getTag());
}n/a
checkFieldType_ = function (a, b) {
a.getFieldType() == goog.proto2.FieldDescriptor.FieldType.ENUM ? goog.asserts.assertNumber(b) : goog.asserts.assert(Object(b).
constructor == a.getNativeType());
}n/a
clear = function (a) {
goog.asserts.assert(a.getContainingType() == this.getDescriptor(), "The current message does not contain the given field");
this.clear$Field(a.getTag());
}...
console.log(formatter.inputDigit('0')); // => 650
console.log(formatter.inputDigit('2')); // => 650-2
console.log(formatter.inputDigit('5')); // => 650-25
console.log(formatter.inputDigit('3')); // => 650-253
console.log(formatter.inputDigit('2')); // => 650-2532
console.log(formatter.inputDigit('2')); // => (650) 253-22
formatter.clear();
```
## Notes
### Differences from other forks
* All classes available from `libphonenumber` are exported as-is. No magic methods.
...clone = function () {
var a = new this.constructor;
a.copyFrom(this);
return a;
}n/a
copyFrom = function (a) {
goog.asserts.assert(this.constructor == a.constructor, "The source message must have the same type.");
this != a && (this.values_ = {}, this.deserializedFields_ && (this.deserializedFields_ = {}), this.mergeFrom(a));
}n/a
countOf = function (a) {
goog.asserts.assert(a.getContainingType() == this.getDescriptor(), "The current message does not contain the given field");
return this.count$Values(a.getTag());
}n/a
equals = function (a) {
if (!a || this.constructor != a.constructor) {
return !1;
}
for (var b = this.getDescriptor().getFields(), c = 0;c < b.length;c++) {
var d = b[c], e = d.getTag();
if (this.has$Value(e) != a.has$Value(e)) {
return !1;
}
if (this.has$Value(e)) {
var f = d.isCompositeType(), g = this.getValueForTag_(e), e = a.getValueForTag_(e);
if (d.isRepeated()) {
if (g.length != e.length) {
return !1;
}
for (d = 0;d < g.length;d++) {
var h = g[d], k = e[d];
if (f ? !h.equals(k) : h != k) {
return !1;
}
}
} else {
if (f ? !g.equals(e) : g != e) {
return !1;
}
}
}
}
return !0;
}n/a
forEachUnknown = function (a, b) {
var c = b || this, d;
for (d in this.values_) {
var e = Number(d);
this.fields_[e] || a.call(c, e, this.values_[d]);
}
}n/a
get = function (a, b) {
goog.asserts.assert(a.getContainingType() == this.getDescriptor(), "The current message does not contain the given field");
return this.get$Value(a.getTag(), b);
}n/a
getDescriptor = function () {
throw Error("unimplemented abstract method");
}n/a
getOrDefault = function (a, b) {
goog.asserts.assert(a.getContainingType() == this.getDescriptor(), "The current message does not contain the given field");
return this.get$ValueOrDefault(a.getTag(), b);
}n/a
getValueForTag_ = function (a) {
var b = this.values_[a];
return goog.isDefAndNotNull(b) ? this.lazyDeserializer_ ? a in this.deserializedFields_ ? this.deserializedFields_[a] : (b = this
.lazyDeserializer_.deserializeField(this, this.fields_[a], b), this.deserializedFields_[a] = b) : b : null;
}n/a
has = function (a) {
goog.asserts.assert(a.getContainingType() == this.getDescriptor(), "The current message does not contain the given field");
return this.has$Value(a.getTag());
}n/a
initDefaults = function (a) {
for (var b = this.getDescriptor().getFields(), c = 0;c < b.length;c++) {
var d = b[c], e = d.getTag(), f = d.isCompositeType();
this.has$Value(e) || d.isRepeated() || (f ? this.values_[e] = new (d.getNativeType()) : a && (this.values_[e] = d.getDefaultValue
()));
if (f) {
if (d.isRepeated()) {
for (d = this.array$Values(e), e = 0;e < d.length;e++) {
d[e].initDefaults(a);
}
} else {
this.get$Value(e).initDefaults(a);
}
}
}
}n/a
initializeForLazyDeserializer = function (a, b) {
this.lazyDeserializer_ = a;
this.values_ = b;
this.deserializedFields_ = {};
}n/a
mergeFrom = function (a) {
goog.asserts.assert(this.constructor == a.constructor, "The source message must have the same type.");
for (var b = this.getDescriptor().getFields(), c = 0;c < b.length;c++) {
var d = b[c], e = d.getTag();
if (a.has$Value(e)) {
this.deserializedFields_ && delete this.deserializedFields_[d.getTag()];
var f = d.isCompositeType();
if (d.isRepeated()) {
for (var d = a.array$Values(e), g = 0;g < d.length;g++) {
this.add$Value(e, f ? d[g].clone() : d[g]);
}
} else {
d = a.getValueForTag_(e), f ? (f = this.getValueForTag_(e)) ? f.mergeFrom(d) : this.set$Value(e, d.clone()) : this.set$Value
(e, d);
}
}
}
}n/a
set = function (a, b) {
goog.asserts.assert(a.getContainingType() == this.getDescriptor(), "The current message does not contain the given field");
this.set$Value(a.getTag(), b);
}n/a
setUnknown = function (a, b) {
goog.asserts.assert(!this.fields_[a], "Field is not unknown in this message");
goog.asserts.assert(1 <= a, "Tag " + a + ' has value "' + b + '" in descriptor ' + this.getDescriptor().getName());
goog.asserts.assert(null !== b, "Value cannot be null");
this.values_[a] = b;
this.deserializedFields_ && delete this.deserializedFields_[a];
}n/a
PhoneMetadata = function () {
goog.proto2.Message.call(this);
}n/a
base = function (a, c, f) {
for (var d = Array(arguments.length - 2), e = 2;e < arguments.length;e++) {
d[e - 2] = arguments[e];
}
return b.prototype[c].apply(a, d);
}n/a
getDescriptor = function () {
var a = i18n.phonenumbers.PhoneMetadata.descriptor_;
a || (i18n.phonenumbers.PhoneMetadata.descriptor_ = a = goog.proto2.Message.createDescriptor(i18n.phonenumbers.PhoneMetadata, {
0:{name:"PhoneMetadata", fullName:"i18n.phonenumbers.PhoneMetadata"}, 1:{name:"general_desc", fieldType:goog.proto2.Message.FieldType
.MESSAGE, type:i18n.phonenumbers.PhoneNumberDesc}, 2:{name:"fixed_line", fieldType:goog.proto2.Message.FieldType.MESSAGE, type:i18n
.phonenumbers.PhoneNumberDesc}, 3:{name:"mobile", fieldType:goog.proto2.Message.FieldType.MESSAGE, type:i18n.phonenumbers.PhoneNumberDesc
},
4:{name:"toll_free", fieldType:goog.proto2.Message.FieldType.MESSAGE, type:i18n.phonenumbers.PhoneNumberDesc}, 5:{name:"premium_rate
", fieldType:goog.proto2.Message.FieldType.MESSAGE, type:i18n.phonenumbers.PhoneNumberDesc}, 6:{name:"shared_cost", fieldType:goog
.proto2.Message.FieldType.MESSAGE, type:i18n.phonenumbers.PhoneNumberDesc}, 7:{name:"personal_number", fieldType:goog.proto2.Message
.FieldType.MESSAGE, type:i18n.phonenumbers.PhoneNumberDesc}, 8:{name:"voip", fieldType:goog.proto2.Message.FieldType.MESSAGE,
type:i18n.phonenumbers.PhoneNumberDesc}, 21:{name:"pager", fieldType:goog.proto2.Message.FieldType.MESSAGE, type:i18n.phonenumbers
.PhoneNumberDesc}, 25:{name:"uan", fieldType:goog.proto2.Message.FieldType.MESSAGE, type:i18n.phonenumbers.PhoneNumberDesc}, 27:{
name:"emergency", fieldType:goog.proto2.Message.FieldType.MESSAGE, type:i18n.phonenumbers.PhoneNumberDesc}, 28:{name:"voicemail",
fieldType:goog.proto2.Message.FieldType.MESSAGE, type:i18n.phonenumbers.PhoneNumberDesc}, 24:{name:"no_international_dialling",
fieldType:goog.proto2.Message.FieldType.MESSAGE, type:i18n.phonenumbers.PhoneNumberDesc}, 9:{name:"id", required:!0, fieldType
:goog.proto2.Message.FieldType.STRING, type:String}, 10:{name:"country_code", fieldType:goog.proto2.Message.FieldType.INT32, type
:Number}, 11:{name:"international_prefix", fieldType:goog.proto2.Message.FieldType.STRING, type:String}, 17:{name:"preferred_international_prefix
", fieldType:goog.proto2.Message.FieldType.STRING, type:String}, 12:{name:"national_prefix", fieldType:goog.proto2.Message.FieldType
.STRING,
type:String}, 13:{name:"preferred_extn_prefix", fieldType:goog.proto2.Message.FieldType.STRING, type:String}, 15:{name:"national_prefix_for_parsing
", fieldType:goog.proto2.Message.FieldType.STRING, type:String}, 16:{name:"national_prefix_transform_rule", fieldType:goog.proto2
.Message.FieldType.STRING, type:String}, 18:{name:"same_mobile_and_fixed_line_pattern", fieldType:goog.proto2.Message.FieldType.
BOOL, defaultValue:!1, type:Boolean}, 19:{name:"number_format", repeated:!0, fieldType:goog.proto2.Message.FieldType.MESSAGE,
type:i18n.phonenumbers.NumberFormat}, 20:{name:"intl_number_format", repeated:!0, fieldType:goog.proto2.Message.FieldType.MESSAGE
, type:i18n.phonenumbers.NumberFormat}, 22:{name:"main_country_for_code", fieldType:goog.proto2.Message.FieldType.BOOL, defaultValue
:!1, type:Boolean}, 23:{name:"leading_digits", fieldType:goog.proto2.Message.FieldType.STRING, type:String}, 26:{name:"leading_zero_possible
", fieldType:goog.proto2.Message.FieldType.BOOL, defaultValue:!1, type:Boolean}}));
return a;
}n/a
messageType_ = function () {
goog.proto2.Message.call(this);
}n/a
addIntlNumberFormat = function (a) {
this.add$Value(20, a);
}n/a
addNumberFormat = function (a) {
this.add$Value(19, a);
}n/a
clearCountryCode = function () {
this.clear$Field(10);
}n/a
clearEmergency = function () {
this.clear$Field(27);
}n/a
clearFixedLine = function () {
this.clear$Field(2);
}n/a
clearGeneralDesc = function () {
this.clear$Field(1);
}n/a
clearId = function () {
this.clear$Field(9);
}n/a
clearInternationalPrefix = function () {
this.clear$Field(11);
}n/a
clearIntlNumberFormat = function () {
this.clear$Field(20);
}n/a
clearLeadingDigits = function () {
this.clear$Field(23);
}n/a
clearLeadingZeroPossible = function () {
this.clear$Field(26);
}n/a
clearMainCountryForCode = function () {
this.clear$Field(22);
}n/a
clearMobile = function () {
this.clear$Field(3);
}n/a
clearNationalPrefix = function () {
this.clear$Field(12);
}n/a
clearNationalPrefixForParsing = function () {
this.clear$Field(15);
}n/a
clearNationalPrefixTransformRule = function () {
this.clear$Field(16);
}n/a
clearNoInternationalDialling = function () {
this.clear$Field(24);
}n/a
clearNumberFormat = function () {
this.clear$Field(19);
}n/a
clearPager = function () {
this.clear$Field(21);
}n/a
clearPersonalNumber = function () {
this.clear$Field(7);
}n/a
clearPreferredExtnPrefix = function () {
this.clear$Field(13);
}n/a
clearPreferredInternationalPrefix = function () {
this.clear$Field(17);
}n/a
clearPremiumRate = function () {
this.clear$Field(5);
}n/a
clearSameMobileAndFixedLinePattern = function () {
this.clear$Field(18);
}n/a
clearSharedCost = function () {
this.clear$Field(6);
}n/a
clearTollFree = function () {
this.clear$Field(4);
}n/a
clearUan = function () {
this.clear$Field(25);
}n/a
clearVoicemail = function () {
this.clear$Field(28);
}n/a
clearVoip = function () {
this.clear$Field(8);
}n/a
constructor = function () {
goog.proto2.Message.call(this);
}n/a
countryCodeCount = function () {
return this.count$Values(10);
}n/a
emergencyCount = function () {
return this.count$Values(27);
}n/a
fixedLineCount = function () {
return this.count$Values(2);
}n/a
generalDescCount = function () {
return this.count$Values(1);
}n/a
getCountryCode = function () {
return this.get$Value(10);
}n/a
getCountryCodeOrDefault = function () {
return this.get$ValueOrDefault(10);
}n/a
getDescriptor = function () {
var a = i18n.phonenumbers.PhoneMetadata.descriptor_;
a || (i18n.phonenumbers.PhoneMetadata.descriptor_ = a = goog.proto2.Message.createDescriptor(i18n.phonenumbers.PhoneMetadata, {
0:{name:"PhoneMetadata", fullName:"i18n.phonenumbers.PhoneMetadata"}, 1:{name:"general_desc", fieldType:goog.proto2.Message.FieldType
.MESSAGE, type:i18n.phonenumbers.PhoneNumberDesc}, 2:{name:"fixed_line", fieldType:goog.proto2.Message.FieldType.MESSAGE, type:i18n
.phonenumbers.PhoneNumberDesc}, 3:{name:"mobile", fieldType:goog.proto2.Message.FieldType.MESSAGE, type:i18n.phonenumbers.PhoneNumberDesc
},
4:{name:"toll_free", fieldType:goog.proto2.Message.FieldType.MESSAGE, type:i18n.phonenumbers.PhoneNumberDesc}, 5:{name:"premium_rate
", fieldType:goog.proto2.Message.FieldType.MESSAGE, type:i18n.phonenumbers.PhoneNumberDesc}, 6:{name:"shared_cost", fieldType:goog
.proto2.Message.FieldType.MESSAGE, type:i18n.phonenumbers.PhoneNumberDesc}, 7:{name:"personal_number", fieldType:goog.proto2.Message
.FieldType.MESSAGE, type:i18n.phonenumbers.PhoneNumberDesc}, 8:{name:"voip", fieldType:goog.proto2.Message.FieldType.MESSAGE,
type:i18n.phonenumbers.PhoneNumberDesc}, 21:{name:"pager", fieldType:goog.proto2.Message.FieldType.MESSAGE, type:i18n.phonenumbers
.PhoneNumberDesc}, 25:{name:"uan", fieldType:goog.proto2.Message.FieldType.MESSAGE, type:i18n.phonenumbers.PhoneNumberDesc}, 27:{
name:"emergency", fieldType:goog.proto2.Message.FieldType.MESSAGE, type:i18n.phonenumbers.PhoneNumberDesc}, 28:{name:"voicemail",
fieldType:goog.proto2.Message.FieldType.MESSAGE, type:i18n.phonenumbers.PhoneNumberDesc}, 24:{name:"no_international_dialling",
fieldType:goog.proto2.Message.FieldType.MESSAGE, type:i18n.phonenumbers.PhoneNumberDesc}, 9:{name:"id", required:!0, fieldType
:goog.proto2.Message.FieldType.STRING, type:String}, 10:{name:"country_code", fieldType:goog.proto2.Message.FieldType.INT32, type
:Number}, 11:{name:"international_prefix", fieldType:goog.proto2.Message.FieldType.STRING, type:String}, 17:{name:"preferred_international_prefix
", fieldType:goog.proto2.Message.FieldType.STRING, type:String}, 12:{name:"national_prefix", fieldType:goog.proto2.Message.FieldType
.STRING,
type:String}, 13:{name:"preferred_extn_prefix", fieldType:goog.proto2.Message.FieldType.STRING, type:String}, 15:{name:"national_prefix_for_parsing
", fieldType:goog.proto2.Message.FieldType.STRING, type:String}, 16:{name:"national_prefix_transform_rule", fieldType:goog.proto2
.Message.FieldType.STRING, type:String}, 18:{name:"same_mobile_and_fixed_line_pattern", fieldType:goog.proto2.Message.FieldType.
BOOL, defaultValue:!1, type:Boolean}, 19:{name:"number_format", repeated:!0, fieldType:goog.proto2.Message.FieldType.MESSAGE,
type:i18n.phonenumbers.NumberFormat}, 20:{name:"intl_number_format", repeated:!0, fieldType:goog.proto2.Message.FieldType.MESSAGE
, type:i18n.phonenumbers.NumberFormat}, 22:{name:"main_country_for_code", fieldType:goog.proto2.Message.FieldType.BOOL, defaultValue
:!1, type:Boolean}, 23:{name:"leading_digits", fieldType:goog.proto2.Message.FieldType.STRING, type:String}, 26:{name:"leading_zero_possible
", fieldType:goog.proto2.Message.FieldType.BOOL, defaultValue:!1, type:Boolean}}));
return a;
}n/a
getEmergency = function () {
return this.get$Value(27);
}n/a
getEmergencyOrDefault = function () {
return this.get$ValueOrDefault(27);
}n/a
getFixedLine = function () {
return this.get$Value(2);
}n/a
getFixedLineOrDefault = function () {
return this.get$ValueOrDefault(2);
}n/a
getGeneralDesc = function () {
return this.get$Value(1);
}n/a
getGeneralDescOrDefault = function () {
return this.get$ValueOrDefault(1);
}n/a
getId = function () {
return this.get$Value(9);
}n/a
getIdOrDefault = function () {
return this.get$ValueOrDefault(9);
}n/a
getInternationalPrefix = function () {
return this.get$Value(11);
}n/a
getInternationalPrefixOrDefault = function () {
return this.get$ValueOrDefault(11);
}n/a
getIntlNumberFormat = function (a) {
return this.get$Value(20, a);
}n/a
getIntlNumberFormatOrDefault = function (a) {
return this.get$ValueOrDefault(20, a);
}n/a
getLeadingDigits = function () {
return this.get$Value(23);
}n/a
getLeadingDigitsOrDefault = function () {
return this.get$ValueOrDefault(23);
}n/a
getLeadingZeroPossible = function () {
return this.get$Value(26);
}n/a
getLeadingZeroPossibleOrDefault = function () {
return this.get$ValueOrDefault(26);
}n/a
getMainCountryForCode = function () {
return this.get$Value(22);
}n/a
getMainCountryForCodeOrDefault = function () {
return this.get$ValueOrDefault(22);
}n/a
getMobile = function () {
return this.get$Value(3);
}n/a
getMobileOrDefault = function () {
return this.get$ValueOrDefault(3);
}n/a
getNationalPrefix = function () {
return this.get$Value(12);
}n/a
getNationalPrefixForParsing = function () {
return this.get$Value(15);
}n/a
getNationalPrefixForParsingOrDefault = function () {
return this.get$ValueOrDefault(15);
}n/a
getNationalPrefixOrDefault = function () {
return this.get$ValueOrDefault(12);
}n/a
getNationalPrefixTransformRule = function () {
return this.get$Value(16);
}n/a
getNationalPrefixTransformRuleOrDefault = function () {
return this.get$ValueOrDefault(16);
}n/a
getNoInternationalDialling = function () {
return this.get$Value(24);
}n/a
getNoInternationalDiallingOrDefault = function () {
return this.get$ValueOrDefault(24);
}n/a
getNumberFormat = function (a) {
return this.get$Value(19, a);
}n/a
getNumberFormatOrDefault = function (a) {
return this.get$ValueOrDefault(19, a);
}n/a
getPager = function () {
return this.get$Value(21);
}n/a
getPagerOrDefault = function () {
return this.get$ValueOrDefault(21);
}n/a
getPersonalNumber = function () {
return this.get$Value(7);
}n/a
getPersonalNumberOrDefault = function () {
return this.get$ValueOrDefault(7);
}n/a
getPreferredExtnPrefix = function () {
return this.get$Value(13);
}n/a
getPreferredExtnPrefixOrDefault = function () {
return this.get$ValueOrDefault(13);
}n/a
getPreferredInternationalPrefix = function () {
return this.get$Value(17);
}n/a
getPreferredInternationalPrefixOrDefault = function () {
return this.get$ValueOrDefault(17);
}n/a
getPremiumRate = function () {
return this.get$Value(5);
}n/a
getPremiumRateOrDefault = function () {
return this.get$ValueOrDefault(5);
}n/a
getSameMobileAndFixedLinePattern = function () {
return this.get$Value(18);
}n/a
getSameMobileAndFixedLinePatternOrDefault = function () {
return this.get$ValueOrDefault(18);
}n/a
getSharedCost = function () {
return this.get$Value(6);
}n/a
getSharedCostOrDefault = function () {
return this.get$ValueOrDefault(6);
}n/a
getTollFree = function () {
return this.get$Value(4);
}n/a
getTollFreeOrDefault = function () {
return this.get$ValueOrDefault(4);
}n/a
getUan = function () {
return this.get$Value(25);
}n/a
getUanOrDefault = function () {
return this.get$ValueOrDefault(25);
}n/a
getVoicemail = function () {
return this.get$Value(28);
}n/a
getVoicemailOrDefault = function () {
return this.get$ValueOrDefault(28);
}n/a
getVoip = function () {
return this.get$Value(8);
}n/a
getVoipOrDefault = function () {
return this.get$ValueOrDefault(8);
}n/a
hasCountryCode = function () {
return this.has$Value(10);
}n/a
hasEmergency = function () {
return this.has$Value(27);
}n/a
hasFixedLine = function () {
return this.has$Value(2);
}n/a
hasGeneralDesc = function () {
return this.has$Value(1);
}n/a
hasId = function () {
return this.has$Value(9);
}n/a
hasInternationalPrefix = function () {
return this.has$Value(11);
}n/a
hasIntlNumberFormat = function () {
return this.has$Value(20);
}n/a
hasLeadingDigits = function () {
return this.has$Value(23);
}n/a
hasLeadingZeroPossible = function () {
return this.has$Value(26);
}n/a
hasMainCountryForCode = function () {
return this.has$Value(22);
}n/a
hasMobile = function () {
return this.has$Value(3);
}n/a
hasNationalPrefix = function () {
return this.has$Value(12);
}n/a
hasNationalPrefixForParsing = function () {
return this.has$Value(15);
}n/a
hasNationalPrefixTransformRule = function () {
return this.has$Value(16);
}n/a
hasNoInternationalDialling = function () {
return this.has$Value(24);
}n/a
hasNumberFormat = function () {
return this.has$Value(19);
}n/a
hasPager = function () {
return this.has$Value(21);
}n/a
hasPersonalNumber = function () {
return this.has$Value(7);
}n/a
hasPreferredExtnPrefix = function () {
return this.has$Value(13);
}n/a
hasPreferredInternationalPrefix = function () {
return this.has$Value(17);
}n/a
hasPremiumRate = function () {
return this.has$Value(5);
}n/a
hasSameMobileAndFixedLinePattern = function () {
return this.has$Value(18);
}n/a
hasSharedCost = function () {
return this.has$Value(6);
}n/a
hasTollFree = function () {
return this.has$Value(4);
}n/a
hasUan = function () {
return this.has$Value(25);
}n/a
hasVoicemail = function () {
return this.has$Value(28);
}n/a
hasVoip = function () {
return this.has$Value(8);
}n/a
idCount = function () {
return this.count$Values(9);
}n/a
internationalPrefixCount = function () {
return this.count$Values(11);
}n/a
intlNumberFormatArray = function () {
return this.array$Values(20);
}n/a
intlNumberFormatCount = function () {
return this.count$Values(20);
}n/a
leadingDigitsCount = function () {
return this.count$Values(23);
}n/a
leadingZeroPossibleCount = function () {
return this.count$Values(26);
}n/a
mainCountryForCodeCount = function () {
return this.count$Values(22);
}n/a
mobileCount = function () {
return this.count$Values(3);
}n/a
nationalPrefixCount = function () {
return this.count$Values(12);
}n/a
nationalPrefixForParsingCount = function () {
return this.count$Values(15);
}n/a
nationalPrefixTransformRuleCount = function () {
return this.count$Values(16);
}n/a
noInternationalDiallingCount = function () {
return this.count$Values(24);
}n/a
numberFormatArray = function () {
return this.array$Values(19);
}n/a
numberFormatCount = function () {
return this.count$Values(19);
}n/a
pagerCount = function () {
return this.count$Values(21);
}n/a
personalNumberCount = function () {
return this.count$Values(7);
}n/a
preferredExtnPrefixCount = function () {
return this.count$Values(13);
}n/a
preferredInternationalPrefixCount = function () {
return this.count$Values(17);
}n/a
premiumRateCount = function () {
return this.count$Values(5);
}n/a
sameMobileAndFixedLinePatternCount = function () {
return this.count$Values(18);
}n/a
setCountryCode = function (a) {
this.set$Value(10, a);
}n/a
setEmergency = function (a) {
this.set$Value(27, a);
}n/a
setFixedLine = function (a) {
this.set$Value(2, a);
}n/a
setGeneralDesc = function (a) {
this.set$Value(1, a);
}n/a
setId = function (a) {
this.set$Value(9, a);
}n/a
setInternationalPrefix = function (a) {
this.set$Value(11, a);
}n/a
setLeadingDigits = function (a) {
this.set$Value(23, a);
}n/a
setLeadingZeroPossible = function (a) {
this.set$Value(26, a);
}n/a
setMainCountryForCode = function (a) {
this.set$Value(22, a);
}n/a
setMobile = function (a) {
this.set$Value(3, a);
}n/a
setNationalPrefix = function (a) {
this.set$Value(12, a);
}n/a
setNationalPrefixForParsing = function (a) {
this.set$Value(15, a);
}n/a
setNationalPrefixTransformRule = function (a) {
this.set$Value(16, a);
}n/a
setNoInternationalDialling = function (a) {
this.set$Value(24, a);
}n/a
setPager = function (a) {
this.set$Value(21, a);
}n/a
setPersonalNumber = function (a) {
this.set$Value(7, a);
}n/a
setPreferredExtnPrefix = function (a) {
this.set$Value(13, a);
}n/a
setPreferredInternationalPrefix = function (a) {
this.set$Value(17, a);
}n/a
setPremiumRate = function (a) {
this.set$Value(5, a);
}n/a
setSameMobileAndFixedLinePattern = function (a) {
this.set$Value(18, a);
}n/a
setSharedCost = function (a) {
this.set$Value(6, a);
}n/a
setTollFree = function (a) {
this.set$Value(4, a);
}n/a
setUan = function (a) {
this.set$Value(25, a);
}n/a
setVoicemail = function (a) {
this.set$Value(28, a);
}n/a
setVoip = function (a) {
this.set$Value(8, a);
}n/a
sharedCostCount = function () {
return this.count$Values(6);
}n/a
tollFreeCount = function () {
return this.count$Values(4);
}n/a
uanCount = function () {
return this.count$Values(25);
}n/a
voicemailCount = function () {
return this.count$Values(28);
}n/a
voipCount = function () {
return this.count$Values(8);
}n/a
PhoneMetadataCollection = function () {
goog.proto2.Message.call(this);
}n/a
base = function (a, c, f) {
for (var d = Array(arguments.length - 2), e = 2;e < arguments.length;e++) {
d[e - 2] = arguments[e];
}
return b.prototype[c].apply(a, d);
}n/a
getDescriptor = function () {
var a = i18n.phonenumbers.PhoneMetadataCollection.descriptor_;
a || (i18n.phonenumbers.PhoneMetadataCollection.descriptor_ = a = goog.proto2.Message.createDescriptor(i18n.phonenumbers.PhoneMetadataCollection
, {0:{name:"PhoneMetadataCollection", fullName:"i18n.phonenumbers.PhoneMetadataCollection"}, 1:{name:"metadata", repeated:!0, fieldType
:goog.proto2.Message.FieldType.MESSAGE, type:i18n.phonenumbers.PhoneMetadata}}));
return a;
}n/a
addMetadata = function (a) {
this.add$Value(1, a);
}n/a
clearMetadata = function () {
this.clear$Field(1);
}n/a
constructor = function () {
goog.proto2.Message.call(this);
}n/a
getDescriptor = function () {
var a = i18n.phonenumbers.PhoneMetadataCollection.descriptor_;
a || (i18n.phonenumbers.PhoneMetadataCollection.descriptor_ = a = goog.proto2.Message.createDescriptor(i18n.phonenumbers.PhoneMetadataCollection
, {0:{name:"PhoneMetadataCollection", fullName:"i18n.phonenumbers.PhoneMetadataCollection"}, 1:{name:"metadata", repeated:!0, fieldType
:goog.proto2.Message.FieldType.MESSAGE, type:i18n.phonenumbers.PhoneMetadata}}));
return a;
}n/a
getMetadata = function (a) {
return this.get$Value(1, a);
}n/a
getMetadataOrDefault = function (a) {
return this.get$ValueOrDefault(1, a);
}n/a
hasMetadata = function () {
return this.has$Value(1);
}n/a
metadataArray = function () {
return this.array$Values(1);
}n/a
metadataCount = function () {
return this.count$Values(1);
}n/a
PhoneNumber = function () {
goog.proto2.Message.call(this);
}n/a
base = function (a, c, f) {
for (var d = Array(arguments.length - 2), e = 2;e < arguments.length;e++) {
d[e - 2] = arguments[e];
}
return b.prototype[c].apply(a, d);
}n/a
ctor = function () {
goog.proto2.Message.call(this);
}n/a
getDescriptor = function () {
i18n.phonenumbers.PhoneNumber.descriptor_ || (i18n.phonenumbers.PhoneNumber.descriptor_ = goog.proto2.Message.createDescriptor
(i18n.phonenumbers.PhoneNumber, {0:{name:"PhoneNumber", fullName:"i18n.phonenumbers.PhoneNumber"}, 1:{name:"country_code", required
:!0, fieldType:goog.proto2.Message.FieldType.INT32, type:Number}, 2:{name:"national_number", required:!0, fieldType:goog.proto2.
Message.FieldType.UINT64, type:Number}, 3:{name:"extension", fieldType:goog.proto2.Message.FieldType.STRING, type:String},
4:{name:"italian_leading_zero", fieldType:goog.proto2.Message.FieldType.BOOL, type:Boolean}, 8:{name:"number_of_leading_zeros",
fieldType:goog.proto2.Message.FieldType.INT32, defaultValue:1, type:Number}, 5:{name:"raw_input", fieldType:goog.proto2.Message.
FieldType.STRING, type:String}, 6:{name:"country_code_source", fieldType:goog.proto2.Message.FieldType.ENUM, defaultValue:i18n.phonenumbers
.PhoneNumber.CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN, type:i18n.phonenumbers.PhoneNumber.CountryCodeSource},
7:{name:"preferred_domestic_carrier_code", fieldType:goog.proto2.Message.FieldType.STRING, type:String}}));
return i18n.phonenumbers.PhoneNumber.descriptor_;
}n/a
clearCountryCode = function () {
this.clear$Field(1);
}n/a
clearCountryCodeSource = function () {
this.clear$Field(6);
}n/a
clearExtension = function () {
this.clear$Field(3);
}n/a
clearItalianLeadingZero = function () {
this.clear$Field(4);
}n/a
clearNationalNumber = function () {
this.clear$Field(2);
}n/a
clearNumberOfLeadingZeros = function () {
this.clear$Field(8);
}n/a
clearPreferredDomesticCarrierCode = function () {
this.clear$Field(7);
}n/a
clearRawInput = function () {
this.clear$Field(5);
}n/a
constructor = function () {
goog.proto2.Message.call(this);
}n/a
countryCodeCount = function () {
return this.count$Values(1);
}n/a
countryCodeSourceCount = function () {
return this.count$Values(6);
}n/a
extensionCount = function () {
return this.count$Values(3);
}n/a
getCountryCode = function () {
return this.get$Value(1);
}n/a
getCountryCodeOrDefault = function () {
return this.get$ValueOrDefault(1);
}n/a
getCountryCodeSource = function () {
return this.get$Value(6);
}n/a
getCountryCodeSourceOrDefault = function () {
return this.get$ValueOrDefault(6);
}n/a
getDescriptor = function () {
i18n.phonenumbers.PhoneNumber.descriptor_ || (i18n.phonenumbers.PhoneNumber.descriptor_ = goog.proto2.Message.createDescriptor
(i18n.phonenumbers.PhoneNumber, {0:{name:"PhoneNumber", fullName:"i18n.phonenumbers.PhoneNumber"}, 1:{name:"country_code", required
:!0, fieldType:goog.proto2.Message.FieldType.INT32, type:Number}, 2:{name:"national_number", required:!0, fieldType:goog.proto2.
Message.FieldType.UINT64, type:Number}, 3:{name:"extension", fieldType:goog.proto2.Message.FieldType.STRING, type:String},
4:{name:"italian_leading_zero", fieldType:goog.proto2.Message.FieldType.BOOL, type:Boolean}, 8:{name:"number_of_leading_zeros",
fieldType:goog.proto2.Message.FieldType.INT32, defaultValue:1, type:Number}, 5:{name:"raw_input", fieldType:goog.proto2.Message.
FieldType.STRING, type:String}, 6:{name:"country_code_source", fieldType:goog.proto2.Message.FieldType.ENUM, defaultValue:i18n.phonenumbers
.PhoneNumber.CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN, type:i18n.phonenumbers.PhoneNumber.CountryCodeSource},
7:{name:"preferred_domestic_carrier_code", fieldType:goog.proto2.Message.FieldType.STRING, type:String}}));
return i18n.phonenumbers.PhoneNumber.descriptor_;
}n/a
getExtension = function () {
return this.get$Value(3);
}n/a
getExtensionOrDefault = function () {
return this.get$ValueOrDefault(3);
}n/a
getItalianLeadingZero = function () {
return this.get$Value(4);
}n/a
getItalianLeadingZeroOrDefault = function () {
return this.get$ValueOrDefault(4);
}n/a
getNationalNumber = function () {
return this.get$Value(2);
}n/a
getNationalNumberOrDefault = function () {
return this.get$ValueOrDefault(2);
}n/a
getNumberOfLeadingZeros = function () {
return this.get$Value(8);
}n/a
getNumberOfLeadingZerosOrDefault = function () {
return this.get$ValueOrDefault(8);
}n/a
getPreferredDomesticCarrierCode = function () {
return this.get$Value(7);
}n/a
getPreferredDomesticCarrierCodeOrDefault = function () {
return this.get$ValueOrDefault(7);
}n/a
getRawInput = function () {
return this.get$Value(5);
}n/a
getRawInputOrDefault = function () {
return this.get$ValueOrDefault(5);
}n/a
hasCountryCode = function () {
return this.has$Value(1);
}n/a
hasCountryCodeSource = function () {
return this.has$Value(6);
}n/a
hasExtension = function () {
return this.has$Value(3);
}n/a
hasItalianLeadingZero = function () {
return this.has$Value(4);
}n/a
hasNationalNumber = function () {
return this.has$Value(2);
}n/a
hasNumberOfLeadingZeros = function () {
return this.has$Value(8);
}n/a
hasPreferredDomesticCarrierCode = function () {
return this.has$Value(7);
}n/a
hasRawInput = function () {
return this.has$Value(5);
}n/a
italianLeadingZeroCount = function () {
return this.count$Values(4);
}n/a
nationalNumberCount = function () {
return this.count$Values(2);
}n/a
numberOfLeadingZerosCount = function () {
return this.count$Values(8);
}n/a
preferredDomesticCarrierCodeCount = function () {
return this.count$Values(7);
}n/a
rawInputCount = function () {
return this.count$Values(5);
}n/a
setCountryCode = function (a) {
this.set$Value(1, a);
}n/a
setCountryCodeSource = function (a) {
this.set$Value(6, a);
}n/a
setExtension = function (a) {
this.set$Value(3, a);
}n/a
setItalianLeadingZero = function (a) {
this.set$Value(4, a);
}n/a
setNationalNumber = function (a) {
this.set$Value(2, a);
}n/a
setNumberOfLeadingZeros = function (a) {
this.set$Value(8, a);
}n/a
setPreferredDomesticCarrierCode = function (a) {
this.set$Value(7, a);
}n/a
setRawInput = function (a) {
this.set$Value(5, a);
}n/a
PhoneNumberDesc = function () {
goog.proto2.Message.call(this);
}n/a
base = function (a, c, f) {
for (var d = Array(arguments.length - 2), e = 2;e < arguments.length;e++) {
d[e - 2] = arguments[e];
}
return b.prototype[c].apply(a, d);
}n/a
getDescriptor = function () {
var a = i18n.phonenumbers.PhoneNumberDesc.descriptor_;
a || (i18n.phonenumbers.PhoneNumberDesc.descriptor_ = a = goog.proto2.Message.createDescriptor(i18n.phonenumbers.PhoneNumberDesc
, {0:{name:"PhoneNumberDesc", fullName:"i18n.phonenumbers.PhoneNumberDesc"}, 2:{name:"national_number_pattern", fieldType:goog.proto2
.Message.FieldType.STRING, type:String}, 3:{name:"possible_number_pattern", fieldType:goog.proto2.Message.FieldType.STRING, type
:String}, 9:{name:"possible_length", repeated:!0, fieldType:goog.proto2.Message.FieldType.INT32, type:Number},
10:{name:"possible_length_local_only", repeated:!0, fieldType:goog.proto2.Message.FieldType.INT32, type:Number}, 6:{name:"example_number
", fieldType:goog.proto2.Message.FieldType.STRING, type:String}, 7:{name:"national_number_matcher_data", fieldType:goog.proto2.Message
.FieldType.BYTES, type:String}, 8:{name:"possible_number_matcher_data", fieldType:goog.proto2.Message.FieldType.BYTES, type:String
}}));
return a;
}n/a
addPossibleLength = function (a) {
this.add$Value(9, a);
}n/a
addPossibleLengthLocalOnly = function (a) {
this.add$Value(10, a);
}n/a
clearExampleNumber = function () {
this.clear$Field(6);
}n/a
clearNationalNumberMatcherData = function () {
this.clear$Field(7);
}n/a
clearNationalNumberPattern = function () {
this.clear$Field(2);
}n/a
clearPossibleLength = function () {
this.clear$Field(9);
}n/a
clearPossibleLengthLocalOnly = function () {
this.clear$Field(10);
}n/a
clearPossibleNumberMatcherData = function () {
this.clear$Field(8);
}n/a
clearPossibleNumberPattern = function () {
this.clear$Field(3);
}n/a
constructor = function () {
goog.proto2.Message.call(this);
}n/a
exampleNumberCount = function () {
return this.count$Values(6);
}n/a
getDescriptor = function () {
var a = i18n.phonenumbers.PhoneNumberDesc.descriptor_;
a || (i18n.phonenumbers.PhoneNumberDesc.descriptor_ = a = goog.proto2.Message.createDescriptor(i18n.phonenumbers.PhoneNumberDesc
, {0:{name:"PhoneNumberDesc", fullName:"i18n.phonenumbers.PhoneNumberDesc"}, 2:{name:"national_number_pattern", fieldType:goog.proto2
.Message.FieldType.STRING, type:String}, 3:{name:"possible_number_pattern", fieldType:goog.proto2.Message.FieldType.STRING, type
:String}, 9:{name:"possible_length", repeated:!0, fieldType:goog.proto2.Message.FieldType.INT32, type:Number},
10:{name:"possible_length_local_only", repeated:!0, fieldType:goog.proto2.Message.FieldType.INT32, type:Number}, 6:{name:"example_number
", fieldType:goog.proto2.Message.FieldType.STRING, type:String}, 7:{name:"national_number_matcher_data", fieldType:goog.proto2.Message
.FieldType.BYTES, type:String}, 8:{name:"possible_number_matcher_data", fieldType:goog.proto2.Message.FieldType.BYTES, type:String
}}));
return a;
}n/a
getExampleNumber = function () {
return this.get$Value(6);
}n/a
getExampleNumberOrDefault = function () {
return this.get$ValueOrDefault(6);
}n/a
getNationalNumberMatcherData = function () {
return this.get$Value(7);
}n/a
getNationalNumberMatcherDataOrDefault = function () {
return this.get$ValueOrDefault(7);
}n/a
getNationalNumberPattern = function () {
return this.get$Value(2);
}n/a
getNationalNumberPatternOrDefault = function () {
return this.get$ValueOrDefault(2);
}n/a
getPossibleLength = function (a) {
return this.get$Value(9, a);
}n/a
getPossibleLengthLocalOnly = function (a) {
return this.get$Value(10, a);
}n/a
getPossibleLengthLocalOnlyOrDefault = function (a) {
return this.get$ValueOrDefault(10, a);
}n/a
getPossibleLengthOrDefault = function (a) {
return this.get$ValueOrDefault(9, a);
}n/a
getPossibleNumberMatcherData = function () {
return this.get$Value(8);
}n/a
getPossibleNumberMatcherDataOrDefault = function () {
return this.get$ValueOrDefault(8);
}n/a
getPossibleNumberPattern = function () {
return this.get$Value(3);
}n/a
getPossibleNumberPatternOrDefault = function () {
return this.get$ValueOrDefault(3);
}n/a
hasExampleNumber = function () {
return this.has$Value(6);
}n/a
hasNationalNumberMatcherData = function () {
return this.has$Value(7);
}n/a
hasNationalNumberPattern = function () {
return this.has$Value(2);
}n/a
hasPossibleLength = function () {
return this.has$Value(9);
}n/a
hasPossibleLengthLocalOnly = function () {
return this.has$Value(10);
}n/a
hasPossibleNumberMatcherData = function () {
return this.has$Value(8);
}n/a
hasPossibleNumberPattern = function () {
return this.has$Value(3);
}n/a
nationalNumberMatcherDataCount = function () {
return this.count$Values(7);
}n/a
nationalNumberPatternCount = function () {
return this.count$Values(2);
}n/a
possibleLengthArray = function () {
return this.array$Values(9);
}n/a
possibleLengthCount = function () {
return this.count$Values(9);
}n/a
possibleLengthLocalOnlyArray = function () {
return this.array$Values(10);
}n/a
possibleLengthLocalOnlyCount = function () {
return this.count$Values(10);
}n/a
possibleNumberMatcherDataCount = function () {
return this.count$Values(8);
}n/a
possibleNumberPatternCount = function () {
return this.count$Values(3);
}n/a
setExampleNumber = function (a) {
this.set$Value(6, a);
}n/a
setNationalNumberMatcherData = function (a) {
this.set$Value(7, a);
}n/a
setNationalNumberPattern = function (a) {
this.set$Value(2, a);
}n/a
setPossibleNumberMatcherData = function (a) {
this.set$Value(8, a);
}n/a
setPossibleNumberPattern = function (a) {
this.set$Value(3, a);
}n/a
PhoneNumberUtil = function () {
this.regionToMetadataMap = {};
}n/a
convertAlphaCharactersInNumber = function (a) {
return i18n.phonenumbers.PhoneNumberUtil.normalizeHelper_(a, i18n.phonenumbers.PhoneNumberUtil.ALL_NORMALIZATION_MAPPINGS_, !1
);
}n/a
copyCoreFieldsOnly_ = function (a) {
var b = new i18n.phonenumbers.PhoneNumber;
b.setCountryCode(a.getCountryCodeOrDefault());
b.setNationalNumber(a.getNationalNumberOrDefault());
0 < a.getExtensionOrDefault().length && b.setExtension(a.getExtensionOrDefault());
a.getItalianLeadingZero() && (b.setItalianLeadingZero(!0), b.setNumberOfLeadingZeros(a.getNumberOfLeadingZerosOrDefault()));
return b;
}n/a
descHasData_ = function (a) {
return null != a && (a.hasExampleNumber() || i18n.phonenumbers.PhoneNumberUtil.descHasPossibleNumberData_(a) || a.hasNationalNumberPattern
&& "NA" != a.getNationalNumberPatternOrDefault());
}n/a
descHasPossibleNumberData_ = function (a) {
return null != a && (1 != a.possibleLengthCount() || -1 != a.possibleLengthArray()[0]);
}n/a
extractPossibleNumber = function (a) {
var b = a.search(i18n.phonenumbers.PhoneNumberUtil.VALID_START_CHAR_PATTERN_);
0 <= b ? (a = a.substring(b), a = a.replace(i18n.phonenumbers.PhoneNumberUtil.UNWANTED_END_CHAR_PATTERN_, ""), b = a.search(i18n
.phonenumbers.PhoneNumberUtil.SECOND_NUMBER_START_PATTERN_), 0 <= b && (a = a.substring(0, b))) : a = "";
return a;
}n/a
getCountryMobileToken = function (a) {
return i18n.phonenumbers.PhoneNumberUtil.MOBILE_TOKEN_MAPPINGS_[a] || "";
}n/a
getInstance = function () {
if (a.instance_) {
return a.instance_;
}
goog.DEBUG && (goog.instantiatedSingletons_[goog.instantiatedSingletons_.length] = a);
return a.instance_ = new a;
}...
Here's a simple example on how to format a US-based number in the international phone number format:
```js
// Require `PhoneNumberFormat`.
var PNF = require('google-libphonenumber').PhoneNumberFormat;
// Get an instance of `PhoneNumberUtil`.
var phoneUtil = require('google-libphonenumber').PhoneNumberUtil.getInstance();
// Parse number with country code.
var phoneNumber = phoneUtil.parse('202-456-1414', 'US');
// Print number in the international format.
console.log(phoneUtil.format(phoneNumber, PNF.INTERNATIONAL));
// => +1 202-456-1414
...getNumberDescByType_ = function (a, b) {
switch(b) {
case i18n.phonenumbers.PhoneNumberType.PREMIUM_RATE:
return a.getPremiumRate();
case i18n.phonenumbers.PhoneNumberType.TOLL_FREE:
return a.getTollFree();
case i18n.phonenumbers.PhoneNumberType.MOBILE:
return a.getMobile();
case i18n.phonenumbers.PhoneNumberType.FIXED_LINE:
case i18n.phonenumbers.PhoneNumberType.FIXED_LINE_OR_MOBILE:
return a.getFixedLine();
case i18n.phonenumbers.PhoneNumberType.SHARED_COST:
return a.getSharedCost();
case i18n.phonenumbers.PhoneNumberType.VOIP:
return a.getVoip();
case i18n.phonenumbers.PhoneNumberType.PERSONAL_NUMBER:
return a.getPersonalNumber();
case i18n.phonenumbers.PhoneNumberType.PAGER:
return a.getPager();
case i18n.phonenumbers.PhoneNumberType.UAN:
return a.getUan();
case i18n.phonenumbers.PhoneNumberType.VOICEMAIL:
return a.getVoicemail();
default:
return a.getGeneralDesc();
}
}n/a
getSupportedTypesForMetadata_ = function (a) {
var b = [];
goog.object.forEach(i18n.phonenumbers.PhoneNumberType, function(c) {
if (c != i18n.phonenumbers.PhoneNumberType.FIXED_LINE_OR_MOBILE && c != i18n.phonenumbers.PhoneNumberType.UNKNOWN) {
var d = i18n.phonenumbers.PhoneNumberUtil.getNumberDescByType_(a, c);
i18n.phonenumbers.PhoneNumberUtil.descHasData_(d) && b.push(c);
}
});
return b;
}n/a
isViablePhoneNumber = function (a) {
return a.length < i18n.phonenumbers.PhoneNumberUtil.MIN_LENGTH_FOR_NSN_ ? !1 : i18n.phonenumbers.PhoneNumberUtil.matchesEntirely_
(i18n.phonenumbers.PhoneNumberUtil.VALID_PHONE_NUMBER_PATTERN_, a);
}n/a
matchesEntirely_ = function (a, b) {
var c = "string" == typeof a ? b.match("^(?:" + a + ")$") : b.match(a);
return c && c[0].length == b.length ? !0 : !1;
}n/a
normalize = function (a) {
return i18n.phonenumbers.PhoneNumberUtil.matchesEntirely_(i18n.phonenumbers.PhoneNumberUtil.VALID_ALPHA_PHONE_PATTERN_, a) ? i18n
.phonenumbers.PhoneNumberUtil.normalizeHelper_(a, i18n.phonenumbers.PhoneNumberUtil.ALL_NORMALIZATION_MAPPINGS_, !0) : i18n.phonenumbers
.PhoneNumberUtil.normalizeDigitsOnly(a);
}n/a
normalizeDiallableCharsOnly = function (a) {
return i18n.phonenumbers.PhoneNumberUtil.normalizeHelper_(a, i18n.phonenumbers.PhoneNumberUtil.DIALLABLE_CHAR_MAPPINGS_, !0);
}n/a
normalizeDigitsOnly = function (a) {
return i18n.phonenumbers.PhoneNumberUtil.normalizeHelper_(a, i18n.phonenumbers.PhoneNumberUtil.DIGIT_MAPPINGS, !0);
}n/a
normalizeHelper_ = function (a, b, c) {
for (var d = new goog.string.StringBuffer, e, f, g = a.length, h = 0;h < g;++h) {
e = a.charAt(h), f = b[e.toUpperCase()], null != f ? d.append(f) : c || d.append(e);
}
return d.toString();
}n/a
normalizeSB_ = function (a) {
var b = i18n.phonenumbers.PhoneNumberUtil.normalize(a.toString());
a.clear();
a.append(b);
}n/a
setItalianLeadingZerosForPhoneNumber_ = function (a, b) {
if (1 < a.length && "0" == a.charAt(0)) {
b.setItalianLeadingZero(!0);
for (var c = 1;c < a.length - 1 && "0" == a.charAt(c);) {
c++;
}
1 != c && b.setNumberOfLeadingZeros(c);
}
}n/a
buildNationalNumberForParsing_ = function (a, b) {
var c = a.indexOf(i18n.phonenumbers.PhoneNumberUtil.RFC3966_PHONE_CONTEXT_);
if (0 < c) {
var d = c + i18n.phonenumbers.PhoneNumberUtil.RFC3966_PHONE_CONTEXT_.length;
if (a.charAt(d) == i18n.phonenumbers.PhoneNumberUtil.PLUS_SIGN) {
var e = a.indexOf(";", d);
0 < e ? b.append(a.substring(d, e)) : b.append(a.substring(d));
}
d = a.indexOf(i18n.phonenumbers.PhoneNumberUtil.RFC3966_PREFIX_);
b.append(a.substring(0 <= d ? d + i18n.phonenumbers.PhoneNumberUtil.RFC3966_PREFIX_.length : 0, c));
} else {
b.append(i18n.phonenumbers.PhoneNumberUtil.extractPossibleNumber(a));
}
c = b.toString();
d = c.indexOf(i18n.phonenumbers.PhoneNumberUtil.RFC3966_ISDN_SUBADDRESS_);
0 < d && (b.clear(), b.append(c.substring(0, d)));
}n/a
canBeInternationallyDialled = function (a) {
var b = this.getMetadataForRegion(this.getRegionCodeForNumber(a));
if (null == b) {
return !0;
}
a = this.getNationalSignificantNumber(a);
return !this.isNumberMatchingDesc_(a, b.getNoInternationalDialling());
}n/a
checkRegionForParsing_ = function (a, b) {
return this.isValidRegionCode_(b) || null != a && 0 < a.length && i18n.phonenumbers.PhoneNumberUtil.LEADING_PLUS_CHARS_PATTERN_
.test(a);
}n/a
chooseFormattingPatternForNumber_ = function (a, b) {
for (var c, d = a.length, e = 0;e < d;++e) {
c = a[e];
var f = c.leadingDigitsPatternCount();
if (0 == f || 0 == b.search(c.getLeadingDigitsPattern(f - 1))) {
if (f = new RegExp(c.getPattern()), i18n.phonenumbers.PhoneNumberUtil.matchesEntirely_(f, b)) {
return c;
}
}
}
return null;
}n/a
extractCountryCode = function (a, b) {
var c = a.toString();
if (0 == c.length || "0" == c.charAt(0)) {
return 0;
}
for (var d, e = c.length, f = 1;f <= i18n.phonenumbers.PhoneNumberUtil.MAX_LENGTH_COUNTRY_CODE_ && f <= e;++f) {
if (d = parseInt(c.substring(0, f), 10), d in i18n.phonenumbers.metadata.countryCodeToRegionCodeMap) {
return b.append(c.substring(f)), d;
}
}
return 0;
}n/a
format = function (a, b) {
if (0 == a.getNationalNumber() && a.hasRawInput()) {
var c = a.getRawInputOrDefault();
if (0 < c.length) {
return c;
}
}
var c = a.getCountryCodeOrDefault(), d = this.getNationalSignificantNumber(a);
if (b == i18n.phonenumbers.PhoneNumberFormat.E164) {
return this.prefixNumberWithCountryCallingCode_(c, i18n.phonenumbers.PhoneNumberFormat.E164, d, "");
}
if (!this.hasValidCountryCallingCode_(c)) {
return d;
}
var e = this.getRegionCodeForCountryCode(c), f = this.getMetadataForRegionOrCallingCode_(c, e), e = this.maybeGetFormattedExtension_
(a, f, b), d = this.formatNsn_(d, f, b);
return this.prefixNumberWithCountryCallingCode_(c, b, d, e);
}...
// Get an instance of `PhoneNumberUtil`.
var phoneUtil = require('google-libphonenumber').PhoneNumberUtil.getInstance();
// Parse number with country code.
var phoneNumber = phoneUtil.parse('202-456-1414', 'US');
// Print number in the international format.
console.log(phoneUtil.format(phoneNumber, PNF.INTERNATIONAL));
// => +1 202-456-1414
```
#### Using the "As You Type" Formatter
```js
// Require `AsYouTypeFormatter`.
...formatByPattern = function (a, b, c) {
var d = a.getCountryCodeOrDefault(), e = this.getNationalSignificantNumber(a);
if (!this.hasValidCountryCallingCode_(d)) {
return e;
}
var f = this.getRegionCodeForCountryCode(d), f = this.getMetadataForRegionOrCallingCode_(d, f), g = this.chooseFormattingPatternForNumber_
(c, e);
if (null != g) {
c = g.clone();
g = g.getNationalPrefixFormattingRuleOrDefault();
if (0 < g.length) {
var h = f.getNationalPrefixOrDefault();
0 < h.length ? (g = g.replace(i18n.phonenumbers.PhoneNumberUtil.NP_PATTERN_, h).replace(i18n.phonenumbers.PhoneNumberUtil.
FG_PATTERN_, "$1"), c.setNationalPrefixFormattingRule(g)) : c.clearNationalPrefixFormattingRule();
}
e = this.formatNsnUsingPattern_(e, c, b);
}
a = this.maybeGetFormattedExtension_(a, f, b);
return this.prefixNumberWithCountryCallingCode_(d, b, e, a);
}n/a
formatInOriginalFormat = function (a, b) {
if (a.hasRawInput() && (this.hasUnexpectedItalianLeadingZero_(a) || !this.hasFormattingPatternForNumber_(a))) {
return a.getRawInputOrDefault();
}
if (!a.hasCountryCodeSource()) {
return this.format(a, i18n.phonenumbers.PhoneNumberFormat.NATIONAL);
}
var c;
switch(a.getCountryCodeSource()) {
case i18n.phonenumbers.PhoneNumber.CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN:
c = this.format(a, i18n.phonenumbers.PhoneNumberFormat.INTERNATIONAL);
break;
case i18n.phonenumbers.PhoneNumber.CountryCodeSource.FROM_NUMBER_WITH_IDD:
c = this.formatOutOfCountryCallingNumber(a, b);
break;
case i18n.phonenumbers.PhoneNumber.CountryCodeSource.FROM_NUMBER_WITHOUT_PLUS_SIGN:
c = this.format(a, i18n.phonenumbers.PhoneNumberFormat.INTERNATIONAL).substring(1);
break;
default:
var d = this.getRegionCodeForCountryCode(a.getCountryCodeOrDefault()), e = this.getNddPrefixForRegion(d, !0);
c = this.format(a, i18n.phonenumbers.PhoneNumberFormat.NATIONAL);
if (null != e && 0 != e.length && !this.rawInputContainsNationalPrefix_(a.getRawInputOrDefault(), e, d) && (d = this.getMetadataForRegion
(d), e = this.getNationalSignificantNumber(a), d = this.chooseFormattingPatternForNumber_(d.numberFormatArray(), e), null != d)) {
var e = d.getNationalPrefixFormattingRuleOrDefault(), f = e.indexOf("$1");
0 >= f || (e = e.substring(0, f), e = i18n.phonenumbers.PhoneNumberUtil.normalizeDigitsOnly(e), 0 != e.length && (c = d.
clone(), c.clearNationalPrefixFormattingRule(), c = this.formatByPattern(a, i18n.phonenumbers.PhoneNumberFormat.NATIONAL, [c])));
}
}
d = a.getRawInputOrDefault();
null != c && 0 < d.length && (e = i18n.phonenumbers.PhoneNumberUtil.normalizeDiallableCharsOnly(c), f = i18n.phonenumbers.PhoneNumberUtil
.normalizeDiallableCharsOnly(d), e != f && (c = d));
return c;
}n/a
formatNationalNumberWithCarrierCode = function (a, b) {
var c = a.getCountryCodeOrDefault(), d = this.getNationalSignificantNumber(a);
if (!this.hasValidCountryCallingCode_(c)) {
return d;
}
var e = this.getRegionCodeForCountryCode(c), f = this.getMetadataForRegionOrCallingCode_(c, e), e = this.maybeGetFormattedExtension_
(a, f, i18n.phonenumbers.PhoneNumberFormat.NATIONAL), d = this.formatNsn_(d, f, i18n.phonenumbers.PhoneNumberFormat.NATIONAL, b);
return this.prefixNumberWithCountryCallingCode_(c, i18n.phonenumbers.PhoneNumberFormat.NATIONAL, d, e);
}n/a
formatNationalNumberWithPreferredCarrierCode = function (a, b) {
return this.formatNationalNumberWithCarrierCode(a, 0 < a.getPreferredDomesticCarrierCodeOrDefault().length ? a.getPreferredDomesticCarrierCodeOrDefault
() : b);
}n/a
formatNsnUsingPattern_ = function (a, b, c, d) {
var e = b.getFormatOrDefault(), f = new RegExp(b.getPattern()), g = b.getDomesticCarrierCodeFormattingRuleOrDefault();
c == i18n.phonenumbers.PhoneNumberFormat.NATIONAL && null != d && 0 < d.length && 0 < g.length ? (b = g.replace(i18n.phonenumbers
.PhoneNumberUtil.CC_PATTERN_, d), e = e.replace(i18n.phonenumbers.PhoneNumberUtil.FIRST_GROUP_PATTERN_, b), a = a.replace(f, e)) : (
b = b.getNationalPrefixFormattingRuleOrDefault(), a = c == i18n.phonenumbers.PhoneNumberFormat.NATIONAL && null != b && 0 < b.length
? a.replace(f, e.replace(i18n.phonenumbers.PhoneNumberUtil.FIRST_GROUP_PATTERN_, b)) : a.replace(f, e));
c == i18n.phonenumbers.PhoneNumberFormat.RFC3966 && (a = a.replace(new RegExp("^" + i18n.phonenumbers.PhoneNumberUtil.SEPARATOR_PATTERN_
), ""), a = a.replace(new RegExp(i18n.phonenumbers.PhoneNumberUtil.SEPARATOR_PATTERN_, "g"), "-"));
return a;
}n/a
formatNsn_ = function (a, b, c, d) {
b = 0 == b.intlNumberFormatArray().length || c == i18n.phonenumbers.PhoneNumberFormat.NATIONAL ? b.numberFormatArray() : b.intlNumberFormatArray
();
b = this.chooseFormattingPatternForNumber_(b, a);
return null == b ? a : this.formatNsnUsingPattern_(a, b, c, d);
}n/a
formatNumberForMobileDialing = function (a, b, c) {
var d = a.getCountryCodeOrDefault();
if (!this.hasValidCountryCallingCode_(d)) {
return a.hasRawInput() ? a.getRawInputOrDefault() : "";
}
var e = "";
a = a.clone();
a.clearExtension();
var f = this.getRegionCodeForCountryCode(d), g = this.getNumberType(a), h = g != i18n.phonenumbers.PhoneNumberType.UNKNOWN;
if (b == f) {
e = g == i18n.phonenumbers.PhoneNumberType.FIXED_LINE || g == i18n.phonenumbers.PhoneNumberType.MOBILE || g == i18n.phonenumbers
.PhoneNumberType.FIXED_LINE_OR_MOBILE, "CO" == f && g == i18n.phonenumbers.PhoneNumberType.FIXED_LINE ? e = this.formatNationalNumberWithCarrierCode
(a, i18n.phonenumbers.PhoneNumberUtil.COLOMBIA_MOBILE_TO_FIXED_LINE_PREFIX_) : "BR" == f && e ? e = 0 < a.getPreferredDomesticCarrierCodeOrDefault
().length ? this.formatNationalNumberWithPreferredCarrierCode(a, "") : "" :
h && "HU" == f ? e = this.getNddPrefixForRegion(f, !0) + " " + this.format(a, i18n.phonenumbers.PhoneNumberFormat.NATIONAL) :
d == i18n.phonenumbers.PhoneNumberUtil.NANPA_COUNTRY_CODE_ ? (b = this.getMetadataForRegion(b), e = this.canBeInternationallyDialled
(a) && this.testNumberLength_(this.getNationalSignificantNumber(a), b) != i18n.phonenumbers.PhoneNumberUtil.ValidationResult.TOO_SHORT
? this.format(a, i18n.phonenumbers.PhoneNumberFormat.INTERNATIONAL) : this.format(a, i18n.phonenumbers.PhoneNumberFormat.NATIONAL
)) :
e = (f == i18n.phonenumbers.PhoneNumberUtil.REGION_CODE_FOR_NON_GEO_ENTITY || ("MX" == f || "CL" == f) && e) && this.canBeInternationallyDialled
(a) ? this.format(a, i18n.phonenumbers.PhoneNumberFormat.INTERNATIONAL) : this.format(a, i18n.phonenumbers.PhoneNumberFormat.NATIONAL
);
} else {
if (h && this.canBeInternationallyDialled(a)) {
return c ? this.format(a, i18n.phonenumbers.PhoneNumberFormat.INTERNATIONAL) : this.format(a, i18n.phonenumbers.PhoneNumberFormat
.E164);
}
}
return c ? e : i18n.phonenumbers.PhoneNumberUtil.normalizeDiallableCharsOnly(e);
}n/a
formatOutOfCountryCallingNumber = function (a, b) {
if (!this.isValidRegionCode_(b)) {
return this.format(a, i18n.phonenumbers.PhoneNumberFormat.INTERNATIONAL);
}
var c = a.getCountryCodeOrDefault(), d = this.getNationalSignificantNumber(a);
if (!this.hasValidCountryCallingCode_(c)) {
return d;
}
if (c == i18n.phonenumbers.PhoneNumberUtil.NANPA_COUNTRY_CODE_) {
if (this.isNANPACountry(b)) {
return c + " " + this.format(a, i18n.phonenumbers.PhoneNumberFormat.NATIONAL);
}
} else {
if (c == this.getCountryCodeForValidRegion_(b)) {
return this.format(a, i18n.phonenumbers.PhoneNumberFormat.NATIONAL);
}
}
var e = this.getMetadataForRegion(b), f = e.getInternationalPrefixOrDefault(), g = "";
i18n.phonenumbers.PhoneNumberUtil.matchesEntirely_(i18n.phonenumbers.PhoneNumberUtil.UNIQUE_INTERNATIONAL_PREFIX_, f) ? g = f :
e.hasPreferredInternationalPrefix() && (g = e.getPreferredInternationalPrefixOrDefault());
e = this.getRegionCodeForCountryCode(c);
e = this.getMetadataForRegionOrCallingCode_(c, e);
d = this.formatNsn_(d, e, i18n.phonenumbers.PhoneNumberFormat.INTERNATIONAL);
e = this.maybeGetFormattedExtension_(a, e, i18n.phonenumbers.PhoneNumberFormat.INTERNATIONAL);
return 0 < g.length ? g + " " + c + " " + d + e : this.prefixNumberWithCountryCallingCode_(c, i18n.phonenumbers.PhoneNumberFormat
.INTERNATIONAL, d, e);
}n/a
formatOutOfCountryKeepingAlphaChars = function (a, b) {
var c = a.getRawInputOrDefault();
if (0 == c.length) {
return this.formatOutOfCountryCallingNumber(a, b);
}
var d = a.getCountryCodeOrDefault();
if (!this.hasValidCountryCallingCode_(d)) {
return c;
}
var c = i18n.phonenumbers.PhoneNumberUtil.normalizeHelper_(c, i18n.phonenumbers.PhoneNumberUtil.ALL_PLUS_NUMBER_GROUPING_SYMBOLS_
, !0), e = this.getNationalSignificantNumber(a);
if (3 < e.length) {
var f = c.indexOf(e.substring(0, 3));
-1 != f && (c = c.substring(f));
}
f = this.getMetadataForRegion(b);
if (d == i18n.phonenumbers.PhoneNumberUtil.NANPA_COUNTRY_CODE_) {
if (this.isNANPACountry(b)) {
return d + " " + c;
}
} else {
if (null != f && d == this.getCountryCodeForValidRegion_(b)) {
d = this.chooseFormattingPatternForNumber_(f.numberFormatArray(), e);
if (null == d) {
return c;
}
d = d.clone();
d.setPattern("(\\d+)(.*)");
d.setFormat("$1$2");
return this.formatNsnUsingPattern_(c, d, i18n.phonenumbers.PhoneNumberFormat.NATIONAL);
}
}
e = "";
null != f && (e = f.getInternationalPrefixOrDefault(), e = i18n.phonenumbers.PhoneNumberUtil.matchesEntirely_(i18n.phonenumbers
.PhoneNumberUtil.UNIQUE_INTERNATIONAL_PREFIX_, e) ? e : f.getPreferredInternationalPrefixOrDefault());
f = this.getRegionCodeForCountryCode(d);
f = this.getMetadataForRegionOrCallingCode_(d, f);
f = this.maybeGetFormattedExtension_(a, f, i18n.phonenumbers.PhoneNumberFormat.INTERNATIONAL);
return 0 < e.length ? e + " " + d + " " + c + f : this.prefixNumberWithCountryCallingCode_(d, i18n.phonenumbers.PhoneNumberFormat
.INTERNATIONAL, c, f);
}n/a
formattingRuleHasFirstGroupOnly = function (a) {
return 0 == a.length || i18n.phonenumbers.PhoneNumberUtil.FIRST_GROUP_ONLY_PREFIX_PATTERN_.test(a);
}n/a
getCountryCodeForRegion = function (a) {
return this.isValidRegionCode_(a) ? this.getCountryCodeForValidRegion_(a) : 0;
}n/a
getCountryCodeForValidRegion_ = function (a) {
var b = this.getMetadataForRegion(a);
if (null == b) {
throw Error("Invalid region code: " + a);
}
return b.getCountryCodeOrDefault();
}n/a
getExampleNumber = function (a) {
return this.getExampleNumberForType(a, i18n.phonenumbers.PhoneNumberType.FIXED_LINE);
}n/a
getExampleNumberForNonGeoEntity = function (a) {
var b = this.getMetadataForNonGeographicalRegion(a);
if (null != b && (b = goog.array.find([b.getMobile(), b.getTollFree(), b.getSharedCost(), b.getVoip(), b.getVoicemail(), b.getUan
(), b.getPremiumRate()], function(a, b) {
return a.hasExampleNumber();
}), null != b)) {
try {
return this.parse("+" + a + b.getExampleNumber(), "ZZ");
} catch (c) {
}
}
return null;
}n/a
getExampleNumberForType = function (a, b) {
if (!this.isValidRegionCode_(a)) {
return null;
}
var c = i18n.phonenumbers.PhoneNumberUtil.getNumberDescByType_(this.getMetadataForRegion(a), b);
try {
if (c.hasExampleNumber()) {
return this.parse(c.getExampleNumber(), a);
}
} catch (d) {
}
return null;
}n/a
getLengthOfGeographicalAreaCode = function (a) {
var b = this.getMetadataForRegion(this.getRegionCodeForNumber(a));
return null != b && (b.hasNationalPrefix() || a.hasItalianLeadingZero()) && this.isNumberGeographical(a) ? this.getLengthOfNationalDestinationCode
(a) : 0;
}n/a
getLengthOfNationalDestinationCode = function (a) {
var b;
a.hasExtension() ? (b = a.clone(), b.clearExtension()) : b = a;
b = this.format(b, i18n.phonenumbers.PhoneNumberFormat.INTERNATIONAL).split(i18n.phonenumbers.PhoneNumberUtil.NON_DIGITS_PATTERN_
);
0 == b[0].length && b.shift();
return 2 >= b.length ? 0 : this.getNumberType(a) == i18n.phonenumbers.PhoneNumberType.MOBILE && (a = i18n.phonenumbers.PhoneNumberUtil
.getCountryMobileToken(a.getCountryCodeOrDefault()), "" != a) ? b[2].length + a.length : b[1].length;
}n/a
getMetadataForNonGeographicalRegion = function (a) {
return this.getMetadataForRegion("" + a);
}n/a
getMetadataForRegion = function (a) {
if (null == a) {
return null;
}
a = a.toUpperCase();
var b = this.regionToMetadataMap[a];
if (null == b) {
var b = new goog.proto2.PbLiteSerializer, c = i18n.phonenumbers.metadata.countryToMetadata[a];
if (null == c) {
return null;
}
b = b.deserialize(i18n.phonenumbers.PhoneMetadata.getDescriptor(), c);
this.regionToMetadataMap[a] = b;
}
return b;
}n/a
getMetadataForRegionOrCallingCode_ = function (a, b) {
return i18n.phonenumbers.PhoneNumberUtil.REGION_CODE_FOR_NON_GEO_ENTITY == b ? this.getMetadataForNonGeographicalRegion(a) : this
.getMetadataForRegion(b);
}n/a
getNationalSignificantNumber = function (a) {
var b = "" + a.getNationalNumber();
return a.hasItalianLeadingZero() && a.getItalianLeadingZero() && 0 < a.getNumberOfLeadingZerosOrDefault() ? Array(a.getNumberOfLeadingZerosOrDefault
() + 1).join("0") + b : b;
}n/a
getNddPrefixForRegion = function (a, b) {
var c = this.getMetadataForRegion(a);
if (null == c) {
return null;
}
c = c.getNationalPrefixOrDefault();
if (0 == c.length) {
return null;
}
b && (c = c.replace("~", ""));
return c;
}n/a
getNumberType = function (a) {
var b = this.getRegionCodeForNumber(a), b = this.getMetadataForRegionOrCallingCode_(a.getCountryCodeOrDefault(), b);
if (null == b) {
return i18n.phonenumbers.PhoneNumberType.UNKNOWN;
}
a = this.getNationalSignificantNumber(a);
return this.getNumberTypeHelper_(a, b);
}n/a
getNumberTypeHelper_ = function (a, b) {
return this.isNumberMatchingDesc_(a, b.getGeneralDesc()) ? this.isNumberMatchingDesc_(a, b.getPremiumRate()) ? i18n.phonenumbers
.PhoneNumberType.PREMIUM_RATE : this.isNumberMatchingDesc_(a, b.getTollFree()) ? i18n.phonenumbers.PhoneNumberType.TOLL_FREE : this
.isNumberMatchingDesc_(a, b.getSharedCost()) ? i18n.phonenumbers.PhoneNumberType.SHARED_COST : this.isNumberMatchingDesc_(a, b.getVoip
()) ? i18n.phonenumbers.PhoneNumberType.VOIP : this.isNumberMatchingDesc_(a, b.getPersonalNumber()) ? i18n.phonenumbers.PhoneNumberType
.PERSONAL_NUMBER :
this.isNumberMatchingDesc_(a, b.getPager()) ? i18n.phonenumbers.PhoneNumberType.PAGER : this.isNumberMatchingDesc_(a, b.getUan
()) ? i18n.phonenumbers.PhoneNumberType.UAN : this.isNumberMatchingDesc_(a, b.getVoicemail()) ? i18n.phonenumbers.PhoneNumberType
.VOICEMAIL : this.isNumberMatchingDesc_(a, b.getFixedLine()) ? b.getSameMobileAndFixedLinePattern() || this.isNumberMatchingDesc_
(a, b.getMobile()) ? i18n.phonenumbers.PhoneNumberType.FIXED_LINE_OR_MOBILE : i18n.phonenumbers.PhoneNumberType.FIXED_LINE :
!b.getSameMobileAndFixedLinePattern() && this.isNumberMatchingDesc_(a, b.getMobile()) ? i18n.phonenumbers.PhoneNumberType.MOBILE
: i18n.phonenumbers.PhoneNumberType.UNKNOWN : i18n.phonenumbers.PhoneNumberType.UNKNOWN;
}n/a
getRegionCodeForCountryCode = function (a) {
a = i18n.phonenumbers.metadata.countryCodeToRegionCodeMap[a];
return null == a ? i18n.phonenumbers.PhoneNumberUtil.UNKNOWN_REGION_ : a[0];
}n/a
getRegionCodeForNumber = function (a) {
if (null == a) {
return null;
}
var b = a.getCountryCodeOrDefault(), b = i18n.phonenumbers.metadata.countryCodeToRegionCodeMap[b];
return null == b ? null : 1 == b.length ? b[0] : this.getRegionCodeForNumberFromRegionList_(a, b);
}n/a
getRegionCodeForNumberFromRegionList_ = function (a, b) {
for (var c = this.getNationalSignificantNumber(a), d, e = b.length, f = 0;f < e;f++) {
d = b[f];
var g = this.getMetadataForRegion(d);
if (g.hasLeadingDigits()) {
if (0 == c.search(g.getLeadingDigits())) {
return d;
}
} else {
if (this.getNumberTypeHelper_(c, g) != i18n.phonenumbers.PhoneNumberType.UNKNOWN) {
return d;
}
}
}
return null;
}n/a
getRegionCodesForCountryCode = function (a) {
a = i18n.phonenumbers.metadata.countryCodeToRegionCodeMap[a];
return null == a ? [] : a;
}n/a
getSupportedGlobalNetworkCallingCodes = function () {
var a = goog.array.filter(Object.keys(i18n.phonenumbers.metadata.countryToMetadata), function(a) {
return !isNaN(a);
});
return goog.array.map(a, function(a) {
return parseInt(a, 10);
});
}n/a
getSupportedRegions = function () {
return goog.array.filter(Object.keys(i18n.phonenumbers.metadata.countryToMetadata), function(a) {
return isNaN(a);
});
}n/a
getSupportedTypesForNonGeoEntity = function (a) {
a = this.getMetadataForNonGeographicalRegion(a);
return null == a ? [] : i18n.phonenumbers.PhoneNumberUtil.getSupportedTypesForMetadata_(a);
}n/a
getSupportedTypesForRegion = function (a) {
return this.isValidRegionCode_(a) ? i18n.phonenumbers.PhoneNumberUtil.getSupportedTypesForMetadata_(this.getMetadataForRegion(
a)) : [];
}n/a
hasFormattingPatternForNumber_ = function (a) {
var b = a.getCountryCodeOrDefault(), c = this.getRegionCodeForCountryCode(b), b = this.getMetadataForRegionOrCallingCode_(b, c
);
if (null == b) {
return !1;
}
a = this.getNationalSignificantNumber(a);
return null != this.chooseFormattingPatternForNumber_(b.numberFormatArray(), a);
}n/a
hasUnexpectedItalianLeadingZero_ = function (a) {
return a.hasItalianLeadingZero() && !this.isLeadingZeroPossible(a.getCountryCodeOrDefault());
}n/a
hasValidCountryCallingCode_ = function (a) {
return a in i18n.phonenumbers.metadata.countryCodeToRegionCodeMap;
}n/a
isAlphaNumber = function (a) {
if (!i18n.phonenumbers.PhoneNumberUtil.isViablePhoneNumber(a)) {
return !1;
}
a = new goog.string.StringBuffer(a);
this.maybeStripExtension(a);
return i18n.phonenumbers.PhoneNumberUtil.matchesEntirely_(i18n.phonenumbers.PhoneNumberUtil.VALID_ALPHA_PHONE_PATTERN_, a.toString
());
}n/a
isLeadingZeroPossible = function (a) {
a = this.getMetadataForRegionOrCallingCode_(a, this.getRegionCodeForCountryCode(a));
return null != a && a.getLeadingZeroPossibleOrDefault();
}n/a
isNANPACountry = function (a) {
return null != a && goog.array.contains(i18n.phonenumbers.metadata.countryCodeToRegionCodeMap[i18n.phonenumbers.PhoneNumberUtil
.NANPA_COUNTRY_CODE_], a.toUpperCase());
}n/a
isNationalNumberSuffixOfTheOther_ = function (a, b) {
var c = "" + a.getNationalNumber(), d = "" + b.getNationalNumber();
return goog.string.endsWith(c, d) || goog.string.endsWith(d, c);
}n/a
isNumberGeographical = function (a) {
var b = this.getNumberType(a);
return b == i18n.phonenumbers.PhoneNumberType.FIXED_LINE || b == i18n.phonenumbers.PhoneNumberType.FIXED_LINE_OR_MOBILE || goog
.array.contains(i18n.phonenumbers.PhoneNumberUtil.GEO_MOBILE_COUNTRIES_, a.getCountryCodeOrDefault()) && b == i18n.phonenumbers.
PhoneNumberType.MOBILE;
}n/a
isNumberMatch = function (a, b) {
var c, d;
if ("string" == typeof a) {
try {
c = this.parse(a, i18n.phonenumbers.PhoneNumberUtil.UNKNOWN_REGION_);
} catch (g) {
if (g.message != i18n.phonenumbers.Error.INVALID_COUNTRY_CODE) {
return i18n.phonenumbers.PhoneNumberUtil.MatchType.NOT_A_NUMBER;
}
if ("string" != typeof b) {
var e = this.getRegionCodeForCountryCode(b.getCountryCodeOrDefault());
if (e != i18n.phonenumbers.PhoneNumberUtil.UNKNOWN_REGION_) {
try {
c = this.parse(a, e);
} catch (h) {
return i18n.phonenumbers.PhoneNumberUtil.MatchType.NOT_A_NUMBER;
}
c = this.isNumberMatch(c, b);
return c == i18n.phonenumbers.PhoneNumberUtil.MatchType.EXACT_MATCH ? i18n.phonenumbers.PhoneNumberUtil.MatchType.NSN_MATCH
: c;
}
}
try {
c = this.parseHelper_(a, null, !1, !1);
} catch (h) {
return i18n.phonenumbers.PhoneNumberUtil.MatchType.NOT_A_NUMBER;
}
}
} else {
c = a.clone();
}
if ("string" == typeof b) {
try {
return d = this.parse(b, i18n.phonenumbers.PhoneNumberUtil.UNKNOWN_REGION_), this.isNumberMatch(a, d);
} catch (g) {
return g.message != i18n.phonenumbers.Error.INVALID_COUNTRY_CODE ? i18n.phonenumbers.PhoneNumberUtil.MatchType.NOT_A_NUMBER
: this.isNumberMatch(b, c);
}
} else {
d = b.clone();
}
c = i18n.phonenumbers.PhoneNumberUtil.copyCoreFieldsOnly_(c);
d = i18n.phonenumbers.PhoneNumberUtil.copyCoreFieldsOnly_(d);
if (c.hasExtension() && d.hasExtension() && c.getExtension() != d.getExtension()) {
return i18n.phonenumbers.PhoneNumberUtil.MatchType.NO_MATCH;
}
var e = c.getCountryCodeOrDefault(), f = d.getCountryCodeOrDefault();
if (0 != e && 0 != f) {
return c.equals(d) ? i18n.phonenumbers.PhoneNumberUtil.MatchType.EXACT_MATCH : e == f && this.isNationalNumberSuffixOfTheOther_
(c, d) ? i18n.phonenumbers.PhoneNumberUtil.MatchType.SHORT_NSN_MATCH : i18n.phonenumbers.PhoneNumberUtil.MatchType.NO_MATCH;
}
c.setCountryCode(0);
d.setCountryCode(0);
return c.equals(d) ? i18n.phonenumbers.PhoneNumberUtil.MatchType.NSN_MATCH : this.isNationalNumberSuffixOfTheOther_(c, d) ? i18n
.phonenumbers.PhoneNumberUtil.MatchType.SHORT_NSN_MATCH : i18n.phonenumbers.PhoneNumberUtil.MatchType.NO_MATCH;
}n/a
isNumberMatchingDesc_ = function (a, b) {
var c = a.length;
return 0 < b.possibleLengthCount() && -1 == goog.array.indexOf(b.possibleLengthArray(), c) ? !1 : i18n.phonenumbers.PhoneNumberUtil
.matchesEntirely_(b.getNationalNumberPatternOrDefault(), a);
}n/a
isPossibleNumber = function (a) {
a = this.isPossibleNumberWithReason(a);
return a == i18n.phonenumbers.PhoneNumberUtil.ValidationResult.IS_POSSIBLE || a == i18n.phonenumbers.PhoneNumberUtil.ValidationResult
.IS_POSSIBLE_LOCAL_ONLY;
}n/a
isPossibleNumberForType = function (a, b) {
var c = this.isPossibleNumberForTypeWithReason(a, b);
return c == i18n.phonenumbers.PhoneNumberUtil.ValidationResult.IS_POSSIBLE || c == i18n.phonenumbers.PhoneNumberUtil.ValidationResult
.IS_POSSIBLE_LOCAL_ONLY;
}n/a
isPossibleNumberForTypeWithReason = function (a, b) {
var c = this.getNationalSignificantNumber(a), d = a.getCountryCodeOrDefault();
if (!this.hasValidCountryCallingCode_(d)) {
return i18n.phonenumbers.PhoneNumberUtil.ValidationResult.INVALID_COUNTRY_CODE;
}
var e = this.getRegionCodeForCountryCode(d), d = this.getMetadataForRegionOrCallingCode_(d, e);
return this.testNumberLengthForType_(c, d, b);
}n/a
isPossibleNumberString = function (a, b) {
try {
return this.isPossibleNumber(this.parse(a, b));
} catch (c) {
return !1;
}
}n/a
isPossibleNumberWithReason = function (a) {
return this.isPossibleNumberForTypeWithReason(a, i18n.phonenumbers.PhoneNumberType.UNKNOWN);
}n/a
isValidNumber = function (a) {
var b = this.getRegionCodeForNumber(a);
return this.isValidNumberForRegion(a, b);
}n/a
isValidNumberForRegion = function (a, b) {
var c = a.getCountryCodeOrDefault(), d = this.getMetadataForRegionOrCallingCode_(c, b);
if (null == d || i18n.phonenumbers.PhoneNumberUtil.REGION_CODE_FOR_NON_GEO_ENTITY != b && c != this.getCountryCodeForValidRegion_
(b)) {
return !1;
}
c = this.getNationalSignificantNumber(a);
return this.getNumberTypeHelper_(c, d) != i18n.phonenumbers.PhoneNumberType.UNKNOWN;
}n/a
isValidRegionCode_ = function (a) {
return null != a && isNaN(a) && a.toUpperCase() in i18n.phonenumbers.metadata.countryToMetadata;
}n/a
maybeExtractCountryCode = function (a, b, c, d, e) {
if (0 == a.length) {
return 0;
}
a = new goog.string.StringBuffer(a);
var f;
null != b && (f = b.getInternationalPrefix());
null == f && (f = "NonMatch");
f = this.maybeStripInternationalPrefixAndNormalize(a, f);
d && e.setCountryCodeSource(f);
if (f != i18n.phonenumbers.PhoneNumber.CountryCodeSource.FROM_DEFAULT_COUNTRY) {
if (a.getLength() <= i18n.phonenumbers.PhoneNumberUtil.MIN_LENGTH_FOR_NSN_) {
throw Error(i18n.phonenumbers.Error.TOO_SHORT_AFTER_IDD);
}
b = this.extractCountryCode(a, c);
if (0 != b) {
return e.setCountryCode(b), b;
}
throw Error(i18n.phonenumbers.Error.INVALID_COUNTRY_CODE);
}
if (null != b) {
f = b.getCountryCodeOrDefault();
var g = "" + f, h = a.toString();
if (goog.string.startsWith(h, g) && (g = new goog.string.StringBuffer(h.substring(g.length)), h = b.getGeneralDesc(), h = new
RegExp(h.getNationalNumberPatternOrDefault()), this.maybeStripNationalPrefixAndCarrierCode(g, b, null), g = g.toString(), !i18n
.phonenumbers.PhoneNumberUtil.matchesEntirely_(h, a.toString()) && i18n.phonenumbers.PhoneNumberUtil.matchesEntirely_(h, g) || this
.testNumberLength_(a.toString(), b) == i18n.phonenumbers.PhoneNumberUtil.ValidationResult.TOO_LONG)) {
return c.append(g), d && e.setCountryCodeSource(i18n.phonenumbers.PhoneNumber.CountryCodeSource.FROM_NUMBER_WITHOUT_PLUS_SIGN
), e.setCountryCode(f), f;
}
}
e.setCountryCode(0);
return 0;
}n/a
maybeGetFormattedExtension_ = function (a, b, c) {
return a.hasExtension() && 0 != a.getExtension().length ? c == i18n.phonenumbers.PhoneNumberFormat.RFC3966 ? i18n.phonenumbers
.PhoneNumberUtil.RFC3966_EXTN_PREFIX_ + a.getExtension() : b.hasPreferredExtnPrefix() ? b.getPreferredExtnPrefix() + a.getExtensionOrDefault
() : i18n.phonenumbers.PhoneNumberUtil.DEFAULT_EXTN_PREFIX_ + a.getExtensionOrDefault() : "";
}n/a
maybeStripExtension = function (a) {
var b = a.toString(), c = b.search(i18n.phonenumbers.PhoneNumberUtil.EXTN_PATTERN_);
if (0 <= c && i18n.phonenumbers.PhoneNumberUtil.isViablePhoneNumber(b.substring(0, c))) {
for (var d = b.match(i18n.phonenumbers.PhoneNumberUtil.EXTN_PATTERN_), e = d.length, f = 1;f < e;++f) {
if (null != d[f] && 0 < d[f].length) {
return a.clear(), a.append(b.substring(0, c)), d[f];
}
}
}
return "";
}n/a
maybeStripInternationalPrefixAndNormalize = function (a, b) {
var c = a.toString();
if (0 == c.length) {
return i18n.phonenumbers.PhoneNumber.CountryCodeSource.FROM_DEFAULT_COUNTRY;
}
if (i18n.phonenumbers.PhoneNumberUtil.LEADING_PLUS_CHARS_PATTERN_.test(c)) {
return c = c.replace(i18n.phonenumbers.PhoneNumberUtil.LEADING_PLUS_CHARS_PATTERN_, ""), a.clear(), a.append(i18n.phonenumbers
.PhoneNumberUtil.normalize(c)), i18n.phonenumbers.PhoneNumber.CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN;
}
c = new RegExp(b);
i18n.phonenumbers.PhoneNumberUtil.normalizeSB_(a);
return this.parsePrefixAsIdd_(c, a) ? i18n.phonenumbers.PhoneNumber.CountryCodeSource.FROM_NUMBER_WITH_IDD : i18n.phonenumbers
.PhoneNumber.CountryCodeSource.FROM_DEFAULT_COUNTRY;
}n/a
maybeStripNationalPrefixAndCarrierCode = function (a, b, c) {
var d = a.toString(), e = d.length, f = b.getNationalPrefixForParsing();
if (0 == e || null == f || 0 == f.length) {
return !1;
}
var g = new RegExp("^(?:" + f + ")");
if (e = g.exec(d)) {
var f = new RegExp(b.getGeneralDesc().getNationalNumberPatternOrDefault()), h = i18n.phonenumbers.PhoneNumberUtil.matchesEntirely_
(f, d), k = e.length - 1;
b = b.getNationalPrefixTransformRule();
if (null == b || 0 == b.length || null == e[k] || 0 == e[k].length) {
if (h && !i18n.phonenumbers.PhoneNumberUtil.matchesEntirely_(f, d.substring(e[0].length))) {
return !1;
}
null != c && 0 < k && null != e[k] && c.append(e[1]);
a.set(d.substring(e[0].length));
} else {
d = d.replace(g, b);
if (h && !i18n.phonenumbers.PhoneNumberUtil.matchesEntirely_(f, d)) {
return !1;
}
null != c && 0 < k && c.append(e[1]);
a.set(d);
}
return !0;
}
return !1;
}n/a
parse = function (a, b) {
return this.parseHelper_(a, b, !1, !0);
}...
// Require `PhoneNumberFormat`.
var PNF = require('google-libphonenumber').PhoneNumberFormat;
// Get an instance of `PhoneNumberUtil`.
var phoneUtil = require('google-libphonenumber').PhoneNumberUtil.getInstance();
// Parse number with country code.
var phoneNumber = phoneUtil.parse('202-456-1414', 'US');
// Print number in the international format.
console.log(phoneUtil.format(phoneNumber, PNF.INTERNATIONAL));
// => +1 202-456-1414
```
#### Using the "As You Type" Formatter
...parseAndKeepRawInput = function (a, b) {
if (!this.isValidRegionCode_(b) && 0 < a.length && a.charAt(0) != i18n.phonenumbers.PhoneNumberUtil.PLUS_SIGN) {
throw Error(i18n.phonenumbers.Error.INVALID_COUNTRY_CODE);
}
return this.parseHelper_(a, b, !0, !0);
}n/a
parseHelper_ = function (a, b, c, d) {
if (null == a) {
throw Error(i18n.phonenumbers.Error.NOT_A_NUMBER);
}
if (a.length > i18n.phonenumbers.PhoneNumberUtil.MAX_INPUT_STRING_LENGTH_) {
throw Error(i18n.phonenumbers.Error.TOO_LONG);
}
var e = new goog.string.StringBuffer;
this.buildNationalNumberForParsing_(a, e);
if (!i18n.phonenumbers.PhoneNumberUtil.isViablePhoneNumber(e.toString())) {
throw Error(i18n.phonenumbers.Error.NOT_A_NUMBER);
}
if (d && !this.checkRegionForParsing_(e.toString(), b)) {
throw Error(i18n.phonenumbers.Error.INVALID_COUNTRY_CODE);
}
d = new i18n.phonenumbers.PhoneNumber;
c && d.setRawInput(a);
a = this.maybeStripExtension(e);
0 < a.length && d.setExtension(a);
a = this.getMetadataForRegion(b);
var f = new goog.string.StringBuffer, g = 0, h = e.toString();
try {
g = this.maybeExtractCountryCode(h, a, f, c, d);
} catch (k) {
if (k.message == i18n.phonenumbers.Error.INVALID_COUNTRY_CODE && i18n.phonenumbers.PhoneNumberUtil.LEADING_PLUS_CHARS_PATTERN_
.test(h)) {
if (h = h.replace(i18n.phonenumbers.PhoneNumberUtil.LEADING_PLUS_CHARS_PATTERN_, ""), g = this.maybeExtractCountryCode(h,
a, f, c, d), 0 == g) {
throw k;
}
} else {
throw k;
}
}
0 != g ? (e = this.getRegionCodeForCountryCode(g), e != b && (a = this.getMetadataForRegionOrCallingCode_(g, e))) : (i18n.phonenumbers
.PhoneNumberUtil.normalizeSB_(e), f.append(e.toString()), null != b ? (g = a.getCountryCodeOrDefault(), d.setCountryCode(g)) : c
&& d.clearCountryCodeSource());
if (f.getLength() < i18n.phonenumbers.PhoneNumberUtil.MIN_LENGTH_FOR_NSN_) {
throw Error(i18n.phonenumbers.Error.TOO_SHORT_NSN);
}
null != a && (b = new goog.string.StringBuffer, e = new goog.string.StringBuffer(f.toString()), this.maybeStripNationalPrefixAndCarrierCode
(e, a, b), this.testNumberLength_(e.toString(), a) != i18n.phonenumbers.PhoneNumberUtil.ValidationResult.TOO_SHORT && (f = e, c &&
0 < b.toString().length && d.setPreferredDomesticCarrierCode(b.toString())));
c = f.toString();
b = c.length;
if (b < i18n.phonenumbers.PhoneNumberUtil.MIN_LENGTH_FOR_NSN_) {
throw Error(i18n.phonenumbers.Error.TOO_SHORT_NSN);
}
if (b > i18n.phonenumbers.PhoneNumberUtil.MAX_LENGTH_FOR_NSN_) {
throw Error(i18n.phonenumbers.Error.TOO_LONG);
}
i18n.phonenumbers.PhoneNumberUtil.setItalianLeadingZerosForPhoneNumber_(c, d);
d.setNationalNumber(parseInt(c, 10));
return d;
}n/a
parsePrefixAsIdd_ = function (a, b) {
var c = b.toString();
if (0 == c.search(a)) {
var d = c.match(a)[0].length, e = c.substring(d).match(i18n.phonenumbers.PhoneNumberUtil.CAPTURING_DIGIT_PATTERN);
if (e && null != e[1] && 0 < e[1].length && "0" == i18n.phonenumbers.PhoneNumberUtil.normalizeDigitsOnly(e[1])) {
return !1;
}
b.clear();
b.append(c.substring(d));
return !0;
}
return !1;
}n/a
prefixNumberWithCountryCallingCode_ = function (a, b, c, d) {
switch(b) {
case i18n.phonenumbers.PhoneNumberFormat.E164:
return i18n.phonenumbers.PhoneNumberUtil.PLUS_SIGN + a + c + d;
case i18n.phonenumbers.PhoneNumberFormat.INTERNATIONAL:
return i18n.phonenumbers.PhoneNumberUtil.PLUS_SIGN + a + " " + c + d;
case i18n.phonenumbers.PhoneNumberFormat.RFC3966:
return i18n.phonenumbers.PhoneNumberUtil.RFC3966_PREFIX_ + i18n.phonenumbers.PhoneNumberUtil.PLUS_SIGN + a + "-" + c + d;
default:
return c + d;
}
}n/a
rawInputContainsNationalPrefix_ = function (a, b, c) {
a = i18n.phonenumbers.PhoneNumberUtil.normalizeDigitsOnly(a);
if (goog.string.startsWith(a, b)) {
try {
return this.isValidNumber(this.parse(a.substring(b.length), c));
} catch (d) {
}
}
return !1;
}n/a
testNumberLengthForType_ = function (a, b, c) {
var d = i18n.phonenumbers.PhoneNumberUtil.getNumberDescByType_(b, c), e = 0 == d.possibleLengthCount() ? b.getGeneralDesc().possibleLengthArray
() : d.possibleLengthArray(), d = d.possibleLengthLocalOnlyArray();
if (c == i18n.phonenumbers.PhoneNumberType.FIXED_LINE_OR_MOBILE) {
if (i18n.phonenumbers.PhoneNumberUtil.descHasPossibleNumberData_(i18n.phonenumbers.PhoneNumberUtil.getNumberDescByType_(b, i18n
.phonenumbers.PhoneNumberType.FIXED_LINE))) {
c = i18n.phonenumbers.PhoneNumberUtil.getNumberDescByType_(b, i18n.phonenumbers.PhoneNumberType.MOBILE), i18n.phonenumbers
.PhoneNumberUtil.descHasPossibleNumberData_(c) && (e = e.concat(0 == c.possibleLengthCount() ? b.getGeneralDesc().possibleLengthArray
() : c.possibleLengthArray()), goog.array.sort(e), 0 == d.length ? d = c.possibleLengthLocalOnlyArray() : (d = d.concat(c.possibleLengthLocalOnlyArray
()), goog.array.sort(d)));
} else {
return this.testNumberLengthForType_(a, b, i18n.phonenumbers.PhoneNumberType.MOBILE);
}
}
if (-1 == e[0]) {
return i18n.phonenumbers.PhoneNumberUtil.ValidationResult.INVALID_LENGTH;
}
a = a.length;
if (-1 < goog.array.indexOf(d, a)) {
return i18n.phonenumbers.PhoneNumberUtil.ValidationResult.IS_POSSIBLE_LOCAL_ONLY;
}
b = e[0];
return b == a ? i18n.phonenumbers.PhoneNumberUtil.ValidationResult.IS_POSSIBLE : b > a ? i18n.phonenumbers.PhoneNumberUtil.ValidationResult
.TOO_SHORT : e[e.length - 1] < a ? i18n.phonenumbers.PhoneNumberUtil.ValidationResult.TOO_LONG : -1 < goog.array.indexOf(e, a, 1
) ? i18n.phonenumbers.PhoneNumberUtil.ValidationResult.IS_POSSIBLE : i18n.phonenumbers.PhoneNumberUtil.ValidationResult.INVALID_LENGTH
;
}n/a
testNumberLength_ = function (a, b) {
return this.testNumberLengthForType_(a, b, i18n.phonenumbers.PhoneNumberType.UNKNOWN);
}n/a
truncateTooLongNumber = function (a) {
if (this.isValidNumber(a)) {
return !0;
}
var b = a.clone(), c = a.getNationalNumberOrDefault();
do {
if (c = Math.floor(c / 10), b.setNationalNumber(c), 0 == c || this.isPossibleNumberWithReason(b) == i18n.phonenumbers.PhoneNumberUtil
.ValidationResult.TOO_SHORT) {
return !1;
}
} while (!this.isValidNumber(b));
a.setNationalNumber(c);
return !0;
}n/a