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
@@ -11,20 +11,22 @@ Object.defineProperty(exports, "DIGIT_PLACEHOLDER", {
11
11
  });
12
12
  exports["default"] = void 0;
13
13
 
14
- var _parseDigits = _interopRequireDefault(require("./parseDigits"));
15
-
16
14
  var _AsYouTypeFormatter = require("./AsYouTypeFormatter.util");
17
15
 
18
16
  var _AsYouTypeFormatter2 = _interopRequireWildcard(require("./AsYouTypeFormatter.complete"));
19
17
 
20
- var _format_ = require("./format_");
18
+ var _parseDigits = _interopRequireDefault(require("./helpers/parseDigits"));
19
+
20
+ var _formatNationalNumberUsingFormat = require("./helpers/formatNationalNumberUsingFormat");
21
21
 
22
22
  var _constants = require("./constants");
23
23
 
24
- 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; } }
24
+ var _applyInternationalSeparatorStyle = _interopRequireDefault(require("./helpers/applyInternationalSeparatorStyle"));
25
25
 
26
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
27
27
 
28
+ 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; } }
29
+
28
30
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
29
31
 
30
32
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
@@ -500,8 +502,19 @@ function () {
500
502
  }
501
503
  }, {
502
504
  key: "getInternationalPrefixBeforeCountryCallingCode",
503
- value: function getInternationalPrefixBeforeCountryCallingCode(IDDPrefix, options) {
504
- return IDDPrefix ? options && options.spacing === false ? IDDPrefix : IDDPrefix + ' ' : '+';
505
+ value: function getInternationalPrefixBeforeCountryCallingCode(_ref6, options) {
506
+ var IDDPrefix = _ref6.IDDPrefix,
507
+ missingPlus = _ref6.missingPlus;
508
+
509
+ if (IDDPrefix) {
510
+ return options && options.spacing === false ? IDDPrefix : IDDPrefix + ' ';
511
+ }
512
+
513
+ if (missingPlus) {
514
+ return '';
515
+ }
516
+
517
+ return '+';
505
518
  }
506
519
  }, {
507
520
  key: "getTemplate",
@@ -515,7 +528,7 @@ function () {
515
528
 
516
529
  var index = -1;
517
530
  var i = 0;
518
- var internationalPrefix = state.international ? this.getInternationalPrefixBeforeCountryCallingCode(state.IDDPrefix, {
531
+ var internationalPrefix = state.international ? this.getInternationalPrefixBeforeCountryCallingCode(state, {
519
532
  spacing: false
520
533
  }) : '';
521
534
 
@@ -528,10 +541,7 @@ function () {
528
541
  }
529
542
  }, {
530
543
  key: "setNationalNumberTemplate",
531
- value: function setNationalNumberTemplate(template, _ref6) {
532
- var international = _ref6.international,
533
- IDDPrefix = _ref6.IDDPrefix,
534
- callingCode = _ref6.callingCode;
544
+ value: function setNationalNumberTemplate(template, state) {
535
545
  this.nationalNumberTemplate = template;
536
546
  this.populatedNationalNumberTemplate = template; // With a new formatting template, the matched position
537
547
  // using the old template needs to be reset.
@@ -542,8 +552,8 @@ function () {
542
552
  // 'x' for the '+' sign, 'x'es for the country phone code,
543
553
  // a spacebar and then the template for the formatted national number.
544
554
 
545
- if (international) {
546
- this.template = this.getInternationalPrefixBeforeCountryCallingCode(IDDPrefix).replace(/[\d\+]/g, _AsYouTypeFormatter.DIGIT_PLACEHOLDER) + (0, _AsYouTypeFormatter.repeat)(_AsYouTypeFormatter.DIGIT_PLACEHOLDER, callingCode.length) + ' ' + template;
555
+ if (state.international) {
556
+ this.template = this.getInternationalPrefixBeforeCountryCallingCode(state).replace(/[\d\+]/g, _AsYouTypeFormatter.DIGIT_PLACEHOLDER) + (0, _AsYouTypeFormatter.repeat)(_AsYouTypeFormatter.DIGIT_PLACEHOLDER, state.callingCode.length) + ' ' + template;
547
557
  } else {
548
558
  this.template = template;
549
559
  }
@@ -638,7 +648,7 @@ function () {
638
648
  international: international,
639
649
  nationalPrefix: nationalPrefix
640
650
  })) {
641
- var numberFormatWithNationalPrefix = numberFormat.replace(_format_.FIRST_GROUP_PATTERN, format.nationalPrefixFormattingRule()); // If `national_prefix_formatting_rule` of a `format` simply prepends
651
+ var numberFormatWithNationalPrefix = numberFormat.replace(_formatNationalNumberUsingFormat.FIRST_GROUP_PATTERN, format.nationalPrefixFormattingRule()); // If `national_prefix_formatting_rule` of a `format` simply prepends
642
652
  // national prefix at the start of a national (significant) number,
643
653
  // then such formatting can be used with `AsYouType` formatter.
644
654
  // There seems to be no `else` case: everywhere in metadata,
@@ -683,7 +693,7 @@ function () {
683
693
  }
684
694
 
685
695
  if (international) {
686
- template = (0, _format_.applyInternationalSeparatorStyle)(template);
696
+ template = (0, _applyInternationalSeparatorStyle["default"])(template);
687
697
  }
688
698
 
689
699
  return template;
@@ -1 +1 @@
1
- {"version":3,"sources":["../source/AsYouTypeFormatter.js"],"names":["DUMMY_DIGIT","LONGEST_NATIONAL_PHONE_NUMBER_LENGTH","LONGEST_DUMMY_PHONE_NUMBER","NATIONAL_PREFIX_SEPARATORS_PATTERN","SUPPORT_LEGACY_FORMATTING_PATTERNS","CREATE_CHARACTER_CLASS_PATTERN","CREATE_STANDALONE_DIGIT_PATTERN","NON_ALTERING_FORMAT_REG_EXP","RegExp","VALID_PUNCTUATION","MIN_LEADING_DIGITS_LENGTH","AsYouTypeFormatter","state","metadata","format","isNANP","nationalPrefixFormattingRule","test","international","nationalPrefix","usesNationalPrefix","resetFormat","chosenFormat","undefined","template","nationalNumberTemplate","populatedNationalNumberTemplate","populatedNationalNumberTemplatePosition","numberingPlan","callingCode","matchingFormats","formats","nationalSignificantNumber","narrowDownMatchingFormats","nextDigits","formattedCompleteNumber","shouldTryNationalPrefixFormattingRule","getSeparatorAfterNationalPrefix","setNationalNumberTemplate","replace","DIGIT_PLACEHOLDER","lastIndexOf","formatNationalNumberWithNextDigits","previouslyChosenFormat","newlyChosenFormat","chooseFormat","formatNextNationalNumberDigits","getNationalDigits","leadingDigits","leadingDigitsPatternIndex","length","filter","formatSuits","formatMatches","indexOf","nationalPrefixIsOptionalWhenFormattingInNationalFormat","nationalPrefixIsMandatoryWhenFormattingInNationalFormat","leadingDigitsPatternsCount","leadingDigitsPatterns","Math","min","leadingDigitsPattern","internationalFormat","getFormatFormat","createTemplateForFormat","_","slice","pattern","getTemplateForFormat","IDDPrefix","options","spacing","index","i","internationalPrefix","getInternationalPrefixBeforeCountryCallingCode","getDigitsWithoutInternationalPrefix","complexPrefixBeforeNationalSignificantNumber","digits","match","strictPattern","nationalNumberDummyDigits","numberFormat","nationalPrefixIncludedInTemplate","numberFormatWithNationalPrefix","FIRST_GROUP_PATTERN","result"],"mappings":";;;;;;;;;;;;;AAAA;;AAEA;;AAcA;;AAEA;;AAKA;;;;;;;;;;;;;;AAIA;AACA;AACA,IAAMA,WAAW,GAAG,GAApB,C,CACA;;AACA,IAAMC,oCAAoC,GAAG,EAA7C,C,CACA;AACA;;AACA,IAAMC,0BAA0B,GAAG,gCAAOF,WAAP,EAAoBC,oCAApB,CAAnC,C,CAEA;AACA;;AACA,IAAME,kCAAkC,GAAG,MAA3C,C,CAEA;AACA;AACA;AACA;AACA;AACA;;AACA,IAAMC,kCAAkC,GAAG,IAA3C,C,CAEA;AACA;;AACA,IAAMC,8BAA8B,GAAGD,kCAAkC,IAAK;AAAA,SAAM,iBAAN;AAAA,CAA9E,C,CAEA;AACA;AACA;AACA;AACA;;;AACA,IAAME,+BAA+B,GAAGF,kCAAkC,IAAK;AAAA,SAAM,mBAAN;AAAA,CAA/E,C,CAEA;AACA;AACA;AACA;AACA;AACA;AACA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C2D,MAAM,CAAC,CAAD,CAArD,CAdsC,CAgBtC;;AACA,aAAO,oDAA2B,KAAK5D,+BAAhC,EAAiE,KAAKC,uCAAL,GAA+C,CAAhH,CAAP,CAjBsC,CAmBtC;AACA;AACA;AACA;AACA","sourcesContent":["import parseDigits from './parseDigits'\r\n\r\nimport {\r\n\tDIGIT_PLACEHOLDER,\r\n\tcountOccurences,\r\n\trepeat,\r\n\tcutAndStripNonPairedParens,\r\n\tcloseNonPairedParens,\r\n\tstripNonPairedParens,\r\n\tpopulateTemplateWithDigits\r\n} from './AsYouTypeFormatter.util'\r\n\r\nexport {\r\n\tDIGIT_PLACEHOLDER\r\n} from './AsYouTypeFormatter.util'\r\n\r\nimport formatCompleteNumber, { canFormatCompleteNumber } from './AsYouTypeFormatter.complete'\r\n\r\nimport {\r\n\tFIRST_GROUP_PATTERN,\r\n\tapplyInternationalSeparatorStyle\r\n} from './format_'\r\n\r\nimport {\r\n\tVALID_PUNCTUATION\r\n} from './constants'\r\n\r\n// Used in phone number format template creation.\r\n// Could be any digit, I guess.\r\nconst DUMMY_DIGIT = '9'\r\n// I don't know why is it exactly `15`\r\nconst LONGEST_NATIONAL_PHONE_NUMBER_LENGTH = 15\r\n// Create a phone number consisting only of the digit 9 that matches the\r\n// `number_pattern` by applying the pattern to the \"longest phone number\" string.\r\nconst LONGEST_DUMMY_PHONE_NUMBER = repeat(DUMMY_DIGIT, LONGEST_NATIONAL_PHONE_NUMBER_LENGTH)\r\n\r\n// A set of characters that, if found in a national prefix formatting rules, are an indicator to\r\n// us that we should separate the national prefix from the number when formatting.\r\nconst NATIONAL_PREFIX_SEPARATORS_PATTERN = /[- ]/\r\n\r\n// Deprecated: Google has removed some formatting pattern related code from their repo.\r\n// https://github.com/googlei18n/libphonenumber/commit/a395b4fef3caf57c4bc5f082e1152a4d2bd0ba4c\r\n// \"We no longer have numbers in formatting matching patterns, only \\d.\"\r\n// Because this library supports generating custom metadata\r\n// some users may still be using old metadata so the relevant\r\n// code seems to stay until some next major version update.\r\nconst SUPPORT_LEGACY_FORMATTING_PATTERNS = true\r\n\r\n// A pattern that is used to match character classes in regular expressions.\r\n// An example of a character class is \"[1-4]\".\r\nconst CREATE_CHARACTER_CLASS_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && (() => /\\[([^\\[\\]])*\\]/g)\r\n\r\n// Any digit in a regular expression that actually denotes a digit. For\r\n// example, in the regular expression \"80[0-2]\\d{6,10}\", the first 2 digits\r\n// (8 and 0) are standalone digits, but the rest are not.\r\n// Two look-aheads are needed because the number following \\\\d could be a\r\n// two-digit number, since the phone number can be as long as 15 digits.\r\nconst CREATE_STANDALONE_DIGIT_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && (() => /\\d(?=[^,}][^,}])/g)\r\n\r\n// A regular expression that is used to determine if a `format` is\r\n// suitable to be used in the \"as you type formatter\".\r\n// A `format` is suitable when the resulting formatted number has\r\n// the same digits as the user has entered.\r\n//\r\n// In the simplest case, that would mean that the format\r\n// doesn't add any additional digits when formatting a number.\r\n// Google says that it also shouldn't add \"star\" (`*`) characters,\r\n// like it does in some Israeli formats.\r\n// Such basic format would only contain \"valid punctuation\"\r\n// and \"captured group\" identifiers ($1, $2, etc).\r\n//\r\n// An example of a format that adds additional digits:\r\n//\r\n// Country: `AR` (Argentina).\r\n// Format:\r\n// {\r\n// \"pattern\": \"(\\\\d)(\\\\d{2})(\\\\d{4})(\\\\d{4})\",\r\n// \"leading_digits_patterns\": [\"91\"],\r\n// \"national_prefix_formatting_rule\": \"0$1\",\r\n// \"format\": \"$2 15-$3-$4\",\r\n// \"international_format\": \"$1 $2 $3-$4\"\r\n// }\r\n//\r\n// In the format above, the `format` adds `15` to the digits when formatting a number.\r\n// A sidenote: this format actually is suitable because `national_prefix_for_parsing`\r\n// has previously removed `15` from a national number, so re-adding `15` in `format`\r\n// doesn't actually result in any extra digits added to user's input.\r\n// But verifying that would be a complex procedure, so the code chooses a simpler path:\r\n// it simply filters out all `format`s that contain anything but \"captured group\" ids.\r\n//\r\n// This regular expression is called `ELIGIBLE_FORMAT_PATTERN` in Google's\r\n// `libphonenumber` code.\r\n//\r\nconst NON_ALTERING_FORMAT_REG_EXP = new RegExp(\r\n\t'^' +\r\n\t'[' + VALID_PUNCTUATION + ']*' +\r\n\t'(\\\\$\\\\d[' + VALID_PUNCTUATION + ']*)+' +\r\n\t'$'\r\n)\r\n\r\n// This is the minimum length of the leading digits of a phone number\r\n// to guarantee the first \"leading digits pattern\" for a phone number format\r\n// to be preemptive.\r\nconst MIN_LEADING_DIGITS_LENGTH = 3\r\n\r\nexport default class AsYouTypeFormatter {\r\n\tconstructor({\r\n\t\tstate,\r\n\t\tmetadata\r\n\t}) {\r\n\t\tthis.metadata = metadata\r\n\t\tthis.resetFormat()\r\n\t}\r\n\r\n\tresetFormat() {\r\n\t\tthis.chosenFormat = undefined\r\n\t\tthis.template = undefined\r\n\t\tthis.nationalNumberTemplate = undefined\r\n\t\tthis.populatedNationalNumberTemplate = undefined\r\n\t\tthis.populatedNationalNumberTemplatePosition = -1\r\n\t}\r\n\r\n\treset(numberingPlan, state) {\r\n\t\tthis.resetFormat()\r\n\t\tif (numberingPlan) {\r\n\t\t\tthis.isNANP = numberingPlan.callingCode() === '1'\r\n\t\t\tthis.matchingFormats = numberingPlan.formats()\r\n\t\t\tif (state.nationalSignificantNumber) {\r\n\t\t\t\tthis.narrowDownMatchingFormats(state)\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tthis.isNANP = undefined\r\n\t\t\tthis.matchingFormats = []\r\n\t\t}\r\n\t}\r\n\r\n\tformat(nextDigits, state) {\r\n\t\t// See if the phone number digits can be formatted as a complete phone number.\r\n\t\t// If not, use the results from `formatNationalNumberWithNextDigits()`,\r\n\t\t// which formats based on the chosen formatting pattern.\r\n\t\t//\r\n\t\t// Attempting to format complete phone number first is how it's done\r\n\t\t// in Google's `libphonenumber`, so this library just follows it.\r\n\t\t// Google's `libphonenumber` code doesn't explain in detail why does it\r\n\t\t// attempt to format digits as a complete phone number\r\n\t\t// instead of just going with a previoulsy (or newly) chosen `format`:\r\n\t\t//\r\n\t\t// \"Checks to see if there is an exact pattern match for these digits.\r\n\t\t// If so, we should use this instead of any other formatting template\r\n\t\t// whose leadingDigitsPattern also matches the input.\"\r\n\t\t//\r\n\t\tif (canFormatCompleteNumber(state.nationalSignificantNumber, this.metadata)) {\r\n\t\t\tfor (const format of this.matchingFormats) {\r\n\t\t\t\tconst formattedCompleteNumber = formatCompleteNumber(\r\n\t\t\t\t\tstate,\r\n\t\t\t\t\tformat,\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tmetadata: this.metadata,\r\n\t\t\t\t\t\tshouldTryNationalPrefixFormattingRule: format => this.shouldTryNationalPrefixFormattingRule(format, {\r\n\t\t\t\t\t\t\tinternational: state.international,\r\n\t\t\t\t\t\t\tnationalPrefix: state.nationalPrefix\r\n\t\t\t\t\t\t}),\r\n\t\t\t\t\t\tgetSeparatorAfterNationalPrefix: this.getSeparatorAfterNationalPrefix\r\n\t\t\t\t\t}\r\n\t\t\t\t)\r\n\t\t\t\tif (formattedCompleteNumber) {\r\n\t\t\t\t\tthis.resetFormat()\r\n\t\t\t\t\tthis.chosenFormat = format\r\n\t\t\t\t\tthis.setNationalNumberTemplate(formattedCompleteNumber.replace(/\\d/g, DIGIT_PLACEHOLDER), state)\r\n\t\t\t\t\tthis.populatedNationalNumberTemplate = formattedCompleteNumber\r\n\t\t\t\t\t// With a new formatting template, the matched position\r\n\t\t\t\t\t// using the old template needs to be reset.\r\n\t\t\t\t\tthis.populatedNationalNumberTemplatePosition = this.template.lastIndexOf(DIGIT_PLACEHOLDER)\r\n\t\t\t\t\treturn formattedCompleteNumber\r\n\t\t\t\t}\r\n\r\n\t\t\t}\r\n\t\t}\r\n\t\t// Format the digits as a partial (incomplete) phone number\r\n\t\t// using the previously chosen formatting pattern (or a newly chosen one).\r\n\t\treturn this.formatNationalNumberWithNextDigits(nextDigits, state)\r\n\t}\r\n\r\n\t// Formats the next phone number digits.\r\n\tformatNationalNumberWithNextDigits(nextDigits, state) {\r\n\t\tconst previouslyChosenFormat = this.chosenFormat\r\n\t\t// Choose a format from the list of matching ones.\r\n\t\tconst newlyChosenFormat = this.chooseFormat(state)\r\n\t\tif (newlyChosenFormat) {\r\n\t\t\tif (newlyChosenFormat === previouslyChosenFormat) {\r\n\t\t\t\t// If it can format the next (current) digits\r\n\t\t\t\t// using the previously chosen phone number format\r\n\t\t\t\t// then return the updated formatted number.\r\n\t\t\t\treturn this.formatNextNationalNumberDigits(nextDigits)\r\n\t\t\t} else {\r\n\t\t\t\t// If a more appropriate phone number format\r\n\t\t\t\t// has been chosen for these \"leading digits\",\r\n\t\t\t\t// then re-format the national phone number part\r\n\t\t\t\t// using the newly selected format.\r\n\t\t\t\treturn this.formatNextNationalNumberDigits(state.getNationalDigits())\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tnarrowDownMatchingFormats({\r\n\t\tnationalSignificantNumber,\r\n\t\tnationalPrefix,\r\n\t\tinternational\r\n\t}) {\r\n\t\tconst leadingDigits = nationalSignificantNumber\r\n\r\n\t\t// \"leading digits\" pattern list starts with a\r\n\t\t// \"leading digits\" pattern fitting a maximum of 3 leading digits.\r\n\t\t// So, after a user inputs 3 digits of a national (significant) phone number\r\n\t\t// this national (significant) number can already be formatted.\r\n\t\t// The next \"leading digits\" pattern is for 4 leading digits max,\r\n\t\t// and the \"leading digits\" pattern after it is for 5 leading digits max, etc.\r\n\r\n\t\t// This implementation is different from Google's\r\n\t\t// in that it searches for a fitting format\r\n\t\t// even if the user has entered less than\r\n\t\t// `MIN_LEADING_DIGITS_LENGTH` digits of a national number.\r\n\t\t// Because some leading digit patterns already match for a single first digit.\r\n\t\tlet leadingDigitsPatternIndex = leadingDigits.length - MIN_LEADING_DIGITS_LENGTH\r\n\t\tif (leadingDigitsPatternIndex < 0) {\r\n\t\t\tleadingDigitsPatternIndex = 0\r\n\t\t}\r\n\r\n\t\tthis.matchingFormats = this.matchingFormats.filter(\r\n\t\t\tformat => this.formatSuits(format, international, nationalPrefix)\r\n\t\t\t\t&& this.formatMatches(format, leadingDigits, leadingDigitsPatternIndex)\r\n\t\t)\r\n\r\n\t\t// If there was a phone number format chosen\r\n\t\t// and it no longer holds given the new leading digits then reset it.\r\n\t\t// The test for this `if` condition is marked as:\r\n\t\t// \"Reset a chosen format when it no longer holds given the new leading digits\".\r\n\t\t// To construct a valid test case for this one can find a country\r\n\t\t// in `PhoneNumberMetadata.xml` yielding one format for 3 `<leadingDigits>`\r\n\t\t// and yielding another format for 4 `<leadingDigits>` (Australia in this case).\r\n\t\tif (this.chosenFormat && this.matchingFormats.indexOf(this.chosenFormat) === -1) {\r\n\t\t\tthis.resetFormat()\r\n\t\t}\r\n\t}\r\n\r\n\tformatSuits(format, international, nationalPrefix) {\r\n\t\t// When a prefix before a national (significant) number is\r\n\t\t// simply a national prefix, then it's parsed as `this.nationalPrefix`.\r\n\t\t// In more complex cases, a prefix before national (significant) number\r\n\t\t// could include a national prefix as well as some \"capturing groups\",\r\n\t\t// and in that case there's no info whether a national prefix has been parsed.\r\n\t\t// If national prefix is not used when formatting a phone number\r\n\t\t// using this format, but a national prefix has been entered by the user,\r\n\t\t// and was extracted, then discard such phone number format.\r\n\t\t// In Google's \"AsYouType\" formatter code, the equivalent would be this part:\r\n\t\t// https://github.com/google/libphonenumber/blob/0a45cfd96e71cad8edb0e162a70fcc8bd9728933/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java#L175-L184\r\n\t\tif (nationalPrefix &&\r\n\t\t\t!format.usesNationalPrefix() &&\r\n\t\t\t// !format.domesticCarrierCodeFormattingRule() &&\r\n\t\t\t!format.nationalPrefixIsOptionalWhenFormattingInNationalFormat()) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\t// If national prefix is mandatory for this phone number format\r\n\t\t// and there're no guarantees that a national prefix is present in user input\r\n\t\t// then discard this phone number format as not suitable.\r\n\t\t// In Google's \"AsYouType\" formatter code, the equivalent would be this part:\r\n\t\t// https://github.com/google/libphonenumber/blob/0a45cfd96e71cad8edb0e162a70fcc8bd9728933/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java#L185-L193\r\n\t\tif (!international &&\r\n\t\t\t!nationalPrefix &&\r\n\t\t\tformat.nationalPrefixIsMandatoryWhenFormattingInNationalFormat()) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\treturn true\r\n\t}\r\n\r\n\tformatMatches(format, leadingDigits, leadingDigitsPatternIndex) {\r\n\t\tconst leadingDigitsPatternsCount = format.leadingDigitsPatterns().length\r\n\t\t// If this format is not restricted to a certain\r\n\t\t// leading digits pattern then it fits.\r\n\t\tif (leadingDigitsPatternsCount === 0) {\r\n\t\t\treturn true\r\n\t\t}\r\n\t\t// Start excluding any non-matching formats only when the\r\n\t\t// national number entered so far is at least 3 digits long,\r\n\t\t// otherwise format matching would give false negatives.\r\n\t\t// For example, when the digits entered so far are `2`\r\n\t\t// and the leading digits pattern is `21` –\r\n\t\t// it's quite obvious in this case that the format could be the one\r\n\t\t// but due to the absence of further digits it would give false negative.\r\n\t\tif (leadingDigits.length < MIN_LEADING_DIGITS_LENGTH) {\r\n\t\t\treturn true\r\n\t\t}\r\n\t\t// If at least `MIN_LEADING_DIGITS_LENGTH` digits of a national number are available\r\n\t\t// then format matching starts narrowing down the list of possible formats\r\n\t\t// (only previously matched formats are considered for next digits).\r\n\t\tleadingDigitsPatternIndex = Math.min(leadingDigitsPatternIndex, leadingDigitsPatternsCount - 1)\r\n\t\tconst leadingDigitsPattern = format.leadingDigitsPatterns()[leadingDigitsPatternIndex]\r\n\t\t// Brackets are required for `^` to be applied to\r\n\t\t// all or-ed (`|`) parts, not just the first one.\r\n\t\treturn new RegExp(`^(${leadingDigitsPattern})`).test(leadingDigits)\r\n\t}\r\n\r\n\tgetFormatFormat(format, international) {\r\n\t\treturn international ? format.internationalFormat() : format.format()\r\n\t}\r\n\r\n\tchooseFormat(state) {\r\n\t\t// When there are multiple available formats, the formatter uses the first\r\n\t\t// format where a formatting template could be created.\r\n\t\tfor (const format of this.matchingFormats.slice()) {\r\n\t\t\t// If this format is currently being used\r\n\t\t\t// and is still suitable, then stick to it.\r\n\t\t\tif (this.chosenFormat === format) {\r\n\t\t\t\tbreak\r\n\t\t\t}\r\n\t\t\t// Sometimes, a formatting rule inserts additional digits in a phone number,\r\n\t\t\t// and \"as you type\" formatter can't do that: it should only use the digits\r\n\t\t\t// that the user has input.\r\n\t\t\t//\r\n\t\t\t// For example, in Argentina, there's a format for mobile phone numbers:\r\n\t\t\t//\r\n\t\t\t// {\r\n\t\t\t// \"pattern\": \"(\\\\d)(\\\\d{2})(\\\\d{4})(\\\\d{4})\",\r\n\t\t\t// \"leading_digits_patterns\": [\"91\"],\r\n\t\t\t// \"national_prefix_formatting_rule\": \"0$1\",\r\n\t\t\t// \"format\": \"$2 15-$3-$4\",\r\n\t\t\t// \"international_format\": \"$1 $2 $3-$4\"\r\n\t\t\t// }\r\n\t\t\t//\r\n\t\t\t// In that format, `international_format` is used instead of `format`\r\n\t\t\t// because `format` inserts `15` in the formatted number,\r\n\t\t\t// and `AsYouType` formatter should only use the digits\r\n\t\t\t// the user has actually input, without adding any extra digits.\r\n\t\t\t// In this case, it wouldn't make a difference, because the `15`\r\n\t\t\t// is first stripped when applying `national_prefix_for_parsing`\r\n\t\t\t// and then re-added when using `format`, so in reality it doesn't\r\n\t\t\t// add any new digits to the number, but to detect that, the code\r\n\t\t\t// would have to be more complex: it would have to try formatting\r\n\t\t\t// the digits using the format and then see if any digits have\r\n\t\t\t// actually been added or removed, and then, every time a new digit\r\n\t\t\t// is input, it should re-check whether the chosen format doesn't\r\n\t\t\t// alter the digits.\r\n\t\t\t//\r\n\t\t\t// Google's code doesn't go that far, and so does this library:\r\n\t\t\t// it simply requires that a `format` doesn't add any additonal\r\n\t\t\t// digits to user's input.\r\n\t\t\t//\r\n\t\t\t// Also, people in general should move from inputting phone numbers\r\n\t\t\t// in national format (possibly with national prefixes)\r\n\t\t\t// and use international phone number format instead:\r\n\t\t\t// it's a logical thing in the modern age of mobile phones,\r\n\t\t\t// globalization and the internet.\r\n\t\t\t//\r\n\t\t\t/* istanbul ignore if */\r\n\t\t\tif (!NON_ALTERING_FORMAT_REG_EXP.test(this.getFormatFormat(format, state.international))) {\r\n\t\t\t\tcontinue\r\n\t\t\t}\r\n\t\t\tif (!this.createTemplateForFormat(format, state)) {\r\n\t\t\t\t// Remove the format if it can't generate a template.\r\n\t\t\t\tthis.matchingFormats = this.matchingFormats.filter(_ => _ !== format)\r\n\t\t\t\tcontinue\r\n\t\t\t}\r\n\t\t\tthis.chosenFormat = format\r\n\t\t\tbreak\r\n\t\t}\r\n\t\tif (!this.chosenFormat) {\r\n\t\t\t// No format matches the national (significant) phone number.\r\n\t\t\tthis.resetFormat()\r\n\t\t}\r\n\t\treturn this.chosenFormat\r\n\t}\r\n\r\n\tcreateTemplateForFormat(format, state) {\r\n\t\t// The formatter doesn't format numbers when numberPattern contains '|', e.g.\r\n\t\t// (20|3)\\d{4}. In those cases we quickly return.\r\n\t\t// (Though there's no such format in current metadata)\r\n\t\t/* istanbul ignore if */\r\n\t\tif (SUPPORT_LEGACY_FORMATTING_PATTERNS && format.pattern().indexOf('|') >= 0) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\t// Get formatting template for this phone number format\r\n\t\tconst template = this.getTemplateForFormat(format, state)\r\n\t\t// If the national number entered is too long\r\n\t\t// for any phone number format, then abort.\r\n\t\tif (template) {\r\n\t\t\tthis.setNationalNumberTemplate(template, state)\r\n\t\t\treturn true\r\n\t\t}\r\n\t}\r\n\r\n\tgetSeparatorAfterNationalPrefix = (format) => {\r\n\t\t// `US` metadata doesn't have a `national_prefix_formatting_rule`,\r\n\t\t// so the `if` condition below doesn't apply to `US`,\r\n\t\t// but in reality there shoudl be a separator\r\n\t\t// between a national prefix and a national (significant) number.\r\n\t\t// So `US` national prefix separator is a \"special\" \"hardcoded\" case.\r\n\t\tif (this.isNANP) {\r\n\t\t\treturn ' '\r\n\t\t}\r\n\t\t// If a `format` has a `national_prefix_formatting_rule`\r\n\t\t// and that rule has a separator after a national prefix,\r\n\t\t// then it means that there should be a separator\r\n\t\t// between a national prefix and a national (significant) number.\r\n\t\tif (format &&\r\n\t\t\tformat.nationalPrefixFormattingRule() &&\r\n\t\t\tNATIONAL_PREFIX_SEPARATORS_PATTERN.test(format.nationalPrefixFormattingRule())) {\r\n\t\t\treturn ' '\r\n\t\t}\r\n\t\t// At this point, there seems to be no clear evidence that\r\n\t\t// there should be a separator between a national prefix\r\n\t\t// and a national (significant) number. So don't insert one.\r\n\t\treturn ''\r\n\t}\r\n\r\n\tgetInternationalPrefixBeforeCountryCallingCode(IDDPrefix, options) {\r\n\t\treturn IDDPrefix ? (\r\n\t\t\toptions && options.spacing === false ? IDDPrefix : IDDPrefix + ' '\r\n\t\t) : '+'\r\n\t}\r\n\r\n\tgetTemplate(state) {\r\n\t\tif (!this.template) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\t// `this.template` holds the template for a \"complete\" phone number.\r\n\t\t// The currently entered phone number is most likely not \"complete\",\r\n\t\t// so trim all non-populated digits.\r\n\t\tlet index = -1\r\n\t\tlet i = 0\r\n\t\tconst internationalPrefix = state.international ? this.getInternationalPrefixBeforeCountryCallingCode(state.IDDPrefix, { spacing: false }) : ''\r\n\t\twhile (i < internationalPrefix.length + state.getDigitsWithoutInternationalPrefix().length) {\r\n\t\t\tindex = this.template.indexOf(DIGIT_PLACEHOLDER, index + 1)\r\n\t\t\ti++\r\n\t\t}\r\n\t\treturn cutAndStripNonPairedParens(this.template, index + 1)\r\n\t}\r\n\r\n\tsetNationalNumberTemplate(template, {\r\n\t\tinternational,\r\n\t\tIDDPrefix,\r\n\t\tcallingCode\r\n\t}) {\r\n\t\tthis.nationalNumberTemplate = template\r\n\t\tthis.populatedNationalNumberTemplate = template\r\n\t\t// With a new formatting template, the matched position\r\n\t\t// using the old template needs to be reset.\r\n\t\tthis.populatedNationalNumberTemplatePosition = -1\r\n\t\t// For convenience, the public `.template` property\r\n\t\t// contains the whole international number\r\n\t\t// if the phone number being input is international:\r\n\t\t// 'x' for the '+' sign, 'x'es for the country phone code,\r\n\t\t// a spacebar and then the template for the formatted national number.\r\n\t\tif (international) {\r\n\t\t\tthis.template =\r\n\t\t\t\tthis.getInternationalPrefixBeforeCountryCallingCode(IDDPrefix).replace(/[\\d\\+]/g, DIGIT_PLACEHOLDER) +\r\n\t\t\t\trepeat(DIGIT_PLACEHOLDER, callingCode.length) +\r\n\t\t\t\t' ' +\r\n\t\t\t\ttemplate\r\n\t\t} else {\r\n\t\t\tthis.template = template\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Generates formatting template for a national phone number,\r\n\t * optionally containing a national prefix, for a format.\r\n\t * @param {Format} format\r\n\t * @param {string} nationalPrefix\r\n\t * @return {string}\r\n\t */\r\n\tgetTemplateForFormat(format, {\r\n\t\tnationalSignificantNumber,\r\n\t\tinternational,\r\n\t\tnationalPrefix,\r\n\t\tcomplexPrefixBeforeNationalSignificantNumber\r\n\t}) {\r\n\t\tlet pattern = format.pattern()\r\n\r\n\t\t/* istanbul ignore else */\r\n\t\tif (SUPPORT_LEGACY_FORMATTING_PATTERNS) {\r\n\t\t\tpattern = pattern\r\n\t\t\t\t// Replace anything in the form of [..] with \\d\r\n\t\t\t\t.replace(CREATE_CHARACTER_CLASS_PATTERN(), '\\\\d')\r\n\t\t\t\t// Replace any standalone digit (not the one in `{}`) with \\d\r\n\t\t\t\t.replace(CREATE_STANDALONE_DIGIT_PATTERN(), '\\\\d')\r\n\t\t}\r\n\r\n\t\t// Generate a dummy national number (consisting of `9`s)\r\n\t\t// that fits this format's `pattern`.\r\n\t\t//\r\n\t\t// This match will always succeed,\r\n\t\t// because the \"longest dummy phone number\"\r\n\t\t// has enough length to accomodate any possible\r\n\t\t// national phone number format pattern.\r\n\t\t//\r\n\t\tlet digits = LONGEST_DUMMY_PHONE_NUMBER.match(pattern)[0]\r\n\r\n\t\t// If the national number entered is too long\r\n\t\t// for any phone number format, then abort.\r\n\t\tif (nationalSignificantNumber.length > digits.length) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\t// Get a formatting template which can be used to efficiently format\r\n\t\t// a partial number where digits are added one by one.\r\n\r\n\t\t// Below `strictPattern` is used for the\r\n\t\t// regular expression (with `^` and `$`).\r\n\t\t// This wasn't originally in Google's `libphonenumber`\r\n\t\t// and I guess they don't really need it\r\n\t\t// because they're not using \"templates\" to format phone numbers\r\n\t\t// but I added `strictPattern` after encountering\r\n\t\t// South Korean phone number formatting bug.\r\n\t\t//\r\n\t\t// Non-strict regular expression bug demonstration:\r\n\t\t//\r\n\t\t// this.nationalSignificantNumber : `111111111` (9 digits)\r\n\t\t//\r\n\t\t// pattern : (\\d{2})(\\d{3,4})(\\d{4})\r\n\t\t// format : `$1 $2 $3`\r\n\t\t// digits : `9999999999` (10 digits)\r\n\t\t//\r\n\t\t// '9999999999'.replace(new RegExp(/(\\d{2})(\\d{3,4})(\\d{4})/g), '$1 $2 $3') = \"99 9999 9999\"\r\n\t\t//\r\n\t\t// template : xx xxxx xxxx\r\n\t\t//\r\n\t\t// But the correct template in this case is `xx xxx xxxx`.\r\n\t\t// The template was generated incorrectly because of the\r\n\t\t// `{3,4}` variability in the `pattern`.\r\n\t\t//\r\n\t\t// The fix is, if `this.nationalSignificantNumber` has already sufficient length\r\n\t\t// to satisfy the `pattern` completely then `this.nationalSignificantNumber`\r\n\t\t// is used instead of `digits`.\r\n\r\n\t\tconst strictPattern = new RegExp('^' + pattern + '$')\r\n\t\tconst nationalNumberDummyDigits = nationalSignificantNumber.replace(/\\d/g, DUMMY_DIGIT)\r\n\r\n\t\t// If `this.nationalSignificantNumber` has already sufficient length\r\n\t\t// to satisfy the `pattern` completely then use it\r\n\t\t// instead of `digits`.\r\n\t\tif (strictPattern.test(nationalNumberDummyDigits)) {\r\n\t\t\tdigits = nationalNumberDummyDigits\r\n\t\t}\r\n\r\n\t\tlet numberFormat = this.getFormatFormat(format, international)\r\n\t\tlet nationalPrefixIncludedInTemplate\r\n\r\n\t\t// If a user did input a national prefix (and that's guaranteed),\r\n\t\t// and if a `format` does have a national prefix formatting rule,\r\n\t\t// then see if that national prefix formatting rule\r\n\t\t// prepends exactly the same national prefix the user has input.\r\n\t\t// If that's the case, then use the `format` with the national prefix formatting rule.\r\n\t\t// Otherwise, use the `format` without the national prefix formatting rule,\r\n\t\t// and prepend a national prefix manually to it.\r\n\t\tif (this.shouldTryNationalPrefixFormattingRule(format, { international, nationalPrefix })) {\r\n\t\t\tconst numberFormatWithNationalPrefix = numberFormat.replace(\r\n\t\t\t\tFIRST_GROUP_PATTERN,\r\n\t\t\t\tformat.nationalPrefixFormattingRule()\r\n\t\t\t)\r\n\t\t\t// If `national_prefix_formatting_rule` of a `format` simply prepends\r\n\t\t\t// national prefix at the start of a national (significant) number,\r\n\t\t\t// then such formatting can be used with `AsYouType` formatter.\r\n\t\t\t// There seems to be no `else` case: everywhere in metadata,\r\n\t\t\t// national prefix formatting rule is national prefix + $1,\r\n\t\t\t// or `($1)`, in which case such format isn't even considered\r\n\t\t\t// when the user has input a national prefix.\r\n\t\t\t/* istanbul ignore else */\r\n\t\t\tif (parseDigits(format.nationalPrefixFormattingRule()) === (nationalPrefix || '') + parseDigits('$1')) {\r\n\t\t\t\tnumberFormat = numberFormatWithNationalPrefix\r\n\t\t\t\tnationalPrefixIncludedInTemplate = true\r\n\t\t\t\t// Replace all digits of the national prefix in the formatting template\r\n\t\t\t\t// with `DIGIT_PLACEHOLDER`s.\r\n\t\t\t\tif (nationalPrefix) {\r\n\t\t\t\t\tlet i = nationalPrefix.length\r\n\t\t\t\t\twhile (i > 0) {\r\n\t\t\t\t\t\tnumberFormat = numberFormat.replace(/\\d/, DIGIT_PLACEHOLDER)\r\n\t\t\t\t\t\ti--\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Generate formatting template for this phone number format.\r\n\t\tlet template = digits\r\n\t\t\t// Format the dummy phone number according to the format.\r\n\t\t\t.replace(new RegExp(pattern), numberFormat)\r\n\t\t\t// Replace each dummy digit with a DIGIT_PLACEHOLDER.\r\n\t\t\t.replace(new RegExp(DUMMY_DIGIT, 'g'), DIGIT_PLACEHOLDER)\r\n\r\n\t\t// If a prefix of a national (significant) number is not as simple\r\n\t\t// as just a basic national prefix, then just prepend such prefix\r\n\t\t// before the national (significant) number, optionally spacing\r\n\t\t// the two with a whitespace.\r\n\t\tif (!nationalPrefixIncludedInTemplate) {\r\n\t\t\tif (complexPrefixBeforeNationalSignificantNumber) {\r\n\t\t\t\t// Prepend the prefix to the template manually.\r\n\t\t\t\ttemplate = repeat(DIGIT_PLACEHOLDER, complexPrefixBeforeNationalSignificantNumber.length) +\r\n\t\t\t\t\t' ' +\r\n\t\t\t\t\ttemplate\r\n\t\t\t} else if (nationalPrefix) {\r\n\t\t\t\t// Prepend national prefix to the template manually.\r\n\t\t\t\ttemplate = repeat(DIGIT_PLACEHOLDER, nationalPrefix.length) +\r\n\t\t\t\t\tthis.getSeparatorAfterNationalPrefix(format) +\r\n\t\t\t\t\ttemplate\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (international) {\r\n\t\t\ttemplate = applyInternationalSeparatorStyle(template)\r\n\t\t}\r\n\r\n\t\treturn template\r\n\t}\r\n\r\n\tformatNextNationalNumberDigits(digits) {\r\n\t\tconst result = populateTemplateWithDigits(\r\n\t\t\tthis.populatedNationalNumberTemplate,\r\n\t\t\tthis.populatedNationalNumberTemplatePosition,\r\n\t\t\tdigits\r\n\t\t)\r\n\r\n\t\tif (!result) {\r\n\t\t\t// Reset the format.\r\n\t\t\tthis.resetFormat()\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tthis.populatedNationalNumberTemplate = result[0]\r\n\t\tthis.populatedNationalNumberTemplatePosition = result[1]\r\n\r\n\t\t// Return the formatted phone number so far.\r\n\t\treturn cutAndStripNonPairedParens(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1)\r\n\r\n\t\t// The old way which was good for `input-format` but is not so good\r\n\t\t// for `react-phone-number-input`'s default input (`InputBasic`).\r\n\t\t// return closeNonPairedParens(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1)\r\n\t\t// \t.replace(new RegExp(DIGIT_PLACEHOLDER, 'g'), ' ')\r\n\t}\r\n\r\n\tshouldTryNationalPrefixFormattingRule = (format, { international, nationalPrefix }) => {\r\n\t\tif (format.nationalPrefixFormattingRule()) {\r\n\t\t\t// In some countries, `national_prefix_formatting_rule` is `($1)`,\r\n\t\t\t// so it applies even if the user hasn't input a national prefix.\r\n\t\t\t// `format.usesNationalPrefix()` detects such cases.\r\n\t\t\tconst usesNationalPrefix = format.usesNationalPrefix()\r\n\t\t\tif ((usesNationalPrefix && nationalPrefix) ||\r\n\t\t\t\t(!usesNationalPrefix && !international)) {\r\n\t\t\t\treturn true\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}"],"file":"AsYouTypeFormatter.js"}
1
+ {"version":3,"sources":["../source/AsYouTypeFormatter.js"],"names":["DUMMY_DIGIT","LONGEST_NATIONAL_PHONE_NUMBER_LENGTH","LONGEST_DUMMY_PHONE_NUMBER","NATIONAL_PREFIX_SEPARATORS_PATTERN","SUPPORT_LEGACY_FORMATTING_PATTERNS","CREATE_CHARACTER_CLASS_PATTERN","CREATE_STANDALONE_DIGIT_PATTERN","NON_ALTERING_FORMAT_REG_EXP","RegExp","VALID_PUNCTUATION","MIN_LEADING_DIGITS_LENGTH","AsYouTypeFormatter","state","metadata","format","isNANP","nationalPrefixFormattingRule","test","international","nationalPrefix","usesNationalPrefix","resetFormat","chosenFormat","undefined","template","nationalNumberTemplate","populatedNationalNumberTemplate","populatedNationalNumberTemplatePosition","numberingPlan","callingCode","matchingFormats","formats","nationalSignificantNumber","narrowDownMatchingFormats","nextDigits","formattedCompleteNumber","shouldTryNationalPrefixFormattingRule","getSeparatorAfterNationalPrefix","setNationalNumberTemplate","replace","DIGIT_PLACEHOLDER","lastIndexOf","formatNationalNumberWithNextDigits","previouslyChosenFormat","newlyChosenFormat","chooseFormat","formatNextNationalNumberDigits","getNationalDigits","leadingDigits","leadingDigitsPatternIndex","length","filter","formatSuits","formatMatches","indexOf","nationalPrefixIsOptionalWhenFormattingInNationalFormat","nationalPrefixIsMandatoryWhenFormattingInNationalFormat","leadingDigitsPatternsCount","leadingDigitsPatterns","Math","min","leadingDigitsPattern","internationalFormat","getFormatFormat","createTemplateForFormat","_","slice","pattern","getTemplateForFormat","options","IDDPrefix","missingPlus","spacing","index","i","internationalPrefix","getInternationalPrefixBeforeCountryCallingCode","getDigitsWithoutInternationalPrefix","complexPrefixBeforeNationalSignificantNumber","digits","match","strictPattern","nationalNumberDummyDigits","numberFormat","nationalPrefixIncludedInTemplate","numberFormatWithNationalPrefix","FIRST_GROUP_PATTERN","result"],"mappings":";;;;;;;;;;;;;AAAA;;AAUA;;AAIA;;AAEA;;AACA;;AACA;;;;;;;;;;;;;;AAEA;AACA;AACA,IAAMA,WAAW,GAAG,GAApB,C,CACA;;AACA,IAAMC,oCAAoC,GAAG,EAA7C,C,CACA;AACA;;AACA,IAAMC,0BAA0B,GAAG,gCAAOF,WAAP,EAAoBC,oCAApB,CAAnC,C,CAEA;AACA;;AACA,IAAME,kCAAkC,GAAG,MAA3C,C,CAEA;AACA;AACA;AACA;AACA;AACA;;AACA,IAAMC,kCAAkC,GAAG,IAA3C,C,CAEA;AACA;;AACA,IAAMC,8BAA8B,GAAGD,kCAAkC,IAAK;AAAA,SAAM,iBAAN;AAAA,CAA9E,C,CAEA;AACA;AACA;AACA;AACA;;;AACA,IAAME,+BAA+B,GAAGF,kCAAkC,IAAK;AAAA,SAAM,mBAAN;AAAA,CAA/E,C,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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,WAAK5D,uCAAL,GAA+C4D,MAAM,CAAC,CAAD,CAArD,CAdsC,CAgBtC;;AACA,aAAO,oDAA2B,KAAK7D,+BAAhC,EAAiE,KAAKC,uCAAL,GAA+C,CAAhH,CAAP,CAjBsC,CAmBtC;AACA;AACA;AACA;AACA","sourcesContent":["import {\r\n\tDIGIT_PLACEHOLDER,\r\n\tcountOccurences,\r\n\trepeat,\r\n\tcutAndStripNonPairedParens,\r\n\tcloseNonPairedParens,\r\n\tstripNonPairedParens,\r\n\tpopulateTemplateWithDigits\r\n} from './AsYouTypeFormatter.util'\r\n\r\nimport formatCompleteNumber, {\r\n\tcanFormatCompleteNumber\r\n} from './AsYouTypeFormatter.complete'\r\n\r\nimport parseDigits from './helpers/parseDigits'\r\nexport { DIGIT_PLACEHOLDER } from './AsYouTypeFormatter.util'\r\nimport { FIRST_GROUP_PATTERN } from './helpers/formatNationalNumberUsingFormat'\r\nimport { VALID_PUNCTUATION } from './constants'\r\nimport applyInternationalSeparatorStyle from './helpers/applyInternationalSeparatorStyle'\r\n\r\n// Used in phone number format template creation.\r\n// Could be any digit, I guess.\r\nconst DUMMY_DIGIT = '9'\r\n// I don't know why is it exactly `15`\r\nconst LONGEST_NATIONAL_PHONE_NUMBER_LENGTH = 15\r\n// Create a phone number consisting only of the digit 9 that matches the\r\n// `number_pattern` by applying the pattern to the \"longest phone number\" string.\r\nconst LONGEST_DUMMY_PHONE_NUMBER = repeat(DUMMY_DIGIT, LONGEST_NATIONAL_PHONE_NUMBER_LENGTH)\r\n\r\n// A set of characters that, if found in a national prefix formatting rules, are an indicator to\r\n// us that we should separate the national prefix from the number when formatting.\r\nconst NATIONAL_PREFIX_SEPARATORS_PATTERN = /[- ]/\r\n\r\n// Deprecated: Google has removed some formatting pattern related code from their repo.\r\n// https://github.com/googlei18n/libphonenumber/commit/a395b4fef3caf57c4bc5f082e1152a4d2bd0ba4c\r\n// \"We no longer have numbers in formatting matching patterns, only \\d.\"\r\n// Because this library supports generating custom metadata\r\n// some users may still be using old metadata so the relevant\r\n// code seems to stay until some next major version update.\r\nconst SUPPORT_LEGACY_FORMATTING_PATTERNS = true\r\n\r\n// A pattern that is used to match character classes in regular expressions.\r\n// An example of a character class is \"[1-4]\".\r\nconst CREATE_CHARACTER_CLASS_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && (() => /\\[([^\\[\\]])*\\]/g)\r\n\r\n// Any digit in a regular expression that actually denotes a digit. For\r\n// example, in the regular expression \"80[0-2]\\d{6,10}\", the first 2 digits\r\n// (8 and 0) are standalone digits, but the rest are not.\r\n// Two look-aheads are needed because the number following \\\\d could be a\r\n// two-digit number, since the phone number can be as long as 15 digits.\r\nconst CREATE_STANDALONE_DIGIT_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && (() => /\\d(?=[^,}][^,}])/g)\r\n\r\n// A regular expression that is used to determine if a `format` is\r\n// suitable to be used in the \"as you type formatter\".\r\n// A `format` is suitable when the resulting formatted number has\r\n// the same digits as the user has entered.\r\n//\r\n// In the simplest case, that would mean that the format\r\n// doesn't add any additional digits when formatting a number.\r\n// Google says that it also shouldn't add \"star\" (`*`) characters,\r\n// like it does in some Israeli formats.\r\n// Such basic format would only contain \"valid punctuation\"\r\n// and \"captured group\" identifiers ($1, $2, etc).\r\n//\r\n// An example of a format that adds additional digits:\r\n//\r\n// Country: `AR` (Argentina).\r\n// Format:\r\n// {\r\n// \"pattern\": \"(\\\\d)(\\\\d{2})(\\\\d{4})(\\\\d{4})\",\r\n// \"leading_digits_patterns\": [\"91\"],\r\n// \"national_prefix_formatting_rule\": \"0$1\",\r\n// \"format\": \"$2 15-$3-$4\",\r\n// \"international_format\": \"$1 $2 $3-$4\"\r\n// }\r\n//\r\n// In the format above, the `format` adds `15` to the digits when formatting a number.\r\n// A sidenote: this format actually is suitable because `national_prefix_for_parsing`\r\n// has previously removed `15` from a national number, so re-adding `15` in `format`\r\n// doesn't actually result in any extra digits added to user's input.\r\n// But verifying that would be a complex procedure, so the code chooses a simpler path:\r\n// it simply filters out all `format`s that contain anything but \"captured group\" ids.\r\n//\r\n// This regular expression is called `ELIGIBLE_FORMAT_PATTERN` in Google's\r\n// `libphonenumber` code.\r\n//\r\nconst NON_ALTERING_FORMAT_REG_EXP = new RegExp(\r\n\t'^' +\r\n\t'[' + VALID_PUNCTUATION + ']*' +\r\n\t'(\\\\$\\\\d[' + VALID_PUNCTUATION + ']*)+' +\r\n\t'$'\r\n)\r\n\r\n// This is the minimum length of the leading digits of a phone number\r\n// to guarantee the first \"leading digits pattern\" for a phone number format\r\n// to be preemptive.\r\nconst MIN_LEADING_DIGITS_LENGTH = 3\r\n\r\nexport default class AsYouTypeFormatter {\r\n\tconstructor({\r\n\t\tstate,\r\n\t\tmetadata\r\n\t}) {\r\n\t\tthis.metadata = metadata\r\n\t\tthis.resetFormat()\r\n\t}\r\n\r\n\tresetFormat() {\r\n\t\tthis.chosenFormat = undefined\r\n\t\tthis.template = undefined\r\n\t\tthis.nationalNumberTemplate = undefined\r\n\t\tthis.populatedNationalNumberTemplate = undefined\r\n\t\tthis.populatedNationalNumberTemplatePosition = -1\r\n\t}\r\n\r\n\treset(numberingPlan, state) {\r\n\t\tthis.resetFormat()\r\n\t\tif (numberingPlan) {\r\n\t\t\tthis.isNANP = numberingPlan.callingCode() === '1'\r\n\t\t\tthis.matchingFormats = numberingPlan.formats()\r\n\t\t\tif (state.nationalSignificantNumber) {\r\n\t\t\t\tthis.narrowDownMatchingFormats(state)\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tthis.isNANP = undefined\r\n\t\t\tthis.matchingFormats = []\r\n\t\t}\r\n\t}\r\n\r\n\tformat(nextDigits, state) {\r\n\t\t// See if the phone number digits can be formatted as a complete phone number.\r\n\t\t// If not, use the results from `formatNationalNumberWithNextDigits()`,\r\n\t\t// which formats based on the chosen formatting pattern.\r\n\t\t//\r\n\t\t// Attempting to format complete phone number first is how it's done\r\n\t\t// in Google's `libphonenumber`, so this library just follows it.\r\n\t\t// Google's `libphonenumber` code doesn't explain in detail why does it\r\n\t\t// attempt to format digits as a complete phone number\r\n\t\t// instead of just going with a previoulsy (or newly) chosen `format`:\r\n\t\t//\r\n\t\t// \"Checks to see if there is an exact pattern match for these digits.\r\n\t\t// If so, we should use this instead of any other formatting template\r\n\t\t// whose leadingDigitsPattern also matches the input.\"\r\n\t\t//\r\n\t\tif (canFormatCompleteNumber(state.nationalSignificantNumber, this.metadata)) {\r\n\t\t\tfor (const format of this.matchingFormats) {\r\n\t\t\t\tconst formattedCompleteNumber = formatCompleteNumber(\r\n\t\t\t\t\tstate,\r\n\t\t\t\t\tformat,\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tmetadata: this.metadata,\r\n\t\t\t\t\t\tshouldTryNationalPrefixFormattingRule: format => this.shouldTryNationalPrefixFormattingRule(format, {\r\n\t\t\t\t\t\t\tinternational: state.international,\r\n\t\t\t\t\t\t\tnationalPrefix: state.nationalPrefix\r\n\t\t\t\t\t\t}),\r\n\t\t\t\t\t\tgetSeparatorAfterNationalPrefix: this.getSeparatorAfterNationalPrefix\r\n\t\t\t\t\t}\r\n\t\t\t\t)\r\n\t\t\t\tif (formattedCompleteNumber) {\r\n\t\t\t\t\tthis.resetFormat()\r\n\t\t\t\t\tthis.chosenFormat = format\r\n\t\t\t\t\tthis.setNationalNumberTemplate(formattedCompleteNumber.replace(/\\d/g, DIGIT_PLACEHOLDER), state)\r\n\t\t\t\t\tthis.populatedNationalNumberTemplate = formattedCompleteNumber\r\n\t\t\t\t\t// With a new formatting template, the matched position\r\n\t\t\t\t\t// using the old template needs to be reset.\r\n\t\t\t\t\tthis.populatedNationalNumberTemplatePosition = this.template.lastIndexOf(DIGIT_PLACEHOLDER)\r\n\t\t\t\t\treturn formattedCompleteNumber\r\n\t\t\t\t}\r\n\r\n\t\t\t}\r\n\t\t}\r\n\t\t// Format the digits as a partial (incomplete) phone number\r\n\t\t// using the previously chosen formatting pattern (or a newly chosen one).\r\n\t\treturn this.formatNationalNumberWithNextDigits(nextDigits, state)\r\n\t}\r\n\r\n\t// Formats the next phone number digits.\r\n\tformatNationalNumberWithNextDigits(nextDigits, state) {\r\n\t\tconst previouslyChosenFormat = this.chosenFormat\r\n\t\t// Choose a format from the list of matching ones.\r\n\t\tconst newlyChosenFormat = this.chooseFormat(state)\r\n\t\tif (newlyChosenFormat) {\r\n\t\t\tif (newlyChosenFormat === previouslyChosenFormat) {\r\n\t\t\t\t// If it can format the next (current) digits\r\n\t\t\t\t// using the previously chosen phone number format\r\n\t\t\t\t// then return the updated formatted number.\r\n\t\t\t\treturn this.formatNextNationalNumberDigits(nextDigits)\r\n\t\t\t} else {\r\n\t\t\t\t// If a more appropriate phone number format\r\n\t\t\t\t// has been chosen for these \"leading digits\",\r\n\t\t\t\t// then re-format the national phone number part\r\n\t\t\t\t// using the newly selected format.\r\n\t\t\t\treturn this.formatNextNationalNumberDigits(state.getNationalDigits())\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tnarrowDownMatchingFormats({\r\n\t\tnationalSignificantNumber,\r\n\t\tnationalPrefix,\r\n\t\tinternational\r\n\t}) {\r\n\t\tconst leadingDigits = nationalSignificantNumber\r\n\r\n\t\t// \"leading digits\" pattern list starts with a\r\n\t\t// \"leading digits\" pattern fitting a maximum of 3 leading digits.\r\n\t\t// So, after a user inputs 3 digits of a national (significant) phone number\r\n\t\t// this national (significant) number can already be formatted.\r\n\t\t// The next \"leading digits\" pattern is for 4 leading digits max,\r\n\t\t// and the \"leading digits\" pattern after it is for 5 leading digits max, etc.\r\n\r\n\t\t// This implementation is different from Google's\r\n\t\t// in that it searches for a fitting format\r\n\t\t// even if the user has entered less than\r\n\t\t// `MIN_LEADING_DIGITS_LENGTH` digits of a national number.\r\n\t\t// Because some leading digit patterns already match for a single first digit.\r\n\t\tlet leadingDigitsPatternIndex = leadingDigits.length - MIN_LEADING_DIGITS_LENGTH\r\n\t\tif (leadingDigitsPatternIndex < 0) {\r\n\t\t\tleadingDigitsPatternIndex = 0\r\n\t\t}\r\n\r\n\t\tthis.matchingFormats = this.matchingFormats.filter(\r\n\t\t\tformat => this.formatSuits(format, international, nationalPrefix)\r\n\t\t\t\t&& this.formatMatches(format, leadingDigits, leadingDigitsPatternIndex)\r\n\t\t)\r\n\r\n\t\t// If there was a phone number format chosen\r\n\t\t// and it no longer holds given the new leading digits then reset it.\r\n\t\t// The test for this `if` condition is marked as:\r\n\t\t// \"Reset a chosen format when it no longer holds given the new leading digits\".\r\n\t\t// To construct a valid test case for this one can find a country\r\n\t\t// in `PhoneNumberMetadata.xml` yielding one format for 3 `<leadingDigits>`\r\n\t\t// and yielding another format for 4 `<leadingDigits>` (Australia in this case).\r\n\t\tif (this.chosenFormat && this.matchingFormats.indexOf(this.chosenFormat) === -1) {\r\n\t\t\tthis.resetFormat()\r\n\t\t}\r\n\t}\r\n\r\n\tformatSuits(format, international, nationalPrefix) {\r\n\t\t// When a prefix before a national (significant) number is\r\n\t\t// simply a national prefix, then it's parsed as `this.nationalPrefix`.\r\n\t\t// In more complex cases, a prefix before national (significant) number\r\n\t\t// could include a national prefix as well as some \"capturing groups\",\r\n\t\t// and in that case there's no info whether a national prefix has been parsed.\r\n\t\t// If national prefix is not used when formatting a phone number\r\n\t\t// using this format, but a national prefix has been entered by the user,\r\n\t\t// and was extracted, then discard such phone number format.\r\n\t\t// In Google's \"AsYouType\" formatter code, the equivalent would be this part:\r\n\t\t// https://github.com/google/libphonenumber/blob/0a45cfd96e71cad8edb0e162a70fcc8bd9728933/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java#L175-L184\r\n\t\tif (nationalPrefix &&\r\n\t\t\t!format.usesNationalPrefix() &&\r\n\t\t\t// !format.domesticCarrierCodeFormattingRule() &&\r\n\t\t\t!format.nationalPrefixIsOptionalWhenFormattingInNationalFormat()) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\t// If national prefix is mandatory for this phone number format\r\n\t\t// and there're no guarantees that a national prefix is present in user input\r\n\t\t// then discard this phone number format as not suitable.\r\n\t\t// In Google's \"AsYouType\" formatter code, the equivalent would be this part:\r\n\t\t// https://github.com/google/libphonenumber/blob/0a45cfd96e71cad8edb0e162a70fcc8bd9728933/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java#L185-L193\r\n\t\tif (!international &&\r\n\t\t\t!nationalPrefix &&\r\n\t\t\tformat.nationalPrefixIsMandatoryWhenFormattingInNationalFormat()) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\treturn true\r\n\t}\r\n\r\n\tformatMatches(format, leadingDigits, leadingDigitsPatternIndex) {\r\n\t\tconst leadingDigitsPatternsCount = format.leadingDigitsPatterns().length\r\n\t\t// If this format is not restricted to a certain\r\n\t\t// leading digits pattern then it fits.\r\n\t\tif (leadingDigitsPatternsCount === 0) {\r\n\t\t\treturn true\r\n\t\t}\r\n\t\t// Start excluding any non-matching formats only when the\r\n\t\t// national number entered so far is at least 3 digits long,\r\n\t\t// otherwise format matching would give false negatives.\r\n\t\t// For example, when the digits entered so far are `2`\r\n\t\t// and the leading digits pattern is `21` –\r\n\t\t// it's quite obvious in this case that the format could be the one\r\n\t\t// but due to the absence of further digits it would give false negative.\r\n\t\tif (leadingDigits.length < MIN_LEADING_DIGITS_LENGTH) {\r\n\t\t\treturn true\r\n\t\t}\r\n\t\t// If at least `MIN_LEADING_DIGITS_LENGTH` digits of a national number are available\r\n\t\t// then format matching starts narrowing down the list of possible formats\r\n\t\t// (only previously matched formats are considered for next digits).\r\n\t\tleadingDigitsPatternIndex = Math.min(leadingDigitsPatternIndex, leadingDigitsPatternsCount - 1)\r\n\t\tconst leadingDigitsPattern = format.leadingDigitsPatterns()[leadingDigitsPatternIndex]\r\n\t\t// Brackets are required for `^` to be applied to\r\n\t\t// all or-ed (`|`) parts, not just the first one.\r\n\t\treturn new RegExp(`^(${leadingDigitsPattern})`).test(leadingDigits)\r\n\t}\r\n\r\n\tgetFormatFormat(format, international) {\r\n\t\treturn international ? format.internationalFormat() : format.format()\r\n\t}\r\n\r\n\tchooseFormat(state) {\r\n\t\t// When there are multiple available formats, the formatter uses the first\r\n\t\t// format where a formatting template could be created.\r\n\t\tfor (const format of this.matchingFormats.slice()) {\r\n\t\t\t// If this format is currently being used\r\n\t\t\t// and is still suitable, then stick to it.\r\n\t\t\tif (this.chosenFormat === format) {\r\n\t\t\t\tbreak\r\n\t\t\t}\r\n\t\t\t// Sometimes, a formatting rule inserts additional digits in a phone number,\r\n\t\t\t// and \"as you type\" formatter can't do that: it should only use the digits\r\n\t\t\t// that the user has input.\r\n\t\t\t//\r\n\t\t\t// For example, in Argentina, there's a format for mobile phone numbers:\r\n\t\t\t//\r\n\t\t\t// {\r\n\t\t\t// \"pattern\": \"(\\\\d)(\\\\d{2})(\\\\d{4})(\\\\d{4})\",\r\n\t\t\t// \"leading_digits_patterns\": [\"91\"],\r\n\t\t\t// \"national_prefix_formatting_rule\": \"0$1\",\r\n\t\t\t// \"format\": \"$2 15-$3-$4\",\r\n\t\t\t// \"international_format\": \"$1 $2 $3-$4\"\r\n\t\t\t// }\r\n\t\t\t//\r\n\t\t\t// In that format, `international_format` is used instead of `format`\r\n\t\t\t// because `format` inserts `15` in the formatted number,\r\n\t\t\t// and `AsYouType` formatter should only use the digits\r\n\t\t\t// the user has actually input, without adding any extra digits.\r\n\t\t\t// In this case, it wouldn't make a difference, because the `15`\r\n\t\t\t// is first stripped when applying `national_prefix_for_parsing`\r\n\t\t\t// and then re-added when using `format`, so in reality it doesn't\r\n\t\t\t// add any new digits to the number, but to detect that, the code\r\n\t\t\t// would have to be more complex: it would have to try formatting\r\n\t\t\t// the digits using the format and then see if any digits have\r\n\t\t\t// actually been added or removed, and then, every time a new digit\r\n\t\t\t// is input, it should re-check whether the chosen format doesn't\r\n\t\t\t// alter the digits.\r\n\t\t\t//\r\n\t\t\t// Google's code doesn't go that far, and so does this library:\r\n\t\t\t// it simply requires that a `format` doesn't add any additonal\r\n\t\t\t// digits to user's input.\r\n\t\t\t//\r\n\t\t\t// Also, people in general should move from inputting phone numbers\r\n\t\t\t// in national format (possibly with national prefixes)\r\n\t\t\t// and use international phone number format instead:\r\n\t\t\t// it's a logical thing in the modern age of mobile phones,\r\n\t\t\t// globalization and the internet.\r\n\t\t\t//\r\n\t\t\t/* istanbul ignore if */\r\n\t\t\tif (!NON_ALTERING_FORMAT_REG_EXP.test(this.getFormatFormat(format, state.international))) {\r\n\t\t\t\tcontinue\r\n\t\t\t}\r\n\t\t\tif (!this.createTemplateForFormat(format, state)) {\r\n\t\t\t\t// Remove the format if it can't generate a template.\r\n\t\t\t\tthis.matchingFormats = this.matchingFormats.filter(_ => _ !== format)\r\n\t\t\t\tcontinue\r\n\t\t\t}\r\n\t\t\tthis.chosenFormat = format\r\n\t\t\tbreak\r\n\t\t}\r\n\t\tif (!this.chosenFormat) {\r\n\t\t\t// No format matches the national (significant) phone number.\r\n\t\t\tthis.resetFormat()\r\n\t\t}\r\n\t\treturn this.chosenFormat\r\n\t}\r\n\r\n\tcreateTemplateForFormat(format, state) {\r\n\t\t// The formatter doesn't format numbers when numberPattern contains '|', e.g.\r\n\t\t// (20|3)\\d{4}. In those cases we quickly return.\r\n\t\t// (Though there's no such format in current metadata)\r\n\t\t/* istanbul ignore if */\r\n\t\tif (SUPPORT_LEGACY_FORMATTING_PATTERNS && format.pattern().indexOf('|') >= 0) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\t// Get formatting template for this phone number format\r\n\t\tconst template = this.getTemplateForFormat(format, state)\r\n\t\t// If the national number entered is too long\r\n\t\t// for any phone number format, then abort.\r\n\t\tif (template) {\r\n\t\t\tthis.setNationalNumberTemplate(template, state)\r\n\t\t\treturn true\r\n\t\t}\r\n\t}\r\n\r\n\tgetSeparatorAfterNationalPrefix = (format) => {\r\n\t\t// `US` metadata doesn't have a `national_prefix_formatting_rule`,\r\n\t\t// so the `if` condition below doesn't apply to `US`,\r\n\t\t// but in reality there shoudl be a separator\r\n\t\t// between a national prefix and a national (significant) number.\r\n\t\t// So `US` national prefix separator is a \"special\" \"hardcoded\" case.\r\n\t\tif (this.isNANP) {\r\n\t\t\treturn ' '\r\n\t\t}\r\n\t\t// If a `format` has a `national_prefix_formatting_rule`\r\n\t\t// and that rule has a separator after a national prefix,\r\n\t\t// then it means that there should be a separator\r\n\t\t// between a national prefix and a national (significant) number.\r\n\t\tif (format &&\r\n\t\t\tformat.nationalPrefixFormattingRule() &&\r\n\t\t\tNATIONAL_PREFIX_SEPARATORS_PATTERN.test(format.nationalPrefixFormattingRule())) {\r\n\t\t\treturn ' '\r\n\t\t}\r\n\t\t// At this point, there seems to be no clear evidence that\r\n\t\t// there should be a separator between a national prefix\r\n\t\t// and a national (significant) number. So don't insert one.\r\n\t\treturn ''\r\n\t}\r\n\r\n\tgetInternationalPrefixBeforeCountryCallingCode({ IDDPrefix, missingPlus }, options) {\r\n\t\tif (IDDPrefix) {\r\n\t\t\treturn options && options.spacing === false ? IDDPrefix : IDDPrefix + ' '\r\n\t\t}\r\n\t\tif (missingPlus) {\r\n\t\t\treturn ''\r\n\t\t}\r\n\t\treturn '+'\r\n\t}\r\n\r\n\tgetTemplate(state) {\r\n\t\tif (!this.template) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\t// `this.template` holds the template for a \"complete\" phone number.\r\n\t\t// The currently entered phone number is most likely not \"complete\",\r\n\t\t// so trim all non-populated digits.\r\n\t\tlet index = -1\r\n\t\tlet i = 0\r\n\t\tconst internationalPrefix = state.international ? this.getInternationalPrefixBeforeCountryCallingCode(state, { spacing: false }) : ''\r\n\t\twhile (i < internationalPrefix.length + state.getDigitsWithoutInternationalPrefix().length) {\r\n\t\t\tindex = this.template.indexOf(DIGIT_PLACEHOLDER, index + 1)\r\n\t\t\ti++\r\n\t\t}\r\n\t\treturn cutAndStripNonPairedParens(this.template, index + 1)\r\n\t}\r\n\r\n\tsetNationalNumberTemplate(template, state) {\r\n\t\tthis.nationalNumberTemplate = template\r\n\t\tthis.populatedNationalNumberTemplate = template\r\n\t\t// With a new formatting template, the matched position\r\n\t\t// using the old template needs to be reset.\r\n\t\tthis.populatedNationalNumberTemplatePosition = -1\r\n\t\t// For convenience, the public `.template` property\r\n\t\t// contains the whole international number\r\n\t\t// if the phone number being input is international:\r\n\t\t// 'x' for the '+' sign, 'x'es for the country phone code,\r\n\t\t// a spacebar and then the template for the formatted national number.\r\n\t\tif (state.international) {\r\n\t\t\tthis.template =\r\n\t\t\t\tthis.getInternationalPrefixBeforeCountryCallingCode(state).replace(/[\\d\\+]/g, DIGIT_PLACEHOLDER) +\r\n\t\t\t\trepeat(DIGIT_PLACEHOLDER, state.callingCode.length) +\r\n\t\t\t\t' ' +\r\n\t\t\t\ttemplate\r\n\t\t} else {\r\n\t\t\tthis.template = template\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Generates formatting template for a national phone number,\r\n\t * optionally containing a national prefix, for a format.\r\n\t * @param {Format} format\r\n\t * @param {string} nationalPrefix\r\n\t * @return {string}\r\n\t */\r\n\tgetTemplateForFormat(format, {\r\n\t\tnationalSignificantNumber,\r\n\t\tinternational,\r\n\t\tnationalPrefix,\r\n\t\tcomplexPrefixBeforeNationalSignificantNumber\r\n\t}) {\r\n\t\tlet pattern = format.pattern()\r\n\r\n\t\t/* istanbul ignore else */\r\n\t\tif (SUPPORT_LEGACY_FORMATTING_PATTERNS) {\r\n\t\t\tpattern = pattern\r\n\t\t\t\t// Replace anything in the form of [..] with \\d\r\n\t\t\t\t.replace(CREATE_CHARACTER_CLASS_PATTERN(), '\\\\d')\r\n\t\t\t\t// Replace any standalone digit (not the one in `{}`) with \\d\r\n\t\t\t\t.replace(CREATE_STANDALONE_DIGIT_PATTERN(), '\\\\d')\r\n\t\t}\r\n\r\n\t\t// Generate a dummy national number (consisting of `9`s)\r\n\t\t// that fits this format's `pattern`.\r\n\t\t//\r\n\t\t// This match will always succeed,\r\n\t\t// because the \"longest dummy phone number\"\r\n\t\t// has enough length to accomodate any possible\r\n\t\t// national phone number format pattern.\r\n\t\t//\r\n\t\tlet digits = LONGEST_DUMMY_PHONE_NUMBER.match(pattern)[0]\r\n\r\n\t\t// If the national number entered is too long\r\n\t\t// for any phone number format, then abort.\r\n\t\tif (nationalSignificantNumber.length > digits.length) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\t// Get a formatting template which can be used to efficiently format\r\n\t\t// a partial number where digits are added one by one.\r\n\r\n\t\t// Below `strictPattern` is used for the\r\n\t\t// regular expression (with `^` and `$`).\r\n\t\t// This wasn't originally in Google's `libphonenumber`\r\n\t\t// and I guess they don't really need it\r\n\t\t// because they're not using \"templates\" to format phone numbers\r\n\t\t// but I added `strictPattern` after encountering\r\n\t\t// South Korean phone number formatting bug.\r\n\t\t//\r\n\t\t// Non-strict regular expression bug demonstration:\r\n\t\t//\r\n\t\t// this.nationalSignificantNumber : `111111111` (9 digits)\r\n\t\t//\r\n\t\t// pattern : (\\d{2})(\\d{3,4})(\\d{4})\r\n\t\t// format : `$1 $2 $3`\r\n\t\t// digits : `9999999999` (10 digits)\r\n\t\t//\r\n\t\t// '9999999999'.replace(new RegExp(/(\\d{2})(\\d{3,4})(\\d{4})/g), '$1 $2 $3') = \"99 9999 9999\"\r\n\t\t//\r\n\t\t// template : xx xxxx xxxx\r\n\t\t//\r\n\t\t// But the correct template in this case is `xx xxx xxxx`.\r\n\t\t// The template was generated incorrectly because of the\r\n\t\t// `{3,4}` variability in the `pattern`.\r\n\t\t//\r\n\t\t// The fix is, if `this.nationalSignificantNumber` has already sufficient length\r\n\t\t// to satisfy the `pattern` completely then `this.nationalSignificantNumber`\r\n\t\t// is used instead of `digits`.\r\n\r\n\t\tconst strictPattern = new RegExp('^' + pattern + '$')\r\n\t\tconst nationalNumberDummyDigits = nationalSignificantNumber.replace(/\\d/g, DUMMY_DIGIT)\r\n\r\n\t\t// If `this.nationalSignificantNumber` has already sufficient length\r\n\t\t// to satisfy the `pattern` completely then use it\r\n\t\t// instead of `digits`.\r\n\t\tif (strictPattern.test(nationalNumberDummyDigits)) {\r\n\t\t\tdigits = nationalNumberDummyDigits\r\n\t\t}\r\n\r\n\t\tlet numberFormat = this.getFormatFormat(format, international)\r\n\t\tlet nationalPrefixIncludedInTemplate\r\n\r\n\t\t// If a user did input a national prefix (and that's guaranteed),\r\n\t\t// and if a `format` does have a national prefix formatting rule,\r\n\t\t// then see if that national prefix formatting rule\r\n\t\t// prepends exactly the same national prefix the user has input.\r\n\t\t// If that's the case, then use the `format` with the national prefix formatting rule.\r\n\t\t// Otherwise, use the `format` without the national prefix formatting rule,\r\n\t\t// and prepend a national prefix manually to it.\r\n\t\tif (this.shouldTryNationalPrefixFormattingRule(format, { international, nationalPrefix })) {\r\n\t\t\tconst numberFormatWithNationalPrefix = numberFormat.replace(\r\n\t\t\t\tFIRST_GROUP_PATTERN,\r\n\t\t\t\tformat.nationalPrefixFormattingRule()\r\n\t\t\t)\r\n\t\t\t// If `national_prefix_formatting_rule` of a `format` simply prepends\r\n\t\t\t// national prefix at the start of a national (significant) number,\r\n\t\t\t// then such formatting can be used with `AsYouType` formatter.\r\n\t\t\t// There seems to be no `else` case: everywhere in metadata,\r\n\t\t\t// national prefix formatting rule is national prefix + $1,\r\n\t\t\t// or `($1)`, in which case such format isn't even considered\r\n\t\t\t// when the user has input a national prefix.\r\n\t\t\t/* istanbul ignore else */\r\n\t\t\tif (parseDigits(format.nationalPrefixFormattingRule()) === (nationalPrefix || '') + parseDigits('$1')) {\r\n\t\t\t\tnumberFormat = numberFormatWithNationalPrefix\r\n\t\t\t\tnationalPrefixIncludedInTemplate = true\r\n\t\t\t\t// Replace all digits of the national prefix in the formatting template\r\n\t\t\t\t// with `DIGIT_PLACEHOLDER`s.\r\n\t\t\t\tif (nationalPrefix) {\r\n\t\t\t\t\tlet i = nationalPrefix.length\r\n\t\t\t\t\twhile (i > 0) {\r\n\t\t\t\t\t\tnumberFormat = numberFormat.replace(/\\d/, DIGIT_PLACEHOLDER)\r\n\t\t\t\t\t\ti--\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Generate formatting template for this phone number format.\r\n\t\tlet template = digits\r\n\t\t\t// Format the dummy phone number according to the format.\r\n\t\t\t.replace(new RegExp(pattern), numberFormat)\r\n\t\t\t// Replace each dummy digit with a DIGIT_PLACEHOLDER.\r\n\t\t\t.replace(new RegExp(DUMMY_DIGIT, 'g'), DIGIT_PLACEHOLDER)\r\n\r\n\t\t// If a prefix of a national (significant) number is not as simple\r\n\t\t// as just a basic national prefix, then just prepend such prefix\r\n\t\t// before the national (significant) number, optionally spacing\r\n\t\t// the two with a whitespace.\r\n\t\tif (!nationalPrefixIncludedInTemplate) {\r\n\t\t\tif (complexPrefixBeforeNationalSignificantNumber) {\r\n\t\t\t\t// Prepend the prefix to the template manually.\r\n\t\t\t\ttemplate = repeat(DIGIT_PLACEHOLDER, complexPrefixBeforeNationalSignificantNumber.length) +\r\n\t\t\t\t\t' ' +\r\n\t\t\t\t\ttemplate\r\n\t\t\t} else if (nationalPrefix) {\r\n\t\t\t\t// Prepend national prefix to the template manually.\r\n\t\t\t\ttemplate = repeat(DIGIT_PLACEHOLDER, nationalPrefix.length) +\r\n\t\t\t\t\tthis.getSeparatorAfterNationalPrefix(format) +\r\n\t\t\t\t\ttemplate\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (international) {\r\n\t\t\ttemplate = applyInternationalSeparatorStyle(template)\r\n\t\t}\r\n\r\n\t\treturn template\r\n\t}\r\n\r\n\tformatNextNationalNumberDigits(digits) {\r\n\t\tconst result = populateTemplateWithDigits(\r\n\t\t\tthis.populatedNationalNumberTemplate,\r\n\t\t\tthis.populatedNationalNumberTemplatePosition,\r\n\t\t\tdigits\r\n\t\t)\r\n\r\n\t\tif (!result) {\r\n\t\t\t// Reset the format.\r\n\t\t\tthis.resetFormat()\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tthis.populatedNationalNumberTemplate = result[0]\r\n\t\tthis.populatedNationalNumberTemplatePosition = result[1]\r\n\r\n\t\t// Return the formatted phone number so far.\r\n\t\treturn cutAndStripNonPairedParens(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1)\r\n\r\n\t\t// The old way which was good for `input-format` but is not so good\r\n\t\t// for `react-phone-number-input`'s default input (`InputBasic`).\r\n\t\t// return closeNonPairedParens(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1)\r\n\t\t// \t.replace(new RegExp(DIGIT_PLACEHOLDER, 'g'), ' ')\r\n\t}\r\n\r\n\tshouldTryNationalPrefixFormattingRule = (format, { international, nationalPrefix }) => {\r\n\t\tif (format.nationalPrefixFormattingRule()) {\r\n\t\t\t// In some countries, `national_prefix_formatting_rule` is `($1)`,\r\n\t\t\t// so it applies even if the user hasn't input a national prefix.\r\n\t\t\t// `format.usesNationalPrefix()` detects such cases.\r\n\t\t\tconst usesNationalPrefix = format.usesNationalPrefix()\r\n\t\t\tif ((usesNationalPrefix && nationalPrefix) ||\r\n\t\t\t\t(!usesNationalPrefix && !international)) {\r\n\t\t\t\treturn true\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}"],"file":"AsYouTypeFormatter.js"}
@@ -4,14 +4,17 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.extractFormattedDigitsAndPlus = extractFormattedDigitsAndPlus;
7
- exports.autoCorrectInternationalNumberWithoutPlus = autoCorrectInternationalNumberWithoutPlus;
8
7
  exports["default"] = void 0;
9
8
 
10
- var _parseDigits = _interopRequireDefault(require("./parseDigits"));
9
+ var _extractCountryCallingCode2 = _interopRequireDefault(require("./helpers/extractCountryCallingCode"));
11
10
 
12
- var _parse_ = require("./parse_");
11
+ var _extractCountryCallingCodeFromInternationalNumberWithoutPlusSign = _interopRequireDefault(require("./helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign"));
13
12
 
14
- var _IDD = require("./IDD");
13
+ var _extractNationalNumberFromPossiblyIncompleteNumber = _interopRequireDefault(require("./helpers/extractNationalNumberFromPossiblyIncompleteNumber"));
14
+
15
+ var _stripIddPrefix = _interopRequireDefault(require("./helpers/stripIddPrefix"));
16
+
17
+ var _parseDigits = _interopRequireDefault(require("./helpers/parseDigits"));
15
18
 
16
19
  var _constants = require("./constants");
17
20
 
@@ -116,7 +119,7 @@ function () {
116
119
  // there's a new digit and the number couldn't be formatted.
117
120
 
118
121
  if (hasReceivedThreeLeadingDigits) {
119
- this.extractIDDPrefix(state);
122
+ this.extractIddPrefix(state);
120
123
  }
121
124
 
122
125
  if (this.isWaitingForCountryCallingCode(state)) {
@@ -150,7 +153,7 @@ function () {
150
153
  }, {
151
154
  key: "extractCountryCallingCode",
152
155
  value: function extractCountryCallingCode(state) {
153
- var _extractCountryCallin = (0, _parse_.extractCountryCallingCode)('+' + state.getDigitsWithoutInternationalPrefix(), this.defaultCountry, this.defaultCallingCode, this.metadata.metadata),
156
+ var _extractCountryCallin = (0, _extractCountryCallingCode2["default"])('+' + state.getDigitsWithoutInternationalPrefix(), this.defaultCountry, this.defaultCallingCode, this.metadata.metadata),
154
157
  countryCallingCode = _extractCountryCallin.countryCallingCode,
155
158
  number = _extractCountryCallin.number;
156
159
 
@@ -191,7 +194,7 @@ function () {
191
194
  return;
192
195
  }
193
196
 
194
- var _extractNationalNumbe = (0, _parse_.extractNationalNumberFromPossiblyIncompleteNumber)(nationalDigits, this.metadata),
197
+ var _extractNationalNumbe = (0, _extractNationalNumberFromPossiblyIncompleteNumber["default"])(nationalDigits, this.metadata),
195
198
  nationalPrefix = _extractNationalNumbe.nationalPrefix,
196
199
  nationalNumber = _extractNationalNumbe.nationalNumber,
197
200
  carrierCode = _extractNationalNumbe.carrierCode;
@@ -220,7 +223,7 @@ function () {
220
223
  return;
221
224
  }
222
225
 
223
- var _extractNationalNumbe2 = (0, _parse_.extractNationalNumberFromPossiblyIncompleteNumber)(nationalDigits, this.metadata),
226
+ var _extractNationalNumbe2 = (0, _extractNationalNumberFromPossiblyIncompleteNumber["default"])(nationalDigits, this.metadata),
224
227
  nationalPrefix = _extractNationalNumbe2.nationalPrefix,
225
228
  nationalNumber = _extractNationalNumbe2.nationalNumber,
226
229
  carrierCode = _extractNationalNumbe2.carrierCode; // If a national prefix has been extracted previously,
@@ -335,13 +338,26 @@ function () {
335
338
  //
336
339
 
337
340
 
338
- if (this.extractIDDPrefix(state)) {
341
+ if (this.extractIddPrefix(state)) {
342
+ this.extractCallingCodeAndNationalSignificantNumber(state);
343
+ return true;
344
+ } // Google's AsYouType formatter supports sort of an "autocorrection" feature
345
+ // when it "autocorrects" numbers that have been input for a country
346
+ // with that country's calling code.
347
+ // Such "autocorrection" feature looks weird, but different people have been requesting it:
348
+ // https://github.com/catamphetamine/libphonenumber-js/issues/376
349
+ // https://github.com/catamphetamine/libphonenumber-js/issues/375
350
+ // https://github.com/catamphetamine/libphonenumber-js/issues/316
351
+
352
+
353
+ if (this.fixMissingPlus(state)) {
354
+ this.extractCallingCodeAndNationalSignificantNumber(state);
339
355
  return true;
340
356
  }
341
357
  }
342
358
  }, {
343
- key: "extractIDDPrefix",
344
- value: function extractIDDPrefix(state) {
359
+ key: "extractIddPrefix",
360
+ value: function extractIddPrefix(state) {
345
361
  // An IDD prefix can't be present in a number written with a `+`.
346
362
  // Also, don't re-extract an IDD prefix if has already been extracted.
347
363
  var international = state.international,
@@ -357,7 +373,7 @@ function () {
357
373
  // Detect such numbers.
358
374
 
359
375
 
360
- var numberWithoutIDD = (0, _IDD.stripIDDPrefix)(digits, this.defaultCountry, this.defaultCallingCode, this.metadata.metadata);
376
+ var numberWithoutIDD = (0, _stripIddPrefix["default"])(digits, this.defaultCountry, this.defaultCallingCode, this.metadata.metadata);
361
377
 
362
378
  if (numberWithoutIDD !== undefined && numberWithoutIDD !== digits) {
363
379
  // If an IDD prefix was stripped then convert the IDD-prefixed number
@@ -365,17 +381,51 @@ function () {
365
381
  state.update({
366
382
  IDDPrefix: digits.slice(0, digits.length - numberWithoutIDD.length)
367
383
  });
368
- state.startInternationalNumber(); // If a national (significant) number has been extracted before, reset it.
369
-
370
- if (nationalSignificantNumber) {
371
- state.resetNationalSignificantNumber();
372
- this.onNationalSignificantNumberChange();
373
- this.hasExtractedNationalSignificantNumber = undefined;
374
- }
375
-
384
+ this.startInternationalNumber(state);
376
385
  return true;
377
386
  }
378
387
  }
388
+ }, {
389
+ key: "fixMissingPlus",
390
+ value: function fixMissingPlus(state) {
391
+ if (!state.international) {
392
+ var _extractCountryCallin2 = (0, _extractCountryCallingCodeFromInternationalNumberWithoutPlusSign["default"])(state.digits, this.defaultCountry, this.defaultCallingCode, this.metadata.metadata),
393
+ newCallingCode = _extractCountryCallin2.countryCallingCode,
394
+ number = _extractCountryCallin2.number;
395
+
396
+ if (newCallingCode) {
397
+ state.update({
398
+ missingPlus: true
399
+ });
400
+ this.startInternationalNumber(state);
401
+ return true;
402
+ }
403
+ }
404
+ }
405
+ }, {
406
+ key: "startInternationalNumber",
407
+ value: function startInternationalNumber(state) {
408
+ state.startInternationalNumber(); // If a national (significant) number has been extracted before, reset it.
409
+
410
+ if (state.nationalSignificantNumber) {
411
+ state.resetNationalSignificantNumber();
412
+ this.onNationalSignificantNumberChange();
413
+ this.hasExtractedNationalSignificantNumber = undefined;
414
+ }
415
+ }
416
+ }, {
417
+ key: "extractCallingCodeAndNationalSignificantNumber",
418
+ value: function extractCallingCodeAndNationalSignificantNumber(state) {
419
+ if (this.extractCountryCallingCode(state)) {
420
+ // `this.extractCallingCode()` is currently called when the number
421
+ // couldn't be formatted during the standard procedure.
422
+ // Normally, the national prefix would be re-extracted
423
+ // for an international number if such number couldn't be formatted,
424
+ // but since it's already not able to be formatted,
425
+ // there won't be yet another retry, so also extract national prefix here.
426
+ this.extractNationalSignificantNumber(state.getNationalDigits(), state.update);
427
+ }
428
+ }
379
429
  }]);
380
430
 
381
431
  return AsYouTypeParser;
@@ -455,21 +505,4 @@ function extractFormattedDigitsAndPlus(text) {
455
505
 
456
506
  return [formattedDigits, hasPlus];
457
507
  }
458
-
459
- function autoCorrectInternationalNumberWithoutPlus(digits, countryCode, callingCode, metadata) {
460
- // Google's AsYouType formatter supports sort of an "autocorrection" feature
461
- // when it "autocorrects" numbers that have been input for a country
462
- // with that country's calling code.
463
- // Such "autocorrection" feature looks weird, but different people have been requesting it:
464
- // https://github.com/catamphetamine/libphonenumber-js/issues/376
465
- // https://github.com/catamphetamine/libphonenumber-js/issues/375
466
- // https://github.com/catamphetamine/libphonenumber-js/issues/316
467
- var _extractCountryCallin2 = (0, _parse_.extractCountryCallingCodeFromInternationalNumberWithoutPlusSign)(digits, countryCode, callingCode, metadata.metadata),
468
- newCallingCode = _extractCountryCallin2.countryCallingCode,
469
- number = _extractCountryCallin2.number;
470
-
471
- if (newCallingCode) {
472
- return (0, _parse_.extractNationalNumber)(number, metadata);
473
- }
474
- }
475
508
  //# sourceMappingURL=AsYouTypeParser.js.map