libphonenumber-js 1.9.2 → 1.9.6

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 (367) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +34 -9
  3. package/build/AsYouType.js +16 -21
  4. package/build/AsYouType.js.map +1 -1
  5. package/build/AsYouType.test.js +12 -3
  6. package/build/AsYouType.test.js.map +1 -1
  7. package/build/AsYouTypeFormatter.complete.js +4 -4
  8. package/build/AsYouTypeFormatter.complete.js.map +1 -1
  9. package/build/AsYouTypeFormatter.js +25 -15
  10. package/build/AsYouTypeFormatter.js.map +1 -1
  11. package/build/AsYouTypeParser.js +70 -37
  12. package/build/AsYouTypeParser.js.map +1 -1
  13. package/build/AsYouTypeState.js +1 -0
  14. package/build/AsYouTypeState.js.map +1 -1
  15. package/build/PhoneNumber.js +2 -2
  16. package/build/PhoneNumber.js.map +1 -1
  17. package/build/PhoneNumberMatcher.js +20 -16
  18. package/build/PhoneNumberMatcher.js.map +1 -1
  19. package/build/findNumbers/Leniency.js +1 -1
  20. package/build/findNumbers/Leniency.js.map +1 -1
  21. package/build/findNumbers.test.js +31 -22
  22. package/build/findNumbers.test.js.map +1 -1
  23. package/build/findPhoneNumbers_.js +21 -4
  24. package/build/findPhoneNumbers_.js.map +1 -1
  25. package/build/format.test.js +0 -6
  26. package/build/format.test.js.map +1 -1
  27. package/build/formatNumberForMobileDialing.js +3 -3
  28. package/build/formatNumberForMobileDialing.js.map +1 -1
  29. package/build/format_.js +15 -84
  30. package/build/format_.js.map +1 -1
  31. package/build/getNumberType.js +3 -3
  32. package/build/getNumberType.js.map +1 -1
  33. package/build/{RFC3966.js → helpers/RFC3966.js} +0 -0
  34. package/build/helpers/RFC3966.js.map +1 -0
  35. package/build/{RFC3966.test.js → helpers/RFC3966.test.js} +0 -0
  36. package/build/helpers/RFC3966.test.js.map +1 -0
  37. package/build/helpers/applyInternationalSeparatorStyle.js +43 -0
  38. package/build/helpers/applyInternationalSeparatorStyle.js.map +1 -0
  39. package/build/helpers/applyInternationalSeparatorStyle.test.js +13 -0
  40. package/build/helpers/applyInternationalSeparatorStyle.test.js.map +1 -0
  41. package/build/{checkNumberLength.js → helpers/checkNumberLength.js} +4 -2
  42. package/build/helpers/checkNumberLength.js.map +1 -0
  43. package/build/{checkNumberLength.test.js → helpers/checkNumberLength.test.js} +2 -2
  44. package/build/helpers/checkNumberLength.test.js.map +1 -0
  45. package/build/{extension.js → helpers/extension/createExtensionPattern.js} +3 -56
  46. package/build/helpers/extension/createExtensionPattern.js.map +1 -0
  47. package/build/helpers/extension/extractExtension.js +42 -0
  48. package/build/helpers/extension/extractExtension.js.map +1 -0
  49. package/build/helpers/extractCountryCallingCode.js +114 -0
  50. package/build/helpers/extractCountryCallingCode.js.map +1 -0
  51. package/build/helpers/extractCountryCallingCode.test.js +22 -0
  52. package/build/helpers/extractCountryCallingCode.test.js.map +1 -0
  53. package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +63 -0
  54. package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -0
  55. package/build/helpers/extractNationalNumber.js +110 -0
  56. package/build/helpers/extractNationalNumber.js.map +1 -0
  57. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +114 -0
  58. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -0
  59. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +22 -0
  60. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js.map +1 -0
  61. package/build/helpers/formatNationalNumberUsingFormat.js +46 -0
  62. package/build/helpers/formatNationalNumberUsingFormat.js.map +1 -0
  63. package/build/helpers/getCountryByCallingCode.js +73 -0
  64. package/build/helpers/getCountryByCallingCode.js.map +1 -0
  65. package/build/helpers/getIddPrefix.js +34 -0
  66. package/build/helpers/getIddPrefix.js.map +1 -0
  67. package/build/{getNumberType_.js → helpers/getNumberType.js} +12 -12
  68. package/build/helpers/getNumberType.js.map +1 -0
  69. package/build/{isViablePhoneNumber.js → helpers/isViablePhoneNumber.js} +5 -3
  70. package/build/helpers/isViablePhoneNumber.js.map +1 -0
  71. package/build/helpers/matchesEntirely.js +19 -0
  72. package/build/helpers/matchesEntirely.js.map +1 -0
  73. package/build/helpers/matchesEntirely.test.js +15 -0
  74. package/build/helpers/matchesEntirely.test.js.map +1 -0
  75. package/build/{util.js → helpers/mergeArrays.js} +3 -18
  76. package/build/helpers/mergeArrays.js.map +1 -0
  77. package/build/helpers/mergeArrays.test.js +12 -0
  78. package/build/helpers/mergeArrays.test.js.map +1 -0
  79. package/build/{parseDigits.js → helpers/parseDigits.js} +0 -0
  80. package/build/helpers/parseDigits.js.map +1 -0
  81. package/build/{parseDigits.test.js → helpers/parseDigits.test.js} +0 -0
  82. package/build/helpers/parseDigits.test.js.map +1 -0
  83. package/build/helpers/stripIddPrefix.js +46 -0
  84. package/build/helpers/stripIddPrefix.js.map +1 -0
  85. package/build/helpers/stripIddPrefix.test.js +23 -0
  86. package/build/helpers/stripIddPrefix.test.js.map +1 -0
  87. package/build/isPossibleNumber_.js +1 -1
  88. package/build/isPossibleNumber_.js.map +1 -1
  89. package/build/isValidNumberForRegion.js +1 -1
  90. package/build/isValidNumberForRegion.js.map +1 -1
  91. package/build/parse.test.js +1 -25
  92. package/build/parse.test.js.map +1 -1
  93. package/build/parseIncompletePhoneNumber.js +9 -6
  94. package/build/parseIncompletePhoneNumber.js.map +1 -1
  95. package/build/parse_.js +19 -425
  96. package/build/parse_.js.map +1 -1
  97. package/build/validate_.js +4 -4
  98. package/build/validate_.js.map +1 -1
  99. package/bundle/libphonenumber-js.min.js +1 -1
  100. package/bundle/libphonenumber-js.min.js.map +1 -1
  101. package/bundle/libphonenumber-max.js +1 -1
  102. package/bundle/libphonenumber-max.js.map +1 -1
  103. package/bundle/libphonenumber-min.js +1 -1
  104. package/bundle/libphonenumber-min.js.map +1 -1
  105. package/bundle/libphonenumber-mobile.js +1 -1
  106. package/bundle/libphonenumber-mobile.js.map +1 -1
  107. package/core/index.commonjs.js +5 -3
  108. package/core/index.d.ts +9 -1
  109. package/core/index.js +6 -2
  110. package/custom.d.ts +9 -1
  111. package/custom.js +5 -6
  112. package/es6/AsYouType.js +17 -22
  113. package/es6/AsYouType.js.map +1 -1
  114. package/es6/AsYouType.test.js +12 -3
  115. package/es6/AsYouType.test.js.map +1 -1
  116. package/es6/AsYouTypeFormatter.complete.js +3 -3
  117. package/es6/AsYouTypeFormatter.complete.js.map +1 -1
  118. package/es6/AsYouTypeFormatter.js +22 -13
  119. package/es6/AsYouTypeFormatter.js.map +1 -1
  120. package/es6/AsYouTypeParser.js +65 -32
  121. package/es6/AsYouTypeParser.js.map +1 -1
  122. package/es6/AsYouTypeState.js +1 -0
  123. package/es6/AsYouTypeState.js.map +1 -1
  124. package/es6/PhoneNumber.js +1 -1
  125. package/es6/PhoneNumber.js.map +1 -1
  126. package/es6/PhoneNumberMatcher.js +18 -15
  127. package/es6/PhoneNumberMatcher.js.map +1 -1
  128. package/es6/findNumbers/Leniency.js +1 -1
  129. package/es6/findNumbers/Leniency.js.map +1 -1
  130. package/es6/findNumbers.test.js +10 -1
  131. package/es6/findNumbers.test.js.map +1 -1
  132. package/es6/findPhoneNumbers_.js +19 -2
  133. package/es6/findPhoneNumbers_.js.map +1 -1
  134. package/es6/format.test.js +0 -5
  135. package/es6/format.test.js.map +1 -1
  136. package/es6/formatNumberForMobileDialing.js +2 -2
  137. package/es6/formatNumberForMobileDialing.js.map +1 -1
  138. package/es6/format_.js +11 -76
  139. package/es6/format_.js.map +1 -1
  140. package/es6/getNumberType.js +2 -2
  141. package/es6/getNumberType.js.map +1 -1
  142. package/es6/{RFC3966.js → helpers/RFC3966.js} +0 -0
  143. package/es6/helpers/RFC3966.js.map +1 -0
  144. package/es6/{RFC3966.test.js → helpers/RFC3966.test.js} +0 -0
  145. package/es6/helpers/RFC3966.test.js.map +1 -0
  146. package/es6/helpers/applyInternationalSeparatorStyle.js +35 -0
  147. package/es6/helpers/applyInternationalSeparatorStyle.js.map +1 -0
  148. package/es6/helpers/applyInternationalSeparatorStyle.test.js +8 -0
  149. package/es6/helpers/applyInternationalSeparatorStyle.test.js.map +1 -0
  150. package/es6/{checkNumberLength.js → helpers/checkNumberLength.js} +1 -1
  151. package/es6/helpers/checkNumberLength.js.map +1 -0
  152. package/es6/{checkNumberLength.test.js → helpers/checkNumberLength.test.js} +2 -2
  153. package/es6/helpers/checkNumberLength.test.js.map +1 -0
  154. package/es6/{extension.js → helpers/extension/createExtensionPattern.js} +3 -51
  155. package/es6/helpers/extension/createExtensionPattern.js.map +1 -0
  156. package/es6/helpers/extension/extractExtension.js +32 -0
  157. package/es6/helpers/extension/extractExtension.js.map +1 -0
  158. package/es6/helpers/extractCountryCallingCode.js +102 -0
  159. package/es6/helpers/extractCountryCallingCode.js.map +1 -0
  160. package/es6/helpers/extractCountryCallingCode.test.js +16 -0
  161. package/es6/helpers/extractCountryCallingCode.test.js.map +1 -0
  162. package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +50 -0
  163. package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -0
  164. package/es6/helpers/extractNationalNumber.js +98 -0
  165. package/es6/helpers/extractNationalNumber.js.map +1 -0
  166. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +107 -0
  167. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -0
  168. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +15 -0
  169. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js.map +1 -0
  170. package/es6/helpers/formatNationalNumberUsingFormat.js +33 -0
  171. package/es6/helpers/formatNationalNumberUsingFormat.js.map +1 -0
  172. package/es6/helpers/getCountryByCallingCode.js +61 -0
  173. package/es6/helpers/getCountryByCallingCode.js.map +1 -0
  174. package/es6/helpers/getIddPrefix.js +25 -0
  175. package/es6/helpers/getIddPrefix.js.map +1 -0
  176. package/es6/{getNumberType_.js → helpers/getNumberType.js} +9 -9
  177. package/es6/helpers/getNumberType.js.map +1 -0
  178. package/es6/{isViablePhoneNumber.js → helpers/isViablePhoneNumber.js} +2 -2
  179. package/es6/helpers/isViablePhoneNumber.js.map +1 -0
  180. package/es6/helpers/matchesEntirely.js +12 -0
  181. package/es6/helpers/matchesEntirely.js.map +1 -0
  182. package/es6/helpers/matchesEntirely.test.js +10 -0
  183. package/es6/helpers/matchesEntirely.test.js.map +1 -0
  184. package/es6/{util.js → helpers/mergeArrays.js} +3 -16
  185. package/es6/helpers/mergeArrays.js.map +1 -0
  186. package/es6/helpers/mergeArrays.test.js +7 -0
  187. package/es6/helpers/mergeArrays.test.js.map +1 -0
  188. package/es6/{parseDigits.js → helpers/parseDigits.js} +0 -0
  189. package/es6/helpers/parseDigits.js.map +1 -0
  190. package/es6/{parseDigits.test.js → helpers/parseDigits.test.js} +0 -0
  191. package/es6/helpers/parseDigits.test.js.map +1 -0
  192. package/es6/helpers/stripIddPrefix.js +34 -0
  193. package/es6/helpers/stripIddPrefix.js.map +1 -0
  194. package/es6/helpers/stripIddPrefix.test.js +17 -0
  195. package/es6/helpers/stripIddPrefix.test.js.map +1 -0
  196. package/es6/isPossibleNumber_.js +1 -1
  197. package/es6/isPossibleNumber_.js.map +1 -1
  198. package/es6/isValidNumberForRegion.js +1 -1
  199. package/es6/isValidNumberForRegion.js.map +1 -1
  200. package/es6/parse.test.js +1 -24
  201. package/es6/parse.test.js.map +1 -1
  202. package/es6/parseIncompletePhoneNumber.js +9 -6
  203. package/es6/parseIncompletePhoneNumber.js.map +1 -1
  204. package/es6/parse_.js +12 -411
  205. package/es6/parse_.js.map +1 -1
  206. package/es6/validate_.js +2 -2
  207. package/es6/validate_.js.map +1 -1
  208. package/index.common.js +71 -183
  209. package/index.d.ts +9 -5
  210. package/index.es6.exports/PhoneNumberSearch.js +11 -0
  211. package/index.es6.exports/findPhoneNumbers.js +7 -0
  212. package/index.es6.exports/format.js +7 -0
  213. package/index.es6.exports/getNumberType.js +7 -0
  214. package/index.es6.exports/isPossibleNumber.js +7 -0
  215. package/index.es6.exports/isValidNumber.js +7 -0
  216. package/index.es6.exports/isValidNumberForRegion.js +7 -0
  217. package/index.es6.exports/parse.js +7 -0
  218. package/index.es6.exports/searchPhoneNumbers.js +7 -0
  219. package/index.es6.js +46 -254
  220. package/max/exports/AsYouType.js +9 -0
  221. package/max/exports/Metadata.js +9 -0
  222. package/max/exports/PhoneNumberMatcher.js +8 -0
  223. package/max/exports/findNumbers.js +6 -0
  224. package/max/exports/findPhoneNumbersInText.js +6 -0
  225. package/max/exports/formatIncompletePhoneNumber.js +6 -0
  226. package/max/exports/getCountries.js +6 -0
  227. package/max/exports/getCountryCallingCode.js +6 -0
  228. package/max/exports/getExampleNumber.js +6 -0
  229. package/max/exports/getExtPrefix.js +6 -0
  230. package/max/exports/isSupportedCountry.js +6 -0
  231. package/max/exports/parsePhoneNumberFromString.js +6 -0
  232. package/max/exports/parsePhoneNumberWithError.js +6 -0
  233. package/max/exports/searchNumbers.js +6 -0
  234. package/max/exports/searchPhoneNumbersInText.js +6 -0
  235. package/max/index.commonjs.js +1 -0
  236. package/max/index.js +23 -103
  237. package/max/metadata.js +11 -0
  238. package/metadata.full.json +1 -1
  239. package/metadata.full.json.js +1 -1
  240. package/metadata.min.json +1 -1
  241. package/metadata.min.json.js +1 -1
  242. package/metadata.mobile.json +1 -1
  243. package/metadata.mobile.json.js +1 -1
  244. package/min/exports/AsYouType.js +9 -0
  245. package/min/exports/Metadata.js +9 -0
  246. package/min/exports/PhoneNumberMatcher.js +8 -0
  247. package/min/exports/findNumbers.js +6 -0
  248. package/min/exports/findPhoneNumbersInText.js +6 -0
  249. package/min/exports/formatIncompletePhoneNumber.js +6 -0
  250. package/min/exports/getCountries.js +6 -0
  251. package/min/exports/getCountryCallingCode.js +6 -0
  252. package/min/exports/getExampleNumber.js +6 -0
  253. package/min/exports/getExtPrefix.js +6 -0
  254. package/min/exports/isSupportedCountry.js +6 -0
  255. package/min/exports/parsePhoneNumberFromString.js +6 -0
  256. package/min/exports/parsePhoneNumberWithError.js +6 -0
  257. package/min/exports/searchNumbers.js +6 -0
  258. package/min/exports/searchPhoneNumbersInText.js +6 -0
  259. package/min/index.commonjs.js +7 -0
  260. package/min/index.d.ts +11 -1
  261. package/min/index.js +23 -103
  262. package/min/metadata.js +11 -0
  263. package/mobile/exports/AsYouType.js +9 -0
  264. package/mobile/exports/Metadata.js +9 -0
  265. package/mobile/exports/PhoneNumberMatcher.js +8 -0
  266. package/mobile/exports/findNumbers.js +6 -0
  267. package/mobile/exports/findPhoneNumbersInText.js +6 -0
  268. package/mobile/exports/formatIncompletePhoneNumber.js +6 -0
  269. package/mobile/exports/getCountries.js +6 -0
  270. package/mobile/exports/getCountryCallingCode.js +6 -0
  271. package/mobile/exports/getExampleNumber.js +6 -0
  272. package/mobile/exports/getExtPrefix.js +6 -0
  273. package/mobile/exports/isSupportedCountry.js +6 -0
  274. package/mobile/exports/parsePhoneNumberFromString.js +6 -0
  275. package/mobile/exports/parsePhoneNumberWithError.js +6 -0
  276. package/mobile/exports/searchNumbers.js +6 -0
  277. package/mobile/exports/searchPhoneNumbersInText.js +6 -0
  278. package/mobile/index.commonjs.js +1 -0
  279. package/mobile/index.js +23 -103
  280. package/mobile/metadata.js +11 -0
  281. package/package.json +3 -2
  282. package/runnable/generate-country-codes.js +13 -0
  283. package/source/AsYouType.js +13 -23
  284. package/source/AsYouType.test.js +13 -3
  285. package/source/AsYouTypeFormatter.complete.js +3 -3
  286. package/source/AsYouTypeFormatter.js +21 -28
  287. package/source/AsYouTypeParser.js +65 -48
  288. package/source/AsYouTypeState.js +1 -0
  289. package/source/PhoneNumber.js +1 -1
  290. package/source/PhoneNumberMatcher.js +28 -35
  291. package/source/findNumbers/Leniency.js +1 -1
  292. package/source/findNumbers.test.js +14 -1
  293. package/source/findPhoneNumbers_.js +19 -2
  294. package/source/format.test.js +0 -6
  295. package/source/formatNumberForMobileDialing.js +2 -2
  296. package/source/format_.js +7 -86
  297. package/source/getNumberType.js +2 -2
  298. package/source/{RFC3966.js → helpers/RFC3966.js} +7 -16
  299. package/source/{RFC3966.test.js → helpers/RFC3966.test.js} +0 -0
  300. package/source/helpers/applyInternationalSeparatorStyle.js +35 -0
  301. package/source/helpers/applyInternationalSeparatorStyle.test.js +8 -0
  302. package/source/{checkNumberLength.js → helpers/checkNumberLength.js} +1 -1
  303. package/source/{checkNumberLength.test.js → helpers/checkNumberLength.test.js} +2 -2
  304. package/source/{extension.js → helpers/extension/createExtensionPattern.js} +2 -49
  305. package/source/helpers/extension/extractExtension.js +29 -0
  306. package/source/helpers/extractCountryCallingCode.js +106 -0
  307. package/source/helpers/extractCountryCallingCode.test.js +18 -0
  308. package/source/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +63 -0
  309. package/source/helpers/extractNationalNumber.js +92 -0
  310. package/source/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +104 -0
  311. package/source/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +15 -0
  312. package/source/helpers/formatNationalNumberUsingFormat.js +46 -0
  313. package/source/helpers/getCountryByCallingCode.js +44 -0
  314. package/source/helpers/getIddPrefix.js +23 -0
  315. package/source/{getNumberType_.js → helpers/getNumberType.js} +14 -28
  316. package/source/{isViablePhoneNumber.js → helpers/isViablePhoneNumber.js} +3 -4
  317. package/source/helpers/matchesEntirely.js +11 -0
  318. package/source/helpers/matchesEntirely.test.js +11 -0
  319. package/source/helpers/mergeArrays.js +24 -0
  320. package/source/helpers/mergeArrays.test.js +7 -0
  321. package/source/{parseDigits.js → helpers/parseDigits.js} +2 -4
  322. package/source/{parseDigits.test.js → helpers/parseDigits.test.js} +0 -0
  323. package/source/helpers/stripIddPrefix.js +30 -0
  324. package/source/helpers/stripIddPrefix.test.js +21 -0
  325. package/source/isPossibleNumber_.js +1 -1
  326. package/source/isValidNumberForRegion.js +1 -1
  327. package/source/parse.test.js +1 -28
  328. package/source/parseIncompletePhoneNumber.js +9 -6
  329. package/source/parse_.js +12 -405
  330. package/source/validate_.js +2 -2
  331. package/types.d.ts +16 -1
  332. package/build/IDD.js +0 -70
  333. package/build/IDD.js.map +0 -1
  334. package/build/IDD.test.js +0 -23
  335. package/build/IDD.test.js.map +0 -1
  336. package/build/RFC3966.js.map +0 -1
  337. package/build/RFC3966.test.js.map +0 -1
  338. package/build/checkNumberLength.js.map +0 -1
  339. package/build/checkNumberLength.test.js.map +0 -1
  340. package/build/extension.js.map +0 -1
  341. package/build/getNumberType_.js.map +0 -1
  342. package/build/isViablePhoneNumber.js.map +0 -1
  343. package/build/parseDigits.js.map +0 -1
  344. package/build/parseDigits.test.js.map +0 -1
  345. package/build/util.js.map +0 -1
  346. package/build/util.test.js +0 -16
  347. package/build/util.test.js.map +0 -1
  348. package/es6/IDD.js +0 -57
  349. package/es6/IDD.js.map +0 -1
  350. package/es6/IDD.test.js +0 -17
  351. package/es6/IDD.test.js.map +0 -1
  352. package/es6/RFC3966.js.map +0 -1
  353. package/es6/RFC3966.test.js.map +0 -1
  354. package/es6/checkNumberLength.js.map +0 -1
  355. package/es6/checkNumberLength.test.js.map +0 -1
  356. package/es6/extension.js.map +0 -1
  357. package/es6/getNumberType_.js.map +0 -1
  358. package/es6/isViablePhoneNumber.js.map +0 -1
  359. package/es6/parseDigits.js.map +0 -1
  360. package/es6/parseDigits.test.js.map +0 -1
  361. package/es6/util.js.map +0 -1
  362. package/es6/util.test.js +0 -13
  363. package/es6/util.test.js.map +0 -1
  364. package/source/IDD.js +0 -52
  365. package/source/IDD.test.js +0 -21
  366. package/source/util.js +0 -37
  367. package/source/util.test.js +0 -15
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ <!--
2
+ The exported `Metadata` name is already used for exporting the "raw" JSON metadata type.
3
+ Then, `Metadata` class has become exported, but its name is already taken, so TypeScript users seem to be unable to use the `Metadata` class.
4
+ If someone knows a solution then they could propose it in an issue.
5
+ -->
6
+
1
7
  <!-- Maybe rename `metadata.full.json` -> `metadata.max.json`. -->
2
8
 
3
9
  <!-- (breaking change) Moved `findPhoneNumbersInText()` to its own subpackage: `libphonenumber-js/find`. The default export is `searchPhoneNumbersInText()` that returns an ES6 "iterator". -->
@@ -63,6 +69,23 @@ And edit the README:
63
69
 
64
70
  <!-- (breaking change) Changed `countries` and `country_calling_codes` properties in metadata: now they're not properties but rather elements of an array (`countries` is an array now rather than an object; `countries` is `metadata[0]` and `country_calling_codes` is `metadata[1]`). If you were using a custom-generated metadata then it has to be re-generated for the new version. -->
65
71
 
72
+ 1.9.5 / 01.12.2020
73
+ ==================
74
+
75
+ * Fixed the [issue](https://gitlab.com/catamphetamine/libphonenumber-js/-/merge_requests/4) with `findPhoneNumbersInText()` returning incorrect `startAt` and `endsAt` positions in some cases.
76
+
77
+ 1.9.4 / 13.11.2020
78
+ ==================
79
+
80
+ * Refactored the main ES6 export in order to support "tree shaking".
81
+
82
+ 1.9.3 / 11.11.2020
83
+ ==================
84
+
85
+ * Added `AsYouType.getChars()` method.
86
+
87
+ * Added formatting of international phone numbers that have been input without a leading `+`.
88
+
66
89
  1.9.2 / 08.11.2020
67
90
  ==================
68
91
 
package/README.md CHANGED
@@ -12,7 +12,7 @@ If you’re trying to build a React component with it, take a look at [`react-ph
12
12
 
13
13
  ## LibPhoneNumber
14
14
 
15
- [`libphonenumber`](https://github.com/googlei18n/libphonenumber) is an ultimate phone number formatting and parsing library developed by Google for [Android](https://en.wikipedia.org/wiki/Android_(operating_system)) phones. It is written in C++ and Java, and, while it has an [official autogenerated javascript port](https://github.com/googlei18n/libphonenumber/tree/master/javascript), that port is tightly coupled to Google's `closure` javascript framework, and, when compiled into a [bundle](https://github.com/ruimarinho/google-libphonenumber), weighs about 550 kB (350 kB code + 200 kB metadata).
15
+ Google's [`libphonenumber`](https://github.com/googlei18n/libphonenumber) is an ultimate phone number formatting and parsing library developed by Google for [Android](https://en.wikipedia.org/wiki/Android_(operating_system)) phones. It is written in C++ and Java, and, while it has an [official autogenerated javascript port](https://github.com/googlei18n/libphonenumber/tree/master/javascript), that port is tightly coupled to Google's `closure` javascript framework, and, when compiled into a [bundle](https://github.com/ruimarinho/google-libphonenumber), weighs about 550 kB (350 kB code + 200 kB metadata).
16
16
 
17
17
  With many websites today asking for user's phone number, the internet could benefit from a simpler and smaller library that would just get the parsing and formatting right, and that's what `libphonenumber-js` is.
18
18
 
@@ -58,7 +58,7 @@ One part of me was curious about how all this phone number parsing and formattin
58
58
 
59
59
  ## GitHub
60
60
 
61
- On March 9th, 2020, GitHub, Inc. silently [banned](https://medium.com/@catamphetamine/how-github-blocked-me-and-all-my-libraries-c32c61f061d3) my account (erasing all my repos, issues and comments) without any notice or explanation. Because of that, all source codes had to be promptly moved to [GitLab](https://gitlab.com/catamphetamine/libphonenumber-js). GitHub repo is now deprecated, and the latest source codes can be found on GitLab, which is also the place to report any issues.
61
+ On March 9th, 2020, GitHub, Inc. silently [banned](https://medium.com/@catamphetamine/how-github-blocked-me-and-all-my-libraries-c32c61f061d3) my account (erasing all my repos, issues and comments) without any notice or explanation. Because of that, all source codes had to be promptly moved to GitLab. The [GitHub repo](https://github.com/catamphetamine/libphonenumber-js) is now only used as a backup (you can star the repo there too), and the primary repo is now the [GitLab one](https://gitlab.com/catamphetamine/libphonenumber-js). Issues can be reported in any repo.
62
62
 
63
63
  ## Install
64
64
 
@@ -492,7 +492,9 @@ The formatter instance also provides the following getters:
492
492
 
493
493
  * `getNumber(): PhoneNumber` — Returns the [`PhoneNumber`](#phonenumber). Will return `undefined` if no [national (significant) number](#national-significant-number) digits have been entered so far, or if no `defaultCountry`/`defaultCallingCode` has been set and the user enters a phone number not in international format.
494
494
 
495
- * `getTemplate(): string` — Returns the template used to format the output. Digits (and the `+` sign, if present) are denoted by `x`-es.
495
+ * `getChars(): string` — Returns the phone number characters entered by the user: digits and a `+` sign (if present). Returns an empty string if no phone number characters have been input.
496
+
497
+ * `getTemplate(): string` — Returns the template used to format the phone number characters (digits and a `+` sign, if present), which are denoted by `x`-es. Returns an empty string if no phone number characters have been input.
496
498
 
497
499
  ```js
498
500
  // National phone number input example.
@@ -501,18 +503,22 @@ const asYouType = new AsYouType('US')
501
503
 
502
504
  asYouType.input('2') === '2'
503
505
  asYouType.getNumber().number === '+12'
506
+ asYouType.getChars() === '2'
504
507
  asYouType.getTemplate() === 'x'
505
508
 
506
509
  asYouType.input('1') === '21'
507
510
  asYouType.getNumber().number === '+121'
511
+ asYouType.getChars() === '21'
508
512
  asYouType.getTemplate() === 'xx'
509
513
 
510
514
  asYouType.input('3') === '(213)'
511
515
  asYouType.getNumber().number === '+1213'
516
+ asYouType.getChars() === '213'
512
517
  asYouType.getTemplate() === '(xxx)'
513
518
 
514
519
  asYouType.input('3734253') === '(213) 373-4253'
515
520
  asYouType.getNumber().number === '+12133734253'
521
+ asYouType.getChars() === '2133734253'
516
522
  asYouType.getTemplate() === '(xxx) xxx-xxxx'
517
523
 
518
524
  // International phone number input example.
@@ -521,6 +527,7 @@ const asYouType = new AsYouType()
521
527
  asYouType.input('+1-213-373-4253') === '+1 213 373 4253'
522
528
  asYouType.getNumber().country === 'US'
523
529
  asYouType.getNumber().number === '+12133734253'
530
+ asYouType.getChars() === '+12133734253'
524
531
  asYouType.getTemplate() === 'xx xxx xxx xxxx'
525
532
  ```
526
533
 
@@ -767,15 +774,33 @@ getExtPrefix('GB') === ' x'
767
774
  ```
768
775
 
769
776
  <!--
770
- ### parsePhoneNumberCharacter(nextCharacter, value)
777
+ ### parsePhoneNumberCharacter(nextCharacter, prevParsedCharacters)
778
+
779
+ Parses next character while parsing phone number digits (including a `+`) from text: discards everything except `+` and digits, and `+` is only allowed at the start of a phone number.
771
780
 
772
- Parses next character while parsing `value` from text: discards everything except `+` and digits, and `+` is only allowed at the start of a phone number. Can be used for [`input-format`](https://gitlab.com/catamphetamine/input-format).
781
+ For example, is used in [`input-format`](https://gitlab.com/catamphetamine/input-format).
773
782
 
774
783
  ```js
775
- parsePhoneNumberCharacter('5', '880055') === '5'
776
- parsePhoneNumberCharacter('+', '') === '+'
777
- parsePhoneNumberCharacter('+', '+7800') === ''
778
- parsePhoneNumberCharacter('a', '') === ''
784
+ // Suppose a user inputs "+1 (213) 373-42-53".
785
+
786
+ parsePhoneNumberCharacter('+', undefined) === '+'
787
+ parsePhoneNumberCharacter('1', '+') === '1'
788
+ parsePhoneNumberCharacter(' ', '+1') === undefined
789
+ parsePhoneNumberCharacter('(', '+1') === undefined
790
+ parsePhoneNumberCharacter('2', '+1') === '2'
791
+ parsePhoneNumberCharacter('1', '+12') === '1'
792
+ parsePhoneNumberCharacter('3', '+121') === '3'
793
+ parsePhoneNumberCharacter(')', '+1213') === undefined
794
+ parsePhoneNumberCharacter(' ', '+1213') === undefined
795
+ parsePhoneNumberCharacter('3', '+1213') === '3'
796
+ parsePhoneNumberCharacter('7', '+12133') === '7'
797
+ parsePhoneNumberCharacter('3', '+121337') === '3'
798
+ parsePhoneNumberCharacter('-', '+121337') === undefined
799
+ parsePhoneNumberCharacter('4', '+1213373') === '4'
800
+ parsePhoneNumberCharacter('2', '+12133734') === '2'
801
+ parsePhoneNumberCharacter('-', '+12133734') === undefined
802
+ parsePhoneNumberCharacter('5', '+121337342') === '5'
803
+ parsePhoneNumberCharacter('3', '+1213373425') === '3'
779
804
  ```
780
805
  -->
781
806
 
@@ -15,7 +15,7 @@ var _AsYouTypeFormatter = _interopRequireWildcard(require("./AsYouTypeFormatter"
15
15
 
16
16
  var _AsYouTypeParser = _interopRequireWildcard(require("./AsYouTypeParser"));
17
17
 
18
- var _parse_ = require("./parse_");
18
+ var _getCountryByCallingCode = _interopRequireDefault(require("./helpers/getCountryByCallingCode"));
19
19
 
20
20
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
21
21
 
@@ -123,7 +123,8 @@ function () {
123
123
  if (formattedNationalNumber === undefined) {
124
124
  // See if another national (significant) number could be re-extracted.
125
125
  if (this.parser.reExtractNationalSignificantNumber(this.state)) {
126
- // If it could, then re-try formatting the new national (significant) number.
126
+ this.determineTheCountryIfNeeded(); // If it could, then re-try formatting the new national (significant) number.
127
+
127
128
  var nationalDigits = this.state.getNationalDigits();
128
129
 
129
130
  if (nationalDigits) {
@@ -271,7 +272,7 @@ function () {
271
272
 
272
273
  if (this.isInternational()) {
273
274
  var prefix = function prefix(text) {
274
- return _this2.formatter.getInternationalPrefixBeforeCountryCallingCode(_this2.state.IDDPrefix, {
275
+ return _this2.formatter.getInternationalPrefixBeforeCountryCallingCode(_this2.state, {
275
276
  spacing: text ? true : false
276
277
  }) + text;
277
278
  };
@@ -335,7 +336,7 @@ function () {
335
336
  }, {
336
337
  key: "determineTheCountry",
337
338
  value: function determineTheCountry() {
338
- this.state.setCountry((0, _parse_.findCountryCode)(this.isInternational() ? this.state.callingCode : this.defaultCallingCode, this.state.nationalSignificantNumber, this.metadata));
339
+ this.state.setCountry((0, _getCountryByCallingCode["default"])(this.isInternational() ? this.state.callingCode : this.defaultCallingCode, this.state.nationalSignificantNumber, this.metadata));
339
340
  }
340
341
  /**
341
342
  * Returns an instance of `PhoneNumber` class.
@@ -366,23 +367,7 @@ function () {
366
367
  }
367
368
 
368
369
  var countryCode = this.getCountry();
369
- var callingCode = this.getCountryCallingCode() || this.defaultCallingCode; // Google's AsYouType formatter supports sort of an "autocorrection" feature
370
- // when it "autocorrects" numbers that have been input for a country
371
- // with that country's calling code.
372
- // Such "autocorrection" feature looks weird, but different people have been requesting it:
373
- // https://github.com/catamphetamine/libphonenumber-js/issues/376
374
- // https://github.com/catamphetamine/libphonenumber-js/issues/375
375
- // https://github.com/catamphetamine/libphonenumber-js/issues/316
376
-
377
- if (!this.isInternational() && nationalSignificantNumber === this.state.digits) {
378
- var autoCorrected = (0, _AsYouTypeParser.autoCorrectInternationalNumberWithoutPlus)(this.state.digits, countryCode, callingCode, this.metadata);
379
-
380
- if (autoCorrected) {
381
- nationalSignificantNumber = autoCorrected.nationalNumber;
382
- carrierCode = autoCorrected.carrierCode;
383
- }
384
- }
385
-
370
+ var callingCode = this.getCountryCallingCode() || this.defaultCallingCode;
386
371
  var phoneNumber = new _PhoneNumber["default"](countryCode || callingCode, nationalSignificantNumber, this.metadata.metadata);
387
372
 
388
373
  if (carrierCode) {
@@ -437,6 +422,16 @@ function () {
437
422
  value: function getNationalNumber() {
438
423
  return this.state.nationalSignificantNumber;
439
424
  }
425
+ /**
426
+ * Returns the phone number characters entered by the user.
427
+ * @return {string}
428
+ */
429
+
430
+ }, {
431
+ key: "getChars",
432
+ value: function getChars() {
433
+ return (this.state.international ? '+' : '') + this.state.digits;
434
+ }
440
435
  /**
441
436
  * Returns the template for the formatted phone number.
442
437
  * @return {string}
@@ -1 +1 @@
1
- {"version":3,"sources":["../source/AsYouType.js"],"names":["USE_NON_GEOGRAPHIC_COUNTRY_CODE","AsYouType","optionsOrDefaultCountry","metadata","Metadata","getCountryAndCallingCode","defaultCountry","defaultCallingCode","reset","hasCountry","undefined","isNonGeographicCallingCode","text","parser","input","state","digits","justLeadingPlus","formattedOutput","determineTheCountryIfNeeded","nationalSignificantNumber","formatter","narrowDownMatchingFormats","formattedNationalNumber","hasSelectedNumberingPlan","format","reExtractNationalSignificantNumber","nationalDigits","getNationalDigits","getFullNumber","getNonFormattedNumber","AsYouTypeState","onCountryChange","country","onCallingCodeChange","callingCode","selectNumberingPlan","numberingPlan","AsYouTypeFormatter","AsYouTypeParser","onNationalSignificantNumberChange","international","getCallingCode","countryCode","isCountryCallingCodeAmbiguous","determineTheCountry","isInternational","prefix","getInternationalPrefixBeforeCountryCallingCode","IDDPrefix","spacing","getDigitsWithoutInternationalPrefix","complexPrefixBeforeNationalSignificantNumber","nationalPrefix","number","nationalSignificantNumberMatchesInput","getNonFormattedNationalNumberWithPrefix","replace","DIGIT_PLACEHOLDER","countryCodes","getCountryCodesForCallingCode","length","setCountry","carrierCode","getCountry","getCountryCallingCode","autoCorrected","nationalNumber","phoneNumber","PhoneNumber","getNumber","isPossible","isValid","getTemplate","getNonFormattedTemplate"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAMA,+BAA+B,GAAG,KAAxC;;IAEqBC,S;;;AACpB;;;;AAIA,qBAAYC,uBAAZ,EAAqCC,QAArC,EAA+C;AAAA;;AAC9C,SAAKA,QAAL,GAAgB,IAAIC,oBAAJ,CAAaD,QAAb,CAAhB;;AAD8C,gCAED,KAAKE,wBAAL,CAA8BH,uBAA9B,CAFC;AAAA;AAAA,QAEvCI,cAFuC;AAAA,QAEvBC,kBAFuB;;AAG9C,SAAKD,cAAL,GAAsBA,cAAtB;AACA,SAAKC,kBAAL,GAA0BA,kBAA1B;AACA,SAAKC,KAAL;AACA;;;;6CAEwBN,uB,EAAyB;AACjD;AACA,UAAII,cAAJ;AACA,UAAIC,kBAAJ,CAHiD,CAIjD;;AACA,UAAIL,uBAAJ,EAA6B;AAC5B,YAAI,QAAOA,uBAAP,MAAmC,QAAvC,EAAiD;AAChDI,UAAAA,cAAc,GAAGJ,uBAAuB,CAACI,cAAzC;AACAC,UAAAA,kBAAkB,GAAGL,uBAAuB,CAACK,kBAA7C;AACA,SAHD,MAGO;AACND,UAAAA,cAAc,GAAGJ,uBAAjB;AACA;AACD;;AACD,UAAII,cAAc,IAAI,CAAC,KAAKH,QAAL,CAAcM,UAAd,CAAyBH,cAAzB,CAAvB,EAAiE;AAChEA,QAAAA,cAAc,GAAGI,SAAjB;AACA;;AACD,UAAIH,kBAAJ,EAAwB;AACvB;AACA,YAAIP,+BAAJ,EAA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AA0BA,WAA1B;AACA,OA7CU,CA8CX;;;AACA,aAAOK,WAAP;AACA;AAED;;;;;;;;iCAKa;AACZ,UAAMA,WAAW,GAAG,KAAKE,SAAL,EAApB;;AACA,UAAI,CAACF,WAAL,EAAkB;AACjB,eAAO,KAAP;AACA;;AACD,aAAOA,WAAW,CAACG,UAAZ,EAAP;AACA;AAED;;;;;;;;8BAKU;AACT,UAAMH,WAAW,GAAG,KAAKE,SAAL,EAApB;;AACA,UAAI,CAACF,WAAL,EAAkB;AACjB,eAAO,KAAP;AACA;;AACD,aAAOA,WAAW,CAACI,OAAZ,EAAP;AACA;AAED;;;;;;;;wCAKoB;AACnB,aAAO,KAAKzD,KAAL,CAAWK,yBAAlB;AACA;AAED;;;;;;;kCAIc;AACb,aAAO,KAAKC,SAAL,CAAeoD,WAAf,CAA2B,KAAK1D,KAAhC,KAA0C,KAAK2D,uBAAL,EAA1C,IAA4E,EAAnF;AACA","sourcesContent":["import Metadata from './metadata'\r\nimport PhoneNumber from './PhoneNumber'\r\nimport AsYouTypeState from './AsYouTypeState'\r\nimport AsYouTypeFormatter, { DIGIT_PLACEHOLDER } from './AsYouTypeFormatter'\r\nimport AsYouTypeParser, { extractFormattedDigitsAndPlus, autoCorrectInternationalNumberWithoutPlus } from './AsYouTypeParser'\r\nimport { findCountryCode } from './parse_'\r\n\r\nconst USE_NON_GEOGRAPHIC_COUNTRY_CODE = false\r\n\r\nexport default class AsYouType {\r\n\t/**\r\n\t * @param {(string|object)?} [optionsOrDefaultCountry] - The default country used for parsing non-international phone numbers. Can also be an `options` object.\r\n\t * @param {Object} metadata\r\n\t */\r\n\tconstructor(optionsOrDefaultCountry, metadata) {\r\n\t\tthis.metadata = new Metadata(metadata)\r\n\t\tconst [defaultCountry, defaultCallingCode] = this.getCountryAndCallingCode(optionsOrDefaultCountry)\r\n\t\tthis.defaultCountry = defaultCountry\r\n\t\tthis.defaultCallingCode = defaultCallingCode\r\n\t\tthis.reset()\r\n\t}\r\n\r\n\tgetCountryAndCallingCode(optionsOrDefaultCountry) {\r\n\t\t// Set `defaultCountry` and `defaultCallingCode` options.\r\n\t\tlet defaultCountry\r\n\t\tlet defaultCallingCode\r\n\t\t// Turns out `null` also has type \"object\". Weird.\r\n\t\tif (optionsOrDefaultCountry) {\r\n\t\t\tif (typeof optionsOrDefaultCountry === 'object') {\r\n\t\t\t\tdefaultCountry = optionsOrDefaultCountry.defaultCountry\r\n\t\t\t\tdefaultCallingCode = optionsOrDefaultCountry.defaultCallingCode\r\n\t\t\t} else {\r\n\t\t\t\tdefaultCountry = optionsOrDefaultCountry\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (defaultCountry && !this.metadata.hasCountry(defaultCountry)) {\r\n\t\t\tdefaultCountry = undefined\r\n\t\t}\r\n\t\tif (defaultCallingCode) {\r\n\t\t\t/* istanbul ignore if */\r\n\t\t\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\t\t\tif (this.metadata.isNonGeographicCallingCode(defaultCallingCode)) {\r\n\t\t\t\t\tdefaultCountry = '001'\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn [defaultCountry, defaultCallingCode]\r\n\t}\r\n\r\n\t/**\r\n\t * Inputs \"next\" phone number characters.\r\n\t * @param {string} text\r\n\t * @return {string} Formatted phone number characters that have been input so far.\r\n\t */\r\n\tinput(text) {\r\n\t\tconst {\r\n\t\t\tdigits,\r\n\t\t\tjustLeadingPlus\r\n\t\t} = this.parser.input(text, this.state)\r\n\t\tif (justLeadingPlus) {\r\n\t\t\tthis.formattedOutput = '+'\r\n\t\t} else if (digits) {\r\n\t\t\tthis.determineTheCountryIfNeeded()\r\n\t\t\t// Match the available formats by the currently available leading digits.\r\n\t\t\tif (this.state.nationalSignificantNumber) {\r\n\t\t\t\tthis.formatter.narrowDownMatchingFormats(this.state)\r\n\t\t\t}\r\n\t\t\tlet formattedNationalNumber\r\n\t\t\tif (this.metadata.hasSelectedNumberingPlan()) {\r\n\t\t\t\tformattedNationalNumber = this.formatter.format(digits, this.state)\r\n\t\t\t}\r\n\t\t\tif (formattedNationalNumber === undefined) {\r\n\t\t\t\t// See if another national (significant) number could be re-extracted.\r\n\t\t\t\tif (this.parser.reExtractNationalSignificantNumber(this.state)) {\r\n\t\t\t\t\t// If it could, then re-try formatting the new national (significant) number.\r\n\t\t\t\t\tconst nationalDigits = this.state.getNationalDigits()\r\n\t\t\t\t\tif (nationalDigits) {\r\n\t\t\t\t\t\tformattedNationalNumber = this.formatter.format(nationalDigits, this.state)\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tthis.formattedOutput = formattedNationalNumber\r\n\t\t\t\t? this.getFullNumber(formattedNationalNumber)\r\n\t\t\t\t: this.getNonFormattedNumber()\r\n\t\t}\r\n\t\treturn this.formattedOutput\r\n\t}\r\n\r\n\treset() {\r\n\t\tthis.state = new AsYouTypeState({\r\n\t\t\tonCountryChange: (country) => {\r\n\t\t\t\t// Before version `1.6.0`, the official `AsYouType` formatter API\r\n\t\t\t\t// included the `.country` property of an `AsYouType` instance.\r\n\t\t\t\t// Since that property (along with the others) have been moved to\r\n\t\t\t\t// `this.state`, `this.country` property is emulated for compatibility\r\n\t\t\t\t// with the old versions.\r\n\t\t\t\tthis.country = country\r\n\t\t\t},\r\n\t\t\tonCallingCodeChange: (country, callingCode) => {\r\n\t\t\t\tthis.metadata.selectNumberingPlan(country, callingCode)\r\n\t\t\t\tthis.formatter.reset(this.metadata.numberingPlan, this.state)\r\n\t\t\t\tthis.parser.reset(this.metadata.numberingPlan)\r\n\t\t\t}\r\n\t\t})\r\n\t\tthis.formatter = new AsYouTypeFormatter({\r\n\t\t\tstate: this.state,\r\n\t\t\tmetadata: this.metadata\r\n\t\t})\r\n\t\tthis.parser = new AsYouTypeParser({\r\n\t\t\tdefaultCountry: this.defaultCountry,\r\n\t\t\tdefaultCallingCode: this.defaultCallingCode,\r\n\t\t\tmetadata: this.metadata,\r\n\t\t\tstate: this.state,\r\n\t\t\tonNationalSignificantNumberChange: () => {\r\n\t\t\t\tthis.determineTheCountryIfNeeded()\r\n\t\t\t\tthis.formatter.reset(this.metadata.numberingPlan, this.state)\r\n\t\t\t}\r\n\t\t})\r\n\t\tthis.state.reset(this.defaultCountry, this.defaultCallingCode)\r\n\t\tthis.formattedOutput = ''\r\n\t\treturn this\r\n\t}\r\n\r\n\t/**\r\n\t * Returns `true` if the phone number is being input in international format.\r\n\t * In other words, returns `true` if and only if the parsed phone number starts with a `\"+\"`.\r\n\t * @return {boolean}\r\n\t */\r\n\tisInternational() {\r\n\t\treturn this.state.international\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the \"country calling code\" part of the phone number.\r\n\t * Returns `undefined` if the number is not being input in international format.\r\n\t * Returns \"country calling code\" for \"non-geographic\" phone numbering plans too.\r\n\t * @return {string} [callingCode]\r\n\t */\r\n\tgetCallingCode() {\r\n\t\treturn this.state.callingCode\r\n\t}\r\n\r\n\t// A legacy alias.\r\n\tgetCountryCallingCode() {\r\n\t\treturn this.getCallingCode()\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a two-letter country code of the phone number.\r\n\t * Returns `undefined` for \"non-geographic\" phone numbering plans.\r\n\t * Returns `undefined` if no phone number has been input yet.\r\n\t * @return {string} [country]\r\n\t */\r\n\tgetCountry() {\r\n\t\tconst { digits, country } = this.state\r\n\t\t// If no digits have been input yet,\r\n\t\t// then `this.country` is the `defaultCountry`.\r\n\t\t// Won't return the `defaultCountry` in such case.\r\n\t\tif (!digits) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\tlet countryCode = country\r\n\t\t/* istanbul ignore if */\r\n\t\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\t\t// `AsYouType.getCountry()` returns `undefined`\r\n\t\t\t// for \"non-geographic\" phone numbering plans.\r\n\t\t\tif (countryCode === '001') {\r\n\t\t\t\tcountryCode = undefined\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn countryCode\r\n\t}\r\n\r\n\tdetermineTheCountryIfNeeded() {\r\n\t\t// Suppose a user enters a phone number in international format,\r\n\t\t// and there're several countries corresponding to that country calling code,\r\n\t\t// and a country has been derived from the number, and then\r\n\t\t// a user enters one more digit and the number is no longer\r\n\t\t// valid for the derived country, so the country should be re-derived\r\n\t\t// on every new digit in those cases.\r\n\t\t//\r\n\t\t// If the phone number is being input in national format,\r\n\t\t// then it could be a case when `defaultCountry` wasn't specified\r\n\t\t// when creating `AsYouType` instance, and just `defaultCallingCode` was specified,\r\n\t\t// and that \"calling code\" could correspond to a \"non-geographic entity\",\r\n\t\t// or there could be several countries corresponding to that country calling code.\r\n\t\t// In those cases, `this.country` is `undefined` and should be derived\r\n\t\t// from the number. Again, if country calling code is ambiguous, then\r\n\t\t// `this.country` should be re-derived with each new digit.\r\n\t\t//\r\n\t\tif (!this.state.country || this.isCountryCallingCodeAmbiguous()) {\r\n\t\t\tthis.determineTheCountry()\r\n\t\t}\r\n\t}\r\n\r\n\t// Prepends `+CountryCode ` in case of an international phone number\r\n\tgetFullNumber(formattedNationalNumber) {\r\n\t\tif (this.isInternational()) {\r\n\t\t\tconst prefix = (text) => this.formatter.getInternationalPrefixBeforeCountryCallingCode(this.state.IDDPrefix, {\r\n\t\t\t\tspacing: text ? true : false\r\n\t\t\t}) + text\r\n\t\t\tconst { callingCode } = this.state\r\n\t\t\tif (!callingCode) {\r\n\t\t\t\treturn prefix(`${this.state.getDigitsWithoutInternationalPrefix()}`)\r\n\t\t\t}\r\n\t\t\tif (!formattedNationalNumber) {\r\n\t\t\t\treturn prefix(callingCode)\r\n\t\t\t}\r\n\t\t\treturn prefix(`${callingCode} ${formattedNationalNumber}`)\r\n\t\t}\r\n\t\treturn formattedNationalNumber\r\n\t}\r\n\r\n\tgetNonFormattedNationalNumberWithPrefix() {\r\n\t\tconst {\r\n\t\t\tnationalSignificantNumber,\r\n\t\t\tcomplexPrefixBeforeNationalSignificantNumber,\r\n\t\t\tnationalPrefix\r\n\t\t} = this.state\r\n\t\tlet number = nationalSignificantNumber\r\n\t\tconst prefix = complexPrefixBeforeNationalSignificantNumber || nationalPrefix\r\n\t\tif (prefix) {\r\n\t\t\tnumber = prefix + number\r\n\t\t}\r\n\t\treturn number\r\n\t}\r\n\r\n\tgetNonFormattedNumber() {\r\n\t\tconst { nationalSignificantNumberMatchesInput } = this.state\r\n\t\treturn this.getFullNumber(\r\n\t\t\tnationalSignificantNumberMatchesInput\r\n\t\t\t\t? this.getNonFormattedNationalNumberWithPrefix()\r\n\t\t\t\t: this.state.getNationalDigits()\r\n\t\t)\r\n\t}\r\n\r\n\tgetNonFormattedTemplate() {\r\n\t\tconst number = this.getNonFormattedNumber()\r\n\t\tif (number) {\r\n\t\t\treturn number.replace(/[\\+\\d]/g, DIGIT_PLACEHOLDER)\r\n\t\t}\r\n\t}\r\n\r\n\tisCountryCallingCodeAmbiguous() {\r\n\t\tconst { callingCode } = this.state\r\n\t\tconst countryCodes = this.metadata.getCountryCodesForCallingCode(callingCode)\r\n\t\treturn countryCodes && countryCodes.length > 1\r\n\t}\r\n\r\n\t// Determines the country of the phone number\r\n\t// entered so far based on the country phone code\r\n\t// and the national phone number.\r\n\tdetermineTheCountry() {\r\n\t\tthis.state.setCountry(findCountryCode(\r\n\t\t\tthis.isInternational() ? this.state.callingCode : this.defaultCallingCode,\r\n\t\t\tthis.state.nationalSignificantNumber,\r\n\t\t\tthis.metadata\r\n\t\t))\r\n\t}\r\n\r\n\t/**\r\n\t * Returns an instance of `PhoneNumber` class.\r\n\t * Will return `undefined` if no national (significant) number\r\n\t * digits have been entered so far, or if no `defaultCountry` has been\r\n\t * set and the user enters a phone number not in international format.\r\n\t */\r\n\tgetNumber() {\r\n\t\tlet {\r\n\t\t\tnationalSignificantNumber,\r\n\t\t\tcarrierCode\r\n\t\t} = this.state\r\n\t\tif (this.isInternational()) {\r\n\t\t\tif (!this.state.callingCode) {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tif (!this.state.country && !this.defaultCallingCode) {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (!nationalSignificantNumber) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\tconst countryCode = this.getCountry()\r\n\t\tconst callingCode = this.getCountryCallingCode() || this.defaultCallingCode\r\n\t\t// Google's AsYouType formatter supports sort of an \"autocorrection\" feature\r\n\t\t// when it \"autocorrects\" numbers that have been input for a country\r\n\t\t// with that country's calling code.\r\n\t\t// Such \"autocorrection\" feature looks weird, but different people have been requesting it:\r\n\t\t// https://github.com/catamphetamine/libphonenumber-js/issues/376\r\n\t\t// https://github.com/catamphetamine/libphonenumber-js/issues/375\r\n\t\t// https://github.com/catamphetamine/libphonenumber-js/issues/316\r\n\t\tif (!this.isInternational() && nationalSignificantNumber === this.state.digits) {\r\n\t\t\tconst autoCorrected = autoCorrectInternationalNumberWithoutPlus(\r\n\t\t\t\tthis.state.digits,\r\n\t\t\t\tcountryCode,\r\n\t\t\t\tcallingCode,\r\n\t\t\t\tthis.metadata\r\n\t\t\t)\r\n\t\t\tif (autoCorrected) {\r\n\t\t\t\tnationalSignificantNumber = autoCorrected.nationalNumber\r\n\t\t\t\tcarrierCode = autoCorrected.carrierCode\r\n\t\t\t}\r\n\t\t}\r\n\t\tconst phoneNumber = new PhoneNumber(\r\n\t\t\tcountryCode || callingCode,\r\n\t\t\tnationalSignificantNumber,\r\n\t\t\tthis.metadata.metadata\r\n\t\t)\r\n\t\tif (carrierCode) {\r\n\t\t\tphoneNumber.carrierCode = carrierCode\r\n\t\t}\r\n\t\t// Phone number extensions are not supported by \"As You Type\" formatter.\r\n\t\treturn phoneNumber\r\n\t}\r\n\r\n\t/**\r\n\t * Returns `true` if the phone number is \"possible\".\r\n\t * Is just a shortcut for `PhoneNumber.isPossible()`.\r\n\t * @return {boolean}\r\n\t */\r\n\tisPossible() {\r\n\t\tconst phoneNumber = this.getNumber()\r\n\t\tif (!phoneNumber) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\treturn phoneNumber.isPossible()\r\n\t}\r\n\r\n\t/**\r\n\t * Returns `true` if the phone number is \"valid\".\r\n\t * Is just a shortcut for `PhoneNumber.isValid()`.\r\n\t * @return {boolean}\r\n\t */\r\n\tisValid() {\r\n\t\tconst phoneNumber = this.getNumber()\r\n\t\tif (!phoneNumber) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\treturn phoneNumber.isValid()\r\n\t}\r\n\r\n\t/**\r\n\t * @deprecated\r\n\t * This method is used in `react-phone-number-input/source/input-control.js`\r\n\t * in versions before `3.0.16`.\r\n\t */\r\n\tgetNationalNumber() {\r\n\t\treturn this.state.nationalSignificantNumber\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the template for the formatted phone number.\r\n\t * @return {string}\r\n\t */\r\n\tgetTemplate() {\r\n\t\treturn this.formatter.getTemplate(this.state) || this.getNonFormattedTemplate() || ''\r\n\t}\r\n}"],"file":"AsYouType.js"}
1
+ {"version":3,"sources":["../source/AsYouType.js"],"names":["USE_NON_GEOGRAPHIC_COUNTRY_CODE","AsYouType","optionsOrDefaultCountry","metadata","Metadata","getCountryAndCallingCode","defaultCountry","defaultCallingCode","reset","hasCountry","undefined","isNonGeographicCallingCode","text","parser","input","state","digits","justLeadingPlus","formattedOutput","determineTheCountryIfNeeded","nationalSignificantNumber","formatter","narrowDownMatchingFormats","formattedNationalNumber","hasSelectedNumberingPlan","format","reExtractNationalSignificantNumber","nationalDigits","getNationalDigits","getFullNumber","getNonFormattedNumber","AsYouTypeState","onCountryChange","country","onCallingCodeChange","callingCode","selectNumberingPlan","numberingPlan","AsYouTypeFormatter","AsYouTypeParser","onNationalSignificantNumberChange","international","getCallingCode","countryCode","isCountryCallingCodeAmbiguous","determineTheCountry","isInternational","prefix","getInternationalPrefixBeforeCountryCallingCode","spacing","getDigitsWithoutInternationalPrefix","complexPrefixBeforeNationalSignificantNumber","nationalPrefix","number","nationalSignificantNumberMatchesInput","getNonFormattedNationalNumberWithPrefix","replace","DIGIT_PLACEHOLDER","countryCodes","getCountryCodesForCallingCode","length","setCountry","carrierCode","getCountry","getCountryCallingCode","phoneNumber","PhoneNumber","getNumber","isPossible","isValid","getTemplate","getNonFormattedTemplate"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAMA,+BAA+B,GAAG,KAAxC;;IAEqBC,S;;;AACpB;;;;AAIA,qBAAYC,uBAAZ,EAAqCC,QAArC,EAA+C;AAAA;;AAC9C,SAAKA,QAAL,GAAgB,IAAIC,oBAAJ,CAAaD,QAAb,CAAhB;;AAD8C,gCAED,KAAKE,wBAAL,CAA8BH,uBAA9B,CAFC;AAAA;AAAA,QAEvCI,cAFuC;AAAA,QAEvBC,kBAFuB;;AAG9C,SAAKD,cAAL,GAAsBA,cAAtB;AACA,SAAKC,kBAAL,GAA0BA,kBAA1B;AACA,SAAKC,KAAL;AACA;;;;6CAEwBN,uB,EAAyB;AACjD;AACA,UAAII,cAAJ;AACA,UAAIC,kBAAJ,CAHiD,CAIjD;;AACA,UAAIL,uBAAJ,EAA6B;AAC5B,YAAI,QAAOA,uBAAP,MAAmC,QAAvC,EAAiD;AAChDI,UAAAA,cAAc,GAAGJ,uBAAuB,CAACI,cAAzC;AACAC,UAAAA,kBAAkB,GAAGL,uBAAuB,CAACK,kBAA7C;AACA,SAHD,MAGO;AACND,UAAAA,cAAc,GAAGJ,uBAAjB;AACA;AACD;;AACD,UAAII,cAAc,IAAI,CAAC,KAAKH,QAAL,CAAcM,UAAd,CAAyBH,cAAzB,CAAvB,EAAiE;AAChEA,QAAAA,cAAc,GAAGI,SAAjB;AACA;;AACD,UAAIH,kBAAJ,EAAwB;AACvB;AACA,YAAIP,+BAAJ,EAAqC;AACpC,cAAI,KAAKG,QAAL,CAAcQ,0BAAd,CAAyCJ,kBAAzC,CAAJ,EAAkE;AACjED,YAAAA,cAAc,GAAG,KAAjB;AACA;AACD;AACD;;AACD,aAAO,CAAC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AA3B,GAAiC,EAAlC,IAAwC,KAAK1B,KAAL,CAAWC,MAA1D;AACA;AAED;;;;;;;kCAIc;AACb,aAAO,KAAKK,SAAL,CAAeiD,WAAf,CAA2B,KAAKvD,KAAhC,KAA0C,KAAKwD,uBAAL,EAA1C,IAA4E,EAAnF;AACA","sourcesContent":["import Metadata from './metadata'\r\nimport PhoneNumber from './PhoneNumber'\r\nimport AsYouTypeState from './AsYouTypeState'\r\nimport AsYouTypeFormatter, { DIGIT_PLACEHOLDER } from './AsYouTypeFormatter'\r\nimport AsYouTypeParser, { extractFormattedDigitsAndPlus } from './AsYouTypeParser'\r\nimport getCountryByCallingCode from './helpers/getCountryByCallingCode'\r\n\r\nconst USE_NON_GEOGRAPHIC_COUNTRY_CODE = false\r\n\r\nexport default class AsYouType {\r\n\t/**\r\n\t * @param {(string|object)?} [optionsOrDefaultCountry] - The default country used for parsing non-international phone numbers. Can also be an `options` object.\r\n\t * @param {Object} metadata\r\n\t */\r\n\tconstructor(optionsOrDefaultCountry, metadata) {\r\n\t\tthis.metadata = new Metadata(metadata)\r\n\t\tconst [defaultCountry, defaultCallingCode] = this.getCountryAndCallingCode(optionsOrDefaultCountry)\r\n\t\tthis.defaultCountry = defaultCountry\r\n\t\tthis.defaultCallingCode = defaultCallingCode\r\n\t\tthis.reset()\r\n\t}\r\n\r\n\tgetCountryAndCallingCode(optionsOrDefaultCountry) {\r\n\t\t// Set `defaultCountry` and `defaultCallingCode` options.\r\n\t\tlet defaultCountry\r\n\t\tlet defaultCallingCode\r\n\t\t// Turns out `null` also has type \"object\". Weird.\r\n\t\tif (optionsOrDefaultCountry) {\r\n\t\t\tif (typeof optionsOrDefaultCountry === 'object') {\r\n\t\t\t\tdefaultCountry = optionsOrDefaultCountry.defaultCountry\r\n\t\t\t\tdefaultCallingCode = optionsOrDefaultCountry.defaultCallingCode\r\n\t\t\t} else {\r\n\t\t\t\tdefaultCountry = optionsOrDefaultCountry\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (defaultCountry && !this.metadata.hasCountry(defaultCountry)) {\r\n\t\t\tdefaultCountry = undefined\r\n\t\t}\r\n\t\tif (defaultCallingCode) {\r\n\t\t\t/* istanbul ignore if */\r\n\t\t\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\t\t\tif (this.metadata.isNonGeographicCallingCode(defaultCallingCode)) {\r\n\t\t\t\t\tdefaultCountry = '001'\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn [defaultCountry, defaultCallingCode]\r\n\t}\r\n\r\n\t/**\r\n\t * Inputs \"next\" phone number characters.\r\n\t * @param {string} text\r\n\t * @return {string} Formatted phone number characters that have been input so far.\r\n\t */\r\n\tinput(text) {\r\n\t\tconst {\r\n\t\t\tdigits,\r\n\t\t\tjustLeadingPlus\r\n\t\t} = this.parser.input(text, this.state)\r\n\t\tif (justLeadingPlus) {\r\n\t\t\tthis.formattedOutput = '+'\r\n\t\t} else if (digits) {\r\n\t\t\tthis.determineTheCountryIfNeeded()\r\n\t\t\t// Match the available formats by the currently available leading digits.\r\n\t\t\tif (this.state.nationalSignificantNumber) {\r\n\t\t\t\tthis.formatter.narrowDownMatchingFormats(this.state)\r\n\t\t\t}\r\n\t\t\tlet formattedNationalNumber\r\n\t\t\tif (this.metadata.hasSelectedNumberingPlan()) {\r\n\t\t\t\tformattedNationalNumber = this.formatter.format(digits, this.state)\r\n\t\t\t}\r\n\t\t\tif (formattedNationalNumber === undefined) {\r\n\t\t\t\t// See if another national (significant) number could be re-extracted.\r\n\t\t\t\tif (this.parser.reExtractNationalSignificantNumber(this.state)) {\r\n\t\t\t\t\tthis.determineTheCountryIfNeeded()\r\n\t\t\t\t\t// If it could, then re-try formatting the new national (significant) number.\r\n\t\t\t\t\tconst nationalDigits = this.state.getNationalDigits()\r\n\t\t\t\t\tif (nationalDigits) {\r\n\t\t\t\t\t\tformattedNationalNumber = this.formatter.format(nationalDigits, this.state)\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tthis.formattedOutput = formattedNationalNumber\r\n\t\t\t\t? this.getFullNumber(formattedNationalNumber)\r\n\t\t\t\t: this.getNonFormattedNumber()\r\n\t\t}\r\n\t\treturn this.formattedOutput\r\n\t}\r\n\r\n\treset() {\r\n\t\tthis.state = new AsYouTypeState({\r\n\t\t\tonCountryChange: (country) => {\r\n\t\t\t\t// Before version `1.6.0`, the official `AsYouType` formatter API\r\n\t\t\t\t// included the `.country` property of an `AsYouType` instance.\r\n\t\t\t\t// Since that property (along with the others) have been moved to\r\n\t\t\t\t// `this.state`, `this.country` property is emulated for compatibility\r\n\t\t\t\t// with the old versions.\r\n\t\t\t\tthis.country = country\r\n\t\t\t},\r\n\t\t\tonCallingCodeChange: (country, callingCode) => {\r\n\t\t\t\tthis.metadata.selectNumberingPlan(country, callingCode)\r\n\t\t\t\tthis.formatter.reset(this.metadata.numberingPlan, this.state)\r\n\t\t\t\tthis.parser.reset(this.metadata.numberingPlan)\r\n\t\t\t}\r\n\t\t})\r\n\t\tthis.formatter = new AsYouTypeFormatter({\r\n\t\t\tstate: this.state,\r\n\t\t\tmetadata: this.metadata\r\n\t\t})\r\n\t\tthis.parser = new AsYouTypeParser({\r\n\t\t\tdefaultCountry: this.defaultCountry,\r\n\t\t\tdefaultCallingCode: this.defaultCallingCode,\r\n\t\t\tmetadata: this.metadata,\r\n\t\t\tstate: this.state,\r\n\t\t\tonNationalSignificantNumberChange: () => {\r\n\t\t\t\tthis.determineTheCountryIfNeeded()\r\n\t\t\t\tthis.formatter.reset(this.metadata.numberingPlan, this.state)\r\n\t\t\t}\r\n\t\t})\r\n\t\tthis.state.reset(this.defaultCountry, this.defaultCallingCode)\r\n\t\tthis.formattedOutput = ''\r\n\t\treturn this\r\n\t}\r\n\r\n\t/**\r\n\t * Returns `true` if the phone number is being input in international format.\r\n\t * In other words, returns `true` if and only if the parsed phone number starts with a `\"+\"`.\r\n\t * @return {boolean}\r\n\t */\r\n\tisInternational() {\r\n\t\treturn this.state.international\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the \"country calling code\" part of the phone number.\r\n\t * Returns `undefined` if the number is not being input in international format.\r\n\t * Returns \"country calling code\" for \"non-geographic\" phone numbering plans too.\r\n\t * @return {string} [callingCode]\r\n\t */\r\n\tgetCallingCode() {\r\n\t\treturn this.state.callingCode\r\n\t}\r\n\r\n\t// A legacy alias.\r\n\tgetCountryCallingCode() {\r\n\t\treturn this.getCallingCode()\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a two-letter country code of the phone number.\r\n\t * Returns `undefined` for \"non-geographic\" phone numbering plans.\r\n\t * Returns `undefined` if no phone number has been input yet.\r\n\t * @return {string} [country]\r\n\t */\r\n\tgetCountry() {\r\n\t\tconst { digits, country } = this.state\r\n\t\t// If no digits have been input yet,\r\n\t\t// then `this.country` is the `defaultCountry`.\r\n\t\t// Won't return the `defaultCountry` in such case.\r\n\t\tif (!digits) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\tlet countryCode = country\r\n\t\t/* istanbul ignore if */\r\n\t\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\t\t// `AsYouType.getCountry()` returns `undefined`\r\n\t\t\t// for \"non-geographic\" phone numbering plans.\r\n\t\t\tif (countryCode === '001') {\r\n\t\t\t\tcountryCode = undefined\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn countryCode\r\n\t}\r\n\r\n\tdetermineTheCountryIfNeeded() {\r\n\t\t// Suppose a user enters a phone number in international format,\r\n\t\t// and there're several countries corresponding to that country calling code,\r\n\t\t// and a country has been derived from the number, and then\r\n\t\t// a user enters one more digit and the number is no longer\r\n\t\t// valid for the derived country, so the country should be re-derived\r\n\t\t// on every new digit in those cases.\r\n\t\t//\r\n\t\t// If the phone number is being input in national format,\r\n\t\t// then it could be a case when `defaultCountry` wasn't specified\r\n\t\t// when creating `AsYouType` instance, and just `defaultCallingCode` was specified,\r\n\t\t// and that \"calling code\" could correspond to a \"non-geographic entity\",\r\n\t\t// or there could be several countries corresponding to that country calling code.\r\n\t\t// In those cases, `this.country` is `undefined` and should be derived\r\n\t\t// from the number. Again, if country calling code is ambiguous, then\r\n\t\t// `this.country` should be re-derived with each new digit.\r\n\t\t//\r\n\t\tif (!this.state.country || this.isCountryCallingCodeAmbiguous()) {\r\n\t\t\tthis.determineTheCountry()\r\n\t\t}\r\n\t}\r\n\r\n\t// Prepends `+CountryCode ` in case of an international phone number\r\n\tgetFullNumber(formattedNationalNumber) {\r\n\t\tif (this.isInternational()) {\r\n\t\t\tconst prefix = (text) => this.formatter.getInternationalPrefixBeforeCountryCallingCode(this.state, {\r\n\t\t\t\tspacing: text ? true : false\r\n\t\t\t}) + text\r\n\t\t\tconst { callingCode } = this.state\r\n\t\t\tif (!callingCode) {\r\n\t\t\t\treturn prefix(`${this.state.getDigitsWithoutInternationalPrefix()}`)\r\n\t\t\t}\r\n\t\t\tif (!formattedNationalNumber) {\r\n\t\t\t\treturn prefix(callingCode)\r\n\t\t\t}\r\n\t\t\treturn prefix(`${callingCode} ${formattedNationalNumber}`)\r\n\t\t}\r\n\t\treturn formattedNationalNumber\r\n\t}\r\n\r\n\tgetNonFormattedNationalNumberWithPrefix() {\r\n\t\tconst {\r\n\t\t\tnationalSignificantNumber,\r\n\t\t\tcomplexPrefixBeforeNationalSignificantNumber,\r\n\t\t\tnationalPrefix\r\n\t\t} = this.state\r\n\t\tlet number = nationalSignificantNumber\r\n\t\tconst prefix = complexPrefixBeforeNationalSignificantNumber || nationalPrefix\r\n\t\tif (prefix) {\r\n\t\t\tnumber = prefix + number\r\n\t\t}\r\n\t\treturn number\r\n\t}\r\n\r\n\tgetNonFormattedNumber() {\r\n\t\tconst { nationalSignificantNumberMatchesInput } = this.state\r\n\t\treturn this.getFullNumber(\r\n\t\t\tnationalSignificantNumberMatchesInput\r\n\t\t\t\t? this.getNonFormattedNationalNumberWithPrefix()\r\n\t\t\t\t: this.state.getNationalDigits()\r\n\t\t)\r\n\t}\r\n\r\n\tgetNonFormattedTemplate() {\r\n\t\tconst number = this.getNonFormattedNumber()\r\n\t\tif (number) {\r\n\t\t\treturn number.replace(/[\\+\\d]/g, DIGIT_PLACEHOLDER)\r\n\t\t}\r\n\t}\r\n\r\n\tisCountryCallingCodeAmbiguous() {\r\n\t\tconst { callingCode } = this.state\r\n\t\tconst countryCodes = this.metadata.getCountryCodesForCallingCode(callingCode)\r\n\t\treturn countryCodes && countryCodes.length > 1\r\n\t}\r\n\r\n\t// Determines the country of the phone number\r\n\t// entered so far based on the country phone code\r\n\t// and the national phone number.\r\n\tdetermineTheCountry() {\r\n\t\tthis.state.setCountry(getCountryByCallingCode(\r\n\t\t\tthis.isInternational() ? this.state.callingCode : this.defaultCallingCode,\r\n\t\t\tthis.state.nationalSignificantNumber,\r\n\t\t\tthis.metadata\r\n\t\t))\r\n\t}\r\n\r\n\t/**\r\n\t * Returns an instance of `PhoneNumber` class.\r\n\t * Will return `undefined` if no national (significant) number\r\n\t * digits have been entered so far, or if no `defaultCountry` has been\r\n\t * set and the user enters a phone number not in international format.\r\n\t */\r\n\tgetNumber() {\r\n\t\tlet {\r\n\t\t\tnationalSignificantNumber,\r\n\t\t\tcarrierCode\r\n\t\t} = this.state\r\n\t\tif (this.isInternational()) {\r\n\t\t\tif (!this.state.callingCode) {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tif (!this.state.country && !this.defaultCallingCode) {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (!nationalSignificantNumber) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\tconst countryCode = this.getCountry()\r\n\t\tconst callingCode = this.getCountryCallingCode() || this.defaultCallingCode\r\n\t\tconst phoneNumber = new PhoneNumber(\r\n\t\t\tcountryCode || callingCode,\r\n\t\t\tnationalSignificantNumber,\r\n\t\t\tthis.metadata.metadata\r\n\t\t)\r\n\t\tif (carrierCode) {\r\n\t\t\tphoneNumber.carrierCode = carrierCode\r\n\t\t}\r\n\t\t// Phone number extensions are not supported by \"As You Type\" formatter.\r\n\t\treturn phoneNumber\r\n\t}\r\n\r\n\t/**\r\n\t * Returns `true` if the phone number is \"possible\".\r\n\t * Is just a shortcut for `PhoneNumber.isPossible()`.\r\n\t * @return {boolean}\r\n\t */\r\n\tisPossible() {\r\n\t\tconst phoneNumber = this.getNumber()\r\n\t\tif (!phoneNumber) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\treturn phoneNumber.isPossible()\r\n\t}\r\n\r\n\t/**\r\n\t * Returns `true` if the phone number is \"valid\".\r\n\t * Is just a shortcut for `PhoneNumber.isValid()`.\r\n\t * @return {boolean}\r\n\t */\r\n\tisValid() {\r\n\t\tconst phoneNumber = this.getNumber()\r\n\t\tif (!phoneNumber) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\treturn phoneNumber.isValid()\r\n\t}\r\n\r\n\t/**\r\n\t * @deprecated\r\n\t * This method is used in `react-phone-number-input/source/input-control.js`\r\n\t * in versions before `3.0.16`.\r\n\t */\r\n\tgetNationalNumber() {\r\n\t\treturn this.state.nationalSignificantNumber\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the phone number characters entered by the user.\r\n\t * @return {string}\r\n\t */\r\n\tgetChars() {\r\n\t\treturn (this.state.international ? '+' : '') + this.state.digits\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the template for the formatted phone number.\r\n\t * @return {string}\r\n\t */\r\n\tgetTemplate() {\r\n\t\treturn this.formatter.getTemplate(this.state) || this.getNonFormattedTemplate() || ''\r\n\t}\r\n}"],"file":"AsYouType.js"}
@@ -35,7 +35,7 @@ function (_AsYouType_) {
35
35
  }(_AsYouType["default"]);
36
36
 
37
37
  var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;
38
- describe('as you type', function () {
38
+ describe('AsYouType', function () {
39
39
  it('should use "national_prefix_formatting_rule"', function () {
40
40
  // With national prefix (full).
41
41
  new AsYouType('RU').input('88005553535').should.equal('8 (800) 555-35-35'); // With national prefix (partial).
@@ -779,13 +779,13 @@ describe('as you type', function () {
779
779
  it('should return PhoneNumber with autocorrected international numbers without leading +', function () {
780
780
  // https://github.com/catamphetamine/libphonenumber-js/issues/316
781
781
  var formatter = new AsYouType('FR');
782
- formatter.input('33612902554').should.equal('33612902554');
782
+ formatter.input('33612902554').should.equal('33 6 12 90 25 54');
783
783
  formatter.getNumber().country.should.equal('FR');
784
784
  formatter.getNumber().nationalNumber.should.equal('612902554');
785
785
  formatter.getNumber().number.should.equal('+33612902554'); // Should also strip national prefix.
786
786
 
787
787
  formatter.reset();
788
- formatter.input('330612902554').should.equal('330612902554');
788
+ formatter.input('330612902554').should.equal('33 06 12 90 25 54');
789
789
  formatter.getNumber().country.should.equal('FR');
790
790
  formatter.getNumber().nationalNumber.should.equal('612902554');
791
791
  formatter.getNumber().number.should.equal('+33612902554'); // On second thought, this "prepend default area code" feature won't be added,
@@ -930,6 +930,15 @@ describe('as you type', function () {
930
930
  formatter.input('1').should.equal('14880011 1 21');
931
931
  formatter.input('3').should.equal('14880011 1 213');
932
932
  });
933
+ it('should return the phone number characters entered by the user', function () {
934
+ var formatter = new AsYouType('RU');
935
+ formatter.getChars().should.equal('');
936
+ formatter.input('+123');
937
+ formatter.getChars().should.equal('+123');
938
+ formatter.reset();
939
+ formatter.input('123');
940
+ formatter.getChars().should.equal('123');
941
+ });
933
942
  });
934
943
 
935
944
  function type(something) {