libphonenumber-js 1.12.42 → 1.13.0

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 (332) hide show
  1. package/CHANGELOG.md +131 -94
  2. package/README.md +36 -6
  3. package/bundle/libphonenumber-js.min.js +1 -1
  4. package/bundle/libphonenumber-js.min.js.map +1 -1
  5. package/bundle/libphonenumber-max.js +1 -1
  6. package/bundle/libphonenumber-max.js.map +1 -1
  7. package/bundle/libphonenumber-min.js +1 -1
  8. package/bundle/libphonenumber-min.js.map +1 -1
  9. package/bundle/libphonenumber-mobile.js +1 -1
  10. package/bundle/libphonenumber-mobile.js.map +1 -1
  11. package/core/es6/index.d.cts +2 -0
  12. package/core/es6/index.d.ts +2 -0
  13. package/core/es6/index.js +39 -0
  14. package/core/es6/package.json +12 -0
  15. package/core/index.cjs +5 -0
  16. package/core/index.cjs.js +5 -0
  17. package/core/index.d.cts +3 -1
  18. package/core/index.d.ts +3 -1
  19. package/core/index.js +5 -0
  20. package/custom.d.ts +6 -4
  21. package/custom.js +5 -5
  22. package/es6-modern/AsYouType.js +445 -0
  23. package/es6-modern/AsYouType.js.map +1 -0
  24. package/es6-modern/AsYouType.test.js.map +1 -0
  25. package/es6-modern/AsYouTypeFormatter.PatternMatcher.js +195 -0
  26. package/es6-modern/AsYouTypeFormatter.PatternMatcher.js.map +1 -0
  27. package/es6-modern/AsYouTypeFormatter.PatternMatcher.test.js.map +1 -0
  28. package/es6-modern/AsYouTypeFormatter.PatternParser.js +184 -0
  29. package/es6-modern/AsYouTypeFormatter.PatternParser.js.map +1 -0
  30. package/es6-modern/AsYouTypeFormatter.PatternParser.test.js.map +1 -0
  31. package/es6-modern/AsYouTypeFormatter.complete.js +120 -0
  32. package/es6-modern/AsYouTypeFormatter.complete.js.map +1 -0
  33. package/es6-modern/AsYouTypeFormatter.js +659 -0
  34. package/es6-modern/AsYouTypeFormatter.js.map +1 -0
  35. package/es6-modern/AsYouTypeFormatter.util.js +96 -0
  36. package/es6-modern/AsYouTypeFormatter.util.js.map +1 -0
  37. package/es6-modern/AsYouTypeFormatter.util.test.js.map +1 -0
  38. package/es6-modern/AsYouTypeParser.js +435 -0
  39. package/es6-modern/AsYouTypeParser.js.map +1 -0
  40. package/es6-modern/AsYouTypeState.js +104 -0
  41. package/es6-modern/AsYouTypeState.js.map +1 -0
  42. package/es6-modern/ParseError.js +15 -0
  43. package/es6-modern/ParseError.js.map +1 -0
  44. package/es6-modern/PhoneNumber.js +166 -0
  45. package/es6-modern/PhoneNumber.js.map +1 -0
  46. package/es6-modern/PhoneNumber.test.js.map +1 -0
  47. package/es6-modern/PhoneNumberMatcher.js +330 -0
  48. package/es6-modern/PhoneNumberMatcher.js.map +1 -0
  49. package/es6-modern/PhoneNumberMatcher.test.js.map +1 -0
  50. package/es6-modern/constants.js +31 -0
  51. package/es6-modern/constants.js.map +1 -0
  52. package/es6-modern/findNumbers/LRUCache.js +98 -0
  53. package/es6-modern/findNumbers/LRUCache.js.map +1 -0
  54. package/es6-modern/findNumbers/Leniency.js +311 -0
  55. package/es6-modern/findNumbers/Leniency.js.map +1 -0
  56. package/es6-modern/findNumbers/RegExpCache.js +20 -0
  57. package/es6-modern/findNumbers/RegExpCache.js.map +1 -0
  58. package/es6-modern/findNumbers/isValidCandidate.js +66 -0
  59. package/es6-modern/findNumbers/isValidCandidate.js.map +1 -0
  60. package/es6-modern/findNumbers/isValidPreCandidate.js +26 -0
  61. package/es6-modern/findNumbers/isValidPreCandidate.js.map +1 -0
  62. package/es6-modern/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js +63 -0
  63. package/es6-modern/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js.map +1 -0
  64. package/es6-modern/findNumbers/parsePreCandidate.js +18 -0
  65. package/es6-modern/findNumbers/parsePreCandidate.js.map +1 -0
  66. package/es6-modern/findNumbers/utf-8.js +63 -0
  67. package/es6-modern/findNumbers/utf-8.js.map +1 -0
  68. package/es6-modern/findNumbers/util.js +26 -0
  69. package/es6-modern/findNumbers/util.js.map +1 -0
  70. package/es6-modern/findNumbers/util.test.js.map +1 -0
  71. package/es6-modern/findPhoneNumbersInText.js +19 -0
  72. package/es6-modern/findPhoneNumbersInText.js.map +1 -0
  73. package/es6-modern/findPhoneNumbersInText.test.js.map +1 -0
  74. package/es6-modern/format.js +204 -0
  75. package/es6-modern/format.js.map +1 -0
  76. package/es6-modern/format.test.js.map +1 -0
  77. package/es6-modern/formatIncompletePhoneNumber.js +18 -0
  78. package/es6-modern/formatIncompletePhoneNumber.js.map +1 -0
  79. package/es6-modern/formatIncompletePhoneNumber.test.js.map +1 -0
  80. package/es6-modern/formatPhoneNumberForMobileDialing.js +190 -0
  81. package/es6-modern/formatPhoneNumberForMobileDialing.js.map +1 -0
  82. package/es6-modern/getCountries.js +5 -0
  83. package/es6-modern/getCountries.js.map +1 -0
  84. package/es6-modern/getCountries.test.js.map +1 -0
  85. package/es6-modern/getCountryCallingCode.js +3 -0
  86. package/es6-modern/getCountryCallingCode.js.map +1 -0
  87. package/es6-modern/getCountryCallingCode.test.js.map +1 -0
  88. package/es6-modern/getExampleNumber.js +7 -0
  89. package/es6-modern/getExampleNumber.js.map +1 -0
  90. package/es6-modern/getExampleNumber.test.js.map +1 -0
  91. package/es6-modern/helpers/RFC3966.js +63 -0
  92. package/es6-modern/helpers/RFC3966.js.map +1 -0
  93. package/es6-modern/helpers/RFC3966.test.js.map +1 -0
  94. package/es6-modern/helpers/applyInternationalSeparatorStyle.js +36 -0
  95. package/es6-modern/helpers/applyInternationalSeparatorStyle.js.map +1 -0
  96. package/es6-modern/helpers/applyInternationalSeparatorStyle.test.js.map +1 -0
  97. package/es6-modern/helpers/checkNumberLength.js +112 -0
  98. package/es6-modern/helpers/checkNumberLength.js.map +1 -0
  99. package/es6-modern/helpers/checkNumberLength.test.js.map +1 -0
  100. package/es6-modern/helpers/extension/createExtensionPattern.js +93 -0
  101. package/es6-modern/helpers/extension/createExtensionPattern.js.map +1 -0
  102. package/es6-modern/helpers/extension/extractExtension.js +30 -0
  103. package/es6-modern/helpers/extension/extractExtension.js.map +1 -0
  104. package/es6-modern/helpers/extractCountryCallingCode.js +142 -0
  105. package/es6-modern/helpers/extractCountryCallingCode.js.map +1 -0
  106. package/es6-modern/helpers/extractCountryCallingCode.test.js.map +1 -0
  107. package/es6-modern/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +49 -0
  108. package/es6-modern/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -0
  109. package/es6-modern/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js +66 -0
  110. package/es6-modern/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js.map +1 -0
  111. package/es6-modern/helpers/extractNationalNumber.js +117 -0
  112. package/es6-modern/helpers/extractNationalNumber.js.map +1 -0
  113. package/es6-modern/helpers/extractNationalNumber.test.js.map +1 -0
  114. package/es6-modern/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +102 -0
  115. package/es6-modern/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -0
  116. package/es6-modern/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js.map +1 -0
  117. package/es6-modern/helpers/extractPhoneContext.js +82 -0
  118. package/es6-modern/helpers/extractPhoneContext.js.map +1 -0
  119. package/es6-modern/helpers/extractPhoneContext.test.js.map +1 -0
  120. package/es6-modern/helpers/formatNationalNumberUsingFormat.js +34 -0
  121. package/es6-modern/helpers/formatNationalNumberUsingFormat.js.map +1 -0
  122. package/es6-modern/helpers/getCountryByCallingCode.js +30 -0
  123. package/es6-modern/helpers/getCountryByCallingCode.js.map +1 -0
  124. package/es6-modern/helpers/getCountryByNationalNumber.js +76 -0
  125. package/es6-modern/helpers/getCountryByNationalNumber.js.map +1 -0
  126. package/es6-modern/helpers/getIddPrefix.js +26 -0
  127. package/es6-modern/helpers/getIddPrefix.js.map +1 -0
  128. package/es6-modern/helpers/getNumberType.js +81 -0
  129. package/es6-modern/helpers/getNumberType.js.map +1 -0
  130. package/es6-modern/helpers/getNumberType.test.js.map +1 -0
  131. package/es6-modern/helpers/getPossibleCountriesForNumber.js +28 -0
  132. package/es6-modern/helpers/getPossibleCountriesForNumber.js.map +1 -0
  133. package/es6-modern/helpers/isObject.js +5 -0
  134. package/es6-modern/helpers/isObject.js.map +1 -0
  135. package/es6-modern/helpers/isViablePhoneNumber.js +77 -0
  136. package/es6-modern/helpers/isViablePhoneNumber.js.map +1 -0
  137. package/es6-modern/helpers/matchesEntirely.js +12 -0
  138. package/es6-modern/helpers/matchesEntirely.js.map +1 -0
  139. package/es6-modern/helpers/matchesEntirely.test.js.map +1 -0
  140. package/es6-modern/helpers/mergeArrays.js +23 -0
  141. package/es6-modern/helpers/mergeArrays.js.map +1 -0
  142. package/es6-modern/helpers/mergeArrays.test.js.map +1 -0
  143. package/es6-modern/helpers/parseDigits.js +111 -0
  144. package/es6-modern/helpers/parseDigits.js.map +1 -0
  145. package/es6-modern/helpers/parseDigits.test.js.map +1 -0
  146. package/es6-modern/helpers/stripIddPrefix.js +29 -0
  147. package/es6-modern/helpers/stripIddPrefix.js.map +1 -0
  148. package/es6-modern/helpers/stripIddPrefix.test.js.map +1 -0
  149. package/es6-modern/isPossible.js +77 -0
  150. package/es6-modern/isPossible.js.map +1 -0
  151. package/es6-modern/isPossible.test.js.map +1 -0
  152. package/es6-modern/isPossiblePhoneNumber.js +16 -0
  153. package/es6-modern/isPossiblePhoneNumber.js.map +1 -0
  154. package/es6-modern/isPossiblePhoneNumber.test.js.map +1 -0
  155. package/es6-modern/isValid.js +57 -0
  156. package/es6-modern/isValid.js.map +1 -0
  157. package/es6-modern/isValid.test.js.map +1 -0
  158. package/es6-modern/isValidPhoneNumber.js +16 -0
  159. package/es6-modern/isValidPhoneNumber.js.map +1 -0
  160. package/es6-modern/isValidPhoneNumber.test.js.map +1 -0
  161. package/es6-modern/legacy/PhoneNumberSearch.js +109 -0
  162. package/es6-modern/legacy/PhoneNumberSearch.js.map +1 -0
  163. package/es6-modern/legacy/findNumbers.js +16 -0
  164. package/es6-modern/legacy/findNumbers.js.map +1 -0
  165. package/es6-modern/legacy/findNumbers.test.js.map +1 -0
  166. package/es6-modern/legacy/findPhoneNumbers.js +26 -0
  167. package/es6-modern/legacy/findPhoneNumbers.js.map +1 -0
  168. package/es6-modern/legacy/findPhoneNumbers.test.js.map +1 -0
  169. package/es6-modern/legacy/findPhoneNumbersInitialImplementation.js +79 -0
  170. package/es6-modern/legacy/findPhoneNumbersInitialImplementation.js.map +1 -0
  171. package/es6-modern/legacy/format.js +97 -0
  172. package/es6-modern/legacy/format.js.map +1 -0
  173. package/es6-modern/legacy/format.test.js.map +1 -0
  174. package/es6-modern/legacy/getNumberType.js +104 -0
  175. package/es6-modern/legacy/getNumberType.js.map +1 -0
  176. package/es6-modern/legacy/getNumberType.test.js.map +1 -0
  177. package/es6-modern/legacy/isPossibleNumber.js +30 -0
  178. package/es6-modern/legacy/isPossibleNumber.js.map +1 -0
  179. package/es6-modern/legacy/isPossibleNumber.test.js.map +1 -0
  180. package/es6-modern/legacy/isValidNumber.js +17 -0
  181. package/es6-modern/legacy/isValidNumber.js.map +1 -0
  182. package/es6-modern/legacy/isValidNumber.test.js.map +1 -0
  183. package/es6-modern/legacy/isValidNumberForRegion.js +65 -0
  184. package/es6-modern/legacy/isValidNumberForRegion.js.map +1 -0
  185. package/es6-modern/legacy/isValidNumberForRegion.test.js.map +1 -0
  186. package/es6-modern/legacy/isValidNumberForRegion_.js +14 -0
  187. package/es6-modern/legacy/isValidNumberForRegion_.js.map +1 -0
  188. package/es6-modern/legacy/parse.js +11 -0
  189. package/es6-modern/legacy/parse.js.map +1 -0
  190. package/es6-modern/legacy/parse.test.js.map +1 -0
  191. package/es6-modern/legacy/searchNumbers.js +32 -0
  192. package/es6-modern/legacy/searchNumbers.js.map +1 -0
  193. package/es6-modern/legacy/searchNumbers.test.js.map +1 -0
  194. package/es6-modern/metadata.js +494 -0
  195. package/es6-modern/metadata.js.map +1 -0
  196. package/es6-modern/metadata.test.js.map +1 -0
  197. package/es6-modern/normalizeArguments.js +52 -0
  198. package/es6-modern/normalizeArguments.js.map +1 -0
  199. package/es6-modern/parse.js +341 -0
  200. package/es6-modern/parse.js.map +1 -0
  201. package/es6-modern/parse.test.js.map +1 -0
  202. package/es6-modern/parseIncompletePhoneNumber.js +70 -0
  203. package/es6-modern/parseIncompletePhoneNumber.js.map +1 -0
  204. package/es6-modern/parseIncompletePhoneNumber.test.js.map +1 -0
  205. package/es6-modern/parsePhoneNumber.js +11 -0
  206. package/es6-modern/parsePhoneNumber.js.map +1 -0
  207. package/es6-modern/parsePhoneNumber.test.js.map +1 -0
  208. package/es6-modern/parsePhoneNumberWithError.js +11 -0
  209. package/es6-modern/parsePhoneNumberWithError.js.map +1 -0
  210. package/es6-modern/parsePhoneNumberWithError.test.js.map +1 -0
  211. package/es6-modern/parsePhoneNumberWithError_.js +8 -0
  212. package/es6-modern/parsePhoneNumberWithError_.js.map +1 -0
  213. package/es6-modern/parsePhoneNumber_.js +24 -0
  214. package/es6-modern/parsePhoneNumber_.js.map +1 -0
  215. package/es6-modern/searchPhoneNumbersInText.js +31 -0
  216. package/es6-modern/searchPhoneNumbersInText.js.map +1 -0
  217. package/es6-modern/searchPhoneNumbersInText.test.js.map +1 -0
  218. package/es6-modern/tools/semver-compare.js +27 -0
  219. package/es6-modern/tools/semver-compare.js.map +1 -0
  220. package/es6-modern/tools/semver-compare.test.js.map +1 -0
  221. package/es6-modern/validatePhoneNumberLength.js +35 -0
  222. package/es6-modern/validatePhoneNumberLength.js.map +1 -0
  223. package/es6-modern/validatePhoneNumberLength.test.js.map +1 -0
  224. package/index.cjs +4 -0
  225. package/index.cjs.js +4 -0
  226. package/index.d.cts +5 -3
  227. package/index.d.ts +5 -3
  228. package/index.js +5 -0
  229. package/max/es6/exports/AsYouType.js +11 -0
  230. package/max/es6/exports/Metadata.js +11 -0
  231. package/max/es6/exports/PhoneNumber.js +11 -0
  232. package/max/es6/exports/PhoneNumberMatcher.js +11 -0
  233. package/max/es6/exports/findNumbers.js +6 -0
  234. package/max/es6/exports/findPhoneNumbersInText.js +6 -0
  235. package/max/es6/exports/formatIncompletePhoneNumber.js +6 -0
  236. package/max/es6/exports/getCountries.js +6 -0
  237. package/max/es6/exports/getCountryCallingCode.js +6 -0
  238. package/max/es6/exports/getExampleNumber.js +6 -0
  239. package/max/es6/exports/getExtPrefix.js +6 -0
  240. package/max/es6/exports/isPossiblePhoneNumber.js +6 -0
  241. package/max/es6/exports/isSupportedCountry.js +6 -0
  242. package/max/es6/exports/isValidPhoneNumber.js +6 -0
  243. package/max/es6/exports/parsePhoneNumber.js +7 -0
  244. package/max/es6/exports/parsePhoneNumberWithError.js +7 -0
  245. package/max/es6/exports/searchNumbers.js +6 -0
  246. package/max/es6/exports/searchPhoneNumbersInText.js +6 -0
  247. package/max/es6/exports/validatePhoneNumberLength.js +6 -0
  248. package/max/es6/exports/withMetadataArgument.js +13 -0
  249. package/max/es6/index.d.cts +2 -0
  250. package/max/es6/index.d.ts +2 -0
  251. package/max/es6/index.js +44 -0
  252. package/max/es6/package.json +12 -0
  253. package/max/index.cjs +5 -0
  254. package/max/index.cjs.js +5 -0
  255. package/max/index.d.cts +3 -1
  256. package/max/index.d.ts +3 -1
  257. package/max/index.js +4 -0
  258. package/max/metadata/metadata.max.json +1 -1
  259. package/max/metadata/metadata.max.json.js +1 -1
  260. package/metadata.full.json +1 -1
  261. package/metadata.full.json.js +1 -1
  262. package/metadata.max.json +1 -1
  263. package/metadata.max.json.js +1 -1
  264. package/metadata.min.json +1 -1
  265. package/metadata.min.json.js +1 -1
  266. package/metadata.mobile.json +1 -1
  267. package/metadata.mobile.json.js +1 -1
  268. package/min/es6/exports/AsYouType.js +11 -0
  269. package/min/es6/exports/Metadata.js +11 -0
  270. package/min/es6/exports/PhoneNumber.js +11 -0
  271. package/min/es6/exports/PhoneNumberMatcher.js +11 -0
  272. package/min/es6/exports/findNumbers.js +6 -0
  273. package/min/es6/exports/findPhoneNumbersInText.js +6 -0
  274. package/min/es6/exports/formatIncompletePhoneNumber.js +6 -0
  275. package/min/es6/exports/getCountries.js +6 -0
  276. package/min/es6/exports/getCountryCallingCode.js +6 -0
  277. package/min/es6/exports/getExampleNumber.js +6 -0
  278. package/min/es6/exports/getExtPrefix.js +6 -0
  279. package/min/es6/exports/isPossiblePhoneNumber.js +6 -0
  280. package/min/es6/exports/isSupportedCountry.js +6 -0
  281. package/min/es6/exports/isValidPhoneNumber.js +6 -0
  282. package/min/es6/exports/parsePhoneNumber.js +7 -0
  283. package/min/es6/exports/parsePhoneNumberWithError.js +7 -0
  284. package/min/es6/exports/searchNumbers.js +6 -0
  285. package/min/es6/exports/searchPhoneNumbersInText.js +6 -0
  286. package/min/es6/exports/validatePhoneNumberLength.js +6 -0
  287. package/min/es6/exports/withMetadataArgument.js +13 -0
  288. package/min/es6/index.d.cts +2 -0
  289. package/min/es6/index.d.ts +2 -0
  290. package/min/es6/index.js +44 -0
  291. package/min/es6/package.json +12 -0
  292. package/min/index.cjs +5 -0
  293. package/min/index.cjs.js +5 -0
  294. package/min/index.d.cts +3 -1
  295. package/min/index.d.ts +3 -1
  296. package/min/index.js +3 -0
  297. package/min/metadata/metadata.min.json +1 -1
  298. package/min/metadata/metadata.min.json.js +1 -1
  299. package/mobile/es6/exports/AsYouType.js +11 -0
  300. package/mobile/es6/exports/Metadata.js +11 -0
  301. package/mobile/es6/exports/PhoneNumber.js +11 -0
  302. package/mobile/es6/exports/PhoneNumberMatcher.js +11 -0
  303. package/mobile/es6/exports/findNumbers.js +6 -0
  304. package/mobile/es6/exports/findPhoneNumbersInText.js +6 -0
  305. package/mobile/es6/exports/formatIncompletePhoneNumber.js +6 -0
  306. package/mobile/es6/exports/getCountries.js +6 -0
  307. package/mobile/es6/exports/getCountryCallingCode.js +6 -0
  308. package/mobile/es6/exports/getExampleNumber.js +6 -0
  309. package/mobile/es6/exports/getExtPrefix.js +6 -0
  310. package/mobile/es6/exports/isPossiblePhoneNumber.js +6 -0
  311. package/mobile/es6/exports/isSupportedCountry.js +6 -0
  312. package/mobile/es6/exports/isValidPhoneNumber.js +6 -0
  313. package/mobile/es6/exports/parsePhoneNumber.js +7 -0
  314. package/mobile/es6/exports/parsePhoneNumberWithError.js +7 -0
  315. package/mobile/es6/exports/searchNumbers.js +6 -0
  316. package/mobile/es6/exports/searchPhoneNumbersInText.js +6 -0
  317. package/mobile/es6/exports/validatePhoneNumberLength.js +6 -0
  318. package/mobile/es6/exports/withMetadataArgument.js +13 -0
  319. package/mobile/es6/index.d.cts +2 -0
  320. package/mobile/es6/index.d.ts +2 -0
  321. package/mobile/es6/index.js +44 -0
  322. package/mobile/es6/package.json +12 -0
  323. package/mobile/index.cjs +5 -0
  324. package/mobile/index.cjs.js +5 -0
  325. package/mobile/index.d.cts +3 -1
  326. package/mobile/index.d.ts +3 -1
  327. package/mobile/index.js +4 -0
  328. package/mobile/metadata/metadata.mobile.json +1 -1
  329. package/mobile/metadata/metadata.mobile.json.js +1 -1
  330. package/package.json +28 -9
  331. package/types.d.cts +54 -21
  332. package/types.d.ts +54 -21
@@ -0,0 +1,2 @@
1
+ export * from '../index.d.js'
2
+ export { default } from '../index.d.js'
@@ -0,0 +1,2 @@
1
+ export * from '../index.d.js'
2
+ export { default } from '../index.d.js'
@@ -0,0 +1,39 @@
1
+ export { default as PhoneNumber } from '../../es6-modern/PhoneNumber.js'
2
+ export { default as ParseError } from '../../es6-modern/ParseError.js'
3
+ // `parsePhoneNumber()` named export has been renamed to `parsePhoneNumberWithError()`.
4
+ export { default as parsePhoneNumberWithError, default as parsePhoneNumber } from '../../es6-modern/parsePhoneNumberWithError.js'
5
+
6
+ // `parsePhoneNumberFromString()` named export is now considered legacy:
7
+ // it has been promoted to a default export due to being too verbose.
8
+ export { default as default, default as parsePhoneNumberFromString } from '../../es6-modern/parsePhoneNumber.js'
9
+
10
+ export { default as isValidPhoneNumber } from '../../es6-modern/isValidPhoneNumber.js'
11
+ export { default as isPossiblePhoneNumber } from '../../es6-modern/isPossiblePhoneNumber.js'
12
+ export { default as validatePhoneNumberLength } from '../../es6-modern/validatePhoneNumberLength.js'
13
+
14
+ // Deprecated.
15
+ export { default as findNumbers } from '../../es6-modern/legacy/findNumbers.js'
16
+ export { default as searchNumbers } from '../../es6-modern/legacy/searchNumbers.js'
17
+
18
+ export { default as findPhoneNumbersInText } from '../../es6-modern/findPhoneNumbersInText.js'
19
+ export { default as searchPhoneNumbersInText } from '../../es6-modern/searchPhoneNumbersInText.js'
20
+ export { default as PhoneNumberMatcher } from '../../es6-modern/PhoneNumberMatcher.js'
21
+
22
+ export { default as AsYouType } from '../../es6-modern/AsYouType.js'
23
+
24
+ // Deprecated:
25
+ // `DIGIT_PLACEHOLDER` is the character that `AsYouType` formatter uses in a phone number template.
26
+ // It's basically an "x" character. I guess, there's no point in exporting it as a constant
27
+ // because the established convention is that it's an "x" character so everyone just assumes "x".
28
+ export { DIGIT_PLACEHOLDER } from '../../es6-modern/AsYouTypeFormatter.js'
29
+
30
+ export { default as getCountries } from '../../es6-modern/getCountries.js'
31
+ export { default as Metadata, isSupportedCountry, getCountryCallingCode, getExtPrefix } from '../../es6-modern/metadata.js'
32
+
33
+ export { default as getExampleNumber } from '../../es6-modern/getExampleNumber.js'
34
+
35
+ export { default as formatIncompletePhoneNumber } from '../../es6-modern/formatIncompletePhoneNumber.js'
36
+ export { default as parseIncompletePhoneNumber, parsePhoneNumberCharacter } from '../../es6-modern/parseIncompletePhoneNumber.js'
37
+ export { default as parseDigits } from '../../es6-modern/helpers/parseDigits.js'
38
+
39
+ export { parseRFC3966, formatRFC3966 } from '../../es6-modern/helpers/RFC3966.js'
@@ -0,0 +1,12 @@
1
+ {
2
+ "private": true,
3
+ "name": "libphonenumber-js/core/es6",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./index.d.ts",
8
+ "import": "./index.js"
9
+ }
10
+ },
11
+ "sideEffects": false
12
+ }
package/core/index.cjs CHANGED
@@ -46,6 +46,11 @@ exports.formatIncompletePhoneNumber = require('../build/formatIncompletePhoneNum
46
46
  exports.parseIncompletePhoneNumber = require('../build/parseIncompletePhoneNumber.js').default
47
47
  exports.parsePhoneNumberCharacter = require('../build/parseIncompletePhoneNumber.js').parsePhoneNumberCharacter
48
48
  exports.parseDigits = require('../build/helpers/parseDigits.js').default
49
+
50
+ // Deprecated:
51
+ // `DIGIT_PLACEHOLDER` is the character that `AsYouType` formatter uses in a phone number template.
52
+ // It's basically an "x" character. I guess, there's no point in exporting it as a constant
53
+ // because the established convention is that it's an "x" character so everyone just assumes "x".
49
54
  exports.DIGIT_PLACEHOLDER = require('../build/AsYouTypeFormatter.js').DIGIT_PLACEHOLDER
50
55
 
51
56
  exports.parseRFC3966 = require('../build/helpers/RFC3966.js').parseRFC3966
package/core/index.cjs.js CHANGED
@@ -51,6 +51,11 @@ exports.formatIncompletePhoneNumber = require('../build/formatIncompletePhoneNum
51
51
  exports.parseIncompletePhoneNumber = require('../build/parseIncompletePhoneNumber.js').default
52
52
  exports.parsePhoneNumberCharacter = require('../build/parseIncompletePhoneNumber.js').parsePhoneNumberCharacter
53
53
  exports.parseDigits = require('../build/helpers/parseDigits.js').default
54
+
55
+ // Deprecated:
56
+ // `DIGIT_PLACEHOLDER` is the character that `AsYouType` formatter uses in a phone number template.
57
+ // It's basically an "x" character. I guess, there's no point in exporting it as a constant
58
+ // because the established convention is that it's an "x" character so everyone just assumes "x".
54
59
  exports.DIGIT_PLACEHOLDER = require('../build/AsYouTypeFormatter.js').DIGIT_PLACEHOLDER
55
60
 
56
61
  exports.parseRFC3966 = require('../build/helpers/RFC3966.js').parseRFC3966
package/core/index.d.cts CHANGED
@@ -9,6 +9,7 @@ import {
9
9
  Extension,
10
10
  ParseError,
11
11
  NumberFoundLegacy,
12
+ PhoneNumberType,
12
13
  NumberType,
13
14
  NumberFormat,
14
15
  NumberingPlan,
@@ -30,6 +31,7 @@ export {
30
31
  Extension,
31
32
  ParseError,
32
33
  NumberFoundLegacy,
34
+ PhoneNumberType,
33
35
  NumberType,
34
36
  NumberFormat,
35
37
  NumberingPlan,
@@ -48,7 +50,7 @@ export class PhoneNumber {
48
50
  getPossibleCountries(): CountryCode[];
49
51
  isPossible(): boolean;
50
52
  isValid(): boolean;
51
- getType(): NumberType;
53
+ getType(): PhoneNumberType | undefined;
52
54
  format(format: NumberFormat, options?: FormatNumberOptions): string;
53
55
  formatNational(options?: FormatNumberOptionsForNationalOrInternational): string;
54
56
  formatInternational(options?: FormatNumberOptionsForNationalOrInternational): string;
package/core/index.d.ts CHANGED
@@ -9,6 +9,7 @@ import {
9
9
  Extension,
10
10
  ParseError,
11
11
  NumberFoundLegacy,
12
+ PhoneNumberType,
12
13
  NumberType,
13
14
  NumberFormat,
14
15
  NumberingPlan,
@@ -30,6 +31,7 @@ export {
30
31
  Extension,
31
32
  ParseError,
32
33
  NumberFoundLegacy,
34
+ PhoneNumberType,
33
35
  NumberType,
34
36
  NumberFormat,
35
37
  NumberingPlan,
@@ -48,7 +50,7 @@ export class PhoneNumber {
48
50
  getPossibleCountries(): CountryCode[];
49
51
  isPossible(): boolean;
50
52
  isValid(): boolean;
51
- getType(): NumberType;
53
+ getType(): PhoneNumberType | undefined;
52
54
  format(format: NumberFormat, options?: FormatNumberOptions): string;
53
55
  formatNational(options?: FormatNumberOptionsForNationalOrInternational): string;
54
56
  formatInternational(options?: FormatNumberOptionsForNationalOrInternational): string;
package/core/index.js CHANGED
@@ -20,6 +20,11 @@ export { default as searchPhoneNumbersInText } from '../es6/searchPhoneNumbersIn
20
20
  export { default as PhoneNumberMatcher } from '../es6/PhoneNumberMatcher.js'
21
21
 
22
22
  export { default as AsYouType } from '../es6/AsYouType.js'
23
+
24
+ // Deprecated:
25
+ // `DIGIT_PLACEHOLDER` is the character that `AsYouType` formatter uses in a phone number template.
26
+ // It's basically an "x" character. I guess, there's no point in exporting it as a constant
27
+ // because the established convention is that it's an "x" character so everyone just assumes "x".
23
28
  export { DIGIT_PLACEHOLDER } from '../es6/AsYouTypeFormatter.js'
24
29
 
25
30
  export { default as getCountries } from '../es6/getCountries.js'
package/custom.d.ts CHANGED
@@ -13,6 +13,7 @@ import {
13
13
  Extension,
14
14
  ParseError,
15
15
  NumberFoundLegacy,
16
+ PhoneNumberType,
16
17
  NumberType,
17
18
  NumberFormat,
18
19
  NumberingPlan
@@ -40,6 +41,7 @@ export {
40
41
  ParseError,
41
42
  NumberFoundLegacy,
42
43
  NumberFormat,
44
+ PhoneNumberType,
43
45
  NumberType,
44
46
  NumberingPlan
45
47
  };
@@ -56,7 +58,7 @@ export class PhoneNumber {
56
58
  getPossibleCountries(): CountryCode[];
57
59
  isPossible(): boolean;
58
60
  isValid(): boolean;
59
- getType(): NumberType;
61
+ getType(): PhoneNumberType | undefined;
60
62
  format(format: NumberFormat, options?: FormatNumberOptions): string;
61
63
  formatNational(options?: FormatNumberOptionsForNationalOrInternational): string;
62
64
  formatInternational(options?: FormatNumberOptionsForNationalOrInternational): string;
@@ -160,9 +162,9 @@ export function formatNumber(phone: string, country: CountryCode, format: Number
160
162
  export function formatNumber(phone: string, country: CountryCode, format: NumberFormat, options: FormatNumberOptions, metadata: MetadataJson): string;
161
163
 
162
164
  // Deprecated
163
- export function getNumberType(parsedNumber: ParsedNumber, metadata: MetadataJson): NumberType;
164
- export function getNumberType(phone: string, metadata: MetadataJson): NumberType;
165
- export function getNumberType(phone: string, country: CountryCode, metadata: MetadataJson): NumberType;
165
+ export function getNumberType(parsedNumber: ParsedNumber, metadata: MetadataJson): PhoneNumberType | undefined;
166
+ export function getNumberType(phone: string, metadata: MetadataJson): PhoneNumberType | undefined;
167
+ export function getNumberType(phone: string, country: CountryCode, metadata: MetadataJson): PhoneNumberType | undefined;
166
168
 
167
169
  // Deprecated
168
170
  export function isPossibleNumber(parsedNumber: ParsedNumber, metadata: MetadataJson): boolean;
package/custom.js CHANGED
@@ -57,11 +57,11 @@ exports.parseDigits = require('./build/helpers/parseDigits.js').default
57
57
 
58
58
  // Deprecated: `DIGITS` were used by `react-phone-number-input`.
59
59
  // Replaced by `parseDigits()`.
60
- //
61
- // Deprecated: `DIGIT_PLACEHOLDER` was used by `react-phone-number-input`.
62
- // Not used anymore.
63
- //
64
- exports.DIGITS = require('./build/helpers/parseDigits.js').DIGITS
60
+ exports.DIGITS = require('./build/helpers/parseDigits.js').DIGITS
61
+ // Deprecated:
62
+ // `DIGIT_PLACEHOLDER` is the character that `AsYouType` formatter uses in a phone number template.
63
+ // It's basically an "x" character. I guess, there's no point in exporting it as a constant
64
+ // because the established convention is that it's an "x" character so everyone just assumes "x".
65
65
  exports.DIGIT_PLACEHOLDER = require('./build/AsYouTypeFormatter.js').DIGIT_PLACEHOLDER
66
66
 
67
67
  exports.getCountries = require('./build/getCountries.js').default
@@ -0,0 +1,445 @@
1
+ import Metadata from './metadata.js';
2
+ import PhoneNumber from './PhoneNumber.js';
3
+ import AsYouTypeState from './AsYouTypeState.js';
4
+ import AsYouTypeFormatter, { DIGIT_PLACEHOLDER } from './AsYouTypeFormatter.js';
5
+ import AsYouTypeParser, { extractFormattedDigitsAndPlus } from './AsYouTypeParser.js';
6
+ import getCountryByCallingCode from './helpers/getCountryByCallingCode.js';
7
+ import getCountryByNationalNumber from './helpers/getCountryByNationalNumber.js';
8
+ import isObject from './helpers/isObject.js';
9
+ const USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;
10
+ export default class AsYouType {
11
+ /**
12
+ * @param {(string|object)?} [optionsOrDefaultCountry] - The default country used for parsing non-international phone numbers. Can also be an `options` object.
13
+ * @param {Object} metadata
14
+ */
15
+ constructor(optionsOrDefaultCountry, metadata) {
16
+ this.metadata = new Metadata(metadata);
17
+ const [defaultCountry, defaultCallingCode] = this.getCountryAndCallingCode(optionsOrDefaultCountry);
18
+ // `this.defaultCountry` and `this.defaultCallingCode` aren't required to be in sync.
19
+ // For example, `this.defaultCountry` could be `"AR"` and `this.defaultCallingCode` could be `undefined`.
20
+ // So `this.defaultCountry` and `this.defaultCallingCode` are totally independent.
21
+ this.defaultCountry = defaultCountry;
22
+ this.defaultCallingCode = defaultCallingCode;
23
+ this.reset();
24
+ }
25
+ getCountryAndCallingCode(optionsOrDefaultCountry) {
26
+ // Set `defaultCountry` and `defaultCallingCode` options.
27
+ let defaultCountry;
28
+ let defaultCallingCode;
29
+ // Turns out `null` also has type "object". Weird.
30
+ if (optionsOrDefaultCountry) {
31
+ if (isObject(optionsOrDefaultCountry)) {
32
+ defaultCountry = optionsOrDefaultCountry.defaultCountry;
33
+ defaultCallingCode = optionsOrDefaultCountry.defaultCallingCode;
34
+ } else {
35
+ defaultCountry = optionsOrDefaultCountry;
36
+ }
37
+ }
38
+ if (defaultCountry && !this.metadata.hasCountry(defaultCountry)) {
39
+ defaultCountry = undefined;
40
+ }
41
+ if (defaultCallingCode) {
42
+ /* istanbul ignore if */
43
+ if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
44
+ if (this.metadata.isNonGeographicCallingCode(defaultCallingCode)) {
45
+ defaultCountry = '001';
46
+ }
47
+ }
48
+ }
49
+ return [defaultCountry, defaultCallingCode];
50
+ }
51
+
52
+ /**
53
+ * Inputs "next" phone number characters.
54
+ * @param {string} text
55
+ * @return {string} Formatted phone number characters that have been input so far.
56
+ */
57
+ input(text) {
58
+ const {
59
+ digits,
60
+ justLeadingPlus
61
+ } = this.parser.input(text, this.state);
62
+ if (justLeadingPlus) {
63
+ this.formattedOutput = '+';
64
+ } else if (digits) {
65
+ this.determineTheCountryIfNeeded();
66
+ // Match the available formats by the currently available leading digits.
67
+ if (this.state.nationalSignificantNumber) {
68
+ this.formatter.narrowDownMatchingFormats(this.state);
69
+ }
70
+ let formattedNationalNumber;
71
+ if (this.metadata.hasSelectedNumberingPlan()) {
72
+ formattedNationalNumber = this.formatter.format(digits, this.state);
73
+ }
74
+ if (formattedNationalNumber === undefined) {
75
+ // See if another national (significant) number could be re-extracted.
76
+ if (this.parser.reExtractNationalSignificantNumber(this.state)) {
77
+ this.determineTheCountryIfNeeded();
78
+ // If it could, then re-try formatting the new national (significant) number.
79
+ const nationalDigits = this.state.getNationalDigits();
80
+ if (nationalDigits) {
81
+ formattedNationalNumber = this.formatter.format(nationalDigits, this.state);
82
+ }
83
+ }
84
+ }
85
+ this.formattedOutput = formattedNationalNumber ? this.getFullNumber(formattedNationalNumber) : this.getNonFormattedNumber();
86
+ }
87
+ return this.formattedOutput;
88
+ }
89
+ reset() {
90
+ this.state = new AsYouTypeState({
91
+ onCountryChange: country => {
92
+ // Before version `1.6.0`, the official `AsYouType` formatter API
93
+ // included a `.country` property on an `AsYouType` instance.
94
+ // Since that property (along with the others) have been moved to
95
+ // `this.state`, `this.country` property is emulated for compatibility
96
+ // with the old versions.
97
+ this.country = country;
98
+ },
99
+ onCallingCodeChange: (callingCode, country) => {
100
+ this.metadata.selectNumberingPlan(country, callingCode);
101
+ this.formatter.reset(this.metadata.numberingPlan, this.state);
102
+ this.parser.reset(this.metadata.numberingPlan);
103
+ }
104
+ });
105
+ this.formatter = new AsYouTypeFormatter({
106
+ state: this.state,
107
+ metadata: this.metadata
108
+ });
109
+ this.parser = new AsYouTypeParser({
110
+ defaultCountry: this.defaultCountry,
111
+ defaultCallingCode: this.defaultCallingCode,
112
+ metadata: this.metadata,
113
+ state: this.state,
114
+ onNationalSignificantNumberChange: () => {
115
+ this.determineTheCountryIfNeeded();
116
+ this.formatter.reset(this.metadata.numberingPlan, this.state);
117
+ }
118
+ });
119
+ this.state.reset({
120
+ country: this.defaultCountry,
121
+ callingCode: this.defaultCallingCode
122
+ });
123
+ this.formattedOutput = '';
124
+ return this;
125
+ }
126
+
127
+ /**
128
+ * Returns `true` if the phone number is being input in international format.
129
+ * In other words, returns `true` if and only if the parsed phone number starts with a `"+"`.
130
+ * @return {boolean}
131
+ */
132
+ isInternational() {
133
+ return this.state.international;
134
+ }
135
+
136
+ /**
137
+ * Returns the "calling code" part of the phone number when it's being input
138
+ * in an international format.
139
+ * If no valid calling code has been entered so far, returns `undefined`.
140
+ * @return {string} [callingCode]
141
+ */
142
+ getCallingCode() {
143
+ // If the number is being input in national format and some "default calling code"
144
+ // has been passed to `AsYouType` constructor, then `this.state.callingCode`
145
+ // is equal to that "default calling code".
146
+ //
147
+ // If the number is being input in national format and no "default calling code"
148
+ // has been passed to `AsYouType` constructor, then returns `undefined`,
149
+ // even if a "default country" has been passed to `AsYouType` constructor.
150
+ //
151
+ if (this.isInternational()) {
152
+ return this.state.callingCode;
153
+ }
154
+ }
155
+
156
+ // A legacy alias.
157
+ getCountryCallingCode() {
158
+ return this.getCallingCode();
159
+ }
160
+
161
+ /**
162
+ * Returns a two-letter country code of the phone number.
163
+ * Returns `undefined` for "non-geographic" phone numbering plans.
164
+ * Returns `undefined` if no phone number has been input yet.
165
+ * @return {string} [country]
166
+ */
167
+ getCountry() {
168
+ const {
169
+ digits
170
+ } = this.state;
171
+ // Return `undefined` if no digits have been input yet.
172
+ if (digits) {
173
+ return this._getCountry();
174
+ }
175
+ }
176
+
177
+ /**
178
+ * Returns a two-letter country code of the phone number.
179
+ * Returns `undefined` for "non-geographic" phone numbering plans.
180
+ * @return {string} [country]
181
+ */
182
+ _getCountry() {
183
+ const {
184
+ country
185
+ } = this.state;
186
+ /* istanbul ignore if */
187
+ if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
188
+ // `AsYouType.getCountry()` returns `undefined`
189
+ // for "non-geographic" phone numbering plans.
190
+ if (country === '001') {
191
+ return;
192
+ }
193
+ }
194
+ return country;
195
+ }
196
+ determineTheCountryIfNeeded() {
197
+ // Suppose a user enters a phone number in international format,
198
+ // and there're several countries corresponding to that country calling code,
199
+ // and a country has been derived from the number, and then
200
+ // a user enters one more digit and the number is no longer
201
+ // valid for the derived country, so the country should be re-derived
202
+ // on every new digit in those cases.
203
+ //
204
+ // If the phone number is being input in national format,
205
+ // then it could be a case when `defaultCountry` wasn't specified
206
+ // when creating `AsYouType` instance, and just `defaultCallingCode` was specified,
207
+ // and that "calling code" could correspond to a "non-geographic entity",
208
+ // or there could be several countries corresponding to that country calling code.
209
+ // In those cases, `this.country` is `undefined` and should be derived
210
+ // from the number. Again, if country calling code is ambiguous, then
211
+ // `this.country` should be re-derived with each new digit.
212
+ //
213
+ if (!this.state.country || this.isCountryCallingCodeAmbiguous()) {
214
+ this.determineTheCountry();
215
+ }
216
+ }
217
+
218
+ // Prepends `+CountryCode ` in case of an international phone number
219
+ getFullNumber(formattedNationalNumber) {
220
+ if (this.isInternational()) {
221
+ const prefix = text => this.formatter.getInternationalPrefixBeforeCountryCallingCode(this.state, {
222
+ spacing: text ? true : false
223
+ }) + text;
224
+ const {
225
+ callingCode
226
+ } = this.state;
227
+ if (!callingCode) {
228
+ return prefix(`${this.state.getDigitsWithoutInternationalPrefix()}`);
229
+ }
230
+ if (!formattedNationalNumber) {
231
+ return prefix(callingCode);
232
+ }
233
+ return prefix(`${callingCode} ${formattedNationalNumber}`);
234
+ }
235
+ return formattedNationalNumber;
236
+ }
237
+ getNonFormattedNationalNumberWithPrefix() {
238
+ const {
239
+ nationalSignificantNumber,
240
+ prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix,
241
+ nationalPrefix
242
+ } = this.state;
243
+ let number = nationalSignificantNumber;
244
+ const prefix = prefixBeforeNationalSignificantNumberThatIsNotNationalPrefix || nationalPrefix;
245
+ if (prefix) {
246
+ number = prefix + number;
247
+ }
248
+ return number;
249
+ }
250
+ getNonFormattedNumber() {
251
+ const {
252
+ nationalSignificantNumberIsModified
253
+ } = this.state;
254
+ return this.getFullNumber(nationalSignificantNumberIsModified ? this.state.getNationalDigits() : this.getNonFormattedNationalNumberWithPrefix());
255
+ }
256
+ getNonFormattedTemplate() {
257
+ const number = this.getNonFormattedNumber();
258
+ if (number) {
259
+ return number.replace(/[\+\d]/g, DIGIT_PLACEHOLDER);
260
+ }
261
+ }
262
+ isCountryCallingCodeAmbiguous() {
263
+ const {
264
+ callingCode
265
+ } = this.state;
266
+ const countryCodes = this.metadata.getCountryCodesForCallingCode(callingCode);
267
+ return countryCodes && countryCodes.length > 1;
268
+ }
269
+
270
+ // Determines the exact country of the phone number
271
+ // entered so far based on the country phone code
272
+ // and the national phone number.
273
+ determineTheCountry() {
274
+ this.state.setCountry(getCountryByCallingCode(this.isInternational() ? this.state.callingCode : this.defaultCallingCode, {
275
+ nationalNumber: this.state.nationalSignificantNumber,
276
+ metadata: this.metadata
277
+ }));
278
+ }
279
+
280
+ /**
281
+ * Returns a E.164 phone number value for the user's input.
282
+ *
283
+ * For example, for country `"US"` and input `"(222) 333-4444"`
284
+ * it will return `"+12223334444"`.
285
+ *
286
+ * For international phone number input, it will also auto-correct
287
+ * some minor errors such as using a national prefix when writing
288
+ * an international phone number. For example, if the user inputs
289
+ * `"+44 0 7400 000000"` then it will return an auto-corrected
290
+ * `"+447400000000"` phone number value.
291
+ *
292
+ * Will return `undefined` if no digits have been input,
293
+ * or when inputting a phone number in national format and no
294
+ * default country or default "country calling code" have been set.
295
+ *
296
+ * @return {string} [value]
297
+ */
298
+ getNumberValue() {
299
+ const {
300
+ digits,
301
+ callingCode,
302
+ country,
303
+ nationalSignificantNumber
304
+ } = this.state;
305
+
306
+ // Will return `undefined` if no digits have been input.
307
+ if (!digits) {
308
+ return;
309
+ }
310
+ if (this.isInternational()) {
311
+ if (callingCode) {
312
+ return '+' + callingCode + nationalSignificantNumber;
313
+ } else {
314
+ return '+' + digits;
315
+ }
316
+ } else {
317
+ if (country || callingCode) {
318
+ const callingCode_ = country ? this.metadata.countryCallingCode() : callingCode;
319
+ return '+' + callingCode_ + nationalSignificantNumber;
320
+ }
321
+ }
322
+ }
323
+
324
+ /**
325
+ * Returns an instance of `PhoneNumber` class.
326
+ * Will return `undefined` if no national (significant) number
327
+ * digits have been entered so far, or if no `defaultCountry` has been
328
+ * set and the user enters a phone number not in international format.
329
+ */
330
+ getNumber() {
331
+ const {
332
+ nationalSignificantNumber,
333
+ carrierCode,
334
+ callingCode
335
+ } = this.state;
336
+
337
+ // `this._getCountry()` is basically same as `this.state.country`
338
+ // with the only change that it return `undefined` in case of a
339
+ // "non-geographic" numbering plan instead of `"001"` "internal use" value.
340
+ let country = this._getCountry();
341
+ if (!nationalSignificantNumber) {
342
+ return;
343
+ }
344
+
345
+ // `state.country` and `state.callingCode` aren't required to be in sync.
346
+ // For example, `country` could be `"AR"` and `callingCode` could be `undefined`.
347
+ // So `country` and `callingCode` are totally independent.
348
+
349
+ if (!country && !callingCode) {
350
+ return;
351
+ }
352
+
353
+ // By default, if `defaultCountry` parameter was passed when
354
+ // creating `AsYouType` instance, `state.country` is gonna be
355
+ // that `defaultCountry`, which doesn't entirely conform with
356
+ // `parsePhoneNumber()`'s behavior where it attempts to determine
357
+ // the country more precisely in cases when multiple countries
358
+ // could correspond to the same `countryCallingCode`.
359
+ // https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/103#note_1417192969
360
+ //
361
+ // Because `AsYouType.getNumber()` method is supposed to be a 1:1
362
+ // equivalent for `parsePhoneNumber(AsYouType.getNumberValue())`,
363
+ // then it should also behave accordingly in cases of `country` ambiguity.
364
+ // That's how users of this library would expect it to behave anyway.
365
+ //
366
+ if (country) {
367
+ if (country === this.defaultCountry) {
368
+ // `state.country` and `state.callingCode` aren't required to be in sync.
369
+ // For example, `state.country` could be `"AR"` and `state.callingCode` could be `undefined`.
370
+ // So `state.country` and `state.callingCode` are totally independent.
371
+ const metadata = new Metadata(this.metadata.metadata);
372
+ metadata.selectNumberingPlan(country);
373
+ const _callingCode = metadata.numberingPlan.callingCode();
374
+ const ambiguousCountries = this.metadata.getCountryCodesForCallingCode(_callingCode);
375
+ if (ambiguousCountries.length > 1) {
376
+ const exactCountry = getCountryByNationalNumber(nationalSignificantNumber, {
377
+ countries: ambiguousCountries,
378
+ metadata: this.metadata.metadata
379
+ });
380
+ if (exactCountry) {
381
+ country = exactCountry;
382
+ }
383
+ }
384
+ }
385
+ }
386
+ const phoneNumber = new PhoneNumber(country || callingCode, nationalSignificantNumber, this.metadata.metadata);
387
+ if (carrierCode) {
388
+ phoneNumber.carrierCode = carrierCode;
389
+ }
390
+ // Phone number extensions are not supported by "As You Type" formatter.
391
+ return phoneNumber;
392
+ }
393
+
394
+ /**
395
+ * Returns `true` if the phone number is "possible".
396
+ * Is just a shortcut for `PhoneNumber.isPossible()`.
397
+ * @return {boolean}
398
+ */
399
+ isPossible() {
400
+ const phoneNumber = this.getNumber();
401
+ if (!phoneNumber) {
402
+ return false;
403
+ }
404
+ return phoneNumber.isPossible();
405
+ }
406
+
407
+ /**
408
+ * Returns `true` if the phone number is "valid".
409
+ * Is just a shortcut for `PhoneNumber.isValid()`.
410
+ * @return {boolean}
411
+ */
412
+ isValid() {
413
+ const phoneNumber = this.getNumber();
414
+ if (!phoneNumber) {
415
+ return false;
416
+ }
417
+ return phoneNumber.isValid();
418
+ }
419
+
420
+ /**
421
+ * @deprecated
422
+ * This method is used in `react-phone-number-input/source/input-control.js`
423
+ * in versions before `3.0.16`.
424
+ */
425
+ getNationalNumber() {
426
+ return this.state.nationalSignificantNumber;
427
+ }
428
+
429
+ /**
430
+ * Returns the phone number characters entered by the user.
431
+ * @return {string}
432
+ */
433
+ getChars() {
434
+ return (this.state.international ? '+' : '') + this.state.digits;
435
+ }
436
+
437
+ /**
438
+ * Returns the template for the formatted phone number.
439
+ * @return {string}
440
+ */
441
+ getTemplate() {
442
+ return this.formatter.getTemplate(this.state) || this.getNonFormattedTemplate() || '';
443
+ }
444
+ }
445
+ //# sourceMappingURL=AsYouType.js.map