libphonenumber-js 1.10.24 → 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 (94) 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.d.ts +3 -3
  67. package/metadata.full.json +1 -1
  68. package/metadata.full.json.d.ts +1 -1
  69. package/metadata.full.json.js +1 -1
  70. package/metadata.max.json +1 -1
  71. package/metadata.max.json.d.ts +1 -1
  72. package/metadata.max.json.js +1 -1
  73. package/metadata.min.json +1 -1
  74. package/metadata.min.json.d.ts +1 -1
  75. package/metadata.min.json.js +1 -1
  76. package/metadata.mobile.json +1 -1
  77. package/metadata.mobile.json.d.ts +1 -1
  78. package/metadata.mobile.json.js +1 -1
  79. package/min/index.d.ts +3 -3
  80. package/package.json +4 -4
  81. package/source/AsYouTypeFormatter.PatternMatcher.d.ts +1 -1
  82. package/source/PhoneNumber.js +6 -0
  83. package/source/PhoneNumberMatcher.js +55 -58
  84. package/source/PhoneNumberMatcher.test.js +4 -0
  85. package/source/findNumbers/Leniency.js +281 -271
  86. package/source/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js +64 -0
  87. package/source/format.js +1 -1
  88. package/source/helpers/RFC3966.test.js +3 -0
  89. package/source/helpers/extractCountryCallingCode.js +48 -3
  90. package/source/helpers/extractCountryCallingCode.test.js +2 -0
  91. package/source/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js +74 -0
  92. package/source/helpers/extractPhoneContext.js +103 -0
  93. package/source/helpers/extractPhoneContext.test.js +104 -0
  94. package/source/parse.js +18 -8
@@ -25,7 +25,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
25
25
  * @param {string} [country] — Default country.
26
26
  * @param {string} [callingCode] — Default calling code (some phone numbering plans are non-geographic).
27
27
  * @param {object} metadata
28
- * @return {object} `{ countryCallingCode: string?, number: string }`
28
+ * @return {object} `{ countryCallingCodeSource: string?, countryCallingCode: string?, number: string }`
29
29
  * @example
30
30
  * // Returns `{ countryCallingCode: "1", number: "2133734253" }`.
31
31
  * extractCountryCallingCode('2133734253', 'US', null, metadata)
@@ -36,7 +36,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
36
36
  function extractCountryCallingCode(number, country, callingCode, metadata) {
37
37
  if (!number) {
38
38
  return {};
39
- } // If this is not an international phone number,
39
+ }
40
+
41
+ var isNumberWithIddPrefix; // If this is not an international phone number,
40
42
  // then either extract an "IDD" prefix, or extract a
41
43
  // country calling code from a number by autocorrecting it
42
44
  // by prepending a leading `+` in cases when it starts
@@ -44,7 +46,6 @@ function extractCountryCallingCode(number, country, callingCode, metadata) {
44
46
  // https://wikitravel.org/en/International_dialling_prefix
45
47
  // https://github.com/catamphetamine/libphonenumber-js/issues/376
46
48
 
47
-
48
49
  if (number[0] !== '+') {
49
50
  // Convert an "out-of-country" dialing phone number
50
51
  // to a proper international phone number.
@@ -53,6 +54,7 @@ function extractCountryCallingCode(number, country, callingCode, metadata) {
53
54
  // for subsequent parsing.
54
55
 
55
56
  if (numberWithoutIDD && numberWithoutIDD !== number) {
57
+ isNumberWithIddPrefix = true;
56
58
  number = '+' + numberWithoutIDD;
57
59
  } else {
58
60
  // Check to see if the number starts with the country calling code
@@ -66,6 +68,7 @@ function extractCountryCallingCode(number, country, callingCode, metadata) {
66
68
 
67
69
  if (countryCallingCode) {
68
70
  return {
71
+ countryCallingCodeSource: 'FROM_NUMBER_WITHOUT_PLUS_SIGN',
69
72
  countryCallingCode: countryCallingCode,
70
73
  number: shorterNumber
71
74
  };
@@ -73,6 +76,8 @@ function extractCountryCallingCode(number, country, callingCode, metadata) {
73
76
  }
74
77
 
75
78
  return {
79
+ // No need to set it to `UNSPECIFIED`. It can be just `undefined`.
80
+ // countryCallingCodeSource: 'UNSPECIFIED',
76
81
  number: number
77
82
  };
78
83
  }
@@ -101,6 +106,7 @@ function extractCountryCallingCode(number, country, callingCode, metadata) {
101
106
  if (metadata.hasCallingCode(_countryCallingCode)) {
102
107
  metadata.selectNumberingPlan(_countryCallingCode);
103
108
  return {
109
+ countryCallingCodeSource: isNumberWithIddPrefix ? 'FROM_NUMBER_WITH_IDD' : 'FROM_NUMBER_WITH_PLUS_SIGN',
104
110
  countryCallingCode: _countryCallingCode,
105
111
  number: number.slice(i)
106
112
  };
@@ -110,5 +116,39 @@ function extractCountryCallingCode(number, country, callingCode, metadata) {
110
116
  }
111
117
 
112
118
  return {};
113
- }
119
+ } // The possible values for the returned `countryCallingCodeSource` are:
120
+ //
121
+ // Copy-pasted from:
122
+ // https://github.com/google/libphonenumber/blob/master/resources/phonenumber.proto
123
+ //
124
+ // // The source from which the country_code is derived. This is not set in the
125
+ // // general parsing method, but in the method that parses and keeps raw_input.
126
+ // // New fields could be added upon request.
127
+ // enum CountryCodeSource {
128
+ // // Default value returned if this is not set, because the phone number was
129
+ // // created using parse, not parseAndKeepRawInput. hasCountryCodeSource will
130
+ // // return false if this is the case.
131
+ // UNSPECIFIED = 0;
132
+ //
133
+ // // The country_code is derived based on a phone number with a leading "+",
134
+ // // e.g. the French number "+33 1 42 68 53 00".
135
+ // FROM_NUMBER_WITH_PLUS_SIGN = 1;
136
+ //
137
+ // // The country_code is derived based on a phone number with a leading IDD,
138
+ // // e.g. the French number "011 33 1 42 68 53 00", as it is dialled from US.
139
+ // FROM_NUMBER_WITH_IDD = 5;
140
+ //
141
+ // // The country_code is derived based on a phone number without a leading
142
+ // // "+", e.g. the French number "33 1 42 68 53 00" when defaultCountry is
143
+ // // supplied as France.
144
+ // FROM_NUMBER_WITHOUT_PLUS_SIGN = 10;
145
+ //
146
+ // // The country_code is derived NOT based on the phone number itself, but
147
+ // // from the defaultCountry parameter provided in the parsing function by the
148
+ // // clients. This happens mostly for numbers written in the national format
149
+ // // (without country code). For example, this would be set when parsing the
150
+ // // French number "01 42 68 53 00", when defaultCountry is supplied as
151
+ // // France.
152
+ // FROM_DEFAULT_COUNTRY = 20;
153
+ // }
114
154
  //# sourceMappingURL=extractCountryCallingCode.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"extractCountryCallingCode.js","names":["extractCountryCallingCode","number","country","callingCode","metadata","numberWithoutIDD","stripIddPrefix","extractCountryCallingCodeFromInternationalNumberWithoutPlusSign","countryCallingCode","shorterNumber","Metadata","i","MAX_LENGTH_COUNTRY_CODE","length","slice","hasCallingCode","selectNumberingPlan"],"sources":["../../source/helpers/extractCountryCallingCode.js"],"sourcesContent":["import stripIddPrefix from './stripIddPrefix.js'\r\nimport extractCountryCallingCodeFromInternationalNumberWithoutPlusSign from './extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js'\r\nimport Metadata from '../metadata.js'\r\nimport { MAX_LENGTH_COUNTRY_CODE } from '../constants.js'\r\n\r\n/**\r\n * Converts a phone number digits (possibly with a `+`)\r\n * into a calling code and the rest phone number digits.\r\n * The \"rest phone number digits\" could include\r\n * a national prefix, carrier code, and national\r\n * (significant) number.\r\n * @param {string} number — Phone number digits (possibly with a `+`).\r\n * @param {string} [country] — Default country.\r\n * @param {string} [callingCode] — Default calling code (some phone numbering plans are non-geographic).\r\n * @param {object} metadata\r\n * @return {object} `{ countryCallingCode: string?, number: string }`\r\n * @example\r\n * // Returns `{ countryCallingCode: \"1\", number: \"2133734253\" }`.\r\n * extractCountryCallingCode('2133734253', 'US', null, metadata)\r\n * extractCountryCallingCode('2133734253', null, '1', metadata)\r\n * extractCountryCallingCode('+12133734253', null, null, metadata)\r\n * extractCountryCallingCode('+12133734253', 'RU', null, metadata)\r\n */\r\nexport default function extractCountryCallingCode(\r\n\tnumber,\r\n\tcountry,\r\n\tcallingCode,\r\n\tmetadata\r\n) {\r\n\tif (!number) {\r\n\t\treturn {}\r\n\t}\r\n\r\n\t// If this is not an international phone number,\r\n\t// then either extract an \"IDD\" prefix, or extract a\r\n\t// country calling code from a number by autocorrecting it\r\n\t// by prepending a leading `+` in cases when it starts\r\n\t// with the country calling code.\r\n\t// https://wikitravel.org/en/International_dialling_prefix\r\n\t// https://github.com/catamphetamine/libphonenumber-js/issues/376\r\n\tif (number[0] !== '+') {\r\n\t\t// Convert an \"out-of-country\" dialing phone number\r\n\t\t// to a proper international phone number.\r\n\t\tconst numberWithoutIDD = stripIddPrefix(number, country, callingCode, metadata)\r\n\t\t// If an IDD prefix was stripped then\r\n\t\t// convert the number to international one\r\n\t\t// for subsequent parsing.\r\n\t\tif (numberWithoutIDD && numberWithoutIDD !== number) {\r\n\t\t\tnumber = '+' + numberWithoutIDD\r\n\t\t} else {\r\n\t\t\t// Check to see if the number starts with the country calling code\r\n\t\t\t// for the default country. If so, we remove the country calling code,\r\n\t\t\t// and do some checks on the validity of the number before and after.\r\n\t\t\t// https://github.com/catamphetamine/libphonenumber-js/issues/376\r\n\t\t\tif (country || callingCode) {\r\n\t\t\t\tconst {\r\n\t\t\t\t\tcountryCallingCode,\r\n\t\t\t\t\tnumber: shorterNumber\r\n\t\t\t\t} = extractCountryCallingCodeFromInternationalNumberWithoutPlusSign(\r\n\t\t\t\t\tnumber,\r\n\t\t\t\t\tcountry,\r\n\t\t\t\t\tcallingCode,\r\n\t\t\t\t\tmetadata\r\n\t\t\t\t)\r\n\t\t\t\tif (countryCallingCode) {\r\n\t\t\t\t\treturn {\r\n\t\t\t\t\t\tcountryCallingCode,\r\n\t\t\t\t\t\tnumber: shorterNumber\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn { number }\r\n\t\t}\r\n\t}\r\n\r\n\t// Fast abortion: country codes do not begin with a '0'\r\n\tif (number[1] === '0') {\r\n\t\treturn {}\r\n\t}\r\n\r\n\tmetadata = new Metadata(metadata)\r\n\r\n\t// The thing with country phone codes\r\n\t// is that they are orthogonal to each other\r\n\t// i.e. there's no such country phone code A\r\n\t// for which country phone code B exists\r\n\t// where B starts with A.\r\n\t// Therefore, while scanning digits,\r\n\t// if a valid country code is found,\r\n\t// that means that it is the country code.\r\n\t//\r\n\tlet i = 2\r\n\twhile (i - 1 <= MAX_LENGTH_COUNTRY_CODE && i <= number.length) {\r\n\t\tconst countryCallingCode = number.slice(1, i)\r\n\t\tif (metadata.hasCallingCode(countryCallingCode)) {\r\n\t\t\tmetadata.selectNumberingPlan(countryCallingCode)\r\n\t\t\treturn {\r\n\t\t\t\tcountryCallingCode,\r\n\t\t\t\tnumber: number.slice(i)\r\n\t\t\t}\r\n\t\t}\r\n\t\ti++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CAAC,GAAG,CAAR;;EACA,OAAOA,CAAC,GAAG,CAAJ,IAASC,kCAAT,IAAoCD,CAAC,IAAIV,MAAM,CAACY,MAAvD,EAA+D;IAC9D,IAAML,mBAAkB,GAAGP,MAAM,CAACa,KAAP,CAAa,CAAb,EAAgBH,CAAhB,CAA3B;;IACA,IAAIP,QAAQ,CAACW,cAAT,CAAwBP,mBAAxB,CAAJ,EAAiD;MAChDJ,QAAQ,CAACY,mBAAT,CAA6BR,mBAA7B;MACA,OAAO;QACNA,kBAAkB,EAAlBA,mBADM;QAENP,MAAM,EAAEA,MAAM,CAACa,KAAP,CAAaH,CAAb;MAFF,CAAP;IAIA;;IACDA,CAAC;EACD;;EAED,OAAO,EAAP;AACA"}
1
+ {"version":3,"file":"extractCountryCallingCode.js","names":["extractCountryCallingCode","number","country","callingCode","metadata","isNumberWithIddPrefix","numberWithoutIDD","stripIddPrefix","extractCountryCallingCodeFromInternationalNumberWithoutPlusSign","countryCallingCode","shorterNumber","countryCallingCodeSource","Metadata","i","MAX_LENGTH_COUNTRY_CODE","length","slice","hasCallingCode","selectNumberingPlan"],"sources":["../../source/helpers/extractCountryCallingCode.js"],"sourcesContent":["import stripIddPrefix from './stripIddPrefix.js'\r\nimport extractCountryCallingCodeFromInternationalNumberWithoutPlusSign from './extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js'\r\nimport Metadata from '../metadata.js'\r\nimport { MAX_LENGTH_COUNTRY_CODE } from '../constants.js'\r\n\r\n/**\r\n * Converts a phone number digits (possibly with a `+`)\r\n * into a calling code and the rest phone number digits.\r\n * The \"rest phone number digits\" could include\r\n * a national prefix, carrier code, and national\r\n * (significant) number.\r\n * @param {string} number — Phone number digits (possibly with a `+`).\r\n * @param {string} [country] — Default country.\r\n * @param {string} [callingCode] — Default calling code (some phone numbering plans are non-geographic).\r\n * @param {object} metadata\r\n * @return {object} `{ countryCallingCodeSource: string?, countryCallingCode: string?, number: string }`\r\n * @example\r\n * // Returns `{ countryCallingCode: \"1\", number: \"2133734253\" }`.\r\n * extractCountryCallingCode('2133734253', 'US', null, metadata)\r\n * extractCountryCallingCode('2133734253', null, '1', metadata)\r\n * extractCountryCallingCode('+12133734253', null, null, metadata)\r\n * extractCountryCallingCode('+12133734253', 'RU', null, metadata)\r\n */\r\nexport default function extractCountryCallingCode(\r\n\tnumber,\r\n\tcountry,\r\n\tcallingCode,\r\n\tmetadata\r\n) {\r\n\tif (!number) {\r\n\t\treturn {}\r\n\t}\r\n\r\n\tlet isNumberWithIddPrefix\r\n\r\n\t// If this is not an international phone number,\r\n\t// then either extract an \"IDD\" prefix, or extract a\r\n\t// country calling code from a number by autocorrecting it\r\n\t// by prepending a leading `+` in cases when it starts\r\n\t// with the country calling code.\r\n\t// https://wikitravel.org/en/International_dialling_prefix\r\n\t// https://github.com/catamphetamine/libphonenumber-js/issues/376\r\n\tif (number[0] !== '+') {\r\n\t\t// Convert an \"out-of-country\" dialing phone number\r\n\t\t// to a proper international phone number.\r\n\t\tconst numberWithoutIDD = stripIddPrefix(number, country, callingCode, metadata)\r\n\t\t// If an IDD prefix was stripped then\r\n\t\t// convert the number to international one\r\n\t\t// for subsequent parsing.\r\n\t\tif (numberWithoutIDD && numberWithoutIDD !== number) {\r\n\t\t\tisNumberWithIddPrefix = true\r\n\t\t\tnumber = '+' + numberWithoutIDD\r\n\t\t} else {\r\n\t\t\t// Check to see if the number starts with the country calling code\r\n\t\t\t// for the default country. If so, we remove the country calling code,\r\n\t\t\t// and do some checks on the validity of the number before and after.\r\n\t\t\t// https://github.com/catamphetamine/libphonenumber-js/issues/376\r\n\t\t\tif (country || callingCode) {\r\n\t\t\t\tconst {\r\n\t\t\t\t\tcountryCallingCode,\r\n\t\t\t\t\tnumber: shorterNumber\r\n\t\t\t\t} = extractCountryCallingCodeFromInternationalNumberWithoutPlusSign(\r\n\t\t\t\t\tnumber,\r\n\t\t\t\t\tcountry,\r\n\t\t\t\t\tcallingCode,\r\n\t\t\t\t\tmetadata\r\n\t\t\t\t)\r\n\t\t\t\tif (countryCallingCode) {\r\n\t\t\t\t\treturn {\r\n\t\t\t\t\t\tcountryCallingCodeSource: 'FROM_NUMBER_WITHOUT_PLUS_SIGN',\r\n\t\t\t\t\t\tcountryCallingCode,\r\n\t\t\t\t\t\tnumber: shorterNumber\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn {\r\n\t\t\t\t// No need to set it to `UNSPECIFIED`. It can be just `undefined`.\r\n\t\t\t\t// countryCallingCodeSource: 'UNSPECIFIED',\r\n\t\t\t\tnumber\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// Fast abortion: country codes do not begin with a '0'\r\n\tif (number[1] === '0') {\r\n\t\treturn {}\r\n\t}\r\n\r\n\tmetadata = new Metadata(metadata)\r\n\r\n\t// The thing with country phone codes\r\n\t// is that they are orthogonal to each other\r\n\t// i.e. there's no such country phone code A\r\n\t// for which country phone code B exists\r\n\t// where B starts with A.\r\n\t// Therefore, while scanning digits,\r\n\t// if a valid country code is found,\r\n\t// that means that it is the country code.\r\n\t//\r\n\tlet i = 2\r\n\twhile (i - 1 <= MAX_LENGTH_COUNTRY_CODE && i <= number.length) {\r\n\t\tconst countryCallingCode = number.slice(1, i)\r\n\t\tif (metadata.hasCallingCode(countryCallingCode)) {\r\n\t\t\tmetadata.selectNumberingPlan(countryCallingCode)\r\n\t\t\treturn {\r\n\t\t\t\tcountryCallingCodeSource: isNumberWithIddPrefix ? 'FROM_NUMBER_WITH_IDD' : 'FROM_NUMBER_WITH_PLUS_SIGN',\r\n\t\t\t\tcountryCallingCode,\r\n\t\t\t\tnumber: number.slice(i)\r\n\t\t\t}\r\n\t\t}\r\n\t\ti++\r\n\t}\r\n\r\n\treturn {}\r\n}\r\n\r\n// The possible values for the returned `countryCallingCodeSource` are:\r\n//\r\n// Copy-pasted from:\r\n// https://github.com/google/libphonenumber/blob/master/resources/phonenumber.proto\r\n//\r\n// // The source from which the country_code is derived. This is not set in the\r\n// // general parsing method, but in the method that parses and keeps raw_input.\r\n// // New fields could be added upon request.\r\n// enum CountryCodeSource {\r\n// // Default value returned if this is not set, because the phone number was\r\n// // created using parse, not parseAndKeepRawInput. hasCountryCodeSource will\r\n// // return false if this is the case.\r\n// UNSPECIFIED = 0;\r\n//\r\n// // The country_code is derived based on a phone number with a leading \"+\",\r\n// // e.g. the French number \"+33 1 42 68 53 00\".\r\n// FROM_NUMBER_WITH_PLUS_SIGN = 1;\r\n//\r\n// // The country_code is derived based on a phone number with a leading IDD,\r\n// // e.g. the French number \"011 33 1 42 68 53 00\", as it is dialled from US.\r\n// FROM_NUMBER_WITH_IDD = 5;\r\n//\r\n// // The country_code is derived based on a phone number without a leading\r\n// // \"+\", e.g. the French number \"33 1 42 68 53 00\" when defaultCountry is\r\n// // supplied as France.\r\n// FROM_NUMBER_WITHOUT_PLUS_SIGN = 10;\r\n//\r\n// // The country_code is derived NOT based on the phone number itself, but\r\n// // from the defaultCountry parameter provided in the parsing function by the\r\n// // clients. This happens mostly for numbers written in the national format\r\n// // (without country code). For example, this would be set when parsing the\r\n// // French number \"01 42 68 53 00\", when defaultCountry is supplied as\r\n// // France.\r\n// FROM_DEFAULT_COUNTRY = 20;\r\n// }"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,yBAAT,CACdC,MADc,EAEdC,OAFc,EAGdC,WAHc,EAIdC,QAJc,EAKb;EACD,IAAI,CAACH,MAAL,EAAa;IACZ,OAAO,EAAP;EACA;;EAED,IAAII,qBAAJ,CALC,CAOD;EACA;EACA;EACA;EACA;EACA;EACA;;EACA,IAAIJ,MAAM,CAAC,CAAD,CAAN,KAAc,GAAlB,EAAuB;IACtB;IACA;IACA,IAAMK,gBAAgB,GAAG,IAAAC,0BAAA,EAAeN,MAAf,EAAuBC,OAAvB,EAAgCC,WAAh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M,EAAEA,MAAM,CAACe,KAAP,CAAaH,CAAb;MAHF,CAAP;IAKA;;IACDA,CAAC;EACD;;EAED,OAAO,EAAP;AACA,C,CAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
@@ -9,10 +9,12 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
9
9
  describe('extractCountryCallingCode', function () {
10
10
  it('should extract country calling code from a number', function () {
11
11
  (0, _extractCountryCallingCode["default"])('+78005553535', null, null, _metadataMin["default"]).should.deep.equal({
12
+ countryCallingCodeSource: 'FROM_NUMBER_WITH_PLUS_SIGN',
12
13
  countryCallingCode: '7',
13
14
  number: '8005553535'
14
15
  });
15
16
  (0, _extractCountryCallingCode["default"])('+7800', null, null, _metadataMin["default"]).should.deep.equal({
17
+ countryCallingCodeSource: 'FROM_NUMBER_WITH_PLUS_SIGN',
16
18
  countryCallingCode: '7',
17
19
  number: '800'
18
20
  });
@@ -1 +1 @@
1
- {"version":3,"file":"extractCountryCallingCode.test.js","names":["describe","it","extractCountryCallingCode","metadata","should","deep","equal","countryCallingCode","number"],"sources":["../../source/helpers/extractCountryCallingCode.test.js"],"sourcesContent":["import extractCountryCallingCode from './extractCountryCallingCode.js'\r\nimport metadata from '../../metadata.min.json' assert { type: 'json' }\r\n\r\ndescribe('extractCountryCallingCode', () => {\r\n\tit('should extract country calling code from a number', () => {\r\n\t\textractCountryCallingCode('+78005553535', null, null, metadata).should.deep.equal({\r\n\t\t\tcountryCallingCode: '7',\r\n\t\t\tnumber: '8005553535'\r\n\t\t})\r\n\r\n\t\textractCountryCallingCode('+7800', null, null, metadata).should.deep.equal({\r\n\t\t\tcountryCallingCode: '7',\r\n\t\t\tnumber: '800'\r\n\t\t})\r\n\r\n\t\textractCountryCallingCode('', null, null, metadata).should.deep.equal({})\r\n\t})\r\n})\r\n"],"mappings":";;AAAA;;AACA;;;;AAEAA,QAAQ,CAAC,2BAAD,EAA8B,YAAM;EAC3CC,EAAE,CAAC,mDAAD,EAAsD,YAAM;IAC7D,IAAAC,qCAAA,EAA0B,cAA1B,EAA0C,IAA1C,EAAgD,IAAhD,EAAsDC,uBAAtD,EAAgEC,MAAhE,CAAuEC,IAAvE,CAA4EC,KAA5E,CAAkF;MACjFC,kBAAkB,EAAE,GAD6D;MAEjFC,MAAM,EAAE;IAFyE,CAAlF;IAKA,IAAAN,qCAAA,EAA0B,OAA1B,EAAmC,IAAnC,EAAyC,IAAzC,EAA+CC,uBAA/C,EAAyDC,MAAzD,CAAgEC,IAAhE,CAAqEC,KAArE,CAA2E;MAC1EC,kBAAkB,EAAE,GADsD;MAE1EC,MAAM,EAAE;IAFkE,CAA3E;IAKA,IAAAN,qCAAA,EAA0B,EAA1B,EAA8B,IAA9B,EAAoC,IAApC,EAA0CC,uBAA1C,EAAoDC,MAApD,CAA2DC,IAA3D,CAAgEC,KAAhE,CAAsE,EAAtE;EACA,CAZC,CAAF;AAaA,CAdO,CAAR"}
1
+ {"version":3,"file":"extractCountryCallingCode.test.js","names":["describe","it","extractCountryCallingCode","metadata","should","deep","equal","countryCallingCodeSource","countryCallingCode","number"],"sources":["../../source/helpers/extractCountryCallingCode.test.js"],"sourcesContent":["import extractCountryCallingCode from './extractCountryCallingCode.js'\r\nimport metadata from '../../metadata.min.json' assert { type: 'json' }\r\n\r\ndescribe('extractCountryCallingCode', () => {\r\n\tit('should extract country calling code from a number', () => {\r\n\t\textractCountryCallingCode('+78005553535', null, null, metadata).should.deep.equal({\r\n\t\t\tcountryCallingCodeSource: 'FROM_NUMBER_WITH_PLUS_SIGN',\r\n\t\t\tcountryCallingCode: '7',\r\n\t\t\tnumber: '8005553535'\r\n\t\t})\r\n\r\n\t\textractCountryCallingCode('+7800', null, null, metadata).should.deep.equal({\r\n\t\t\tcountryCallingCodeSource: 'FROM_NUMBER_WITH_PLUS_SIGN',\r\n\t\t\tcountryCallingCode: '7',\r\n\t\t\tnumber: '800'\r\n\t\t})\r\n\r\n\t\textractCountryCallingCode('', null, null, metadata).should.deep.equal({})\r\n\t})\r\n})\r\n"],"mappings":";;AAAA;;AACA;;;;AAEAA,QAAQ,CAAC,2BAAD,EAA8B,YAAM;EAC3CC,EAAE,CAAC,mDAAD,EAAsD,YAAM;IAC7D,IAAAC,qCAAA,EAA0B,cAA1B,EAA0C,IAA1C,EAAgD,IAAhD,EAAsDC,uBAAtD,EAAgEC,MAAhE,CAAuEC,IAAvE,CAA4EC,KAA5E,CAAkF;MACjFC,wBAAwB,EAAE,4BADuD;MAEjFC,kBAAkB,EAAE,GAF6D;MAGjFC,MAAM,EAAE;IAHyE,CAAlF;IAMA,IAAAP,qCAAA,EAA0B,OAA1B,EAAmC,IAAnC,EAAyC,IAAzC,EAA+CC,uBAA/C,EAAyDC,MAAzD,CAAgEC,IAAhE,CAAqEC,KAArE,CAA2E;MAC1EC,wBAAwB,EAAE,4BADgD;MAE1EC,kBAAkB,EAAE,GAFsD;MAG1EC,MAAM,EAAE;IAHkE,CAA3E;IAMA,IAAAP,qCAAA,EAA0B,EAA1B,EAA8B,IAA9B,EAAoC,IAApC,EAA0CC,uBAA1C,EAAoDC,MAApD,CAA2DC,IAA3D,CAAgEC,KAAhE,CAAsE,EAAtE;EACA,CAdC,CAAF;AAeA,CAhBO,CAAR"}
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = extractFormattedPhoneNumberFromPossibleRfc3966NumberUri;
9
+
10
+ var _extractPhoneContext = _interopRequireWildcard(require("./extractPhoneContext.js"));
11
+
12
+ var _ParseError = _interopRequireDefault(require("../ParseError.js"));
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
+
16
+ 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); }
17
+
18
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
+
20
+ /**
21
+ * @param {string} numberToParse
22
+ * @param {string} nationalNumber
23
+ * @return {}
24
+ */
25
+ function extractFormattedPhoneNumberFromPossibleRfc3966NumberUri(numberToParse, _ref) {
26
+ var extractFormattedPhoneNumber = _ref.extractFormattedPhoneNumber;
27
+ var phoneContext = (0, _extractPhoneContext["default"])(numberToParse);
28
+
29
+ if (!(0, _extractPhoneContext.isPhoneContextValid)(phoneContext)) {
30
+ throw new _ParseError["default"]('NOT_A_NUMBER');
31
+ }
32
+
33
+ var phoneNumberString;
34
+
35
+ if (phoneContext === null) {
36
+ // Extract a possible number from the string passed in.
37
+ // (this strips leading characters that could not be the start of a phone number)
38
+ phoneNumberString = extractFormattedPhoneNumber(numberToParse) || '';
39
+ } else {
40
+ phoneNumberString = ''; // If the phone context contains a phone number prefix, we need to capture
41
+ // it, whereas domains will be ignored.
42
+
43
+ if (phoneContext.charAt(0) === _extractPhoneContext.PLUS_SIGN) {
44
+ phoneNumberString += phoneContext;
45
+ } // Now append everything between the "tel:" prefix and the phone-context.
46
+ // This should include the national number, an optional extension or
47
+ // isdn-subaddress component. Note we also handle the case when "tel:" is
48
+ // missing, as we have seen in some of the phone number inputs.
49
+ // In that case, we append everything from the beginning.
50
+
51
+
52
+ var indexOfRfc3966Prefix = numberToParse.indexOf(_extractPhoneContext.RFC3966_PREFIX_);
53
+ var indexOfNationalNumber; // RFC 3966 "tel:" prefix is preset at this stage because
54
+ // `isPhoneContextValid()` requires it to be present.
55
+
56
+ /* istanbul ignore else */
57
+
58
+ if (indexOfRfc3966Prefix >= 0) {
59
+ indexOfNationalNumber = indexOfRfc3966Prefix + _extractPhoneContext.RFC3966_PREFIX_.length;
60
+ } else {
61
+ indexOfNationalNumber = 0;
62
+ }
63
+
64
+ var indexOfPhoneContext = numberToParse.indexOf(_extractPhoneContext.RFC3966_PHONE_CONTEXT_);
65
+ phoneNumberString += numberToParse.substring(indexOfNationalNumber, indexOfPhoneContext);
66
+ } // Delete the isdn-subaddress and everything after it if it is present.
67
+ // Note extension won't appear at the same time with isdn-subaddress
68
+ // according to paragraph 5.3 of the RFC3966 spec.
69
+
70
+
71
+ var indexOfIsdn = phoneNumberString.indexOf(_extractPhoneContext.RFC3966_ISDN_SUBADDRESS_);
72
+
73
+ if (indexOfIsdn > 0) {
74
+ phoneNumberString = phoneNumberString.substring(0, indexOfIsdn);
75
+ } // If both phone context and isdn-subaddress are absent but other
76
+ // parameters are present, the parameters are left in nationalNumber.
77
+ // This is because we are concerned about deleting content from a potential
78
+ // number string when there is no strong evidence that the number is
79
+ // actually written in RFC3966.
80
+
81
+
82
+ if (phoneNumberString !== '') {
83
+ return phoneNumberString;
84
+ }
85
+ }
86
+ //# sourceMappingURL=extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js","names":["extractFormattedPhoneNumberFromPossibleRfc3966NumberUri","numberToParse","extractFormattedPhoneNumber","phoneContext","extractPhoneContext","isPhoneContextValid","ParseError","phoneNumberString","charAt","PLUS_SIGN","indexOfRfc3966Prefix","indexOf","RFC3966_PREFIX_","indexOfNationalNumber","length","indexOfPhoneContext","RFC3966_PHONE_CONTEXT_","substring","indexOfIsdn","RFC3966_ISDN_SUBADDRESS_"],"sources":["../../source/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js"],"sourcesContent":["import extractPhoneContext, {\r\n\tisPhoneContextValid,\r\n\tPLUS_SIGN,\r\n\tRFC3966_PREFIX_,\r\n\tRFC3966_PHONE_CONTEXT_,\r\n\tRFC3966_ISDN_SUBADDRESS_\r\n} from './extractPhoneContext.js'\r\n\r\nimport ParseError from '../ParseError.js'\r\n\r\n/**\r\n * @param {string} numberToParse\r\n * @param {string} nationalNumber\r\n * @return {}\r\n */\r\nexport default function extractFormattedPhoneNumberFromPossibleRfc3966NumberUri(numberToParse, {\r\n\textractFormattedPhoneNumber\r\n}) {\r\n\tconst phoneContext = extractPhoneContext(numberToParse)\r\n\tif (!isPhoneContextValid(phoneContext)) {\r\n\t\tthrow new ParseError('NOT_A_NUMBER')\r\n\t}\r\n\r\n\tlet phoneNumberString\r\n\r\n\tif (phoneContext === null) {\r\n\t\t// Extract a possible number from the string passed in.\r\n\t\t// (this strips leading characters that could not be the start of a phone number)\r\n\t\tphoneNumberString = extractFormattedPhoneNumber(numberToParse) || ''\r\n\t} else {\r\n\t\tphoneNumberString = ''\r\n\r\n\t\t// If the phone context contains a phone number prefix, we need to capture\r\n\t\t// it, whereas domains will be ignored.\r\n\t\tif (phoneContext.charAt(0) === PLUS_SIGN) {\r\n\t\t\tphoneNumberString += phoneContext\r\n\t\t}\r\n\r\n\t\t// Now append everything between the \"tel:\" prefix and the phone-context.\r\n\t\t// This should include the national number, an optional extension or\r\n\t\t// isdn-subaddress component. Note we also handle the case when \"tel:\" is\r\n\t\t// missing, as we have seen in some of the phone number inputs.\r\n\t\t// In that case, we append everything from the beginning.\r\n\t\tconst indexOfRfc3966Prefix = numberToParse.indexOf(RFC3966_PREFIX_)\r\n\t\tlet indexOfNationalNumber\r\n\t\t// RFC 3966 \"tel:\" prefix is preset at this stage because\r\n\t\t// `isPhoneContextValid()` requires it to be present.\r\n\t\t/* istanbul ignore else */\r\n\t\tif (indexOfRfc3966Prefix >= 0) {\r\n\t\t\tindexOfNationalNumber = indexOfRfc3966Prefix + RFC3966_PREFIX_.length\r\n\t\t} else {\r\n\t\t\tindexOfNationalNumber = 0\r\n\t\t}\r\n\t\tconst indexOfPhoneContext = numberToParse.indexOf(RFC3966_PHONE_CONTEXT_)\r\n\t\tphoneNumberString += numberToParse.substring(indexOfNationalNumber, indexOfPhoneContext)\r\n\t}\r\n\r\n\t// Delete the isdn-subaddress and everything after it if it is present.\r\n\t// Note extension won't appear at the same time with isdn-subaddress\r\n\t// according to paragraph 5.3 of the RFC3966 spec.\r\n\tconst indexOfIsdn = phoneNumberString.indexOf(RFC3966_ISDN_SUBADDRESS_)\r\n\tif (indexOfIsdn > 0) {\r\n\t\tphoneNumberString = phoneNumberString.substring(0, indexOfIsdn)\r\n\t}\r\n\t// If both phone context and isdn-subaddress are absent but other\r\n\t// parameters are present, the parameters are left in nationalNumber.\r\n\t// This is because we are concerned about deleting content from a potential\r\n\t// number string when there is no strong evidence that the number is\r\n\t// actually written in RFC3966.\r\n\r\n\tif (phoneNumberString !== '') {\r\n\t\treturn phoneNumberString\r\n\t}\r\n}"],"mappings":";;;;;;;;;AAAA;;AAQA;;;;;;;;AAEA;AACA;AACA;AACA;AACA;AACe,SAASA,uDAAT,CAAiEC,aAAjE,QAEZ;EAAA,IADFC,2BACE,QADFA,2BACE;EACF,IAAMC,YAAY,GAAG,IAAAC,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 -0,0 +1,97 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.RFC3966_PREFIX_ = exports.RFC3966_PHONE_CONTEXT_ = exports.RFC3966_ISDN_SUBADDRESS_ = exports.PLUS_SIGN = void 0;
7
+ exports["default"] = extractPhoneContext;
8
+ exports.isPhoneContextValid = isPhoneContextValid;
9
+
10
+ var _constants = require("../constants.js");
11
+
12
+ // When phone numbers are written in `RFC3966` format — `"tel:+12133734253"` —
13
+ // they can have their "calling code" part written separately in a `phone-context` parameter.
14
+ // Example: `"tel:12133734253;phone-context=+1"`.
15
+ // This function parses the full phone number from the local number and the `phone-context`
16
+ // when the `phone-context` contains a `+` sign.
17
+ var PLUS_SIGN = '+';
18
+ exports.PLUS_SIGN = PLUS_SIGN;
19
+ var RFC3966_VISUAL_SEPARATOR_ = '[\\-\\.\\(\\)]?';
20
+ var RFC3966_PHONE_DIGIT_ = '(' + '[' + _constants.VALID_DIGITS + ']' + '|' + RFC3966_VISUAL_SEPARATOR_ + ')';
21
+ var RFC3966_GLOBAL_NUMBER_DIGITS_ = '^' + '\\' + PLUS_SIGN + RFC3966_PHONE_DIGIT_ + '*' + '[' + _constants.VALID_DIGITS + ']' + RFC3966_PHONE_DIGIT_ + '*' + '$';
22
+ /**
23
+ * Regular expression of valid global-number-digits for the phone-context
24
+ * parameter, following the syntax defined in RFC3966.
25
+ */
26
+
27
+ var RFC3966_GLOBAL_NUMBER_DIGITS_PATTERN_ = new RegExp(RFC3966_GLOBAL_NUMBER_DIGITS_, 'g'); // In this port of Google's library, we don't accept alpha characters in phone numbers.
28
+ // const ALPHANUM_ = VALID_ALPHA_ + VALID_DIGITS
29
+
30
+ var ALPHANUM_ = _constants.VALID_DIGITS;
31
+ var RFC3966_DOMAINLABEL_ = '[' + ALPHANUM_ + ']+((\\-)*[' + ALPHANUM_ + '])*';
32
+ var VALID_ALPHA_ = 'a-zA-Z';
33
+ var RFC3966_TOPLABEL_ = '[' + VALID_ALPHA_ + ']+((\\-)*[' + ALPHANUM_ + '])*';
34
+ var RFC3966_DOMAINNAME_ = '^(' + RFC3966_DOMAINLABEL_ + '\\.)*' + RFC3966_TOPLABEL_ + '\\.?$';
35
+ /**
36
+ * Regular expression of valid domainname for the phone-context parameter,
37
+ * following the syntax defined in RFC3966.
38
+ */
39
+
40
+ var RFC3966_DOMAINNAME_PATTERN_ = new RegExp(RFC3966_DOMAINNAME_, 'g');
41
+ var RFC3966_PREFIX_ = 'tel:';
42
+ exports.RFC3966_PREFIX_ = RFC3966_PREFIX_;
43
+ var RFC3966_PHONE_CONTEXT_ = ';phone-context=';
44
+ exports.RFC3966_PHONE_CONTEXT_ = RFC3966_PHONE_CONTEXT_;
45
+ var RFC3966_ISDN_SUBADDRESS_ = ';isub=';
46
+ /**
47
+ * Extracts the value of the phone-context parameter of `numberToExtractFrom`,
48
+ * following the syntax defined in RFC3966.
49
+ *
50
+ * @param {string} numberToExtractFrom
51
+ * @return {string|null} the extracted string (possibly empty), or `null` if no phone-context parameter is found.
52
+ */
53
+
54
+ exports.RFC3966_ISDN_SUBADDRESS_ = RFC3966_ISDN_SUBADDRESS_;
55
+
56
+ function extractPhoneContext(numberToExtractFrom) {
57
+ var indexOfPhoneContext = numberToExtractFrom.indexOf(RFC3966_PHONE_CONTEXT_); // If no phone-context parameter is present
58
+
59
+ if (indexOfPhoneContext < 0) {
60
+ return null;
61
+ }
62
+
63
+ var phoneContextStart = indexOfPhoneContext + RFC3966_PHONE_CONTEXT_.length; // If phone-context parameter is empty
64
+
65
+ if (phoneContextStart >= numberToExtractFrom.length) {
66
+ return '';
67
+ }
68
+
69
+ var phoneContextEnd = numberToExtractFrom.indexOf(';', phoneContextStart); // If phone-context is not the last parameter
70
+
71
+ if (phoneContextEnd >= 0) {
72
+ return numberToExtractFrom.substring(phoneContextStart, phoneContextEnd);
73
+ } else {
74
+ return numberToExtractFrom.substring(phoneContextStart);
75
+ }
76
+ }
77
+ /**
78
+ * Returns whether the value of phoneContext follows the syntax defined in RFC3966.
79
+ *
80
+ * @param {string|null} phoneContext
81
+ * @return {boolean}
82
+ */
83
+
84
+
85
+ function isPhoneContextValid(phoneContext) {
86
+ if (phoneContext === null) {
87
+ return true;
88
+ }
89
+
90
+ if (phoneContext.length === 0) {
91
+ return false;
92
+ } // Does phone-context value match pattern of global-number-digits or domainname.
93
+
94
+
95
+ return RFC3966_GLOBAL_NUMBER_DIGITS_PATTERN_.test(phoneContext) || RFC3966_DOMAINNAME_PATTERN_.test(phoneContext);
96
+ }
97
+ //# sourceMappingURL=extractPhoneContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractPhoneContext.js","names":["PLUS_SIGN","RFC3966_VISUAL_SEPARATOR_","RFC3966_PHONE_DIGIT_","VALID_DIGITS","RFC3966_GLOBAL_NUMBER_DIGITS_","RFC3966_GLOBAL_NUMBER_DIGITS_PATTERN_","RegExp","ALPHANUM_","RFC3966_DOMAINLABEL_","VALID_ALPHA_","RFC3966_TOPLABEL_","RFC3966_DOMAINNAME_","RFC3966_DOMAINNAME_PATTERN_","RFC3966_PREFIX_","RFC3966_PHONE_CONTEXT_","RFC3966_ISDN_SUBADDRESS_","extractPhoneContext","numberToExtractFrom","indexOfPhoneContext","indexOf","phoneContextStart","length","phoneContextEnd","substring","isPhoneContextValid","phoneContext","test"],"sources":["../../source/helpers/extractPhoneContext.js"],"sourcesContent":["// When phone numbers are written in `RFC3966` format — `\"tel:+12133734253\"` —\r\n// they can have their \"calling code\" part written separately in a `phone-context` parameter.\r\n// Example: `\"tel:12133734253;phone-context=+1\"`.\r\n// This function parses the full phone number from the local number and the `phone-context`\r\n// when the `phone-context` contains a `+` sign.\r\n\r\nimport {\r\n VALID_DIGITS,\r\n // PLUS_CHARS\r\n} from '../constants.js'\r\n\r\nexport const PLUS_SIGN = '+'\r\n\r\nconst RFC3966_VISUAL_SEPARATOR_ = '[\\\\-\\\\.\\\\(\\\\)]?'\r\n\r\nconst RFC3966_PHONE_DIGIT_ = '(' + '[' + VALID_DIGITS + ']' + '|' + RFC3966_VISUAL_SEPARATOR_ + ')'\r\n\r\nconst RFC3966_GLOBAL_NUMBER_DIGITS_ =\r\n\t'^' +\r\n\t'\\\\' +\r\n\tPLUS_SIGN +\r\n\tRFC3966_PHONE_DIGIT_ +\r\n\t'*' +\r\n\t'[' + VALID_DIGITS + ']' +\r\n\tRFC3966_PHONE_DIGIT_ +\r\n\t'*' +\r\n\t'$'\r\n\r\n/**\r\n * Regular expression of valid global-number-digits for the phone-context\r\n * parameter, following the syntax defined in RFC3966.\r\n */\r\nconst RFC3966_GLOBAL_NUMBER_DIGITS_PATTERN_ = new RegExp(RFC3966_GLOBAL_NUMBER_DIGITS_, 'g')\r\n\r\n// In this port of Google's library, we don't accept alpha characters in phone numbers.\r\n// const ALPHANUM_ = VALID_ALPHA_ + VALID_DIGITS\r\nconst ALPHANUM_ = VALID_DIGITS\r\n\r\nconst RFC3966_DOMAINLABEL_ = '[' + ALPHANUM_ + ']+((\\\\-)*[' + ALPHANUM_ + '])*'\r\n\r\nconst VALID_ALPHA_ = 'a-zA-Z'\r\nconst RFC3966_TOPLABEL_ = '[' + VALID_ALPHA_ + ']+((\\\\-)*[' + ALPHANUM_ + '])*'\r\n\r\nconst RFC3966_DOMAINNAME_ = '^(' + RFC3966_DOMAINLABEL_ + '\\\\.)*' + RFC3966_TOPLABEL_ + '\\\\.?$'\r\n\r\n/**\r\n * Regular expression of valid domainname for the phone-context parameter,\r\n * following the syntax defined in RFC3966.\r\n */\r\nconst RFC3966_DOMAINNAME_PATTERN_ = new RegExp(RFC3966_DOMAINNAME_, 'g')\r\n\r\nexport const RFC3966_PREFIX_ = 'tel:'\r\nexport const RFC3966_PHONE_CONTEXT_ = ';phone-context='\r\nexport const RFC3966_ISDN_SUBADDRESS_ = ';isub='\r\n\r\n/**\r\n * Extracts the value of the phone-context parameter of `numberToExtractFrom`,\r\n * following the syntax defined in RFC3966.\r\n *\r\n * @param {string} numberToExtractFrom\r\n * @return {string|null} the extracted string (possibly empty), or `null` if no phone-context parameter is found.\r\n */\r\nexport default function extractPhoneContext(numberToExtractFrom) {\r\n\tconst indexOfPhoneContext = numberToExtractFrom.indexOf(RFC3966_PHONE_CONTEXT_)\r\n\t// If no phone-context parameter is present\r\n\tif (indexOfPhoneContext < 0) {\r\n\t\treturn null\r\n\t}\r\n\r\n\tconst phoneContextStart = indexOfPhoneContext + RFC3966_PHONE_CONTEXT_.length\r\n\t// If phone-context parameter is empty\r\n\tif (phoneContextStart >= numberToExtractFrom.length) {\r\n\t\treturn ''\r\n\t}\r\n\r\n\tconst phoneContextEnd = numberToExtractFrom.indexOf(';', phoneContextStart)\r\n\t// If phone-context is not the last parameter\r\n\tif (phoneContextEnd >= 0) {\r\n\t\treturn numberToExtractFrom.substring(phoneContextStart, phoneContextEnd)\r\n\t} else {\r\n\t\treturn numberToExtractFrom.substring(phoneContextStart)\r\n\t}\r\n}\r\n\r\n/**\r\n * Returns whether the value of phoneContext follows the syntax defined in RFC3966.\r\n *\r\n * @param {string|null} phoneContext\r\n * @return {boolean}\r\n */\r\nexport function isPhoneContextValid(phoneContext) {\r\n\tif (phoneContext === null) {\r\n\t\treturn true\r\n\t}\r\n\r\n\tif (phoneContext.length === 0) {\r\n\t\treturn false\r\n\t}\r\n\r\n\t// Does phone-context value match pattern of global-number-digits or domainname.\r\n\treturn RFC3966_GLOBAL_NUMBER_DIGITS_PATTERN_.test(phoneContext) ||\r\n\t\tRFC3966_DOMAINNAME_PATTERN_.test(phoneContext)\r\n}"],"mappings":";;;;;;;;;AAMA;;AANA;AACA;AACA;AACA;AACA;AAOO,IAAMA,SAAS,GAAG,GAAlB;;AAEP,IAAMC,yBAAyB,GAAG,iBAAlC;AAEA,IAAMC,oBAAoB,GAAG,MAAM,GAAN,GAAYC,uBAAZ,GAA2B,GAA3B,GAAiC,GAAjC,GAAuCF,yBAAvC,GAAmE,GAAhG;AAEA,IAAMG,6BAA6B,GAClC,MACA,IADA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CAchE;;EACA,IAAIE,eAAe,IAAI,CAAvB,EAA0B;IACzB,OAAOL,mBAAmB,CAACM,SAApB,CAA8BH,iBAA9B,EAAiDE,eAAjD,CAAP;EACA,CAFD,MAEO;IACN,OAAOL,mBAAmB,CAACM,SAApB,CAA8BH,iBAA9B,CAAP;EACA;AACD;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASI,mBAAT,CAA6BC,YAA7B,EAA2C;EACjD,IAAIA,YAAY,KAAK,IAArB,EAA2B;IAC1B,OAAO,IAAP;EACA;;EAED,IAAIA,YAAY,CAACJ,MAAb,KAAwB,CAA5B,EAA+B;IAC9B,OAAO,KAAP;EACA,CAPgD,CASjD;;;EACA,OAAOhB,qCAAqC,CAACqB,IAAtC,CAA2CD,YAA3C,KACNb,2BAA2B,CAACc,IAA5B,CAAiCD,YAAjC,CADD;AAEA"}
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+
3
+ var _parsePhoneNumber = _interopRequireDefault(require("../parsePhoneNumber.js"));
4
+
5
+ var _PhoneNumber = _interopRequireDefault(require("../PhoneNumber.js"));
6
+
7
+ var _metadataMin = _interopRequireDefault(require("../../metadata.min.json"));
8
+
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
+
11
+ function parsePhoneNumber() {
12
+ for (var _len = arguments.length, parameters = new Array(_len), _key = 0; _key < _len; _key++) {
13
+ parameters[_key] = arguments[_key];
14
+ }
15
+
16
+ parameters.push(_metadataMin["default"]);
17
+ return _parsePhoneNumber["default"].apply(this, parameters);
18
+ }
19
+
20
+ describe('extractPhoneContext', function () {
21
+ it('should parse RFC 3966 phone number URIs', function () {
22
+ // context = ";phone-context=" descriptor
23
+ // descriptor = domainname / global-number-digits
24
+ var NZ_NUMBER = new _PhoneNumber["default"]('64', '33316005', _metadataMin["default"]); // Valid global-phone-digits
25
+
26
+ expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=+64'), NZ_NUMBER);
27
+ expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=+64;{this isn\'t part of phone-context anymore!}'), NZ_NUMBER);
28
+ var nzFromPhoneContext = new _PhoneNumber["default"]('64', '3033316005', _metadataMin["default"]);
29
+ expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=+64-3'), nzFromPhoneContext);
30
+ var brFromPhoneContext = new _PhoneNumber["default"]('55', '5033316005', _metadataMin["default"]);
31
+ expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=+(555)'), brFromPhoneContext);
32
+ var usFromPhoneContext = new _PhoneNumber["default"]('1', '23033316005', _metadataMin["default"]);
33
+ expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=+-1-2.3()'), usFromPhoneContext); // Valid domainname.
34
+
35
+ expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=abc.nz', 'NZ'), NZ_NUMBER);
36
+ expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=www.PHONE-numb3r.com', 'NZ'), NZ_NUMBER);
37
+ expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=a', 'NZ'), NZ_NUMBER);
38
+ expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=3phone.J.', 'NZ'), NZ_NUMBER);
39
+ expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;phone-context=a--z', 'NZ'), NZ_NUMBER); // Should strip ISDN subaddress.
40
+
41
+ expectPhoneNumbersToBeEqual(parsePhoneNumber('tel:033316005;isub=/@;phone-context=+64', 'NZ'), NZ_NUMBER); // // Should support incorrectly-written RFC 3966 phone numbers:
42
+ // // the ones written without a `tel:` prefix.
43
+ // expectPhoneNumbersToBeEqual(
44
+ // parsePhoneNumber('033316005;phone-context=+64', 'NZ'),
45
+ // NZ_NUMBER
46
+ // )
47
+ // Invalid descriptor.
48
+
49
+ expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=');
50
+ expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=+');
51
+ expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=64');
52
+ expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=++64');
53
+ expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=+abc');
54
+ expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=.');
55
+ expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=3phone');
56
+ expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=a-.nz');
57
+ expectToThrowForInvalidPhoneContext('tel:033316005;phone-context=a{b}c');
58
+ });
59
+ });
60
+
61
+ function expectToThrowForInvalidPhoneContext(string) {
62
+ expect(parsePhoneNumber(string)).to.be.undefined;
63
+ }
64
+
65
+ function expectPhoneNumbersToBeEqual(phoneNumber1, phoneNumber2) {
66
+ if (!phoneNumber1 || !phoneNumber2) {
67
+ return false;
68
+ }
69
+
70
+ return phoneNumber1.number === phoneNumber2.number && phoneNumber1.ext === phoneNumber2.ext;
71
+ }
72
+ //# sourceMappingURL=extractPhoneContext.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractPhoneContext.test.js","names":["parsePhoneNumber","parameters","push","metadata","parsePhoneNumber_","apply","describe","it","NZ_NUMBER","PhoneNumber","expectPhoneNumbersToBeEqual","nzFromPhoneContext","brFromPhoneContext","usFromPhoneContext","expectToThrowForInvalidPhoneContext","string","expect","to","be","undefined","phoneNumber1","phoneNumber2","number","ext"],"sources":["../../source/helpers/extractPhoneContext.test.js"],"sourcesContent":["import parsePhoneNumber_ from '../parsePhoneNumber.js'\r\nimport PhoneNumber from '../PhoneNumber.js'\r\nimport metadata from '../../metadata.min.json' assert { type: 'json' }\r\n\r\nfunction parsePhoneNumber(...parameters) {\r\n\tparameters.push(metadata)\r\n\treturn parsePhoneNumber_.apply(this, parameters)\r\n}\r\n\r\ndescribe('extractPhoneContext', function() {\r\n\tit('should parse RFC 3966 phone number URIs', function() {\r\n\t\t// context = \";phone-context=\" descriptor\r\n\t\t// descriptor = domainname / global-number-digits\r\n\r\n\t\tconst NZ_NUMBER = new PhoneNumber('64', '33316005', metadata)\r\n\r\n\t\t// Valid global-phone-digits\r\n\t\texpectPhoneNumbersToBeEqual(\r\n\t\t\tparsePhoneNumber('tel:033316005;phone-context=+64'),\r\n\t\t\tNZ_NUMBER\r\n\t\t)\r\n\r\n\t\texpectPhoneNumbersToBeEqual(\r\n\t\t\tparsePhoneNumber('tel:033316005;phone-context=+64;{this isn\\'t part of phone-context anymore!}'),\r\n\t\t\tNZ_NUMBER\r\n\t\t)\r\n\r\n\t\tconst nzFromPhoneContext = new PhoneNumber('64', '3033316005', metadata)\r\n\t\texpectPhoneNumbersToBeEqual(\r\n\t\t\tparsePhoneNumber('tel:033316005;phone-context=+64-3'),\r\n\t\t\tnzFromPhoneContext\r\n\t\t)\r\n\r\n\t\tconst brFromPhoneContext = new PhoneNumber('55', '5033316005', metadata)\r\n\t\texpectPhoneNumbersToBeEqual(\r\n\t\t\tparsePhoneNumber('tel:033316005;phone-context=+(555)'),\r\n\t\t\tbrFromPhoneContext\r\n\t\t)\r\n\r\n\t\tconst usFromPhoneContext = new PhoneNumber('1', '23033316005', metadata)\r\n\t\texpectPhoneNumbersToBeEqual(\r\n\t\t\tparsePhoneNumber('tel:033316005;phone-context=+-1-2.3()'),\r\n\t\t\tusFromPhoneContext\r\n\t\t)\r\n\r\n\t\t// Valid domainname.\r\n\t\texpectPhoneNumbersToBeEqual(\r\n\t\t\tparsePhoneNumber('tel:033316005;phone-context=abc.nz', 'NZ'),\r\n\t\t\tNZ_NUMBER\r\n\t\t)\r\n\t\texpectPhoneNumbersToBeEqual(\r\n\t\t\tparsePhoneNumber('tel:033316005;phone-context=www.PHONE-numb3r.com', 'NZ'),\r\n\t\t\tNZ_NUMBER\r\n\t\t)\r\n\t\texpectPhoneNumbersToBeEqual(\r\n\t\t\tparsePhoneNumber('tel:033316005;phone-context=a', 'NZ'),\r\n\t\t\tNZ_NUMBER\r\n\t\t)\r\n\t\texpectPhoneNumbersToBeEqual(\r\n\t\t\tparsePhoneNumber('tel:033316005;phone-context=3phone.J.', 'NZ'),\r\n\t\t\tNZ_NUMBER\r\n\t\t)\r\n\t\texpectPhoneNumbersToBeEqual(\r\n\t\t\tparsePhoneNumber('tel:033316005;phone-context=a--z', 'NZ'),\r\n\t\t\tNZ_NUMBER\r\n\t\t)\r\n\r\n\t\t// Should strip ISDN subaddress.\r\n\t\texpectPhoneNumbersToBeEqual(\r\n\t\t\tparsePhoneNumber('tel:033316005;isub=/@;phone-context=+64', 'NZ'),\r\n\t\t\tNZ_NUMBER\r\n\t\t)\r\n\r\n\t\t// // Should support incorrectly-written RFC 3966 phone numbers:\r\n\t\t// // the ones written without a `tel:` prefix.\r\n\t\t// expectPhoneNumbersToBeEqual(\r\n\t\t// \tparsePhoneNumber('033316005;phone-context=+64', 'NZ'),\r\n\t\t// \tNZ_NUMBER\r\n\t\t// )\r\n\r\n\t\t// Invalid descriptor.\r\n\t\texpectToThrowForInvalidPhoneContext('tel:033316005;phone-context=')\r\n\t\texpectToThrowForInvalidPhoneContext('tel:033316005;phone-context=+')\r\n\t\texpectToThrowForInvalidPhoneContext('tel:033316005;phone-context=64')\r\n\t\texpectToThrowForInvalidPhoneContext('tel:033316005;phone-context=++64')\r\n\t\texpectToThrowForInvalidPhoneContext('tel:033316005;phone-context=+abc')\r\n\t\texpectToThrowForInvalidPhoneContext('tel:033316005;phone-context=.')\r\n\t\texpectToThrowForInvalidPhoneContext('tel:033316005;phone-context=3phone')\r\n\t\texpectToThrowForInvalidPhoneContext('tel:033316005;phone-context=a-.nz')\r\n\t\texpectToThrowForInvalidPhoneContext('tel:033316005;phone-context=a{b}c')\r\n\t})\r\n})\r\n\r\nfunction expectToThrowForInvalidPhoneContext(string) {\r\n\texpect(parsePhoneNumber(string)).to.be.undefined\r\n}\r\n\r\nfunction expectPhoneNumbersToBeEqual(phoneNumber1, phoneNumber2) {\r\n\tif (!phoneNumber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b,KAAwBD,YAAY,CAACC,MAArC,IACNF,YAAY,CAACG,GAAb,KAAqBF,YAAY,CAACE,GADnC;AAEA"}
package/build/parse.js CHANGED
@@ -23,8 +23,6 @@ var _getCountryCallingCode = _interopRequireDefault(require("./getCountryCalling
23
23
 
24
24
  var _isPossible = require("./isPossible.js");
25
25
 
26
- var _RFC = require("./helpers/RFC3966.js");
27
-
28
26
  var _PhoneNumber = _interopRequireDefault(require("./PhoneNumber.js"));
29
27
 
30
28
  var _matchesEntirely = _interopRequireDefault(require("./helpers/matchesEntirely.js"));
@@ -37,6 +35,8 @@ var _stripIddPrefix = _interopRequireDefault(require("./helpers/stripIddPrefix.j
37
35
 
38
36
  var _getCountryByCallingCode = _interopRequireDefault(require("./helpers/getCountryByCallingCode.js"));
39
37
 
38
+ var _extractFormattedPhoneNumberFromPossibleRfc3966NumberUri = _interopRequireDefault(require("./helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js"));
39
+
40
40
  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); }
41
41
 
42
42
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -47,6 +47,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
47
47
  // `phonenumberutil.js` of December 31th, 2018.
48
48
  //
49
49
  // https://github.com/googlei18n/libphonenumber/commits/master/javascript/i18n/phonenumbers/phonenumberutil.js
50
+ // import { parseRFC3966 } from './helpers/RFC3966.js'
50
51
  // We don't allow input strings for parsing to be longer than 250 chars.
51
52
  // This prevents malicious input from consuming CPU.
52
53
  var MAX_INPUT_STRING_LENGTH = 250; // This consists of the plus symbol, digits, and arabic-indic digits.
@@ -118,6 +119,7 @@ function parse(text, options, metadata) {
118
119
  country = _parsePhoneNumber.country,
119
120
  nationalNumber = _parsePhoneNumber.nationalNumber,
120
121
  countryCallingCode = _parsePhoneNumber.countryCallingCode,
122
+ countryCallingCodeSource = _parsePhoneNumber.countryCallingCodeSource,
121
123
  carrierCode = _parsePhoneNumber.carrierCode;
122
124
 
123
125
  if (!metadata.hasSelectedNumberingPlan()) {
@@ -174,6 +176,7 @@ function parse(text, options, metadata) {
174
176
  phoneNumber.ext = ext;
175
177
  }
176
178
 
179
+ phoneNumber.__countryCallingCodeSource = countryCallingCodeSource;
177
180
  return phoneNumber;
178
181
  } // Check if national phone number pattern matches the number.
179
182
  // National number pattern is different for each country,
@@ -211,7 +214,7 @@ function parse(text, options, metadata) {
211
214
  */
212
215
 
213
216
 
214
- function extractFormattedPhoneNumber(text, extract, throwOnError) {
217
+ function _extractFormattedPhoneNumber(text, extract, throwOnError) {
215
218
  if (!text) {
216
219
  return;
217
220
  }
@@ -248,12 +251,16 @@ function extractFormattedPhoneNumber(text, extract, throwOnError) {
248
251
 
249
252
 
250
253
  function parseInput(text, v2, extract) {
251
- // Parse RFC 3966 phone number URI.
252
- if (text && text.indexOf('tel:') === 0) {
253
- return (0, _RFC.parseRFC3966)(text);
254
- }
255
-
256
- var number = extractFormattedPhoneNumber(text, extract, v2); // If the phone number is not viable, then abort.
254
+ // // Parse RFC 3966 phone number URI.
255
+ // if (text && text.indexOf('tel:') === 0) {
256
+ // return parseRFC3966(text)
257
+ // }
258
+ // let number = extractFormattedPhoneNumber(text, extract, v2)
259
+ var number = (0, _extractFormattedPhoneNumberFromPossibleRfc3966NumberUri["default"])(text, {
260
+ extractFormattedPhoneNumber: function extractFormattedPhoneNumber(text) {
261
+ return _extractFormattedPhoneNumber(text, extract, v2);
262
+ }
263
+ }); // If the phone number is not viable, then abort.
257
264
 
258
265
  if (!number) {
259
266
  return {};
@@ -311,6 +318,7 @@ function result(country, nationalNumber, ext) {
311
318
  function parsePhoneNumber(formattedPhoneNumber, defaultCountry, defaultCallingCode, metadata) {
312
319
  // Extract calling code from phone number.
313
320
  var _extractCountryCallin = (0, _extractCountryCallingCode["default"])((0, _parseIncompletePhoneNumber["default"])(formattedPhoneNumber), defaultCountry, defaultCallingCode, metadata.metadata),
321
+ countryCallingCodeSource = _extractCountryCallin.countryCallingCodeSource,
314
322
  countryCallingCode = _extractCountryCallin.countryCallingCode,
315
323
  number = _extractCountryCallin.number; // Choose a country by `countryCallingCode`.
316
324
 
@@ -340,6 +348,7 @@ function parsePhoneNumber(formattedPhoneNumber, defaultCountry, defaultCallingCo
340
348
 
341
349
  if (!number) {
342
350
  return {
351
+ countryCallingCodeSource: countryCallingCodeSource,
343
352
  countryCallingCode: countryCallingCode
344
353
  };
345
354
  }
@@ -375,6 +384,7 @@ function parsePhoneNumber(formattedPhoneNumber, defaultCountry, defaultCallingCo
375
384
  return {
376
385
  country: country,
377
386
  countryCallingCode: countryCallingCode,
387
+ countryCallingCodeSource: countryCallingCodeSource,
378
388
  nationalNumber: nationalNumber,
379
389
  carrierCode: carrierCode
380
390
  };