libphonenumber-js 1.13.7 → 1.13.8

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 (830) hide show
  1. package/.gitlab-ci.yml +50 -50
  2. package/AUTHORS +4 -4
  3. package/CHANGELOG.md +984 -971
  4. package/CODE_OF_CONDUCT.md +78 -78
  5. package/LICENSE +21 -21
  6. package/LICENSE.Apache +175 -175
  7. package/README.md +2110 -2110
  8. package/build/AsYouType.js +70 -70
  9. package/build/AsYouType.js.map +1 -1
  10. package/build/AsYouType.test.js.map +1 -1
  11. package/build/AsYouTypeFormatter.PatternMatcher.js +6 -6
  12. package/build/AsYouTypeFormatter.PatternMatcher.js.map +1 -1
  13. package/build/AsYouTypeFormatter.PatternMatcher.test.js.map +1 -1
  14. package/build/AsYouTypeFormatter.PatternParser.js.map +1 -1
  15. package/build/AsYouTypeFormatter.PatternParser.test.js.map +1 -1
  16. package/build/AsYouTypeFormatter.complete.js.map +1 -1
  17. package/build/AsYouTypeFormatter.js +11 -11
  18. package/build/AsYouTypeFormatter.js.map +1 -1
  19. package/build/AsYouTypeFormatter.util.js.map +1 -1
  20. package/build/AsYouTypeFormatter.util.test.js.map +1 -1
  21. package/build/AsYouTypeParser.js +26 -26
  22. package/build/AsYouTypeParser.js.map +1 -1
  23. package/build/AsYouTypeState.js +6 -6
  24. package/build/AsYouTypeState.js.map +1 -1
  25. package/build/ParseError.js.map +1 -1
  26. package/build/PhoneNumber.js +5 -5
  27. package/build/PhoneNumber.js.map +1 -1
  28. package/build/PhoneNumber.test.js.map +1 -1
  29. package/build/PhoneNumberMatcher.js +60 -60
  30. package/build/PhoneNumberMatcher.js.map +1 -1
  31. package/build/PhoneNumberMatcher.test.js.map +1 -1
  32. package/build/constants.js.map +1 -1
  33. package/build/findNumbers/LRUCache.js.map +1 -1
  34. package/build/findNumbers/Leniency.js +34 -34
  35. package/build/findNumbers/Leniency.js.map +1 -1
  36. package/build/findNumbers/RegExpCache.js.map +1 -1
  37. package/build/findNumbers/isValidCandidate.js +14 -14
  38. package/build/findNumbers/isValidCandidate.js.map +1 -1
  39. package/build/findNumbers/isValidPreCandidate.js.map +1 -1
  40. package/build/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js +6 -6
  41. package/build/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js.map +1 -1
  42. package/build/findNumbers/parsePreCandidate.js.map +1 -1
  43. package/build/findNumbers/utf-8.js +19 -19
  44. package/build/findNumbers/utf-8.js.map +1 -1
  45. package/build/findNumbers/util.js +3 -3
  46. package/build/findNumbers/util.js.map +1 -1
  47. package/build/findNumbers/util.test.js.map +1 -1
  48. package/build/findPhoneNumbersInText.js.map +1 -1
  49. package/build/findPhoneNumbersInText.test.js.map +1 -1
  50. package/build/format.js +14 -14
  51. package/build/format.js.map +1 -1
  52. package/build/format.test.js.map +1 -1
  53. package/build/formatIncompletePhoneNumber.js +7 -7
  54. package/build/formatIncompletePhoneNumber.js.map +1 -1
  55. package/build/formatIncompletePhoneNumber.test.js.map +1 -1
  56. package/build/formatPhoneNumberForMobileDialing.js +35 -35
  57. package/build/formatPhoneNumberForMobileDialing.js.map +1 -1
  58. package/build/getCountries.js.map +1 -1
  59. package/build/getCountries.test.js.map +1 -1
  60. package/build/getCountryCallingCode.js.map +1 -1
  61. package/build/getCountryCallingCode.test.js.map +1 -1
  62. package/build/getExampleNumber.js.map +1 -1
  63. package/build/getExampleNumber.test.js.map +1 -1
  64. package/build/helpers/RFC3966.js +6 -6
  65. package/build/helpers/RFC3966.js.map +1 -1
  66. package/build/helpers/RFC3966.test.js.map +1 -1
  67. package/build/helpers/applyInternationalSeparatorStyle.js.map +1 -1
  68. package/build/helpers/applyInternationalSeparatorStyle.test.js.map +1 -1
  69. package/build/helpers/checkNumberLength.js +15 -15
  70. package/build/helpers/checkNumberLength.js.map +1 -1
  71. package/build/helpers/checkNumberLength.test.js.map +1 -1
  72. package/build/helpers/extension/createExtensionPattern.js +10 -10
  73. package/build/helpers/extension/createExtensionPattern.js.map +1 -1
  74. package/build/helpers/extension/extractExtension.js.map +1 -1
  75. package/build/helpers/extractCountryCallingCode.js +23 -23
  76. package/build/helpers/extractCountryCallingCode.js.map +1 -1
  77. package/build/helpers/extractCountryCallingCode.test.js.map +1 -1
  78. package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +9 -9
  79. package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -1
  80. package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.test.js.map +1 -1
  81. package/build/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js +4 -4
  82. package/build/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js.map +1 -1
  83. package/build/helpers/extractNationalNumber.js +15 -15
  84. package/build/helpers/extractNationalNumber.js.map +1 -1
  85. package/build/helpers/extractNationalNumber.test.js.map +1 -1
  86. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +12 -12
  87. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -1
  88. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js.map +1 -1
  89. package/build/helpers/extractPhoneContext.js +17 -17
  90. package/build/helpers/extractPhoneContext.js.map +1 -1
  91. package/build/helpers/extractPhoneContext.test.js.map +1 -1
  92. package/build/helpers/formatNationalNumberUsingFormat.js.map +1 -1
  93. package/build/helpers/getCountryAndCallingCodeFromOneOfThem.js.map +1 -1
  94. package/build/helpers/getCountryByCallingCode.js +7 -7
  95. package/build/helpers/getCountryByCallingCode.js.map +1 -1
  96. package/build/helpers/getCountryByNationalNumber.js +7 -7
  97. package/build/helpers/getCountryByNationalNumber.js.map +1 -1
  98. package/build/helpers/getIddPrefix.js +8 -8
  99. package/build/helpers/getIddPrefix.js.map +1 -1
  100. package/build/helpers/getNumberType.js.map +1 -1
  101. package/build/helpers/getNumberType.test.js.map +1 -1
  102. package/build/helpers/getPossibleCountriesForNumber.js +6 -6
  103. package/build/helpers/getPossibleCountriesForNumber.js.map +1 -1
  104. package/build/helpers/isCallingCode.js.map +1 -1
  105. package/build/helpers/isCallingCode.test.js.map +1 -1
  106. package/build/helpers/isCountryCode.js.map +1 -1
  107. package/build/helpers/isCountryCode.test.js.map +1 -1
  108. package/build/helpers/isObject.js.map +1 -1
  109. package/build/helpers/isViablePhoneNumber.js.map +1 -1
  110. package/build/helpers/matchesEntirely.js +4 -4
  111. package/build/helpers/matchesEntirely.js.map +1 -1
  112. package/build/helpers/matchesEntirely.test.js.map +1 -1
  113. package/build/helpers/mergeArrays.js +5 -5
  114. package/build/helpers/mergeArrays.js.map +1 -1
  115. package/build/helpers/mergeArrays.test.js.map +1 -1
  116. package/build/helpers/parseDigits.js +12 -12
  117. package/build/helpers/parseDigits.js.map +1 -1
  118. package/build/helpers/parseDigits.test.js.map +1 -1
  119. package/build/helpers/stripIddPrefix.js.map +1 -1
  120. package/build/helpers/stripIddPrefix.test.js.map +1 -1
  121. package/build/isPossible.js +17 -17
  122. package/build/isPossible.js.map +1 -1
  123. package/build/isPossible.test.js.map +1 -1
  124. package/build/isPossiblePhoneNumber.js.map +1 -1
  125. package/build/isPossiblePhoneNumber.test.js.map +1 -1
  126. package/build/isValid.js +33 -33
  127. package/build/isValid.js.map +1 -1
  128. package/build/isValid.test.js.map +1 -1
  129. package/build/isValidPhoneNumber.js.map +1 -1
  130. package/build/isValidPhoneNumber.test.js.map +1 -1
  131. package/build/legacy/PhoneNumberSearch.js +4 -4
  132. package/build/legacy/PhoneNumberSearch.js.map +1 -1
  133. package/build/legacy/findNumbers.js.map +1 -1
  134. package/build/legacy/findNumbers.test.js.map +1 -1
  135. package/build/legacy/findPhoneNumbers.js +2 -2
  136. package/build/legacy/findPhoneNumbers.js.map +1 -1
  137. package/build/legacy/findPhoneNumbers.test.js.map +1 -1
  138. package/build/legacy/findPhoneNumbersInitialImplementation.js +16 -16
  139. package/build/legacy/findPhoneNumbersInitialImplementation.js.map +1 -1
  140. package/build/legacy/format.js.map +1 -1
  141. package/build/legacy/format.test.js.map +1 -1
  142. package/build/legacy/getNumberType.js.map +1 -1
  143. package/build/legacy/getNumberType.test.js.map +1 -1
  144. package/build/legacy/isPossibleNumber.js +13 -13
  145. package/build/legacy/isPossibleNumber.js.map +1 -1
  146. package/build/legacy/isPossibleNumber.test.js.map +1 -1
  147. package/build/legacy/isValidNumber.js.map +1 -1
  148. package/build/legacy/isValidNumber.test.js.map +1 -1
  149. package/build/legacy/isValidNumberForRegion.js.map +1 -1
  150. package/build/legacy/isValidNumberForRegion.test.js.map +1 -1
  151. package/build/legacy/isValidNumberForRegion_.js +4 -4
  152. package/build/legacy/isValidNumberForRegion_.js.map +1 -1
  153. package/build/legacy/parse.js.map +1 -1
  154. package/build/legacy/parse.test.js.map +1 -1
  155. package/build/legacy/searchNumbers.js +2 -2
  156. package/build/legacy/searchNumbers.js.map +1 -1
  157. package/build/legacy/searchNumbers.test.js.map +1 -1
  158. package/build/metadata.js +40 -40
  159. package/build/metadata.js.map +1 -1
  160. package/build/metadata.test.js.map +1 -1
  161. package/build/normalizeArguments.js.map +1 -1
  162. package/build/parse.js +36 -36
  163. package/build/parse.js.map +1 -1
  164. package/build/parse.test.js.map +1 -1
  165. package/build/parseIncompletePhoneNumber.js +24 -24
  166. package/build/parseIncompletePhoneNumber.js.map +1 -1
  167. package/build/parseIncompletePhoneNumber.test.js.map +1 -1
  168. package/build/parsePhoneNumber.js.map +1 -1
  169. package/build/parsePhoneNumber.test.js.map +1 -1
  170. package/build/parsePhoneNumberWithError.js.map +1 -1
  171. package/build/parsePhoneNumberWithError.test.js.map +1 -1
  172. package/build/parsePhoneNumberWithError_.js.map +1 -1
  173. package/build/parsePhoneNumber_.js.map +1 -1
  174. package/build/searchPhoneNumbersInText.js.map +1 -1
  175. package/build/searchPhoneNumbersInText.test.js.map +1 -1
  176. package/build/tools/semver-compare.js.map +1 -1
  177. package/build/tools/semver-compare.test.js.map +1 -1
  178. package/build/validatePhoneNumberLength.js.map +1 -1
  179. package/build/validatePhoneNumberLength.test.js.map +1 -1
  180. package/bundle/libphonenumber-js.min.js +1 -1
  181. package/bundle/libphonenumber-js.min.js.map +1 -1
  182. package/bundle/libphonenumber-max.js +1 -1
  183. package/bundle/libphonenumber-max.js.map +1 -1
  184. package/bundle/libphonenumber-min.js +1 -1
  185. package/bundle/libphonenumber-min.js.map +1 -1
  186. package/bundle/libphonenumber-mobile.js +1 -1
  187. package/bundle/libphonenumber-mobile.js.map +1 -1
  188. package/core/es6/index.d.cts +2 -2
  189. package/core/es6/index.d.ts +2 -2
  190. package/core/es6/index.js +39 -39
  191. package/core/es6/package.json +12 -12
  192. package/core/index.cjs +57 -57
  193. package/core/index.cjs.js +62 -62
  194. package/core/index.d.cts +150 -150
  195. package/core/index.d.ts +150 -150
  196. package/core/index.js +39 -39
  197. package/core/package.json +14 -14
  198. package/custom.d.ts +209 -209
  199. package/custom.js +78 -78
  200. package/es6/AsYouType.js +70 -70
  201. package/es6/AsYouType.js.map +1 -1
  202. package/es6/AsYouType.test.js.map +1 -1
  203. package/es6/AsYouTypeFormatter.PatternMatcher.js +6 -6
  204. package/es6/AsYouTypeFormatter.PatternMatcher.js.map +1 -1
  205. package/es6/AsYouTypeFormatter.PatternMatcher.test.js.map +1 -1
  206. package/es6/AsYouTypeFormatter.PatternParser.js.map +1 -1
  207. package/es6/AsYouTypeFormatter.PatternParser.test.js.map +1 -1
  208. package/es6/AsYouTypeFormatter.complete.js.map +1 -1
  209. package/es6/AsYouTypeFormatter.js +11 -11
  210. package/es6/AsYouTypeFormatter.js.map +1 -1
  211. package/es6/AsYouTypeFormatter.util.js.map +1 -1
  212. package/es6/AsYouTypeFormatter.util.test.js.map +1 -1
  213. package/es6/AsYouTypeParser.js +26 -26
  214. package/es6/AsYouTypeParser.js.map +1 -1
  215. package/es6/AsYouTypeState.js +6 -6
  216. package/es6/AsYouTypeState.js.map +1 -1
  217. package/es6/ParseError.js.map +1 -1
  218. package/es6/PhoneNumber.js +5 -5
  219. package/es6/PhoneNumber.js.map +1 -1
  220. package/es6/PhoneNumber.test.js.map +1 -1
  221. package/es6/PhoneNumberMatcher.js +60 -60
  222. package/es6/PhoneNumberMatcher.js.map +1 -1
  223. package/es6/PhoneNumberMatcher.test.js.map +1 -1
  224. package/es6/constants.js.map +1 -1
  225. package/es6/findNumbers/LRUCache.js.map +1 -1
  226. package/es6/findNumbers/Leniency.js +34 -34
  227. package/es6/findNumbers/Leniency.js.map +1 -1
  228. package/es6/findNumbers/RegExpCache.js.map +1 -1
  229. package/es6/findNumbers/isValidCandidate.js +14 -14
  230. package/es6/findNumbers/isValidCandidate.js.map +1 -1
  231. package/es6/findNumbers/isValidPreCandidate.js.map +1 -1
  232. package/es6/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js +6 -6
  233. package/es6/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js.map +1 -1
  234. package/es6/findNumbers/parsePreCandidate.js.map +1 -1
  235. package/es6/findNumbers/utf-8.js +19 -19
  236. package/es6/findNumbers/utf-8.js.map +1 -1
  237. package/es6/findNumbers/util.js +3 -3
  238. package/es6/findNumbers/util.js.map +1 -1
  239. package/es6/findNumbers/util.test.js.map +1 -1
  240. package/es6/findPhoneNumbersInText.js.map +1 -1
  241. package/es6/findPhoneNumbersInText.test.js.map +1 -1
  242. package/es6/format.js +14 -14
  243. package/es6/format.js.map +1 -1
  244. package/es6/format.test.js.map +1 -1
  245. package/es6/formatIncompletePhoneNumber.js +7 -7
  246. package/es6/formatIncompletePhoneNumber.js.map +1 -1
  247. package/es6/formatIncompletePhoneNumber.test.js.map +1 -1
  248. package/es6/formatPhoneNumberForMobileDialing.js +35 -35
  249. package/es6/formatPhoneNumberForMobileDialing.js.map +1 -1
  250. package/es6/getCountries.js.map +1 -1
  251. package/es6/getCountries.test.js.map +1 -1
  252. package/es6/getCountryCallingCode.js.map +1 -1
  253. package/es6/getCountryCallingCode.test.js.map +1 -1
  254. package/es6/getExampleNumber.js.map +1 -1
  255. package/es6/getExampleNumber.test.js.map +1 -1
  256. package/es6/helpers/RFC3966.js +6 -6
  257. package/es6/helpers/RFC3966.js.map +1 -1
  258. package/es6/helpers/RFC3966.test.js.map +1 -1
  259. package/es6/helpers/applyInternationalSeparatorStyle.js.map +1 -1
  260. package/es6/helpers/applyInternationalSeparatorStyle.test.js.map +1 -1
  261. package/es6/helpers/checkNumberLength.js +15 -15
  262. package/es6/helpers/checkNumberLength.js.map +1 -1
  263. package/es6/helpers/checkNumberLength.test.js.map +1 -1
  264. package/es6/helpers/extension/createExtensionPattern.js +10 -10
  265. package/es6/helpers/extension/createExtensionPattern.js.map +1 -1
  266. package/es6/helpers/extension/extractExtension.js.map +1 -1
  267. package/es6/helpers/extractCountryCallingCode.js +23 -23
  268. package/es6/helpers/extractCountryCallingCode.js.map +1 -1
  269. package/es6/helpers/extractCountryCallingCode.test.js.map +1 -1
  270. package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +9 -9
  271. package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -1
  272. package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.test.js.map +1 -1
  273. package/es6/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js +4 -4
  274. package/es6/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js.map +1 -1
  275. package/es6/helpers/extractNationalNumber.js +15 -15
  276. package/es6/helpers/extractNationalNumber.js.map +1 -1
  277. package/es6/helpers/extractNationalNumber.test.js.map +1 -1
  278. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +12 -12
  279. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -1
  280. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js.map +1 -1
  281. package/es6/helpers/extractPhoneContext.js +17 -17
  282. package/es6/helpers/extractPhoneContext.js.map +1 -1
  283. package/es6/helpers/extractPhoneContext.test.js.map +1 -1
  284. package/es6/helpers/formatNationalNumberUsingFormat.js.map +1 -1
  285. package/es6/helpers/getCountryAndCallingCodeFromOneOfThem.js.map +1 -1
  286. package/es6/helpers/getCountryByCallingCode.js +7 -7
  287. package/es6/helpers/getCountryByCallingCode.js.map +1 -1
  288. package/es6/helpers/getCountryByNationalNumber.js +7 -7
  289. package/es6/helpers/getCountryByNationalNumber.js.map +1 -1
  290. package/es6/helpers/getIddPrefix.js +8 -8
  291. package/es6/helpers/getIddPrefix.js.map +1 -1
  292. package/es6/helpers/getNumberType.js.map +1 -1
  293. package/es6/helpers/getNumberType.test.js.map +1 -1
  294. package/es6/helpers/getPossibleCountriesForNumber.js +6 -6
  295. package/es6/helpers/getPossibleCountriesForNumber.js.map +1 -1
  296. package/es6/helpers/isCallingCode.js.map +1 -1
  297. package/es6/helpers/isCallingCode.test.js.map +1 -1
  298. package/es6/helpers/isCountryCode.js.map +1 -1
  299. package/es6/helpers/isCountryCode.test.js.map +1 -1
  300. package/es6/helpers/isObject.js.map +1 -1
  301. package/es6/helpers/isViablePhoneNumber.js.map +1 -1
  302. package/es6/helpers/matchesEntirely.js +4 -4
  303. package/es6/helpers/matchesEntirely.js.map +1 -1
  304. package/es6/helpers/matchesEntirely.test.js.map +1 -1
  305. package/es6/helpers/mergeArrays.js +5 -5
  306. package/es6/helpers/mergeArrays.js.map +1 -1
  307. package/es6/helpers/mergeArrays.test.js.map +1 -1
  308. package/es6/helpers/parseDigits.js +12 -12
  309. package/es6/helpers/parseDigits.js.map +1 -1
  310. package/es6/helpers/parseDigits.test.js.map +1 -1
  311. package/es6/helpers/stripIddPrefix.js.map +1 -1
  312. package/es6/helpers/stripIddPrefix.test.js.map +1 -1
  313. package/es6/isPossible.js +17 -17
  314. package/es6/isPossible.js.map +1 -1
  315. package/es6/isPossible.test.js.map +1 -1
  316. package/es6/isPossiblePhoneNumber.js.map +1 -1
  317. package/es6/isPossiblePhoneNumber.test.js.map +1 -1
  318. package/es6/isValid.js +33 -33
  319. package/es6/isValid.js.map +1 -1
  320. package/es6/isValid.test.js.map +1 -1
  321. package/es6/isValidPhoneNumber.js.map +1 -1
  322. package/es6/isValidPhoneNumber.test.js.map +1 -1
  323. package/es6/legacy/PhoneNumberSearch.js +4 -4
  324. package/es6/legacy/PhoneNumberSearch.js.map +1 -1
  325. package/es6/legacy/findNumbers.js.map +1 -1
  326. package/es6/legacy/findNumbers.test.js.map +1 -1
  327. package/es6/legacy/findPhoneNumbers.js +2 -2
  328. package/es6/legacy/findPhoneNumbers.js.map +1 -1
  329. package/es6/legacy/findPhoneNumbers.test.js.map +1 -1
  330. package/es6/legacy/findPhoneNumbersInitialImplementation.js +16 -16
  331. package/es6/legacy/findPhoneNumbersInitialImplementation.js.map +1 -1
  332. package/es6/legacy/format.js.map +1 -1
  333. package/es6/legacy/format.test.js.map +1 -1
  334. package/es6/legacy/getNumberType.js.map +1 -1
  335. package/es6/legacy/getNumberType.test.js.map +1 -1
  336. package/es6/legacy/isPossibleNumber.js +13 -13
  337. package/es6/legacy/isPossibleNumber.js.map +1 -1
  338. package/es6/legacy/isPossibleNumber.test.js.map +1 -1
  339. package/es6/legacy/isValidNumber.js.map +1 -1
  340. package/es6/legacy/isValidNumber.test.js.map +1 -1
  341. package/es6/legacy/isValidNumberForRegion.js.map +1 -1
  342. package/es6/legacy/isValidNumberForRegion.test.js.map +1 -1
  343. package/es6/legacy/isValidNumberForRegion_.js +4 -4
  344. package/es6/legacy/isValidNumberForRegion_.js.map +1 -1
  345. package/es6/legacy/parse.js.map +1 -1
  346. package/es6/legacy/parse.test.js.map +1 -1
  347. package/es6/legacy/searchNumbers.js +2 -2
  348. package/es6/legacy/searchNumbers.js.map +1 -1
  349. package/es6/legacy/searchNumbers.test.js.map +1 -1
  350. package/es6/metadata.js +40 -40
  351. package/es6/metadata.js.map +1 -1
  352. package/es6/metadata.test.js.map +1 -1
  353. package/es6/normalizeArguments.js.map +1 -1
  354. package/es6/parse.js +36 -36
  355. package/es6/parse.js.map +1 -1
  356. package/es6/parse.test.js.map +1 -1
  357. package/es6/parseIncompletePhoneNumber.js +24 -24
  358. package/es6/parseIncompletePhoneNumber.js.map +1 -1
  359. package/es6/parseIncompletePhoneNumber.test.js.map +1 -1
  360. package/es6/parsePhoneNumber.js.map +1 -1
  361. package/es6/parsePhoneNumber.test.js.map +1 -1
  362. package/es6/parsePhoneNumberWithError.js.map +1 -1
  363. package/es6/parsePhoneNumberWithError.test.js.map +1 -1
  364. package/es6/parsePhoneNumberWithError_.js.map +1 -1
  365. package/es6/parsePhoneNumber_.js.map +1 -1
  366. package/es6/searchPhoneNumbersInText.js.map +1 -1
  367. package/es6/searchPhoneNumbersInText.test.js.map +1 -1
  368. package/es6/tools/semver-compare.js.map +1 -1
  369. package/es6/tools/semver-compare.test.js.map +1 -1
  370. package/es6/validatePhoneNumberLength.js.map +1 -1
  371. package/es6/validatePhoneNumberLength.test.js.map +1 -1
  372. package/es6-modern/AsYouType.js +70 -70
  373. package/es6-modern/AsYouType.js.map +1 -1
  374. package/es6-modern/AsYouType.test.js.map +1 -1
  375. package/es6-modern/AsYouTypeFormatter.PatternMatcher.js +6 -6
  376. package/es6-modern/AsYouTypeFormatter.PatternMatcher.js.map +1 -1
  377. package/es6-modern/AsYouTypeFormatter.PatternMatcher.test.js.map +1 -1
  378. package/es6-modern/AsYouTypeFormatter.PatternParser.js.map +1 -1
  379. package/es6-modern/AsYouTypeFormatter.PatternParser.test.js.map +1 -1
  380. package/es6-modern/AsYouTypeFormatter.complete.js.map +1 -1
  381. package/es6-modern/AsYouTypeFormatter.js +11 -11
  382. package/es6-modern/AsYouTypeFormatter.js.map +1 -1
  383. package/es6-modern/AsYouTypeFormatter.util.js.map +1 -1
  384. package/es6-modern/AsYouTypeFormatter.util.test.js.map +1 -1
  385. package/es6-modern/AsYouTypeParser.js +26 -26
  386. package/es6-modern/AsYouTypeParser.js.map +1 -1
  387. package/es6-modern/AsYouTypeState.js +6 -6
  388. package/es6-modern/AsYouTypeState.js.map +1 -1
  389. package/es6-modern/ParseError.js.map +1 -1
  390. package/es6-modern/PhoneNumber.js +5 -5
  391. package/es6-modern/PhoneNumber.js.map +1 -1
  392. package/es6-modern/PhoneNumber.test.js.map +1 -1
  393. package/es6-modern/PhoneNumberMatcher.js +60 -60
  394. package/es6-modern/PhoneNumberMatcher.js.map +1 -1
  395. package/es6-modern/PhoneNumberMatcher.test.js.map +1 -1
  396. package/es6-modern/constants.js.map +1 -1
  397. package/es6-modern/findNumbers/LRUCache.js.map +1 -1
  398. package/es6-modern/findNumbers/Leniency.js +34 -34
  399. package/es6-modern/findNumbers/Leniency.js.map +1 -1
  400. package/es6-modern/findNumbers/RegExpCache.js.map +1 -1
  401. package/es6-modern/findNumbers/isValidCandidate.js +14 -14
  402. package/es6-modern/findNumbers/isValidCandidate.js.map +1 -1
  403. package/es6-modern/findNumbers/isValidPreCandidate.js.map +1 -1
  404. package/es6-modern/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js +6 -6
  405. package/es6-modern/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js.map +1 -1
  406. package/es6-modern/findNumbers/parsePreCandidate.js.map +1 -1
  407. package/es6-modern/findNumbers/utf-8.js +19 -19
  408. package/es6-modern/findNumbers/utf-8.js.map +1 -1
  409. package/es6-modern/findNumbers/util.js +3 -3
  410. package/es6-modern/findNumbers/util.js.map +1 -1
  411. package/es6-modern/findNumbers/util.test.js.map +1 -1
  412. package/es6-modern/findPhoneNumbersInText.js.map +1 -1
  413. package/es6-modern/findPhoneNumbersInText.test.js.map +1 -1
  414. package/es6-modern/format.js +14 -14
  415. package/es6-modern/format.js.map +1 -1
  416. package/es6-modern/format.test.js.map +1 -1
  417. package/es6-modern/formatIncompletePhoneNumber.js +7 -7
  418. package/es6-modern/formatIncompletePhoneNumber.js.map +1 -1
  419. package/es6-modern/formatIncompletePhoneNumber.test.js.map +1 -1
  420. package/es6-modern/formatPhoneNumberForMobileDialing.js +35 -35
  421. package/es6-modern/formatPhoneNumberForMobileDialing.js.map +1 -1
  422. package/es6-modern/getCountries.js.map +1 -1
  423. package/es6-modern/getCountries.test.js.map +1 -1
  424. package/es6-modern/getCountryCallingCode.js.map +1 -1
  425. package/es6-modern/getCountryCallingCode.test.js.map +1 -1
  426. package/es6-modern/getExampleNumber.js.map +1 -1
  427. package/es6-modern/getExampleNumber.test.js.map +1 -1
  428. package/es6-modern/helpers/RFC3966.js +6 -6
  429. package/es6-modern/helpers/RFC3966.js.map +1 -1
  430. package/es6-modern/helpers/RFC3966.test.js.map +1 -1
  431. package/es6-modern/helpers/applyInternationalSeparatorStyle.js.map +1 -1
  432. package/es6-modern/helpers/applyInternationalSeparatorStyle.test.js.map +1 -1
  433. package/es6-modern/helpers/checkNumberLength.js +15 -15
  434. package/es6-modern/helpers/checkNumberLength.js.map +1 -1
  435. package/es6-modern/helpers/checkNumberLength.test.js.map +1 -1
  436. package/es6-modern/helpers/extension/createExtensionPattern.js +10 -10
  437. package/es6-modern/helpers/extension/createExtensionPattern.js.map +1 -1
  438. package/es6-modern/helpers/extension/extractExtension.js.map +1 -1
  439. package/es6-modern/helpers/extractCountryCallingCode.js +23 -23
  440. package/es6-modern/helpers/extractCountryCallingCode.js.map +1 -1
  441. package/es6-modern/helpers/extractCountryCallingCode.test.js.map +1 -1
  442. package/es6-modern/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +9 -9
  443. package/es6-modern/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -1
  444. package/es6-modern/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.test.js.map +1 -1
  445. package/es6-modern/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js +4 -4
  446. package/es6-modern/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js.map +1 -1
  447. package/es6-modern/helpers/extractNationalNumber.js +15 -15
  448. package/es6-modern/helpers/extractNationalNumber.js.map +1 -1
  449. package/es6-modern/helpers/extractNationalNumber.test.js.map +1 -1
  450. package/es6-modern/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +12 -12
  451. package/es6-modern/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -1
  452. package/es6-modern/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js.map +1 -1
  453. package/es6-modern/helpers/extractPhoneContext.js +17 -17
  454. package/es6-modern/helpers/extractPhoneContext.js.map +1 -1
  455. package/es6-modern/helpers/extractPhoneContext.test.js.map +1 -1
  456. package/es6-modern/helpers/formatNationalNumberUsingFormat.js.map +1 -1
  457. package/es6-modern/helpers/getCountryAndCallingCodeFromOneOfThem.js.map +1 -1
  458. package/es6-modern/helpers/getCountryByCallingCode.js +7 -7
  459. package/es6-modern/helpers/getCountryByCallingCode.js.map +1 -1
  460. package/es6-modern/helpers/getCountryByNationalNumber.js +7 -7
  461. package/es6-modern/helpers/getCountryByNationalNumber.js.map +1 -1
  462. package/es6-modern/helpers/getIddPrefix.js +8 -8
  463. package/es6-modern/helpers/getIddPrefix.js.map +1 -1
  464. package/es6-modern/helpers/getNumberType.js.map +1 -1
  465. package/es6-modern/helpers/getNumberType.test.js.map +1 -1
  466. package/es6-modern/helpers/getPossibleCountriesForNumber.js +6 -6
  467. package/es6-modern/helpers/getPossibleCountriesForNumber.js.map +1 -1
  468. package/es6-modern/helpers/isCallingCode.js.map +1 -1
  469. package/es6-modern/helpers/isCallingCode.test.js.map +1 -1
  470. package/es6-modern/helpers/isCountryCode.js.map +1 -1
  471. package/es6-modern/helpers/isCountryCode.test.js.map +1 -1
  472. package/es6-modern/helpers/isObject.js.map +1 -1
  473. package/es6-modern/helpers/isViablePhoneNumber.js.map +1 -1
  474. package/es6-modern/helpers/matchesEntirely.js +4 -4
  475. package/es6-modern/helpers/matchesEntirely.js.map +1 -1
  476. package/es6-modern/helpers/matchesEntirely.test.js.map +1 -1
  477. package/es6-modern/helpers/mergeArrays.js +5 -5
  478. package/es6-modern/helpers/mergeArrays.js.map +1 -1
  479. package/es6-modern/helpers/mergeArrays.test.js.map +1 -1
  480. package/es6-modern/helpers/parseDigits.js +12 -12
  481. package/es6-modern/helpers/parseDigits.js.map +1 -1
  482. package/es6-modern/helpers/parseDigits.test.js.map +1 -1
  483. package/es6-modern/helpers/stripIddPrefix.js.map +1 -1
  484. package/es6-modern/helpers/stripIddPrefix.test.js.map +1 -1
  485. package/es6-modern/isPossible.js +17 -17
  486. package/es6-modern/isPossible.js.map +1 -1
  487. package/es6-modern/isPossible.test.js.map +1 -1
  488. package/es6-modern/isPossiblePhoneNumber.js.map +1 -1
  489. package/es6-modern/isPossiblePhoneNumber.test.js.map +1 -1
  490. package/es6-modern/isValid.js +33 -33
  491. package/es6-modern/isValid.js.map +1 -1
  492. package/es6-modern/isValid.test.js.map +1 -1
  493. package/es6-modern/isValidPhoneNumber.js.map +1 -1
  494. package/es6-modern/isValidPhoneNumber.test.js.map +1 -1
  495. package/es6-modern/legacy/PhoneNumberSearch.js +4 -4
  496. package/es6-modern/legacy/PhoneNumberSearch.js.map +1 -1
  497. package/es6-modern/legacy/findNumbers.js.map +1 -1
  498. package/es6-modern/legacy/findNumbers.test.js.map +1 -1
  499. package/es6-modern/legacy/findPhoneNumbers.js +2 -2
  500. package/es6-modern/legacy/findPhoneNumbers.js.map +1 -1
  501. package/es6-modern/legacy/findPhoneNumbers.test.js.map +1 -1
  502. package/es6-modern/legacy/findPhoneNumbersInitialImplementation.js +16 -16
  503. package/es6-modern/legacy/findPhoneNumbersInitialImplementation.js.map +1 -1
  504. package/es6-modern/legacy/format.js.map +1 -1
  505. package/es6-modern/legacy/format.test.js.map +1 -1
  506. package/es6-modern/legacy/getNumberType.js.map +1 -1
  507. package/es6-modern/legacy/getNumberType.test.js.map +1 -1
  508. package/es6-modern/legacy/isPossibleNumber.js +13 -13
  509. package/es6-modern/legacy/isPossibleNumber.js.map +1 -1
  510. package/es6-modern/legacy/isPossibleNumber.test.js.map +1 -1
  511. package/es6-modern/legacy/isValidNumber.js.map +1 -1
  512. package/es6-modern/legacy/isValidNumber.test.js.map +1 -1
  513. package/es6-modern/legacy/isValidNumberForRegion.js.map +1 -1
  514. package/es6-modern/legacy/isValidNumberForRegion.test.js.map +1 -1
  515. package/es6-modern/legacy/isValidNumberForRegion_.js +4 -4
  516. package/es6-modern/legacy/isValidNumberForRegion_.js.map +1 -1
  517. package/es6-modern/legacy/parse.js.map +1 -1
  518. package/es6-modern/legacy/parse.test.js.map +1 -1
  519. package/es6-modern/legacy/searchNumbers.js +2 -2
  520. package/es6-modern/legacy/searchNumbers.js.map +1 -1
  521. package/es6-modern/legacy/searchNumbers.test.js.map +1 -1
  522. package/es6-modern/metadata.js +40 -40
  523. package/es6-modern/metadata.js.map +1 -1
  524. package/es6-modern/metadata.test.js.map +1 -1
  525. package/es6-modern/normalizeArguments.js.map +1 -1
  526. package/es6-modern/parse.js +36 -36
  527. package/es6-modern/parse.js.map +1 -1
  528. package/es6-modern/parse.test.js.map +1 -1
  529. package/es6-modern/parseIncompletePhoneNumber.js +24 -24
  530. package/es6-modern/parseIncompletePhoneNumber.js.map +1 -1
  531. package/es6-modern/parseIncompletePhoneNumber.test.js.map +1 -1
  532. package/es6-modern/parsePhoneNumber.js.map +1 -1
  533. package/es6-modern/parsePhoneNumber.test.js.map +1 -1
  534. package/es6-modern/parsePhoneNumberWithError.js.map +1 -1
  535. package/es6-modern/parsePhoneNumberWithError.test.js.map +1 -1
  536. package/es6-modern/parsePhoneNumberWithError_.js.map +1 -1
  537. package/es6-modern/parsePhoneNumber_.js.map +1 -1
  538. package/es6-modern/searchPhoneNumbersInText.js.map +1 -1
  539. package/es6-modern/searchPhoneNumbersInText.test.js.map +1 -1
  540. package/es6-modern/tools/semver-compare.js.map +1 -1
  541. package/es6-modern/tools/semver-compare.test.js.map +1 -1
  542. package/es6-modern/validatePhoneNumberLength.js.map +1 -1
  543. package/es6-modern/validatePhoneNumberLength.test.js.map +1 -1
  544. package/examples.mobile.json.d.cts +3 -3
  545. package/examples.mobile.json.d.ts +3 -3
  546. package/index.cjs +129 -129
  547. package/index.cjs.js +135 -135
  548. package/index.d.cts +232 -232
  549. package/index.d.ts +232 -232
  550. package/index.es6.exports/PhoneNumberSearch.js +13 -13
  551. package/index.es6.exports/findPhoneNumbers.js +7 -7
  552. package/index.es6.exports/format.js +7 -7
  553. package/index.es6.exports/getNumberType.js +7 -7
  554. package/index.es6.exports/isPossibleNumber.js +9 -9
  555. package/index.es6.exports/isValidNumber.js +9 -9
  556. package/index.es6.exports/isValidNumberForRegion.js +7 -7
  557. package/index.es6.exports/parse.js +7 -7
  558. package/index.es6.exports/searchPhoneNumbers.js +7 -7
  559. package/index.es6.js +5 -5
  560. package/index.js +72 -72
  561. package/max/es6/exports/AsYouType.js +11 -11
  562. package/max/es6/exports/Metadata.js +11 -11
  563. package/max/es6/exports/PhoneNumber.js +11 -11
  564. package/max/es6/exports/PhoneNumberMatcher.js +11 -11
  565. package/max/es6/exports/findNumbers.js +5 -5
  566. package/max/es6/exports/findPhoneNumbersInText.js +5 -5
  567. package/max/es6/exports/formatIncompletePhoneNumber.js +5 -5
  568. package/max/es6/exports/getCountries.js +5 -5
  569. package/max/es6/exports/getCountryCallingCode.js +5 -5
  570. package/max/es6/exports/getExampleNumber.js +5 -5
  571. package/max/es6/exports/getExtPrefix.js +5 -5
  572. package/max/es6/exports/isPossiblePhoneNumber.js +5 -5
  573. package/max/es6/exports/isSupportedCountry.js +5 -5
  574. package/max/es6/exports/isValidPhoneNumber.js +5 -5
  575. package/max/es6/exports/parsePhoneNumber.js +6 -6
  576. package/max/es6/exports/parsePhoneNumberWithError.js +7 -7
  577. package/max/es6/exports/searchNumbers.js +5 -5
  578. package/max/es6/exports/searchPhoneNumbersInText.js +5 -5
  579. package/max/es6/exports/validatePhoneNumberLength.js +5 -5
  580. package/max/es6/exports/withMetadataArgument.js +12 -12
  581. package/max/es6/index.d.cts +2 -2
  582. package/max/es6/index.d.ts +2 -2
  583. package/max/es6/index.js +44 -44
  584. package/max/es6/package.json +12 -12
  585. package/max/exports/AsYouType.js +11 -11
  586. package/max/exports/Metadata.js +11 -11
  587. package/max/exports/PhoneNumber.js +21 -21
  588. package/max/exports/PhoneNumberMatcher.js +11 -11
  589. package/max/exports/findNumbers.js +5 -5
  590. package/max/exports/findPhoneNumbersInText.js +5 -5
  591. package/max/exports/formatIncompletePhoneNumber.js +5 -5
  592. package/max/exports/getCountries.js +5 -5
  593. package/max/exports/getCountryCallingCode.js +5 -5
  594. package/max/exports/getExampleNumber.js +5 -5
  595. package/max/exports/getExtPrefix.js +5 -5
  596. package/max/exports/isPossiblePhoneNumber.js +5 -5
  597. package/max/exports/isSupportedCountry.js +5 -5
  598. package/max/exports/isValidPhoneNumber.js +5 -5
  599. package/max/exports/parsePhoneNumber.js +5 -5
  600. package/max/exports/parsePhoneNumberWithError.js +6 -6
  601. package/max/exports/searchNumbers.js +5 -5
  602. package/max/exports/searchPhoneNumbersInText.js +5 -5
  603. package/max/exports/validatePhoneNumberLength.js +5 -5
  604. package/max/exports/withMetadataArgument.js +8 -8
  605. package/max/index.cjs +113 -113
  606. package/max/index.cjs.js +118 -118
  607. package/max/index.d.cts +137 -137
  608. package/max/index.d.ts +137 -137
  609. package/max/index.js +44 -44
  610. package/max/metadata/metadata.max.json +1 -1
  611. package/max/metadata/metadata.max.json.d.cts +4 -4
  612. package/max/metadata/metadata.max.json.d.ts +4 -4
  613. package/max/metadata/metadata.max.json.js +1 -1
  614. package/max/metadata/package.json +16 -16
  615. package/max/package.json +14 -14
  616. package/metadata.full.json +1 -1
  617. package/metadata.full.json.d.cts +4 -4
  618. package/metadata.full.json.d.ts +4 -4
  619. package/metadata.full.json.js +1 -1
  620. package/metadata.max.json +1 -1
  621. package/metadata.max.json.d.cts +4 -4
  622. package/metadata.max.json.d.ts +4 -4
  623. package/metadata.max.json.js +1 -1
  624. package/metadata.min.json +1 -1
  625. package/metadata.min.json.d.cts +4 -4
  626. package/metadata.min.json.d.ts +4 -4
  627. package/metadata.min.json.js +1 -1
  628. package/metadata.mobile.json +1 -1
  629. package/metadata.mobile.json.d.cts +4 -4
  630. package/metadata.mobile.json.d.ts +4 -4
  631. package/metadata.mobile.json.js +1 -1
  632. package/min/es6/exports/AsYouType.js +11 -11
  633. package/min/es6/exports/Metadata.js +11 -11
  634. package/min/es6/exports/PhoneNumber.js +11 -11
  635. package/min/es6/exports/PhoneNumberMatcher.js +11 -11
  636. package/min/es6/exports/findNumbers.js +5 -5
  637. package/min/es6/exports/findPhoneNumbersInText.js +5 -5
  638. package/min/es6/exports/formatIncompletePhoneNumber.js +5 -5
  639. package/min/es6/exports/getCountries.js +5 -5
  640. package/min/es6/exports/getCountryCallingCode.js +5 -5
  641. package/min/es6/exports/getExampleNumber.js +5 -5
  642. package/min/es6/exports/getExtPrefix.js +5 -5
  643. package/min/es6/exports/isPossiblePhoneNumber.js +5 -5
  644. package/min/es6/exports/isSupportedCountry.js +5 -5
  645. package/min/es6/exports/isValidPhoneNumber.js +5 -5
  646. package/min/es6/exports/parsePhoneNumber.js +6 -6
  647. package/min/es6/exports/parsePhoneNumberWithError.js +7 -7
  648. package/min/es6/exports/searchNumbers.js +5 -5
  649. package/min/es6/exports/searchPhoneNumbersInText.js +5 -5
  650. package/min/es6/exports/validatePhoneNumberLength.js +5 -5
  651. package/min/es6/exports/withMetadataArgument.js +12 -12
  652. package/min/es6/index.d.cts +2 -2
  653. package/min/es6/index.d.ts +2 -2
  654. package/min/es6/index.js +44 -44
  655. package/min/es6/package.json +12 -12
  656. package/min/exports/AsYouType.js +11 -11
  657. package/min/exports/Metadata.js +11 -11
  658. package/min/exports/PhoneNumber.js +21 -21
  659. package/min/exports/PhoneNumberMatcher.js +11 -11
  660. package/min/exports/findNumbers.js +5 -5
  661. package/min/exports/findPhoneNumbersInText.js +5 -5
  662. package/min/exports/formatIncompletePhoneNumber.js +5 -5
  663. package/min/exports/getCountries.js +5 -5
  664. package/min/exports/getCountryCallingCode.js +5 -5
  665. package/min/exports/getExampleNumber.js +5 -5
  666. package/min/exports/getExtPrefix.js +5 -5
  667. package/min/exports/isPossiblePhoneNumber.js +5 -5
  668. package/min/exports/isSupportedCountry.js +5 -5
  669. package/min/exports/isValidPhoneNumber.js +5 -5
  670. package/min/exports/parsePhoneNumber.js +5 -5
  671. package/min/exports/parsePhoneNumberWithError.js +6 -6
  672. package/min/exports/searchNumbers.js +5 -5
  673. package/min/exports/searchPhoneNumbersInText.js +5 -5
  674. package/min/exports/validatePhoneNumberLength.js +5 -5
  675. package/min/exports/withMetadataArgument.js +8 -8
  676. package/min/index.cjs +124 -124
  677. package/min/index.cjs.js +129 -129
  678. package/min/index.d.cts +137 -137
  679. package/min/index.d.ts +137 -137
  680. package/min/index.js +43 -43
  681. package/min/metadata/metadata.min.json +1 -1
  682. package/min/metadata/metadata.min.json.d.cts +4 -4
  683. package/min/metadata/metadata.min.json.d.ts +4 -4
  684. package/min/metadata/metadata.min.json.js +1 -1
  685. package/min/metadata/package.json +16 -16
  686. package/min/package.json +14 -14
  687. package/mobile/es6/exports/AsYouType.js +11 -11
  688. package/mobile/es6/exports/Metadata.js +11 -11
  689. package/mobile/es6/exports/PhoneNumber.js +11 -11
  690. package/mobile/es6/exports/PhoneNumberMatcher.js +11 -11
  691. package/mobile/es6/exports/findNumbers.js +5 -5
  692. package/mobile/es6/exports/findPhoneNumbersInText.js +5 -5
  693. package/mobile/es6/exports/formatIncompletePhoneNumber.js +5 -5
  694. package/mobile/es6/exports/getCountries.js +5 -5
  695. package/mobile/es6/exports/getCountryCallingCode.js +5 -5
  696. package/mobile/es6/exports/getExampleNumber.js +5 -5
  697. package/mobile/es6/exports/getExtPrefix.js +5 -5
  698. package/mobile/es6/exports/isPossiblePhoneNumber.js +5 -5
  699. package/mobile/es6/exports/isSupportedCountry.js +5 -5
  700. package/mobile/es6/exports/isValidPhoneNumber.js +5 -5
  701. package/mobile/es6/exports/parsePhoneNumber.js +6 -6
  702. package/mobile/es6/exports/parsePhoneNumberWithError.js +7 -7
  703. package/mobile/es6/exports/searchNumbers.js +5 -5
  704. package/mobile/es6/exports/searchPhoneNumbersInText.js +5 -5
  705. package/mobile/es6/exports/validatePhoneNumberLength.js +5 -5
  706. package/mobile/es6/exports/withMetadataArgument.js +12 -12
  707. package/mobile/es6/index.d.cts +2 -2
  708. package/mobile/es6/index.d.ts +2 -2
  709. package/mobile/es6/index.js +44 -44
  710. package/mobile/es6/package.json +12 -12
  711. package/mobile/examples/examples.mobile.json.d.cts +3 -3
  712. package/mobile/examples/examples.mobile.json.d.ts +3 -3
  713. package/mobile/examples/package.json +16 -16
  714. package/mobile/exports/AsYouType.js +11 -11
  715. package/mobile/exports/Metadata.js +11 -11
  716. package/mobile/exports/PhoneNumber.js +21 -21
  717. package/mobile/exports/PhoneNumberMatcher.js +11 -11
  718. package/mobile/exports/findNumbers.js +5 -5
  719. package/mobile/exports/findPhoneNumbersInText.js +5 -5
  720. package/mobile/exports/formatIncompletePhoneNumber.js +5 -5
  721. package/mobile/exports/getCountries.js +5 -5
  722. package/mobile/exports/getCountryCallingCode.js +5 -5
  723. package/mobile/exports/getExampleNumber.js +5 -5
  724. package/mobile/exports/getExtPrefix.js +5 -5
  725. package/mobile/exports/isPossiblePhoneNumber.js +5 -5
  726. package/mobile/exports/isSupportedCountry.js +5 -5
  727. package/mobile/exports/isValidPhoneNumber.js +5 -5
  728. package/mobile/exports/parsePhoneNumber.js +5 -5
  729. package/mobile/exports/parsePhoneNumberWithError.js +6 -6
  730. package/mobile/exports/searchNumbers.js +5 -5
  731. package/mobile/exports/searchPhoneNumbersInText.js +5 -5
  732. package/mobile/exports/validatePhoneNumberLength.js +5 -5
  733. package/mobile/exports/withMetadataArgument.js +8 -8
  734. package/mobile/index.cjs +113 -113
  735. package/mobile/index.cjs.js +118 -118
  736. package/mobile/index.d.cts +137 -137
  737. package/mobile/index.d.ts +137 -137
  738. package/mobile/index.js +44 -44
  739. package/mobile/metadata/metadata.mobile.json +1 -1
  740. package/mobile/metadata/metadata.mobile.json.d.cts +4 -4
  741. package/mobile/metadata/metadata.mobile.json.d.ts +4 -4
  742. package/mobile/metadata/metadata.mobile.json.js +1 -1
  743. package/mobile/metadata/package.json +16 -16
  744. package/mobile/package.json +14 -14
  745. package/package.json +202 -202
  746. package/source/AsYouType.js +539 -539
  747. package/source/AsYouTypeFormatter.PatternMatcher.d.ts +66 -66
  748. package/source/AsYouTypeFormatter.PatternMatcher.js +196 -196
  749. package/source/AsYouTypeFormatter.PatternParser.d.ts +58 -58
  750. package/source/AsYouTypeFormatter.PatternParser.js +213 -213
  751. package/source/AsYouTypeFormatter.complete.js +134 -134
  752. package/source/AsYouTypeFormatter.js +713 -713
  753. package/source/AsYouTypeFormatter.util.js +99 -99
  754. package/source/AsYouTypeParser.js +519 -519
  755. package/source/AsYouTypeState.js +123 -123
  756. package/source/ParseError.js +13 -13
  757. package/source/PhoneNumber.js +161 -161
  758. package/source/PhoneNumberMatcher.js +398 -398
  759. package/source/constants.js +30 -30
  760. package/source/findNumbers/LRUCache.js +106 -106
  761. package/source/findNumbers/Leniency.js +407 -407
  762. package/source/findNumbers/RegExpCache.js +19 -19
  763. package/source/findNumbers/isValidCandidate.js +85 -85
  764. package/source/findNumbers/isValidPreCandidate.js +28 -28
  765. package/source/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js +63 -63
  766. package/source/findNumbers/parsePreCandidate.js +18 -18
  767. package/source/findNumbers/utf-8.js +81 -81
  768. package/source/findNumbers/util.js +33 -33
  769. package/source/findPhoneNumbersInText.js +11 -11
  770. package/source/format.js +235 -235
  771. package/source/formatIncompletePhoneNumber.js +16 -16
  772. package/source/formatPhoneNumberForMobileDialing.js +224 -224
  773. package/source/getCountries.js +4 -4
  774. package/source/getCountryCallingCode.js +1 -1
  775. package/source/getExampleNumber.js +6 -6
  776. package/source/helpers/RFC3966.js +58 -58
  777. package/source/helpers/applyInternationalSeparatorStyle.js +34 -34
  778. package/source/helpers/checkNumberLength.js +133 -133
  779. package/source/helpers/extension/createExtensionPattern.js +111 -111
  780. package/source/helpers/extension/extractExtension.js +28 -28
  781. package/source/helpers/extractCountryCallingCode.js +160 -160
  782. package/source/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +83 -83
  783. package/source/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js +73 -73
  784. package/source/helpers/extractNationalNumber.js +123 -123
  785. package/source/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +103 -103
  786. package/source/helpers/extractPhoneContext.js +102 -102
  787. package/source/helpers/formatNationalNumberUsingFormat.js +45 -45
  788. package/source/helpers/getCountryAndCallingCodeFromOneOfThem.js +30 -30
  789. package/source/helpers/getCountryByCallingCode.js +32 -32
  790. package/source/helpers/getCountryByNationalNumber.js +75 -75
  791. package/source/helpers/getIddPrefix.js +25 -25
  792. package/source/helpers/getNumberType.js +101 -101
  793. package/source/helpers/getPossibleCountriesForNumber.js +24 -24
  794. package/source/helpers/isCallingCode.js +5 -5
  795. package/source/helpers/isCountryCode.js +5 -5
  796. package/source/helpers/isObject.js +5 -5
  797. package/source/helpers/isViablePhoneNumber.js +107 -107
  798. package/source/helpers/matchesEntirely.js +10 -10
  799. package/source/helpers/mergeArrays.js +23 -23
  800. package/source/helpers/parseDigits.js +81 -81
  801. package/source/helpers/stripIddPrefix.js +35 -35
  802. package/source/isPossible.js +84 -84
  803. package/source/isPossiblePhoneNumber.js +11 -11
  804. package/source/isValid.js +58 -58
  805. package/source/isValidPhoneNumber.js +11 -11
  806. package/source/legacy/PhoneNumberSearch.js +121 -121
  807. package/source/legacy/findNumbers.js +11 -11
  808. package/source/legacy/findPhoneNumbers.js +19 -19
  809. package/source/legacy/findPhoneNumbersInitialImplementation.js +81 -81
  810. package/source/legacy/format.js +116 -116
  811. package/source/legacy/getNumberType.js +120 -120
  812. package/source/legacy/isPossibleNumber.js +24 -24
  813. package/source/legacy/isValidNumber.js +11 -11
  814. package/source/legacy/isValidNumberForRegion.js +61 -61
  815. package/source/legacy/isValidNumberForRegion_.js +12 -12
  816. package/source/legacy/parse.js +6 -6
  817. package/source/legacy/searchNumbers.js +30 -30
  818. package/source/metadata.js +580 -580
  819. package/source/normalizeArguments.js +54 -54
  820. package/source/parse.js +403 -403
  821. package/source/parseIncompletePhoneNumber.js +68 -68
  822. package/source/parsePhoneNumber.js +7 -7
  823. package/source/parsePhoneNumberWithError.js +6 -6
  824. package/source/parsePhoneNumberWithError_.js +4 -4
  825. package/source/parsePhoneNumber_.js +24 -24
  826. package/source/searchPhoneNumbersInText.js +23 -23
  827. package/source/tools/semver-compare.js +25 -25
  828. package/source/validatePhoneNumberLength.js +30 -30
  829. package/types.d.cts +181 -181
  830. package/types.d.ts +181 -181
@@ -1,540 +1,540 @@
1
- import Metadata from './metadata.js'
2
- import PhoneNumber from './PhoneNumber.js'
3
- import checkNumberLength from './helpers/checkNumberLength.js'
4
- import AsYouTypeState from './AsYouTypeState.js'
5
- import AsYouTypeFormatter, { DIGIT_PLACEHOLDER } from './AsYouTypeFormatter.js'
6
- import AsYouTypeParser, { extractFormattedDigitsAndPlus } from './AsYouTypeParser.js'
7
- import getCountryByCallingCode from './helpers/getCountryByCallingCode.js'
8
- import getCountryByNationalNumber from './helpers/getCountryByNationalNumber.js'
9
- import isObject from './helpers/isObject.js'
10
-
11
- const USE_NON_GEOGRAPHIC_COUNTRY_CODE = false
12
-
13
- export default class AsYouType {
14
- /**
15
- * @param {(string|object)?} [optionsOrDefaultCountry] - The default country used for parsing non-international phone numbers. Can also be an `options` object.
16
- * @param {Object} metadata
17
- */
18
- constructor(optionsOrDefaultCountry, metadata) {
19
- // Metadata instance is created once and stays constant.
20
- // This is required because other utility classes such as `AsYouTypeFormatter`
21
- // will use this metadata instance "reference" and will assume that it stays constant.
22
- this.metadata = new Metadata(metadata)
23
- const [defaultCountry, defaultCallingCode] = this.getCountryAndCallingCode(optionsOrDefaultCountry)
24
- // `this.defaultCountry` and `this.defaultCallingCode` aren't required to be in sync.
25
- // For example, `this.defaultCountry` could be `"AR"` and `this.defaultCallingCode` could be `undefined`.
26
- // So `this.defaultCountry` and `this.defaultCallingCode` are totally independent.
27
- this.defaultCountry = defaultCountry
28
- this.defaultCallingCode = defaultCallingCode
29
- this.reset()
30
- }
31
-
32
- getCountryAndCallingCode(optionsOrDefaultCountry) {
33
- // Set `defaultCountry` and `defaultCallingCode` options.
34
- let defaultCountry
35
- let defaultCallingCode
36
- // Turns out `null` also has type "object". Weird.
37
- if (optionsOrDefaultCountry) {
38
- if (isObject(optionsOrDefaultCountry)) {
39
- defaultCountry = optionsOrDefaultCountry.defaultCountry
40
- defaultCallingCode = optionsOrDefaultCountry.defaultCallingCode
41
- } else {
42
- defaultCountry = optionsOrDefaultCountry
43
- }
44
- }
45
- if (defaultCountry && !this.metadata.hasCountry(defaultCountry)) {
46
- defaultCountry = undefined
47
- }
48
- if (defaultCallingCode) {
49
- /* istanbul ignore if */
50
- if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
51
- if (this.metadata.isNonGeographicCallingCode(defaultCallingCode)) {
52
- defaultCountry = '001'
53
- }
54
- }
55
- }
56
- return [defaultCountry, defaultCallingCode]
57
- }
58
-
59
- /**
60
- * Inputs "next" phone number characters.
61
- * @param {string} text
62
- * @return {string} Formatted phone number characters that have been input so far.
63
- */
64
- input(text) {
65
- const {
66
- digits,
67
- justLeadingPlus
68
- } = this.parser.input(text, this.state)
69
- if (justLeadingPlus) {
70
- this.formattedOutput = '+'
71
- } else if (digits) {
72
- this.determineTheCountryIfNeeded()
73
- // Match the available formats by the currently available leading digits.
74
- if (this.state.nationalSignificantNumber) {
75
- this.formatter.narrowDownMatchingFormats(this.state)
76
- }
77
- let formattedNationalNumber
78
- if (this.metadata.hasSelectedNumberingPlan()) {
79
- formattedNationalNumber = this.formatter.format(digits, this.state)
80
- }
81
- if (formattedNationalNumber === undefined) {
82
- // See if another national (significant) number could be re-extracted.
83
- if (this.parser.reExtractNationalSignificantNumber(this.state)) {
84
- this.determineTheCountryIfNeeded()
85
- // If it could, then re-try formatting the new national (significant) number.
86
- const nationalDigits = this.state.getNationalDigits()
87
- if (nationalDigits) {
88
- formattedNationalNumber = this.formatter.format(nationalDigits, this.state)
89
- }
90
- }
91
- }
92
- this.formattedOutput = formattedNationalNumber
93
- ? this.getFullNumber(formattedNationalNumber)
94
- : this.getNonFormattedNumber()
95
- }
96
- return this.formattedOutput
97
- }
98
-
99
- reset() {
100
- this.state = new AsYouTypeState({
101
- onCountryChange: (country) => {
102
- // Before version `1.6.0`, the official `AsYouType` formatter API
103
- // included a `.country` property on an `AsYouType` instance.
104
- // Since that property (along with the others) have been moved to
105
- // `this.state`, `this.country` property is emulated for compatibility
106
- // with the old versions.
107
- this.country = country
108
- },
109
- onCallingCodeChange: (callingCode, country) => {
110
- this.metadata.selectNumberingPlan(country || callingCode)
111
- this.formatter.reset(this.metadata.numberingPlan, this.state)
112
- this.parser.reset(this.metadata.numberingPlan)
113
- }
114
- })
115
- this.formatter = new AsYouTypeFormatter({
116
- state: this.state,
117
- metadata: this.metadata
118
- })
119
- this.parser = new AsYouTypeParser({
120
- defaultCountry: this.defaultCountry,
121
- defaultCallingCode: this.defaultCallingCode,
122
- metadata: this.metadata,
123
- state: this.state,
124
- onNationalSignificantNumberChange: () => {
125
- this.determineTheCountryIfNeeded()
126
- this.formatter.reset(this.metadata.numberingPlan, this.state)
127
- }
128
- })
129
- this.state.reset({
130
- country: this.defaultCountry,
131
- callingCode: this.defaultCallingCode
132
- })
133
- this.formattedOutput = ''
134
- return this
135
- }
136
-
137
- /**
138
- * Returns `true` if the phone number is being input in international format.
139
- * In other words, returns `true` if and only if the parsed phone number starts with a `"+"`.
140
- * @return {boolean}
141
- */
142
- isInternational() {
143
- return this.state.international
144
- }
145
-
146
- /**
147
- * Returns the "calling code" part of the phone number when it's being input
148
- * in an international format.
149
- * If no valid calling code has been entered so far, returns `undefined`.
150
- * @return {string} [callingCode]
151
- */
152
- getCallingCode() {
153
- // If the number is being input in national format and some "default calling code"
154
- // has been passed to `AsYouType` constructor, then `this.state.callingCode`
155
- // is equal to that "default calling code".
156
- //
157
- // If the number is being input in national format and no "default calling code"
158
- // has been passed to `AsYouType` constructor, then returns `undefined`,
159
- // even if a "default country" has been passed to `AsYouType` constructor.
160
- //
161
- if (this.isInternational()) {
162
- return this.state.callingCode
163
- }
164
- }
165
-
166
- // A legacy alias.
167
- getCountryCallingCode() {
168
- return this.getCallingCode()
169
- }
170
-
171
- /**
172
- * Returns a two-letter country code of the phone number.
173
- * Returns `undefined` for "non-geographic" phone numbering plans.
174
- * Returns `undefined` if no phone number has been input yet.
175
- * @return {string} [country]
176
- */
177
- getCountry() {
178
- const { digits } = this.state
179
- // Return `undefined` if no digits have been input yet.
180
- if (digits) {
181
- return this._getCountry()
182
- }
183
- }
184
-
185
- /**
186
- * Returns a two-letter country code of the phone number.
187
- * Returns `undefined` for "non-geographic" phone numbering plans.
188
- * @return {string} [country]
189
- */
190
- _getCountry() {
191
- const { country } = this.state
192
- /* istanbul ignore if */
193
- if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
194
- // `AsYouType.getCountry()` returns `undefined`
195
- // for "non-geographic" phone numbering plans.
196
- if (country === '001') {
197
- return
198
- }
199
- }
200
- return country
201
- }
202
-
203
- determineTheCountryIfNeeded() {
204
- // Suppose a user enters a phone number in international format,
205
- // and there're several countries corresponding to that country calling code,
206
- // and a country has been derived from the number, and then
207
- // a user enters one more digit and the number is no longer
208
- // valid for the derived country, so the country should be re-derived
209
- // on every new digit in those cases.
210
- //
211
- // If the phone number is being input in national format,
212
- // then it could be a case when `defaultCountry` wasn't specified
213
- // when creating `AsYouType` instance, and just `defaultCallingCode` was specified,
214
- // and that "calling code" could correspond to a "non-geographic entity",
215
- // or there could be several countries corresponding to that country calling code.
216
- // In those cases, `this.country` is `undefined` and should be derived
217
- // from the number. Again, if country calling code is ambiguous, then
218
- // `this.country` should be re-derived with each new digit.
219
- //
220
- if (!this.state.country || this.isCountryCallingCodeAmbiguous()) {
221
- this.determineTheCountry()
222
- }
223
- }
224
-
225
- // Prepends `+CountryCode ` in case of an international phone number
226
- getFullNumber(formattedNationalNumber) {
227
- if (this.isInternational()) {
228
- const prefix = (text) => this.formatter.getInternationalPrefixBeforeCountryCallingCode(this.state, {
229
- spacing: text ? true : false
230
- }) + text
231
- const { callingCode } = this.state
232
- if (!callingCode) {
233
- return prefix(`${this.state.getDigitsWithoutInternationalPrefix()}`)
234
- }
235
- if (!formattedNationalNumber) {
236
- return prefix(callingCode)
237
- }
238
- return prefix(`${callingCode} ${formattedNationalNumber}`)
239
- }
240
- return formattedNationalNumber
241
- }
242
-
243
- getNonFormattedNationalNumberWithPrefix() {
244
- const {
245
- nationalSignificantNumber,
246
- prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix,
247
- nationalPrefix
248
- } = this.state
249
- let number = nationalSignificantNumber
250
- const prefix = prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix || nationalPrefix
251
- if (prefix) {
252
- number = prefix + number
253
- }
254
- return number
255
- }
256
-
257
- getNonFormattedNumber() {
258
- const { nationalSignificantNumberIsModified } = this.state
259
- return this.getFullNumber(
260
- nationalSignificantNumberIsModified
261
- ? this.state.getNationalDigits()
262
- : this.getNonFormattedNationalNumberWithPrefix()
263
- )
264
- }
265
-
266
- getNonFormattedTemplate() {
267
- const number = this.getNonFormattedNumber()
268
- if (number) {
269
- return number.replace(/[\+\d]/g, DIGIT_PLACEHOLDER)
270
- }
271
- }
272
-
273
- isCountryCallingCodeAmbiguous() {
274
- const { callingCode } = this.state
275
- const countryCodes = this.metadata.getCountryCodesForCallingCode(callingCode)
276
- return countryCodes && countryCodes.length > 1
277
- }
278
-
279
- // Determines the exact country of the phone number
280
- // entered so far based on the country phone code
281
- // and the national phone number.
282
- determineTheCountry() {
283
- // Get a more precise country code for this national number.
284
- // It is possible that the precise country couldn't be determined
285
- // in cases when there're multiple countries sharing the same calling code.
286
- // In that case, `country` will be `undefined`.
287
- const country = getCountryByCallingCode(
288
- this.isInternational() ? this.state.callingCode : this.defaultCallingCode,
289
- {
290
- nationalNumber: this.state.nationalSignificantNumber,
291
- metadata: this.metadata
292
- }
293
- )
294
- // If the derived country is indeed more precise,
295
- // or if no country could be derived for the updated phone number.
296
- if (country !== this.state.country) {
297
- // Set (or reset) the more precise country.
298
- this.state.setCountry(country)
299
- // If a more precise country could be derived.
300
- if (country) {
301
- // Select a more precise telephone numbering plan.
302
- // For example, consider that `AsYouType` instance was created with `defaultCountry: "US"` argument.
303
- // In that case, the metadata instance will be using "US" metadata.
304
- // But then the user could input a Canadian phone number, in which case
305
- // the metadata instance should be switched to Canadian telephone numbering plan.
306
- // It is required to do that because later `canFormatCompleteNumber()` function will be called,
307
- // and that function relies on the precise country being pre-selected in the metadata instance.
308
- // Or, for example, `checkNumberLength()` function also relies on same thing.
309
- this.metadata.selectNumberingPlan(country)
310
- }
311
- }
312
- }
313
-
314
- /**
315
- * Returns a E.164 phone number value for the user's input.
316
- *
317
- * For example, for country `"US"` and input `"(222) 333-4444"`
318
- * it will return `"+12223334444"`.
319
- *
320
- * For international phone number input, it will also auto-correct
321
- * some minor errors such as using a national prefix when writing
322
- * an international phone number. For example, if the user inputs
323
- * `"+44 0 7400 000000"` then it will return an auto-corrected
324
- * `"+447400000000"` phone number value.
325
- *
326
- * Will return `undefined` if no digits have been input,
327
- * or when inputting a phone number in national format and no
328
- * default country or default "country calling code" have been set.
329
- *
330
- * @return {string} [value]
331
- */
332
- getNumberValue() {
333
- const {
334
- digits,
335
- callingCode,
336
- country,
337
- nationalSignificantNumber
338
- } = this.state
339
-
340
- // Will return `undefined` if no digits have been input.
341
- if (!digits) {
342
- return
343
- }
344
-
345
- if (this.isInternational()) {
346
- if (callingCode) {
347
- return '+' + callingCode + nationalSignificantNumber
348
- } else {
349
- return '+' + digits
350
- }
351
- } else {
352
- if (country || callingCode) {
353
- const callingCode_ = country ? this.metadata.countryCallingCode() : callingCode
354
- return '+' + callingCode_ + nationalSignificantNumber
355
- }
356
- }
357
- }
358
-
359
- /**
360
- * Returns an instance of `PhoneNumber` class.
361
- * Will return `undefined` if no national (significant) number
362
- * digits have been entered so far, or if no `defaultCountry` has been
363
- * set and the user enters a phone number not in international format.
364
- */
365
- getNumber() {
366
- const {
367
- nationalSignificantNumber,
368
- carrierCode,
369
- callingCode
370
- } = this.state
371
-
372
- if (!nationalSignificantNumber) {
373
- return
374
- }
375
-
376
- // `this._getCountry()` is basically same as `this.state.country`
377
- // with the only change that it returns `undefined` in case of a
378
- // "non-geographic" numbering plan instead of `"001"` "internal use" value.
379
- let country = this._getCountry()
380
-
381
- // Sidenote:
382
- // `state.callingCode` and `state.country` are somewhat independent from one another
383
- // and there could be situations when one is defined but the other is not.
384
- // See the comment in `AsYouTypeState.js` for more info on when that is possible.
385
-
386
- if (!country && !callingCode) {
387
- return
388
- }
389
-
390
- // By default, if `defaultCountry` parameter was passed when
391
- // creating `AsYouType` instance, `state.country` is gonna be
392
- // that `defaultCountry`, which doesn't entirely conform with
393
- // `parsePhoneNumber()`'s behavior where it attempts to determine
394
- // the country more precisely in cases when multiple countries
395
- // could correspond to the same `countryCallingCode`.
396
- // https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/103#note_1417192969
397
- //
398
- // Because `AsYouType.getNumber()` method is supposed to be a 1:1
399
- // equivalent for `parsePhoneNumber(AsYouType.getNumberValue())`,
400
- // it means that it should also behave accordingly in such cases of `country` ambiguity.
401
- // That's how users of this library would expect it to behave anyway.
402
- //
403
- // So here it checks if `state.country` is same as the `defaultCountry`,
404
- // and if it is, it attempts to get rid of any potential ambiguity.
405
- //
406
- if (country) {
407
- if (country === this.defaultCountry) {
408
- // // Create a `Metadata` instance just to get the calling code of the `country`.
409
- // const metadata = new Metadata(this.metadata.metadata)
410
- // // `state.callingCode` and `state.country` are somewhat independent from one another
411
- // // and there could be situations when one is defined but the other is not.
412
- // // See the comment in `AsYouTypeState.js` for more info on when that is possible.
413
- // // Here, it only passes `state.country` because there's no need to pass `state.callingCode`
414
- // // because `state.country` is known to be defined.
415
- // metadata.selectNumberingPlan(country)
416
- // const countryCallingCode = metadata.numberingPlan.callingCode()
417
-
418
- // Instead of getting `countryCallingCode` value above,
419
- // it could simply read it from the existing metadata instance.
420
- const countryCallingCode = this.metadata.numberingPlan.callingCode()
421
-
422
- // Attempt to rule out any potential country code ambiguity, if present.
423
- const exactCountry = getExactCountryForMultiCountryCallingCode(
424
- countryCallingCode,
425
- nationalSignificantNumber,
426
- this.metadata
427
- )
428
- if (exactCountry) {
429
- country = exactCountry
430
- }
431
- }
432
- }
433
-
434
- const phoneNumber = new PhoneNumber(
435
- country || callingCode,
436
- nationalSignificantNumber,
437
- this.metadata.metadata
438
- )
439
- if (carrierCode) {
440
- phoneNumber.carrierCode = carrierCode
441
- }
442
- // Phone number extensions are not supported by "As You Type" formatter.
443
- return phoneNumber
444
- }
445
-
446
- /**
447
- * Returns `true` if the phone number is "possible".
448
- * Is just a shortcut for `PhoneNumber.isPossible()`.
449
- * @return {boolean}
450
- */
451
- isPossible() {
452
- const phoneNumber = this.getNumber()
453
- if (!phoneNumber) {
454
- return false
455
- }
456
- return phoneNumber.isPossible()
457
- }
458
-
459
- /**
460
- * Returns `true` if the phone number is "valid".
461
- * Is just a shortcut for `PhoneNumber.isValid()`.
462
- * @return {boolean}
463
- */
464
- isValid() {
465
- const phoneNumber = this.getNumber()
466
- if (!phoneNumber) {
467
- return false
468
- }
469
- return phoneNumber.isValid()
470
- }
471
-
472
- /**
473
- * Checks if the phone number length is valid.
474
- * If it is, nothing is returned.
475
- * Otherwise, a rejection reason is returned.
476
- * @return {string?}
477
- */
478
- validateLength() {
479
- const {
480
- digits,
481
- nationalSignificantNumber
482
- } = this.state
483
-
484
- if (!digits) {
485
- return 'NOT_A_NUMBER'
486
- }
487
-
488
- if (!this.metadata.numberingPlan) {
489
- return 'INVALID_COUNTRY'
490
- }
491
-
492
- if (!nationalSignificantNumber) {
493
- return 'TOO_SHORT'
494
- }
495
-
496
- // `state.callingCode` and `state.country` are somewhat independent from one another
497
- // and there could be situations when one is defined but the other is not.
498
- // See the comment in `AsYouTypeState.js` for more info on when that is possible.
499
- // Here, it uses both: if `country` is defined then it will use that,
500
- // otherwise it will use `callingCode`.
501
- const result = checkNumberLength(nationalSignificantNumber, undefined, this.metadata)
502
- if (result !== 'IS_POSSIBLE') {
503
- return result
504
- }
505
- }
506
-
507
- /**
508
- * @deprecated
509
- * This method is used in `react-phone-number-input/source/input-control.js`
510
- * in versions before `3.0.16`.
511
- */
512
- getNationalNumber() {
513
- return this.state.nationalSignificantNumber
514
- }
515
-
516
- /**
517
- * Returns the phone number characters entered by the user.
518
- * @return {string}
519
- */
520
- getChars() {
521
- return (this.state.international ? '+' : '') + this.state.digits
522
- }
523
-
524
- /**
525
- * Returns the template for the formatted phone number.
526
- * @return {string}
527
- */
528
- getTemplate() {
529
- return this.formatter.getTemplate(this.state) || this.getNonFormattedTemplate() || ''
530
- }
531
- }
532
-
533
- // In situations when multiple countries use the same calling code,
534
- // this function tells what exact country does a given national (significant) number belong to.
535
- function getExactCountryForMultiCountryCallingCode(callingCode, nationalSignificantNumber, metadata) {
536
- const ambiguousCountries = metadata.getCountryCodesForCallingCode(callingCode)
537
- if (ambiguousCountries.length > 1) {
538
- return getCountryByNationalNumber(nationalSignificantNumber, ambiguousCountries, metadata.metadata)
539
- }
1
+ import Metadata from './metadata.js'
2
+ import PhoneNumber from './PhoneNumber.js'
3
+ import checkNumberLength from './helpers/checkNumberLength.js'
4
+ import AsYouTypeState from './AsYouTypeState.js'
5
+ import AsYouTypeFormatter, { DIGIT_PLACEHOLDER } from './AsYouTypeFormatter.js'
6
+ import AsYouTypeParser, { extractFormattedDigitsAndPlus } from './AsYouTypeParser.js'
7
+ import getCountryByCallingCode from './helpers/getCountryByCallingCode.js'
8
+ import getCountryByNationalNumber from './helpers/getCountryByNationalNumber.js'
9
+ import isObject from './helpers/isObject.js'
10
+
11
+ const USE_NON_GEOGRAPHIC_COUNTRY_CODE = false
12
+
13
+ export default class AsYouType {
14
+ /**
15
+ * @param {(string|object)?} [optionsOrDefaultCountry] - The default country used for parsing non-international phone numbers. Can also be an `options` object.
16
+ * @param {Object} metadata
17
+ */
18
+ constructor(optionsOrDefaultCountry, metadata) {
19
+ // Metadata instance is created once and stays constant.
20
+ // This is required because other utility classes such as `AsYouTypeFormatter`
21
+ // will use this metadata instance "reference" and will assume that it stays constant.
22
+ this.metadata = new Metadata(metadata)
23
+ const [defaultCountry, defaultCallingCode] = this.getCountryAndCallingCode(optionsOrDefaultCountry)
24
+ // `this.defaultCountry` and `this.defaultCallingCode` aren't required to be in sync.
25
+ // For example, `this.defaultCountry` could be `"AR"` and `this.defaultCallingCode` could be `undefined`.
26
+ // So `this.defaultCountry` and `this.defaultCallingCode` are totally independent.
27
+ this.defaultCountry = defaultCountry
28
+ this.defaultCallingCode = defaultCallingCode
29
+ this.reset()
30
+ }
31
+
32
+ getCountryAndCallingCode(optionsOrDefaultCountry) {
33
+ // Set `defaultCountry` and `defaultCallingCode` options.
34
+ let defaultCountry
35
+ let defaultCallingCode
36
+ // Turns out `null` also has type "object". Weird.
37
+ if (optionsOrDefaultCountry) {
38
+ if (isObject(optionsOrDefaultCountry)) {
39
+ defaultCountry = optionsOrDefaultCountry.defaultCountry
40
+ defaultCallingCode = optionsOrDefaultCountry.defaultCallingCode
41
+ } else {
42
+ defaultCountry = optionsOrDefaultCountry
43
+ }
44
+ }
45
+ if (defaultCountry && !this.metadata.hasCountry(defaultCountry)) {
46
+ defaultCountry = undefined
47
+ }
48
+ if (defaultCallingCode) {
49
+ /* istanbul ignore if */
50
+ if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
51
+ if (this.metadata.isNonGeographicCallingCode(defaultCallingCode)) {
52
+ defaultCountry = '001'
53
+ }
54
+ }
55
+ }
56
+ return [defaultCountry, defaultCallingCode]
57
+ }
58
+
59
+ /**
60
+ * Inputs "next" phone number characters.
61
+ * @param {string} text
62
+ * @return {string} Formatted phone number characters that have been input so far.
63
+ */
64
+ input(text) {
65
+ const {
66
+ digits,
67
+ justLeadingPlus
68
+ } = this.parser.input(text, this.state)
69
+ if (justLeadingPlus) {
70
+ this.formattedOutput = '+'
71
+ } else if (digits) {
72
+ this.determineTheCountryIfNeeded()
73
+ // Match the available formats by the currently available leading digits.
74
+ if (this.state.nationalSignificantNumber) {
75
+ this.formatter.narrowDownMatchingFormats(this.state)
76
+ }
77
+ let formattedNationalNumber
78
+ if (this.metadata.hasSelectedNumberingPlan()) {
79
+ formattedNationalNumber = this.formatter.format(digits, this.state)
80
+ }
81
+ if (formattedNationalNumber === undefined) {
82
+ // See if another national (significant) number could be re-extracted.
83
+ if (this.parser.reExtractNationalSignificantNumber(this.state)) {
84
+ this.determineTheCountryIfNeeded()
85
+ // If it could, then re-try formatting the new national (significant) number.
86
+ const nationalDigits = this.state.getNationalDigits()
87
+ if (nationalDigits) {
88
+ formattedNationalNumber = this.formatter.format(nationalDigits, this.state)
89
+ }
90
+ }
91
+ }
92
+ this.formattedOutput = formattedNationalNumber
93
+ ? this.getFullNumber(formattedNationalNumber)
94
+ : this.getNonFormattedNumber()
95
+ }
96
+ return this.formattedOutput
97
+ }
98
+
99
+ reset() {
100
+ this.state = new AsYouTypeState({
101
+ onCountryChange: (country) => {
102
+ // Before version `1.6.0`, the official `AsYouType` formatter API
103
+ // included a `.country` property on an `AsYouType` instance.
104
+ // Since that property (along with the others) have been moved to
105
+ // `this.state`, `this.country` property is emulated for compatibility
106
+ // with the old versions.
107
+ this.country = country
108
+ },
109
+ onCallingCodeChange: (callingCode, country) => {
110
+ this.metadata.selectNumberingPlan(country || callingCode)
111
+ this.formatter.reset(this.metadata.numberingPlan, this.state)
112
+ this.parser.reset(this.metadata.numberingPlan)
113
+ }
114
+ })
115
+ this.formatter = new AsYouTypeFormatter({
116
+ state: this.state,
117
+ metadata: this.metadata
118
+ })
119
+ this.parser = new AsYouTypeParser({
120
+ defaultCountry: this.defaultCountry,
121
+ defaultCallingCode: this.defaultCallingCode,
122
+ metadata: this.metadata,
123
+ state: this.state,
124
+ onNationalSignificantNumberChange: () => {
125
+ this.determineTheCountryIfNeeded()
126
+ this.formatter.reset(this.metadata.numberingPlan, this.state)
127
+ }
128
+ })
129
+ this.state.reset({
130
+ country: this.defaultCountry,
131
+ callingCode: this.defaultCallingCode
132
+ })
133
+ this.formattedOutput = ''
134
+ return this
135
+ }
136
+
137
+ /**
138
+ * Returns `true` if the phone number is being input in international format.
139
+ * In other words, returns `true` if and only if the parsed phone number starts with a `"+"`.
140
+ * @return {boolean}
141
+ */
142
+ isInternational() {
143
+ return this.state.international
144
+ }
145
+
146
+ /**
147
+ * Returns the "calling code" part of the phone number when it's being input
148
+ * in an international format.
149
+ * If no valid calling code has been entered so far, returns `undefined`.
150
+ * @return {string} [callingCode]
151
+ */
152
+ getCallingCode() {
153
+ // If the number is being input in national format and some "default calling code"
154
+ // has been passed to `AsYouType` constructor, then `this.state.callingCode`
155
+ // is equal to that "default calling code".
156
+ //
157
+ // If the number is being input in national format and no "default calling code"
158
+ // has been passed to `AsYouType` constructor, then returns `undefined`,
159
+ // even if a "default country" has been passed to `AsYouType` constructor.
160
+ //
161
+ if (this.isInternational()) {
162
+ return this.state.callingCode
163
+ }
164
+ }
165
+
166
+ // A legacy alias.
167
+ getCountryCallingCode() {
168
+ return this.getCallingCode()
169
+ }
170
+
171
+ /**
172
+ * Returns a two-letter country code of the phone number.
173
+ * Returns `undefined` for "non-geographic" phone numbering plans.
174
+ * Returns `undefined` if no phone number has been input yet.
175
+ * @return {string} [country]
176
+ */
177
+ getCountry() {
178
+ const { digits } = this.state
179
+ // Return `undefined` if no digits have been input yet.
180
+ if (digits) {
181
+ return this._getCountry()
182
+ }
183
+ }
184
+
185
+ /**
186
+ * Returns a two-letter country code of the phone number.
187
+ * Returns `undefined` for "non-geographic" phone numbering plans.
188
+ * @return {string} [country]
189
+ */
190
+ _getCountry() {
191
+ const { country } = this.state
192
+ /* istanbul ignore if */
193
+ if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
194
+ // `AsYouType.getCountry()` returns `undefined`
195
+ // for "non-geographic" phone numbering plans.
196
+ if (country === '001') {
197
+ return
198
+ }
199
+ }
200
+ return country
201
+ }
202
+
203
+ determineTheCountryIfNeeded() {
204
+ // Suppose a user enters a phone number in international format,
205
+ // and there're several countries corresponding to that country calling code,
206
+ // and a country has been derived from the number, and then
207
+ // a user enters one more digit and the number is no longer
208
+ // valid for the derived country, so the country should be re-derived
209
+ // on every new digit in those cases.
210
+ //
211
+ // If the phone number is being input in national format,
212
+ // then it could be a case when `defaultCountry` wasn't specified
213
+ // when creating `AsYouType` instance, and just `defaultCallingCode` was specified,
214
+ // and that "calling code" could correspond to a "non-geographic entity",
215
+ // or there could be several countries corresponding to that country calling code.
216
+ // In those cases, `this.country` is `undefined` and should be derived
217
+ // from the number. Again, if country calling code is ambiguous, then
218
+ // `this.country` should be re-derived with each new digit.
219
+ //
220
+ if (!this.state.country || this.isCountryCallingCodeAmbiguous()) {
221
+ this.determineTheCountry()
222
+ }
223
+ }
224
+
225
+ // Prepends `+CountryCode ` in case of an international phone number
226
+ getFullNumber(formattedNationalNumber) {
227
+ if (this.isInternational()) {
228
+ const prefix = (text) => this.formatter.getInternationalPrefixBeforeCountryCallingCode(this.state, {
229
+ spacing: text ? true : false
230
+ }) + text
231
+ const { callingCode } = this.state
232
+ if (!callingCode) {
233
+ return prefix(`${this.state.getDigitsWithoutInternationalPrefix()}`)
234
+ }
235
+ if (!formattedNationalNumber) {
236
+ return prefix(callingCode)
237
+ }
238
+ return prefix(`${callingCode} ${formattedNationalNumber}`)
239
+ }
240
+ return formattedNationalNumber
241
+ }
242
+
243
+ getNonFormattedNationalNumberWithPrefix() {
244
+ const {
245
+ nationalSignificantNumber,
246
+ prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix,
247
+ nationalPrefix
248
+ } = this.state
249
+ let number = nationalSignificantNumber
250
+ const prefix = prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix || nationalPrefix
251
+ if (prefix) {
252
+ number = prefix + number
253
+ }
254
+ return number
255
+ }
256
+
257
+ getNonFormattedNumber() {
258
+ const { nationalSignificantNumberIsModified } = this.state
259
+ return this.getFullNumber(
260
+ nationalSignificantNumberIsModified
261
+ ? this.state.getNationalDigits()
262
+ : this.getNonFormattedNationalNumberWithPrefix()
263
+ )
264
+ }
265
+
266
+ getNonFormattedTemplate() {
267
+ const number = this.getNonFormattedNumber()
268
+ if (number) {
269
+ return number.replace(/[\+\d]/g, DIGIT_PLACEHOLDER)
270
+ }
271
+ }
272
+
273
+ isCountryCallingCodeAmbiguous() {
274
+ const { callingCode } = this.state
275
+ const countryCodes = this.metadata.getCountryCodesForCallingCode(callingCode)
276
+ return countryCodes && countryCodes.length > 1
277
+ }
278
+
279
+ // Determines the exact country of the phone number
280
+ // entered so far based on the country phone code
281
+ // and the national phone number.
282
+ determineTheCountry() {
283
+ // Get a more precise country code for this national number.
284
+ // It is possible that the precise country couldn't be determined
285
+ // in cases when there're multiple countries sharing the same calling code.
286
+ // In that case, `country` will be `undefined`.
287
+ const country = getCountryByCallingCode(
288
+ this.isInternational() ? this.state.callingCode : this.defaultCallingCode,
289
+ {
290
+ nationalNumber: this.state.nationalSignificantNumber,
291
+ metadata: this.metadata
292
+ }
293
+ )
294
+ // If the derived country is indeed more precise,
295
+ // or if no country could be derived for the updated phone number.
296
+ if (country !== this.state.country) {
297
+ // Set (or reset) the more precise country.
298
+ this.state.setCountry(country)
299
+ // If a more precise country could be derived.
300
+ if (country) {
301
+ // Select a more precise telephone numbering plan.
302
+ // For example, consider that `AsYouType` instance was created with `defaultCountry: "US"` argument.
303
+ // In that case, the metadata instance will be using "US" metadata.
304
+ // But then the user could input a Canadian phone number, in which case
305
+ // the metadata instance should be switched to Canadian telephone numbering plan.
306
+ // It is required to do that because later `canFormatCompleteNumber()` function will be called,
307
+ // and that function relies on the precise country being pre-selected in the metadata instance.
308
+ // Or, for example, `checkNumberLength()` function also relies on same thing.
309
+ this.metadata.selectNumberingPlan(country)
310
+ }
311
+ }
312
+ }
313
+
314
+ /**
315
+ * Returns a E.164 phone number value for the user's input.
316
+ *
317
+ * For example, for country `"US"` and input `"(222) 333-4444"`
318
+ * it will return `"+12223334444"`.
319
+ *
320
+ * For international phone number input, it will also auto-correct
321
+ * some minor errors such as using a national prefix when writing
322
+ * an international phone number. For example, if the user inputs
323
+ * `"+44 0 7400 000000"` then it will return an auto-corrected
324
+ * `"+447400000000"` phone number value.
325
+ *
326
+ * Will return `undefined` if no digits have been input,
327
+ * or when inputting a phone number in national format and no
328
+ * default country or default "country calling code" have been set.
329
+ *
330
+ * @return {string} [value]
331
+ */
332
+ getNumberValue() {
333
+ const {
334
+ digits,
335
+ callingCode,
336
+ country,
337
+ nationalSignificantNumber
338
+ } = this.state
339
+
340
+ // Will return `undefined` if no digits have been input.
341
+ if (!digits) {
342
+ return
343
+ }
344
+
345
+ if (this.isInternational()) {
346
+ if (callingCode) {
347
+ return '+' + callingCode + nationalSignificantNumber
348
+ } else {
349
+ return '+' + digits
350
+ }
351
+ } else {
352
+ if (country || callingCode) {
353
+ const callingCode_ = country ? this.metadata.countryCallingCode() : callingCode
354
+ return '+' + callingCode_ + nationalSignificantNumber
355
+ }
356
+ }
357
+ }
358
+
359
+ /**
360
+ * Returns an instance of `PhoneNumber` class.
361
+ * Will return `undefined` if no national (significant) number
362
+ * digits have been entered so far, or if no `defaultCountry` has been
363
+ * set and the user enters a phone number not in international format.
364
+ */
365
+ getNumber() {
366
+ const {
367
+ nationalSignificantNumber,
368
+ carrierCode,
369
+ callingCode
370
+ } = this.state
371
+
372
+ if (!nationalSignificantNumber) {
373
+ return
374
+ }
375
+
376
+ // `this._getCountry()` is basically same as `this.state.country`
377
+ // with the only change that it returns `undefined` in case of a
378
+ // "non-geographic" numbering plan instead of `"001"` "internal use" value.
379
+ let country = this._getCountry()
380
+
381
+ // Sidenote:
382
+ // `state.callingCode` and `state.country` are somewhat independent from one another
383
+ // and there could be situations when one is defined but the other is not.
384
+ // See the comment in `AsYouTypeState.js` for more info on when that is possible.
385
+
386
+ if (!country && !callingCode) {
387
+ return
388
+ }
389
+
390
+ // By default, if `defaultCountry` parameter was passed when
391
+ // creating `AsYouType` instance, `state.country` is gonna be
392
+ // that `defaultCountry`, which doesn't entirely conform with
393
+ // `parsePhoneNumber()`'s behavior where it attempts to determine
394
+ // the country more precisely in cases when multiple countries
395
+ // could correspond to the same `countryCallingCode`.
396
+ // https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/103#note_1417192969
397
+ //
398
+ // Because `AsYouType.getNumber()` method is supposed to be a 1:1
399
+ // equivalent for `parsePhoneNumber(AsYouType.getNumberValue())`,
400
+ // it means that it should also behave accordingly in such cases of `country` ambiguity.
401
+ // That's how users of this library would expect it to behave anyway.
402
+ //
403
+ // So here it checks if `state.country` is same as the `defaultCountry`,
404
+ // and if it is, it attempts to get rid of any potential ambiguity.
405
+ //
406
+ if (country) {
407
+ if (country === this.defaultCountry) {
408
+ // // Create a `Metadata` instance just to get the calling code of the `country`.
409
+ // const metadata = new Metadata(this.metadata.metadata)
410
+ // // `state.callingCode` and `state.country` are somewhat independent from one another
411
+ // // and there could be situations when one is defined but the other is not.
412
+ // // See the comment in `AsYouTypeState.js` for more info on when that is possible.
413
+ // // Here, it only passes `state.country` because there's no need to pass `state.callingCode`
414
+ // // because `state.country` is known to be defined.
415
+ // metadata.selectNumberingPlan(country)
416
+ // const countryCallingCode = metadata.numberingPlan.callingCode()
417
+
418
+ // Instead of getting `countryCallingCode` value above,
419
+ // it could simply read it from the existing metadata instance.
420
+ const countryCallingCode = this.metadata.numberingPlan.callingCode()
421
+
422
+ // Attempt to rule out any potential country code ambiguity, if present.
423
+ const exactCountry = getExactCountryForMultiCountryCallingCode(
424
+ countryCallingCode,
425
+ nationalSignificantNumber,
426
+ this.metadata
427
+ )
428
+ if (exactCountry) {
429
+ country = exactCountry
430
+ }
431
+ }
432
+ }
433
+
434
+ const phoneNumber = new PhoneNumber(
435
+ country || callingCode,
436
+ nationalSignificantNumber,
437
+ this.metadata.metadata
438
+ )
439
+ if (carrierCode) {
440
+ phoneNumber.carrierCode = carrierCode
441
+ }
442
+ // Phone number extensions are not supported by "As You Type" formatter.
443
+ return phoneNumber
444
+ }
445
+
446
+ /**
447
+ * Returns `true` if the phone number is "possible".
448
+ * Is just a shortcut for `PhoneNumber.isPossible()`.
449
+ * @return {boolean}
450
+ */
451
+ isPossible() {
452
+ const phoneNumber = this.getNumber()
453
+ if (!phoneNumber) {
454
+ return false
455
+ }
456
+ return phoneNumber.isPossible()
457
+ }
458
+
459
+ /**
460
+ * Returns `true` if the phone number is "valid".
461
+ * Is just a shortcut for `PhoneNumber.isValid()`.
462
+ * @return {boolean}
463
+ */
464
+ isValid() {
465
+ const phoneNumber = this.getNumber()
466
+ if (!phoneNumber) {
467
+ return false
468
+ }
469
+ return phoneNumber.isValid()
470
+ }
471
+
472
+ /**
473
+ * Checks if the phone number length is valid.
474
+ * If it is, nothing is returned.
475
+ * Otherwise, a rejection reason is returned.
476
+ * @return {string?}
477
+ */
478
+ validateLength() {
479
+ const {
480
+ digits,
481
+ nationalSignificantNumber
482
+ } = this.state
483
+
484
+ if (!digits) {
485
+ return 'NOT_A_NUMBER'
486
+ }
487
+
488
+ if (!this.metadata.numberingPlan) {
489
+ return 'INVALID_COUNTRY'
490
+ }
491
+
492
+ if (!nationalSignificantNumber) {
493
+ return 'TOO_SHORT'
494
+ }
495
+
496
+ // `state.callingCode` and `state.country` are somewhat independent from one another
497
+ // and there could be situations when one is defined but the other is not.
498
+ // See the comment in `AsYouTypeState.js` for more info on when that is possible.
499
+ // Here, it uses both: if `country` is defined then it will use that,
500
+ // otherwise it will use `callingCode`.
501
+ const result = checkNumberLength(nationalSignificantNumber, undefined, this.metadata)
502
+ if (result !== 'IS_POSSIBLE') {
503
+ return result
504
+ }
505
+ }
506
+
507
+ /**
508
+ * @deprecated
509
+ * This method is used in `react-phone-number-input/source/input-control.js`
510
+ * in versions before `3.0.16`.
511
+ */
512
+ getNationalNumber() {
513
+ return this.state.nationalSignificantNumber
514
+ }
515
+
516
+ /**
517
+ * Returns the phone number characters entered by the user.
518
+ * @return {string}
519
+ */
520
+ getChars() {
521
+ return (this.state.international ? '+' : '') + this.state.digits
522
+ }
523
+
524
+ /**
525
+ * Returns the template for the formatted phone number.
526
+ * @return {string}
527
+ */
528
+ getTemplate() {
529
+ return this.formatter.getTemplate(this.state) || this.getNonFormattedTemplate() || ''
530
+ }
531
+ }
532
+
533
+ // In situations when multiple countries use the same calling code,
534
+ // this function tells what exact country does a given national (significant) number belong to.
535
+ function getExactCountryForMultiCountryCallingCode(callingCode, nationalSignificantNumber, metadata) {
536
+ const ambiguousCountries = metadata.getCountryCodesForCallingCode(callingCode)
537
+ if (ambiguousCountries.length > 1) {
538
+ return getCountryByNationalNumber(nationalSignificantNumber, ambiguousCountries, metadata.metadata)
539
+ }
540
540
  }