libphonenumber-js 1.10.31 → 1.10.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/build/AsYouType.js +5 -1
  2. package/build/AsYouType.js.map +1 -1
  3. package/build/AsYouType.test.js +6 -0
  4. package/build/AsYouType.test.js.map +1 -1
  5. package/build/PhoneNumber.js +15 -9
  6. package/build/PhoneNumber.js.map +1 -1
  7. package/build/PhoneNumberMatcher.js +6 -1
  8. package/build/PhoneNumberMatcher.js.map +1 -1
  9. package/build/findNumbers/Leniency.js +38 -9
  10. package/build/findNumbers/Leniency.js.map +1 -1
  11. package/build/helpers/getCountryByCallingCode.js +10 -2
  12. package/build/helpers/getCountryByCallingCode.js.map +1 -1
  13. package/build/helpers/getCountryByNationalNumber.js +23 -3
  14. package/build/helpers/getCountryByNationalNumber.js.map +1 -1
  15. package/build/parse.js +5 -1
  16. package/build/parse.js.map +1 -1
  17. package/build/parse.test.js +8 -0
  18. package/build/parse.test.js.map +1 -1
  19. package/bundle/libphonenumber-js.min.js +1 -1
  20. package/bundle/libphonenumber-js.min.js.map +1 -1
  21. package/bundle/libphonenumber-max.js +1 -1
  22. package/bundle/libphonenumber-max.js.map +1 -1
  23. package/bundle/libphonenumber-min.js +1 -1
  24. package/bundle/libphonenumber-min.js.map +1 -1
  25. package/bundle/libphonenumber-mobile.js +1 -1
  26. package/bundle/libphonenumber-mobile.js.map +1 -1
  27. package/es6/AsYouType.js +5 -1
  28. package/es6/AsYouType.js.map +1 -1
  29. package/es6/AsYouType.test.js +6 -0
  30. package/es6/AsYouType.test.js.map +1 -1
  31. package/es6/PhoneNumber.js +15 -9
  32. package/es6/PhoneNumber.js.map +1 -1
  33. package/es6/PhoneNumberMatcher.js +6 -1
  34. package/es6/PhoneNumberMatcher.js.map +1 -1
  35. package/es6/findNumbers/Leniency.js +38 -9
  36. package/es6/findNumbers/Leniency.js.map +1 -1
  37. package/es6/helpers/getCountryByCallingCode.js +10 -2
  38. package/es6/helpers/getCountryByCallingCode.js.map +1 -1
  39. package/es6/helpers/getCountryByNationalNumber.js +23 -3
  40. package/es6/helpers/getCountryByNationalNumber.js.map +1 -1
  41. package/es6/parse.js +5 -1
  42. package/es6/parse.js.map +1 -1
  43. package/es6/parse.test.js +8 -0
  44. package/es6/parse.test.js.map +1 -1
  45. package/package.json +1 -1
  46. package/source/AsYouType.js +5 -2
  47. package/source/AsYouType.test.js +7 -0
  48. package/source/PhoneNumber.js +12 -8
  49. package/source/PhoneNumberMatcher.js +6 -1
  50. package/source/findNumbers/Leniency.js +13 -9
  51. package/source/helpers/getCountryByCallingCode.js +10 -2
  52. package/source/helpers/getCountryByNationalNumber.js +21 -3
  53. package/source/parse.js +5 -1
  54. package/source/parse.test.js +6 -0
@@ -48,8 +48,14 @@ var PhoneNumber = /*#__PURE__*/function () {
48
48
  this.country = country;
49
49
  this.countryCallingCode = countryCallingCode;
50
50
  this.nationalNumber = nationalNumber;
51
- this.number = '+' + this.countryCallingCode + this.nationalNumber;
52
- this.metadata = metadata;
51
+ this.number = '+' + this.countryCallingCode + this.nationalNumber; // Exclude `metadata` property output from `PhoneNumber.toString()`
52
+ // so that it doesn't clutter the console output of Node.js.
53
+ // Previously, when Node.js did `console.log(new PhoneNumber(...))`,
54
+ // it would output the whole internal structure of the `metadata` object.
55
+
56
+ this.getMetadata = function () {
57
+ return metadata;
58
+ };
53
59
  }
54
60
 
55
61
  _createClass(PhoneNumber, [{
@@ -64,26 +70,26 @@ var PhoneNumber = /*#__PURE__*/function () {
64
70
  return [this.country];
65
71
  }
66
72
 
67
- return getPossibleCountriesForNumber(this.countryCallingCode, this.nationalNumber, this.metadata);
73
+ return getPossibleCountriesForNumber(this.countryCallingCode, this.nationalNumber, this.getMetadata());
68
74
  }
69
75
  }, {
70
76
  key: "isPossible",
71
77
  value: function isPossible() {
72
78
  return isPossibleNumber(this, {
73
79
  v2: true
74
- }, this.metadata);
80
+ }, this.getMetadata());
75
81
  }
76
82
  }, {
77
83
  key: "isValid",
78
84
  value: function isValid() {
79
85
  return isValidNumber(this, {
80
86
  v2: true
81
- }, this.metadata);
87
+ }, this.getMetadata());
82
88
  }
83
89
  }, {
84
90
  key: "isNonGeographic",
85
91
  value: function isNonGeographic() {
86
- var metadata = new Metadata(this.metadata);
92
+ var metadata = new Metadata(this.getMetadata());
87
93
  return metadata.isNonGeographicCallingCode(this.countryCallingCode);
88
94
  }
89
95
  }, {
@@ -97,7 +103,7 @@ var PhoneNumber = /*#__PURE__*/function () {
97
103
  // and just left the `validatePhoneNumberLength()` function, even though that one would require
98
104
  // and additional step to also validate the actual country / calling code of the phone number.
99
105
  // validateLength() {
100
- // const metadata = new Metadata(this.metadata)
106
+ // const metadata = new Metadata(this.getMetadata())
101
107
  // metadata.selectNumberingPlan(this.countryCallingCode)
102
108
  // const result = checkNumberLength(this.nationalNumber, metadata)
103
109
  // if (result !== 'IS_POSSIBLE') {
@@ -110,7 +116,7 @@ var PhoneNumber = /*#__PURE__*/function () {
110
116
  value: function getType() {
111
117
  return getNumberType(this, {
112
118
  v2: true
113
- }, this.metadata);
119
+ }, this.getMetadata());
114
120
  }
115
121
  }, {
116
122
  key: "format",
@@ -119,7 +125,7 @@ var PhoneNumber = /*#__PURE__*/function () {
119
125
  v2: true
120
126
  }) : {
121
127
  v2: true
122
- }, this.metadata);
128
+ }, this.getMetadata());
123
129
  }
124
130
  }, {
125
131
  key: "formatNational",
@@ -1 +1 @@
1
- {"version":3,"file":"PhoneNumber.js","names":["Metadata","isPossibleNumber","isValidNumber","getNumberType","getPossibleCountriesForNumber","formatNumber","USE_NON_GEOGRAPHIC_COUNTRY_CODE","PhoneNumber","countryOrCountryCallingCode","nationalNumber","metadata","TypeError","getCountryAndCountryCallingCode","country","countryCallingCode","number","ext","v2","isNonGeographicCallingCode","phoneNumber","format","options","isCountryCode","value","test","metadataJson","selectNumberingPlan"],"sources":["../source/PhoneNumber.js"],"sourcesContent":["import Metadata from './metadata.js'\r\nimport isPossibleNumber from './isPossible.js'\r\nimport isValidNumber from './isValid.js'\r\n// import checkNumberLength from './helpers/checkNumberLength.js'\r\nimport getNumberType from './helpers/getNumberType.js'\r\nimport getPossibleCountriesForNumber from './helpers/getPossibleCountriesForNumber.js'\r\nimport formatNumber from './format.js'\r\n\r\nconst USE_NON_GEOGRAPHIC_COUNTRY_CODE = false\r\n\r\nexport default class PhoneNumber {\r\n\t/**\r\n\t * @param {string} countryOrCountryCallingCode\r\n\t * @param {string} nationalNumber\r\n\t * @param {object} metadata — Metadata JSON\r\n\t * @return {PhoneNumber}\r\n\t */\r\n\tconstructor(countryOrCountryCallingCode, nationalNumber, metadata) {\r\n\t\tif (!countryOrCountryCallingCode) {\r\n\t\t\tthrow new TypeError('`country` or `countryCallingCode` not passed')\r\n\t\t}\r\n\t\tif (!nationalNumber) {\r\n\t\t\tthrow new TypeError('`nationalNumber` not passed')\r\n\t\t}\r\n\t\tif (!metadata) {\r\n\t\t\tthrow new TypeError('`metadata` not passed')\r\n\t\t}\r\n\t\tconst { country, countryCallingCode } = getCountryAndCountryCallingCode(\r\n\t\t\tcountryOrCountryCallingCode,\r\n\t\t\tmetadata\r\n\t\t)\r\n\t\tthis.country = country\r\n\t\tthis.countryCallingCode = countryCallingCode\r\n\t\tthis.nationalNumber = nationalNumber\r\n\t\tthis.number = '+' + this.countryCallingCode + this.nationalNumber\r\n\t\tthis.metadata = metadata\r\n\t}\r\n\r\n\tsetExt(ext) {\r\n\t\tthis.ext = ext\r\n\t}\r\n\r\n\tgetPossibleCountries() {\r\n\t\tif (this.country) {\r\n\t\t\treturn [this.country]\r\n\t\t}\r\n\t\treturn getPossibleCountriesForNumber(\r\n\t\t\tthis.countryCallingCode,\r\n\t\t\tthis.nationalNumber,\r\n\t\t\tthis.metadata\r\n\t\t)\r\n\t}\r\n\r\n\tisPossible() {\r\n\t\treturn isPossibleNumber(this, { v2: true }, this.metadata)\r\n\t}\r\n\r\n\tisValid() {\r\n\t\treturn isValidNumber(this, { v2: true }, this.metadata)\r\n\t}\r\n\r\n\tisNonGeographic() {\r\n\t\tconst metadata = new Metadata(this.metadata)\r\n\t\treturn metadata.isNonGeographicCallingCode(this.countryCallingCode)\r\n\t}\r\n\r\n\tisEqual(phoneNumber) {\r\n\t\treturn this.number === phoneNumber.number && this.ext === phoneNumber.ext\r\n\t}\r\n\r\n\t// This function was originally meant to be an equivalent for `validatePhoneNumberLength()`,\r\n\t// but later it was found out that it doesn't include the possible `TOO_SHORT` result\r\n\t// returned from `parsePhoneNumberWithError()` in the original `validatePhoneNumberLength()`,\r\n\t// so eventually I simply commented out this method from the `PhoneNumber` class\r\n\t// and just left the `validatePhoneNumberLength()` function, even though that one would require\r\n\t// and additional step to also validate the actual country / calling code of the phone number.\r\n\t// validateLength() {\r\n\t// \tconst metadata = new Metadata(this.metadata)\r\n\t// \tmetadata.selectNumberingPlan(this.countryCallingCode)\r\n\t// \tconst result = checkNumberLength(this.nationalNumber, metadata)\r\n\t// \tif (result !== 'IS_POSSIBLE') {\r\n\t// \t\treturn result\r\n\t// \t}\r\n\t// }\r\n\r\n\tgetType() {\r\n\t\treturn getNumberType(this, { v2: true }, this.metadata)\r\n\t}\r\n\r\n\tformat(format, options) {\r\n\t\treturn formatNumber(\r\n\t\t\tthis,\r\n\t\t\tformat,\r\n\t\t\toptions ? { ...options, v2: true } : { v2: true },\r\n\t\t\tthis.metadata\r\n\t\t)\r\n\t}\r\n\r\n\tformatNational(options) {\r\n\t\treturn this.format('NATIONAL', options)\r\n\t}\r\n\r\n\tformatInternational(options) {\r\n\t\treturn this.format('INTERNATIONAL', options)\r\n\t}\r\n\r\n\tgetURI(options) {\r\n\t\treturn this.format('RFC3966', options)\r\n\t}\r\n}\r\n\r\nconst isCountryCode = (value) => /^[A-Z]{2}$/.test(value)\r\n\r\nfunction getCountryAndCountryCallingCode(countryOrCountryCallingCode, metadataJson) {\r\n\tlet country\r\n\tlet countryCallingCode\r\n\r\n\tconst metadata = new Metadata(metadataJson)\r\n\t// If country code is passed then derive `countryCallingCode` from it.\r\n\t// Also store the country code as `.country`.\r\n\tif (isCountryCode(countryOrCountryCallingCode)) {\r\n\t\tcountry = countryOrCountryCallingCode\r\n\t\tmetadata.selectNumberingPlan(country)\r\n\t\tcountryCallingCode = metadata.countryCallingCode()\r\n\t} else {\r\n\t\tcountryCallingCode = countryOrCountryCallingCode\r\n\t\t/* istanbul ignore if */\r\n\t\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\t\tif (metadata.isNonGeographicCallingCode(countryCallingCode)) {\r\n\t\t\t\tcountry = '001'\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\treturn {\r\n\t\tcountry,\r\n\t\tcountryCallingCode\r\n\t}\r\n}"],"mappings":";;;;;;;;;;;;AAAA,OAAOA,QAAP,MAAqB,eAArB;AACA,OAAOC,gBAAP,MAA6B,iBAA7B;AACA,OAAOC,aAAP,MAA0B,cAA1B,C,CACA;;AACA,OAAOC,aAAP,MAA0B,4BAA1B;AACA,OAAOC,6BAAP,MAA0C,4CAA1C;AACA,OAAOC,YAAP,MAAyB,aAAzB;AAEA,IAAMC,+BAA+B,GAAG,KAAxC;;IAEqBC,W;EACpB;AACD;AACA;AACA;AACA;AACA;EACC,qBAAYC,2BAAZ,EAAyCC,cAAzC,EAAyDC,QAAzD,EAAmE;IAAA;;IAClE,IAAI,CAACF,2BAAL,EAAkC;MACjC,MAAM,IAAIG,SAAJ,CAAc,8CAAd,CAAN;IACA;;IACD,IAAI,CAACF,cAAL,EAAqB;MACpB,MAAM,IAAIE,SAAJ,CAAc,6BAAd,CAAN;IACA;;IACD,IAAI,CAACD,QAAL,EAAe;MACd,MAAM,IAAIC,SAAJ,CAAc,uBAAd,CAAN;IACA;;IACD,4BAAwCC,+BAA+B,CACtEJ,2BADsE,EAEtEE,QAFsE,CAAvE;IAAA,IAAQG,OAAR,yBAAQA,OAAR;IAAA,IAAiBC,kBAAjB,yBAAiBA,kBAAjB;;I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","isPossibleNumber","isValidNumber","getNumberType","getPossibleCountriesForNumber","formatNumber","USE_NON_GEOGRAPHIC_COUNTRY_CODE","PhoneNumber","countryOrCountryCallingCode","nationalNumber","metadata","TypeError","getCountryAndCountryCallingCode","country","countryCallingCode","number","getMetadata","ext","v2","isNonGeographicCallingCode","phoneNumber","format","options","isCountryCode","value","test","metadataJson","selectNumberingPlan"],"sources":["../source/PhoneNumber.js"],"sourcesContent":["import Metadata from './metadata.js'\r\nimport isPossibleNumber from './isPossible.js'\r\nimport isValidNumber from './isValid.js'\r\n// import checkNumberLength from './helpers/checkNumberLength.js'\r\nimport getNumberType from './helpers/getNumberType.js'\r\nimport getPossibleCountriesForNumber from './helpers/getPossibleCountriesForNumber.js'\r\nimport formatNumber from './format.js'\r\n\r\nconst USE_NON_GEOGRAPHIC_COUNTRY_CODE = false\r\n\r\nexport default class PhoneNumber {\r\n\t/**\r\n\t * @param {string} countryOrCountryCallingCode\r\n\t * @param {string} nationalNumber\r\n\t * @param {object} metadata — Metadata JSON\r\n\t * @return {PhoneNumber}\r\n\t */\r\n\tconstructor(countryOrCountryCallingCode, nationalNumber, metadata) {\r\n\t\tif (!countryOrCountryCallingCode) {\r\n\t\t\tthrow new TypeError('`country` or `countryCallingCode` not passed')\r\n\t\t}\r\n\t\tif (!nationalNumber) {\r\n\t\t\tthrow new TypeError('`nationalNumber` not passed')\r\n\t\t}\r\n\t\tif (!metadata) {\r\n\t\t\tthrow new TypeError('`metadata` not passed')\r\n\t\t}\r\n\t\tconst { country, countryCallingCode } = getCountryAndCountryCallingCode(\r\n\t\t\tcountryOrCountryCallingCode,\r\n\t\t\tmetadata\r\n\t\t)\r\n\t\tthis.country = country\r\n\t\tthis.countryCallingCode = countryCallingCode\r\n\t\tthis.nationalNumber = nationalNumber\r\n\t\tthis.number = '+' + this.countryCallingCode + this.nationalNumber\r\n\t\t// Exclude `metadata` property output from `PhoneNumber.toString()`\r\n\t\t// so that it doesn't clutter the console output of Node.js.\r\n\t\t// Previously, when Node.js did `console.log(new PhoneNumber(...))`,\r\n\t\t// it would output the whole internal structure of the `metadata` object.\r\n\t\tthis.getMetadata = () => metadata\r\n\t}\r\n\r\n\tsetExt(ext) {\r\n\t\tthis.ext = ext\r\n\t}\r\n\r\n\tgetPossibleCountries() {\r\n\t\tif (this.country) {\r\n\t\t\treturn [this.country]\r\n\t\t}\r\n\t\treturn getPossibleCountriesForNumber(\r\n\t\t\tthis.countryCallingCode,\r\n\t\t\tthis.nationalNumber,\r\n\t\t\tthis.getMetadata()\r\n\t\t)\r\n\t}\r\n\r\n\tisPossible() {\r\n\t\treturn isPossibleNumber(this, { v2: true }, this.getMetadata())\r\n\t}\r\n\r\n\tisValid() {\r\n\t\treturn isValidNumber(this, { v2: true }, this.getMetadata())\r\n\t}\r\n\r\n\tisNonGeographic() {\r\n\t\tconst metadata = new Metadata(this.getMetadata())\r\n\t\treturn metadata.isNonGeographicCallingCode(this.countryCallingCode)\r\n\t}\r\n\r\n\tisEqual(phoneNumber) {\r\n\t\treturn this.number === phoneNumber.number && this.ext === phoneNumber.ext\r\n\t}\r\n\r\n\t// This function was originally meant to be an equivalent for `validatePhoneNumberLength()`,\r\n\t// but later it was found out that it doesn't include the possible `TOO_SHORT` result\r\n\t// returned from `parsePhoneNumberWithError()` in the original `validatePhoneNumberLength()`,\r\n\t// so eventually I simply commented out this method from the `PhoneNumber` class\r\n\t// and just left the `validatePhoneNumberLength()` function, even though that one would require\r\n\t// and additional step to also validate the actual country / calling code of the phone number.\r\n\t// validateLength() {\r\n\t// \tconst metadata = new Metadata(this.getMetadata())\r\n\t// \tmetadata.selectNumberingPlan(this.countryCallingCode)\r\n\t// \tconst result = checkNumberLength(this.nationalNumber, metadata)\r\n\t// \tif (result !== 'IS_POSSIBLE') {\r\n\t// \t\treturn result\r\n\t// \t}\r\n\t// }\r\n\r\n\tgetType() {\r\n\t\treturn getNumberType(this, { v2: true }, this.getMetadata())\r\n\t}\r\n\r\n\tformat(format, options) {\r\n\t\treturn formatNumber(\r\n\t\t\tthis,\r\n\t\t\tformat,\r\n\t\t\toptions ? { ...options, v2: true } : { v2: true },\r\n\t\t\tthis.getMetadata()\r\n\t\t)\r\n\t}\r\n\r\n\tformatNational(options) {\r\n\t\treturn this.format('NATIONAL', options)\r\n\t}\r\n\r\n\tformatInternational(options) {\r\n\t\treturn this.format('INTERNATIONAL', options)\r\n\t}\r\n\r\n\tgetURI(options) {\r\n\t\treturn this.format('RFC3966', options)\r\n\t}\r\n}\r\n\r\nconst isCountryCode = (value) => /^[A-Z]{2}$/.test(value)\r\n\r\nfunction getCountryAndCountryCallingCode(countryOrCountryCallingCode, metadataJson) {\r\n\tlet country\r\n\tlet countryCallingCode\r\n\r\n\tconst metadata = new Metadata(metadataJson)\r\n\t// If country code is passed then derive `countryCallingCode` from it.\r\n\t// Also store the country code as `.country`.\r\n\tif (isCountryCode(countryOrCountryCallingCode)) {\r\n\t\tcountry = countryOrCountryCallingCode\r\n\t\tmetadata.selectNumberingPlan(country)\r\n\t\tcountryCallingCode = metadata.countryCallingCode()\r\n\t} else {\r\n\t\tcountryCallingCode = countryOrCountryCallingCode\r\n\t\t/* istanbul ignore if */\r\n\t\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\t\tif (metadata.isNonGeographicCallingCode(countryCallingCode)) {\r\n\t\t\t\tcountry = '001'\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\treturn {\r\n\t\tcountry,\r\n\t\tcountryCallingCode\r\n\t}\r\n}"],"mappings":";;;;;;;;;;;;AAAA,OAAOA,QAAP,MAAqB,eAArB;AACA,OAAOC,gBAAP,MAA6B,iBAA7B;AACA,OAAOC,aAAP,MAA0B,cAA1B,C,CACA;;AACA,OAAOC,aAAP,MAA0B,4BAA1B;AACA,OAAOC,6BAAP,MAA0C,4CAA1C;AACA,OAAOC,YAAP,MAAyB,aAAzB;AAEA,IAAMC,+BAA+B,GAAG,KAAxC;;IAEqBC,W;EACpB;AACD;AACA;A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EAEA,IAAMJ,QAAQ,GAAG,IAAIV,QAAJ,CAAa0B,YAAb,CAAjB,CAJmF,CAKnF;EACA;;EACA,IAAIH,aAAa,CAACf,2BAAD,CAAjB,EAAgD;IAC/CK,OAAO,GAAGL,2BAAV;IACAE,QAAQ,CAACiB,mBAAT,CAA6Bd,OAA7B;IACAC,kBAAkB,GAAGJ,QAAQ,CAACI,kBAAT,EAArB;EACA,CAJD,MAIO;IACNA,kBAAkB,GAAGN,2BAArB;IACA;;IACA,IAAIF,+BAAJ,EAAqC;MACpC,IAAII,QAAQ,CAACS,0BAAT,CAAoCL,kBAApC,CAAJ,EAA6D;QAC5DD,OAAO,GAAG,KAAV;MACA;IACD;EACD;;EAED,OAAO;IACNA,OAAO,EAAPA,OADM;IAENC,kBAAkB,EAAlBA;EAFM,CAAP;AAIA"}
@@ -310,7 +310,12 @@ var PhoneNumberMatcher = /*#__PURE__*/function () {
310
310
  return;
311
311
  }
312
312
 
313
- if (this.leniency(phoneNumber, candidate, this.metadata, this.regExpCache)) {
313
+ if (this.leniency(phoneNumber, {
314
+ candidate: candidate,
315
+ defaultCountry: this.options.defaultCountry,
316
+ metadata: this.metadata,
317
+ regExpCache: this.regExpCache
318
+ })) {
314
319
  return {
315
320
  startsAt: offset,
316
321
  endsAt: offset + candidate.length,
@@ -1 +1 @@
1
- {"version":3,"file":"PhoneNumberMatcher.js","names":["PhoneNumber","MAX_LENGTH_FOR_NSN","MAX_LENGTH_COUNTRY_CODE","VALID_PUNCTUATION","createExtensionPattern","RegExpCache","limit","trimAfterFirstMatch","_pL","_pN","pZ","PZ","pNd","Leniency","parsePreCandidate","isValidPreCandidate","isValidCandidate","LEAD_CLASS","isSupportedCountry","parsePhoneNumber","USE_NON_GEOGRAPHIC_COUNTRY_CODE","EXTN_PATTERNS_FOR_MATCHING","INNER_MATCHES","leadLimit","punctuationLimit","digitBlockLimit","blockLimit","punctuation","digitSequence","PATTERN","UNWANTED_END_CHAR_PATTERN","RegExp","NON_DIGITS_PATTERN","MAX_SAFE_INTEGER","Number","Math","pow","PhoneNumberMatcher","text","options","metadata","v2","defaultCallingCode","defaultCountry","undefined","leniency","extended","maxTries","TypeError","state","searchIndex","regExpCache","matches","exec","candidate","offset","index","match","parseAndVerify","extractInnerMatch","startsAt","endsAt","number","phoneNumber","result","phone","nationalNumber","country","countryCallingCode","ext","substring","innerMatchPattern","isFirstMatch","candidateMatch","innerMatchRegExp","slice","candidateIndexGuess","indexOf","isPossible","length","lastMatch","find","hasNext","Error"],"sources":["../source/PhoneNumberMatcher.js"],"sourcesContent":["/**\r\n * A port of Google's `PhoneNumberMatcher.java`.\r\n * https://github.com/googlei18n/libphonenumber/blob/master/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberMatcher.java\r\n * Date: 08.03.2018.\r\n */\r\n\r\nimport PhoneNumber from './PhoneNumber.js'\r\n\r\nimport {\r\n MAX_LENGTH_FOR_NSN,\r\n MAX_LENGTH_COUNTRY_CODE,\r\n VALID_PUNCTUATION\r\n} from './constants.js'\r\n\r\nimport createExtensionPattern from './helpers/extension/createExtensionPattern.js'\r\n\r\nimport RegExpCache from './findNumbers/RegExpCache.js'\r\n\r\nimport {\r\n\tlimit,\r\n\ttrimAfterFirstMatch\r\n} from './findNumbers/util.js'\r\n\r\nimport {\r\n\t_pL,\r\n\t_pN,\r\n\tpZ,\r\n\tPZ,\r\n\tpNd\r\n} from './findNumbers/utf-8.js'\r\n\r\nimport Leniency from './findNumbers/Leniency.js'\r\nimport parsePreCandidate from './findNumbers/parsePreCandidate.js'\r\nimport isValidPreCandidate from './findNumbers/isValidPreCandidate.js'\r\nimport isValidCandidate, { LEAD_CLASS } from './findNumbers/isValidCandidate.js'\r\n\r\nimport { isSupportedCountry } from './metadata.js'\r\n\r\nimport parsePhoneNumber from './parsePhoneNumber.js'\r\n\r\nconst USE_NON_GEOGRAPHIC_COUNTRY_CODE = false\r\n\r\nconst EXTN_PATTERNS_FOR_MATCHING = createExtensionPattern('matching')\r\n\r\n/**\r\n * Patterns used to extract phone numbers from a larger phone-number-like pattern. These are\r\n * ordered according to specificity. For example, white-space is last since that is frequently\r\n * used in numbers, not just to separate two numbers. We have separate patterns since we don't\r\n * want to break up the phone-number-like text on more than one different kind of symbol at one\r\n * time, although symbols of the same type (e.g. space) can be safely grouped together.\r\n *\r\n * Note that if there is a match, we will always check any text found up to the first match as\r\n * well.\r\n */\r\nconst INNER_MATCHES =\r\n[\r\n\t// Breaks on the slash - e.g. \"651-234-2345/332-445-1234\"\r\n\t'\\\\/+(.*)/',\r\n\r\n\t// Note that the bracket here is inside the capturing group, since we consider it part of the\r\n\t// phone number. Will match a pattern like \"(650) 223 3345 (754) 223 3321\".\r\n\t'(\\\\([^(]*)',\r\n\r\n\t// Breaks on a hyphen - e.g. \"12345 - 332-445-1234 is my number.\"\r\n\t// We require a space on either side of the hyphen for it to be considered a separator.\r\n\t`(?:${pZ}-|-${pZ})${pZ}*(.+)`,\r\n\r\n\t// Various types of wide hyphens. Note we have decided not to enforce a space here, since it's\r\n\t// possible that it's supposed to be used to break two numbers without spaces, and we haven't\r\n\t// seen many instances of it used within a number.\r\n\t`[\\u2012-\\u2015\\uFF0D]${pZ}*(.+)`,\r\n\r\n\t// Breaks on a full stop - e.g. \"12345. 332-445-1234 is my number.\"\r\n\t`\\\\.+${pZ}*([^.]+)`,\r\n\r\n\t// Breaks on space - e.g. \"3324451234 8002341234\"\r\n\t`${pZ}+(${PZ}+)`\r\n]\r\n\r\n// Limit on the number of leading (plus) characters.\r\nconst leadLimit = limit(0, 2)\r\n\r\n// Limit on the number of consecutive punctuation characters.\r\nconst punctuationLimit = limit(0, 4)\r\n\r\n/* The maximum number of digits allowed in a digit-separated block. As we allow all digits in a\r\n * single block, set high enough to accommodate the entire national number and the international\r\n * country code. */\r\nconst digitBlockLimit = MAX_LENGTH_FOR_NSN + MAX_LENGTH_COUNTRY_CODE\r\n\r\n// Limit on the number of blocks separated by punctuation.\r\n// Uses digitBlockLimit since some formats use spaces to separate each digit.\r\nconst blockLimit = limit(0, digitBlockLimit)\r\n\r\n/* A punctuation sequence allowing white space. */\r\nconst punctuation = `[${VALID_PUNCTUATION}]` + punctuationLimit\r\n\r\n// A digits block without punctuation.\r\nconst digitSequence = pNd + limit(1, digitBlockLimit)\r\n\r\n/**\r\n * Phone number pattern allowing optional punctuation.\r\n * The phone number pattern used by `find()`, similar to\r\n * VALID_PHONE_NUMBER, but with the following differences:\r\n * <ul>\r\n * <li>All captures are limited in order to place an upper bound to the text matched by the\r\n * pattern.\r\n * <ul>\r\n * <li>Leading punctuation / plus signs are limited.\r\n * <li>Consecutive occurrences of punctuation are limited.\r\n * <li>Number of digits is limited.\r\n * </ul>\r\n * <li>No whitespace is allowed at the start or end.\r\n * <li>No alpha digits (vanity numbers such as 1-800-SIX-FLAGS) are currently supported.\r\n * </ul>\r\n */\r\nconst PATTERN = '(?:' + LEAD_CLASS + punctuation + ')' + leadLimit\r\n\t+ digitSequence + '(?:' + punctuation + digitSequence + ')' + blockLimit\r\n\t+ '(?:' + EXTN_PATTERNS_FOR_MATCHING + ')?'\r\n\r\n// Regular expression of trailing characters that we want to remove.\r\n// We remove all characters that are not alpha or numerical characters.\r\n// The hash character is retained here, as it may signify\r\n// the previous block was an extension.\r\n//\r\n// // Don't know what does '&&' mean here.\r\n// const UNWANTED_END_CHAR_PATTERN = new RegExp(`[[\\\\P{N}&&\\\\P{L}]&&[^#]]+$`)\r\n//\r\nconst UNWANTED_END_CHAR_PATTERN = new RegExp(`[^${_pN}${_pL}#]+$`)\r\n\r\nconst NON_DIGITS_PATTERN = /(\\D+)/\r\n\r\nconst MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1\r\n\r\n/**\r\n * A stateful class that finds and extracts telephone numbers from {@linkplain CharSequence text}.\r\n * Instances can be created using the {@linkplain PhoneNumberUtil#findNumbers factory methods} in\r\n * {@link PhoneNumberUtil}.\r\n *\r\n * <p>Vanity numbers (phone numbers using alphabetic digits such as <tt>1-800-SIX-FLAGS</tt> are\r\n * not found.\r\n *\r\n * <p>This class is not thread-safe.\r\n */\r\nexport default class PhoneNumberMatcher\r\n{\r\n /**\r\n * @param {string} text — the character sequence that we will search, null for no text.\r\n * @param {'POSSIBLE'|'VALID'|'STRICT_GROUPING'|'EXACT_GROUPING'} [options.leniency] — The leniency to use when evaluating candidate phone numbers. See `source/findNumbers/Leniency.js` for more details.\r\n * @param {number} [options.maxTries] — The maximum number of invalid numbers to try before giving up on the text. This is to cover degenerate cases where the text has a lot of false positives in it. Must be >= 0.\r\n */\r\n constructor(text = '', options = {}, metadata)\r\n {\r\n options = {\r\n v2: options.v2,\r\n defaultCallingCode: options.defaultCallingCode,\r\n defaultCountry: options.defaultCountry && isSupportedCountry(options.defaultCountry, metadata) ? options.defaultCountry : undefined,\r\n leniency: options.leniency || (options.extended ? 'POSSIBLE' : 'VALID'),\r\n maxTries: options.maxTries || MAX_SAFE_INTEGER\r\n }\r\n\r\n // Validate `leniency`.\r\n\t\tif (!options.leniency) {\r\n\t\t\tthrow new TypeError('`leniency` is required')\r\n\t\t}\r\n if (options.leniency !== 'POSSIBLE' && options.leniency !== 'VALID') {\r\n throw new TypeError(`Invalid \\`leniency\\`: \"${options.leniency}\". Supported values: \"POSSIBLE\", \"VALID\".`)\r\n }\r\n\r\n // Validate `maxTries`.\r\n\t\tif (options.maxTries < 0) {\r\n\t\t\tthrow new TypeError('`maxTries` must be `>= 0`')\r\n\t\t}\r\n\r\n\t\tthis.text = text\r\n\t\tthis.options = options\r\n this.metadata = metadata\r\n\r\n\t\t// The degree of phone number validation.\r\n\t\tthis.leniency = Leniency[options.leniency]\r\n\r\n\t\tif (!this.leniency) {\r\n\t\t\tthrow new TypeError(`Unknown leniency: \"${options.leniency}\"`)\r\n\t\t}\r\n\r\n\t\t/** The maximum number of retries after matching an invalid number. */\r\n\t\tthis.maxTries = options.maxTries\r\n\r\n\t\tthis.PATTERN = new RegExp(PATTERN, 'ig')\r\n\r\n /** The iteration tristate. */\r\n this.state = 'NOT_READY'\r\n\r\n /** The next index to start searching at. Undefined in {@link State#DONE}. */\r\n this.searchIndex = 0\r\n\r\n // A cache for frequently used country-specific regular expressions. Set to 32 to cover ~2-3\r\n // countries being used for the same doc with ~10 patterns for each country. Some pages will have\r\n // a lot more countries in use, but typically fewer numbers for each so expanding the cache for\r\n // that use-case won't have a lot of benefit.\r\n this.regExpCache = new RegExpCache(32)\r\n }\r\n\r\n /**\r\n * Attempts to find the next subsequence in the searched sequence on or after {@code searchIndex}\r\n * that represents a phone number. Returns the next match, null if none was found.\r\n *\r\n * @param index the search index to start searching at\r\n * @return the phone number match found, null if none can be found\r\n */\r\n\tfind() {\r\n\t\t// // Reset the regular expression.\r\n\t\t// this.PATTERN.lastIndex = index\r\n\r\n\t\tlet matches\r\n\t\twhile ((this.maxTries > 0) && (matches = this.PATTERN.exec(this.text)) !== null) {\r\n\t\t\tlet candidate = matches[0]\r\n\t\t\tconst offset = matches.index\r\n\r\n\t\t\tcandidate = parsePreCandidate(candidate)\r\n\r\n\t\t\tif (isValidPreCandidate(candidate, offset, this.text)) {\r\n\t\t\t\tconst match =\r\n\t\t\t\t\t// Try to come up with a valid match given the entire candidate.\r\n\t\t\t\t\tthis.parseAndVerify(candidate, offset, this.text)\r\n\t\t\t\t\t// If that failed, try to find an \"inner match\" -\r\n\t\t\t\t\t// there might be a phone number within this candidate.\r\n\t\t\t\t\t|| this.extractInnerMatch(candidate, offset, this.text)\r\n\r\n\t\t\t\tif (match) {\r\n\t\t\t\t\tif (this.options.v2) {\r\n\t\t\t\t\t\treturn {\r\n\t\t\t\t\t\t\tstartsAt: match.startsAt,\r\n\t\t\t\t\t\t\tendsAt: match.endsAt,\r\n\t\t\t\t\t\t\tnumber: match.phoneNumber\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t} else {\r\n const { phoneNumber } = match\r\n\r\n const result = {\r\n startsAt: match.startsAt,\r\n endsAt: match.endsAt,\r\n phone: phoneNumber.nationalNumber\r\n }\r\n\r\n if (phoneNumber.country) {\r\n /* istanbul ignore if */\r\n if (USE_NON_GEOGRAPHIC_COUNTRY_CODE && country === '001') {\r\n result.countryCallingCode = phoneNumber.countryCallingCode\r\n } else {\r\n result.country = phoneNumber.country\r\n }\r\n } else {\r\n result.countryCallingCode = phoneNumber.countryCallingCode\r\n }\r\n\r\n if (phoneNumber.ext) {\r\n result.ext = phoneNumber.ext\r\n }\r\n\r\n return result\r\n }\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tthis.maxTries--\r\n\t\t}\r\n\t}\r\n\r\n /**\r\n * Attempts to extract a match from `substring`\r\n * if the substring itself does not qualify as a match.\r\n */\r\n extractInnerMatch(substring, offset, text) {\r\n for (const innerMatchPattern of INNER_MATCHES) {\r\n let isFirstMatch = true\r\n let candidateMatch\r\n const innerMatchRegExp = new RegExp(innerMatchPattern, 'g')\r\n while (this.maxTries > 0 && (candidateMatch = innerMatchRegExp.exec(substring)) !== null) {\r\n if (isFirstMatch) {\r\n // We should handle any group before this one too.\r\n const candidate = trimAfterFirstMatch(\r\n UNWANTED_END_CHAR_PATTERN,\r\n substring.slice(0, candidateMatch.index)\r\n )\r\n\r\n const match = this.parseAndVerify(candidate, offset, text)\r\n\r\n if (match) {\r\n return match\r\n }\r\n\r\n this.maxTries--\r\n isFirstMatch = false\r\n }\r\n\r\n const candidate = trimAfterFirstMatch(UNWANTED_END_CHAR_PATTERN, candidateMatch[1])\r\n\r\n // Java code does `groupMatcher.start(1)` here,\r\n // but there's no way in javascript to get a `candidate` start index,\r\n // therefore resort to using this kind of an approximation.\r\n // (`groupMatcher` is called `candidateInSubstringMatch` in this javascript port)\r\n // https://stackoverflow.com/questions/15934353/get-index-of-each-capture-in-a-javascript-regex\r\n const candidateIndexGuess = substring.indexOf(candidate, candidateMatch.index)\r\n\r\n const match = this.parseAndVerify(candidate, offset + candidateIndexGuess, text)\r\n if (match) {\r\n return match\r\n }\r\n\r\n this.maxTries--\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Parses a phone number from the `candidate` using `parse` and\r\n * verifies it matches the requested `leniency`. If parsing and verification succeed,\r\n * a corresponding `PhoneNumberMatch` is returned, otherwise this method returns `null`.\r\n *\r\n * @param candidate the candidate match\r\n * @param offset the offset of {@code candidate} within {@link #text}\r\n * @return the parsed and validated phone number match, or null\r\n */\r\n parseAndVerify(candidate, offset, text) {\r\n if (!isValidCandidate(candidate, offset, text, this.options.leniency)) {\r\n return\r\n \t}\r\n\r\n const phoneNumber = parsePhoneNumber(\r\n candidate,\r\n {\r\n extended: true,\r\n defaultCountry: this.options.defaultCountry,\r\n defaultCallingCode: this.options.defaultCallingCode\r\n },\r\n this.metadata\r\n )\r\n\r\n if (!phoneNumber) {\r\n return\r\n }\r\n\r\n if (!phoneNumber.isPossible()) {\r\n return\r\n }\r\n\r\n if (this.leniency(phoneNumber, candidate, this.metadata, this.regExpCache)) {\r\n return {\r\n startsAt: offset,\r\n endsAt: offset + candidate.length,\r\n phoneNumber\r\n }\r\n }\r\n }\r\n\r\n hasNext()\r\n {\r\n if (this.state === 'NOT_READY')\r\n {\r\n this.lastMatch = this.find() // (this.searchIndex)\r\n\r\n if (this.lastMatch)\r\n {\r\n // this.searchIndex = this.lastMatch.endsAt\r\n this.state = 'READY'\r\n }\r\n else\r\n {\r\n this.state = 'DONE'\r\n }\r\n }\r\n\r\n return this.state === 'READY'\r\n }\r\n\r\n next()\r\n {\r\n // Check the state and find the next match as a side-effect if necessary.\r\n if (!this.hasNext())\r\n {\r\n throw new Error('No next element')\r\n }\r\n\r\n // Don't retain that memory any longer than necessary.\r\n const result = this.lastMatch\r\n this.lastMatch = null\r\n this.state = 'NOT_READY'\r\n return result\r\n }\r\n}"],"mappings":";;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AAEA,OAAOA,WAAP,MAAwB,kBAAxB;AAEA,SACEC,kBADF,EAEEC,uBAFF,EAGEC,iBAHF,QAIO,gBAJP;AAMA,OAAOC,sBAAP,MAA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,IAAjB;MACA,KAAK/B,KAAL,GAAa,WAAb;MACA,OAAOe,MAAP;IACD;;;;;;SArPkB3B,kB"}
1
+ {"version":3,"file":"PhoneNumberMatcher.js","names":["PhoneNumber","MAX_LENGTH_FOR_NSN","MAX_LENGTH_COUNTRY_CODE","VALID_PUNCTUATION","createExtensionPattern","RegExpCache","limit","trimAfterFirstMatch","_pL","_pN","pZ","PZ","pNd","Leniency","parsePreCandidate","isValidPreCandidate","isValidCandidate","LEAD_CLASS","isSupportedCountry","parsePhoneNumber","USE_NON_GEOGRAPHIC_COUNTRY_CODE","EXTN_PATTERNS_FOR_MATCHING","INNER_MATCHES","leadLimit","punctuationLimit","digitBlockLimit","blockLimit","punctuation","digitSequence","PATTERN","UNWANTED_END_CHAR_PATTERN","RegExp","NON_DIGITS_PATTERN","MAX_SAFE_INTEGER","Number","Math","pow","PhoneNumberMatcher","text","options","metadata","v2","defaultCallingCode","defaultCountry","undefined","leniency","extended","maxTries","TypeError","state","searchIndex","regExpCache","matches","exec","candidate","offset","index","match","parseAndVerify","extractInnerMatch","startsAt","endsAt","number","phoneNumber","result","phone","nationalNumber","country","countryCallingCode","ext","substring","innerMatchPattern","isFirstMatch","candidateMatch","innerMatchRegExp","slice","candidateIndexGuess","indexOf","isPossible","length","lastMatch","find","hasNext","Error"],"sources":["../source/PhoneNumberMatcher.js"],"sourcesContent":["/**\r\n * A port of Google's `PhoneNumberMatcher.java`.\r\n * https://github.com/googlei18n/libphonenumber/blob/master/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberMatcher.java\r\n * Date: 08.03.2018.\r\n */\r\n\r\nimport PhoneNumber from './PhoneNumber.js'\r\n\r\nimport {\r\n MAX_LENGTH_FOR_NSN,\r\n MAX_LENGTH_COUNTRY_CODE,\r\n VALID_PUNCTUATION\r\n} from './constants.js'\r\n\r\nimport createExtensionPattern from './helpers/extension/createExtensionPattern.js'\r\n\r\nimport RegExpCache from './findNumbers/RegExpCache.js'\r\n\r\nimport {\r\n\tlimit,\r\n\ttrimAfterFirstMatch\r\n} from './findNumbers/util.js'\r\n\r\nimport {\r\n\t_pL,\r\n\t_pN,\r\n\tpZ,\r\n\tPZ,\r\n\tpNd\r\n} from './findNumbers/utf-8.js'\r\n\r\nimport Leniency from './findNumbers/Leniency.js'\r\nimport parsePreCandidate from './findNumbers/parsePreCandidate.js'\r\nimport isValidPreCandidate from './findNumbers/isValidPreCandidate.js'\r\nimport isValidCandidate, { LEAD_CLASS } from './findNumbers/isValidCandidate.js'\r\n\r\nimport { isSupportedCountry } from './metadata.js'\r\n\r\nimport parsePhoneNumber from './parsePhoneNumber.js'\r\n\r\nconst USE_NON_GEOGRAPHIC_COUNTRY_CODE = false\r\n\r\nconst EXTN_PATTERNS_FOR_MATCHING = createExtensionPattern('matching')\r\n\r\n/**\r\n * Patterns used to extract phone numbers from a larger phone-number-like pattern. These are\r\n * ordered according to specificity. For example, white-space is last since that is frequently\r\n * used in numbers, not just to separate two numbers. We have separate patterns since we don't\r\n * want to break up the phone-number-like text on more than one different kind of symbol at one\r\n * time, although symbols of the same type (e.g. space) can be safely grouped together.\r\n *\r\n * Note that if there is a match, we will always check any text found up to the first match as\r\n * well.\r\n */\r\nconst INNER_MATCHES =\r\n[\r\n\t// Breaks on the slash - e.g. \"651-234-2345/332-445-1234\"\r\n\t'\\\\/+(.*)/',\r\n\r\n\t// Note that the bracket here is inside the capturing group, since we consider it part of the\r\n\t// phone number. Will match a pattern like \"(650) 223 3345 (754) 223 3321\".\r\n\t'(\\\\([^(]*)',\r\n\r\n\t// Breaks on a hyphen - e.g. \"12345 - 332-445-1234 is my number.\"\r\n\t// We require a space on either side of the hyphen for it to be considered a separator.\r\n\t`(?:${pZ}-|-${pZ})${pZ}*(.+)`,\r\n\r\n\t// Various types of wide hyphens. Note we have decided not to enforce a space here, since it's\r\n\t// possible that it's supposed to be used to break two numbers without spaces, and we haven't\r\n\t// seen many instances of it used within a number.\r\n\t`[\\u2012-\\u2015\\uFF0D]${pZ}*(.+)`,\r\n\r\n\t// Breaks on a full stop - e.g. \"12345. 332-445-1234 is my number.\"\r\n\t`\\\\.+${pZ}*([^.]+)`,\r\n\r\n\t// Breaks on space - e.g. \"3324451234 8002341234\"\r\n\t`${pZ}+(${PZ}+)`\r\n]\r\n\r\n// Limit on the number of leading (plus) characters.\r\nconst leadLimit = limit(0, 2)\r\n\r\n// Limit on the number of consecutive punctuation characters.\r\nconst punctuationLimit = limit(0, 4)\r\n\r\n/* The maximum number of digits allowed in a digit-separated block. As we allow all digits in a\r\n * single block, set high enough to accommodate the entire national number and the international\r\n * country code. */\r\nconst digitBlockLimit = MAX_LENGTH_FOR_NSN + MAX_LENGTH_COUNTRY_CODE\r\n\r\n// Limit on the number of blocks separated by punctuation.\r\n// Uses digitBlockLimit since some formats use spaces to separate each digit.\r\nconst blockLimit = limit(0, digitBlockLimit)\r\n\r\n/* A punctuation sequence allowing white space. */\r\nconst punctuation = `[${VALID_PUNCTUATION}]` + punctuationLimit\r\n\r\n// A digits block without punctuation.\r\nconst digitSequence = pNd + limit(1, digitBlockLimit)\r\n\r\n/**\r\n * Phone number pattern allowing optional punctuation.\r\n * The phone number pattern used by `find()`, similar to\r\n * VALID_PHONE_NUMBER, but with the following differences:\r\n * <ul>\r\n * <li>All captures are limited in order to place an upper bound to the text matched by the\r\n * pattern.\r\n * <ul>\r\n * <li>Leading punctuation / plus signs are limited.\r\n * <li>Consecutive occurrences of punctuation are limited.\r\n * <li>Number of digits is limited.\r\n * </ul>\r\n * <li>No whitespace is allowed at the start or end.\r\n * <li>No alpha digits (vanity numbers such as 1-800-SIX-FLAGS) are currently supported.\r\n * </ul>\r\n */\r\nconst PATTERN = '(?:' + LEAD_CLASS + punctuation + ')' + leadLimit\r\n\t+ digitSequence + '(?:' + punctuation + digitSequence + ')' + blockLimit\r\n\t+ '(?:' + EXTN_PATTERNS_FOR_MATCHING + ')?'\r\n\r\n// Regular expression of trailing characters that we want to remove.\r\n// We remove all characters that are not alpha or numerical characters.\r\n// The hash character is retained here, as it may signify\r\n// the previous block was an extension.\r\n//\r\n// // Don't know what does '&&' mean here.\r\n// const UNWANTED_END_CHAR_PATTERN = new RegExp(`[[\\\\P{N}&&\\\\P{L}]&&[^#]]+$`)\r\n//\r\nconst UNWANTED_END_CHAR_PATTERN = new RegExp(`[^${_pN}${_pL}#]+$`)\r\n\r\nconst NON_DIGITS_PATTERN = /(\\D+)/\r\n\r\nconst MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1\r\n\r\n/**\r\n * A stateful class that finds and extracts telephone numbers from {@linkplain CharSequence text}.\r\n * Instances can be created using the {@linkplain PhoneNumberUtil#findNumbers factory methods} in\r\n * {@link PhoneNumberUtil}.\r\n *\r\n * <p>Vanity numbers (phone numbers using alphabetic digits such as <tt>1-800-SIX-FLAGS</tt> are\r\n * not found.\r\n *\r\n * <p>This class is not thread-safe.\r\n */\r\nexport default class PhoneNumberMatcher\r\n{\r\n /**\r\n * @param {string} text — the character sequence that we will search, null for no text.\r\n * @param {'POSSIBLE'|'VALID'|'STRICT_GROUPING'|'EXACT_GROUPING'} [options.leniency] — The leniency to use when evaluating candidate phone numbers. See `source/findNumbers/Leniency.js` for more details.\r\n * @param {number} [options.maxTries] — The maximum number of invalid numbers to try before giving up on the text. This is to cover degenerate cases where the text has a lot of false positives in it. Must be >= 0.\r\n */\r\n constructor(text = '', options = {}, metadata)\r\n {\r\n options = {\r\n v2: options.v2,\r\n defaultCallingCode: options.defaultCallingCode,\r\n defaultCountry: options.defaultCountry && isSupportedCountry(options.defaultCountry, metadata) ? options.defaultCountry : undefined,\r\n leniency: options.leniency || (options.extended ? 'POSSIBLE' : 'VALID'),\r\n maxTries: options.maxTries || MAX_SAFE_INTEGER\r\n }\r\n\r\n // Validate `leniency`.\r\n\t\tif (!options.leniency) {\r\n\t\t\tthrow new TypeError('`leniency` is required')\r\n\t\t}\r\n if (options.leniency !== 'POSSIBLE' && options.leniency !== 'VALID') {\r\n throw new TypeError(`Invalid \\`leniency\\`: \"${options.leniency}\". Supported values: \"POSSIBLE\", \"VALID\".`)\r\n }\r\n\r\n // Validate `maxTries`.\r\n\t\tif (options.maxTries < 0) {\r\n\t\t\tthrow new TypeError('`maxTries` must be `>= 0`')\r\n\t\t}\r\n\r\n\t\tthis.text = text\r\n\t\tthis.options = options\r\n this.metadata = metadata\r\n\r\n\t\t// The degree of phone number validation.\r\n\t\tthis.leniency = Leniency[options.leniency]\r\n\r\n\t\tif (!this.leniency) {\r\n\t\t\tthrow new TypeError(`Unknown leniency: \"${options.leniency}\"`)\r\n\t\t}\r\n\r\n\t\t/** The maximum number of retries after matching an invalid number. */\r\n\t\tthis.maxTries = options.maxTries\r\n\r\n\t\tthis.PATTERN = new RegExp(PATTERN, 'ig')\r\n\r\n /** The iteration tristate. */\r\n this.state = 'NOT_READY'\r\n\r\n /** The next index to start searching at. Undefined in {@link State#DONE}. */\r\n this.searchIndex = 0\r\n\r\n // A cache for frequently used country-specific regular expressions. Set to 32 to cover ~2-3\r\n // countries being used for the same doc with ~10 patterns for each country. Some pages will have\r\n // a lot more countries in use, but typically fewer numbers for each so expanding the cache for\r\n // that use-case won't have a lot of benefit.\r\n this.regExpCache = new RegExpCache(32)\r\n }\r\n\r\n /**\r\n * Attempts to find the next subsequence in the searched sequence on or after {@code searchIndex}\r\n * that represents a phone number. Returns the next match, null if none was found.\r\n *\r\n * @param index the search index to start searching at\r\n * @return the phone number match found, null if none can be found\r\n */\r\n\tfind() {\r\n\t\t// // Reset the regular expression.\r\n\t\t// this.PATTERN.lastIndex = index\r\n\r\n\t\tlet matches\r\n\t\twhile ((this.maxTries > 0) && (matches = this.PATTERN.exec(this.text)) !== null) {\r\n\t\t\tlet candidate = matches[0]\r\n\t\t\tconst offset = matches.index\r\n\r\n\t\t\tcandidate = parsePreCandidate(candidate)\r\n\r\n\t\t\tif (isValidPreCandidate(candidate, offset, this.text)) {\r\n\t\t\t\tconst match =\r\n\t\t\t\t\t// Try to come up with a valid match given the entire candidate.\r\n\t\t\t\t\tthis.parseAndVerify(candidate, offset, this.text)\r\n\t\t\t\t\t// If that failed, try to find an \"inner match\" -\r\n\t\t\t\t\t// there might be a phone number within this candidate.\r\n\t\t\t\t\t|| this.extractInnerMatch(candidate, offset, this.text)\r\n\r\n\t\t\t\tif (match) {\r\n\t\t\t\t\tif (this.options.v2) {\r\n\t\t\t\t\t\treturn {\r\n\t\t\t\t\t\t\tstartsAt: match.startsAt,\r\n\t\t\t\t\t\t\tendsAt: match.endsAt,\r\n\t\t\t\t\t\t\tnumber: match.phoneNumber\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t} else {\r\n const { phoneNumber } = match\r\n\r\n const result = {\r\n startsAt: match.startsAt,\r\n endsAt: match.endsAt,\r\n phone: phoneNumber.nationalNumber\r\n }\r\n\r\n if (phoneNumber.country) {\r\n /* istanbul ignore if */\r\n if (USE_NON_GEOGRAPHIC_COUNTRY_CODE && country === '001') {\r\n result.countryCallingCode = phoneNumber.countryCallingCode\r\n } else {\r\n result.country = phoneNumber.country\r\n }\r\n } else {\r\n result.countryCallingCode = phoneNumber.countryCallingCode\r\n }\r\n\r\n if (phoneNumber.ext) {\r\n result.ext = phoneNumber.ext\r\n }\r\n\r\n return result\r\n }\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tthis.maxTries--\r\n\t\t}\r\n\t}\r\n\r\n /**\r\n * Attempts to extract a match from `substring`\r\n * if the substring itself does not qualify as a match.\r\n */\r\n extractInnerMatch(substring, offset, text) {\r\n for (const innerMatchPattern of INNER_MATCHES) {\r\n let isFirstMatch = true\r\n let candidateMatch\r\n const innerMatchRegExp = new RegExp(innerMatchPattern, 'g')\r\n while (this.maxTries > 0 && (candidateMatch = innerMatchRegExp.exec(substring)) !== null) {\r\n if (isFirstMatch) {\r\n // We should handle any group before this one too.\r\n const candidate = trimAfterFirstMatch(\r\n UNWANTED_END_CHAR_PATTERN,\r\n substring.slice(0, candidateMatch.index)\r\n )\r\n\r\n const match = this.parseAndVerify(candidate, offset, text)\r\n\r\n if (match) {\r\n return match\r\n }\r\n\r\n this.maxTries--\r\n isFirstMatch = false\r\n }\r\n\r\n const candidate = trimAfterFirstMatch(UNWANTED_END_CHAR_PATTERN, candidateMatch[1])\r\n\r\n // Java code does `groupMatcher.start(1)` here,\r\n // but there's no way in javascript to get a `candidate` start index,\r\n // therefore resort to using this kind of an approximation.\r\n // (`groupMatcher` is called `candidateInSubstringMatch` in this javascript port)\r\n // https://stackoverflow.com/questions/15934353/get-index-of-each-capture-in-a-javascript-regex\r\n const candidateIndexGuess = substring.indexOf(candidate, candidateMatch.index)\r\n\r\n const match = this.parseAndVerify(candidate, offset + candidateIndexGuess, text)\r\n if (match) {\r\n return match\r\n }\r\n\r\n this.maxTries--\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Parses a phone number from the `candidate` using `parse` and\r\n * verifies it matches the requested `leniency`. If parsing and verification succeed,\r\n * a corresponding `PhoneNumberMatch` is returned, otherwise this method returns `null`.\r\n *\r\n * @param candidate the candidate match\r\n * @param offset the offset of {@code candidate} within {@link #text}\r\n * @return the parsed and validated phone number match, or null\r\n */\r\n parseAndVerify(candidate, offset, text) {\r\n if (!isValidCandidate(candidate, offset, text, this.options.leniency)) {\r\n return\r\n \t}\r\n\r\n const phoneNumber = parsePhoneNumber(\r\n candidate,\r\n {\r\n extended: true,\r\n defaultCountry: this.options.defaultCountry,\r\n defaultCallingCode: this.options.defaultCallingCode\r\n },\r\n this.metadata\r\n )\r\n\r\n if (!phoneNumber) {\r\n return\r\n }\r\n\r\n if (!phoneNumber.isPossible()) {\r\n return\r\n }\r\n\r\n if (this.leniency(phoneNumber, {\r\n candidate,\r\n defaultCountry: this.options.defaultCountry,\r\n metadata: this.metadata,\r\n regExpCache: this.regExpCache\r\n })) {\r\n return {\r\n startsAt: offset,\r\n endsAt: offset + candidate.length,\r\n phoneNumber\r\n }\r\n }\r\n }\r\n\r\n hasNext()\r\n {\r\n if (this.state === 'NOT_READY')\r\n {\r\n this.lastMatch = this.find() // (this.searchIndex)\r\n\r\n if (this.lastMatch)\r\n {\r\n // this.searchIndex = this.lastMatch.endsAt\r\n this.state = 'READY'\r\n }\r\n else\r\n {\r\n this.state = 'DONE'\r\n }\r\n }\r\n\r\n return this.state === 'READY'\r\n }\r\n\r\n next()\r\n {\r\n // Check the state and find the next match as a side-effect if necessary.\r\n if (!this.hasNext())\r\n {\r\n throw new Error('No next element')\r\n }\r\n\r\n // Don't retain that memory any longer than necessary.\r\n const result = this.lastMatch\r\n this.lastMatch = null\r\n this.state = 'NOT_READY'\r\n return result\r\n }\r\n}"],"mappings":";;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AAEA,OAAOA,WAAP,MAAwB,kBAAxB;AAEA,SACEC,kBADF,EAEEC,uBAFF,EAGEC,iBAHF,QAIO,gBAJP;AAMA,OAAOC,sBAAP,MAAmC,+CAAnC;AAEA,OAAOC,WAAP,MAAwB,8BAAxB;AAEA,SACCC,KADD,EAECC,mBAFD,QAGO,uBAHP;AAKA,SACCC,GADD,EAECC,GAFD,EAGCC,EAHD,EAICC,EAJD,EAKCC,GALD,QAMO,wBANP;AAQA,OAAOC,QAAP,MAAqB,2BAArB;AACA,OAAOC,iBAAP,MAA8B,oCAA9B;AACA,OAAOC,mBAAP,MAAgC,sCAAhC;AACA,OAAOC,gBAAP,IAA2BC,UAA3B,QAA6C,mCAA7C;AAEA,SAASC,kBAAT,QAAmC,eAAnC;AAEA,OAAOC,gBAAP,MAA6B,uBAA7B;AAEA,IAAMC,+BAA+B,GAAG,KAAxC;AAEA,IAAMC,0BAA0B,GAAGjB,sBAAsB,CAAC,UAAD,CAAzD;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,IAAMkB,aAAa,GACnB,CACC;AACA,WAFD,EAIC;AACA;AACA,YAND,EAQC;AACA;AATD,aAUOZ,EAVP,gBAUeA,EAVf,cAUqBA,EAVrB,YAYC;AACA;AACA;AAdD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W,WAAW,EAAE,KAAKA;MAJW,CAA3B,CAAJ,EAKI;QACF,OAAO;UACLS,QAAQ,EAAEL,MADL;UAELM,MAAM,EAAEN,MAAM,GAAGD,SAAS,CAACyB,MAFtB;UAGLhB,WAAW,EAAXA;QAHK,CAAP;MAKD;IACF;;;WAED,mBACA;MACE,IAAI,KAAKd,KAAL,KAAe,WAAnB,EACA;QACE,KAAK+B,SAAL,GAAiB,KAAKC,IAAL,EAAjB,CADF,CAC+B;;QAE7B,IAAI,KAAKD,SAAT,EACA;UACE;UACA,KAAK/B,KAAL,GAAa,OAAb;QACD,CAJD,MAMA;UACE,KAAKA,KAAL,GAAa,MAAb;QACD;MACF;;MAED,OAAO,KAAKA,KAAL,KAAe,OAAtB;IACD;;;WAED,gBACA;MACE;MACA,IAAI,CAAC,KAAKiC,OAAL,EAAL,EACA;QACE,MAAM,IAAIC,KAAJ,CAAU,iBAAV,CAAN;MACD,CALH,CAOE;;;MACA,IAAMnB,MAAM,GAAG,KAAKgB,SAApB;MACA,KAAKA,SAAL,GAAiB,IAAjB;MACA,KAAK/B,KAAL,GAAa,WAAb;MACA,OAAOe,MAAP;IACD;;;;;;SA1PkB3B,kB"}
@@ -20,7 +20,9 @@ export default {
20
20
  /**
21
21
  * Phone numbers accepted are "possible", but not necessarily "valid".
22
22
  */
23
- POSSIBLE: function POSSIBLE(phoneNumber, candidate, metadata) {
23
+ POSSIBLE: function POSSIBLE(phoneNumber, _ref) {
24
+ var candidate = _ref.candidate,
25
+ metadata = _ref.metadata;
24
26
  return true;
25
27
  },
26
28
 
@@ -29,11 +31,15 @@ export default {
29
31
  * Numbers written in national format must have their national-prefix
30
32
  * present if it is usually written for a number of this type.
31
33
  */
32
- VALID: function VALID(phoneNumber, candidate, metadata) {
34
+ VALID: function VALID(phoneNumber, _ref2) {
35
+ var candidate = _ref2.candidate,
36
+ defaultCountry = _ref2.defaultCountry,
37
+ metadata = _ref2.metadata;
38
+
33
39
  if (!phoneNumber.isValid() || !containsOnlyValidXChars(phoneNumber, candidate, metadata)) {
34
40
  return false;
35
41
  } // Skipped for simplicity.
36
- // return isNationalPrefixPresentIfRequired(phoneNumber, metadata)
42
+ // return isNationalPrefixPresentIfRequired(phoneNumber, { defaultCountry, metadata })
37
43
 
38
44
 
39
45
  return true;
@@ -51,8 +57,16 @@ export default {
51
57
  * country code "+1". If you are not sure about which level to use,
52
58
  * email the discussion group libphonenumber-discuss@googlegroups.com.
53
59
  */
54
- STRICT_GROUPING: function STRICT_GROUPING(phoneNumber, candidate, metadata, regExpCache) {
55
- if (!phoneNumber.isValid() || !containsOnlyValidXChars(phoneNumber, candidate, metadata) || containsMoreThanOneSlashInNationalNumber(phoneNumber, candidate) || !isNationalPrefixPresentIfRequired(phoneNumber, metadata)) {
60
+ STRICT_GROUPING: function STRICT_GROUPING(phoneNumber, _ref3) {
61
+ var candidate = _ref3.candidate,
62
+ defaultCountry = _ref3.defaultCountry,
63
+ metadata = _ref3.metadata,
64
+ regExpCache = _ref3.regExpCache;
65
+
66
+ if (!phoneNumber.isValid() || !containsOnlyValidXChars(phoneNumber, candidate, metadata) || containsMoreThanOneSlashInNationalNumber(phoneNumber, candidate) || !isNationalPrefixPresentIfRequired(phoneNumber, {
67
+ defaultCountry: defaultCountry,
68
+ metadata: metadata
69
+ })) {
56
70
  return false;
57
71
  }
58
72
 
@@ -70,8 +84,16 @@ export default {
70
84
  * country code "+1". If you are not sure about which level to use, email the discussion group
71
85
  * libphonenumber-discuss@googlegroups.com.
72
86
  */
73
- EXACT_GROUPING: function EXACT_GROUPING(phoneNumber, candidate, metadata, regExpCache) {
74
- if (!phoneNumber.isValid() || !containsOnlyValidXChars(phoneNumber, candidate, metadata) || containsMoreThanOneSlashInNationalNumber(phoneNumber, candidate) || !isNationalPrefixPresentIfRequired(phoneNumber, metadata)) {
87
+ EXACT_GROUPING: function EXACT_GROUPING(phoneNumber, _ref4) {
88
+ var candidate = _ref4.candidate,
89
+ defaultCountry = _ref4.defaultCountry,
90
+ metadata = _ref4.metadata,
91
+ regExpCache = _ref4.regExpCache;
92
+
93
+ if (!phoneNumber.isValid() || !containsOnlyValidXChars(phoneNumber, candidate, metadata) || containsMoreThanOneSlashInNationalNumber(phoneNumber, candidate) || !isNationalPrefixPresentIfRequired(phoneNumber, {
94
+ defaultCountry: defaultCountry,
95
+ metadata: metadata
96
+ })) {
75
97
  return false;
76
98
  }
77
99
 
@@ -120,7 +142,10 @@ function containsOnlyValidXChars(phoneNumber, candidate, metadata) {
120
142
  return true;
121
143
  }
122
144
 
123
- function isNationalPrefixPresentIfRequired(phoneNumber, _metadata) {
145
+ function isNationalPrefixPresentIfRequired(phoneNumber, _ref5) {
146
+ var defaultCountry = _ref5.defaultCountry,
147
+ _metadata = _ref5.metadata;
148
+
124
149
  // First, check how we deduced the country code. If it was written in international format, then
125
150
  // the national prefix is not required.
126
151
  if (phoneNumber.__countryCallingCodeSource !== 'FROM_DEFAULT_COUNTRY') {
@@ -129,7 +154,11 @@ function isNationalPrefixPresentIfRequired(phoneNumber, _metadata) {
129
154
 
130
155
  var metadata = new Metadata(_metadata);
131
156
  metadata.selectNumberingPlan(phoneNumber.countryCallingCode);
132
- var phoneNumberRegion = phoneNumber.country || getCountryByCallingCode(phoneNumber.countryCallingCode, phoneNumber.nationalNumber, metadata); // Check if a national prefix should be present when formatting this number.
157
+ var phoneNumberRegion = phoneNumber.country || getCountryByCallingCode(phoneNumber.countryCallingCode, {
158
+ nationalNumber: phoneNumber.nationalNumber,
159
+ defaultCountry: defaultCountry,
160
+ metadata: metadata
161
+ }); // Check if a national prefix should be present when formatting this number.
133
162
 
134
163
  var nationalNumber = phoneNumber.nationalNumber;
135
164
  var format = chooseFormatForNumber(metadata.numberingPlan.formats(), nationalNumber); // To do this, we check that a national prefix formatting rule was present
@@ -1 +1 @@
1
- {"version":3,"file":"Leniency.js","names":["isValidNumber","parseDigits","matchPhoneNumberStringAgainstPhoneNumber","Metadata","getCountryByCallingCode","chooseFormatForNumber","startsWith","endsWith","POSSIBLE","phoneNumber","candidate","metadata","VALID","isValid","containsOnlyValidXChars","STRICT_GROUPING","regExpCache","containsMoreThanOneSlashInNationalNumber","isNationalPrefixPresentIfRequired","checkNumberGroupingIsValid","allNumberGroupsRemainGrouped","EXACT_GROUPING","allNumberGroupsAreExactlyPresent","index","length","charAtIndex","charAt","charAtNextIndex","substring","ext","_metadata","__countryCallingCodeSource","selectNumberingPlan","countryCallingCode","phoneNumberRegion","country","nationalNumber","format","numberingPlan","formats","nationalPrefixFormattingRule","nationalPrefixIsOptionalWhenFormattingInNationalFormat","usesNationalPrefix","Boolean","nationalPrefix","firstSlashInBodyIndex","indexOf","secondSlashInBodyIndex","candidateHasCountryCode","slice","number","checkGroups","Error","normalizedCandidate","normalizeDigits","formattedNumberGroups","getNationalNumberGroups","alternateFormats","MetadataManager","getAlternateFormatsForCountry","getCountryCode","nationalSignificantNumber","util","getNationalSignificantNumber","numberFormats","alternateFormat","leadingDigitsPatterns","leadingDigitsRegExp","getPatternForRegExp","test","formattingPattern","formatNsnUsingPattern","split","rfc3966Format","formatNumber","endIndex","startIndex","candidateGroups","NON_DIGITS_PATTERN","candidateNumberGroupIndex","hasExtension","contains","formattedNumberGroupIndex","fromIndex","getCountryCodeSource","CountryCodeSource","FROM_DEFAULT_COUNTRY","countryCode","String","i","region","getRegionCodeForCountryCode","getNddPrefixForRegion","Character","isDigit","getExtension"],"sources":["../../source/findNumbers/Leniency.js"],"sourcesContent":["import isValidNumber from '../isValid.js'\r\nimport parseDigits from '../helpers/parseDigits.js'\r\nimport matchPhoneNumberStringAgainstPhoneNumber from './matchPhoneNumberStringAgainstPhoneNumber.js'\r\nimport Metadata from '../metadata.js'\r\nimport getCountryByCallingCode from '../helpers/getCountryByCallingCode.js'\r\nimport { chooseFormatForNumber } from '../format.js'\r\n\r\nimport {\r\n\tstartsWith,\r\n\tendsWith\r\n} from './util.js'\r\n\r\n/**\r\n * Leniency when finding potential phone numbers in text segments\r\n * The levels here are ordered in increasing strictness.\r\n */\r\nexport default\r\n{\r\n\t/**\r\n\t * Phone numbers accepted are \"possible\", but not necessarily \"valid\".\r\n\t */\r\n\tPOSSIBLE(phoneNumber, candidate, metadata)\r\n\t{\r\n\t\treturn true\r\n\t},\r\n\r\n\t/**\r\n\t * Phone numbers accepted are \"possible\" and \"valid\".\r\n\t * Numbers written in national format must have their national-prefix\r\n\t * present if it is usually written for a number of this type.\r\n\t */\r\n\tVALID(phoneNumber, candidate, metadata)\r\n\t{\r\n\t\tif (\r\n\t\t\t!phoneNumber.isValid() ||\r\n\t\t\t!containsOnlyValidXChars(phoneNumber, candidate, metadata)\r\n\t\t)\r\n\t\t{\r\n\t\t\treturn false\r\n\t\t}\r\n\r\n\t\t// Skipped for simplicity.\r\n\t\t// return isNationalPrefixPresentIfRequired(phoneNumber, metadata)\r\n\t\treturn true\r\n\t},\r\n\r\n\t/**\r\n\t * Phone numbers accepted are \"valid\" and\r\n\t * are grouped in a possible way for this locale. For example, a US number written as\r\n\t * \"65 02 53 00 00\" and \"650253 0000\" are not accepted at this leniency level, whereas\r\n\t * \"650 253 0000\", \"650 2530000\" or \"6502530000\" are.\r\n\t * Numbers with more than one '/' symbol in the national significant number\r\n\t * are also dropped at this level.\r\n\t *\r\n\t * Warning: This level might result in lower coverage especially for regions outside of\r\n\t * country code \"+1\". If you are not sure about which level to use,\r\n\t * email the discussion group libphonenumber-discuss@googlegroups.com.\r\n\t */\r\n\tSTRICT_GROUPING(phoneNumber, candidate, metadata, regExpCache)\r\n\t{\r\n\t\tif (\r\n\t\t\t!phoneNumber.isValid() ||\r\n\t\t\t!containsOnlyValidXChars(phoneNumber, candidate, metadata) ||\r\n\t\t\tcontainsMoreThanOneSlashInNationalNumber(phoneNumber, candidate) ||\r\n\t\t\t!isNationalPrefixPresentIfRequired(phoneNumber, metadata)\r\n\t\t)\r\n\t\t{\r\n\t\t\treturn false\r\n\t\t}\r\n\r\n\t\treturn checkNumberGroupingIsValid\r\n\t\t(\r\n\t\t\tphoneNumber,\r\n\t\t\tcandidate,\r\n\t\t\tmetadata,\r\n\t\t\tallNumberGroupsRemainGrouped,\r\n\t\t\tregExpCache\r\n\t\t)\r\n\t},\r\n\r\n\t/**\r\n\t * Phone numbers accepted are \"valid\" and are grouped in the same way\r\n\t * that we would have formatted it, or as a single block.\r\n\t * For example, a US number written as \"650 2530000\" is not accepted\r\n\t * at this leniency level, whereas \"650 253 0000\" or \"6502530000\" are.\r\n\t * Numbers with more than one '/' symbol are also dropped at this level.\r\n\t *\r\n\t * Warning: This level might result in lower coverage especially for regions outside of\r\n\t * country code \"+1\". If you are not sure about which level to use, email the discussion group\r\n\t * libphonenumber-discuss@googlegroups.com.\r\n\t */\r\n\tEXACT_GROUPING(phoneNumber, candidate, metadata, regExpCache)\r\n\t{\r\n\t\tif (\r\n\t\t\t!phoneNumber.isValid() ||\r\n\t\t\t!containsOnlyValidXChars(phoneNumber, candidate, metadata) ||\r\n\t\t\tcontainsMoreThanOneSlashInNationalNumber(phoneNumber, candidate) ||\r\n\t\t\t!isNationalPrefixPresentIfRequired(phoneNumber, metadata)\r\n\t\t)\r\n\t\t{\r\n\t\t\treturn false\r\n\t\t}\r\n\r\n\t\treturn checkNumberGroupingIsValid\r\n\t\t(\r\n\t\t\tphoneNumber,\r\n\t\t\tcandidate,\r\n\t\t\tmetadata,\r\n\t\t\tallNumberGroupsAreExactlyPresent,\r\n\t\t\tregExpCache\r\n\t\t)\r\n\t}\r\n}\r\n\r\nfunction containsOnlyValidXChars(phoneNumber, candidate, metadata)\r\n{\r\n\t// The characters 'x' and 'X' can be (1) a carrier code, in which case they always precede the\r\n\t// national significant number or (2) an extension sign, in which case they always precede the\r\n\t// extension number. We assume a carrier code is more than 1 digit, so the first case has to\r\n\t// have more than 1 consecutive 'x' or 'X', whereas the second case can only have exactly 1 'x'\r\n\t// or 'X'. We ignore the character if it appears as the last character of the string.\r\n\tfor (let index = 0; index < candidate.length - 1; index++)\r\n\t{\r\n\t\tconst charAtIndex = candidate.charAt(index)\r\n\r\n\t\tif (charAtIndex === 'x' || charAtIndex === 'X')\r\n\t\t{\r\n\t\t\tconst charAtNextIndex = candidate.charAt(index + 1)\r\n\r\n\t\t\tif (charAtNextIndex === 'x' || charAtNextIndex === 'X')\r\n\t\t\t{\r\n\t\t\t\t// This is the carrier code case, in which the 'X's always precede the national\r\n\t\t\t\t// significant number.\r\n\t\t\t\tindex++\r\n\t\t\t\tif (matchPhoneNumberStringAgainstPhoneNumber(candidate.substring(index), phoneNumber, metadata) !== 'NSN_MATCH')\r\n\t\t\t\t{\r\n\t\t\t\t\treturn false\r\n\t\t\t\t}\r\n\t\t\t\t// This is the extension sign case, in which the 'x' or 'X' should always precede the\r\n\t\t\t\t// extension number.\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tconst ext = parseDigits(candidate.substring(index))\r\n\t\t\t\tif (ext) {\r\n\t\t\t\t\tif (phoneNumber.ext !== ext) {\r\n\t\t\t\t\t\treturn false\r\n\t\t\t\t\t}\r\n\t\t\t\t} else {\r\n\t\t\t\t\tif (phoneNumber.ext) {\r\n\t\t\t\t\t\treturn false\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\treturn true\r\n}\r\n\r\nfunction isNationalPrefixPresentIfRequired(phoneNumber, _metadata)\r\n{\r\n\t// First, check how we deduced the country code. If it was written in international format, then\r\n\t// the national prefix is not required.\r\n\tif (phoneNumber.__countryCallingCodeSource !== 'FROM_DEFAULT_COUNTRY')\r\n\t{\r\n\t\treturn true\r\n\t}\r\n\r\n\tconst metadata = new Metadata(_metadata)\r\n\tmetadata.selectNumberingPlan(phoneNumber.countryCallingCode)\r\n\r\n\tconst phoneNumberRegion = phoneNumber.country || getCountryByCallingCode(phoneNumber.countryCallingCode, phoneNumber.nationalNumber, metadata)\r\n\r\n\t// Check if a national prefix should be present when formatting this number.\r\n\tconst nationalNumber = phoneNumber.nationalNumber\r\n\tconst format = chooseFormatForNumber(metadata.numberingPlan.formats(), nationalNumber)\r\n\r\n\t// To do this, we check that a national prefix formatting rule was present\r\n\t// and that it wasn't just the first-group symbol ($1) with punctuation.\r\n\tif (format.nationalPrefixFormattingRule())\r\n\t{\r\n\t\tif (metadata.numberingPlan.nationalPrefixIsOptionalWhenFormattingInNationalFormat())\r\n\t\t{\r\n\t\t\t// The national-prefix is optional in these cases, so we don't need to check if it was present.\r\n\t\t\treturn true\r\n\t\t}\r\n\r\n\t\tif (!format.usesNationalPrefix())\r\n\t\t{\r\n\t\t\t// National Prefix not needed for this number.\r\n\t\t\treturn true\r\n\t\t}\r\n\r\n\t\treturn Boolean(phoneNumber.nationalPrefix)\r\n\t}\r\n\r\n\treturn true\r\n}\r\n\r\nexport function containsMoreThanOneSlashInNationalNumber(phoneNumber, candidate)\r\n{\r\n\tconst firstSlashInBodyIndex = candidate.indexOf('/')\r\n\tif (firstSlashInBodyIndex < 0)\r\n\t{\r\n\t\t// No slashes, this is okay.\r\n\t\treturn false\r\n\t}\r\n\r\n\t// Now look for a second one.\r\n\tconst secondSlashInBodyIndex = candidate.indexOf('/', firstSlashInBodyIndex + 1)\r\n\tif (secondSlashInBodyIndex < 0)\r\n\t{\r\n\t\t// Only one slash, this is okay.\r\n\t\treturn false\r\n\t}\r\n\r\n\t// If the first slash is after the country calling code, this is permitted.\r\n\tconst candidateHasCountryCode =\r\n\t\t\tphoneNumber.__countryCallingCodeSource === 'FROM_NUMBER_WITH_PLUS_SIGN' ||\r\n\t\t\tphoneNumber.__countryCallingCodeSource === 'FROM_NUMBER_WITHOUT_PLUS_SIGN'\r\n\r\n\tif (candidateHasCountryCode && parseDigits(candidate.substring(0, firstSlashInBodyIndex)) === phoneNumber.countryCallingCode)\r\n\t{\r\n\t\t// Any more slashes and this is illegal.\r\n\t\treturn candidate.slice(secondSlashInBodyIndex + 1).indexOf('/') >= 0\r\n\t}\r\n\r\n\treturn true\r\n}\r\n\r\nfunction checkNumberGroupingIsValid(\r\n\tnumber,\r\n\tcandidate,\r\n\tmetadata,\r\n\tcheckGroups,\r\n\tregExpCache\r\n) {\r\n\tthrow new Error('This part of code hasn\\'t been ported')\r\n\r\n\tconst normalizedCandidate = normalizeDigits(candidate, true /* keep non-digits */)\r\n\tlet formattedNumberGroups = getNationalNumberGroups(metadata, number, null)\r\n\tif (checkGroups(metadata, number, normalizedCandidate, formattedNumberGroups)) {\r\n\t\treturn true\r\n\t}\r\n\r\n\t// If this didn't pass, see if there are any alternate formats that match, and try them instead.\r\n\tconst alternateFormats = MetadataManager.getAlternateFormatsForCountry(number.getCountryCode())\r\n\tconst nationalSignificantNumber = util.getNationalSignificantNumber(number)\r\n\r\n\tif (alternateFormats) {\r\n\t\tfor (const alternateFormat of alternateFormats.numberFormats()) {\r\n\t\t\tif (alternateFormat.leadingDigitsPatterns().length > 0) {\r\n\t\t\t\t// There is only one leading digits pattern for alternate formats.\r\n\t\t\t\tconst leadingDigitsRegExp = regExpCache.getPatternForRegExp('^' + alternateFormat.leadingDigitsPatterns()[0])\r\n\t\t\t\tif (!leadingDigitsRegExp.test(nationalSignificantNumber)) {\r\n\t\t\t\t\t// Leading digits don't match; try another one.\r\n\t\t\t\t\tcontinue\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tformattedNumberGroups = getNationalNumberGroups(metadata, number, alternateFormat)\r\n\t\t\tif (checkGroups(metadata, number, normalizedCandidate, formattedNumberGroups)) {\r\n\t\t\t\treturn true\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\treturn false\r\n}\r\n\r\n/**\r\n * Helper method to get the national-number part of a number, formatted without any national\r\n * prefix, and return it as a set of digit blocks that would be formatted together following\r\n * standard formatting rules.\r\n */\r\nfunction getNationalNumberGroups(\r\n\tmetadata,\r\n\tnumber,\r\n\tformattingPattern\r\n) {\r\n\tthrow new Error('This part of code hasn\\'t been ported')\r\n\r\n\tif (formattingPattern) {\r\n\t\t// We format the NSN only, and split that according to the separator.\r\n\t\tconst nationalSignificantNumber = util.getNationalSignificantNumber(number)\r\n\t\treturn util.formatNsnUsingPattern(nationalSignificantNumber,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tformattingPattern, 'RFC3966', metadata).split('-')\r\n\t}\r\n\r\n\t// This will be in the format +CC-DG1-DG2-DGX;ext=EXT where DG1..DGX represents groups of digits.\r\n\tconst rfc3966Format = formatNumber(number, 'RFC3966', metadata)\r\n\r\n\t// We remove the extension part from the formatted string before splitting it into different\r\n\t// groups.\r\n\tlet endIndex = rfc3966Format.indexOf(';')\r\n\tif (endIndex < 0) {\r\n\t\tendIndex = rfc3966Format.length\r\n\t}\r\n\r\n\t// The country-code will have a '-' following it.\r\n\tconst startIndex = rfc3966Format.indexOf('-') + 1\r\n\treturn rfc3966Format.slice(startIndex, endIndex).split('-')\r\n}\r\n\r\nfunction allNumberGroupsAreExactlyPresent\r\n(\r\n\tmetadata,\r\n\tnumber,\r\n\tnormalizedCandidate,\r\n\tformattedNumberGroups\r\n)\r\n{\r\n\tthrow new Error('This part of code hasn\\'t been ported')\r\n\r\n\tconst candidateGroups = normalizedCandidate.split(NON_DIGITS_PATTERN)\r\n\r\n\t// Set this to the last group, skipping it if the number has an extension.\r\n\tlet candidateNumberGroupIndex =\r\n\t\t\tnumber.hasExtension() ? candidateGroups.length - 2 : candidateGroups.length - 1\r\n\r\n\t// First we check if the national significant number is formatted as a block.\r\n\t// We use contains and not equals, since the national significant number may be present with\r\n\t// a prefix such as a national number prefix, or the country code itself.\r\n\tif (candidateGroups.length == 1\r\n\t\t\t|| candidateGroups[candidateNumberGroupIndex].contains(\r\n\t\t\t\t\tutil.getNationalSignificantNumber(number)))\r\n\t{\r\n\t\treturn true\r\n\t}\r\n\r\n\t// Starting from the end, go through in reverse, excluding the first group, and check the\r\n\t// candidate and number groups are the same.\r\n\tlet formattedNumberGroupIndex = (formattedNumberGroups.length - 1)\r\n\twhile (formattedNumberGroupIndex > 0 && candidateNumberGroupIndex >= 0)\r\n\t{\r\n\t\tif (candidateGroups[candidateNumberGroupIndex] !== formattedNumberGroups[formattedNumberGroupIndex])\r\n\t\t{\r\n\t\t\treturn false\r\n\t\t}\r\n\t\tformattedNumberGroupIndex--\r\n\t\tcandidateNumberGroupIndex--\r\n\t}\r\n\r\n\t// Now check the first group. There may be a national prefix at the start, so we only check\r\n\t// that the candidate group ends with the formatted number group.\r\n\treturn (candidateNumberGroupIndex >= 0\r\n\t\t\t&& endsWith(candidateGroups[candidateNumberGroupIndex], formattedNumberGroups[0]))\r\n}\r\n\r\n\r\nfunction allNumberGroupsRemainGrouped\r\n(\r\n\tmetadata,\r\n\tnumber,\r\n\tnormalizedCandidate,\r\n\tformattedNumberGroups\r\n)\r\n{\r\n\tthrow new Error('This part of code hasn\\'t been ported')\r\n\r\n\tlet fromIndex = 0\r\n\tif (number.getCountryCodeSource() !== CountryCodeSource.FROM_DEFAULT_COUNTRY)\r\n\t{\r\n\t\t// First skip the country code if the normalized candidate contained it.\r\n\t\tconst countryCode = String(number.getCountryCode())\r\n\t\tfromIndex = normalizedCandidate.indexOf(countryCode) + countryCode.length()\r\n\t}\r\n\r\n\t// Check each group of consecutive digits are not broken into separate groupings in the\r\n\t// {@code normalizedCandidate} string.\r\n\tfor (let i = 0; i < formattedNumberGroups.length; i++)\r\n\t{\r\n\t\t// Fails if the substring of {@code normalizedCandidate} starting from {@code fromIndex}\r\n\t\t// doesn't contain the consecutive digits in formattedNumberGroups[i].\r\n\t\tfromIndex = normalizedCandidate.indexOf(formattedNumberGroups[i], fromIndex)\r\n\t\tif (fromIndex < 0) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\t// Moves {@code fromIndex} forward.\r\n\t\tfromIndex += formattedNumberGroups[i].length()\r\n\t\tif (i == 0 && fromIndex < normalizedCandidate.length())\r\n\t\t{\r\n\t\t\t// We are at the position right after the NDC. We get the region used for formatting\r\n\t\t\t// information based on the country code in the phone number, rather than the number itself,\r\n\t\t\t// as we do not need to distinguish between different countries with the same country\r\n\t\t\t// calling code and this is faster.\r\n\t\t\tconst region = util.getRegionCodeForCountryCode(number.getCountryCode())\r\n\t\t\tif (util.getNddPrefixForRegion(region, true) != null\r\n\t\t\t\t\t&& Character.isDigit(normalizedCandidate.charAt(fromIndex))) {\r\n\t\t\t\t// This means there is no formatting symbol after the NDC. In this case, we only\r\n\t\t\t\t// accept the number if there is no formatting symbol at all in the number, except\r\n\t\t\t\t// for extensions. This is only important for countries with national prefixes.\r\n\t\t\t\tconst nationalSignificantNumber = util.getNationalSignificantNumber(number)\r\n\t\t\t\treturn startsWith\r\n\t\t\t\t(\r\n\t\t\t\t\tnormalizedCandidate.slice(fromIndex - formattedNumberGroups[i].length),\r\n\t\t\t\t\t nationalSignificantNumber\r\n\t\t\t\t)\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// The check here makes sure that we haven't mistakenly already used the extension to\r\n\t// match the last group of the subscriber number. Note the extension cannot have\r\n\t// formatting in-between digits.\r\n\treturn normalizedCandidate.slice(fromIndex).contains(number.getExtension())\r\n}"],"mappings":";;;;;;AAAA,OAAOA,aAAP,MAA0B,eAA1B;AACA,OAAOC,WAAP,MAAwB,2BAAxB;AACA,OAAOC,wCAAP,MAAqD,+CAArD;AACA,OAAOC,QAAP,MAAqB,gBAArB;AACA,OAAOC,uBAAP,MAAoC,uCAApC;AACA,SAASC,qBAAT,QAAsC,cAAtC;AAEA,SACCC,UADD,EAECC,QAFD,QAGO,WAHP;AAKA;AACA;AACA;AACA;;AACA,eACA;EACC;AACD;AACA;EACCC,QAJD,oBAIUC,WAJV,EAIuBC,SAJvB,EAIkCC,QAJlC,EAKC;IACC,OAAO,IAAP;EACA,CAPF;;EASC;AACD;AACA;AACA;AACA;EACCC,KAdD,iBAcOH,WAdP,EAcoBC,SAdpB,EAc+BC,QAd/B,EAeC;IACC,IACC,CAACF,WAAW,CAACI,OAAZ,EAAD,IACA,CAACC,uBAAuB,CAACL,WAAD,EAAcC,SAAd,EAAyBC,QAAzB,CAFzB,EAIA;MACC,OA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B,mBAAmB,CAACP,OAApB,CAA4BS,qBAAqB,CAACkC,CAAD,CAAjD,EAAsDN,SAAtD,CAAZ;;IACA,IAAIA,SAAS,GAAG,CAAhB,EAAmB;MAClB,OAAO,KAAP;IACA,CANF,CAOC;;;IACAA,SAAS,IAAI5B,qBAAqB,CAACkC,CAAD,CAArB,CAAyBjE,MAAzB,EAAb;;IACA,IAAIiE,CAAC,IAAI,CAAL,IAAUN,SAAS,GAAG9B,mBAAmB,CAAC7B,MAApB,EAA1B,EACA;MACC;MACA;MACA;MACA;MACA,IAAMkE,MAAM,GAAG5B,IAAI,CAAC6B,2BAAL,CAAiCzC,MAAM,CAACU,cAAP,EAAjC,CAAf;;MACA,IAAIE,IAAI,CAAC8B,qBAAL,CAA2BF,MAA3B,EAAmC,IAAnC,KAA4C,IAA5C,IACCG,SAAS,CAACC,OAAV,CAAkBzC,mBAAmB,CAAC3B,MAApB,CAA2ByD,SAA3B,CAAlB,CADL,EAC+D;QAC9D;QACA;QACA;QACA,IAAMtB,yBAAyB,GAAGC,IAAI,CAACC,4BAAL,CAAkCb,MAAlC,CAAlC;QACA,OAAO5C,UAAU,CAEhB+C,mBAAmB,CAACJ,KAApB,CAA0BkC,SAAS,GAAG5B,qBAAqB,CAACkC,CAAD,CAArB,CAAyBjE,MAA/D,CAFgB,EAGfqC,yBAHe,CAAjB;MAKA;IACD;EACD,CA3CF,CA6CC;EACA;EACA;;;EACA,OAAOR,mBAAmB,CAACJ,KAApB,CAA0BkC,SAA1B,EAAqCF,QAArC,CAA8C/B,MAAM,CAAC6C,YAAP,EAA9C,CAAP;AACA"}
1
+ {"version":3,"file":"Leniency.js","names":["isValidNumber","parseDigits","matchPhoneNumberStringAgainstPhoneNumber","Metadata","getCountryByCallingCode","chooseFormatForNumber","startsWith","endsWith","POSSIBLE","phoneNumber","candidate","metadata","VALID","defaultCountry","isValid","containsOnlyValidXChars","STRICT_GROUPING","regExpCache","containsMoreThanOneSlashInNationalNumber","isNationalPrefixPresentIfRequired","checkNumberGroupingIsValid","allNumberGroupsRemainGrouped","EXACT_GROUPING","allNumberGroupsAreExactlyPresent","index","length","charAtIndex","charAt","charAtNextIndex","substring","ext","_metadata","__countryCallingCodeSource","selectNumberingPlan","countryCallingCode","phoneNumberRegion","country","nationalNumber","format","numberingPlan","formats","nationalPrefixFormattingRule","nationalPrefixIsOptionalWhenFormattingInNationalFormat","usesNationalPrefix","Boolean","nationalPrefix","firstSlashInBodyIndex","indexOf","secondSlashInBodyIndex","candidateHasCountryCode","slice","number","checkGroups","Error","normalizedCandidate","normalizeDigits","formattedNumberGroups","getNationalNumberGroups","alternateFormats","MetadataManager","getAlternateFormatsForCountry","getCountryCode","nationalSignificantNumber","util","getNationalSignificantNumber","numberFormats","alternateFormat","leadingDigitsPatterns","leadingDigitsRegExp","getPatternForRegExp","test","formattingPattern","formatNsnUsingPattern","split","rfc3966Format","formatNumber","endIndex","startIndex","candidateGroups","NON_DIGITS_PATTERN","candidateNumberGroupIndex","hasExtension","contains","formattedNumberGroupIndex","fromIndex","getCountryCodeSource","CountryCodeSource","FROM_DEFAULT_COUNTRY","countryCode","String","i","region","getRegionCodeForCountryCode","getNddPrefixForRegion","Character","isDigit","getExtension"],"sources":["../../source/findNumbers/Leniency.js"],"sourcesContent":["import isValidNumber from '../isValid.js'\r\nimport parseDigits from '../helpers/parseDigits.js'\r\nimport matchPhoneNumberStringAgainstPhoneNumber from './matchPhoneNumberStringAgainstPhoneNumber.js'\r\nimport Metadata from '../metadata.js'\r\nimport getCountryByCallingCode from '../helpers/getCountryByCallingCode.js'\r\nimport { chooseFormatForNumber } from '../format.js'\r\n\r\nimport {\r\n\tstartsWith,\r\n\tendsWith\r\n} from './util.js'\r\n\r\n/**\r\n * Leniency when finding potential phone numbers in text segments\r\n * The levels here are ordered in increasing strictness.\r\n */\r\nexport default\r\n{\r\n\t/**\r\n\t * Phone numbers accepted are \"possible\", but not necessarily \"valid\".\r\n\t */\r\n\tPOSSIBLE(phoneNumber, { candidate, metadata })\r\n\t{\r\n\t\treturn true\r\n\t},\r\n\r\n\t/**\r\n\t * Phone numbers accepted are \"possible\" and \"valid\".\r\n\t * Numbers written in national format must have their national-prefix\r\n\t * present if it is usually written for a number of this type.\r\n\t */\r\n\tVALID(phoneNumber, { candidate, defaultCountry, metadata })\r\n\t{\r\n\t\tif (\r\n\t\t\t!phoneNumber.isValid() ||\r\n\t\t\t!containsOnlyValidXChars(phoneNumber, candidate, metadata)\r\n\t\t)\r\n\t\t{\r\n\t\t\treturn false\r\n\t\t}\r\n\r\n\t\t// Skipped for simplicity.\r\n\t\t// return isNationalPrefixPresentIfRequired(phoneNumber, { defaultCountry, metadata })\r\n\t\treturn true\r\n\t},\r\n\r\n\t/**\r\n\t * Phone numbers accepted are \"valid\" and\r\n\t * are grouped in a possible way for this locale. For example, a US number written as\r\n\t * \"65 02 53 00 00\" and \"650253 0000\" are not accepted at this leniency level, whereas\r\n\t * \"650 253 0000\", \"650 2530000\" or \"6502530000\" are.\r\n\t * Numbers with more than one '/' symbol in the national significant number\r\n\t * are also dropped at this level.\r\n\t *\r\n\t * Warning: This level might result in lower coverage especially for regions outside of\r\n\t * country code \"+1\". If you are not sure about which level to use,\r\n\t * email the discussion group libphonenumber-discuss@googlegroups.com.\r\n\t */\r\n\tSTRICT_GROUPING(phoneNumber, { candidate, defaultCountry, metadata, regExpCache })\r\n\t{\r\n\t\tif (\r\n\t\t\t!phoneNumber.isValid() ||\r\n\t\t\t!containsOnlyValidXChars(phoneNumber, candidate, metadata) ||\r\n\t\t\tcontainsMoreThanOneSlashInNationalNumber(phoneNumber, candidate) ||\r\n\t\t\t!isNationalPrefixPresentIfRequired(phoneNumber, { defaultCountry, metadata })\r\n\t\t)\r\n\t\t{\r\n\t\t\treturn false\r\n\t\t}\r\n\r\n\t\treturn checkNumberGroupingIsValid\r\n\t\t(\r\n\t\t\tphoneNumber,\r\n\t\t\tcandidate,\r\n\t\t\tmetadata,\r\n\t\t\tallNumberGroupsRemainGrouped,\r\n\t\t\tregExpCache\r\n\t\t)\r\n\t},\r\n\r\n\t/**\r\n\t * Phone numbers accepted are \"valid\" and are grouped in the same way\r\n\t * that we would have formatted it, or as a single block.\r\n\t * For example, a US number written as \"650 2530000\" is not accepted\r\n\t * at this leniency level, whereas \"650 253 0000\" or \"6502530000\" are.\r\n\t * Numbers with more than one '/' symbol are also dropped at this level.\r\n\t *\r\n\t * Warning: This level might result in lower coverage especially for regions outside of\r\n\t * country code \"+1\". If you are not sure about which level to use, email the discussion group\r\n\t * libphonenumber-discuss@googlegroups.com.\r\n\t */\r\n\tEXACT_GROUPING(phoneNumber, { candidate, defaultCountry, metadata, regExpCache })\r\n\t{\r\n\t\tif (\r\n\t\t\t!phoneNumber.isValid() ||\r\n\t\t\t!containsOnlyValidXChars(phoneNumber, candidate, metadata) ||\r\n\t\t\tcontainsMoreThanOneSlashInNationalNumber(phoneNumber, candidate) ||\r\n\t\t\t!isNationalPrefixPresentIfRequired(phoneNumber, { defaultCountry, metadata })\r\n\t\t)\r\n\t\t{\r\n\t\t\treturn false\r\n\t\t}\r\n\r\n\t\treturn checkNumberGroupingIsValid\r\n\t\t(\r\n\t\t\tphoneNumber,\r\n\t\t\tcandidate,\r\n\t\t\tmetadata,\r\n\t\t\tallNumberGroupsAreExactlyPresent,\r\n\t\t\tregExpCache\r\n\t\t)\r\n\t}\r\n}\r\n\r\nfunction containsOnlyValidXChars(phoneNumber, candidate, metadata)\r\n{\r\n\t// The characters 'x' and 'X' can be (1) a carrier code, in which case they always precede the\r\n\t// national significant number or (2) an extension sign, in which case they always precede the\r\n\t// extension number. We assume a carrier code is more than 1 digit, so the first case has to\r\n\t// have more than 1 consecutive 'x' or 'X', whereas the second case can only have exactly 1 'x'\r\n\t// or 'X'. We ignore the character if it appears as the last character of the string.\r\n\tfor (let index = 0; index < candidate.length - 1; index++)\r\n\t{\r\n\t\tconst charAtIndex = candidate.charAt(index)\r\n\r\n\t\tif (charAtIndex === 'x' || charAtIndex === 'X')\r\n\t\t{\r\n\t\t\tconst charAtNextIndex = candidate.charAt(index + 1)\r\n\r\n\t\t\tif (charAtNextIndex === 'x' || charAtNextIndex === 'X')\r\n\t\t\t{\r\n\t\t\t\t// This is the carrier code case, in which the 'X's always precede the national\r\n\t\t\t\t// significant number.\r\n\t\t\t\tindex++\r\n\t\t\t\tif (matchPhoneNumberStringAgainstPhoneNumber(candidate.substring(index), phoneNumber, metadata) !== 'NSN_MATCH')\r\n\t\t\t\t{\r\n\t\t\t\t\treturn false\r\n\t\t\t\t}\r\n\t\t\t\t// This is the extension sign case, in which the 'x' or 'X' should always precede the\r\n\t\t\t\t// extension number.\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tconst ext = parseDigits(candidate.substring(index))\r\n\t\t\t\tif (ext) {\r\n\t\t\t\t\tif (phoneNumber.ext !== ext) {\r\n\t\t\t\t\t\treturn false\r\n\t\t\t\t\t}\r\n\t\t\t\t} else {\r\n\t\t\t\t\tif (phoneNumber.ext) {\r\n\t\t\t\t\t\treturn false\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\treturn true\r\n}\r\n\r\nfunction isNationalPrefixPresentIfRequired(phoneNumber, { defaultCountry, metadata: _metadata })\r\n{\r\n\t// First, check how we deduced the country code. If it was written in international format, then\r\n\t// the national prefix is not required.\r\n\tif (phoneNumber.__countryCallingCodeSource !== 'FROM_DEFAULT_COUNTRY')\r\n\t{\r\n\t\treturn true\r\n\t}\r\n\r\n\tconst metadata = new Metadata(_metadata)\r\n\tmetadata.selectNumberingPlan(phoneNumber.countryCallingCode)\r\n\r\n\tconst phoneNumberRegion = phoneNumber.country || getCountryByCallingCode(phoneNumber.countryCallingCode, {\r\n\t\tnationalNumber: phoneNumber.nationalNumber,\r\n\t\tdefaultCountry,\r\n\t\tmetadata\r\n\t})\r\n\r\n\t// Check if a national prefix should be present when formatting this number.\r\n\tconst nationalNumber = phoneNumber.nationalNumber\r\n\tconst format = chooseFormatForNumber(metadata.numberingPlan.formats(), nationalNumber)\r\n\r\n\t// To do this, we check that a national prefix formatting rule was present\r\n\t// and that it wasn't just the first-group symbol ($1) with punctuation.\r\n\tif (format.nationalPrefixFormattingRule())\r\n\t{\r\n\t\tif (metadata.numberingPlan.nationalPrefixIsOptionalWhenFormattingInNationalFormat())\r\n\t\t{\r\n\t\t\t// The national-prefix is optional in these cases, so we don't need to check if it was present.\r\n\t\t\treturn true\r\n\t\t}\r\n\r\n\t\tif (!format.usesNationalPrefix())\r\n\t\t{\r\n\t\t\t// National Prefix not needed for this number.\r\n\t\t\treturn true\r\n\t\t}\r\n\r\n\t\treturn Boolean(phoneNumber.nationalPrefix)\r\n\t}\r\n\r\n\treturn true\r\n}\r\n\r\nexport function containsMoreThanOneSlashInNationalNumber(phoneNumber, candidate)\r\n{\r\n\tconst firstSlashInBodyIndex = candidate.indexOf('/')\r\n\tif (firstSlashInBodyIndex < 0)\r\n\t{\r\n\t\t// No slashes, this is okay.\r\n\t\treturn false\r\n\t}\r\n\r\n\t// Now look for a second one.\r\n\tconst secondSlashInBodyIndex = candidate.indexOf('/', firstSlashInBodyIndex + 1)\r\n\tif (secondSlashInBodyIndex < 0)\r\n\t{\r\n\t\t// Only one slash, this is okay.\r\n\t\treturn false\r\n\t}\r\n\r\n\t// If the first slash is after the country calling code, this is permitted.\r\n\tconst candidateHasCountryCode =\r\n\t\t\tphoneNumber.__countryCallingCodeSource === 'FROM_NUMBER_WITH_PLUS_SIGN' ||\r\n\t\t\tphoneNumber.__countryCallingCodeSource === 'FROM_NUMBER_WITHOUT_PLUS_SIGN'\r\n\r\n\tif (candidateHasCountryCode && parseDigits(candidate.substring(0, firstSlashInBodyIndex)) === phoneNumber.countryCallingCode)\r\n\t{\r\n\t\t// Any more slashes and this is illegal.\r\n\t\treturn candidate.slice(secondSlashInBodyIndex + 1).indexOf('/') >= 0\r\n\t}\r\n\r\n\treturn true\r\n}\r\n\r\nfunction checkNumberGroupingIsValid(\r\n\tnumber,\r\n\tcandidate,\r\n\tmetadata,\r\n\tcheckGroups,\r\n\tregExpCache\r\n) {\r\n\tthrow new Error('This part of code hasn\\'t been ported')\r\n\r\n\tconst normalizedCandidate = normalizeDigits(candidate, true /* keep non-digits */)\r\n\tlet formattedNumberGroups = getNationalNumberGroups(metadata, number, null)\r\n\tif (checkGroups(metadata, number, normalizedCandidate, formattedNumberGroups)) {\r\n\t\treturn true\r\n\t}\r\n\r\n\t// If this didn't pass, see if there are any alternate formats that match, and try them instead.\r\n\tconst alternateFormats = MetadataManager.getAlternateFormatsForCountry(number.getCountryCode())\r\n\tconst nationalSignificantNumber = util.getNationalSignificantNumber(number)\r\n\r\n\tif (alternateFormats) {\r\n\t\tfor (const alternateFormat of alternateFormats.numberFormats()) {\r\n\t\t\tif (alternateFormat.leadingDigitsPatterns().length > 0) {\r\n\t\t\t\t// There is only one leading digits pattern for alternate formats.\r\n\t\t\t\tconst leadingDigitsRegExp = regExpCache.getPatternForRegExp('^' + alternateFormat.leadingDigitsPatterns()[0])\r\n\t\t\t\tif (!leadingDigitsRegExp.test(nationalSignificantNumber)) {\r\n\t\t\t\t\t// Leading digits don't match; try another one.\r\n\t\t\t\t\tcontinue\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tformattedNumberGroups = getNationalNumberGroups(metadata, number, alternateFormat)\r\n\t\t\tif (checkGroups(metadata, number, normalizedCandidate, formattedNumberGroups)) {\r\n\t\t\t\treturn true\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\treturn false\r\n}\r\n\r\n/**\r\n * Helper method to get the national-number part of a number, formatted without any national\r\n * prefix, and return it as a set of digit blocks that would be formatted together following\r\n * standard formatting rules.\r\n */\r\nfunction getNationalNumberGroups(\r\n\tmetadata,\r\n\tnumber,\r\n\tformattingPattern\r\n) {\r\n\tthrow new Error('This part of code hasn\\'t been ported')\r\n\r\n\tif (formattingPattern) {\r\n\t\t// We format the NSN only, and split that according to the separator.\r\n\t\tconst nationalSignificantNumber = util.getNationalSignificantNumber(number)\r\n\t\treturn util.formatNsnUsingPattern(nationalSignificantNumber,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tformattingPattern, 'RFC3966', metadata).split('-')\r\n\t}\r\n\r\n\t// This will be in the format +CC-DG1-DG2-DGX;ext=EXT where DG1..DGX represents groups of digits.\r\n\tconst rfc3966Format = formatNumber(number, 'RFC3966', metadata)\r\n\r\n\t// We remove the extension part from the formatted string before splitting it into different\r\n\t// groups.\r\n\tlet endIndex = rfc3966Format.indexOf(';')\r\n\tif (endIndex < 0) {\r\n\t\tendIndex = rfc3966Format.length\r\n\t}\r\n\r\n\t// The country-code will have a '-' following it.\r\n\tconst startIndex = rfc3966Format.indexOf('-') + 1\r\n\treturn rfc3966Format.slice(startIndex, endIndex).split('-')\r\n}\r\n\r\nfunction allNumberGroupsAreExactlyPresent\r\n(\r\n\tmetadata,\r\n\tnumber,\r\n\tnormalizedCandidate,\r\n\tformattedNumberGroups\r\n)\r\n{\r\n\tthrow new Error('This part of code hasn\\'t been ported')\r\n\r\n\tconst candidateGroups = normalizedCandidate.split(NON_DIGITS_PATTERN)\r\n\r\n\t// Set this to the last group, skipping it if the number has an extension.\r\n\tlet candidateNumberGroupIndex =\r\n\t\t\tnumber.hasExtension() ? candidateGroups.length - 2 : candidateGroups.length - 1\r\n\r\n\t// First we check if the national significant number is formatted as a block.\r\n\t// We use contains and not equals, since the national significant number may be present with\r\n\t// a prefix such as a national number prefix, or the country code itself.\r\n\tif (candidateGroups.length == 1\r\n\t\t\t|| candidateGroups[candidateNumberGroupIndex].contains(\r\n\t\t\t\t\tutil.getNationalSignificantNumber(number)))\r\n\t{\r\n\t\treturn true\r\n\t}\r\n\r\n\t// Starting from the end, go through in reverse, excluding the first group, and check the\r\n\t// candidate and number groups are the same.\r\n\tlet formattedNumberGroupIndex = (formattedNumberGroups.length - 1)\r\n\twhile (formattedNumberGroupIndex > 0 && candidateNumberGroupIndex >= 0)\r\n\t{\r\n\t\tif (candidateGroups[candidateNumberGroupIndex] !== formattedNumberGroups[formattedNumberGroupIndex])\r\n\t\t{\r\n\t\t\treturn false\r\n\t\t}\r\n\t\tformattedNumberGroupIndex--\r\n\t\tcandidateNumberGroupIndex--\r\n\t}\r\n\r\n\t// Now check the first group. There may be a national prefix at the start, so we only check\r\n\t// that the candidate group ends with the formatted number group.\r\n\treturn (candidateNumberGroupIndex >= 0\r\n\t\t\t&& endsWith(candidateGroups[candidateNumberGroupIndex], formattedNumberGroups[0]))\r\n}\r\n\r\n\r\nfunction allNumberGroupsRemainGrouped\r\n(\r\n\tmetadata,\r\n\tnumber,\r\n\tnormalizedCandidate,\r\n\tformattedNumberGroups\r\n)\r\n{\r\n\tthrow new Error('This part of code hasn\\'t been ported')\r\n\r\n\tlet fromIndex = 0\r\n\tif (number.getCountryCodeSource() !== CountryCodeSource.FROM_DEFAULT_COUNTRY)\r\n\t{\r\n\t\t// First skip the country code if the normalized candidate contained it.\r\n\t\tconst countryCode = String(number.getCountryCode())\r\n\t\tfromIndex = normalizedCandidate.indexOf(countryCode) + countryCode.length()\r\n\t}\r\n\r\n\t// Check each group of consecutive digits are not broken into separate groupings in the\r\n\t// {@code normalizedCandidate} string.\r\n\tfor (let i = 0; i < formattedNumberGroups.length; i++)\r\n\t{\r\n\t\t// Fails if the substring of {@code normalizedCandidate} starting from {@code fromIndex}\r\n\t\t// doesn't contain the consecutive digits in formattedNumberGroups[i].\r\n\t\tfromIndex = normalizedCandidate.indexOf(formattedNumberGroups[i], fromIndex)\r\n\t\tif (fromIndex < 0) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\t// Moves {@code fromIndex} forward.\r\n\t\tfromIndex += formattedNumberGroups[i].length()\r\n\t\tif (i == 0 && fromIndex < normalizedCandidate.length())\r\n\t\t{\r\n\t\t\t// We are at the position right after the NDC. We get the region used for formatting\r\n\t\t\t// information based on the country code in the phone number, rather than the number itself,\r\n\t\t\t// as we do not need to distinguish between different countries with the same country\r\n\t\t\t// calling code and this is faster.\r\n\t\t\tconst region = util.getRegionCodeForCountryCode(number.getCountryCode())\r\n\t\t\tif (util.getNddPrefixForRegion(region, true) != null\r\n\t\t\t\t\t&& Character.isDigit(normalizedCandidate.charAt(fromIndex))) {\r\n\t\t\t\t// This means there is no formatting symbol after the NDC. In this case, we only\r\n\t\t\t\t// accept the number if there is no formatting symbol at all in the number, except\r\n\t\t\t\t// for extensions. This is only important for countries with national prefixes.\r\n\t\t\t\tconst nationalSignificantNumber = util.getNationalSignificantNumber(number)\r\n\t\t\t\treturn startsWith\r\n\t\t\t\t(\r\n\t\t\t\t\tnormalizedCandidate.slice(fromIndex - formattedNumberGroups[i].length),\r\n\t\t\t\t\t nationalSignificantNumber\r\n\t\t\t\t)\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// The check here makes sure that we haven't mistakenly already used the extension to\r\n\t// match the last group of the subscriber number. Note the extension cannot have\r\n\t// formatting in-between digits.\r\n\treturn normalizedCandidate.slice(fromIndex).contains(number.getExtension())\r\n}"],"mappings":";;;;;;AAAA,OAAOA,aAAP,MAA0B,eAA1B;AACA,OAAOC,WAAP,MAAwB,2BAAxB;AACA,OAAOC,wCAAP,MAAqD,+CAArD;AACA,OAAOC,QAAP,MAAqB,gBAArB;AACA,OAAOC,uBAAP,MAAoC,uCAApC;AACA,SAASC,qBAAT,QAAsC,cAAtC;AAEA,SACCC,UADD,EAECC,QAFD,QAGO,WAHP;AAKA;AACA;AACA;AACA;;AACA,eACA;EACC;AACD;AACA;EACCC,QAJD,oBAIUC,WAJV,QAKC;IAAA,IADwBC,SACxB,QADwBA,SACxB;IAAA,IADmCC,QACnC,QADmCA,QACnC;IACC,OAAO,IAAP;EACA,CAPF;;EASC;AACD;AACA;AACA;AACA;EACCC,KAdD,iBAcOH,WAdP,SAeC;IAAA,IADqBC,SACrB,SADqBA,SACrB;IAAA,IADgCG,cAChC,SADgCA,cAChC;IAAA,IADgDF,QAChD,SADgDA,QAChD;;I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AEhBgD,mBAAmB,CAACJ,KAApB,CAA0BkC,SAAS,GAAG5B,qBAAqB,CAACkC,CAAD,CAArB,CAAyBjE,MAA/D,CAFgB,EAGfqC,yBAHe,CAAjB;MAKA;IACD;EACD,CA3CF,CA6CC;EACA;EACA;;;EACA,OAAOR,mBAAmB,CAACJ,KAApB,CAA0BkC,SAA1B,EAAqCF,QAArC,CAA8C/B,MAAM,CAAC6C,YAAP,EAA9C,CAAP;AACA"}
@@ -1,6 +1,10 @@
1
1
  import getCountryByNationalNumber from './getCountryByNationalNumber.js';
2
2
  var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;
3
- export default function getCountryByCallingCode(callingCode, nationalPhoneNumber, metadata) {
3
+ export default function getCountryByCallingCode(callingCode, _ref) {
4
+ var nationalPhoneNumber = _ref.nationalNumber,
5
+ defaultCountry = _ref.defaultCountry,
6
+ metadata = _ref.metadata;
7
+
4
8
  /* istanbul ignore if */
5
9
  if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
6
10
  if (metadata.isNonGeographicCallingCode(callingCode)) {
@@ -20,6 +24,10 @@ export default function getCountryByCallingCode(callingCode, nationalPhoneNumber
20
24
  return possibleCountries[0];
21
25
  }
22
26
 
23
- return getCountryByNationalNumber(possibleCountries, nationalPhoneNumber, metadata.metadata);
27
+ return getCountryByNationalNumber(nationalPhoneNumber, {
28
+ countries: possibleCountries,
29
+ defaultCountry: defaultCountry,
30
+ metadata: metadata.metadata
31
+ });
24
32
  }
25
33
  //# sourceMappingURL=getCountryByCallingCode.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getCountryByCallingCode.js","names":["getCountryByNationalNumber","USE_NON_GEOGRAPHIC_COUNTRY_CODE","getCountryByCallingCode","callingCode","nationalPhoneNumber","metadata","isNonGeographicCallingCode","possibleCountries","getCountryCodesForCallingCode","length"],"sources":["../../source/helpers/getCountryByCallingCode.js"],"sourcesContent":["import getCountryByNationalNumber from './getCountryByNationalNumber.js'\r\n\r\nconst USE_NON_GEOGRAPHIC_COUNTRY_CODE = false\r\n\r\nexport default function getCountryByCallingCode(callingCode, nationalPhoneNumber, metadata) {\r\n\t/* istanbul ignore if */\r\n\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\tif (metadata.isNonGeographicCallingCode(callingCode)) {\r\n\t\t\treturn '001'\r\n\t\t}\r\n\t}\r\n\tconst possibleCountries = metadata.getCountryCodesForCallingCode(callingCode)\r\n\tif (!possibleCountries) {\r\n\t\treturn\r\n\t}\r\n\t// If there's just one country corresponding to the country code,\r\n\t// then just return it, without further phone number digits validation.\r\n\tif (possibleCountries.length === 1) {\r\n\t\treturn possibleCountries[0]\r\n\t}\r\n\treturn getCountryByNationalNumber(possibleCountries, nationalPhoneNumber, metadata.metadata)\r\n}"],"mappings":"AAAA,OAAOA,0BAAP,MAAuC,iCAAvC;AAEA,IAAMC,+BAA+B,GAAG,KAAxC;AAEA,eAAe,SAASC,uBAAT,CAAiCC,WAAjC,EAA8CC,mBAA9C,EAAmEC,QAAnE,EAA6E;EAC3F;EACA,IAAIJ,+BAAJ,EAAqC;IACpC,IAAII,QAAQ,CAACC,0BAAT,CAAoCH,WAApC,CAAJ,EAAsD;MACrD,OAAO,KAAP;IACA;EACD;;EACD,IAAMI,iBAAiB,GAAGF,QAAQ,CAACG,6BAAT,CAAuCL,WAAvC,CAA1B;;EACA,IAAI,CAACI,iBAAL,EAAwB;IACvB;EACA,CAV0F,CAW3F;EACA;;;EACA,IAAIA,iBAAiB,CAACE,MAAlB,KAA6B,CAAjC,EAAoC;IACnC,OAAOF,iBAAiB,CAAC,CAAD,CAAxB;EACA;;EACD,OAAOP,0BAA0B,CAACO,iBAAD,EAAoBH,mBAApB,EAAyCC,QAAQ,CAACA,QAAlD,CAAjC;AACA"}
1
+ {"version":3,"file":"getCountryByCallingCode.js","names":["getCountryByNationalNumber","USE_NON_GEOGRAPHIC_COUNTRY_CODE","getCountryByCallingCode","callingCode","nationalPhoneNumber","nationalNumber","defaultCountry","metadata","isNonGeographicCallingCode","possibleCountries","getCountryCodesForCallingCode","length","countries"],"sources":["../../source/helpers/getCountryByCallingCode.js"],"sourcesContent":["import getCountryByNationalNumber from './getCountryByNationalNumber.js'\r\n\r\nconst USE_NON_GEOGRAPHIC_COUNTRY_CODE = false\r\n\r\nexport default function getCountryByCallingCode(callingCode, {\r\n\tnationalNumber: nationalPhoneNumber,\r\n\tdefaultCountry,\r\n\tmetadata\r\n}) {\r\n\t/* istanbul ignore if */\r\n\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\tif (metadata.isNonGeographicCallingCode(callingCode)) {\r\n\t\t\treturn '001'\r\n\t\t}\r\n\t}\r\n\tconst possibleCountries = metadata.getCountryCodesForCallingCode(callingCode)\r\n\tif (!possibleCountries) {\r\n\t\treturn\r\n\t}\r\n\t// If there's just one country corresponding to the country code,\r\n\t// then just return it, without further phone number digits validation.\r\n\tif (possibleCountries.length === 1) {\r\n\t\treturn possibleCountries[0]\r\n\t}\r\n\treturn getCountryByNationalNumber(nationalPhoneNumber, {\r\n\t\tcountries: possibleCountries,\r\n\t\tdefaultCountry,\r\n\t\tmetadata: metadata.metadata\r\n\t})\r\n}"],"mappings":"AAAA,OAAOA,0BAAP,MAAuC,iCAAvC;AAEA,IAAMC,+BAA+B,GAAG,KAAxC;AAEA,eAAe,SAASC,uBAAT,CAAiCC,WAAjC,QAIZ;EAAA,IAHcC,mBAGd,QAHFC,cAGE;EAAA,IAFFC,cAEE,QAFFA,cAEE;EAAA,IADFC,QACE,QADFA,QACE;;EACF;EACA,IAAIN,+BAAJ,EAAqC;IACpC,IAAIM,QAAQ,CAACC,0BAAT,CAAoCL,WAApC,CAAJ,EAAsD;MACrD,OAAO,KAAP;IACA;EACD;;EACD,IAAMM,iBAAiB,GAAGF,QAAQ,CAACG,6BAAT,CAAuCP,WAAvC,CAA1B;;EACA,IAAI,CAACM,iBAAL,EAAwB;IACvB;EACA,CAVC,CAWF;EACA;;;EACA,IAAIA,iBAAiB,CAACE,MAAlB,KAA6B,CAAjC,EAAoC;IACnC,OAAOF,iBAAiB,CAAC,CAAD,CAAxB;EACA;;EACD,OAAOT,0BAA0B,CAACI,mBAAD,EAAsB;IACtDQ,SAAS,EAAEH,iBAD2C;IAEtDH,cAAc,EAAdA,cAFsD;IAGtDC,QAAQ,EAAEA,QAAQ,CAACA;EAHmC,CAAtB,CAAjC;AAKA"}
@@ -6,17 +6,23 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
6
6
 
7
7
  import Metadata from '../metadata.js';
8
8
  import getNumberType from './getNumberType.js';
9
- export default function getCountryByNationalNumber(possibleCountries, nationalPhoneNumber, metadata) {
9
+ export default function getCountryByNationalNumber(nationalPhoneNumber, _ref) {
10
+ var countries = _ref.countries,
11
+ defaultCountry = _ref.defaultCountry,
12
+ metadata = _ref.metadata;
10
13
  // Re-create `metadata` because it will be selecting a `country`.
11
14
  metadata = new Metadata(metadata);
15
+ var matchingCountries = [];
12
16
 
13
- for (var _iterator = _createForOfIteratorHelperLoose(possibleCountries), _step; !(_step = _iterator()).done;) {
17
+ for (var _iterator = _createForOfIteratorHelperLoose(countries), _step; !(_step = _iterator()).done;) {
14
18
  var country = _step.value;
15
19
  metadata.country(country); // "Leading digits" patterns are only defined for about 20% of all countries.
16
20
  // By definition, matching "leading digits" is a sufficient but not a necessary
17
21
  // condition for a phone number to belong to a country.
18
22
  // The point of "leading digits" check is that it's the fastest one to get a match.
19
23
  // https://gitlab.com/catamphetamine/libphonenumber-js/blob/master/METADATA.md#leading_digits
24
+ // I'd suppose that "leading digits" patterns are mutually exclusive for different countries
25
+ // because of the intended use of that feature.
20
26
 
21
27
  if (metadata.leadingDigits()) {
22
28
  if (nationalPhoneNumber && nationalPhoneNumber.search(metadata.leadingDigits()) === 0) {
@@ -28,8 +34,22 @@ export default function getCountryByNationalNumber(possibleCountries, nationalPh
28
34
  phone: nationalPhoneNumber,
29
35
  country: country
30
36
  }, undefined, metadata.metadata)) {
31
- return country;
37
+ // If the `defaultCountry` is among the `matchingCountries` then return it.
38
+ if (defaultCountry) {
39
+ if (country === defaultCountry) {
40
+ return country;
41
+ }
42
+
43
+ matchingCountries.push(country);
44
+ } else {
45
+ return country;
46
+ }
32
47
  }
48
+ } // Return the first ("main") one of the `matchingCountries`.
49
+
50
+
51
+ if (matchingCountries.length > 0) {
52
+ return matchingCountries[0];
33
53
  }
34
54
  }
35
55
  //# sourceMappingURL=getCountryByNationalNumber.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getCountryByNationalNumber.js","names":["Metadata","getNumberType","getCountryByNationalNumber","possibleCountries","nationalPhoneNumber","metadata","country","leadingDigits","search","phone","undefined"],"sources":["../../source/helpers/getCountryByNationalNumber.js"],"sourcesContent":["import Metadata from '../metadata.js'\r\nimport getNumberType from './getNumberType.js'\r\n\r\nexport default function getCountryByNationalNumber(possibleCountries, nationalPhoneNumber, metadata) {\r\n\t// Re-create `metadata` because it will be selecting a `country`.\r\n\tmetadata = new Metadata(metadata)\r\n\tfor (const country of possibleCountries) {\r\n\t\tmetadata.country(country)\r\n\t\t// \"Leading digits\" patterns are only defined for about 20% of all countries.\r\n\t\t// By definition, matching \"leading digits\" is a sufficient but not a necessary\r\n\t\t// condition for a phone number to belong to a country.\r\n\t\t// The point of \"leading digits\" check is that it's the fastest one to get a match.\r\n\t\t// https://gitlab.com/catamphetamine/libphonenumber-js/blob/master/METADATA.md#leading_digits\r\n\t\tif (metadata.leadingDigits()) {\r\n\t\t\tif (nationalPhoneNumber &&\r\n\t\t\t\tnationalPhoneNumber.search(metadata.leadingDigits()) === 0) {\r\n\t\t\t\treturn country\r\n\t\t\t}\r\n\t\t}\r\n\t\t// Else perform full validation with all of those\r\n\t\t// fixed-line/mobile/etc regular expressions.\r\n\t\telse if (getNumberType({ phone: nationalPhoneNumber, country }, undefined, metadata.metadata)) {\r\n\t\t\treturn country\r\n\t\t}\r\n\t}\r\n}"],"mappings":";;;;;;AAAA,OAAOA,QAAP,MAAqB,gBAArB;AACA,OAAOC,aAAP,MAA0B,oBAA1B;AAEA,eAAe,SAASC,0BAAT,CAAoCC,iBAApC,EAAuDC,mBAAvD,EAA4EC,QAA5E,EAAsF;EACpG;EACAA,QAAQ,GAAG,IAAIL,QAAJ,CAAaK,QAAb,CAAX;;EACA,qDAAsBF,iBAAtB,wCAAyC;IAAA,IAA9BG,OAA8B;IACxCD,QAAQ,CAACC,OAAT,CAAiBA,OAAjB,EADwC,CAExC;IACA;IACA;IACA;IACA;;IACA,IAAID,QAAQ,CAACE,aAAT,EAAJ,EAA8B;MAC7B,IAAIH,mBAAmB,IACtBA,mBAAmB,CAACI,MAApB,CAA2BH,QAAQ,CAACE,aAAT,EAA3B,MAAyD,CAD1D,EAC6D;QAC5D,OAAOD,OAAP;MACA;IACD,CALD,CAMA;IACA;IAPA,KAQK,IAAIL,aAAa,CAAC;MAAEQ,KAAK,EAAEL,mBAAT;MAA8BE,OAAO,EAAPA;IAA9B,CAAD,EAA0CI,SAA1C,EAAqDL,QAAQ,CAACA,QAA9D,CAAjB,EAA0F;MAC9F,OAAOC,OAAP;IACA;EACD;AACD"}
1
+ {"version":3,"file":"getCountryByNationalNumber.js","names":["Metadata","getNumberType","getCountryByNationalNumber","nationalPhoneNumber","countries","defaultCountry","metadata","matchingCountries","country","leadingDigits","search","phone","undefined","push","length"],"sources":["../../source/helpers/getCountryByNationalNumber.js"],"sourcesContent":["import Metadata from '../metadata.js'\r\nimport getNumberType from './getNumberType.js'\r\n\r\nexport default function getCountryByNationalNumber(nationalPhoneNumber, { countries, defaultCountry, metadata }) {\r\n\t// Re-create `metadata` because it will be selecting a `country`.\r\n\tmetadata = new Metadata(metadata)\r\n\r\n\tconst matchingCountries = []\r\n\r\n\tfor (const country of countries) {\r\n\t\tmetadata.country(country)\r\n\t\t// \"Leading digits\" patterns are only defined for about 20% of all countries.\r\n\t\t// By definition, matching \"leading digits\" is a sufficient but not a necessary\r\n\t\t// condition for a phone number to belong to a country.\r\n\t\t// The point of \"leading digits\" check is that it's the fastest one to get a match.\r\n\t\t// https://gitlab.com/catamphetamine/libphonenumber-js/blob/master/METADATA.md#leading_digits\r\n\t\t// I'd suppose that \"leading digits\" patterns are mutually exclusive for different countries\r\n\t\t// because of the intended use of that feature.\r\n\t\tif (metadata.leadingDigits()) {\r\n\t\t\tif (nationalPhoneNumber &&\r\n\t\t\t\tnationalPhoneNumber.search(metadata.leadingDigits()) === 0) {\r\n\t\t\t\treturn country\r\n\t\t\t}\r\n\t\t}\r\n\t\t// Else perform full validation with all of those\r\n\t\t// fixed-line/mobile/etc regular expressions.\r\n\t\telse if (getNumberType({ phone: nationalPhoneNumber, country }, undefined, metadata.metadata)) {\r\n\t\t\t// If the `defaultCountry` is among the `matchingCountries` then return it.\r\n\t\t\tif (defaultCountry) {\r\n\t\t\t\tif (country === defaultCountry) {\r\n\t\t\t\t\treturn country\r\n\t\t\t\t}\r\n\t\t\t\tmatchingCountries.push(country)\r\n\t\t\t} else {\r\n\t\t\t\treturn country\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// Return the first (\"main\") one of the `matchingCountries`.\r\n\tif (matchingCountries.length > 0) {\r\n\t\treturn matchingCountries[0]\r\n\t}\r\n}"],"mappings":";;;;;;AAAA,OAAOA,QAAP,MAAqB,gBAArB;AACA,OAAOC,aAAP,MAA0B,oBAA1B;AAEA,eAAe,SAASC,0BAAT,CAAoCC,mBAApC,QAAkG;EAAA,IAAvCC,SAAuC,QAAvCA,SAAuC;EAAA,IAA5BC,cAA4B,QAA5BA,cAA4B;EAAA,IAAZC,QAAY,QAAZA,QAAY;EAChH;EACAA,QAAQ,GAAG,IAAIN,QAAJ,CAAaM,QAAb,CAAX;EAEA,IAAMC,iBAAiB,GAAG,EAA1B;;EAEA,qDAAsBH,SAAtB,wCAAiC;IAAA,IAAtBI,OAAsB;IAChCF,QAAQ,CAACE,OAAT,CAAiBA,OAAjB,EADgC,CAEhC;IACA;IACA;IACA;IACA;IACA;IACA;;IACA,IAAIF,QAAQ,CAACG,aAAT,EAAJ,EAA8B;MAC7B,IAAIN,mBAAmB,IACtBA,mBAAmB,CAACO,MAApB,CAA2BJ,QAAQ,CAACG,aAAT,EAA3B,MAAyD,CAD1D,EAC6D;QAC5D,OAAOD,OAAP;MACA;IACD,CALD,CAMA;IACA;IAPA,KAQK,IAAIP,aAAa,CAAC;MAAEU,KAAK,EAAER,mBAAT;MAA8BK,OAAO,EAAPA;IAA9B,CAAD,EAA0CI,SAA1C,EAAqDN,QAAQ,CAACA,QAA9D,CAAjB,EAA0F;MAC9F;MACA,IAAID,cAAJ,EAAoB;QACnB,IAAIG,OAAO,KAAKH,cAAhB,EAAgC;UAC/B,OAAOG,OAAP;QACA;;QACDD,iBAAiB,CAACM,IAAlB,CAAuBL,OAAvB;MACA,CALD,MAKO;QACN,OAAOA,OAAP;MACA;IACD;EACD,CAlC+G,CAoChH;;;EACA,IAAID,iBAAiB,CAACO,MAAlB,GAA2B,CAA/B,EAAkC;IACjC,OAAOP,iBAAiB,CAAC,CAAD,CAAxB;EACA;AACD"}
package/es6/parse.js CHANGED
@@ -336,7 +336,11 @@ function parsePhoneNumber(formattedPhoneNumber, defaultCountry, defaultCallingCo
336
336
  //
337
337
 
338
338
 
339
- var exactCountry = getCountryByCallingCode(countryCallingCode, nationalNumber, metadata);
339
+ var exactCountry = getCountryByCallingCode(countryCallingCode, {
340
+ nationalNumber: nationalNumber,
341
+ defaultCountry: defaultCountry,
342
+ metadata: metadata
343
+ });
340
344
 
341
345
  if (exactCountry) {
342
346
  country = exactCountry;