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