libphonenumber-js 1.12.9 → 1.12.11

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 (569) hide show
  1. package/CODE_OF_CONDUCT.md +78 -78
  2. package/README.md +2 -3
  3. package/build/AsYouType.js +69 -131
  4. package/build/AsYouType.js.map +1 -1
  5. package/build/AsYouType.test.js +610 -553
  6. package/build/AsYouType.test.js.map +1 -1
  7. package/build/AsYouTypeFormatter.PatternMatcher.js +29 -77
  8. package/build/AsYouTypeFormatter.PatternMatcher.js.map +1 -1
  9. package/build/AsYouTypeFormatter.PatternMatcher.test.js +107 -109
  10. package/build/AsYouTypeFormatter.PatternMatcher.test.js.map +1 -1
  11. package/build/AsYouTypeFormatter.PatternParser.js +34 -67
  12. package/build/AsYouTypeFormatter.PatternParser.js.map +1 -1
  13. package/build/AsYouTypeFormatter.PatternParser.test.js +7 -9
  14. package/build/AsYouTypeFormatter.PatternParser.test.js.map +1 -1
  15. package/build/AsYouTypeFormatter.complete.js +18 -28
  16. package/build/AsYouTypeFormatter.complete.js.map +1 -1
  17. package/build/AsYouTypeFormatter.js +193 -233
  18. package/build/AsYouTypeFormatter.js.map +1 -1
  19. package/build/AsYouTypeFormatter.util.js +11 -38
  20. package/build/AsYouTypeFormatter.util.js.map +1 -1
  21. package/build/AsYouTypeFormatter.util.test.js +6 -7
  22. package/build/AsYouTypeFormatter.util.test.js.map +1 -1
  23. package/build/AsYouTypeParser.js +89 -143
  24. package/build/AsYouTypeParser.js.map +1 -1
  25. package/build/AsYouTypeState.js +13 -23
  26. package/build/AsYouTypeState.js.map +1 -1
  27. package/build/ParseError.js +22 -43
  28. package/build/ParseError.js.map +1 -1
  29. package/build/PhoneNumber.js +46 -85
  30. package/build/PhoneNumber.js.map +1 -1
  31. package/build/PhoneNumber.test.js +41 -33
  32. package/build/PhoneNumber.test.js.map +1 -1
  33. package/build/PhoneNumberMatcher.js +67 -101
  34. package/build/PhoneNumberMatcher.js.map +1 -1
  35. package/build/PhoneNumberMatcher.test.js +35 -18
  36. package/build/PhoneNumberMatcher.test.js.map +1 -1
  37. package/build/constants.js +17 -19
  38. package/build/constants.js.map +1 -1
  39. package/build/findNumbers/LRUCache.js +23 -34
  40. package/build/findNumbers/LRUCache.js.map +1 -1
  41. package/build/findNumbers/Leniency.js +58 -114
  42. package/build/findNumbers/Leniency.js.map +1 -1
  43. package/build/findNumbers/RegExpCache.js +9 -20
  44. package/build/findNumbers/RegExpCache.js.map +1 -1
  45. package/build/findNumbers/isValidCandidate.js +12 -19
  46. package/build/findNumbers/isValidCandidate.js.map +1 -1
  47. package/build/findNumbers/isValidPreCandidate.js +5 -7
  48. package/build/findNumbers/isValidPreCandidate.js.map +1 -1
  49. package/build/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js +9 -15
  50. package/build/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js.map +1 -1
  51. package/build/findNumbers/parsePreCandidate.js +0 -3
  52. package/build/findNumbers/parsePreCandidate.js.map +1 -1
  53. package/build/findNumbers/utf-8.js +9 -13
  54. package/build/findNumbers/utf-8.js.map +1 -1
  55. package/build/findNumbers/util.js +1 -8
  56. package/build/findNumbers/util.js.map +1 -1
  57. package/build/findNumbers/util.test.js +9 -15
  58. package/build/findNumbers/util.test.js.map +1 -1
  59. package/build/findPhoneNumbersInText.js +10 -17
  60. package/build/findPhoneNumbersInText.js.map +1 -1
  61. package/build/findPhoneNumbersInText.test.js +100 -93
  62. package/build/findPhoneNumbersInText.test.js.map +1 -1
  63. package/build/format.js +31 -64
  64. package/build/format.js.map +1 -1
  65. package/build/format.test.js +133 -119
  66. package/build/format.test.js.map +1 -1
  67. package/build/formatIncompletePhoneNumber.js +1 -5
  68. package/build/formatIncompletePhoneNumber.js.map +1 -1
  69. package/build/formatIncompletePhoneNumber.test.js +14 -13
  70. package/build/formatIncompletePhoneNumber.test.js.map +1 -1
  71. package/build/formatPhoneNumberForMobileDialing.js +32 -32
  72. package/build/formatPhoneNumberForMobileDialing.js.map +1 -1
  73. package/build/getCountries.js +1 -4
  74. package/build/getCountries.js.map +1 -1
  75. package/build/getCountries.test.js +2 -5
  76. package/build/getCountries.test.js.map +1 -1
  77. package/build/getCountryCallingCode.js +0 -1
  78. package/build/getCountryCallingCode.js.map +1 -1
  79. package/build/getCountryCallingCode.test.js +2 -5
  80. package/build/getCountryCallingCode.test.js.map +1 -1
  81. package/build/getExampleNumber.js +1 -4
  82. package/build/getExampleNumber.js.map +1 -1
  83. package/build/getExampleNumber.test.js +5 -9
  84. package/build/getExampleNumber.test.js.map +1 -1
  85. package/build/helpers/RFC3966.js +16 -38
  86. package/build/helpers/RFC3966.js.map +1 -1
  87. package/build/helpers/RFC3966.test.js +16 -14
  88. package/build/helpers/RFC3966.test.js.map +1 -1
  89. package/build/helpers/applyInternationalSeparatorStyle.js +0 -2
  90. package/build/helpers/applyInternationalSeparatorStyle.js.map +1 -1
  91. package/build/helpers/applyInternationalSeparatorStyle.test.js +3 -5
  92. package/build/helpers/applyInternationalSeparatorStyle.test.js.map +1 -1
  93. package/build/helpers/checkNumberLength.js +18 -22
  94. package/build/helpers/checkNumberLength.js.map +1 -1
  95. package/build/helpers/checkNumberLength.test.js +19 -27
  96. package/build/helpers/checkNumberLength.test.js.map +1 -1
  97. package/build/helpers/extension/createExtensionPattern.js +19 -35
  98. package/build/helpers/extension/createExtensionPattern.js.map +1 -1
  99. package/build/helpers/extension/extractExtension.js +6 -12
  100. package/build/helpers/extension/extractExtension.js.map +1 -1
  101. package/build/helpers/extractCountryCallingCode.js +14 -24
  102. package/build/helpers/extractCountryCallingCode.js.map +1 -1
  103. package/build/helpers/extractCountryCallingCode.test.js +4 -7
  104. package/build/helpers/extractCountryCallingCode.test.js.map +1 -1
  105. package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +4 -16
  106. package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -1
  107. package/build/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js +16 -29
  108. package/build/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js.map +1 -1
  109. package/build/helpers/extractNationalNumber.js +10 -21
  110. package/build/helpers/extractNationalNumber.js.map +1 -1
  111. package/build/helpers/extractNationalNumber.test.js +2 -8
  112. package/build/helpers/extractNationalNumber.test.js.map +1 -1
  113. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +12 -18
  114. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -1
  115. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +2 -6
  116. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js.map +1 -1
  117. package/build/helpers/extractPhoneContext.js +19 -28
  118. package/build/helpers/extractPhoneContext.js.map +1 -1
  119. package/build/helpers/extractPhoneContext.test.js +12 -15
  120. package/build/helpers/extractPhoneContext.test.js.map +1 -1
  121. package/build/helpers/formatNationalNumberUsingFormat.js +7 -13
  122. package/build/helpers/formatNationalNumberUsingFormat.js.map +1 -1
  123. package/build/helpers/getCountryByCallingCode.js +5 -14
  124. package/build/helpers/getCountryByCallingCode.js.map +1 -1
  125. package/build/helpers/getCountryByNationalNumber.js +18 -20
  126. package/build/helpers/getCountryByNationalNumber.js.map +1 -1
  127. package/build/helpers/getIddPrefix.js +4 -8
  128. package/build/helpers/getIddPrefix.js.map +1 -1
  129. package/build/helpers/getNumberType.js +23 -35
  130. package/build/helpers/getNumberType.js.map +1 -1
  131. package/build/helpers/getNumberType.test.js +4 -8
  132. package/build/helpers/getNumberType.test.js.map +1 -1
  133. package/build/helpers/getPossibleCountriesForNumber.js +1 -11
  134. package/build/helpers/getPossibleCountriesForNumber.js.map +1 -1
  135. package/build/helpers/isObject.js +0 -1
  136. package/build/helpers/isObject.js.map +1 -1
  137. package/build/helpers/isViablePhoneNumber.js +19 -19
  138. package/build/helpers/isViablePhoneNumber.js.map +1 -1
  139. package/build/helpers/matchesEntirely.js +0 -1
  140. package/build/helpers/matchesEntirely.js.map +1 -1
  141. package/build/helpers/matchesEntirely.test.js +4 -5
  142. package/build/helpers/matchesEntirely.test.js.map +1 -1
  143. package/build/helpers/mergeArrays.js +6 -11
  144. package/build/helpers/mergeArrays.js.map +1 -1
  145. package/build/helpers/mergeArrays.test.js +2 -4
  146. package/build/helpers/mergeArrays.test.js.map +1 -1
  147. package/build/helpers/parseDigits.js +7 -17
  148. package/build/helpers/parseDigits.js.map +1 -1
  149. package/build/helpers/parseDigits.test.js +2 -4
  150. package/build/helpers/parseDigits.test.js.map +1 -1
  151. package/build/helpers/stripIddPrefix.js +7 -17
  152. package/build/helpers/stripIddPrefix.js.map +1 -1
  153. package/build/helpers/stripIddPrefix.test.js +4 -7
  154. package/build/helpers/stripIddPrefix.test.js.map +1 -1
  155. package/build/isPossible.js +3 -15
  156. package/build/isPossible.js.map +1 -1
  157. package/build/isPossible.test.js +34 -41
  158. package/build/isPossible.test.js.map +1 -1
  159. package/build/isPossiblePhoneNumber.js +10 -15
  160. package/build/isPossiblePhoneNumber.js.map +1 -1
  161. package/build/isPossiblePhoneNumber.test.js +11 -17
  162. package/build/isPossiblePhoneNumber.test.js.map +1 -1
  163. package/build/isValid.js +7 -11
  164. package/build/isValid.js.map +1 -1
  165. package/build/isValid.test.js +59 -58
  166. package/build/isValid.test.js.map +1 -1
  167. package/build/isValidPhoneNumber.js +10 -15
  168. package/build/isValidPhoneNumber.js.map +1 -1
  169. package/build/isValidPhoneNumber.test.js +10 -15
  170. package/build/isValidPhoneNumber.test.js.map +1 -1
  171. package/build/legacy/findNumbers.js +4 -11
  172. package/build/legacy/findNumbers.js.map +1 -1
  173. package/build/legacy/findNumbers.test.js +77 -63
  174. package/build/legacy/findNumbers.test.js.map +1 -1
  175. package/build/legacy/findPhoneNumbers.js +11 -21
  176. package/build/legacy/findPhoneNumbers.js.map +1 -1
  177. package/build/legacy/findPhoneNumbers.test.js +75 -72
  178. package/build/legacy/findPhoneNumbers.test.js.map +1 -1
  179. package/build/legacy/findPhoneNumbersInitialImplementation.js +34 -62
  180. package/build/legacy/findPhoneNumbersInitialImplementation.js.map +1 -1
  181. package/build/legacy/format.js +28 -44
  182. package/build/legacy/format.js.map +1 -1
  183. package/build/legacy/format.test.js +119 -103
  184. package/build/legacy/format.test.js.map +1 -1
  185. package/build/legacy/getNumberType.js +30 -44
  186. package/build/legacy/getNumberType.js.map +1 -1
  187. package/build/legacy/getNumberType.test.js +31 -34
  188. package/build/legacy/getNumberType.test.js.map +1 -1
  189. package/build/legacy/isPossibleNumber.js +5 -11
  190. package/build/legacy/isPossibleNumber.js.map +1 -1
  191. package/build/legacy/isPossibleNumber.test.js +22 -25
  192. package/build/legacy/isPossibleNumber.test.js.map +1 -1
  193. package/build/legacy/isValidNumber.js +5 -11
  194. package/build/legacy/isValidNumber.js.map +1 -1
  195. package/build/legacy/isValidNumber.test.js +41 -39
  196. package/build/legacy/isValidNumber.test.js.map +1 -1
  197. package/build/legacy/isValidNumberForRegion.js +4 -12
  198. package/build/legacy/isValidNumberForRegion.js.map +1 -1
  199. package/build/legacy/isValidNumberForRegion.test.js +6 -11
  200. package/build/legacy/isValidNumberForRegion.test.js.map +1 -1
  201. package/build/legacy/isValidNumberForRegion_.js +1 -4
  202. package/build/legacy/isValidNumberForRegion_.js.map +1 -1
  203. package/build/legacy/parse.js +4 -9
  204. package/build/legacy/parse.js.map +1 -1
  205. package/build/legacy/parse.test.js +233 -194
  206. package/build/legacy/parse.test.js.map +1 -1
  207. package/build/legacy/searchNumbers.js +8 -12
  208. package/build/legacy/searchNumbers.js.map +1 -1
  209. package/build/legacy/searchNumbers.test.js +6 -14
  210. package/build/legacy/searchNumbers.test.js.map +1 -1
  211. package/build/metadata.js +85 -122
  212. package/build/metadata.js.map +1 -1
  213. package/build/metadata.test.js +54 -80
  214. package/build/metadata.test.js.map +1 -1
  215. package/build/normalizeArguments.js +25 -35
  216. package/build/normalizeArguments.js.map +1 -1
  217. package/build/parse.js +66 -116
  218. package/build/parse.js.map +1 -1
  219. package/build/parse.test.js +244 -206
  220. package/build/parse.test.js.map +1 -1
  221. package/build/parseIncompletePhoneNumber.js +8 -18
  222. package/build/parseIncompletePhoneNumber.js.map +1 -1
  223. package/build/parseIncompletePhoneNumber.test.js +24 -25
  224. package/build/parseIncompletePhoneNumber.test.js.map +1 -1
  225. package/build/parsePhoneNumber.js +4 -9
  226. package/build/parsePhoneNumber.js.map +1 -1
  227. package/build/parsePhoneNumber.test.js +14 -25
  228. package/build/parsePhoneNumber.test.js.map +1 -1
  229. package/build/parsePhoneNumberWithError.js +4 -9
  230. package/build/parsePhoneNumberWithError.js.map +1 -1
  231. package/build/parsePhoneNumberWithError.test.js +31 -35
  232. package/build/parsePhoneNumberWithError.test.js.map +1 -1
  233. package/build/parsePhoneNumberWithError_.js +7 -10
  234. package/build/parsePhoneNumberWithError_.js.map +1 -1
  235. package/build/parsePhoneNumber_.js +11 -16
  236. package/build/parsePhoneNumber_.js.map +1 -1
  237. package/build/searchPhoneNumbersInText.js +10 -16
  238. package/build/searchPhoneNumbersInText.js.map +1 -1
  239. package/build/searchPhoneNumbersInText.test.js +11 -21
  240. package/build/searchPhoneNumbersInText.test.js.map +1 -1
  241. package/build/tools/semver-compare.js +0 -4
  242. package/build/tools/semver-compare.js.map +1 -1
  243. package/build/tools/semver-compare.test.js +2 -4
  244. package/build/tools/semver-compare.test.js.map +1 -1
  245. package/build/validatePhoneNumberLength.js +12 -20
  246. package/build/validatePhoneNumberLength.js.map +1 -1
  247. package/build/validatePhoneNumberLength.test.js +14 -16
  248. package/build/validatePhoneNumberLength.test.js.map +1 -1
  249. package/bundle/libphonenumber-js.min.js +1 -1
  250. package/bundle/libphonenumber-js.min.js.map +1 -1
  251. package/bundle/libphonenumber-max.js +1 -1
  252. package/bundle/libphonenumber-max.js.map +1 -1
  253. package/bundle/libphonenumber-min.js +1 -1
  254. package/bundle/libphonenumber-min.js.map +1 -1
  255. package/bundle/libphonenumber-mobile.js +1 -1
  256. package/bundle/libphonenumber-mobile.js.map +1 -1
  257. package/es6/AsYouType.js +66 -112
  258. package/es6/AsYouType.js.map +1 -1
  259. package/es6/AsYouType.test.js +610 -551
  260. package/es6/AsYouType.test.js.map +1 -1
  261. package/es6/AsYouTypeFormatter.PatternMatcher.js +27 -72
  262. package/es6/AsYouTypeFormatter.PatternMatcher.js.map +1 -1
  263. package/es6/AsYouTypeFormatter.PatternMatcher.test.js +106 -106
  264. package/es6/AsYouTypeFormatter.PatternMatcher.test.js.map +1 -1
  265. package/es6/AsYouTypeFormatter.PatternParser.js +33 -64
  266. package/es6/AsYouTypeFormatter.PatternParser.js.map +1 -1
  267. package/es6/AsYouTypeFormatter.PatternParser.test.js +6 -6
  268. package/es6/AsYouTypeFormatter.PatternParser.test.js.map +1 -1
  269. package/es6/AsYouTypeFormatter.complete.js +17 -21
  270. package/es6/AsYouTypeFormatter.complete.js.map +1 -1
  271. package/es6/AsYouTypeFormatter.js +193 -217
  272. package/es6/AsYouTypeFormatter.js.map +1 -1
  273. package/es6/AsYouTypeFormatter.util.js +10 -30
  274. package/es6/AsYouTypeFormatter.util.js.map +1 -1
  275. package/es6/AsYouTypeFormatter.util.test.js +6 -6
  276. package/es6/AsYouTypeFormatter.util.test.js.map +1 -1
  277. package/es6/AsYouTypeParser.js +87 -132
  278. package/es6/AsYouTypeParser.js.map +1 -1
  279. package/es6/AsYouTypeState.js +12 -20
  280. package/es6/AsYouTypeState.js.map +1 -1
  281. package/es6/ParseError.js +21 -40
  282. package/es6/ParseError.js.map +1 -1
  283. package/es6/PhoneNumber.js +45 -68
  284. package/es6/PhoneNumber.js.map +1 -1
  285. package/es6/PhoneNumber.test.js +41 -30
  286. package/es6/PhoneNumber.test.js.map +1 -1
  287. package/es6/PhoneNumberMatcher.js +61 -78
  288. package/es6/PhoneNumberMatcher.js.map +1 -1
  289. package/es6/PhoneNumberMatcher.test.js +35 -16
  290. package/es6/PhoneNumberMatcher.test.js.map +1 -1
  291. package/es6/constants.js +15 -9
  292. package/es6/constants.js.map +1 -1
  293. package/es6/findNumbers/LRUCache.js +22 -31
  294. package/es6/findNumbers/LRUCache.js.map +1 -1
  295. package/es6/findNumbers/Leniency.js +57 -103
  296. package/es6/findNumbers/Leniency.js.map +1 -1
  297. package/es6/findNumbers/RegExpCache.js +10 -16
  298. package/es6/findNumbers/RegExpCache.js.map +1 -1
  299. package/es6/findNumbers/isValidCandidate.js +12 -13
  300. package/es6/findNumbers/isValidCandidate.js.map +1 -1
  301. package/es6/findNumbers/isValidPreCandidate.js +5 -6
  302. package/es6/findNumbers/isValidPreCandidate.js.map +1 -1
  303. package/es6/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js +9 -12
  304. package/es6/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js.map +1 -1
  305. package/es6/findNumbers/parsePreCandidate.js +3 -2
  306. package/es6/findNumbers/parsePreCandidate.js.map +1 -1
  307. package/es6/findNumbers/utf-8.js +5 -3
  308. package/es6/findNumbers/utf-8.js.map +1 -1
  309. package/es6/findNumbers/util.js +1 -4
  310. package/es6/findNumbers/util.js.map +1 -1
  311. package/es6/findNumbers/util.test.js +9 -14
  312. package/es6/findNumbers/util.test.js.map +1 -1
  313. package/es6/findPhoneNumbersInText.js +9 -12
  314. package/es6/findPhoneNumbersInText.js.map +1 -1
  315. package/es6/findPhoneNumbersInText.test.js +101 -91
  316. package/es6/findPhoneNumbersInText.test.js.map +1 -1
  317. package/es6/format.js +27 -50
  318. package/es6/format.js.map +1 -1
  319. package/es6/format.test.js +133 -116
  320. package/es6/format.test.js.map +1 -1
  321. package/es6/formatIncompletePhoneNumber.js +1 -2
  322. package/es6/formatIncompletePhoneNumber.js.map +1 -1
  323. package/es6/formatIncompletePhoneNumber.test.js +14 -10
  324. package/es6/formatIncompletePhoneNumber.test.js.map +1 -1
  325. package/es6/formatPhoneNumberForMobileDialing.js +31 -24
  326. package/es6/formatPhoneNumberForMobileDialing.js.map +1 -1
  327. package/es6/getCountries.js.map +1 -1
  328. package/es6/getCountries.test.js +2 -2
  329. package/es6/getCountries.test.js.map +1 -1
  330. package/es6/getCountryCallingCode.js.map +1 -1
  331. package/es6/getCountryCallingCode.test.js +2 -2
  332. package/es6/getCountryCallingCode.test.js.map +1 -1
  333. package/es6/getExampleNumber.js.map +1 -1
  334. package/es6/getExampleNumber.test.js +6 -6
  335. package/es6/getExampleNumber.test.js.map +1 -1
  336. package/es6/helpers/RFC3966.js +17 -34
  337. package/es6/helpers/RFC3966.js.map +1 -1
  338. package/es6/helpers/RFC3966.test.js +16 -13
  339. package/es6/helpers/RFC3966.test.js.map +1 -1
  340. package/es6/helpers/applyInternationalSeparatorStyle.js +3 -2
  341. package/es6/helpers/applyInternationalSeparatorStyle.js.map +1 -1
  342. package/es6/helpers/applyInternationalSeparatorStyle.test.js +2 -2
  343. package/es6/helpers/applyInternationalSeparatorStyle.test.js.map +1 -1
  344. package/es6/helpers/checkNumberLength.js +17 -17
  345. package/es6/helpers/checkNumberLength.js.map +1 -1
  346. package/es6/helpers/checkNumberLength.test.js +20 -23
  347. package/es6/helpers/checkNumberLength.test.js.map +1 -1
  348. package/es6/helpers/extension/createExtensionPattern.js +21 -34
  349. package/es6/helpers/extension/createExtensionPattern.js.map +1 -1
  350. package/es6/helpers/extension/extractExtension.js +7 -9
  351. package/es6/helpers/extension/extractExtension.js.map +1 -1
  352. package/es6/helpers/extractCountryCallingCode.js +14 -18
  353. package/es6/helpers/extractCountryCallingCode.js.map +1 -1
  354. package/es6/helpers/extractCountryCallingCode.test.js +4 -4
  355. package/es6/helpers/extractCountryCallingCode.test.js.map +1 -1
  356. package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +4 -9
  357. package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -1
  358. package/es6/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js +14 -19
  359. package/es6/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js.map +1 -1
  360. package/es6/helpers/extractNationalNumber.js +10 -15
  361. package/es6/helpers/extractNationalNumber.js.map +1 -1
  362. package/es6/helpers/extractNationalNumber.test.js +2 -4
  363. package/es6/helpers/extractNationalNumber.test.js.map +1 -1
  364. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +12 -17
  365. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -1
  366. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +2 -2
  367. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js.map +1 -1
  368. package/es6/helpers/extractPhoneContext.js +17 -17
  369. package/es6/helpers/extractPhoneContext.js.map +1 -1
  370. package/es6/helpers/extractPhoneContext.test.js +12 -12
  371. package/es6/helpers/extractPhoneContext.test.js.map +1 -1
  372. package/es6/helpers/formatNationalNumberUsingFormat.js +8 -8
  373. package/es6/helpers/formatNationalNumberUsingFormat.js.map +1 -1
  374. package/es6/helpers/getCountryByCallingCode.js +4 -9
  375. package/es6/helpers/getCountryByCallingCode.js.map +1 -1
  376. package/es6/helpers/getCountryByNationalNumber.js +17 -15
  377. package/es6/helpers/getCountryByNationalNumber.js.map +1 -1
  378. package/es6/helpers/getIddPrefix.js +3 -4
  379. package/es6/helpers/getIddPrefix.js.map +1 -1
  380. package/es6/helpers/getNumberType.js +22 -29
  381. package/es6/helpers/getNumberType.js.map +1 -1
  382. package/es6/helpers/getNumberType.test.js +4 -4
  383. package/es6/helpers/getNumberType.test.js.map +1 -1
  384. package/es6/helpers/getPossibleCountriesForNumber.js +1 -8
  385. package/es6/helpers/getPossibleCountriesForNumber.js.map +1 -1
  386. package/es6/helpers/isObject.js.map +1 -1
  387. package/es6/helpers/isViablePhoneNumber.js +21 -13
  388. package/es6/helpers/isViablePhoneNumber.js.map +1 -1
  389. package/es6/helpers/matchesEntirely.js.map +1 -1
  390. package/es6/helpers/matchesEntirely.test.js +3 -2
  391. package/es6/helpers/matchesEntirely.test.js.map +1 -1
  392. package/es6/helpers/mergeArrays.js +6 -10
  393. package/es6/helpers/mergeArrays.js.map +1 -1
  394. package/es6/helpers/mergeArrays.test.js +1 -1
  395. package/es6/helpers/mergeArrays.test.js.map +1 -1
  396. package/es6/helpers/parseDigits.js +6 -12
  397. package/es6/helpers/parseDigits.js.map +1 -1
  398. package/es6/helpers/parseDigits.test.js +1 -1
  399. package/es6/helpers/parseDigits.test.js.map +1 -1
  400. package/es6/helpers/stripIddPrefix.js +6 -11
  401. package/es6/helpers/stripIddPrefix.js.map +1 -1
  402. package/es6/helpers/stripIddPrefix.test.js +4 -4
  403. package/es6/helpers/stripIddPrefix.test.js.map +1 -1
  404. package/es6/isPossible.js +3 -10
  405. package/es6/isPossible.js.map +1 -1
  406. package/es6/isPossible.test.js +34 -38
  407. package/es6/isPossible.test.js.map +1 -1
  408. package/es6/isPossiblePhoneNumber.js +9 -10
  409. package/es6/isPossiblePhoneNumber.js.map +1 -1
  410. package/es6/isPossiblePhoneNumber.test.js +12 -16
  411. package/es6/isPossiblePhoneNumber.test.js.map +1 -1
  412. package/es6/isValid.js +7 -6
  413. package/es6/isValid.js.map +1 -1
  414. package/es6/isValid.test.js +59 -55
  415. package/es6/isValid.test.js.map +1 -1
  416. package/es6/isValidPhoneNumber.js +9 -10
  417. package/es6/isValidPhoneNumber.js.map +1 -1
  418. package/es6/isValidPhoneNumber.test.js +10 -13
  419. package/es6/isValidPhoneNumber.test.js.map +1 -1
  420. package/es6/legacy/findNumbers.js +3 -6
  421. package/es6/legacy/findNumbers.js.map +1 -1
  422. package/es6/legacy/findNumbers.test.js +77 -60
  423. package/es6/legacy/findNumbers.test.js.map +1 -1
  424. package/es6/legacy/findPhoneNumbers.js +8 -9
  425. package/es6/legacy/findPhoneNumbers.js.map +1 -1
  426. package/es6/legacy/findPhoneNumbers.test.js +73 -62
  427. package/es6/legacy/findPhoneNumbers.test.js.map +1 -1
  428. package/es6/legacy/findPhoneNumbersInitialImplementation.js +32 -45
  429. package/es6/legacy/findPhoneNumbersInitialImplementation.js.map +1 -1
  430. package/es6/legacy/format.js +27 -37
  431. package/es6/legacy/format.js.map +1 -1
  432. package/es6/legacy/format.test.js +119 -101
  433. package/es6/legacy/format.test.js.map +1 -1
  434. package/es6/legacy/getNumberType.js +31 -37
  435. package/es6/legacy/getNumberType.js.map +1 -1
  436. package/es6/legacy/getNumberType.test.js +31 -31
  437. package/es6/legacy/getNumberType.test.js.map +1 -1
  438. package/es6/legacy/isPossibleNumber.js +5 -7
  439. package/es6/legacy/isPossibleNumber.js.map +1 -1
  440. package/es6/legacy/isPossibleNumber.test.js +22 -23
  441. package/es6/legacy/isPossibleNumber.test.js.map +1 -1
  442. package/es6/legacy/isValidNumber.js +6 -7
  443. package/es6/legacy/isValidNumber.js.map +1 -1
  444. package/es6/legacy/isValidNumber.test.js +41 -37
  445. package/es6/legacy/isValidNumber.test.js.map +1 -1
  446. package/es6/legacy/isValidNumberForRegion.js +5 -7
  447. package/es6/legacy/isValidNumberForRegion.js.map +1 -1
  448. package/es6/legacy/isValidNumberForRegion.test.js +6 -8
  449. package/es6/legacy/isValidNumberForRegion.test.js.map +1 -1
  450. package/es6/legacy/isValidNumberForRegion_.js +1 -1
  451. package/es6/legacy/isValidNumberForRegion_.js.map +1 -1
  452. package/es6/legacy/parse.js +3 -4
  453. package/es6/legacy/parse.js.map +1 -1
  454. package/es6/legacy/parse.test.js +233 -191
  455. package/es6/legacy/parse.test.js.map +1 -1
  456. package/es6/legacy/searchNumbers.js +8 -8
  457. package/es6/legacy/searchNumbers.js.map +1 -1
  458. package/es6/legacy/searchNumbers.test.js +6 -11
  459. package/es6/legacy/searchNumbers.test.js.map +1 -1
  460. package/es6/metadata.js +86 -114
  461. package/es6/metadata.js.map +1 -1
  462. package/es6/metadata.test.js +57 -73
  463. package/es6/metadata.test.js.map +1 -1
  464. package/es6/normalizeArguments.js +26 -32
  465. package/es6/normalizeArguments.js.map +1 -1
  466. package/es6/parse.js +66 -94
  467. package/es6/parse.js.map +1 -1
  468. package/es6/parse.test.js +244 -203
  469. package/es6/parse.test.js.map +1 -1
  470. package/es6/parseIncompletePhoneNumber.js +9 -16
  471. package/es6/parseIncompletePhoneNumber.js.map +1 -1
  472. package/es6/parseIncompletePhoneNumber.test.js +22 -18
  473. package/es6/parseIncompletePhoneNumber.test.js.map +1 -1
  474. package/es6/parsePhoneNumber.js +3 -4
  475. package/es6/parsePhoneNumber.js.map +1 -1
  476. package/es6/parsePhoneNumber.test.js +14 -23
  477. package/es6/parsePhoneNumber.test.js.map +1 -1
  478. package/es6/parsePhoneNumberWithError.js +3 -4
  479. package/es6/parsePhoneNumberWithError.js.map +1 -1
  480. package/es6/parsePhoneNumberWithError.test.js +32 -33
  481. package/es6/parsePhoneNumberWithError.test.js.map +1 -1
  482. package/es6/parsePhoneNumberWithError_.js +6 -6
  483. package/es6/parsePhoneNumberWithError_.js.map +1 -1
  484. package/es6/parsePhoneNumber_.js +10 -10
  485. package/es6/parsePhoneNumber_.js.map +1 -1
  486. package/es6/searchPhoneNumbersInText.js +9 -11
  487. package/es6/searchPhoneNumbersInText.js.map +1 -1
  488. package/es6/searchPhoneNumbersInText.test.js +11 -18
  489. package/es6/searchPhoneNumbersInText.test.js.map +1 -1
  490. package/es6/tools/semver-compare.js +0 -3
  491. package/es6/tools/semver-compare.js.map +1 -1
  492. package/es6/tools/semver-compare.test.js +1 -1
  493. package/es6/tools/semver-compare.test.js.map +1 -1
  494. package/es6/validatePhoneNumberLength.js +11 -12
  495. package/es6/validatePhoneNumberLength.js.map +1 -1
  496. package/es6/validatePhoneNumberLength.test.js +14 -14
  497. package/es6/validatePhoneNumberLength.test.js.map +1 -1
  498. package/jest.config.json +26 -0
  499. package/metadata.full.json +1 -1
  500. package/metadata.full.json.js +1 -1
  501. package/metadata.max.json +1 -1
  502. package/metadata.max.json.js +1 -1
  503. package/metadata.min.json +1 -1
  504. package/metadata.min.json.js +1 -1
  505. package/metadata.mobile.json +1 -1
  506. package/metadata.mobile.json.js +1 -1
  507. package/package.json +36 -26
  508. package/rollup.config.mjs +2 -2
  509. package/runnable/generate-country-codes.js +1 -1
  510. package/source/AsYouType.test.js +414 -414
  511. package/source/AsYouTypeFormatter.PatternMatcher.test.js +91 -91
  512. package/source/AsYouTypeFormatter.PatternParser.test.js +6 -6
  513. package/source/AsYouTypeFormatter.util.test.js +6 -6
  514. package/source/PhoneNumber.js +13 -15
  515. package/source/PhoneNumber.test.js +36 -29
  516. package/source/PhoneNumberMatcher.js +8 -9
  517. package/source/PhoneNumberMatcher.test.js +18 -6
  518. package/source/findNumbers/Leniency.js +0 -1
  519. package/source/findNumbers/util.test.js +14 -19
  520. package/source/findPhoneNumbersInText.test.js +98 -53
  521. package/source/format.test.js +70 -65
  522. package/source/formatIncompletePhoneNumber.test.js +11 -7
  523. package/source/formatPhoneNumberForMobileDialing.js +16 -1
  524. package/source/getCountries.test.js +2 -2
  525. package/source/getCountryCallingCode.test.js +2 -2
  526. package/source/getExampleNumber.test.js +6 -6
  527. package/source/helpers/RFC3966.test.js +8 -8
  528. package/source/helpers/applyInternationalSeparatorStyle.test.js +2 -2
  529. package/source/helpers/checkNumberLength.test.js +11 -11
  530. package/source/helpers/extractCountryCallingCode.test.js +4 -4
  531. package/source/helpers/extractNationalNumber.test.js +2 -2
  532. package/source/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +2 -2
  533. package/source/helpers/extractPhoneContext.test.js +1 -1
  534. package/source/helpers/getNumberType.test.js +4 -4
  535. package/source/helpers/matchesEntirely.test.js +2 -2
  536. package/source/helpers/mergeArrays.test.js +1 -1
  537. package/source/helpers/parseDigits.test.js +1 -1
  538. package/source/helpers/stripIddPrefix.test.js +4 -4
  539. package/source/isPossible.test.js +16 -10
  540. package/source/isPossiblePhoneNumber.test.js +12 -13
  541. package/source/isValid.test.js +20 -20
  542. package/source/isValidPhoneNumber.test.js +9 -9
  543. package/source/legacy/findNumbers.test.js +57 -44
  544. package/source/legacy/findPhoneNumbers.test.js +51 -35
  545. package/source/legacy/format.test.js +74 -71
  546. package/source/legacy/getNumberType.test.js +20 -18
  547. package/source/legacy/isPossibleNumber.test.js +16 -10
  548. package/source/legacy/isValidNumber.test.js +25 -23
  549. package/source/legacy/isValidNumberForRegion.test.js +5 -5
  550. package/source/legacy/parse.test.js +114 -117
  551. package/source/legacy/searchNumbers.test.js +3 -3
  552. package/source/metadata.test.js +61 -49
  553. package/source/parse.test.js +116 -119
  554. package/source/parseIncompletePhoneNumber.test.js +13 -13
  555. package/source/parsePhoneNumber.test.js +14 -14
  556. package/source/parsePhoneNumberWithError.test.js +26 -26
  557. package/source/searchPhoneNumbersInText.test.js +8 -8
  558. package/source/tools/semver-compare.test.js +1 -1
  559. package/source/validatePhoneNumberLength.test.js +10 -10
  560. package/build/findNumbers/Leniency.test.js +0 -37
  561. package/build/findNumbers/Leniency.test.js.map +0 -1
  562. package/build/formatPhoneNumberForMobileDialing.test.js +0 -15
  563. package/build/formatPhoneNumberForMobileDialing.test.js.map +0 -1
  564. package/es6/findNumbers/Leniency.test.js +0 -36
  565. package/es6/findNumbers/Leniency.test.js.map +0 -1
  566. package/es6/formatPhoneNumberForMobileDialing.test.js +0 -14
  567. package/es6/formatPhoneNumberForMobileDialing.test.js.map +0 -1
  568. package/source/findNumbers/Leniency.test.js +0 -35
  569. package/source/formatPhoneNumberForMobileDialing.test.js +0 -16
@@ -1,15 +1,12 @@
1
- function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
2
-
3
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
-
5
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
6
-
7
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
-
9
- 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); } }
10
-
11
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
12
-
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _createForOfIteratorHelperLoose(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (t) return (t = t.call(r)).next.bind(t); if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var o = 0; return function () { return o >= r.length ? { done: !0 } : { done: !1, value: r[o++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
4
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
5
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
6
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
7
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
8
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
9
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
10
  import { DIGIT_PLACEHOLDER, countOccurences, repeat, cutAndStripNonPairedParens, closeNonPairedParens, stripNonPairedParens, populateTemplateWithDigits } from './AsYouTypeFormatter.util.js';
14
11
  import formatCompleteNumber, { canFormatCompleteNumber } from './AsYouTypeFormatter.complete.js';
15
12
  import PatternMatcher from './AsYouTypeFormatter.PatternMatcher.js';
@@ -17,39 +14,45 @@ import parseDigits from './helpers/parseDigits.js';
17
14
  export { DIGIT_PLACEHOLDER } from './AsYouTypeFormatter.util.js';
18
15
  import { FIRST_GROUP_PATTERN } from './helpers/formatNationalNumberUsingFormat.js';
19
16
  import { VALID_PUNCTUATION } from './constants.js';
20
- import applyInternationalSeparatorStyle from './helpers/applyInternationalSeparatorStyle.js'; // Used in phone number format template creation.
21
- // Could be any digit, I guess.
17
+ import applyInternationalSeparatorStyle from './helpers/applyInternationalSeparatorStyle.js';
22
18
 
23
- var DUMMY_DIGIT = '9'; // I don't know why is it exactly `15`
24
-
25
- var LONGEST_NATIONAL_PHONE_NUMBER_LENGTH = 15; // Create a phone number consisting only of the digit 9 that matches the
19
+ // Used in phone number format template creation.
20
+ // Could be any digit, I guess.
21
+ var DUMMY_DIGIT = '9';
22
+ // I don't know why is it exactly `15`
23
+ var LONGEST_NATIONAL_PHONE_NUMBER_LENGTH = 15;
24
+ // Create a phone number consisting only of the digit 9 that matches the
26
25
  // `number_pattern` by applying the pattern to the "longest phone number" string.
26
+ var LONGEST_DUMMY_PHONE_NUMBER = repeat(DUMMY_DIGIT, LONGEST_NATIONAL_PHONE_NUMBER_LENGTH);
27
27
 
28
- var LONGEST_DUMMY_PHONE_NUMBER = repeat(DUMMY_DIGIT, LONGEST_NATIONAL_PHONE_NUMBER_LENGTH); // A set of characters that, if found in a national prefix formatting rules, are an indicator to
28
+ // A set of characters that, if found in a national prefix formatting rules, are an indicator to
29
29
  // us that we should separate the national prefix from the number when formatting.
30
+ var NATIONAL_PREFIX_SEPARATORS_PATTERN = /[- ]/;
30
31
 
31
- var NATIONAL_PREFIX_SEPARATORS_PATTERN = /[- ]/; // Deprecated: Google has removed some formatting pattern related code from their repo.
32
+ // Deprecated: Google has removed some formatting pattern related code from their repo.
32
33
  // https://github.com/googlei18n/libphonenumber/commit/a395b4fef3caf57c4bc5f082e1152a4d2bd0ba4c
33
34
  // "We no longer have numbers in formatting matching patterns, only \d."
34
35
  // Because this library supports generating custom metadata
35
36
  // some users may still be using old metadata so the relevant
36
37
  // code seems to stay until some next major version update.
38
+ var SUPPORT_LEGACY_FORMATTING_PATTERNS = true;
37
39
 
38
- var SUPPORT_LEGACY_FORMATTING_PATTERNS = true; // A pattern that is used to match character classes in regular expressions.
40
+ // A pattern that is used to match character classes in regular expressions.
39
41
  // An example of a character class is "[1-4]".
40
-
41
42
  var CREATE_CHARACTER_CLASS_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && function () {
42
43
  return /\[([^\[\]])*\]/g;
43
- }; // Any digit in a regular expression that actually denotes a digit. For
44
+ };
45
+
46
+ // Any digit in a regular expression that actually denotes a digit. For
44
47
  // example, in the regular expression "80[0-2]\d{6,10}", the first 2 digits
45
48
  // (8 and 0) are standalone digits, but the rest are not.
46
49
  // Two look-aheads are needed because the number following \\d could be a
47
50
  // two-digit number, since the phone number can be as long as 15 digits.
48
-
49
-
50
51
  var CREATE_STANDALONE_DIGIT_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && function () {
51
52
  return /\d(?=[^,}][^,}])/g;
52
- }; // A regular expression that is used to determine if a `format` is
53
+ };
54
+
55
+ // A regular expression that is used to determine if a `format` is
53
56
  // suitable to be used in the "as you type formatter".
54
57
  // A `format` is suitable when the resulting formatted number has
55
58
  // the same digits as the user has entered.
@@ -83,29 +86,25 @@ var CREATE_STANDALONE_DIGIT_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && func
83
86
  // This regular expression is called `ELIGIBLE_FORMAT_PATTERN` in Google's
84
87
  // `libphonenumber` code.
85
88
  //
86
-
87
-
88
- var NON_ALTERING_FORMAT_REG_EXP = new RegExp('[' + VALID_PUNCTUATION + ']*' + // Google developers say:
89
+ var NON_ALTERING_FORMAT_REG_EXP = new RegExp('[' + VALID_PUNCTUATION + ']*' +
90
+ // Google developers say:
89
91
  // "We require that the first matching group is present in the
90
92
  // output pattern to ensure no data is lost while formatting."
91
- '\\$1' + '[' + VALID_PUNCTUATION + ']*' + '(\\$\\d[' + VALID_PUNCTUATION + ']*)*' + '$'); // This is the minimum length of the leading digits of a phone number
93
+ '\\$1' + '[' + VALID_PUNCTUATION + ']*' + '(\\$\\d[' + VALID_PUNCTUATION + ']*)*' + '$');
94
+
95
+ // This is the minimum length of the leading digits of a phone number
92
96
  // to guarantee the first "leading digits pattern" for a phone number format
93
97
  // to be preemptive.
94
-
95
98
  var MIN_LEADING_DIGITS_LENGTH = 3;
96
-
97
99
  var AsYouTypeFormatter = /*#__PURE__*/function () {
98
100
  function AsYouTypeFormatter(_ref) {
99
101
  var state = _ref.state,
100
- metadata = _ref.metadata;
101
-
102
+ metadata = _ref.metadata;
102
103
  _classCallCheck(this, AsYouTypeFormatter);
103
-
104
104
  this.metadata = metadata;
105
105
  this.resetFormat();
106
106
  }
107
-
108
- _createClass(AsYouTypeFormatter, [{
107
+ return _createClass(AsYouTypeFormatter, [{
109
108
  key: "resetFormat",
110
109
  value: function resetFormat() {
111
110
  this.chosenFormat = undefined;
@@ -118,11 +117,9 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
118
117
  key: "reset",
119
118
  value: function reset(numberingPlan, state) {
120
119
  this.resetFormat();
121
-
122
120
  if (numberingPlan) {
123
121
  this.isNANP = numberingPlan.callingCode() === '1';
124
122
  this.matchingFormats = numberingPlan.formats();
125
-
126
123
  if (state.nationalSignificantNumber) {
127
124
  this.narrowDownMatchingFormats(state);
128
125
  }
@@ -131,18 +128,17 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
131
128
  this.matchingFormats = [];
132
129
  }
133
130
  }
131
+
134
132
  /**
135
133
  * Formats an updated phone number.
136
134
  * @param {string} nextDigits — Additional phone number digits.
137
135
  * @param {object} state — `AsYouType` state.
138
136
  * @return {[string]} Returns undefined if the updated phone number can't be formatted using any of the available formats.
139
137
  */
140
-
141
138
  }, {
142
139
  key: "format",
143
140
  value: function format(nextDigits, state) {
144
141
  var _this = this;
145
-
146
142
  // See if the phone number digits can be formatted as a complete phone number.
147
143
  // If not, use the results from `formatNationalNumberWithNextDigits()`,
148
144
  // which formats based on the chosen formatting pattern.
@@ -159,8 +155,8 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
159
155
  //
160
156
  if (canFormatCompleteNumber(state.nationalSignificantNumber, this.metadata)) {
161
157
  for (var _iterator = _createForOfIteratorHelperLoose(this.matchingFormats), _step; !(_step = _iterator()).done;) {
162
- var format = _step.value;
163
- var formattedCompleteNumber = formatCompleteNumber(state, format, {
158
+ var _format = _step.value;
159
+ var formattedCompleteNumber = formatCompleteNumber(state, _format, {
164
160
  metadata: this.metadata,
165
161
  shouldTryNationalPrefixFormattingRule: function shouldTryNationalPrefixFormattingRule(format) {
166
162
  return _this.shouldTryNationalPrefixFormattingRule(format, {
@@ -172,32 +168,31 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
172
168
  return _this.getSeparatorAfterNationalPrefix(format);
173
169
  }
174
170
  });
175
-
176
171
  if (formattedCompleteNumber) {
177
172
  this.resetFormat();
178
- this.chosenFormat = format;
173
+ this.chosenFormat = _format;
179
174
  this.setNationalNumberTemplate(formattedCompleteNumber.replace(/\d/g, DIGIT_PLACEHOLDER), state);
180
- this.populatedNationalNumberTemplate = formattedCompleteNumber; // With a new formatting template, the matched position
175
+ this.populatedNationalNumberTemplate = formattedCompleteNumber;
176
+ // With a new formatting template, the matched position
181
177
  // using the old template needs to be reset.
182
-
183
178
  this.populatedNationalNumberTemplatePosition = this.template.lastIndexOf(DIGIT_PLACEHOLDER);
184
179
  return formattedCompleteNumber;
185
180
  }
186
181
  }
187
- } // Format the digits as a partial (incomplete) phone number
182
+ }
183
+ // Format the digits as a partial (incomplete) phone number
188
184
  // using the previously chosen formatting pattern (or a newly chosen one).
189
-
190
-
191
185
  return this.formatNationalNumberWithNextDigits(nextDigits, state);
192
- } // Formats the next phone number digits.
186
+ }
193
187
 
188
+ // Formats the next phone number digits.
194
189
  }, {
195
190
  key: "formatNationalNumberWithNextDigits",
196
191
  value: function formatNationalNumberWithNextDigits(nextDigits, state) {
197
- var previouslyChosenFormat = this.chosenFormat; // Choose a format from the list of matching ones.
192
+ var previouslyChosenFormat = this.chosenFormat;
198
193
 
194
+ // Choose a format from the list of matching ones.
199
195
  var newlyChosenFormat = this.chooseFormat(state);
200
-
201
196
  if (newlyChosenFormat) {
202
197
  if (newlyChosenFormat === previouslyChosenFormat) {
203
198
  // If it can format the next (current) digits
@@ -217,38 +212,38 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
217
212
  key: "narrowDownMatchingFormats",
218
213
  value: function narrowDownMatchingFormats(_ref2) {
219
214
  var _this2 = this;
220
-
221
215
  var nationalSignificantNumber = _ref2.nationalSignificantNumber,
222
- nationalPrefix = _ref2.nationalPrefix,
223
- international = _ref2.international;
224
- var leadingDigits = nationalSignificantNumber; // "leading digits" pattern list starts with a
216
+ nationalPrefix = _ref2.nationalPrefix,
217
+ international = _ref2.international;
218
+ var leadingDigits = nationalSignificantNumber;
219
+
220
+ // "leading digits" pattern list starts with a
225
221
  // "leading digits" pattern fitting a maximum of 3 leading digits.
226
222
  // So, after a user inputs 3 digits of a national (significant) phone number
227
223
  // this national (significant) number can already be formatted.
228
224
  // The next "leading digits" pattern is for 4 leading digits max,
229
225
  // and the "leading digits" pattern after it is for 5 leading digits max, etc.
226
+
230
227
  // This implementation is different from Google's
231
228
  // in that it searches for a fitting format
232
229
  // even if the user has entered less than
233
230
  // `MIN_LEADING_DIGITS_LENGTH` digits of a national number.
234
231
  // Because some leading digit patterns already match for a single first digit.
235
-
236
232
  var leadingDigitsPatternIndex = leadingDigits.length - MIN_LEADING_DIGITS_LENGTH;
237
-
238
233
  if (leadingDigitsPatternIndex < 0) {
239
234
  leadingDigitsPatternIndex = 0;
240
235
  }
241
-
242
236
  this.matchingFormats = this.matchingFormats.filter(function (format) {
243
237
  return _this2.formatSuits(format, international, nationalPrefix) && _this2.formatMatches(format, leadingDigits, leadingDigitsPatternIndex);
244
- }); // If there was a phone number format chosen
238
+ });
239
+
240
+ // If there was a phone number format chosen
245
241
  // and it no longer holds given the new leading digits then reset it.
246
242
  // The test for this `if` condition is marked as:
247
243
  // "Reset a chosen format when it no longer holds given the new leading digits".
248
244
  // To construct a valid test case for this one can find a country
249
245
  // in `PhoneNumberMetadata.xml` yielding one format for 3 `<leadingDigits>`
250
246
  // and yielding another format for 4 `<leadingDigits>` (Australia in this case).
251
-
252
247
  if (this.chosenFormat && this.matchingFormats.indexOf(this.chosenFormat) === -1) {
253
248
  this.resetFormat();
254
249
  }
@@ -266,39 +261,42 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
266
261
  // and was extracted, then discard such phone number format.
267
262
  // In Google's "AsYouType" formatter code, the equivalent would be this part:
268
263
  // https://github.com/google/libphonenumber/blob/0a45cfd96e71cad8edb0e162a70fcc8bd9728933/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java#L175-L184
269
- if (nationalPrefix && !format.usesNationalPrefix() && // !format.domesticCarrierCodeFormattingRule() &&
264
+ if (nationalPrefix && !format.usesNationalPrefix() &&
265
+ // !format.domesticCarrierCodeFormattingRule() &&
270
266
  !format.nationalPrefixIsOptionalWhenFormattingInNationalFormat()) {
271
267
  return false;
272
- } // If national prefix is mandatory for this phone number format
268
+ }
269
+ // If national prefix is mandatory for this phone number format
273
270
  // and there're no guarantees that a national prefix is present in user input
274
271
  // then discard this phone number format as not suitable.
275
272
  // In Google's "AsYouType" formatter code, the equivalent would be this part:
276
273
  // https://github.com/google/libphonenumber/blob/0a45cfd96e71cad8edb0e162a70fcc8bd9728933/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java#L185-L193
277
-
278
-
279
274
  if (!international && !nationalPrefix && format.nationalPrefixIsMandatoryWhenFormattingInNationalFormat()) {
280
275
  return false;
281
276
  }
282
-
283
277
  return true;
284
278
  }
285
279
  }, {
286
280
  key: "formatMatches",
287
281
  value: function formatMatches(format, leadingDigits, leadingDigitsPatternIndex) {
288
- var leadingDigitsPatternsCount = format.leadingDigitsPatterns().length; // If this format is not restricted to a certain
282
+ var leadingDigitsPatternsCount = format.leadingDigitsPatterns().length;
283
+
284
+ // If this format is not restricted to a certain
289
285
  // leading digits pattern then it fits.
290
286
  // The test case could be found by searching for "leadingDigitsPatternsCount === 0".
291
-
292
287
  if (leadingDigitsPatternsCount === 0) {
293
288
  return true;
294
- } // Start narrowing down the list of possible formats based on the leading digits.
289
+ }
290
+
291
+ // Start narrowing down the list of possible formats based on the leading digits.
295
292
  // (only previously matched formats take part in the narrowing down process)
293
+
296
294
  // `leading_digits_patterns` start with 3 digits min
297
295
  // and then go up from there one digit at a time.
298
-
299
-
300
296
  leadingDigitsPatternIndex = Math.min(leadingDigitsPatternIndex, leadingDigitsPatternsCount - 1);
301
- var leadingDigitsPattern = format.leadingDigitsPatterns()[leadingDigitsPatternIndex]; // Google imposes a requirement on the leading digits
297
+ var leadingDigitsPattern = format.leadingDigitsPatterns()[leadingDigitsPatternIndex];
298
+
299
+ // Google imposes a requirement on the leading digits
302
300
  // to be minimum 3 digits long in order to be eligible
303
301
  // for checking those with a leading digits pattern.
304
302
  //
@@ -323,7 +321,6 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
323
321
  // even when there's only 1 or 2 digits of the national (significant) number.
324
322
  // To do that, it uses a non-strict pattern matcher written specifically for that.
325
323
  //
326
-
327
324
  if (leadingDigits.length < MIN_LEADING_DIGITS_LENGTH) {
328
325
  // Before leading digits < 3 matching was implemented:
329
326
  // return true
@@ -333,9 +330,7 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
333
330
  return new PatternMatcher(leadingDigitsPattern).match(leadingDigits, {
334
331
  allowOverflow: true
335
332
  }) !== undefined;
336
- } catch (error)
337
- /* istanbul ignore next */
338
- {
333
+ } catch (error) /* istanbul ignore next */{
339
334
  // There's a slight possibility that there could be some undiscovered bug
340
335
  // in the pattern matcher code. Since the "leading digits < 3 matching"
341
336
  // feature is not "essential" for operation, it can fall back to the old way
@@ -343,14 +338,14 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
343
338
  console.error(error);
344
339
  return true;
345
340
  }
346
- } // If at least `MIN_LEADING_DIGITS_LENGTH` digits of a national number are
341
+ }
342
+
343
+ // If at least `MIN_LEADING_DIGITS_LENGTH` digits of a national number are
347
344
  // available then use the usual regular expression matching.
348
345
  //
349
346
  // The whole pattern is wrapped in round brackets (`()`) because
350
347
  // the pattern can use "or" operator (`|`) at the top level of the pattern.
351
348
  //
352
-
353
-
354
349
  return new RegExp("^(".concat(leadingDigitsPattern, ")")).test(leadingDigits);
355
350
  }
356
351
  }, {
@@ -362,72 +357,66 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
362
357
  key: "chooseFormat",
363
358
  value: function chooseFormat(state) {
364
359
  var _this3 = this;
365
-
366
360
  var _loop = function _loop() {
367
- var format = _step2.value;
368
-
369
- // If this format is currently being used
370
- // and is still suitable, then stick to it.
371
- if (_this3.chosenFormat === format) {
372
- return "break";
373
- } // Sometimes, a formatting rule inserts additional digits in a phone number,
374
- // and "as you type" formatter can't do that: it should only use the digits
375
- // that the user has input.
376
- //
377
- // For example, in Argentina, there's a format for mobile phone numbers:
378
- //
379
- // {
380
- // "pattern": "(\\d)(\\d{2})(\\d{4})(\\d{4})",
381
- // "leading_digits_patterns": ["91"],
382
- // "national_prefix_formatting_rule": "0$1",
383
- // "format": "$2 15-$3-$4",
384
- // "international_format": "$1 $2 $3-$4"
385
- // }
386
- //
387
- // In that format, `international_format` is used instead of `format`
388
- // because `format` inserts `15` in the formatted number,
389
- // and `AsYouType` formatter should only use the digits
390
- // the user has actually input, without adding any extra digits.
391
- // In this case, it wouldn't make a difference, because the `15`
392
- // is first stripped when applying `national_prefix_for_parsing`
393
- // and then re-added when using `format`, so in reality it doesn't
394
- // add any new digits to the number, but to detect that, the code
395
- // would have to be more complex: it would have to try formatting
396
- // the digits using the format and then see if any digits have
397
- // actually been added or removed, and then, every time a new digit
398
- // is input, it should re-check whether the chosen format doesn't
399
- // alter the digits.
400
- //
401
- // Google's code doesn't go that far, and so does this library:
402
- // it simply requires that a `format` doesn't add any additonal
403
- // digits to user's input.
404
- //
405
- // Also, people in general should move from inputting phone numbers
406
- // in national format (possibly with national prefixes)
407
- // and use international phone number format instead:
408
- // it's a logical thing in the modern age of mobile phones,
409
- // globalization and the internet.
410
- //
411
-
412
- /* istanbul ignore if */
413
-
414
-
415
- if (!NON_ALTERING_FORMAT_REG_EXP.test(_this3.getFormatFormat(format, state.international))) {
416
- return "continue";
417
- }
418
-
419
- if (!_this3.createTemplateForFormat(format, state)) {
420
- // Remove the format if it can't generate a template.
421
- _this3.matchingFormats = _this3.matchingFormats.filter(function (_) {
422
- return _ !== format;
423
- });
424
- return "continue";
425
- }
426
-
427
- _this3.chosenFormat = format;
428
- return "break";
429
- };
430
-
361
+ var format = _step2.value;
362
+ // If this format is currently being used
363
+ // and is still suitable, then stick to it.
364
+ if (_this3.chosenFormat === format) {
365
+ return 0; // break
366
+ }
367
+ // Sometimes, a formatting rule inserts additional digits in a phone number,
368
+ // and "as you type" formatter can't do that: it should only use the digits
369
+ // that the user has input.
370
+ //
371
+ // For example, in Argentina, there's a format for mobile phone numbers:
372
+ //
373
+ // {
374
+ // "pattern": "(\\d)(\\d{2})(\\d{4})(\\d{4})",
375
+ // "leading_digits_patterns": ["91"],
376
+ // "national_prefix_formatting_rule": "0$1",
377
+ // "format": "$2 15-$3-$4",
378
+ // "international_format": "$1 $2 $3-$4"
379
+ // }
380
+ //
381
+ // In that format, `international_format` is used instead of `format`
382
+ // because `format` inserts `15` in the formatted number,
383
+ // and `AsYouType` formatter should only use the digits
384
+ // the user has actually input, without adding any extra digits.
385
+ // In this case, it wouldn't make a difference, because the `15`
386
+ // is first stripped when applying `national_prefix_for_parsing`
387
+ // and then re-added when using `format`, so in reality it doesn't
388
+ // add any new digits to the number, but to detect that, the code
389
+ // would have to be more complex: it would have to try formatting
390
+ // the digits using the format and then see if any digits have
391
+ // actually been added or removed, and then, every time a new digit
392
+ // is input, it should re-check whether the chosen format doesn't
393
+ // alter the digits.
394
+ //
395
+ // Google's code doesn't go that far, and so does this library:
396
+ // it simply requires that a `format` doesn't add any additonal
397
+ // digits to user's input.
398
+ //
399
+ // Also, people in general should move from inputting phone numbers
400
+ // in national format (possibly with national prefixes)
401
+ // and use international phone number format instead:
402
+ // it's a logical thing in the modern age of mobile phones,
403
+ // globalization and the internet.
404
+ //
405
+ /* istanbul ignore if */
406
+ if (!NON_ALTERING_FORMAT_REG_EXP.test(_this3.getFormatFormat(format, state.international))) {
407
+ return 1; // continue
408
+ }
409
+ if (!_this3.createTemplateForFormat(format, state)) {
410
+ // Remove the format if it can't generate a template.
411
+ _this3.matchingFormats = _this3.matchingFormats.filter(function (_) {
412
+ return _ !== format;
413
+ });
414
+ return 1; // continue
415
+ }
416
+ _this3.chosenFormat = format;
417
+ return 0; // break
418
+ },
419
+ _ret;
431
420
  // When there are multiple available formats, the formatter uses the first
432
421
  // format where a formatting template could be created.
433
422
  //
@@ -442,20 +431,16 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
442
431
  // It doesn't skip the contents of the `for of` loop,
443
432
  // it just skips the `for of` line.
444
433
  //
445
-
446
434
  /* istanbul ignore next */
447
435
  for (var _iterator2 = _createForOfIteratorHelperLoose(this.matchingFormats.slice()), _step2; !(_step2 = _iterator2()).done;) {
448
- var _ret = _loop();
449
-
450
- if (_ret === "break") break;
451
- if (_ret === "continue") continue;
436
+ _ret = _loop();
437
+ if (_ret === 0) break;
438
+ if (_ret === 1) continue;
452
439
  }
453
-
454
440
  if (!this.chosenFormat) {
455
441
  // No format matches the national (significant) phone number.
456
442
  this.resetFormat();
457
443
  }
458
-
459
444
  return this.chosenFormat;
460
445
  }
461
446
  }, {
@@ -464,16 +449,14 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
464
449
  // The formatter doesn't format numbers when numberPattern contains '|', e.g.
465
450
  // (20|3)\d{4}. In those cases we quickly return.
466
451
  // (Though there's no such format in current metadata)
467
-
468
452
  /* istanbul ignore if */
469
453
  if (SUPPORT_LEGACY_FORMATTING_PATTERNS && format.pattern().indexOf('|') >= 0) {
470
454
  return;
471
- } // Get formatting template for this phone number format
472
-
473
-
474
- var template = this.getTemplateForFormat(format, state); // If the national number entered is too long
455
+ }
456
+ // Get formatting template for this phone number format
457
+ var template = this.getTemplateForFormat(format, state);
458
+ // If the national number entered is too long
475
459
  // for any phone number format, then abort.
476
-
477
460
  if (template) {
478
461
  this.setNationalNumberTemplate(template, state);
479
462
  return true;
@@ -489,35 +472,30 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
489
472
  // So `US` national prefix separator is a "special" "hardcoded" case.
490
473
  if (this.isNANP) {
491
474
  return ' ';
492
- } // If a `format` has a `national_prefix_formatting_rule`
475
+ }
476
+ // If a `format` has a `national_prefix_formatting_rule`
493
477
  // and that rule has a separator after a national prefix,
494
478
  // then it means that there should be a separator
495
479
  // between a national prefix and a national (significant) number.
496
-
497
-
498
480
  if (format && format.nationalPrefixFormattingRule() && NATIONAL_PREFIX_SEPARATORS_PATTERN.test(format.nationalPrefixFormattingRule())) {
499
481
  return ' ';
500
- } // At this point, there seems to be no clear evidence that
482
+ }
483
+ // At this point, there seems to be no clear evidence that
501
484
  // there should be a separator between a national prefix
502
485
  // and a national (significant) number. So don't insert one.
503
-
504
-
505
486
  return '';
506
487
  }
507
488
  }, {
508
489
  key: "getInternationalPrefixBeforeCountryCallingCode",
509
490
  value: function getInternationalPrefixBeforeCountryCallingCode(_ref3, options) {
510
491
  var IDDPrefix = _ref3.IDDPrefix,
511
- missingPlus = _ref3.missingPlus;
512
-
492
+ missingPlus = _ref3.missingPlus;
513
493
  if (IDDPrefix) {
514
494
  return options && options.spacing === false ? IDDPrefix : IDDPrefix + ' ';
515
495
  }
516
-
517
496
  if (missingPlus) {
518
497
  return '';
519
498
  }
520
-
521
499
  return '+';
522
500
  }
523
501
  }, {
@@ -525,43 +503,41 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
525
503
  value: function getTemplate(state) {
526
504
  if (!this.template) {
527
505
  return;
528
- } // `this.template` holds the template for a "complete" phone number.
506
+ }
507
+ // `this.template` holds the template for a "complete" phone number.
529
508
  // The currently entered phone number is most likely not "complete",
530
509
  // so trim all non-populated digits.
531
-
532
-
533
510
  var index = -1;
534
511
  var i = 0;
535
512
  var internationalPrefix = state.international ? this.getInternationalPrefixBeforeCountryCallingCode(state, {
536
513
  spacing: false
537
514
  }) : '';
538
-
539
515
  while (i < internationalPrefix.length + state.getDigitsWithoutInternationalPrefix().length) {
540
516
  index = this.template.indexOf(DIGIT_PLACEHOLDER, index + 1);
541
517
  i++;
542
518
  }
543
-
544
519
  return cutAndStripNonPairedParens(this.template, index + 1);
545
520
  }
546
521
  }, {
547
522
  key: "setNationalNumberTemplate",
548
523
  value: function setNationalNumberTemplate(template, state) {
549
524
  this.nationalNumberTemplate = template;
550
- this.populatedNationalNumberTemplate = template; // With a new formatting template, the matched position
525
+ this.populatedNationalNumberTemplate = template;
526
+ // With a new formatting template, the matched position
551
527
  // using the old template needs to be reset.
552
-
553
- this.populatedNationalNumberTemplatePosition = -1; // For convenience, the public `.template` property
528
+ this.populatedNationalNumberTemplatePosition = -1;
529
+ // For convenience, the public `.template` property
554
530
  // contains the whole international number
555
531
  // if the phone number being input is international:
556
532
  // 'x' for the '+' sign, 'x'es for the country phone code,
557
533
  // a spacebar and then the template for the formatted national number.
558
-
559
534
  if (state.international) {
560
535
  this.template = this.getInternationalPrefixBeforeCountryCallingCode(state).replace(/[\d\+]/g, DIGIT_PLACEHOLDER) + repeat(DIGIT_PLACEHOLDER, state.callingCode.length) + ' ' + template;
561
536
  } else {
562
537
  this.template = template;
563
538
  }
564
539
  }
540
+
565
541
  /**
566
542
  * Generates formatting template for a national phone number,
567
543
  * optionally containing a national prefix, for a format.
@@ -569,22 +545,25 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
569
545
  * @param {string} nationalPrefix
570
546
  * @return {string}
571
547
  */
572
-
573
548
  }, {
574
549
  key: "getTemplateForFormat",
575
550
  value: function getTemplateForFormat(format, _ref4) {
576
551
  var nationalSignificantNumber = _ref4.nationalSignificantNumber,
577
- international = _ref4.international,
578
- nationalPrefix = _ref4.nationalPrefix,
579
- complexPrefixBeforeNationalSignificantNumber = _ref4.complexPrefixBeforeNationalSignificantNumber;
552
+ international = _ref4.international,
553
+ nationalPrefix = _ref4.nationalPrefix,
554
+ complexPrefixBeforeNationalSignificantNumber = _ref4.complexPrefixBeforeNationalSignificantNumber;
580
555
  var pattern = format.pattern();
581
- /* istanbul ignore else */
582
556
 
557
+ /* istanbul ignore else */
583
558
  if (SUPPORT_LEGACY_FORMATTING_PATTERNS) {
584
- pattern = pattern // Replace anything in the form of [..] with \d
585
- .replace(CREATE_CHARACTER_CLASS_PATTERN(), '\\d') // Replace any standalone digit (not the one in `{}`) with \d
559
+ pattern = pattern
560
+ // Replace anything in the form of [..] with \d
561
+ .replace(CREATE_CHARACTER_CLASS_PATTERN(), '\\d')
562
+ // Replace any standalone digit (not the one in `{}`) with \d
586
563
  .replace(CREATE_STANDALONE_DIGIT_PATTERN(), '\\d');
587
- } // Generate a dummy national number (consisting of `9`s)
564
+ }
565
+
566
+ // Generate a dummy national number (consisting of `9`s)
588
567
  // that fits this format's `pattern`.
589
568
  //
590
569
  // This match will always succeed,
@@ -592,15 +571,17 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
592
571
  // has enough length to accomodate any possible
593
572
  // national phone number format pattern.
594
573
  //
574
+ var digits = LONGEST_DUMMY_PHONE_NUMBER.match(pattern)[0];
595
575
 
596
-
597
- var digits = LONGEST_DUMMY_PHONE_NUMBER.match(pattern)[0]; // If the national number entered is too long
576
+ // If the national number entered is too long
598
577
  // for any phone number format, then abort.
599
-
600
578
  if (nationalSignificantNumber.length > digits.length) {
601
579
  return;
602
- } // Get a formatting template which can be used to efficiently format
580
+ }
581
+
582
+ // Get a formatting template which can be used to efficiently format
603
583
  // a partial number where digits are added one by one.
584
+
604
585
  // Below `strictPattern` is used for the
605
586
  // regular expression (with `^` and `$`).
606
587
  // This wasn't originally in Google's `libphonenumber`
@@ -629,63 +610,64 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
629
610
  // to satisfy the `pattern` completely then `this.nationalSignificantNumber`
630
611
  // is used instead of `digits`.
631
612
 
632
-
633
613
  var strictPattern = new RegExp('^' + pattern + '$');
634
- var nationalNumberDummyDigits = nationalSignificantNumber.replace(/\d/g, DUMMY_DIGIT); // If `this.nationalSignificantNumber` has already sufficient length
614
+ var nationalNumberDummyDigits = nationalSignificantNumber.replace(/\d/g, DUMMY_DIGIT);
615
+
616
+ // If `this.nationalSignificantNumber` has already sufficient length
635
617
  // to satisfy the `pattern` completely then use it
636
618
  // instead of `digits`.
637
-
638
619
  if (strictPattern.test(nationalNumberDummyDigits)) {
639
620
  digits = nationalNumberDummyDigits;
640
621
  }
641
-
642
622
  var numberFormat = this.getFormatFormat(format, international);
643
- var nationalPrefixIncludedInTemplate; // If a user did input a national prefix (and that's guaranteed),
623
+ var nationalPrefixIncludedInTemplate;
624
+
625
+ // If a user did input a national prefix (and that's guaranteed),
644
626
  // and if a `format` does have a national prefix formatting rule,
645
627
  // then see if that national prefix formatting rule
646
628
  // prepends exactly the same national prefix the user has input.
647
629
  // If that's the case, then use the `format` with the national prefix formatting rule.
648
630
  // Otherwise, use the `format` without the national prefix formatting rule,
649
631
  // and prepend a national prefix manually to it.
650
-
651
632
  if (this.shouldTryNationalPrefixFormattingRule(format, {
652
633
  international: international,
653
634
  nationalPrefix: nationalPrefix
654
635
  })) {
655
- var numberFormatWithNationalPrefix = numberFormat.replace(FIRST_GROUP_PATTERN, format.nationalPrefixFormattingRule()); // If `national_prefix_formatting_rule` of a `format` simply prepends
636
+ var numberFormatWithNationalPrefix = numberFormat.replace(FIRST_GROUP_PATTERN, format.nationalPrefixFormattingRule());
637
+ // If `national_prefix_formatting_rule` of a `format` simply prepends
656
638
  // national prefix at the start of a national (significant) number,
657
639
  // then such formatting can be used with `AsYouType` formatter.
658
640
  // There seems to be no `else` case: everywhere in metadata,
659
641
  // national prefix formatting rule is national prefix + $1,
660
642
  // or `($1)`, in which case such format isn't even considered
661
643
  // when the user has input a national prefix.
662
-
663
644
  /* istanbul ignore else */
664
-
665
645
  if (parseDigits(format.nationalPrefixFormattingRule()) === (nationalPrefix || '') + parseDigits('$1')) {
666
646
  numberFormat = numberFormatWithNationalPrefix;
667
- nationalPrefixIncludedInTemplate = true; // Replace all digits of the national prefix in the formatting template
647
+ nationalPrefixIncludedInTemplate = true;
648
+ // Replace all digits of the national prefix in the formatting template
668
649
  // with `DIGIT_PLACEHOLDER`s.
669
-
670
650
  if (nationalPrefix) {
671
651
  var i = nationalPrefix.length;
672
-
673
652
  while (i > 0) {
674
653
  numberFormat = numberFormat.replace(/\d/, DIGIT_PLACEHOLDER);
675
654
  i--;
676
655
  }
677
656
  }
678
657
  }
679
- } // Generate formatting template for this phone number format.
658
+ }
680
659
 
660
+ // Generate formatting template for this phone number format.
661
+ var template = digits
662
+ // Format the dummy phone number according to the format.
663
+ .replace(new RegExp(pattern), numberFormat)
664
+ // Replace each dummy digit with a DIGIT_PLACEHOLDER.
665
+ .replace(new RegExp(DUMMY_DIGIT, 'g'), DIGIT_PLACEHOLDER);
681
666
 
682
- var template = digits // Format the dummy phone number according to the format.
683
- .replace(new RegExp(pattern), numberFormat) // Replace each dummy digit with a DIGIT_PLACEHOLDER.
684
- .replace(new RegExp(DUMMY_DIGIT, 'g'), DIGIT_PLACEHOLDER); // If a prefix of a national (significant) number is not as simple
667
+ // If a prefix of a national (significant) number is not as simple
685
668
  // as just a basic national prefix, then just prepend such prefix
686
669
  // before the national (significant) number, optionally spacing
687
670
  // the two with a whitespace.
688
-
689
671
  if (!nationalPrefixIncludedInTemplate) {
690
672
  if (complexPrefixBeforeNationalSignificantNumber) {
691
673
  // Prepend the prefix to the template manually.
@@ -695,28 +677,27 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
695
677
  template = repeat(DIGIT_PLACEHOLDER, nationalPrefix.length) + this.getSeparatorAfterNationalPrefix(format) + template;
696
678
  }
697
679
  }
698
-
699
680
  if (international) {
700
681
  template = applyInternationalSeparatorStyle(template);
701
682
  }
702
-
703
683
  return template;
704
684
  }
705
685
  }, {
706
686
  key: "formatNextNationalNumberDigits",
707
687
  value: function formatNextNationalNumberDigits(digits) {
708
688
  var result = populateTemplateWithDigits(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition, digits);
709
-
710
689
  if (!result) {
711
690
  // Reset the format.
712
691
  this.resetFormat();
713
692
  return;
714
693
  }
715
-
716
694
  this.populatedNationalNumberTemplate = result[0];
717
- this.populatedNationalNumberTemplatePosition = result[1]; // Return the formatted phone number so far.
695
+ this.populatedNationalNumberTemplatePosition = result[1];
696
+
697
+ // Return the formatted phone number so far.
698
+ return cutAndStripNonPairedParens(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1);
718
699
 
719
- return cutAndStripNonPairedParens(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1); // The old way which was good for `input-format` but is not so good
700
+ // The old way which was good for `input-format` but is not so good
720
701
  // for `react-phone-number-input`'s default input (`InputBasic`).
721
702
  // return closeNonPairedParens(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1)
722
703
  // .replace(new RegExp(DIGIT_PLACEHOLDER, 'g'), ' ')
@@ -725,23 +706,18 @@ var AsYouTypeFormatter = /*#__PURE__*/function () {
725
706
  key: "shouldTryNationalPrefixFormattingRule",
726
707
  value: function shouldTryNationalPrefixFormattingRule(format, _ref5) {
727
708
  var international = _ref5.international,
728
- nationalPrefix = _ref5.nationalPrefix;
729
-
709
+ nationalPrefix = _ref5.nationalPrefix;
730
710
  if (format.nationalPrefixFormattingRule()) {
731
711
  // In some countries, `national_prefix_formatting_rule` is `($1)`,
732
712
  // so it applies even if the user hasn't input a national prefix.
733
713
  // `format.usesNationalPrefix()` detects such cases.
734
714
  var usesNationalPrefix = format.usesNationalPrefix();
735
-
736
715
  if (usesNationalPrefix && nationalPrefix || !usesNationalPrefix && !international) {
737
716
  return true;
738
717
  }
739
718
  }
740
719
  }
741
720
  }]);
742
-
743
- return AsYouTypeFormatter;
744
721
  }();
745
-
746
722
  export { AsYouTypeFormatter as default };
747
723
  //# sourceMappingURL=AsYouTypeFormatter.js.map