libphonenumber-js 1.10.23 → 1.10.26

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 (95) hide show
  1. package/CODE_OF_CONDUCT.md +78 -0
  2. package/README.md +16 -6
  3. package/build/PhoneNumber.js +6 -0
  4. package/build/PhoneNumber.js.map +1 -1
  5. package/build/PhoneNumberMatcher.js +53 -62
  6. package/build/PhoneNumberMatcher.js.map +1 -1
  7. package/build/PhoneNumberMatcher.test.js +8 -0
  8. package/build/PhoneNumberMatcher.test.js.map +1 -1
  9. package/build/findNumbers/Leniency.js +60 -50
  10. package/build/findNumbers/Leniency.js.map +1 -1
  11. package/build/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js +75 -0
  12. package/build/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js.map +1 -0
  13. package/build/format.js +1 -0
  14. package/build/format.js.map +1 -1
  15. package/build/helpers/RFC3966.test.js +3 -1
  16. package/build/helpers/RFC3966.test.js.map +1 -1
  17. package/build/helpers/extractCountryCallingCode.js +44 -4
  18. package/build/helpers/extractCountryCallingCode.js.map +1 -1
  19. package/build/helpers/extractCountryCallingCode.test.js +2 -0
  20. package/build/helpers/extractCountryCallingCode.test.js.map +1 -1
  21. package/build/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js +86 -0
  22. package/build/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js.map +1 -0
  23. package/build/helpers/extractPhoneContext.js +97 -0
  24. package/build/helpers/extractPhoneContext.js.map +1 -0
  25. package/build/helpers/extractPhoneContext.test.js +72 -0
  26. package/build/helpers/extractPhoneContext.test.js.map +1 -0
  27. package/build/parse.js +19 -9
  28. package/build/parse.js.map +1 -1
  29. package/bundle/libphonenumber-js.min.js +1 -1
  30. package/bundle/libphonenumber-js.min.js.map +1 -1
  31. package/bundle/libphonenumber-max.js +1 -1
  32. package/bundle/libphonenumber-max.js.map +1 -1
  33. package/bundle/libphonenumber-min.js +1 -1
  34. package/bundle/libphonenumber-min.js.map +1 -1
  35. package/bundle/libphonenumber-mobile.js +1 -1
  36. package/bundle/libphonenumber-mobile.js.map +1 -1
  37. package/core/index.d.ts +3 -3
  38. package/custom.d.ts +4 -4
  39. package/es6/PhoneNumber.js +6 -0
  40. package/es6/PhoneNumber.js.map +1 -1
  41. package/es6/PhoneNumberMatcher.js +53 -62
  42. package/es6/PhoneNumberMatcher.js.map +1 -1
  43. package/es6/PhoneNumberMatcher.test.js +8 -0
  44. package/es6/PhoneNumberMatcher.test.js.map +1 -1
  45. package/es6/findNumbers/Leniency.js +56 -50
  46. package/es6/findNumbers/Leniency.js.map +1 -1
  47. package/es6/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js +66 -0
  48. package/es6/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js.map +1 -0
  49. package/es6/format.js +1 -1
  50. package/es6/format.js.map +1 -1
  51. package/es6/helpers/RFC3966.test.js +3 -1
  52. package/es6/helpers/RFC3966.test.js.map +1 -1
  53. package/es6/helpers/extractCountryCallingCode.js +44 -4
  54. package/es6/helpers/extractCountryCallingCode.js.map +1 -1
  55. package/es6/helpers/extractCountryCallingCode.test.js +2 -0
  56. package/es6/helpers/extractCountryCallingCode.test.js.map +1 -1
  57. package/es6/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js +70 -0
  58. package/es6/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js.map +1 -0
  59. package/es6/helpers/extractPhoneContext.js +82 -0
  60. package/es6/helpers/extractPhoneContext.js.map +1 -0
  61. package/es6/helpers/extractPhoneContext.test.js +66 -0
  62. package/es6/helpers/extractPhoneContext.test.js.map +1 -0
  63. package/es6/parse.js +20 -10
  64. package/es6/parse.js.map +1 -1
  65. package/examples.mobile.json.d.ts +1 -1
  66. package/index.cjs.js +1 -1
  67. package/index.d.ts +3 -3
  68. package/metadata.full.json +1 -1
  69. package/metadata.full.json.d.ts +1 -1
  70. package/metadata.full.json.js +1 -1
  71. package/metadata.max.json +1 -1
  72. package/metadata.max.json.d.ts +1 -1
  73. package/metadata.max.json.js +1 -1
  74. package/metadata.min.json +1 -1
  75. package/metadata.min.json.d.ts +1 -1
  76. package/metadata.min.json.js +1 -1
  77. package/metadata.mobile.json +1 -1
  78. package/metadata.mobile.json.d.ts +1 -1
  79. package/metadata.mobile.json.js +1 -1
  80. package/min/index.d.ts +3 -3
  81. package/package.json +4 -4
  82. package/source/AsYouTypeFormatter.PatternMatcher.d.ts +1 -1
  83. package/source/PhoneNumber.js +6 -0
  84. package/source/PhoneNumberMatcher.js +55 -58
  85. package/source/PhoneNumberMatcher.test.js +4 -0
  86. package/source/findNumbers/Leniency.js +281 -271
  87. package/source/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js +64 -0
  88. package/source/format.js +1 -1
  89. package/source/helpers/RFC3966.test.js +3 -0
  90. package/source/helpers/extractCountryCallingCode.js +48 -3
  91. package/source/helpers/extractCountryCallingCode.test.js +2 -0
  92. package/source/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js +74 -0
  93. package/source/helpers/extractPhoneContext.js +103 -0
  94. package/source/helpers/extractPhoneContext.test.js +104 -0
  95. package/source/parse.js +18 -8
@@ -0,0 +1,78 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and free environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a censorship-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ education, socio-economic status, nationality, personal appearance, race,
10
+ religion, or sexual identity and orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating an open and free environment
15
+ include:
16
+
17
+ * Not constraining the language to be "welcoming" or "inclusive"
18
+ * Not demanding show of empathy towards other community members
19
+ * Not dictating anyone to be respectful of differing viewpoints and experiences
20
+ * Not forcing anyone to change their views or opinions regardless of those
21
+ * Not intimidating other people into accepting your own views or opinions
22
+ * Not blackmailing other people to disclose their personal views or opinions
23
+ * Not constraining other people from publishing their personal views or opinions in an unintrusive way
24
+ * Focusing on what is best for the ecosystem
25
+
26
+ Examples of acceptable behavior by participants include:
27
+
28
+ * The use of sexualized language
29
+ * Occasional trolling or insulting comments that are not completely off-topic
30
+
31
+ Examples of unacceptable behavior by participants include:
32
+
33
+ * Publishing others' private information, such as a physical or electronic address, without explicit permission
34
+ * Unwelcome sexual attention or advances
35
+ * Public harassment or personal attacks when carried out in an bold or intrusive way
36
+ * Private harassment
37
+ * Any actions that are in violation of the local laws or otherwise considered illegal
38
+ * Other conduct which could reasonably be considered inappropriate in an open and free setting
39
+
40
+ ## Our Responsibilities
41
+
42
+ Project maintainers are responsible for clarifying the standards of acceptable
43
+ behavior and are free to take appropriate and fair corrective action in
44
+ response to any instances of unacceptable behavior.
45
+
46
+ Project maintainers have the right and authority to remove, edit, or
47
+ reject comments, commits, code, wiki edits, issues, and other contributions
48
+ that are not aligned to this Code of Conduct, or to ban temporarily or
49
+ permanently any contributor for other behaviors that they deem inappropriate,
50
+ threatening, offensive, or harmful.
51
+
52
+ ## Scope
53
+
54
+ This Code of Conduct applies both within project spaces and in public spaces
55
+ when an individual is representing the project or its community. Examples of
56
+ representing a project or community include using an official project e-mail
57
+ address, posting via an official social media account, or acting as an appointed
58
+ representative at an online or offline event. Representation of a project may be
59
+ further defined and clarified by project maintainers.
60
+
61
+ ## Enforcement
62
+
63
+ Instances of unacceptable behavior may be reported by contacting the project team.
64
+ The complaints will likely be reviewed and investigated and may result in a response that
65
+ is deemed necessary and appropriate to the circumstances. The project team should maintain confidentiality with regard to the reporter of an incident.
66
+ Further details of specific enforcement policies may be posted separately.
67
+
68
+ Project maintainers who do not follow the Code of Conduct in good
69
+ faith may face temporary or permanent repercussions as determined by other
70
+ members of the project's leadership.
71
+
72
+ ## Attribution
73
+
74
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
75
+ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
76
+
77
+ [homepage]: https://www.contributor-covenant.org
78
+
package/README.md CHANGED
@@ -444,6 +444,11 @@ const phoneNumber = new PhoneNumber('RU', '8005553535', metadata)
444
444
  * `ext: string?` — The [phone number extension](https://en.wikipedia.org/wiki/Extension_(telephone)), if any. Example: `"1234"`.
445
445
  * `carrierCode: string?` — The ["carrier code"](https://www.voip-info.org/carrier-identification-codes/), if any. Example: `"15"`. "Carrier codes" are only used in Colombia and Brazil and only when dialing within those countries from a mobile phone to a fixed line number.
446
446
 
447
+ <!-- * `countryCallingCodeSource: string` — How the [country calling code](#country-calling-code) was obtained for this phone number. -->
448
+ <!-- * `FROM_NUMBER_WITH_PLUS_SIGN` — The country_code is derived based on a phone number with a leading "+", e.g. the French number "+33 1 42 68 53 00". -->
449
+ <!-- * `FROM_NUMBER_WITHOUT_PLUS_SIGN` — The country_code is derived based on a phone number without a leading "+", e.g. the French number "33 1 42 68 53 00" when defaultCountry is supplied as France. -->
450
+ <!-- * `FROM_DEFAULT_COUNTRY` — The country_code is derived NOT based on the phone number itself, but from the defaultCountry parameter provided in the parsing function by the clients. This happens mostly for numbers written in the national format (without country code). For example, this would be set when parsing the French number "01 42 68 53 00", when defaultCountry is supplied as France. -->
451
+
447
452
  `PhoneNumber` class instance provides the following methods:
448
453
 
449
454
  #### `setExt(ext: string)`
@@ -662,7 +667,7 @@ isPossiblePhoneNumber('8 (888) 888-88-88', 'RU') === true
662
667
  isPossiblePhoneNumber('+12223333333') === true
663
668
  ```
664
669
 
665
- For the description of the `defaultCountry?: string | options?: object` argument, see [`parsePhoneNumber()`](#parsephonenumberstring-defaultcountry-string-options-object-phonenumber) function description.
670
+ For the description of the `defaultCountry?: string | options?: object` argument, see [`parsePhoneNumber()`](#parsephonenumberstring-defaultcountry-string--options-object-phonenumber) function description.
666
671
 
667
672
  This function is just a shortcut for a two-step process of ["strictly"](#strictness) parsing a phone number and then calling `.isPossible()`.
668
673
 
@@ -677,7 +682,7 @@ isValidPhoneNumber('+12223333333') === false
677
682
  isValidPhoneNumber('+12133734253') === true
678
683
  ```
679
684
 
680
- For the description of the `defaultCountry?: string | options?: object` argument, see [`parsePhoneNumber()`](#parsephonenumberstring-defaultcountry-string-options-object-phonenumber) function description.
685
+ For the description of the `defaultCountry?: string | options?: object` argument, see [`parsePhoneNumber()`](#parsephonenumberstring-defaultcountry-string--options-object-phonenumber) function description.
681
686
 
682
687
  This function is just a shortcut for a two-step process of ["strictly"](#strictness) parsing a phone number and then calling `.isValid()`.
683
688
 
@@ -752,7 +757,7 @@ validatePhoneNumberLength('444 1 444444', 'TR') === undefined // Length is valid
752
757
  validatePhoneNumberLength('444 1 4444444444', 'TR') === 'TOO_LONG'
753
758
  ```
754
759
 
755
- For the description of the `defaultCountry?: string | options?: object` argument, see [`parsePhoneNumber()`](#parsephonenumberstring-defaultcountry-string-options-object-phonenumber) function description.
760
+ For the description of the `defaultCountry?: string | options?: object` argument, see [`parsePhoneNumber()`](#parsephonenumberstring-defaultcountry-string--options-object-phonenumber) function description.
756
761
 
757
762
  This function is just a more detailed version of `isPossiblePhoneNumber()` for those who've [asked](https://github.com/catamphetamine/libphonenumber-js/issues/406) for a more specific rejection reason.
758
763
 
@@ -764,7 +769,7 @@ The phone number is parsed ["strictly"](#strictness) from the input string.
764
769
 
765
770
  Creates a formatter for a partially entered phone number.
766
771
 
767
- For the description of the `defaultCountry?: string | options?: object` argument, see [`parsePhoneNumber()`](#parsephonenumberstring-defaultcountry-string-options-object-phonenumber) function description.
772
+ For the description of the `defaultCountry?: string | options?: object` argument, see [`parsePhoneNumber()`](#parsephonenumberstring-defaultcountry-string--options-object-phonenumber) function description.
768
773
 
769
774
  The formatter instance has the following methods:
770
775
 
@@ -881,7 +886,12 @@ Google's "As You Type" formatter does not support entering phone number extensio
881
886
 
882
887
  Searches for phone numbers in `text`.
883
888
 
884
- For the description of the `defaultCountry?: string | options?: object` argument, see [`parsePhoneNumber()`](#parsephonenumberstring-defaultcountry-string-options-object-phonenumber) function description.
889
+ Available `options`:
890
+
891
+ * `defaultCountry: string`
892
+ * `defaultCallingCode: string`
893
+
894
+ For the description of `defaultCountry` or `defaultCallingCode`, see [`parsePhoneNumber()`](#parsephonenumberstring-defaultcountry-string--options-object-phonenumber) function description.
885
895
 
886
896
  ```js
887
897
  import { findPhoneNumbersInText } from 'libphonenumber-js'
@@ -1787,7 +1797,7 @@ Also Google sometimes (very rarely) updates their code:
1787
1797
  * [`AsYouTypeFormatter.java`](https://github.com/google/libphonenumber/blob/master/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java) — `AsYouType`
1788
1798
  * [`PhoneNumberMatcher.java`](https://github.com/googlei18n/libphonenumber/blob/master/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberMatcher.java) — `findPhoneNumbersInText()`
1789
1799
 
1790
- The latest sync-up was on April 24th, 2022.
1800
+ The latest sync-up was on Mar 15th, 2023.
1791
1801
 
1792
1802
  ## Contributing
1793
1803
 
@@ -34,6 +34,12 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
34
34
  var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;
35
35
 
36
36
  var PhoneNumber = /*#__PURE__*/function () {
37
+ /**
38
+ * @param {string} countryOrCountryCallingCode
39
+ * @param {string} nationalNumber
40
+ * @param {object} metadata — Metadata JSON
41
+ * @return {PhoneNumber}
42
+ */
37
43
  function PhoneNumber(countryOrCountryCallingCode, nationalNumber, metadata) {
38
44
  _classCallCheck(this, PhoneNumber);
39
45
 
@@ -1 +1 @@
1
- {"version":3,"file":"PhoneNumber.js","names":["USE_NON_GEOGRAPHIC_COUNTRY_CODE","PhoneNumber","countryOrCountryCallingCode","nationalNumber","metadata","TypeError","getCountryAndCountryCallingCode","country","countryCallingCode","number","ext","getPossibleCountriesForNumber","isPossibleNumber","v2","isValidNumber","Metadata","isNonGeographicCallingCode","phoneNumber","getNumberType","format","options","formatNumber","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\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;;AACA;;AACA;;AAEA;;AACA;;AACA;;;;;;;;;;;;;;;;AAEA,IAAMA,+BAA+B,GAAG,KAAxC;;IAEqBC,W;EACpB,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;;IAIA,KAAKD,OAAL,GAAeA,OAAf;IACA,KAAKC,kBAAL,GAA0BA,kBAA1B;IACA,KAAKL,cAAL,GAAsBA,cAAtB;IACA,KAAKM,MAAL,GAAc,MAAM,KAAKD,kBAAX,GAAgC,KAAKL,cAAnD;IACA,KAAKC,QAAL,GAAgBA,QAAhB;EACA;;;;WAED,gBAAOM,GAAP,EAAY;MACX,KAAKA,GAAL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xB,CAAP;IACA;;;WAED,6BAAoBA,OAApB,EAA6B;MAC5B,OAAO,KAAKD,MAAL,CAAY,eAAZ,EAA6BC,OAA7B,CAAP;IACA;;;WAED,gBAAOA,OAAP,EAAgB;MACf,OAAO,KAAKD,MAAL,CAAY,SAAZ,EAAuBC,OAAvB,CAAP;IACA;;;;;;;;AAGF,IAAME,aAAa,GAAG,SAAhBA,aAAgB,CAACC,KAAD;EAAA,OAAW,aAAaC,IAAb,CAAkBD,KAAlB,CAAX;AAAA,CAAtB;;AAEA,SAASjB,+BAAT,CAAyCJ,2BAAzC,EAAsEuB,YAAtE,EAAoF;EACnF,IAAIlB,OAAJ;EACA,IAAIC,kBAAJ;EAEA,IAAMJ,QAAQ,GAAG,IAAIW,oBAAJ,CAAaU,YAAb,CAAjB,CAJmF,CAKnF;EACA;;EACA,IAAIH,aAAa,CAACpB,2BAAD,CAAjB,EAAgD;IAC/CK,OAAO,GAAGL,2BAAV;IACAE,QAAQ,CAACsB,mBAAT,CAA6BnB,OAA7B;IACAC,kBAAkB,GAAGJ,QAAQ,CAACI,kBAAT,EAArB;EACA,CAJD,MAIO;IACNA,kBAAkB,GAAGN,2BAArB;IACA;;IACA,IAAIF,+BAAJ,EAAqC;MACpC,IAAII,QAAQ,CAACY,0BAAT,CAAoCR,kBAApC,CAAJ,EAA6D;QAC5DD,OAAO,GAAG,KAAV;MACA;IACD;EACD;;EAED,OAAO;IACNA,OAAO,EAAPA,OADM;IAENC,kBAAkB,EAAlBA;EAFM,CAAP;AAIA"}
1
+ {"version":3,"file":"PhoneNumber.js","names":["USE_NON_GEOGRAPHIC_COUNTRY_CODE","PhoneNumber","countryOrCountryCallingCode","nationalNumber","metadata","TypeError","getCountryAndCountryCallingCode","country","countryCallingCode","number","ext","getPossibleCountriesForNumber","isPossibleNumber","v2","isValidNumber","Metadata","isNonGeographicCallingCode","phoneNumber","getNumberType","format","options","formatNumber","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;;AACA;;AACA;;AAEA;;AACA;;AACA;;;;;;;;;;;;;;;;AAEA,IAAMA,+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;;IAIA,KAAKD,OAAL,GAAeA,OAAf;IACA,KAAKC,kBAAL,GAA0BA,kBAA1B;IACA,KAAKL,cAAL,GAAsBA,cAAtB;IACA,KAAKM,MAAL,GAAc,MAA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AAN,CAH/B,EAIN,KAAKT,QAJC,CAAP;IAMA;;;WAED,wBAAegB,OAAf,EAAwB;MACvB,OAAO,KAAKD,MAAL,CAAY,UAAZ,EAAwBC,OAAxB,CAAP;IACA;;;WAED,6BAAoBA,OAApB,EAA6B;MAC5B,OAAO,KAAKD,MAAL,CAAY,eAAZ,EAA6BC,OAA7B,CAAP;IACA;;;WAED,gBAAOA,OAAP,EAAgB;MACf,OAAO,KAAKD,MAAL,CAAY,SAAZ,EAAuBC,OAAvB,CAAP;IACA;;;;;;;;AAGF,IAAME,aAAa,GAAG,SAAhBA,aAAgB,CAACC,KAAD;EAAA,OAAW,aAAaC,IAAb,CAAkBD,KAAlB,CAAX;AAAA,CAAtB;;AAEA,SAASjB,+BAAT,CAAyCJ,2BAAzC,EAAsEuB,YAAtE,EAAoF;EACnF,IAAIlB,OAAJ;EACA,IAAIC,kBAAJ;EAEA,IAAMJ,QAAQ,GAAG,IAAIW,oBAAJ,CAAaU,YAAb,CAAjB,CAJmF,CAKnF;EACA;;EACA,IAAIH,aAAa,CAACpB,2BAAD,CAAjB,EAAgD;IAC/CK,OAAO,GAAGL,2BAAV;IACAE,QAAQ,CAACsB,mBAAT,CAA6BnB,OAA7B;IACAC,kBAAkB,GAAGJ,QAAQ,CAACI,kBAAT,EAArB;EACA,CAJD,MAIO;IACNA,kBAAkB,GAAGN,2BAArB;IACA;;IACA,IAAIF,+BAAJ,EAAqC;MACpC,IAAII,QAAQ,CAACY,0BAAT,CAAoCR,kBAApC,CAAJ,EAA6D;QAC5DD,OAAO,GAAG,KAAV;MACA;IACD;EACD;;EAED,OAAO;IACNA,OAAO,EAAPA,OADM;IAENC,kBAAkB,EAAlBA;EAFM,CAAP;AAIA"}
@@ -29,7 +29,7 @@ var _isValidCandidate = _interopRequireWildcard(require("./findNumbers/isValidCa
29
29
 
30
30
  var _metadata = require("./metadata.js");
31
31
 
32
- var _parse = _interopRequireDefault(require("./parse.js"));
32
+ var _parsePhoneNumber = _interopRequireDefault(require("./parsePhoneNumber.js"));
33
33
 
34
34
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
35
35
 
@@ -43,18 +43,13 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
43
43
 
44
44
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
45
45
 
46
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
47
-
48
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
49
-
50
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
51
-
52
46
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
53
47
 
54
48
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
55
49
 
56
50
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
57
51
 
52
+ var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;
58
53
  var EXTN_PATTERNS_FOR_MATCHING = (0, _createExtensionPattern["default"])('matching');
59
54
  /**
60
55
  * Patterns used to extract phone numbers from a larger phone-number-like pattern. These are
@@ -137,19 +132,9 @@ var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1;
137
132
 
138
133
  var PhoneNumberMatcher = /*#__PURE__*/function () {
139
134
  /**
140
- * Creates a new instance. See the factory methods in {@link PhoneNumberUtil} on how to obtain a
141
- * new instance.
142
- *
143
- * @param util the phone number util to use
144
- * @param text the character sequence that we will search, null for no text
145
- * @param country the country to assume for phone numbers not written in international format
146
- * (with a leading plus, or with the international dialing prefix of the specified region).
147
- * May be null or "ZZ" if only numbers with a leading plus should be
148
- * considered.
149
- * @param leniency the leniency to use when evaluating candidate phone numbers
150
- * @param maxTries the maximum number of invalid numbers to try before giving up on the text.
151
- * This is to cover degenerate cases where the text has a lot of false positives in it. Must
152
- * be {@code >= 0}.
135
+ * @param {string} text — the character sequence that we will search, null for no text.
136
+ * @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.
137
+ * @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.
153
138
  */
154
139
  function PhoneNumberMatcher() {
155
140
  var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
@@ -158,30 +143,35 @@ var PhoneNumberMatcher = /*#__PURE__*/function () {
158
143
 
159
144
  _classCallCheck(this, PhoneNumberMatcher);
160
145
 
161
- options = _objectSpread(_objectSpread({}, options), {}, {
146
+ options = {
147
+ v2: options.v2,
162
148
  defaultCallingCode: options.defaultCallingCode,
163
149
  defaultCountry: options.defaultCountry && (0, _metadata.isSupportedCountry)(options.defaultCountry, metadata) ? options.defaultCountry : undefined,
164
- leniency: options.leniency || options.extended ? 'POSSIBLE' : 'VALID',
150
+ leniency: options.leniency || (options.extended ? 'POSSIBLE' : 'VALID'),
165
151
  maxTries: options.maxTries || MAX_SAFE_INTEGER
166
- });
152
+ }; // Validate `leniency`.
167
153
 
168
154
  if (!options.leniency) {
169
- throw new TypeError('`Leniency` not supplied');
155
+ throw new TypeError('`leniency` is required');
170
156
  }
171
157
 
158
+ if (options.leniency !== 'POSSIBLE' && options.leniency !== 'VALID') {
159
+ throw new TypeError("Invalid `leniency`: \"".concat(options.leniency, "\". Supported values: \"POSSIBLE\", \"VALID\"."));
160
+ } // Validate `maxTries`.
161
+
162
+
172
163
  if (options.maxTries < 0) {
173
- throw new TypeError('`maxTries` not supplied');
164
+ throw new TypeError('`maxTries` must be `>= 0`');
174
165
  }
175
166
 
176
167
  this.text = text;
177
168
  this.options = options;
178
- this.metadata = metadata;
179
- /** The degree of validation requested. */
169
+ this.metadata = metadata; // The degree of phone number validation.
180
170
 
181
171
  this.leniency = _Leniency["default"][options.leniency];
182
172
 
183
173
  if (!this.leniency) {
184
- throw new TypeError("Unknown leniency: ".concat(options.leniency, "."));
174
+ throw new TypeError("Unknown leniency: \"".concat(options.leniency, "\""));
185
175
  }
186
176
  /** The maximum number of retries after matching an invalid number. */
187
177
 
@@ -229,20 +219,36 @@ var PhoneNumberMatcher = /*#__PURE__*/function () {
229
219
 
230
220
  if (match) {
231
221
  if (this.options.v2) {
232
- var phoneNumber = new _PhoneNumber["default"](match.country || match.countryCallingCode, match.phone, this.metadata);
233
-
234
- if (match.ext) {
235
- phoneNumber.ext = match.ext;
236
- }
237
-
238
222
  return {
239
223
  startsAt: match.startsAt,
240
224
  endsAt: match.endsAt,
241
- number: phoneNumber
225
+ number: match.phoneNumber
226
+ };
227
+ } else {
228
+ var phoneNumber = match.phoneNumber;
229
+ var result = {
230
+ startsAt: match.startsAt,
231
+ endsAt: match.endsAt,
232
+ phone: phoneNumber.nationalNumber
242
233
  };
243
- }
244
234
 
245
- return match;
235
+ if (phoneNumber.country) {
236
+ /* istanbul ignore if */
237
+ if (USE_NON_GEOGRAPHIC_COUNTRY_CODE && country === '001') {
238
+ result.countryCallingCode = phoneNumber.countryCallingCode;
239
+ } else {
240
+ result.country = phoneNumber.country;
241
+ }
242
+ } else {
243
+ result.countryCallingCode = phoneNumber.countryCallingCode;
244
+ }
245
+
246
+ if (phoneNumber.ext) {
247
+ result.ext = phoneNumber.ext;
248
+ }
249
+
250
+ return result;
251
+ }
246
252
  }
247
253
  }
248
254
 
@@ -296,7 +302,7 @@ var PhoneNumberMatcher = /*#__PURE__*/function () {
296
302
  }
297
303
  }
298
304
  /**
299
- * Parses a phone number from the `candidate` using `parseNumber` and
305
+ * Parses a phone number from the `candidate` using `parse` and
300
306
  * verifies it matches the requested `leniency`. If parsing and verification succeed,
301
307
  * a corresponding `PhoneNumberMatch` is returned, otherwise this method returns `null`.
302
308
  *
@@ -312,41 +318,26 @@ var PhoneNumberMatcher = /*#__PURE__*/function () {
312
318
  return;
313
319
  }
314
320
 
315
- var number = (0, _parse["default"])(candidate, {
321
+ var phoneNumber = (0, _parsePhoneNumber["default"])(candidate, {
316
322
  extended: true,
317
323
  defaultCountry: this.options.defaultCountry,
318
324
  defaultCallingCode: this.options.defaultCallingCode
319
325
  }, this.metadata);
320
326
 
321
- if (!number.possible) {
327
+ if (!phoneNumber) {
328
+ return;
329
+ }
330
+
331
+ if (!phoneNumber.isPossible()) {
322
332
  return;
323
333
  }
324
334
 
325
- if (this.leniency(number, candidate, this.metadata, this.regExpCache)) {
326
- // // We used parseAndKeepRawInput to create this number,
327
- // // but for now we don't return the extra values parsed.
328
- // // TODO: stop clearing all values here and switch all users over
329
- // // to using rawInput() rather than the rawString() of PhoneNumberMatch.
330
- // number.clearCountryCodeSource()
331
- // number.clearRawInput()
332
- // number.clearPreferredDomesticCarrierCode()
333
- var result = {
335
+ if (this.leniency(phoneNumber, candidate, this.metadata, this.regExpCache)) {
336
+ return {
334
337
  startsAt: offset,
335
338
  endsAt: offset + candidate.length,
336
- phone: number.phone
339
+ phoneNumber: phoneNumber
337
340
  };
338
-
339
- if (number.country && number.country !== '001') {
340
- result.country = number.country;
341
- } else {
342
- result.countryCallingCode = number.countryCallingCode;
343
- }
344
-
345
- if (number.ext) {
346
- result.ext = number.ext;
347
- }
348
-
349
- return result;
350
341
  }
351
342
  }
352
343
  }, {
@@ -1 +1 @@
1
- {"version":3,"file":"PhoneNumberMatcher.js","names":["EXTN_PATTERNS_FOR_MATCHING","createExtensionPattern","INNER_MATCHES","pZ","PZ","leadLimit","limit","punctuationLimit","digitBlockLimit","MAX_LENGTH_FOR_NSN","MAX_LENGTH_COUNTRY_CODE","blockLimit","punctuation","VALID_PUNCTUATION","digitSequence","pNd","PATTERN","LEAD_CLASS","UNWANTED_END_CHAR_PATTERN","RegExp","_pN","_pL","NON_DIGITS_PATTERN","MAX_SAFE_INTEGER","Number","Math","pow","PhoneNumberMatcher","text","options","metadata","defaultCallingCode","defaultCountry","isSupportedCountry","undefined","leniency","extended","maxTries","TypeError","Leniency","state","searchIndex","regExpCache","RegExpCache","matches","exec","candidate","offset","index","parsePreCandidate","isValidPreCandidate","match","parseAndVerify","extractInnerMatch","v2","phoneNumber","PhoneNumber","country","countryCallingCode","phone","ext","startsAt","endsAt","number","substring","innerMatchPattern","isFirstMatch","candidateMatch","innerMatchRegExp","trimAfterFirstMatch","slice","candidateIndexGuess","indexOf","isValidCandidate","parseNumber","possible","result","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 parseNumber from './parse.js'\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 * Creates a new instance. See the factory methods in {@link PhoneNumberUtil} on how to obtain a\r\n * new instance.\r\n *\r\n * @param util the phone number util to use\r\n * @param text the character sequence that we will search, null for no text\r\n * @param country the country to assume for phone numbers not written in international format\r\n * (with a leading plus, or with the international dialing prefix of the specified region).\r\n * May be null or \"ZZ\" if only numbers with a leading plus should be\r\n * considered.\r\n * @param leniency the leniency to use when evaluating candidate phone numbers\r\n * @param maxTries the maximum number of invalid numbers to try before giving up on the text.\r\n * This is to cover degenerate cases where the text has a lot of false positives in it. Must\r\n * be {@code >= 0}.\r\n */\r\n constructor(text = '', options = {}, metadata)\r\n {\r\n options = {\r\n ...options,\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\t\tif (!options.leniency) {\r\n\t\t\tthrow new TypeError('`Leniency` not supplied')\r\n\t\t}\r\n\r\n\t\tif (options.maxTries < 0) {\r\n\t\t\tthrow new TypeError('`maxTries` not supplied')\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 validation requested. */\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\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\tconst phoneNumber = new PhoneNumber(\r\n match.country || match.countryCallingCode,\r\n match.phone,\r\n this.metadata\r\n )\r\n\t\t\t\t\t\tif (match.ext) {\r\n\t\t\t\t\t\t\tphoneNumber.ext = match.ext\r\n\t\t\t\t\t\t}\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: phoneNumber\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn match\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 `parseNumber` 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 number = parseNumber(\r\n candidate, {\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 (!number.possible) {\r\n return\r\n }\r\n\r\n if (this.leniency(number, candidate, this.metadata, this.regExpCache)) {\r\n // // We used parseAndKeepRawInput to create this number,\r\n // // but for now we don't return the extra values parsed.\r\n // // TODO: stop clearing all values here and switch all users over\r\n // // to using rawInput() rather than the rawString() of PhoneNumberMatch.\r\n // number.clearCountryCodeSource()\r\n // number.clearRawInput()\r\n // number.clearPreferredDomesticCarrierCode()\r\n\r\n const result = {\r\n startsAt: offset,\r\n endsAt: offset + candidate.length,\r\n phone: number.phone\r\n }\r\n\r\n if (number.country && number.country !== '001') {\r\n result.country = number.country\r\n } else {\r\n result.countryCallingCode = number.countryCallingCode\r\n }\r\n\r\n if (number.ext) {\r\n result.ext = number.ext\r\n }\r\n\r\n return result\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":";;;;;;;;;AAMA;;AAEA;;AAMA;;AAEA;;AAEA;;AAKA;;AAQA;;AACA;;AACA;;AACA;;AAEA;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAMA,0BAA0B,GAAG,IAAAC,kCAAA,EAAuB,UAAvB,CAAnC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,IAAMC,aAAa,GACnB,CACC;AACA,WAFD,EAIC;AACA;AACA,YAND,EAQC;AACA;AATD,aAUOC,OAVP,gBAUeA,OAVf,cAUqBA,OAVrB,YAYC;AACA;AACA;AAdD,+BAeyBA,OAfzB,YAiBC;AAjBD,cAkBQA,OAlBR,eAoBC;AApBD,UAqBIA,OArBJ,eAqBWC,OArBX,QADA,C,CAyBA;;AACA,IAAMC,SAAS,GAAG,IAAAC,WAAA,EAAM,CAAN,EAAS,CAAT,CAAlB,C,CAEA;;AACA,IAAMC,gBAAgB,GAAG,IAAAD,WAAA,EAAM,CAAN,EAAS,CAAT,CAAzB;AAEA;AACA;AACA;;AACA,IAAME,eAAe,GAAG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;;MACA,IAAML,MAAM,GAAG,KAAKE,SAApB;MACA,KAAKA,SAAL,GAAiB,IAAjB;MACA,KAAKtC,KAAL,GAAa,WAAb;MACA,OAAOoC,MAAP;IACD"}
1
+ {"version":3,"file":"PhoneNumberMatcher.js","names":["USE_NON_GEOGRAPHIC_COUNTRY_CODE","EXTN_PATTERNS_FOR_MATCHING","createExtensionPattern","INNER_MATCHES","pZ","PZ","leadLimit","limit","punctuationLimit","digitBlockLimit","MAX_LENGTH_FOR_NSN","MAX_LENGTH_COUNTRY_CODE","blockLimit","punctuation","VALID_PUNCTUATION","digitSequence","pNd","PATTERN","LEAD_CLASS","UNWANTED_END_CHAR_PATTERN","RegExp","_pN","_pL","NON_DIGITS_PATTERN","MAX_SAFE_INTEGER","Number","Math","pow","PhoneNumberMatcher","text","options","metadata","v2","defaultCallingCode","defaultCountry","isSupportedCountry","undefined","leniency","extended","maxTries","TypeError","Leniency","state","searchIndex","regExpCache","RegExpCache","matches","exec","candidate","offset","index","parsePreCandidate","isValidPreCandidate","match","parseAndVerify","extractInnerMatch","startsAt","endsAt","number","phoneNumber","result","phone","nationalNumber","country","countryCallingCode","ext","substring","innerMatchPattern","isFirstMatch","candidateMatch","innerMatchRegExp","trimAfterFirstMatch","slice","candidateIndexGuess","indexOf","isValidCandidate","parsePhoneNumber","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":";;;;;;;;;AAMA;;AAEA;;AAMA;;AAEA;;AAEA;;AAKA;;AAQA;;AACA;;AACA;;AACA;;AAEA;;AAEA;;;;;;;;;;;;;;;;;;;;AAEA,IAAMA,+BAA+B,GAAG,KAAxC;AAEA,IAAMC,0BAA0B,GAAG,IAAAC,kCAAA,EAAuB,UAAvB,CAAnC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,IAAMC,aAAa,GACnB,CACC;AACA,WAFD,EAIC;AACA;AACA,YAND,EAQC;AACA;AATD,aAUOC,OAVP,gBAUeA,OAVf,cAUqBA,OAVrB,YAYC;AACA;AACA;AAdD,+BAeyBA,OAfzB,YAiBC;AAjBD,cAkBQA,OAlBR,eAoBC;AApBD,UAqBIA,OArBJ,eAqBWC,OArBX,QADA,C,CAyBA;;AACA,IAAMC,SAAS,GAAG,IAAAC,WAAA,EAAM,CAAN,EAAS,CAAT,CAAlB,C,CAEA;;AACA,IAAMC,gBAAgB,GAAG,IAAAD,WAAA,EAAM,CAAN,EAAS,CAAT,CAAzB;AAEA;AACA;AACA;;AACA,IAAME,eAAe,GAAGC,6BAAA,GAAqBC,kCAA7C,C,CAEA;AACA;;AACA,IAAMC,UAAU,GAAG,IAAAL,WAAA,EAAM,CAAN,EAASE,eAAT,CAAnB;AAEA;;AACA,IAAMI,WAAW,GAAG,WAAIC,4BAAJ,SAA2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CAAC,KAAKuC,OAAL,EAAL,EACA;QACE,MAAM,IAAIC,KAAJ,CAAU,iBAAV,CAAN;MACD,CALH,CAOE;;;MACA,IAAMtB,MAAM,GAAG,KAAKmB,SAApB;MACA,KAAKA,SAAL,GAAiB,IAAjB;MACA,KAAKrC,KAAL,GAAa,WAAb;MACA,OAAOkB,MAAP;IACD"}
@@ -75,5 +75,13 @@ describe('PhoneNumberMatcher', function () {
75
75
  test('+54 23 1234 0000', 'AR', '2312340000');
76
76
  test('023 1234 0000', 'AR', '2312340000');
77
77
  });
78
+ it('should only support the supported leniency values', function () {
79
+ expect(function () {
80
+ return new _PhoneNumberMatcher["default"]('+54 23 1234 0000', {
81
+ leniency: 'STRICT_GROUPING',
82
+ v2: true
83
+ }, _metadataMin["default"]);
84
+ }).to["throw"]('Supported values: "POSSIBLE", "VALID".');
85
+ });
78
86
  });
79
87
  //# sourceMappingURL=PhoneNumberMatcher.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PhoneNumberMatcher.test.js","names":["test","text","defaultCountry","expectedNumbers","nationalNumber","matcher","PhoneNumberMatcher","v2","metadata","hasNext","number","next","phoneNumber","shift","startsAt","undefined","should","equal","endsAt","country","length","describe","it"],"sources":["../source/PhoneNumberMatcher.test.js"],"sourcesContent":["import PhoneNumberMatcher from './PhoneNumberMatcher.js'\r\nimport metadata from '../metadata.min.json' assert { type: 'json' }\r\n\r\nfunction test(text, defaultCountry, expectedNumbers) {\r\n\tif (typeof expectedNumbers === 'string') {\r\n\t\texpectedNumbers = [{\r\n\t\t\tnationalNumber: expectedNumbers\r\n\t\t}]\r\n\t}\r\n\tconst matcher = new PhoneNumberMatcher(text, { defaultCountry, v2: true }, metadata)\r\n\twhile (matcher.hasNext()) {\r\n\t\tconst number = matcher.next()\r\n\t\tconst phoneNumber = expectedNumbers.shift()\r\n\t\tif (phoneNumber.startsAt !== undefined) {\r\n\t\t\tnumber.startsAt.should.equal(phoneNumber.startsAt)\r\n\t\t}\r\n\t\tif (phoneNumber.endsAt !== undefined) {\r\n\t\t\tnumber.endsAt.should.equal(phoneNumber.endsAt)\r\n\t\t}\r\n\t\tnumber.number.country.should.equal(phoneNumber.country || defaultCountry)\r\n\t\tnumber.number.nationalNumber.should.equal(phoneNumber.nationalNumber)\r\n\t}\r\n\texpectedNumbers.length.should.equal(0)\r\n}\r\n\r\ndescribe('PhoneNumberMatcher', () => {\r\n\tit('should find phone numbers', () => {\r\n\t\ttest(\r\n\t\t\t'The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.',\r\n\t\t\t'US',\r\n\t\t\t[{\r\n\t\t\t\tcountry: 'RU',\r\n\t\t\t\tnationalNumber: '8005553535',\r\n\t\t\t\tstartsAt: 14,\r\n\t\t\t\tendsAt: 32\r\n\t\t\t}, {\r\n\t\t\t\tcountry: 'US',\r\n\t\t\t\tnationalNumber: '2133734253',\r\n\t\t\t\tstartsAt: 41,\r\n\t\t\t\tendsAt: 55\r\n\t\t\t}]\r\n\t\t)\r\n\t})\r\n\r\n\tit('should find phone numbers from Mexico', () => {\r\n\t\t// Test parsing fixed-line numbers of Mexico.\r\n\t\ttest('+52 (449)978-0001', 'MX', '4499780001')\r\n\t\ttest('01 (449)978-0001', 'MX', '4499780001')\r\n\t\ttest('(449)978-0001', 'MX', '4499780001')\r\n\t\t// Test parsing mobile numbers of Mexico.\r\n\t\ttest('+52 1 33 1234-5678', 'MX', '3312345678')\r\n\t\ttest('044 (33) 1234-5678', 'MX', '3312345678')\r\n\t\ttest('045 33 1234-5678', 'MX', '3312345678')\r\n\t})\r\n\r\n\tit('should find phone numbers from Argentina', () => {\r\n\t\t// Test parsing mobile numbers of Argentina.\r\n\t\ttest('+54 9 343 555 1212', 'AR', '93435551212')\r\n\t\ttest('0343 15-555-1212', 'AR', '93435551212')\r\n\r\n\t\ttest('+54 9 3715 65 4320', 'AR', '93715654320')\r\n\t\ttest('03715 15 65 4320', 'AR', '93715654320')\r\n\r\n\t\t// Test parsing fixed-line numbers of Argentina.\r\n\t\ttest('+54 11 3797 0000', 'AR', '1137970000')\r\n\t\ttest('011 3797 0000', 'AR', '1137970000')\r\n\r\n\t\ttest('+54 3715 65 4321', 'AR', '3715654321')\r\n\t\ttest('03715 65 4321', 'AR', '3715654321')\r\n\r\n\t\ttest('+54 23 1234 0000', 'AR', '2312340000')\r\n\t\ttest('023 1234 0000', 'AR', '2312340000')\r\n\t})\r\n})"],"mappings":";;AAAA;;AACA;;;;AAEA,SAASA,IAAT,CAAcC,IAAd,EAAoBC,cAApB,EAAoCC,eAApC,EAAqD;EACpD,IAAI,OAAOA,eAAP,KAA2B,QAA/B,EAAyC;IACxCA,eAAe,GAAG,CAAC;MAClBC,cAAc,EAAED;IADE,CAAD,CAAlB;EAGA;;EACD,IAAME,OAAO,GAAG,IAAIC,8BAAJ,CAAuBL,IAAvB,EAA6B;IAAEC,cAAc,EAAdA,cAAF;IAAkBK,EAAE,EAAE;EAAtB,CAA7B,EAA2DC,uBAA3D,CAAhB;;EACA,OAAOH,OAAO,CAACI,OAAR,EAAP,EAA0B;IACzB,IAAMC,MAAM,GAAGL,OAAO,CAACM,IAAR,EAAf;IACA,IAAMC,WAAW,GAAGT,eAAe,CAACU,KAAhB,EAApB;;IACA,IAAID,WAAW,CAACE,QAAZ,KAAyBC,SAA7B,EAAwC;MACvCL,MAAM,CAACI,QAAP,CAAgBE,MAAhB,CAAuBC,KAAvB,CAA6BL,WAAW,CAACE,QAAzC;IACA;;IACD,IAAIF,WAAW,CAACM,MAAZ,KAAuBH,SAA3B,EAAsC;MACrCL,MAAM,CAACQ,MAAP,CAAcF,MAAd,CAAqBC,KAArB,CAA2BL,WAAW,CAACM,MAAvC;IACA;;IACDR,MAAM,CAACA,MAAP,CAAcS,OAAd,CAAsBH,MAAtB,CAA6BC,KAA7B,CAAmCL,WAAW,CAACO,OAAZ,IAAuBjB,cAA1D;IACAQ,MAAM,CAACA,MAAP,CAAcN,cAAd,CAA6BY,MAA7B,CAAoCC,KAApC,CAA0CL,WA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;IACAA,IAAI,CAAC,kBAAD,EAAqB,IAArB,EAA2B,YAA3B,CAAJ;IACAA,IAAI,CAAC,eAAD,EAAkB,IAAlB,EAAwB,YAAxB,CAAJ;IAEAA,IAAI,CAAC,kBAAD,EAAqB,IAArB,EAA2B,YAA3B,CAAJ;IACAA,IAAI,CAAC,eAAD,EAAkB,IAAlB,EAAwB,YAAxB,CAAJ;IAEAA,IAAI,CAAC,kBAAD,EAAqB,IAArB,EAA2B,YAA3B,CAAJ;IACAA,IAAI,CAAC,eAAD,EAAkB,IAAlB,EAAwB,YAAxB,CAAJ;EACA,CAjBC,CAAF;AAkBA,CAhDO,CAAR"}
1
+ {"version":3,"file":"PhoneNumberMatcher.test.js","names":["test","text","defaultCountry","expectedNumbers","nationalNumber","matcher","PhoneNumberMatcher","v2","metadata","hasNext","number","next","phoneNumber","shift","startsAt","undefined","should","equal","endsAt","country","length","describe","it","expect","leniency","to"],"sources":["../source/PhoneNumberMatcher.test.js"],"sourcesContent":["import PhoneNumberMatcher from './PhoneNumberMatcher.js'\r\nimport metadata from '../metadata.min.json' assert { type: 'json' }\r\n\r\nfunction test(text, defaultCountry, expectedNumbers) {\r\n\tif (typeof expectedNumbers === 'string') {\r\n\t\texpectedNumbers = [{\r\n\t\t\tnationalNumber: expectedNumbers\r\n\t\t}]\r\n\t}\r\n\tconst matcher = new PhoneNumberMatcher(text, { defaultCountry, v2: true }, metadata)\r\n\twhile (matcher.hasNext()) {\r\n\t\tconst number = matcher.next()\r\n\t\tconst phoneNumber = expectedNumbers.shift()\r\n\t\tif (phoneNumber.startsAt !== undefined) {\r\n\t\t\tnumber.startsAt.should.equal(phoneNumber.startsAt)\r\n\t\t}\r\n\t\tif (phoneNumber.endsAt !== undefined) {\r\n\t\t\tnumber.endsAt.should.equal(phoneNumber.endsAt)\r\n\t\t}\r\n\t\tnumber.number.country.should.equal(phoneNumber.country || defaultCountry)\r\n\t\tnumber.number.nationalNumber.should.equal(phoneNumber.nationalNumber)\r\n\t}\r\n\texpectedNumbers.length.should.equal(0)\r\n}\r\n\r\ndescribe('PhoneNumberMatcher', () => {\r\n\tit('should find phone numbers', () => {\r\n\t\ttest(\r\n\t\t\t'The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.',\r\n\t\t\t'US',\r\n\t\t\t[{\r\n\t\t\t\tcountry: 'RU',\r\n\t\t\t\tnationalNumber: '8005553535',\r\n\t\t\t\tstartsAt: 14,\r\n\t\t\t\tendsAt: 32\r\n\t\t\t}, {\r\n\t\t\t\tcountry: 'US',\r\n\t\t\t\tnationalNumber: '2133734253',\r\n\t\t\t\tstartsAt: 41,\r\n\t\t\t\tendsAt: 55\r\n\t\t\t}]\r\n\t\t)\r\n\t})\r\n\r\n\tit('should find phone numbers from Mexico', () => {\r\n\t\t// Test parsing fixed-line numbers of Mexico.\r\n\t\ttest('+52 (449)978-0001', 'MX', '4499780001')\r\n\t\ttest('01 (449)978-0001', 'MX', '4499780001')\r\n\t\ttest('(449)978-0001', 'MX', '4499780001')\r\n\t\t// Test parsing mobile numbers of Mexico.\r\n\t\ttest('+52 1 33 1234-5678', 'MX', '3312345678')\r\n\t\ttest('044 (33) 1234-5678', 'MX', '3312345678')\r\n\t\ttest('045 33 1234-5678', 'MX', '3312345678')\r\n\t})\r\n\r\n\tit('should find phone numbers from Argentina', () => {\r\n\t\t// Test parsing mobile numbers of Argentina.\r\n\t\ttest('+54 9 343 555 1212', 'AR', '93435551212')\r\n\t\ttest('0343 15-555-1212', 'AR', '93435551212')\r\n\r\n\t\ttest('+54 9 3715 65 4320', 'AR', '93715654320')\r\n\t\ttest('03715 15 65 4320', 'AR', '93715654320')\r\n\r\n\t\t// Test parsing fixed-line numbers of Argentina.\r\n\t\ttest('+54 11 3797 0000', 'AR', '1137970000')\r\n\t\ttest('011 3797 0000', 'AR', '1137970000')\r\n\r\n\t\ttest('+54 3715 65 4321', 'AR', '3715654321')\r\n\t\ttest('03715 65 4321', 'AR', '3715654321')\r\n\r\n\t\ttest('+54 23 1234 0000', 'AR', '2312340000')\r\n\t\ttest('023 1234 0000', 'AR', '2312340000')\r\n\t})\r\n\r\n\tit('should only support the supported leniency values', function() {\r\n\t\texpect(() => new PhoneNumberMatcher('+54 23 1234 0000', { leniency: 'STRICT_GROUPING', v2: true }, metadata)).to.throw('Supported values: \"POSSIBLE\", \"VALID\".')\r\n\t})\r\n})"],"mappings":";;AAAA;;AACA;;;;AAEA,SAASA,IAAT,CAAcC,IAAd,EAAoBC,cAApB,EAAoCC,eAApC,EAAqD;EACpD,IAAI,OAAOA,eAAP,KAA2B,QAA/B,EAAyC;IACxCA,eAAe,GAAG,CAAC;MAClBC,cAAc,EAAED;IADE,CAAD,CAAlB;EAGA;;EACD,IAAME,OAAO,GAAG,IAAIC,8BAAJ,CAAuBL,IAAvB,EAA6B;IAAEC,cAAc,EAAdA,cAAF;IAAkBK,EAAE,EAAE;EAAtB,CAA7B,EAA2DC,uBAA3D,CAAhB;;EACA,OAAOH,OAAO,CAACI,OAAR,EAAP,EAA0B;IACzB,IAAMC,MAAM,GAAGL,OAAO,CAACM,IAAR,EAAf;IACA,IAAMC,WAAW,GAAGT,eAAe,CAACU,KAAhB,EAApB;;IACA,IAAID,WAAW,CAACE,QAAZ,KAAyBC,SAA7B,EAAwC;MACvCL,MAAM,CAACI,QAAP,CAAgBE,MAAhB,CAAuBC,KAAvB,CAA6BL,WAAW,CAACE,QAAzC;IACA;;IACD,IAAIF,WAAW,CAACM,MAAZ,KAAuBH,SAA3B,EAAsC;MACrCL,MAAM,CAACQ,MAAP,CAAcF,MAAd,CAAqBC,KAArB,CAA2BL,WAAW,CAACM,MAAvC;IACA;;IACDR,MAAM,CAACA,MAAP,CAAcS,OAAd,CAAsBH,MAAtB,CAA6BC,KAA7B,CAAmCL,WAAW,CAACO,OAAZ,IAAuBjB,cAA1D;IACAQ,MAAM,CAACA,MAAP,CAAcN,cAAd,CAA6BY,MAA7B,CAAoCC,KAApC,CAA0CL,WAAW,CAACR,cAAtD;EACA;;E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