libphonenumber-js 1.12.10 → 1.12.12

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 (587) hide show
  1. package/README.md +2 -3
  2. package/build/AsYouType.js +69 -131
  3. package/build/AsYouType.js.map +1 -1
  4. package/build/AsYouType.test.js +610 -553
  5. package/build/AsYouType.test.js.map +1 -1
  6. package/build/AsYouTypeFormatter.PatternMatcher.js +29 -77
  7. package/build/AsYouTypeFormatter.PatternMatcher.js.map +1 -1
  8. package/build/AsYouTypeFormatter.PatternMatcher.test.js +107 -109
  9. package/build/AsYouTypeFormatter.PatternMatcher.test.js.map +1 -1
  10. package/build/AsYouTypeFormatter.PatternParser.js +34 -67
  11. package/build/AsYouTypeFormatter.PatternParser.js.map +1 -1
  12. package/build/AsYouTypeFormatter.PatternParser.test.js +7 -9
  13. package/build/AsYouTypeFormatter.PatternParser.test.js.map +1 -1
  14. package/build/AsYouTypeFormatter.complete.js +18 -28
  15. package/build/AsYouTypeFormatter.complete.js.map +1 -1
  16. package/build/AsYouTypeFormatter.js +193 -233
  17. package/build/AsYouTypeFormatter.js.map +1 -1
  18. package/build/AsYouTypeFormatter.util.js +11 -38
  19. package/build/AsYouTypeFormatter.util.js.map +1 -1
  20. package/build/AsYouTypeFormatter.util.test.js +6 -7
  21. package/build/AsYouTypeFormatter.util.test.js.map +1 -1
  22. package/build/AsYouTypeParser.js +89 -143
  23. package/build/AsYouTypeParser.js.map +1 -1
  24. package/build/AsYouTypeState.js +13 -23
  25. package/build/AsYouTypeState.js.map +1 -1
  26. package/build/ParseError.js +22 -43
  27. package/build/ParseError.js.map +1 -1
  28. package/build/PhoneNumber.js +33 -70
  29. package/build/PhoneNumber.js.map +1 -1
  30. package/build/PhoneNumber.test.js +35 -33
  31. package/build/PhoneNumber.test.js.map +1 -1
  32. package/build/PhoneNumberMatcher.js +67 -101
  33. package/build/PhoneNumberMatcher.js.map +1 -1
  34. package/build/PhoneNumberMatcher.test.js +35 -18
  35. package/build/PhoneNumberMatcher.test.js.map +1 -1
  36. package/build/constants.js +17 -19
  37. package/build/constants.js.map +1 -1
  38. package/build/findNumbers/LRUCache.js +23 -34
  39. package/build/findNumbers/LRUCache.js.map +1 -1
  40. package/build/findNumbers/Leniency.js +58 -114
  41. package/build/findNumbers/Leniency.js.map +1 -1
  42. package/build/findNumbers/RegExpCache.js +9 -20
  43. package/build/findNumbers/RegExpCache.js.map +1 -1
  44. package/build/findNumbers/isValidCandidate.js +12 -19
  45. package/build/findNumbers/isValidCandidate.js.map +1 -1
  46. package/build/findNumbers/isValidPreCandidate.js +5 -7
  47. package/build/findNumbers/isValidPreCandidate.js.map +1 -1
  48. package/build/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js +9 -15
  49. package/build/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js.map +1 -1
  50. package/build/findNumbers/parsePreCandidate.js +0 -3
  51. package/build/findNumbers/parsePreCandidate.js.map +1 -1
  52. package/build/findNumbers/utf-8.js +9 -13
  53. package/build/findNumbers/utf-8.js.map +1 -1
  54. package/build/findNumbers/util.js +1 -8
  55. package/build/findNumbers/util.js.map +1 -1
  56. package/build/findNumbers/util.test.js +9 -15
  57. package/build/findNumbers/util.test.js.map +1 -1
  58. package/build/findPhoneNumbersInText.js +10 -17
  59. package/build/findPhoneNumbersInText.js.map +1 -1
  60. package/build/findPhoneNumbersInText.test.js +100 -93
  61. package/build/findPhoneNumbersInText.test.js.map +1 -1
  62. package/build/format.js +31 -64
  63. package/build/format.js.map +1 -1
  64. package/build/format.test.js +133 -119
  65. package/build/format.test.js.map +1 -1
  66. package/build/formatIncompletePhoneNumber.js +1 -5
  67. package/build/formatIncompletePhoneNumber.js.map +1 -1
  68. package/build/formatIncompletePhoneNumber.test.js +14 -13
  69. package/build/formatIncompletePhoneNumber.test.js.map +1 -1
  70. package/build/formatPhoneNumberForMobileDialing.js +32 -32
  71. package/build/formatPhoneNumberForMobileDialing.js.map +1 -1
  72. package/build/getCountries.js +1 -4
  73. package/build/getCountries.js.map +1 -1
  74. package/build/getCountries.test.js +2 -5
  75. package/build/getCountries.test.js.map +1 -1
  76. package/build/getCountryCallingCode.js +0 -1
  77. package/build/getCountryCallingCode.js.map +1 -1
  78. package/build/getCountryCallingCode.test.js +2 -5
  79. package/build/getCountryCallingCode.test.js.map +1 -1
  80. package/build/getExampleNumber.js +1 -4
  81. package/build/getExampleNumber.js.map +1 -1
  82. package/build/getExampleNumber.test.js +5 -9
  83. package/build/getExampleNumber.test.js.map +1 -1
  84. package/build/helpers/RFC3966.js +16 -38
  85. package/build/helpers/RFC3966.js.map +1 -1
  86. package/build/helpers/RFC3966.test.js +16 -14
  87. package/build/helpers/RFC3966.test.js.map +1 -1
  88. package/build/helpers/applyInternationalSeparatorStyle.js +0 -2
  89. package/build/helpers/applyInternationalSeparatorStyle.js.map +1 -1
  90. package/build/helpers/applyInternationalSeparatorStyle.test.js +3 -5
  91. package/build/helpers/applyInternationalSeparatorStyle.test.js.map +1 -1
  92. package/build/helpers/checkNumberLength.js +18 -22
  93. package/build/helpers/checkNumberLength.js.map +1 -1
  94. package/build/helpers/checkNumberLength.test.js +19 -27
  95. package/build/helpers/checkNumberLength.test.js.map +1 -1
  96. package/build/helpers/extension/createExtensionPattern.js +19 -35
  97. package/build/helpers/extension/createExtensionPattern.js.map +1 -1
  98. package/build/helpers/extension/extractExtension.js +6 -12
  99. package/build/helpers/extension/extractExtension.js.map +1 -1
  100. package/build/helpers/extractCountryCallingCode.js +14 -24
  101. package/build/helpers/extractCountryCallingCode.js.map +1 -1
  102. package/build/helpers/extractCountryCallingCode.test.js +4 -7
  103. package/build/helpers/extractCountryCallingCode.test.js.map +1 -1
  104. package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +4 -16
  105. package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -1
  106. package/build/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js +16 -29
  107. package/build/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js.map +1 -1
  108. package/build/helpers/extractNationalNumber.js +10 -21
  109. package/build/helpers/extractNationalNumber.js.map +1 -1
  110. package/build/helpers/extractNationalNumber.test.js +2 -8
  111. package/build/helpers/extractNationalNumber.test.js.map +1 -1
  112. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +12 -18
  113. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -1
  114. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +2 -6
  115. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js.map +1 -1
  116. package/build/helpers/extractPhoneContext.js +19 -28
  117. package/build/helpers/extractPhoneContext.js.map +1 -1
  118. package/build/helpers/extractPhoneContext.test.js +12 -15
  119. package/build/helpers/extractPhoneContext.test.js.map +1 -1
  120. package/build/helpers/formatNationalNumberUsingFormat.js +7 -13
  121. package/build/helpers/formatNationalNumberUsingFormat.js.map +1 -1
  122. package/build/helpers/getCountryByCallingCode.js +5 -14
  123. package/build/helpers/getCountryByCallingCode.js.map +1 -1
  124. package/build/helpers/getCountryByNationalNumber.js +18 -20
  125. package/build/helpers/getCountryByNationalNumber.js.map +1 -1
  126. package/build/helpers/getIddPrefix.js +4 -8
  127. package/build/helpers/getIddPrefix.js.map +1 -1
  128. package/build/helpers/getNumberType.js +23 -35
  129. package/build/helpers/getNumberType.js.map +1 -1
  130. package/build/helpers/getNumberType.test.js +4 -8
  131. package/build/helpers/getNumberType.test.js.map +1 -1
  132. package/build/helpers/getPossibleCountriesForNumber.js +1 -11
  133. package/build/helpers/getPossibleCountriesForNumber.js.map +1 -1
  134. package/build/helpers/isObject.js +0 -1
  135. package/build/helpers/isObject.js.map +1 -1
  136. package/build/helpers/isViablePhoneNumber.js +19 -19
  137. package/build/helpers/isViablePhoneNumber.js.map +1 -1
  138. package/build/helpers/matchesEntirely.js +0 -1
  139. package/build/helpers/matchesEntirely.js.map +1 -1
  140. package/build/helpers/matchesEntirely.test.js +4 -5
  141. package/build/helpers/matchesEntirely.test.js.map +1 -1
  142. package/build/helpers/mergeArrays.js +6 -11
  143. package/build/helpers/mergeArrays.js.map +1 -1
  144. package/build/helpers/mergeArrays.test.js +2 -4
  145. package/build/helpers/mergeArrays.test.js.map +1 -1
  146. package/build/helpers/parseDigits.js +7 -17
  147. package/build/helpers/parseDigits.js.map +1 -1
  148. package/build/helpers/parseDigits.test.js +2 -4
  149. package/build/helpers/parseDigits.test.js.map +1 -1
  150. package/build/helpers/stripIddPrefix.js +7 -17
  151. package/build/helpers/stripIddPrefix.js.map +1 -1
  152. package/build/helpers/stripIddPrefix.test.js +4 -7
  153. package/build/helpers/stripIddPrefix.test.js.map +1 -1
  154. package/build/isPossible.js +3 -15
  155. package/build/isPossible.js.map +1 -1
  156. package/build/isPossible.test.js +34 -41
  157. package/build/isPossible.test.js.map +1 -1
  158. package/build/isPossiblePhoneNumber.js +10 -15
  159. package/build/isPossiblePhoneNumber.js.map +1 -1
  160. package/build/isPossiblePhoneNumber.test.js +11 -17
  161. package/build/isPossiblePhoneNumber.test.js.map +1 -1
  162. package/build/isValid.js +7 -11
  163. package/build/isValid.js.map +1 -1
  164. package/build/isValid.test.js +59 -58
  165. package/build/isValid.test.js.map +1 -1
  166. package/build/isValidPhoneNumber.js +10 -15
  167. package/build/isValidPhoneNumber.js.map +1 -1
  168. package/build/isValidPhoneNumber.test.js +10 -15
  169. package/build/isValidPhoneNumber.test.js.map +1 -1
  170. package/build/legacy/findNumbers.js +4 -11
  171. package/build/legacy/findNumbers.js.map +1 -1
  172. package/build/legacy/findNumbers.test.js +77 -63
  173. package/build/legacy/findNumbers.test.js.map +1 -1
  174. package/build/legacy/findPhoneNumbers.js +11 -21
  175. package/build/legacy/findPhoneNumbers.js.map +1 -1
  176. package/build/legacy/findPhoneNumbers.test.js +75 -72
  177. package/build/legacy/findPhoneNumbers.test.js.map +1 -1
  178. package/build/legacy/findPhoneNumbersInitialImplementation.js +34 -62
  179. package/build/legacy/findPhoneNumbersInitialImplementation.js.map +1 -1
  180. package/build/legacy/format.js +28 -44
  181. package/build/legacy/format.js.map +1 -1
  182. package/build/legacy/format.test.js +119 -103
  183. package/build/legacy/format.test.js.map +1 -1
  184. package/build/legacy/getNumberType.js +30 -44
  185. package/build/legacy/getNumberType.js.map +1 -1
  186. package/build/legacy/getNumberType.test.js +31 -34
  187. package/build/legacy/getNumberType.test.js.map +1 -1
  188. package/build/legacy/isPossibleNumber.js +5 -11
  189. package/build/legacy/isPossibleNumber.js.map +1 -1
  190. package/build/legacy/isPossibleNumber.test.js +22 -25
  191. package/build/legacy/isPossibleNumber.test.js.map +1 -1
  192. package/build/legacy/isValidNumber.js +5 -11
  193. package/build/legacy/isValidNumber.js.map +1 -1
  194. package/build/legacy/isValidNumber.test.js +41 -39
  195. package/build/legacy/isValidNumber.test.js.map +1 -1
  196. package/build/legacy/isValidNumberForRegion.js +4 -12
  197. package/build/legacy/isValidNumberForRegion.js.map +1 -1
  198. package/build/legacy/isValidNumberForRegion.test.js +6 -11
  199. package/build/legacy/isValidNumberForRegion.test.js.map +1 -1
  200. package/build/legacy/isValidNumberForRegion_.js +1 -4
  201. package/build/legacy/isValidNumberForRegion_.js.map +1 -1
  202. package/build/legacy/parse.js +4 -9
  203. package/build/legacy/parse.js.map +1 -1
  204. package/build/legacy/parse.test.js +232 -193
  205. package/build/legacy/parse.test.js.map +1 -1
  206. package/build/legacy/searchNumbers.js +8 -12
  207. package/build/legacy/searchNumbers.js.map +1 -1
  208. package/build/legacy/searchNumbers.test.js +6 -14
  209. package/build/legacy/searchNumbers.test.js.map +1 -1
  210. package/build/metadata.js +85 -122
  211. package/build/metadata.js.map +1 -1
  212. package/build/metadata.test.js +54 -80
  213. package/build/metadata.test.js.map +1 -1
  214. package/build/normalizeArguments.js +25 -35
  215. package/build/normalizeArguments.js.map +1 -1
  216. package/build/parse.js +66 -116
  217. package/build/parse.js.map +1 -1
  218. package/build/parse.test.js +243 -205
  219. package/build/parse.test.js.map +1 -1
  220. package/build/parseIncompletePhoneNumber.js +8 -18
  221. package/build/parseIncompletePhoneNumber.js.map +1 -1
  222. package/build/parseIncompletePhoneNumber.test.js +24 -25
  223. package/build/parseIncompletePhoneNumber.test.js.map +1 -1
  224. package/build/parsePhoneNumber.js +4 -9
  225. package/build/parsePhoneNumber.js.map +1 -1
  226. package/build/parsePhoneNumber.test.js +14 -25
  227. package/build/parsePhoneNumber.test.js.map +1 -1
  228. package/build/parsePhoneNumberWithError.js +4 -9
  229. package/build/parsePhoneNumberWithError.js.map +1 -1
  230. package/build/parsePhoneNumberWithError.test.js +30 -34
  231. package/build/parsePhoneNumberWithError.test.js.map +1 -1
  232. package/build/parsePhoneNumberWithError_.js +7 -10
  233. package/build/parsePhoneNumberWithError_.js.map +1 -1
  234. package/build/parsePhoneNumber_.js +11 -16
  235. package/build/parsePhoneNumber_.js.map +1 -1
  236. package/build/searchPhoneNumbersInText.js +10 -16
  237. package/build/searchPhoneNumbersInText.js.map +1 -1
  238. package/build/searchPhoneNumbersInText.test.js +11 -21
  239. package/build/searchPhoneNumbersInText.test.js.map +1 -1
  240. package/build/tools/semver-compare.js +0 -4
  241. package/build/tools/semver-compare.js.map +1 -1
  242. package/build/tools/semver-compare.test.js +2 -4
  243. package/build/tools/semver-compare.test.js.map +1 -1
  244. package/build/validatePhoneNumberLength.js +12 -20
  245. package/build/validatePhoneNumberLength.js.map +1 -1
  246. package/build/validatePhoneNumberLength.test.js +14 -16
  247. package/build/validatePhoneNumberLength.test.js.map +1 -1
  248. package/bundle/libphonenumber-js.min.js +1 -1
  249. package/bundle/libphonenumber-js.min.js.map +1 -1
  250. package/bundle/libphonenumber-max.js +1 -1
  251. package/bundle/libphonenumber-max.js.map +1 -1
  252. package/bundle/libphonenumber-min.js +1 -1
  253. package/bundle/libphonenumber-min.js.map +1 -1
  254. package/bundle/libphonenumber-mobile.js +1 -1
  255. package/bundle/libphonenumber-mobile.js.map +1 -1
  256. package/es6/AsYouType.js +66 -112
  257. package/es6/AsYouType.js.map +1 -1
  258. package/es6/AsYouType.test.js +610 -551
  259. package/es6/AsYouType.test.js.map +1 -1
  260. package/es6/AsYouTypeFormatter.PatternMatcher.js +27 -72
  261. package/es6/AsYouTypeFormatter.PatternMatcher.js.map +1 -1
  262. package/es6/AsYouTypeFormatter.PatternMatcher.test.js +106 -106
  263. package/es6/AsYouTypeFormatter.PatternMatcher.test.js.map +1 -1
  264. package/es6/AsYouTypeFormatter.PatternParser.js +33 -64
  265. package/es6/AsYouTypeFormatter.PatternParser.js.map +1 -1
  266. package/es6/AsYouTypeFormatter.PatternParser.test.js +6 -6
  267. package/es6/AsYouTypeFormatter.PatternParser.test.js.map +1 -1
  268. package/es6/AsYouTypeFormatter.complete.js +17 -21
  269. package/es6/AsYouTypeFormatter.complete.js.map +1 -1
  270. package/es6/AsYouTypeFormatter.js +193 -217
  271. package/es6/AsYouTypeFormatter.js.map +1 -1
  272. package/es6/AsYouTypeFormatter.util.js +10 -30
  273. package/es6/AsYouTypeFormatter.util.js.map +1 -1
  274. package/es6/AsYouTypeFormatter.util.test.js +6 -6
  275. package/es6/AsYouTypeFormatter.util.test.js.map +1 -1
  276. package/es6/AsYouTypeParser.js +87 -132
  277. package/es6/AsYouTypeParser.js.map +1 -1
  278. package/es6/AsYouTypeState.js +12 -20
  279. package/es6/AsYouTypeState.js.map +1 -1
  280. package/es6/ParseError.js +21 -40
  281. package/es6/ParseError.js.map +1 -1
  282. package/es6/PhoneNumber.js +32 -53
  283. package/es6/PhoneNumber.js.map +1 -1
  284. package/es6/PhoneNumber.test.js +35 -30
  285. package/es6/PhoneNumber.test.js.map +1 -1
  286. package/es6/PhoneNumberMatcher.js +61 -78
  287. package/es6/PhoneNumberMatcher.js.map +1 -1
  288. package/es6/PhoneNumberMatcher.test.js +35 -16
  289. package/es6/PhoneNumberMatcher.test.js.map +1 -1
  290. package/es6/constants.js +15 -9
  291. package/es6/constants.js.map +1 -1
  292. package/es6/findNumbers/LRUCache.js +22 -31
  293. package/es6/findNumbers/LRUCache.js.map +1 -1
  294. package/es6/findNumbers/Leniency.js +57 -103
  295. package/es6/findNumbers/Leniency.js.map +1 -1
  296. package/es6/findNumbers/RegExpCache.js +10 -16
  297. package/es6/findNumbers/RegExpCache.js.map +1 -1
  298. package/es6/findNumbers/isValidCandidate.js +12 -13
  299. package/es6/findNumbers/isValidCandidate.js.map +1 -1
  300. package/es6/findNumbers/isValidPreCandidate.js +5 -6
  301. package/es6/findNumbers/isValidPreCandidate.js.map +1 -1
  302. package/es6/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js +9 -12
  303. package/es6/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js.map +1 -1
  304. package/es6/findNumbers/parsePreCandidate.js +3 -2
  305. package/es6/findNumbers/parsePreCandidate.js.map +1 -1
  306. package/es6/findNumbers/utf-8.js +5 -3
  307. package/es6/findNumbers/utf-8.js.map +1 -1
  308. package/es6/findNumbers/util.js +1 -4
  309. package/es6/findNumbers/util.js.map +1 -1
  310. package/es6/findNumbers/util.test.js +9 -14
  311. package/es6/findNumbers/util.test.js.map +1 -1
  312. package/es6/findPhoneNumbersInText.js +9 -12
  313. package/es6/findPhoneNumbersInText.js.map +1 -1
  314. package/es6/findPhoneNumbersInText.test.js +101 -91
  315. package/es6/findPhoneNumbersInText.test.js.map +1 -1
  316. package/es6/format.js +27 -50
  317. package/es6/format.js.map +1 -1
  318. package/es6/format.test.js +133 -116
  319. package/es6/format.test.js.map +1 -1
  320. package/es6/formatIncompletePhoneNumber.js +1 -2
  321. package/es6/formatIncompletePhoneNumber.js.map +1 -1
  322. package/es6/formatIncompletePhoneNumber.test.js +14 -10
  323. package/es6/formatIncompletePhoneNumber.test.js.map +1 -1
  324. package/es6/formatPhoneNumberForMobileDialing.js +31 -24
  325. package/es6/formatPhoneNumberForMobileDialing.js.map +1 -1
  326. package/es6/getCountries.js.map +1 -1
  327. package/es6/getCountries.test.js +2 -2
  328. package/es6/getCountries.test.js.map +1 -1
  329. package/es6/getCountryCallingCode.js.map +1 -1
  330. package/es6/getCountryCallingCode.test.js +2 -2
  331. package/es6/getCountryCallingCode.test.js.map +1 -1
  332. package/es6/getExampleNumber.js.map +1 -1
  333. package/es6/getExampleNumber.test.js +6 -6
  334. package/es6/getExampleNumber.test.js.map +1 -1
  335. package/es6/helpers/RFC3966.js +17 -34
  336. package/es6/helpers/RFC3966.js.map +1 -1
  337. package/es6/helpers/RFC3966.test.js +16 -13
  338. package/es6/helpers/RFC3966.test.js.map +1 -1
  339. package/es6/helpers/applyInternationalSeparatorStyle.js +3 -2
  340. package/es6/helpers/applyInternationalSeparatorStyle.js.map +1 -1
  341. package/es6/helpers/applyInternationalSeparatorStyle.test.js +2 -2
  342. package/es6/helpers/applyInternationalSeparatorStyle.test.js.map +1 -1
  343. package/es6/helpers/checkNumberLength.js +17 -17
  344. package/es6/helpers/checkNumberLength.js.map +1 -1
  345. package/es6/helpers/checkNumberLength.test.js +20 -23
  346. package/es6/helpers/checkNumberLength.test.js.map +1 -1
  347. package/es6/helpers/extension/createExtensionPattern.js +21 -34
  348. package/es6/helpers/extension/createExtensionPattern.js.map +1 -1
  349. package/es6/helpers/extension/extractExtension.js +7 -9
  350. package/es6/helpers/extension/extractExtension.js.map +1 -1
  351. package/es6/helpers/extractCountryCallingCode.js +14 -18
  352. package/es6/helpers/extractCountryCallingCode.js.map +1 -1
  353. package/es6/helpers/extractCountryCallingCode.test.js +4 -4
  354. package/es6/helpers/extractCountryCallingCode.test.js.map +1 -1
  355. package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +4 -9
  356. package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -1
  357. package/es6/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js +14 -19
  358. package/es6/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js.map +1 -1
  359. package/es6/helpers/extractNationalNumber.js +10 -15
  360. package/es6/helpers/extractNationalNumber.js.map +1 -1
  361. package/es6/helpers/extractNationalNumber.test.js +2 -4
  362. package/es6/helpers/extractNationalNumber.test.js.map +1 -1
  363. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +12 -17
  364. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -1
  365. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +2 -2
  366. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js.map +1 -1
  367. package/es6/helpers/extractPhoneContext.js +17 -17
  368. package/es6/helpers/extractPhoneContext.js.map +1 -1
  369. package/es6/helpers/extractPhoneContext.test.js +12 -12
  370. package/es6/helpers/extractPhoneContext.test.js.map +1 -1
  371. package/es6/helpers/formatNationalNumberUsingFormat.js +8 -8
  372. package/es6/helpers/formatNationalNumberUsingFormat.js.map +1 -1
  373. package/es6/helpers/getCountryByCallingCode.js +4 -9
  374. package/es6/helpers/getCountryByCallingCode.js.map +1 -1
  375. package/es6/helpers/getCountryByNationalNumber.js +17 -15
  376. package/es6/helpers/getCountryByNationalNumber.js.map +1 -1
  377. package/es6/helpers/getIddPrefix.js +3 -4
  378. package/es6/helpers/getIddPrefix.js.map +1 -1
  379. package/es6/helpers/getNumberType.js +22 -29
  380. package/es6/helpers/getNumberType.js.map +1 -1
  381. package/es6/helpers/getNumberType.test.js +4 -4
  382. package/es6/helpers/getNumberType.test.js.map +1 -1
  383. package/es6/helpers/getPossibleCountriesForNumber.js +1 -8
  384. package/es6/helpers/getPossibleCountriesForNumber.js.map +1 -1
  385. package/es6/helpers/isObject.js.map +1 -1
  386. package/es6/helpers/isViablePhoneNumber.js +21 -13
  387. package/es6/helpers/isViablePhoneNumber.js.map +1 -1
  388. package/es6/helpers/matchesEntirely.js.map +1 -1
  389. package/es6/helpers/matchesEntirely.test.js +3 -2
  390. package/es6/helpers/matchesEntirely.test.js.map +1 -1
  391. package/es6/helpers/mergeArrays.js +6 -10
  392. package/es6/helpers/mergeArrays.js.map +1 -1
  393. package/es6/helpers/mergeArrays.test.js +1 -1
  394. package/es6/helpers/mergeArrays.test.js.map +1 -1
  395. package/es6/helpers/parseDigits.js +6 -12
  396. package/es6/helpers/parseDigits.js.map +1 -1
  397. package/es6/helpers/parseDigits.test.js +1 -1
  398. package/es6/helpers/parseDigits.test.js.map +1 -1
  399. package/es6/helpers/stripIddPrefix.js +6 -11
  400. package/es6/helpers/stripIddPrefix.js.map +1 -1
  401. package/es6/helpers/stripIddPrefix.test.js +4 -4
  402. package/es6/helpers/stripIddPrefix.test.js.map +1 -1
  403. package/es6/isPossible.js +3 -10
  404. package/es6/isPossible.js.map +1 -1
  405. package/es6/isPossible.test.js +34 -38
  406. package/es6/isPossible.test.js.map +1 -1
  407. package/es6/isPossiblePhoneNumber.js +9 -10
  408. package/es6/isPossiblePhoneNumber.js.map +1 -1
  409. package/es6/isPossiblePhoneNumber.test.js +12 -16
  410. package/es6/isPossiblePhoneNumber.test.js.map +1 -1
  411. package/es6/isValid.js +7 -6
  412. package/es6/isValid.js.map +1 -1
  413. package/es6/isValid.test.js +59 -55
  414. package/es6/isValid.test.js.map +1 -1
  415. package/es6/isValidPhoneNumber.js +9 -10
  416. package/es6/isValidPhoneNumber.js.map +1 -1
  417. package/es6/isValidPhoneNumber.test.js +10 -13
  418. package/es6/isValidPhoneNumber.test.js.map +1 -1
  419. package/es6/legacy/findNumbers.js +3 -6
  420. package/es6/legacy/findNumbers.js.map +1 -1
  421. package/es6/legacy/findNumbers.test.js +77 -60
  422. package/es6/legacy/findNumbers.test.js.map +1 -1
  423. package/es6/legacy/findPhoneNumbers.js +8 -9
  424. package/es6/legacy/findPhoneNumbers.js.map +1 -1
  425. package/es6/legacy/findPhoneNumbers.test.js +73 -62
  426. package/es6/legacy/findPhoneNumbers.test.js.map +1 -1
  427. package/es6/legacy/findPhoneNumbersInitialImplementation.js +32 -45
  428. package/es6/legacy/findPhoneNumbersInitialImplementation.js.map +1 -1
  429. package/es6/legacy/format.js +27 -37
  430. package/es6/legacy/format.js.map +1 -1
  431. package/es6/legacy/format.test.js +119 -101
  432. package/es6/legacy/format.test.js.map +1 -1
  433. package/es6/legacy/getNumberType.js +31 -37
  434. package/es6/legacy/getNumberType.js.map +1 -1
  435. package/es6/legacy/getNumberType.test.js +31 -31
  436. package/es6/legacy/getNumberType.test.js.map +1 -1
  437. package/es6/legacy/isPossibleNumber.js +5 -7
  438. package/es6/legacy/isPossibleNumber.js.map +1 -1
  439. package/es6/legacy/isPossibleNumber.test.js +22 -23
  440. package/es6/legacy/isPossibleNumber.test.js.map +1 -1
  441. package/es6/legacy/isValidNumber.js +6 -7
  442. package/es6/legacy/isValidNumber.js.map +1 -1
  443. package/es6/legacy/isValidNumber.test.js +41 -37
  444. package/es6/legacy/isValidNumber.test.js.map +1 -1
  445. package/es6/legacy/isValidNumberForRegion.js +5 -7
  446. package/es6/legacy/isValidNumberForRegion.js.map +1 -1
  447. package/es6/legacy/isValidNumberForRegion.test.js +6 -8
  448. package/es6/legacy/isValidNumberForRegion.test.js.map +1 -1
  449. package/es6/legacy/isValidNumberForRegion_.js +1 -1
  450. package/es6/legacy/isValidNumberForRegion_.js.map +1 -1
  451. package/es6/legacy/parse.js +3 -4
  452. package/es6/legacy/parse.js.map +1 -1
  453. package/es6/legacy/parse.test.js +232 -190
  454. package/es6/legacy/parse.test.js.map +1 -1
  455. package/es6/legacy/searchNumbers.js +8 -8
  456. package/es6/legacy/searchNumbers.js.map +1 -1
  457. package/es6/legacy/searchNumbers.test.js +6 -11
  458. package/es6/legacy/searchNumbers.test.js.map +1 -1
  459. package/es6/metadata.js +86 -114
  460. package/es6/metadata.js.map +1 -1
  461. package/es6/metadata.test.js +57 -73
  462. package/es6/metadata.test.js.map +1 -1
  463. package/es6/normalizeArguments.js +26 -32
  464. package/es6/normalizeArguments.js.map +1 -1
  465. package/es6/parse.js +66 -94
  466. package/es6/parse.js.map +1 -1
  467. package/es6/parse.test.js +243 -202
  468. package/es6/parse.test.js.map +1 -1
  469. package/es6/parseIncompletePhoneNumber.js +9 -16
  470. package/es6/parseIncompletePhoneNumber.js.map +1 -1
  471. package/es6/parseIncompletePhoneNumber.test.js +22 -18
  472. package/es6/parseIncompletePhoneNumber.test.js.map +1 -1
  473. package/es6/parsePhoneNumber.js +3 -4
  474. package/es6/parsePhoneNumber.js.map +1 -1
  475. package/es6/parsePhoneNumber.test.js +14 -23
  476. package/es6/parsePhoneNumber.test.js.map +1 -1
  477. package/es6/parsePhoneNumberWithError.js +3 -4
  478. package/es6/parsePhoneNumberWithError.js.map +1 -1
  479. package/es6/parsePhoneNumberWithError.test.js +31 -32
  480. package/es6/parsePhoneNumberWithError.test.js.map +1 -1
  481. package/es6/parsePhoneNumberWithError_.js +6 -6
  482. package/es6/parsePhoneNumberWithError_.js.map +1 -1
  483. package/es6/parsePhoneNumber_.js +10 -10
  484. package/es6/parsePhoneNumber_.js.map +1 -1
  485. package/es6/searchPhoneNumbersInText.js +9 -11
  486. package/es6/searchPhoneNumbersInText.js.map +1 -1
  487. package/es6/searchPhoneNumbersInText.test.js +11 -18
  488. package/es6/searchPhoneNumbersInText.test.js.map +1 -1
  489. package/es6/tools/semver-compare.js +0 -3
  490. package/es6/tools/semver-compare.js.map +1 -1
  491. package/es6/tools/semver-compare.test.js +1 -1
  492. package/es6/tools/semver-compare.test.js.map +1 -1
  493. package/es6/validatePhoneNumberLength.js +11 -12
  494. package/es6/validatePhoneNumberLength.js.map +1 -1
  495. package/es6/validatePhoneNumberLength.test.js +14 -14
  496. package/es6/validatePhoneNumberLength.test.js.map +1 -1
  497. package/jest.config.json +26 -0
  498. package/max/metadata/metadata.max.json +1 -0
  499. package/max/metadata/metadata.max.json.d.cts +4 -0
  500. package/max/metadata/metadata.max.json.d.ts +4 -0
  501. package/max/metadata/metadata.max.json.js +4 -0
  502. package/max/metadata/package.json +6 -6
  503. package/metadata.full.json +1 -1
  504. package/metadata.full.json.js +1 -1
  505. package/metadata.max.json +1 -1
  506. package/metadata.max.json.js +1 -1
  507. package/metadata.min.json +1 -1
  508. package/metadata.min.json.js +1 -1
  509. package/metadata.mobile.json +1 -1
  510. package/metadata.mobile.json.js +1 -1
  511. package/min/metadata/metadata.min.json +1 -0
  512. package/min/metadata/metadata.min.json.d.cts +4 -0
  513. package/min/metadata/metadata.min.json.d.ts +4 -0
  514. package/min/metadata/metadata.min.json.js +4 -0
  515. package/min/metadata/package.json +6 -6
  516. package/mobile/examples/examples.mobile.json +1 -0
  517. package/mobile/examples/examples.mobile.json.d.cts +4 -0
  518. package/mobile/examples/examples.mobile.json.d.ts +4 -0
  519. package/mobile/examples/examples.mobile.json.js +4 -0
  520. package/mobile/examples/package.json +6 -6
  521. package/mobile/metadata/metadata.mobile.json +1 -0
  522. package/mobile/metadata/metadata.mobile.json.d.cts +4 -0
  523. package/mobile/metadata/metadata.mobile.json.d.ts +4 -0
  524. package/mobile/metadata/metadata.mobile.json.js +4 -0
  525. package/mobile/metadata/package.json +6 -6
  526. package/package.json +43 -27
  527. package/rollup.config.mjs +2 -2
  528. package/runnable/generate-country-codes.js +1 -1
  529. package/source/AsYouType.test.js +414 -414
  530. package/source/AsYouTypeFormatter.PatternMatcher.test.js +91 -91
  531. package/source/AsYouTypeFormatter.PatternParser.test.js +6 -6
  532. package/source/AsYouTypeFormatter.util.test.js +6 -6
  533. package/source/PhoneNumber.test.js +34 -29
  534. package/source/PhoneNumberMatcher.js +8 -9
  535. package/source/PhoneNumberMatcher.test.js +18 -6
  536. package/source/findNumbers/Leniency.js +0 -1
  537. package/source/findNumbers/util.test.js +14 -19
  538. package/source/findPhoneNumbersInText.test.js +98 -53
  539. package/source/format.test.js +70 -65
  540. package/source/formatIncompletePhoneNumber.test.js +11 -7
  541. package/source/formatPhoneNumberForMobileDialing.js +16 -1
  542. package/source/getCountries.test.js +2 -2
  543. package/source/getCountryCallingCode.test.js +2 -2
  544. package/source/getExampleNumber.test.js +6 -6
  545. package/source/helpers/RFC3966.test.js +8 -8
  546. package/source/helpers/applyInternationalSeparatorStyle.test.js +2 -2
  547. package/source/helpers/checkNumberLength.test.js +11 -11
  548. package/source/helpers/extractCountryCallingCode.test.js +4 -4
  549. package/source/helpers/extractNationalNumber.test.js +2 -2
  550. package/source/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +2 -2
  551. package/source/helpers/extractPhoneContext.test.js +1 -1
  552. package/source/helpers/getNumberType.test.js +4 -4
  553. package/source/helpers/matchesEntirely.test.js +2 -2
  554. package/source/helpers/mergeArrays.test.js +1 -1
  555. package/source/helpers/parseDigits.test.js +1 -1
  556. package/source/helpers/stripIddPrefix.test.js +4 -4
  557. package/source/isPossible.test.js +16 -10
  558. package/source/isPossiblePhoneNumber.test.js +12 -13
  559. package/source/isValid.test.js +20 -20
  560. package/source/isValidPhoneNumber.test.js +9 -9
  561. package/source/legacy/findNumbers.test.js +57 -44
  562. package/source/legacy/findPhoneNumbers.test.js +51 -35
  563. package/source/legacy/format.test.js +74 -71
  564. package/source/legacy/getNumberType.test.js +20 -18
  565. package/source/legacy/isPossibleNumber.test.js +16 -10
  566. package/source/legacy/isValidNumber.test.js +25 -23
  567. package/source/legacy/isValidNumberForRegion.test.js +5 -5
  568. package/source/legacy/parse.test.js +113 -116
  569. package/source/legacy/searchNumbers.test.js +3 -3
  570. package/source/metadata.test.js +61 -49
  571. package/source/parse.test.js +115 -118
  572. package/source/parseIncompletePhoneNumber.test.js +13 -13
  573. package/source/parsePhoneNumber.test.js +14 -14
  574. package/source/parsePhoneNumberWithError.test.js +25 -25
  575. package/source/searchPhoneNumbersInText.test.js +8 -8
  576. package/source/tools/semver-compare.test.js +1 -1
  577. package/source/validatePhoneNumberLength.test.js +10 -10
  578. package/build/findNumbers/Leniency.test.js +0 -37
  579. package/build/findNumbers/Leniency.test.js.map +0 -1
  580. package/build/formatPhoneNumberForMobileDialing.test.js +0 -15
  581. package/build/formatPhoneNumberForMobileDialing.test.js.map +0 -1
  582. package/es6/findNumbers/Leniency.test.js +0 -36
  583. package/es6/findNumbers/Leniency.test.js.map +0 -1
  584. package/es6/formatPhoneNumberForMobileDialing.test.js +0 -14
  585. package/es6/formatPhoneNumberForMobileDialing.test.js.map +0 -1
  586. package/source/findNumbers/Leniency.test.js +0 -35
  587. package/source/formatPhoneNumberForMobileDialing.test.js +0 -16
@@ -1 +1 @@
1
- {"version":3,"file":"AsYouTypeFormatter.js","names":["DIGIT_PLACEHOLDER","countOccurences","repeat","cutAndStripNonPairedParens","closeNonPairedParens","stripNonPairedParens","populateTemplateWithDigits","formatCompleteNumber","canFormatCompleteNumber","PatternMatcher","parseDigits","FIRST_GROUP_PATTERN","VALID_PUNCTUATION","applyInternationalSeparatorStyle","DUMMY_DIGIT","LONGEST_NATIONAL_PHONE_NUMBER_LENGTH","LONGEST_DUMMY_PHONE_NUMBER","NATIONAL_PREFIX_SEPARATORS_PATTERN","SUPPORT_LEGACY_FORMATTING_PATTERNS","CREATE_CHARACTER_CLASS_PATTERN","CREATE_STANDALONE_DIGIT_PATTERN","NON_ALTERING_FORMAT_REG_EXP","RegExp","MIN_LEADING_DIGITS_LENGTH","AsYouTypeFormatter","state","metadata","resetFormat","chosenFormat","undefined","template","nationalNumberTemplate","populatedNationalNumberTemplate","populatedNationalNumberTemplatePosition","numberingPlan","isNANP","callingCode","matchingFormats","formats","nationalSignificantNumber","narrowDownMatchingFormats","nextDigits","format","formattedCompleteNumber","shouldTryNationalPrefixFormattingRule","international","nationalPrefix","getSeparatorAfterNationalPrefix","setNationalNumberTemplate","replace","lastIndexOf","formatNationalNumberWithNextDigits","previouslyChosenFormat","newlyChosenFormat","chooseFormat","formatNextNationalNumberDigits","getNationalDigits","leadingDigits","leadingDigitsPatternIndex","length","filter","formatSuits","formatMatches","indexOf","usesNationalPrefix","nationalPrefixIsOptionalWhenFormattingInNationalFormat","nationalPrefixIsMandatoryWhenFormattingInNationalFormat","leadingDigitsPatternsCount","leadingDigitsPatterns","Math","min","leadingDigitsPattern","match","allowOverflow","error","console","test","internationalFormat","getFormatFormat","createTemplateForFormat","_","slice","pattern","getTemplateForFormat","nationalPrefixFormattingRule","options","IDDPrefix","missingPlus","spacing","index","i","internationalPrefix","getInternationalPrefixBeforeCountryCallingCode","getDigitsWithoutInternationalPrefix","complexPrefixBeforeNationalSignificantNumber","digits","strictPattern","nationalNumberDummyDigits","numberFormat","nationalPrefixIncludedInTemplate","numberFormatWithNationalPrefix","result"],"sources":["../source/AsYouTypeFormatter.js"],"sourcesContent":["import {\r\n\tDIGIT_PLACEHOLDER,\r\n\tcountOccurences,\r\n\trepeat,\r\n\tcutAndStripNonPairedParens,\r\n\tcloseNonPairedParens,\r\n\tstripNonPairedParens,\r\n\tpopulateTemplateWithDigits\r\n} from './AsYouTypeFormatter.util.js'\r\n\r\nimport formatCompleteNumber, {\r\n\tcanFormatCompleteNumber\r\n} from './AsYouTypeFormatter.complete.js'\r\n\r\nimport PatternMatcher from './AsYouTypeFormatter.PatternMatcher.js'\r\n\r\nimport parseDigits from './helpers/parseDigits.js'\r\nexport { DIGIT_PLACEHOLDER } from './AsYouTypeFormatter.util.js'\r\nimport { FIRST_GROUP_PATTERN } from './helpers/formatNationalNumberUsingFormat.js'\r\nimport { VALID_PUNCTUATION } from './constants.js'\r\nimport applyInternationalSeparatorStyle from './helpers/applyInternationalSeparatorStyle.js'\r\n\r\n// Used in phone number format template creation.\r\n// Could be any digit, I guess.\r\nconst DUMMY_DIGIT = '9'\r\n// I don't know why is it exactly `15`\r\nconst LONGEST_NATIONAL_PHONE_NUMBER_LENGTH = 15\r\n// Create a phone number consisting only of the digit 9 that matches the\r\n// `number_pattern` by applying the pattern to the \"longest phone number\" string.\r\nconst LONGEST_DUMMY_PHONE_NUMBER = repeat(DUMMY_DIGIT, LONGEST_NATIONAL_PHONE_NUMBER_LENGTH)\r\n\r\n// A set of characters that, if found in a national prefix formatting rules, are an indicator to\r\n// us that we should separate the national prefix from the number when formatting.\r\nconst NATIONAL_PREFIX_SEPARATORS_PATTERN = /[- ]/\r\n\r\n// Deprecated: Google has removed some formatting pattern related code from their repo.\r\n// https://github.com/googlei18n/libphonenumber/commit/a395b4fef3caf57c4bc5f082e1152a4d2bd0ba4c\r\n// \"We no longer have numbers in formatting matching patterns, only \\d.\"\r\n// Because this library supports generating custom metadata\r\n// some users may still be using old metadata so the relevant\r\n// code seems to stay until some next major version update.\r\nconst SUPPORT_LEGACY_FORMATTING_PATTERNS = true\r\n\r\n// A pattern that is used to match character classes in regular expressions.\r\n// An example of a character class is \"[1-4]\".\r\nconst CREATE_CHARACTER_CLASS_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && (() => /\\[([^\\[\\]])*\\]/g)\r\n\r\n// Any digit in a regular expression that actually denotes a digit. For\r\n// example, in the regular expression \"80[0-2]\\d{6,10}\", the first 2 digits\r\n// (8 and 0) are standalone digits, but the rest are not.\r\n// Two look-aheads are needed because the number following \\\\d could be a\r\n// two-digit number, since the phone number can be as long as 15 digits.\r\nconst CREATE_STANDALONE_DIGIT_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && (() => /\\d(?=[^,}][^,}])/g)\r\n\r\n// A regular expression that is used to determine if a `format` is\r\n// suitable to be used in the \"as you type formatter\".\r\n// A `format` is suitable when the resulting formatted number has\r\n// the same digits as the user has entered.\r\n//\r\n// In the simplest case, that would mean that the format\r\n// doesn't add any additional digits when formatting a number.\r\n// Google says that it also shouldn't add \"star\" (`*`) characters,\r\n// like it does in some Israeli formats.\r\n// Such basic format would only contain \"valid punctuation\"\r\n// and \"captured group\" identifiers ($1, $2, etc).\r\n//\r\n// An example of a format that adds additional digits:\r\n//\r\n// Country: `AR` (Argentina).\r\n// Format:\r\n// {\r\n// \"pattern\": \"(\\\\d)(\\\\d{2})(\\\\d{4})(\\\\d{4})\",\r\n// \"leading_digits_patterns\": [\"91\"],\r\n// \"national_prefix_formatting_rule\": \"0$1\",\r\n// \"format\": \"$2 15-$3-$4\",\r\n// \"international_format\": \"$1 $2 $3-$4\"\r\n// }\r\n//\r\n// In the format above, the `format` adds `15` to the digits when formatting a number.\r\n// A sidenote: this format actually is suitable because `national_prefix_for_parsing`\r\n// has previously removed `15` from a national number, so re-adding `15` in `format`\r\n// doesn't actually result in any extra digits added to user's input.\r\n// But verifying that would be a complex procedure, so the code chooses a simpler path:\r\n// it simply filters out all `format`s that contain anything but \"captured group\" ids.\r\n//\r\n// This regular expression is called `ELIGIBLE_FORMAT_PATTERN` in Google's\r\n// `libphonenumber` code.\r\n//\r\nconst NON_ALTERING_FORMAT_REG_EXP = new RegExp(\r\n\t'[' + VALID_PUNCTUATION + ']*' +\r\n\t// Google developers say:\r\n\t// \"We require that the first matching group is present in the\r\n\t// output pattern to ensure no data is lost while formatting.\"\r\n\t'\\\\$1' +\r\n\t'[' + VALID_PUNCTUATION + ']*' +\r\n\t'(\\\\$\\\\d[' + VALID_PUNCTUATION + ']*)*' +\r\n\t'$'\r\n)\r\n\r\n// This is the minimum length of the leading digits of a phone number\r\n// to guarantee the first \"leading digits pattern\" for a phone number format\r\n// to be preemptive.\r\nconst MIN_LEADING_DIGITS_LENGTH = 3\r\n\r\nexport default class AsYouTypeFormatter {\r\n\tconstructor({\r\n\t\tstate,\r\n\t\tmetadata\r\n\t}) {\r\n\t\tthis.metadata = metadata\r\n\t\tthis.resetFormat()\r\n\t}\r\n\r\n\tresetFormat() {\r\n\t\tthis.chosenFormat = undefined\r\n\t\tthis.template = undefined\r\n\t\tthis.nationalNumberTemplate = undefined\r\n\t\tthis.populatedNationalNumberTemplate = undefined\r\n\t\tthis.populatedNationalNumberTemplatePosition = -1\r\n\t}\r\n\r\n\treset(numberingPlan, state) {\r\n\t\tthis.resetFormat()\r\n\t\tif (numberingPlan) {\r\n\t\t\tthis.isNANP = numberingPlan.callingCode() === '1'\r\n\t\t\tthis.matchingFormats = numberingPlan.formats()\r\n\t\t\tif (state.nationalSignificantNumber) {\r\n\t\t\t\tthis.narrowDownMatchingFormats(state)\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tthis.isNANP = undefined\r\n\t\t\tthis.matchingFormats = []\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Formats an updated phone number.\r\n\t * @param {string} nextDigits — Additional phone number digits.\r\n\t * @param {object} state — `AsYouType` state.\r\n\t * @return {[string]} Returns undefined if the updated phone number can't be formatted using any of the available formats.\r\n\t */\r\n\tformat(nextDigits, state) {\r\n\t\t// See if the phone number digits can be formatted as a complete phone number.\r\n\t\t// If not, use the results from `formatNationalNumberWithNextDigits()`,\r\n\t\t// which formats based on the chosen formatting pattern.\r\n\t\t//\r\n\t\t// Attempting to format complete phone number first is how it's done\r\n\t\t// in Google's `libphonenumber`, so this library just follows it.\r\n\t\t// Google's `libphonenumber` code doesn't explain in detail why does it\r\n\t\t// attempt to format digits as a complete phone number\r\n\t\t// instead of just going with a previoulsy (or newly) chosen `format`:\r\n\t\t//\r\n\t\t// \"Checks to see if there is an exact pattern match for these digits.\r\n\t\t// If so, we should use this instead of any other formatting template\r\n\t\t// whose leadingDigitsPattern also matches the input.\"\r\n\t\t//\r\n\t\tif (canFormatCompleteNumber(state.nationalSignificantNumber, this.metadata)) {\r\n\t\t\tfor (const format of this.matchingFormats) {\r\n\t\t\t\tconst formattedCompleteNumber = formatCompleteNumber(\r\n\t\t\t\t\tstate,\r\n\t\t\t\t\tformat,\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tmetadata: this.metadata,\r\n\t\t\t\t\t\tshouldTryNationalPrefixFormattingRule: (format) => this.shouldTryNationalPrefixFormattingRule(format, {\r\n\t\t\t\t\t\t\tinternational: state.international,\r\n\t\t\t\t\t\t\tnationalPrefix: state.nationalPrefix\r\n\t\t\t\t\t\t}),\r\n\t\t\t\t\t\tgetSeparatorAfterNationalPrefix: (format) => this.getSeparatorAfterNationalPrefix(format)\r\n\t\t\t\t\t}\r\n\t\t\t\t)\r\n\t\t\t\tif (formattedCompleteNumber) {\r\n\t\t\t\t\tthis.resetFormat()\r\n\t\t\t\t\tthis.chosenFormat = format\r\n\t\t\t\t\tthis.setNationalNumberTemplate(formattedCompleteNumber.replace(/\\d/g, DIGIT_PLACEHOLDER), state)\r\n\t\t\t\t\tthis.populatedNationalNumberTemplate = formattedCompleteNumber\r\n\t\t\t\t\t// With a new formatting template, the matched position\r\n\t\t\t\t\t// using the old template needs to be reset.\r\n\t\t\t\t\tthis.populatedNationalNumberTemplatePosition = this.template.lastIndexOf(DIGIT_PLACEHOLDER)\r\n\t\t\t\t\treturn formattedCompleteNumber\r\n\t\t\t\t}\r\n\r\n\t\t\t}\r\n\t\t}\r\n\t\t// Format the digits as a partial (incomplete) phone number\r\n\t\t// using the previously chosen formatting pattern (or a newly chosen one).\r\n\t\treturn this.formatNationalNumberWithNextDigits(nextDigits, state)\r\n\t}\r\n\r\n\t// Formats the next phone number digits.\r\n\tformatNationalNumberWithNextDigits(nextDigits, state) {\r\n\t\tconst previouslyChosenFormat = this.chosenFormat\r\n\r\n\t\t// Choose a format from the list of matching ones.\r\n\t\tconst newlyChosenFormat = this.chooseFormat(state)\r\n\r\n\t\tif (newlyChosenFormat) {\r\n\t\t\tif (newlyChosenFormat === previouslyChosenFormat) {\r\n\t\t\t\t// If it can format the next (current) digits\r\n\t\t\t\t// using the previously chosen phone number format\r\n\t\t\t\t// then return the updated formatted number.\r\n\t\t\t\treturn this.formatNextNationalNumberDigits(nextDigits)\r\n\t\t\t} else {\r\n\t\t\t\t// If a more appropriate phone number format\r\n\t\t\t\t// has been chosen for these \"leading digits\",\r\n\t\t\t\t// then re-format the national phone number part\r\n\t\t\t\t// using the newly selected format.\r\n\t\t\t\treturn this.formatNextNationalNumberDigits(state.getNationalDigits())\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tnarrowDownMatchingFormats({\r\n\t\tnationalSignificantNumber,\r\n\t\tnationalPrefix,\r\n\t\tinternational\r\n\t}) {\r\n\t\tconst leadingDigits = nationalSignificantNumber\r\n\r\n\t\t// \"leading digits\" pattern list starts with a\r\n\t\t// \"leading digits\" pattern fitting a maximum of 3 leading digits.\r\n\t\t// So, after a user inputs 3 digits of a national (significant) phone number\r\n\t\t// this national (significant) number can already be formatted.\r\n\t\t// The next \"leading digits\" pattern is for 4 leading digits max,\r\n\t\t// and the \"leading digits\" pattern after it is for 5 leading digits max, etc.\r\n\r\n\t\t// This implementation is different from Google's\r\n\t\t// in that it searches for a fitting format\r\n\t\t// even if the user has entered less than\r\n\t\t// `MIN_LEADING_DIGITS_LENGTH` digits of a national number.\r\n\t\t// Because some leading digit patterns already match for a single first digit.\r\n\t\tlet leadingDigitsPatternIndex = leadingDigits.length - MIN_LEADING_DIGITS_LENGTH\r\n\t\tif (leadingDigitsPatternIndex < 0) {\r\n\t\t\tleadingDigitsPatternIndex = 0\r\n\t\t}\r\n\r\n\t\tthis.matchingFormats = this.matchingFormats.filter(\r\n\t\t\tformat => this.formatSuits(format, international, nationalPrefix)\r\n\t\t\t\t&& this.formatMatches(format, leadingDigits, leadingDigitsPatternIndex)\r\n\t\t)\r\n\r\n\t\t// If there was a phone number format chosen\r\n\t\t// and it no longer holds given the new leading digits then reset it.\r\n\t\t// The test for this `if` condition is marked as:\r\n\t\t// \"Reset a chosen format when it no longer holds given the new leading digits\".\r\n\t\t// To construct a valid test case for this one can find a country\r\n\t\t// in `PhoneNumberMetadata.xml` yielding one format for 3 `<leadingDigits>`\r\n\t\t// and yielding another format for 4 `<leadingDigits>` (Australia in this case).\r\n\t\tif (this.chosenFormat && this.matchingFormats.indexOf(this.chosenFormat) === -1) {\r\n\t\t\tthis.resetFormat()\r\n\t\t}\r\n\t}\r\n\r\n\tformatSuits(format, international, nationalPrefix) {\r\n\t\t// When a prefix before a national (significant) number is\r\n\t\t// simply a national prefix, then it's parsed as `this.nationalPrefix`.\r\n\t\t// In more complex cases, a prefix before national (significant) number\r\n\t\t// could include a national prefix as well as some \"capturing groups\",\r\n\t\t// and in that case there's no info whether a national prefix has been parsed.\r\n\t\t// If national prefix is not used when formatting a phone number\r\n\t\t// using this format, but a national prefix has been entered by the user,\r\n\t\t// and was extracted, then discard such phone number format.\r\n\t\t// In Google's \"AsYouType\" formatter code, the equivalent would be this part:\r\n\t\t// https://github.com/google/libphonenumber/blob/0a45cfd96e71cad8edb0e162a70fcc8bd9728933/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java#L175-L184\r\n\t\tif (nationalPrefix &&\r\n\t\t\t!format.usesNationalPrefix() &&\r\n\t\t\t// !format.domesticCarrierCodeFormattingRule() &&\r\n\t\t\t!format.nationalPrefixIsOptionalWhenFormattingInNationalFormat()) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\t// If national prefix is mandatory for this phone number format\r\n\t\t// and there're no guarantees that a national prefix is present in user input\r\n\t\t// then discard this phone number format as not suitable.\r\n\t\t// In Google's \"AsYouType\" formatter code, the equivalent would be this part:\r\n\t\t// https://github.com/google/libphonenumber/blob/0a45cfd96e71cad8edb0e162a70fcc8bd9728933/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java#L185-L193\r\n\t\tif (!international &&\r\n\t\t\t!nationalPrefix &&\r\n\t\t\tformat.nationalPrefixIsMandatoryWhenFormattingInNationalFormat()) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\treturn true\r\n\t}\r\n\r\n\tformatMatches(format, leadingDigits, leadingDigitsPatternIndex) {\r\n\t\tconst leadingDigitsPatternsCount = format.leadingDigitsPatterns().length\r\n\r\n\t\t// If this format is not restricted to a certain\r\n\t\t// leading digits pattern then it fits.\r\n\t\t// The test case could be found by searching for \"leadingDigitsPatternsCount === 0\".\r\n\t\tif (leadingDigitsPatternsCount === 0) {\r\n\t\t\treturn true\r\n\t\t}\r\n\r\n\t\t// Start narrowing down the list of possible formats based on the leading digits.\r\n\t\t// (only previously matched formats take part in the narrowing down process)\r\n\r\n\t\t// `leading_digits_patterns` start with 3 digits min\r\n\t\t// and then go up from there one digit at a time.\r\n\t\tleadingDigitsPatternIndex = Math.min(leadingDigitsPatternIndex, leadingDigitsPatternsCount - 1)\r\n\t\tconst leadingDigitsPattern = format.leadingDigitsPatterns()[leadingDigitsPatternIndex]\r\n\r\n\t\t// Google imposes a requirement on the leading digits\r\n\t\t// to be minimum 3 digits long in order to be eligible\r\n\t\t// for checking those with a leading digits pattern.\r\n\t\t//\r\n\t\t// Since `leading_digits_patterns` start with 3 digits min,\r\n\t\t// Google's original `libphonenumber` library only starts\r\n\t\t// excluding any non-matching formats only when the\r\n\t\t// national number entered so far is at least 3 digits long,\r\n\t\t// otherwise format matching would give false negatives.\r\n\t\t//\r\n\t\t// For example, when the digits entered so far are `2`\r\n\t\t// and the leading digits pattern is `21` –\r\n\t\t// it's quite obvious in this case that the format could be the one\r\n\t\t// but due to the absence of further digits it would give false negative.\r\n\t\t//\r\n\t\t// Also, `leading_digits_patterns` doesn't always correspond to a single\r\n\t\t// digits count. For example, `60|8` pattern would already match `8`\r\n\t\t// but the `60` part would require having at least two leading digits,\r\n\t\t// so the whole pattern would require inputting two digits first in order to\r\n\t\t// decide on whether it matches the input, even when the input is \"80\".\r\n\t\t//\r\n\t\t// This library — `libphonenumber-js` — allows filtering by `leading_digits_patterns`\r\n\t\t// even when there's only 1 or 2 digits of the national (significant) number.\r\n\t\t// To do that, it uses a non-strict pattern matcher written specifically for that.\r\n\t\t//\r\n\t\tif (leadingDigits.length < MIN_LEADING_DIGITS_LENGTH) {\r\n\t\t\t// Before leading digits < 3 matching was implemented:\r\n\t\t\t// return true\r\n\t\t\t//\r\n\t\t\t// After leading digits < 3 matching was implemented:\r\n\t\t\ttry {\r\n\t\t\t\treturn new PatternMatcher(leadingDigitsPattern).match(leadingDigits, { allowOverflow: true }) !== undefined\r\n\t\t\t} catch (error) /* istanbul ignore next */ {\r\n\t\t\t\t// There's a slight possibility that there could be some undiscovered bug\r\n\t\t\t\t// in the pattern matcher code. Since the \"leading digits < 3 matching\"\r\n\t\t\t\t// feature is not \"essential\" for operation, it can fall back to the old way\r\n\t\t\t\t// in case of any issues rather than halting the application's execution.\r\n\t\t\t\tconsole.error(error)\r\n\t\t\t\treturn true\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// If at least `MIN_LEADING_DIGITS_LENGTH` digits of a national number are\r\n\t\t// available then use the usual regular expression matching.\r\n\t\t//\r\n\t\t// The whole pattern is wrapped in round brackets (`()`) because\r\n\t\t// the pattern can use \"or\" operator (`|`) at the top level of the pattern.\r\n\t\t//\r\n\t\treturn new RegExp(`^(${leadingDigitsPattern})`).test(leadingDigits)\r\n\t}\r\n\r\n\tgetFormatFormat(format, international) {\r\n\t\treturn international ? format.internationalFormat() : format.format()\r\n\t}\r\n\r\n\tchooseFormat(state) {\r\n\t\t// When there are multiple available formats, the formatter uses the first\r\n\t\t// format where a formatting template could be created.\r\n\t\t//\r\n\t\t// For some weird reason, `istanbul` says \"else path not taken\"\r\n\t\t// for the `for of` line below. Supposedly that means that\r\n\t\t// the loop doesn't ever go over the last element in the list.\r\n\t\t// That's true because there always is `this.chosenFormat`\r\n\t\t// when `this.matchingFormats` is non-empty.\r\n\t\t// And, for some weird reason, it doesn't think that the case\r\n\t\t// with empty `this.matchingFormats` qualifies for a valid \"else\" path.\r\n\t\t// So simply muting this `istanbul` warning.\r\n\t\t// It doesn't skip the contents of the `for of` loop,\r\n\t\t// it just skips the `for of` line.\r\n\t\t//\r\n\t\t/* istanbul ignore next */\r\n\t\tfor (const format of this.matchingFormats.slice()) {\r\n\t\t\t// If this format is currently being used\r\n\t\t\t// and is still suitable, then stick to it.\r\n\t\t\tif (this.chosenFormat === format) {\r\n\t\t\t\tbreak\r\n\t\t\t}\r\n\t\t\t// Sometimes, a formatting rule inserts additional digits in a phone number,\r\n\t\t\t// and \"as you type\" formatter can't do that: it should only use the digits\r\n\t\t\t// that the user has input.\r\n\t\t\t//\r\n\t\t\t// For example, in Argentina, there's a format for mobile phone numbers:\r\n\t\t\t//\r\n\t\t\t// {\r\n\t\t\t// \"pattern\": \"(\\\\d)(\\\\d{2})(\\\\d{4})(\\\\d{4})\",\r\n\t\t\t// \"leading_digits_patterns\": [\"91\"],\r\n\t\t\t// \"national_prefix_formatting_rule\": \"0$1\",\r\n\t\t\t// \"format\": \"$2 15-$3-$4\",\r\n\t\t\t// \"international_format\": \"$1 $2 $3-$4\"\r\n\t\t\t// }\r\n\t\t\t//\r\n\t\t\t// In that format, `international_format` is used instead of `format`\r\n\t\t\t// because `format` inserts `15` in the formatted number,\r\n\t\t\t// and `AsYouType` formatter should only use the digits\r\n\t\t\t// the user has actually input, without adding any extra digits.\r\n\t\t\t// In this case, it wouldn't make a difference, because the `15`\r\n\t\t\t// is first stripped when applying `national_prefix_for_parsing`\r\n\t\t\t// and then re-added when using `format`, so in reality it doesn't\r\n\t\t\t// add any new digits to the number, but to detect that, the code\r\n\t\t\t// would have to be more complex: it would have to try formatting\r\n\t\t\t// the digits using the format and then see if any digits have\r\n\t\t\t// actually been added or removed, and then, every time a new digit\r\n\t\t\t// is input, it should re-check whether the chosen format doesn't\r\n\t\t\t// alter the digits.\r\n\t\t\t//\r\n\t\t\t// Google's code doesn't go that far, and so does this library:\r\n\t\t\t// it simply requires that a `format` doesn't add any additonal\r\n\t\t\t// digits to user's input.\r\n\t\t\t//\r\n\t\t\t// Also, people in general should move from inputting phone numbers\r\n\t\t\t// in national format (possibly with national prefixes)\r\n\t\t\t// and use international phone number format instead:\r\n\t\t\t// it's a logical thing in the modern age of mobile phones,\r\n\t\t\t// globalization and the internet.\r\n\t\t\t//\r\n\t\t\t/* istanbul ignore if */\r\n\t\t\tif (!NON_ALTERING_FORMAT_REG_EXP.test(this.getFormatFormat(format, state.international))) {\r\n\t\t\t\tcontinue\r\n\t\t\t}\r\n\t\t\tif (!this.createTemplateForFormat(format, state)) {\r\n\t\t\t\t// Remove the format if it can't generate a template.\r\n\t\t\t\tthis.matchingFormats = this.matchingFormats.filter(_ => _ !== format)\r\n\t\t\t\tcontinue\r\n\t\t\t}\r\n\t\t\tthis.chosenFormat = format\r\n\t\t\tbreak\r\n\t\t}\r\n\t\tif (!this.chosenFormat) {\r\n\t\t\t// No format matches the national (significant) phone number.\r\n\t\t\tthis.resetFormat()\r\n\t\t}\r\n\t\treturn this.chosenFormat\r\n\t}\r\n\r\n\tcreateTemplateForFormat(format, state) {\r\n\t\t// The formatter doesn't format numbers when numberPattern contains '|', e.g.\r\n\t\t// (20|3)\\d{4}. In those cases we quickly return.\r\n\t\t// (Though there's no such format in current metadata)\r\n\t\t/* istanbul ignore if */\r\n\t\tif (SUPPORT_LEGACY_FORMATTING_PATTERNS && format.pattern().indexOf('|') >= 0) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\t// Get formatting template for this phone number format\r\n\t\tconst template = this.getTemplateForFormat(format, state)\r\n\t\t// If the national number entered is too long\r\n\t\t// for any phone number format, then abort.\r\n\t\tif (template) {\r\n\t\t\tthis.setNationalNumberTemplate(template, state)\r\n\t\t\treturn true\r\n\t\t}\r\n\t}\r\n\r\n\tgetSeparatorAfterNationalPrefix(format) {\r\n\t\t// `US` metadata doesn't have a `national_prefix_formatting_rule`,\r\n\t\t// so the `if` condition below doesn't apply to `US`,\r\n\t\t// but in reality there shoudl be a separator\r\n\t\t// between a national prefix and a national (significant) number.\r\n\t\t// So `US` national prefix separator is a \"special\" \"hardcoded\" case.\r\n\t\tif (this.isNANP) {\r\n\t\t\treturn ' '\r\n\t\t}\r\n\t\t// If a `format` has a `national_prefix_formatting_rule`\r\n\t\t// and that rule has a separator after a national prefix,\r\n\t\t// then it means that there should be a separator\r\n\t\t// between a national prefix and a national (significant) number.\r\n\t\tif (format &&\r\n\t\t\tformat.nationalPrefixFormattingRule() &&\r\n\t\t\tNATIONAL_PREFIX_SEPARATORS_PATTERN.test(format.nationalPrefixFormattingRule())) {\r\n\t\t\treturn ' '\r\n\t\t}\r\n\t\t// At this point, there seems to be no clear evidence that\r\n\t\t// there should be a separator between a national prefix\r\n\t\t// and a national (significant) number. So don't insert one.\r\n\t\treturn ''\r\n\t}\r\n\r\n\tgetInternationalPrefixBeforeCountryCallingCode({ IDDPrefix, missingPlus }, options) {\r\n\t\tif (IDDPrefix) {\r\n\t\t\treturn options && options.spacing === false ? IDDPrefix : IDDPrefix + ' '\r\n\t\t}\r\n\t\tif (missingPlus) {\r\n\t\t\treturn ''\r\n\t\t}\r\n\t\treturn '+'\r\n\t}\r\n\r\n\tgetTemplate(state) {\r\n\t\tif (!this.template) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\t// `this.template` holds the template for a \"complete\" phone number.\r\n\t\t// The currently entered phone number is most likely not \"complete\",\r\n\t\t// so trim all non-populated digits.\r\n\t\tlet index = -1\r\n\t\tlet i = 0\r\n\t\tconst internationalPrefix = state.international ? this.getInternationalPrefixBeforeCountryCallingCode(state, { spacing: false }) : ''\r\n\t\twhile (i < internationalPrefix.length + state.getDigitsWithoutInternationalPrefix().length) {\r\n\t\t\tindex = this.template.indexOf(DIGIT_PLACEHOLDER, index + 1)\r\n\t\t\ti++\r\n\t\t}\r\n\t\treturn cutAndStripNonPairedParens(this.template, index + 1)\r\n\t}\r\n\r\n\tsetNationalNumberTemplate(template, state) {\r\n\t\tthis.nationalNumberTemplate = template\r\n\t\tthis.populatedNationalNumberTemplate = template\r\n\t\t// With a new formatting template, the matched position\r\n\t\t// using the old template needs to be reset.\r\n\t\tthis.populatedNationalNumberTemplatePosition = -1\r\n\t\t// For convenience, the public `.template` property\r\n\t\t// contains the whole international number\r\n\t\t// if the phone number being input is international:\r\n\t\t// 'x' for the '+' sign, 'x'es for the country phone code,\r\n\t\t// a spacebar and then the template for the formatted national number.\r\n\t\tif (state.international) {\r\n\t\t\tthis.template =\r\n\t\t\t\tthis.getInternationalPrefixBeforeCountryCallingCode(state).replace(/[\\d\\+]/g, DIGIT_PLACEHOLDER) +\r\n\t\t\t\trepeat(DIGIT_PLACEHOLDER, state.callingCode.length) +\r\n\t\t\t\t' ' +\r\n\t\t\t\ttemplate\r\n\t\t} else {\r\n\t\t\tthis.template = template\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Generates formatting template for a national phone number,\r\n\t * optionally containing a national prefix, for a format.\r\n\t * @param {Format} format\r\n\t * @param {string} nationalPrefix\r\n\t * @return {string}\r\n\t */\r\n\tgetTemplateForFormat(format, {\r\n\t\tnationalSignificantNumber,\r\n\t\tinternational,\r\n\t\tnationalPrefix,\r\n\t\tcomplexPrefixBeforeNationalSignificantNumber\r\n\t}) {\r\n\t\tlet pattern = format.pattern()\r\n\r\n\t\t/* istanbul ignore else */\r\n\t\tif (SUPPORT_LEGACY_FORMATTING_PATTERNS) {\r\n\t\t\tpattern = pattern\r\n\t\t\t\t// Replace anything in the form of [..] with \\d\r\n\t\t\t\t.replace(CREATE_CHARACTER_CLASS_PATTERN(), '\\\\d')\r\n\t\t\t\t// Replace any standalone digit (not the one in `{}`) with \\d\r\n\t\t\t\t.replace(CREATE_STANDALONE_DIGIT_PATTERN(), '\\\\d')\r\n\t\t}\r\n\r\n\t\t// Generate a dummy national number (consisting of `9`s)\r\n\t\t// that fits this format's `pattern`.\r\n\t\t//\r\n\t\t// This match will always succeed,\r\n\t\t// because the \"longest dummy phone number\"\r\n\t\t// has enough length to accomodate any possible\r\n\t\t// national phone number format pattern.\r\n\t\t//\r\n\t\tlet digits = LONGEST_DUMMY_PHONE_NUMBER.match(pattern)[0]\r\n\r\n\t\t// If the national number entered is too long\r\n\t\t// for any phone number format, then abort.\r\n\t\tif (nationalSignificantNumber.length > digits.length) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\t// Get a formatting template which can be used to efficiently format\r\n\t\t// a partial number where digits are added one by one.\r\n\r\n\t\t// Below `strictPattern` is used for the\r\n\t\t// regular expression (with `^` and `$`).\r\n\t\t// This wasn't originally in Google's `libphonenumber`\r\n\t\t// and I guess they don't really need it\r\n\t\t// because they're not using \"templates\" to format phone numbers\r\n\t\t// but I added `strictPattern` after encountering\r\n\t\t// South Korean phone number formatting bug.\r\n\t\t//\r\n\t\t// Non-strict regular expression bug demonstration:\r\n\t\t//\r\n\t\t// this.nationalSignificantNumber : `111111111` (9 digits)\r\n\t\t//\r\n\t\t// pattern : (\\d{2})(\\d{3,4})(\\d{4})\r\n\t\t// format : `$1 $2 $3`\r\n\t\t// digits : `9999999999` (10 digits)\r\n\t\t//\r\n\t\t// '9999999999'.replace(new RegExp(/(\\d{2})(\\d{3,4})(\\d{4})/g), '$1 $2 $3') = \"99 9999 9999\"\r\n\t\t//\r\n\t\t// template : xx xxxx xxxx\r\n\t\t//\r\n\t\t// But the correct template in this case is `xx xxx xxxx`.\r\n\t\t// The template was generated incorrectly because of the\r\n\t\t// `{3,4}` variability in the `pattern`.\r\n\t\t//\r\n\t\t// The fix is, if `this.nationalSignificantNumber` has already sufficient length\r\n\t\t// to satisfy the `pattern` completely then `this.nationalSignificantNumber`\r\n\t\t// is used instead of `digits`.\r\n\r\n\t\tconst strictPattern = new RegExp('^' + pattern + '$')\r\n\t\tconst nationalNumberDummyDigits = nationalSignificantNumber.replace(/\\d/g, DUMMY_DIGIT)\r\n\r\n\t\t// If `this.nationalSignificantNumber` has already sufficient length\r\n\t\t// to satisfy the `pattern` completely then use it\r\n\t\t// instead of `digits`.\r\n\t\tif (strictPattern.test(nationalNumberDummyDigits)) {\r\n\t\t\tdigits = nationalNumberDummyDigits\r\n\t\t}\r\n\r\n\t\tlet numberFormat = this.getFormatFormat(format, international)\r\n\t\tlet nationalPrefixIncludedInTemplate\r\n\r\n\t\t// If a user did input a national prefix (and that's guaranteed),\r\n\t\t// and if a `format` does have a national prefix formatting rule,\r\n\t\t// then see if that national prefix formatting rule\r\n\t\t// prepends exactly the same national prefix the user has input.\r\n\t\t// If that's the case, then use the `format` with the national prefix formatting rule.\r\n\t\t// Otherwise, use the `format` without the national prefix formatting rule,\r\n\t\t// and prepend a national prefix manually to it.\r\n\t\tif (this.shouldTryNationalPrefixFormattingRule(format, { international, nationalPrefix })) {\r\n\t\t\tconst numberFormatWithNationalPrefix = numberFormat.replace(\r\n\t\t\t\tFIRST_GROUP_PATTERN,\r\n\t\t\t\tformat.nationalPrefixFormattingRule()\r\n\t\t\t)\r\n\t\t\t// If `national_prefix_formatting_rule` of a `format` simply prepends\r\n\t\t\t// national prefix at the start of a national (significant) number,\r\n\t\t\t// then such formatting can be used with `AsYouType` formatter.\r\n\t\t\t// There seems to be no `else` case: everywhere in metadata,\r\n\t\t\t// national prefix formatting rule is national prefix + $1,\r\n\t\t\t// or `($1)`, in which case such format isn't even considered\r\n\t\t\t// when the user has input a national prefix.\r\n\t\t\t/* istanbul ignore else */\r\n\t\t\tif (parseDigits(format.nationalPrefixFormattingRule()) === (nationalPrefix || '') + parseDigits('$1')) {\r\n\t\t\t\tnumberFormat = numberFormatWithNationalPrefix\r\n\t\t\t\tnationalPrefixIncludedInTemplate = true\r\n\t\t\t\t// Replace all digits of the national prefix in the formatting template\r\n\t\t\t\t// with `DIGIT_PLACEHOLDER`s.\r\n\t\t\t\tif (nationalPrefix) {\r\n\t\t\t\t\tlet i = nationalPrefix.length\r\n\t\t\t\t\twhile (i > 0) {\r\n\t\t\t\t\t\tnumberFormat = numberFormat.replace(/\\d/, DIGIT_PLACEHOLDER)\r\n\t\t\t\t\t\ti--\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Generate formatting template for this phone number format.\r\n\t\tlet template = digits\r\n\t\t\t// Format the dummy phone number according to the format.\r\n\t\t\t.replace(new RegExp(pattern), numberFormat)\r\n\t\t\t// Replace each dummy digit with a DIGIT_PLACEHOLDER.\r\n\t\t\t.replace(new RegExp(DUMMY_DIGIT, 'g'), DIGIT_PLACEHOLDER)\r\n\r\n\t\t// If a prefix of a national (significant) number is not as simple\r\n\t\t// as just a basic national prefix, then just prepend such prefix\r\n\t\t// before the national (significant) number, optionally spacing\r\n\t\t// the two with a whitespace.\r\n\t\tif (!nationalPrefixIncludedInTemplate) {\r\n\t\t\tif (complexPrefixBeforeNationalSignificantNumber) {\r\n\t\t\t\t// Prepend the prefix to the template manually.\r\n\t\t\t\ttemplate = repeat(DIGIT_PLACEHOLDER, complexPrefixBeforeNationalSignificantNumber.length) +\r\n\t\t\t\t\t' ' +\r\n\t\t\t\t\ttemplate\r\n\t\t\t} else if (nationalPrefix) {\r\n\t\t\t\t// Prepend national prefix to the template manually.\r\n\t\t\t\ttemplate = repeat(DIGIT_PLACEHOLDER, nationalPrefix.length) +\r\n\t\t\t\t\tthis.getSeparatorAfterNationalPrefix(format) +\r\n\t\t\t\t\ttemplate\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (international) {\r\n\t\t\ttemplate = applyInternationalSeparatorStyle(template)\r\n\t\t}\r\n\r\n\t\treturn template\r\n\t}\r\n\r\n\tformatNextNationalNumberDigits(digits) {\r\n\t\tconst result = populateTemplateWithDigits(\r\n\t\t\tthis.populatedNationalNumberTemplate,\r\n\t\t\tthis.populatedNationalNumberTemplatePosition,\r\n\t\t\tdigits\r\n\t\t)\r\n\r\n\t\tif (!result) {\r\n\t\t\t// Reset the format.\r\n\t\t\tthis.resetFormat()\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tthis.populatedNationalNumberTemplate = result[0]\r\n\t\tthis.populatedNationalNumberTemplatePosition = result[1]\r\n\r\n\t\t// Return the formatted phone number so far.\r\n\t\treturn cutAndStripNonPairedParens(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1)\r\n\r\n\t\t// The old way which was good for `input-format` but is not so good\r\n\t\t// for `react-phone-number-input`'s default input (`InputBasic`).\r\n\t\t// return closeNonPairedParens(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1)\r\n\t\t// \t.replace(new RegExp(DIGIT_PLACEHOLDER, 'g'), ' ')\r\n\t}\r\n\r\n\tshouldTryNationalPrefixFormattingRule(format, { international, nationalPrefix }) {\r\n\t\tif (format.nationalPrefixFormattingRule()) {\r\n\t\t\t// In some countries, `national_prefix_formatting_rule` is `($1)`,\r\n\t\t\t// so it applies even if the user hasn't input a national prefix.\r\n\t\t\t// `format.usesNationalPrefix()` detects such cases.\r\n\t\t\tconst usesNationalPrefix = format.usesNationalPrefix()\r\n\t\t\tif ((usesNationalPrefix && nationalPrefix) ||\r\n\t\t\t\t(!usesNationalPrefix && !international)) {\r\n\t\t\t\treturn true\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}"],"mappings":";;;;;;;;;;;;AAAA,SACCA,iBADD,EAECC,eAFD,EAGCC,MAHD,EAICC,0BAJD,EAKCC,oBALD,EAMCC,oBAND,EAOCC,0BAPD,QAQO,8BARP;AAUA,OAAOC,oBAAP,IACCC,uBADD,QAEO,kCAFP;AAIA,OAAOC,cAAP,MAA2B,wCAA3B;AAEA,OAAOC,WAAP,MAAwB,0BAAxB;AACA,SAASV,iBAAT,QAAkC,8BAAlC;AACA,SAASW,mBAAT,QAAoC,8CAApC;AACA,SAASC,iBAAT,QAAkC,gBAAlC;AACA,OAAOC,gCAAP,MAA6C,+CAA7C,C,CAEA;AACA;;AACA,IAAMC,WAAW,GAAG,GAApB,C,CACA;;AACA,IAAMC,oCAAoC,GAAG,EAA7C,C,CACA;AACA;;AACA,IAAMC,0BAA0B,GAAGd,MAAM,CAACY,WAAD,EAAcC,oCAAd,CAAzC,C,CAEA;AACA;;AACA,IAAME,kCAAkC,GAAG,MAA3C,C,CAEA;AACA;AACA;AACA;AACA;AACA;;AACA,IAAMC,kCAAkC,GAAG,IAA3C,C,CAEA;AACA;;AACA,IAAMC,8BAA8B,GAAGD,kCAAkC,IAAK;EAAA,OAAM,iBAAN;AAAA,CAA9E,C,CAEA;AACA;AACA;AACA;AACA;;;AACA,IAAME,+BAA+B,GAAGF,kCAAkC,IAAK;EAAA,OAAM,mBAAN;AAAA,CAA/E,C,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,IA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MAHwC,CAAzC;;MAMA,IAAI,CAACM,MAAL,EAAa;QACZ;QACA,KAAK1E,WAAL;QACA;MACA;;MAED,KAAKK,+BAAL,GAAuCqE,MAAM,CAAC,CAAD,CAA7C;MACA,KAAKpE,uCAAL,GAA+CoE,MAAM,CAAC,CAAD,CAArD,CAdsC,CAgBtC;;MACA,OAAOlG,0BAA0B,CAAC,KAAK6B,+BAAN,EAAuC,KAAKC,uCAAL,GAA+C,CAAtF,CAAjC,CAjBsC,CAmBtC;MACA;MACA;MACA;IACA;;;WAED,+CAAsCS,MAAtC,SAAiF;MAAA,IAAjCG,aAAiC,SAAjCA,aAAiC;MAAA,IAAlBC,cAAkB,SAAlBA,cAAkB;;MAChF,IAAIJ,MAAM,CAAC0C,4BAAP,EAAJ,EAA2C;QAC1C;QACA;QACA;QACA,IAAMpB,kBAAkB,GAAGtB,MAAM,CAACsB,kBAAP,EAA3B;;QACA,IAAKA,kBAAkB,IAAIlB,cAAvB,IACF,CAACkB,kBAAD,IAAuB,CAACnB,aAD1B,EAC0C;UACzC,OAAO,IAAP;QACA;MACD;IACD;;;;;;SAhmBmBrB,kB"}
1
+ {"version":3,"file":"AsYouTypeFormatter.js","names":["DIGIT_PLACEHOLDER","countOccurences","repeat","cutAndStripNonPairedParens","closeNonPairedParens","stripNonPairedParens","populateTemplateWithDigits","formatCompleteNumber","canFormatCompleteNumber","PatternMatcher","parseDigits","FIRST_GROUP_PATTERN","VALID_PUNCTUATION","applyInternationalSeparatorStyle","DUMMY_DIGIT","LONGEST_NATIONAL_PHONE_NUMBER_LENGTH","LONGEST_DUMMY_PHONE_NUMBER","NATIONAL_PREFIX_SEPARATORS_PATTERN","SUPPORT_LEGACY_FORMATTING_PATTERNS","CREATE_CHARACTER_CLASS_PATTERN","CREATE_STANDALONE_DIGIT_PATTERN","NON_ALTERING_FORMAT_REG_EXP","RegExp","MIN_LEADING_DIGITS_LENGTH","AsYouTypeFormatter","_ref","state","metadata","_classCallCheck","resetFormat","_createClass","key","value","chosenFormat","undefined","template","nationalNumberTemplate","populatedNationalNumberTemplate","populatedNationalNumberTemplatePosition","reset","numberingPlan","isNANP","callingCode","matchingFormats","formats","nationalSignificantNumber","narrowDownMatchingFormats","format","nextDigits","_this","_iterator","_createForOfIteratorHelperLoose","_step","done","formattedCompleteNumber","shouldTryNationalPrefixFormattingRule","international","nationalPrefix","getSeparatorAfterNationalPrefix","setNationalNumberTemplate","replace","lastIndexOf","formatNationalNumberWithNextDigits","previouslyChosenFormat","newlyChosenFormat","chooseFormat","formatNextNationalNumberDigits","getNationalDigits","_ref2","_this2","leadingDigits","leadingDigitsPatternIndex","length","filter","formatSuits","formatMatches","indexOf","usesNationalPrefix","nationalPrefixIsOptionalWhenFormattingInNationalFormat","nationalPrefixIsMandatoryWhenFormattingInNationalFormat","leadingDigitsPatternsCount","leadingDigitsPatterns","Math","min","leadingDigitsPattern","match","allowOverflow","error","console","concat","test","getFormatFormat","internationalFormat","_this3","_loop","_step2","createTemplateForFormat","_","_ret","_iterator2","slice","pattern","getTemplateForFormat","nationalPrefixFormattingRule","getInternationalPrefixBeforeCountryCallingCode","_ref3","options","IDDPrefix","missingPlus","spacing","getTemplate","index","i","internationalPrefix","getDigitsWithoutInternationalPrefix","_ref4","complexPrefixBeforeNationalSignificantNumber","digits","strictPattern","nationalNumberDummyDigits","numberFormat","nationalPrefixIncludedInTemplate","numberFormatWithNationalPrefix","result","_ref5","default"],"sources":["../source/AsYouTypeFormatter.js"],"sourcesContent":["import {\r\n\tDIGIT_PLACEHOLDER,\r\n\tcountOccurences,\r\n\trepeat,\r\n\tcutAndStripNonPairedParens,\r\n\tcloseNonPairedParens,\r\n\tstripNonPairedParens,\r\n\tpopulateTemplateWithDigits\r\n} from './AsYouTypeFormatter.util.js'\r\n\r\nimport formatCompleteNumber, {\r\n\tcanFormatCompleteNumber\r\n} from './AsYouTypeFormatter.complete.js'\r\n\r\nimport PatternMatcher from './AsYouTypeFormatter.PatternMatcher.js'\r\n\r\nimport parseDigits from './helpers/parseDigits.js'\r\nexport { DIGIT_PLACEHOLDER } from './AsYouTypeFormatter.util.js'\r\nimport { FIRST_GROUP_PATTERN } from './helpers/formatNationalNumberUsingFormat.js'\r\nimport { VALID_PUNCTUATION } from './constants.js'\r\nimport applyInternationalSeparatorStyle from './helpers/applyInternationalSeparatorStyle.js'\r\n\r\n// Used in phone number format template creation.\r\n// Could be any digit, I guess.\r\nconst DUMMY_DIGIT = '9'\r\n// I don't know why is it exactly `15`\r\nconst LONGEST_NATIONAL_PHONE_NUMBER_LENGTH = 15\r\n// Create a phone number consisting only of the digit 9 that matches the\r\n// `number_pattern` by applying the pattern to the \"longest phone number\" string.\r\nconst LONGEST_DUMMY_PHONE_NUMBER = repeat(DUMMY_DIGIT, LONGEST_NATIONAL_PHONE_NUMBER_LENGTH)\r\n\r\n// A set of characters that, if found in a national prefix formatting rules, are an indicator to\r\n// us that we should separate the national prefix from the number when formatting.\r\nconst NATIONAL_PREFIX_SEPARATORS_PATTERN = /[- ]/\r\n\r\n// Deprecated: Google has removed some formatting pattern related code from their repo.\r\n// https://github.com/googlei18n/libphonenumber/commit/a395b4fef3caf57c4bc5f082e1152a4d2bd0ba4c\r\n// \"We no longer have numbers in formatting matching patterns, only \\d.\"\r\n// Because this library supports generating custom metadata\r\n// some users may still be using old metadata so the relevant\r\n// code seems to stay until some next major version update.\r\nconst SUPPORT_LEGACY_FORMATTING_PATTERNS = true\r\n\r\n// A pattern that is used to match character classes in regular expressions.\r\n// An example of a character class is \"[1-4]\".\r\nconst CREATE_CHARACTER_CLASS_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && (() => /\\[([^\\[\\]])*\\]/g)\r\n\r\n// Any digit in a regular expression that actually denotes a digit. For\r\n// example, in the regular expression \"80[0-2]\\d{6,10}\", the first 2 digits\r\n// (8 and 0) are standalone digits, but the rest are not.\r\n// Two look-aheads are needed because the number following \\\\d could be a\r\n// two-digit number, since the phone number can be as long as 15 digits.\r\nconst CREATE_STANDALONE_DIGIT_PATTERN = SUPPORT_LEGACY_FORMATTING_PATTERNS && (() => /\\d(?=[^,}][^,}])/g)\r\n\r\n// A regular expression that is used to determine if a `format` is\r\n// suitable to be used in the \"as you type formatter\".\r\n// A `format` is suitable when the resulting formatted number has\r\n// the same digits as the user has entered.\r\n//\r\n// In the simplest case, that would mean that the format\r\n// doesn't add any additional digits when formatting a number.\r\n// Google says that it also shouldn't add \"star\" (`*`) characters,\r\n// like it does in some Israeli formats.\r\n// Such basic format would only contain \"valid punctuation\"\r\n// and \"captured group\" identifiers ($1, $2, etc).\r\n//\r\n// An example of a format that adds additional digits:\r\n//\r\n// Country: `AR` (Argentina).\r\n// Format:\r\n// {\r\n// \"pattern\": \"(\\\\d)(\\\\d{2})(\\\\d{4})(\\\\d{4})\",\r\n// \"leading_digits_patterns\": [\"91\"],\r\n// \"national_prefix_formatting_rule\": \"0$1\",\r\n// \"format\": \"$2 15-$3-$4\",\r\n// \"international_format\": \"$1 $2 $3-$4\"\r\n// }\r\n//\r\n// In the format above, the `format` adds `15` to the digits when formatting a number.\r\n// A sidenote: this format actually is suitable because `national_prefix_for_parsing`\r\n// has previously removed `15` from a national number, so re-adding `15` in `format`\r\n// doesn't actually result in any extra digits added to user's input.\r\n// But verifying that would be a complex procedure, so the code chooses a simpler path:\r\n// it simply filters out all `format`s that contain anything but \"captured group\" ids.\r\n//\r\n// This regular expression is called `ELIGIBLE_FORMAT_PATTERN` in Google's\r\n// `libphonenumber` code.\r\n//\r\nconst NON_ALTERING_FORMAT_REG_EXP = new RegExp(\r\n\t'[' + VALID_PUNCTUATION + ']*' +\r\n\t// Google developers say:\r\n\t// \"We require that the first matching group is present in the\r\n\t// output pattern to ensure no data is lost while formatting.\"\r\n\t'\\\\$1' +\r\n\t'[' + VALID_PUNCTUATION + ']*' +\r\n\t'(\\\\$\\\\d[' + VALID_PUNCTUATION + ']*)*' +\r\n\t'$'\r\n)\r\n\r\n// This is the minimum length of the leading digits of a phone number\r\n// to guarantee the first \"leading digits pattern\" for a phone number format\r\n// to be preemptive.\r\nconst MIN_LEADING_DIGITS_LENGTH = 3\r\n\r\nexport default class AsYouTypeFormatter {\r\n\tconstructor({\r\n\t\tstate,\r\n\t\tmetadata\r\n\t}) {\r\n\t\tthis.metadata = metadata\r\n\t\tthis.resetFormat()\r\n\t}\r\n\r\n\tresetFormat() {\r\n\t\tthis.chosenFormat = undefined\r\n\t\tthis.template = undefined\r\n\t\tthis.nationalNumberTemplate = undefined\r\n\t\tthis.populatedNationalNumberTemplate = undefined\r\n\t\tthis.populatedNationalNumberTemplatePosition = -1\r\n\t}\r\n\r\n\treset(numberingPlan, state) {\r\n\t\tthis.resetFormat()\r\n\t\tif (numberingPlan) {\r\n\t\t\tthis.isNANP = numberingPlan.callingCode() === '1'\r\n\t\t\tthis.matchingFormats = numberingPlan.formats()\r\n\t\t\tif (state.nationalSignificantNumber) {\r\n\t\t\t\tthis.narrowDownMatchingFormats(state)\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tthis.isNANP = undefined\r\n\t\t\tthis.matchingFormats = []\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Formats an updated phone number.\r\n\t * @param {string} nextDigits — Additional phone number digits.\r\n\t * @param {object} state — `AsYouType` state.\r\n\t * @return {[string]} Returns undefined if the updated phone number can't be formatted using any of the available formats.\r\n\t */\r\n\tformat(nextDigits, state) {\r\n\t\t// See if the phone number digits can be formatted as a complete phone number.\r\n\t\t// If not, use the results from `formatNationalNumberWithNextDigits()`,\r\n\t\t// which formats based on the chosen formatting pattern.\r\n\t\t//\r\n\t\t// Attempting to format complete phone number first is how it's done\r\n\t\t// in Google's `libphonenumber`, so this library just follows it.\r\n\t\t// Google's `libphonenumber` code doesn't explain in detail why does it\r\n\t\t// attempt to format digits as a complete phone number\r\n\t\t// instead of just going with a previoulsy (or newly) chosen `format`:\r\n\t\t//\r\n\t\t// \"Checks to see if there is an exact pattern match for these digits.\r\n\t\t// If so, we should use this instead of any other formatting template\r\n\t\t// whose leadingDigitsPattern also matches the input.\"\r\n\t\t//\r\n\t\tif (canFormatCompleteNumber(state.nationalSignificantNumber, this.metadata)) {\r\n\t\t\tfor (const format of this.matchingFormats) {\r\n\t\t\t\tconst formattedCompleteNumber = formatCompleteNumber(\r\n\t\t\t\t\tstate,\r\n\t\t\t\t\tformat,\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tmetadata: this.metadata,\r\n\t\t\t\t\t\tshouldTryNationalPrefixFormattingRule: (format) => this.shouldTryNationalPrefixFormattingRule(format, {\r\n\t\t\t\t\t\t\tinternational: state.international,\r\n\t\t\t\t\t\t\tnationalPrefix: state.nationalPrefix\r\n\t\t\t\t\t\t}),\r\n\t\t\t\t\t\tgetSeparatorAfterNationalPrefix: (format) => this.getSeparatorAfterNationalPrefix(format)\r\n\t\t\t\t\t}\r\n\t\t\t\t)\r\n\t\t\t\tif (formattedCompleteNumber) {\r\n\t\t\t\t\tthis.resetFormat()\r\n\t\t\t\t\tthis.chosenFormat = format\r\n\t\t\t\t\tthis.setNationalNumberTemplate(formattedCompleteNumber.replace(/\\d/g, DIGIT_PLACEHOLDER), state)\r\n\t\t\t\t\tthis.populatedNationalNumberTemplate = formattedCompleteNumber\r\n\t\t\t\t\t// With a new formatting template, the matched position\r\n\t\t\t\t\t// using the old template needs to be reset.\r\n\t\t\t\t\tthis.populatedNationalNumberTemplatePosition = this.template.lastIndexOf(DIGIT_PLACEHOLDER)\r\n\t\t\t\t\treturn formattedCompleteNumber\r\n\t\t\t\t}\r\n\r\n\t\t\t}\r\n\t\t}\r\n\t\t// Format the digits as a partial (incomplete) phone number\r\n\t\t// using the previously chosen formatting pattern (or a newly chosen one).\r\n\t\treturn this.formatNationalNumberWithNextDigits(nextDigits, state)\r\n\t}\r\n\r\n\t// Formats the next phone number digits.\r\n\tformatNationalNumberWithNextDigits(nextDigits, state) {\r\n\t\tconst previouslyChosenFormat = this.chosenFormat\r\n\r\n\t\t// Choose a format from the list of matching ones.\r\n\t\tconst newlyChosenFormat = this.chooseFormat(state)\r\n\r\n\t\tif (newlyChosenFormat) {\r\n\t\t\tif (newlyChosenFormat === previouslyChosenFormat) {\r\n\t\t\t\t// If it can format the next (current) digits\r\n\t\t\t\t// using the previously chosen phone number format\r\n\t\t\t\t// then return the updated formatted number.\r\n\t\t\t\treturn this.formatNextNationalNumberDigits(nextDigits)\r\n\t\t\t} else {\r\n\t\t\t\t// If a more appropriate phone number format\r\n\t\t\t\t// has been chosen for these \"leading digits\",\r\n\t\t\t\t// then re-format the national phone number part\r\n\t\t\t\t// using the newly selected format.\r\n\t\t\t\treturn this.formatNextNationalNumberDigits(state.getNationalDigits())\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tnarrowDownMatchingFormats({\r\n\t\tnationalSignificantNumber,\r\n\t\tnationalPrefix,\r\n\t\tinternational\r\n\t}) {\r\n\t\tconst leadingDigits = nationalSignificantNumber\r\n\r\n\t\t// \"leading digits\" pattern list starts with a\r\n\t\t// \"leading digits\" pattern fitting a maximum of 3 leading digits.\r\n\t\t// So, after a user inputs 3 digits of a national (significant) phone number\r\n\t\t// this national (significant) number can already be formatted.\r\n\t\t// The next \"leading digits\" pattern is for 4 leading digits max,\r\n\t\t// and the \"leading digits\" pattern after it is for 5 leading digits max, etc.\r\n\r\n\t\t// This implementation is different from Google's\r\n\t\t// in that it searches for a fitting format\r\n\t\t// even if the user has entered less than\r\n\t\t// `MIN_LEADING_DIGITS_LENGTH` digits of a national number.\r\n\t\t// Because some leading digit patterns already match for a single first digit.\r\n\t\tlet leadingDigitsPatternIndex = leadingDigits.length - MIN_LEADING_DIGITS_LENGTH\r\n\t\tif (leadingDigitsPatternIndex < 0) {\r\n\t\t\tleadingDigitsPatternIndex = 0\r\n\t\t}\r\n\r\n\t\tthis.matchingFormats = this.matchingFormats.filter(\r\n\t\t\tformat => this.formatSuits(format, international, nationalPrefix)\r\n\t\t\t\t&& this.formatMatches(format, leadingDigits, leadingDigitsPatternIndex)\r\n\t\t)\r\n\r\n\t\t// If there was a phone number format chosen\r\n\t\t// and it no longer holds given the new leading digits then reset it.\r\n\t\t// The test for this `if` condition is marked as:\r\n\t\t// \"Reset a chosen format when it no longer holds given the new leading digits\".\r\n\t\t// To construct a valid test case for this one can find a country\r\n\t\t// in `PhoneNumberMetadata.xml` yielding one format for 3 `<leadingDigits>`\r\n\t\t// and yielding another format for 4 `<leadingDigits>` (Australia in this case).\r\n\t\tif (this.chosenFormat && this.matchingFormats.indexOf(this.chosenFormat) === -1) {\r\n\t\t\tthis.resetFormat()\r\n\t\t}\r\n\t}\r\n\r\n\tformatSuits(format, international, nationalPrefix) {\r\n\t\t// When a prefix before a national (significant) number is\r\n\t\t// simply a national prefix, then it's parsed as `this.nationalPrefix`.\r\n\t\t// In more complex cases, a prefix before national (significant) number\r\n\t\t// could include a national prefix as well as some \"capturing groups\",\r\n\t\t// and in that case there's no info whether a national prefix has been parsed.\r\n\t\t// If national prefix is not used when formatting a phone number\r\n\t\t// using this format, but a national prefix has been entered by the user,\r\n\t\t// and was extracted, then discard such phone number format.\r\n\t\t// In Google's \"AsYouType\" formatter code, the equivalent would be this part:\r\n\t\t// https://github.com/google/libphonenumber/blob/0a45cfd96e71cad8edb0e162a70fcc8bd9728933/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java#L175-L184\r\n\t\tif (nationalPrefix &&\r\n\t\t\t!format.usesNationalPrefix() &&\r\n\t\t\t// !format.domesticCarrierCodeFormattingRule() &&\r\n\t\t\t!format.nationalPrefixIsOptionalWhenFormattingInNationalFormat()) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\t// If national prefix is mandatory for this phone number format\r\n\t\t// and there're no guarantees that a national prefix is present in user input\r\n\t\t// then discard this phone number format as not suitable.\r\n\t\t// In Google's \"AsYouType\" formatter code, the equivalent would be this part:\r\n\t\t// https://github.com/google/libphonenumber/blob/0a45cfd96e71cad8edb0e162a70fcc8bd9728933/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java#L185-L193\r\n\t\tif (!international &&\r\n\t\t\t!nationalPrefix &&\r\n\t\t\tformat.nationalPrefixIsMandatoryWhenFormattingInNationalFormat()) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\treturn true\r\n\t}\r\n\r\n\tformatMatches(format, leadingDigits, leadingDigitsPatternIndex) {\r\n\t\tconst leadingDigitsPatternsCount = format.leadingDigitsPatterns().length\r\n\r\n\t\t// If this format is not restricted to a certain\r\n\t\t// leading digits pattern then it fits.\r\n\t\t// The test case could be found by searching for \"leadingDigitsPatternsCount === 0\".\r\n\t\tif (leadingDigitsPatternsCount === 0) {\r\n\t\t\treturn true\r\n\t\t}\r\n\r\n\t\t// Start narrowing down the list of possible formats based on the leading digits.\r\n\t\t// (only previously matched formats take part in the narrowing down process)\r\n\r\n\t\t// `leading_digits_patterns` start with 3 digits min\r\n\t\t// and then go up from there one digit at a time.\r\n\t\tleadingDigitsPatternIndex = Math.min(leadingDigitsPatternIndex, leadingDigitsPatternsCount - 1)\r\n\t\tconst leadingDigitsPattern = format.leadingDigitsPatterns()[leadingDigitsPatternIndex]\r\n\r\n\t\t// Google imposes a requirement on the leading digits\r\n\t\t// to be minimum 3 digits long in order to be eligible\r\n\t\t// for checking those with a leading digits pattern.\r\n\t\t//\r\n\t\t// Since `leading_digits_patterns` start with 3 digits min,\r\n\t\t// Google's original `libphonenumber` library only starts\r\n\t\t// excluding any non-matching formats only when the\r\n\t\t// national number entered so far is at least 3 digits long,\r\n\t\t// otherwise format matching would give false negatives.\r\n\t\t//\r\n\t\t// For example, when the digits entered so far are `2`\r\n\t\t// and the leading digits pattern is `21` –\r\n\t\t// it's quite obvious in this case that the format could be the one\r\n\t\t// but due to the absence of further digits it would give false negative.\r\n\t\t//\r\n\t\t// Also, `leading_digits_patterns` doesn't always correspond to a single\r\n\t\t// digits count. For example, `60|8` pattern would already match `8`\r\n\t\t// but the `60` part would require having at least two leading digits,\r\n\t\t// so the whole pattern would require inputting two digits first in order to\r\n\t\t// decide on whether it matches the input, even when the input is \"80\".\r\n\t\t//\r\n\t\t// This library — `libphonenumber-js` — allows filtering by `leading_digits_patterns`\r\n\t\t// even when there's only 1 or 2 digits of the national (significant) number.\r\n\t\t// To do that, it uses a non-strict pattern matcher written specifically for that.\r\n\t\t//\r\n\t\tif (leadingDigits.length < MIN_LEADING_DIGITS_LENGTH) {\r\n\t\t\t// Before leading digits < 3 matching was implemented:\r\n\t\t\t// return true\r\n\t\t\t//\r\n\t\t\t// After leading digits < 3 matching was implemented:\r\n\t\t\ttry {\r\n\t\t\t\treturn new PatternMatcher(leadingDigitsPattern).match(leadingDigits, { allowOverflow: true }) !== undefined\r\n\t\t\t} catch (error) /* istanbul ignore next */ {\r\n\t\t\t\t// There's a slight possibility that there could be some undiscovered bug\r\n\t\t\t\t// in the pattern matcher code. Since the \"leading digits < 3 matching\"\r\n\t\t\t\t// feature is not \"essential\" for operation, it can fall back to the old way\r\n\t\t\t\t// in case of any issues rather than halting the application's execution.\r\n\t\t\t\tconsole.error(error)\r\n\t\t\t\treturn true\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// If at least `MIN_LEADING_DIGITS_LENGTH` digits of a national number are\r\n\t\t// available then use the usual regular expression matching.\r\n\t\t//\r\n\t\t// The whole pattern is wrapped in round brackets (`()`) because\r\n\t\t// the pattern can use \"or\" operator (`|`) at the top level of the pattern.\r\n\t\t//\r\n\t\treturn new RegExp(`^(${leadingDigitsPattern})`).test(leadingDigits)\r\n\t}\r\n\r\n\tgetFormatFormat(format, international) {\r\n\t\treturn international ? format.internationalFormat() : format.format()\r\n\t}\r\n\r\n\tchooseFormat(state) {\r\n\t\t// When there are multiple available formats, the formatter uses the first\r\n\t\t// format where a formatting template could be created.\r\n\t\t//\r\n\t\t// For some weird reason, `istanbul` says \"else path not taken\"\r\n\t\t// for the `for of` line below. Supposedly that means that\r\n\t\t// the loop doesn't ever go over the last element in the list.\r\n\t\t// That's true because there always is `this.chosenFormat`\r\n\t\t// when `this.matchingFormats` is non-empty.\r\n\t\t// And, for some weird reason, it doesn't think that the case\r\n\t\t// with empty `this.matchingFormats` qualifies for a valid \"else\" path.\r\n\t\t// So simply muting this `istanbul` warning.\r\n\t\t// It doesn't skip the contents of the `for of` loop,\r\n\t\t// it just skips the `for of` line.\r\n\t\t//\r\n\t\t/* istanbul ignore next */\r\n\t\tfor (const format of this.matchingFormats.slice()) {\r\n\t\t\t// If this format is currently being used\r\n\t\t\t// and is still suitable, then stick to it.\r\n\t\t\tif (this.chosenFormat === format) {\r\n\t\t\t\tbreak\r\n\t\t\t}\r\n\t\t\t// Sometimes, a formatting rule inserts additional digits in a phone number,\r\n\t\t\t// and \"as you type\" formatter can't do that: it should only use the digits\r\n\t\t\t// that the user has input.\r\n\t\t\t//\r\n\t\t\t// For example, in Argentina, there's a format for mobile phone numbers:\r\n\t\t\t//\r\n\t\t\t// {\r\n\t\t\t// \"pattern\": \"(\\\\d)(\\\\d{2})(\\\\d{4})(\\\\d{4})\",\r\n\t\t\t// \"leading_digits_patterns\": [\"91\"],\r\n\t\t\t// \"national_prefix_formatting_rule\": \"0$1\",\r\n\t\t\t// \"format\": \"$2 15-$3-$4\",\r\n\t\t\t// \"international_format\": \"$1 $2 $3-$4\"\r\n\t\t\t// }\r\n\t\t\t//\r\n\t\t\t// In that format, `international_format` is used instead of `format`\r\n\t\t\t// because `format` inserts `15` in the formatted number,\r\n\t\t\t// and `AsYouType` formatter should only use the digits\r\n\t\t\t// the user has actually input, without adding any extra digits.\r\n\t\t\t// In this case, it wouldn't make a difference, because the `15`\r\n\t\t\t// is first stripped when applying `national_prefix_for_parsing`\r\n\t\t\t// and then re-added when using `format`, so in reality it doesn't\r\n\t\t\t// add any new digits to the number, but to detect that, the code\r\n\t\t\t// would have to be more complex: it would have to try formatting\r\n\t\t\t// the digits using the format and then see if any digits have\r\n\t\t\t// actually been added or removed, and then, every time a new digit\r\n\t\t\t// is input, it should re-check whether the chosen format doesn't\r\n\t\t\t// alter the digits.\r\n\t\t\t//\r\n\t\t\t// Google's code doesn't go that far, and so does this library:\r\n\t\t\t// it simply requires that a `format` doesn't add any additonal\r\n\t\t\t// digits to user's input.\r\n\t\t\t//\r\n\t\t\t// Also, people in general should move from inputting phone numbers\r\n\t\t\t// in national format (possibly with national prefixes)\r\n\t\t\t// and use international phone number format instead:\r\n\t\t\t// it's a logical thing in the modern age of mobile phones,\r\n\t\t\t// globalization and the internet.\r\n\t\t\t//\r\n\t\t\t/* istanbul ignore if */\r\n\t\t\tif (!NON_ALTERING_FORMAT_REG_EXP.test(this.getFormatFormat(format, state.international))) {\r\n\t\t\t\tcontinue\r\n\t\t\t}\r\n\t\t\tif (!this.createTemplateForFormat(format, state)) {\r\n\t\t\t\t// Remove the format if it can't generate a template.\r\n\t\t\t\tthis.matchingFormats = this.matchingFormats.filter(_ => _ !== format)\r\n\t\t\t\tcontinue\r\n\t\t\t}\r\n\t\t\tthis.chosenFormat = format\r\n\t\t\tbreak\r\n\t\t}\r\n\t\tif (!this.chosenFormat) {\r\n\t\t\t// No format matches the national (significant) phone number.\r\n\t\t\tthis.resetFormat()\r\n\t\t}\r\n\t\treturn this.chosenFormat\r\n\t}\r\n\r\n\tcreateTemplateForFormat(format, state) {\r\n\t\t// The formatter doesn't format numbers when numberPattern contains '|', e.g.\r\n\t\t// (20|3)\\d{4}. In those cases we quickly return.\r\n\t\t// (Though there's no such format in current metadata)\r\n\t\t/* istanbul ignore if */\r\n\t\tif (SUPPORT_LEGACY_FORMATTING_PATTERNS && format.pattern().indexOf('|') >= 0) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\t// Get formatting template for this phone number format\r\n\t\tconst template = this.getTemplateForFormat(format, state)\r\n\t\t// If the national number entered is too long\r\n\t\t// for any phone number format, then abort.\r\n\t\tif (template) {\r\n\t\t\tthis.setNationalNumberTemplate(template, state)\r\n\t\t\treturn true\r\n\t\t}\r\n\t}\r\n\r\n\tgetSeparatorAfterNationalPrefix(format) {\r\n\t\t// `US` metadata doesn't have a `national_prefix_formatting_rule`,\r\n\t\t// so the `if` condition below doesn't apply to `US`,\r\n\t\t// but in reality there shoudl be a separator\r\n\t\t// between a national prefix and a national (significant) number.\r\n\t\t// So `US` national prefix separator is a \"special\" \"hardcoded\" case.\r\n\t\tif (this.isNANP) {\r\n\t\t\treturn ' '\r\n\t\t}\r\n\t\t// If a `format` has a `national_prefix_formatting_rule`\r\n\t\t// and that rule has a separator after a national prefix,\r\n\t\t// then it means that there should be a separator\r\n\t\t// between a national prefix and a national (significant) number.\r\n\t\tif (format &&\r\n\t\t\tformat.nationalPrefixFormattingRule() &&\r\n\t\t\tNATIONAL_PREFIX_SEPARATORS_PATTERN.test(format.nationalPrefixFormattingRule())) {\r\n\t\t\treturn ' '\r\n\t\t}\r\n\t\t// At this point, there seems to be no clear evidence that\r\n\t\t// there should be a separator between a national prefix\r\n\t\t// and a national (significant) number. So don't insert one.\r\n\t\treturn ''\r\n\t}\r\n\r\n\tgetInternationalPrefixBeforeCountryCallingCode({ IDDPrefix, missingPlus }, options) {\r\n\t\tif (IDDPrefix) {\r\n\t\t\treturn options && options.spacing === false ? IDDPrefix : IDDPrefix + ' '\r\n\t\t}\r\n\t\tif (missingPlus) {\r\n\t\t\treturn ''\r\n\t\t}\r\n\t\treturn '+'\r\n\t}\r\n\r\n\tgetTemplate(state) {\r\n\t\tif (!this.template) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\t// `this.template` holds the template for a \"complete\" phone number.\r\n\t\t// The currently entered phone number is most likely not \"complete\",\r\n\t\t// so trim all non-populated digits.\r\n\t\tlet index = -1\r\n\t\tlet i = 0\r\n\t\tconst internationalPrefix = state.international ? this.getInternationalPrefixBeforeCountryCallingCode(state, { spacing: false }) : ''\r\n\t\twhile (i < internationalPrefix.length + state.getDigitsWithoutInternationalPrefix().length) {\r\n\t\t\tindex = this.template.indexOf(DIGIT_PLACEHOLDER, index + 1)\r\n\t\t\ti++\r\n\t\t}\r\n\t\treturn cutAndStripNonPairedParens(this.template, index + 1)\r\n\t}\r\n\r\n\tsetNationalNumberTemplate(template, state) {\r\n\t\tthis.nationalNumberTemplate = template\r\n\t\tthis.populatedNationalNumberTemplate = template\r\n\t\t// With a new formatting template, the matched position\r\n\t\t// using the old template needs to be reset.\r\n\t\tthis.populatedNationalNumberTemplatePosition = -1\r\n\t\t// For convenience, the public `.template` property\r\n\t\t// contains the whole international number\r\n\t\t// if the phone number being input is international:\r\n\t\t// 'x' for the '+' sign, 'x'es for the country phone code,\r\n\t\t// a spacebar and then the template for the formatted national number.\r\n\t\tif (state.international) {\r\n\t\t\tthis.template =\r\n\t\t\t\tthis.getInternationalPrefixBeforeCountryCallingCode(state).replace(/[\\d\\+]/g, DIGIT_PLACEHOLDER) +\r\n\t\t\t\trepeat(DIGIT_PLACEHOLDER, state.callingCode.length) +\r\n\t\t\t\t' ' +\r\n\t\t\t\ttemplate\r\n\t\t} else {\r\n\t\t\tthis.template = template\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Generates formatting template for a national phone number,\r\n\t * optionally containing a national prefix, for a format.\r\n\t * @param {Format} format\r\n\t * @param {string} nationalPrefix\r\n\t * @return {string}\r\n\t */\r\n\tgetTemplateForFormat(format, {\r\n\t\tnationalSignificantNumber,\r\n\t\tinternational,\r\n\t\tnationalPrefix,\r\n\t\tcomplexPrefixBeforeNationalSignificantNumber\r\n\t}) {\r\n\t\tlet pattern = format.pattern()\r\n\r\n\t\t/* istanbul ignore else */\r\n\t\tif (SUPPORT_LEGACY_FORMATTING_PATTERNS) {\r\n\t\t\tpattern = pattern\r\n\t\t\t\t// Replace anything in the form of [..] with \\d\r\n\t\t\t\t.replace(CREATE_CHARACTER_CLASS_PATTERN(), '\\\\d')\r\n\t\t\t\t// Replace any standalone digit (not the one in `{}`) with \\d\r\n\t\t\t\t.replace(CREATE_STANDALONE_DIGIT_PATTERN(), '\\\\d')\r\n\t\t}\r\n\r\n\t\t// Generate a dummy national number (consisting of `9`s)\r\n\t\t// that fits this format's `pattern`.\r\n\t\t//\r\n\t\t// This match will always succeed,\r\n\t\t// because the \"longest dummy phone number\"\r\n\t\t// has enough length to accomodate any possible\r\n\t\t// national phone number format pattern.\r\n\t\t//\r\n\t\tlet digits = LONGEST_DUMMY_PHONE_NUMBER.match(pattern)[0]\r\n\r\n\t\t// If the national number entered is too long\r\n\t\t// for any phone number format, then abort.\r\n\t\tif (nationalSignificantNumber.length > digits.length) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\t// Get a formatting template which can be used to efficiently format\r\n\t\t// a partial number where digits are added one by one.\r\n\r\n\t\t// Below `strictPattern` is used for the\r\n\t\t// regular expression (with `^` and `$`).\r\n\t\t// This wasn't originally in Google's `libphonenumber`\r\n\t\t// and I guess they don't really need it\r\n\t\t// because they're not using \"templates\" to format phone numbers\r\n\t\t// but I added `strictPattern` after encountering\r\n\t\t// South Korean phone number formatting bug.\r\n\t\t//\r\n\t\t// Non-strict regular expression bug demonstration:\r\n\t\t//\r\n\t\t// this.nationalSignificantNumber : `111111111` (9 digits)\r\n\t\t//\r\n\t\t// pattern : (\\d{2})(\\d{3,4})(\\d{4})\r\n\t\t// format : `$1 $2 $3`\r\n\t\t// digits : `9999999999` (10 digits)\r\n\t\t//\r\n\t\t// '9999999999'.replace(new RegExp(/(\\d{2})(\\d{3,4})(\\d{4})/g), '$1 $2 $3') = \"99 9999 9999\"\r\n\t\t//\r\n\t\t// template : xx xxxx xxxx\r\n\t\t//\r\n\t\t// But the correct template in this case is `xx xxx xxxx`.\r\n\t\t// The template was generated incorrectly because of the\r\n\t\t// `{3,4}` variability in the `pattern`.\r\n\t\t//\r\n\t\t// The fix is, if `this.nationalSignificantNumber` has already sufficient length\r\n\t\t// to satisfy the `pattern` completely then `this.nationalSignificantNumber`\r\n\t\t// is used instead of `digits`.\r\n\r\n\t\tconst strictPattern = new RegExp('^' + pattern + '$')\r\n\t\tconst nationalNumberDummyDigits = nationalSignificantNumber.replace(/\\d/g, DUMMY_DIGIT)\r\n\r\n\t\t// If `this.nationalSignificantNumber` has already sufficient length\r\n\t\t// to satisfy the `pattern` completely then use it\r\n\t\t// instead of `digits`.\r\n\t\tif (strictPattern.test(nationalNumberDummyDigits)) {\r\n\t\t\tdigits = nationalNumberDummyDigits\r\n\t\t}\r\n\r\n\t\tlet numberFormat = this.getFormatFormat(format, international)\r\n\t\tlet nationalPrefixIncludedInTemplate\r\n\r\n\t\t// If a user did input a national prefix (and that's guaranteed),\r\n\t\t// and if a `format` does have a national prefix formatting rule,\r\n\t\t// then see if that national prefix formatting rule\r\n\t\t// prepends exactly the same national prefix the user has input.\r\n\t\t// If that's the case, then use the `format` with the national prefix formatting rule.\r\n\t\t// Otherwise, use the `format` without the national prefix formatting rule,\r\n\t\t// and prepend a national prefix manually to it.\r\n\t\tif (this.shouldTryNationalPrefixFormattingRule(format, { international, nationalPrefix })) {\r\n\t\t\tconst numberFormatWithNationalPrefix = numberFormat.replace(\r\n\t\t\t\tFIRST_GROUP_PATTERN,\r\n\t\t\t\tformat.nationalPrefixFormattingRule()\r\n\t\t\t)\r\n\t\t\t// If `national_prefix_formatting_rule` of a `format` simply prepends\r\n\t\t\t// national prefix at the start of a national (significant) number,\r\n\t\t\t// then such formatting can be used with `AsYouType` formatter.\r\n\t\t\t// There seems to be no `else` case: everywhere in metadata,\r\n\t\t\t// national prefix formatting rule is national prefix + $1,\r\n\t\t\t// or `($1)`, in which case such format isn't even considered\r\n\t\t\t// when the user has input a national prefix.\r\n\t\t\t/* istanbul ignore else */\r\n\t\t\tif (parseDigits(format.nationalPrefixFormattingRule()) === (nationalPrefix || '') + parseDigits('$1')) {\r\n\t\t\t\tnumberFormat = numberFormatWithNationalPrefix\r\n\t\t\t\tnationalPrefixIncludedInTemplate = true\r\n\t\t\t\t// Replace all digits of the national prefix in the formatting template\r\n\t\t\t\t// with `DIGIT_PLACEHOLDER`s.\r\n\t\t\t\tif (nationalPrefix) {\r\n\t\t\t\t\tlet i = nationalPrefix.length\r\n\t\t\t\t\twhile (i > 0) {\r\n\t\t\t\t\t\tnumberFormat = numberFormat.replace(/\\d/, DIGIT_PLACEHOLDER)\r\n\t\t\t\t\t\ti--\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Generate formatting template for this phone number format.\r\n\t\tlet template = digits\r\n\t\t\t// Format the dummy phone number according to the format.\r\n\t\t\t.replace(new RegExp(pattern), numberFormat)\r\n\t\t\t// Replace each dummy digit with a DIGIT_PLACEHOLDER.\r\n\t\t\t.replace(new RegExp(DUMMY_DIGIT, 'g'), DIGIT_PLACEHOLDER)\r\n\r\n\t\t// If a prefix of a national (significant) number is not as simple\r\n\t\t// as just a basic national prefix, then just prepend such prefix\r\n\t\t// before the national (significant) number, optionally spacing\r\n\t\t// the two with a whitespace.\r\n\t\tif (!nationalPrefixIncludedInTemplate) {\r\n\t\t\tif (complexPrefixBeforeNationalSignificantNumber) {\r\n\t\t\t\t// Prepend the prefix to the template manually.\r\n\t\t\t\ttemplate = repeat(DIGIT_PLACEHOLDER, complexPrefixBeforeNationalSignificantNumber.length) +\r\n\t\t\t\t\t' ' +\r\n\t\t\t\t\ttemplate\r\n\t\t\t} else if (nationalPrefix) {\r\n\t\t\t\t// Prepend national prefix to the template manually.\r\n\t\t\t\ttemplate = repeat(DIGIT_PLACEHOLDER, nationalPrefix.length) +\r\n\t\t\t\t\tthis.getSeparatorAfterNationalPrefix(format) +\r\n\t\t\t\t\ttemplate\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (international) {\r\n\t\t\ttemplate = applyInternationalSeparatorStyle(template)\r\n\t\t}\r\n\r\n\t\treturn template\r\n\t}\r\n\r\n\tformatNextNationalNumberDigits(digits) {\r\n\t\tconst result = populateTemplateWithDigits(\r\n\t\t\tthis.populatedNationalNumberTemplate,\r\n\t\t\tthis.populatedNationalNumberTemplatePosition,\r\n\t\t\tdigits\r\n\t\t)\r\n\r\n\t\tif (!result) {\r\n\t\t\t// Reset the format.\r\n\t\t\tthis.resetFormat()\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tthis.populatedNationalNumberTemplate = result[0]\r\n\t\tthis.populatedNationalNumberTemplatePosition = result[1]\r\n\r\n\t\t// Return the formatted phone number so far.\r\n\t\treturn cutAndStripNonPairedParens(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1)\r\n\r\n\t\t// The old way which was good for `input-format` but is not so good\r\n\t\t// for `react-phone-number-input`'s default input (`InputBasic`).\r\n\t\t// return closeNonPairedParens(this.populatedNationalNumberTemplate, this.populatedNationalNumberTemplatePosition + 1)\r\n\t\t// \t.replace(new RegExp(DIGIT_PLACEHOLDER, 'g'), ' ')\r\n\t}\r\n\r\n\tshouldTryNationalPrefixFormattingRule(format, { international, nationalPrefix }) {\r\n\t\tif (format.nationalPrefixFormattingRule()) {\r\n\t\t\t// In some countries, `national_prefix_formatting_rule` is `($1)`,\r\n\t\t\t// so it applies even if the user hasn't input a national prefix.\r\n\t\t\t// `format.usesNationalPrefix()` detects such cases.\r\n\t\t\tconst usesNationalPrefix = format.usesNationalPrefix()\r\n\t\t\tif ((usesNationalPrefix && nationalPrefix) ||\r\n\t\t\t\t(!usesNationalPrefix && !international)) {\r\n\t\t\t\treturn true\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}"],"mappings":";;;;;;;;;AAAA,SACCA,iBAAiB,EACjBC,eAAe,EACfC,MAAM,EACNC,0BAA0B,EAC1BC,oBAAoB,EACpBC,oBAAoB,EACpBC,0BAA0B,QACpB,8BAA8B;AAErC,OAAOC,oBAAoB,IAC1BC,uBAAuB,QACjB,kCAAkC;AAEzC,OAAOC,cAAc,MAAM,wCAAwC;AAEnE,OAAOC,WAAW,MAAM,0BAA0B;AAClD,SAASV,iBAAiB,QAAQ,8BAA8B;AAChE,SAASW,mBAAmB,QAAQ,8CAA8C;AAClF,SAASC,iBAAiB,QAAQ,gBAAgB;AAClD,OAAOC,gCAAgC,MAAM,+CAA+C;;AAE5F;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AAqCA,CAACR,MAAM,EAAA6E,KAAA,EAAqC;MAAA,IAAjCpE,aAAa,GAAAoE,KAAA,CAAbpE,aAAa;QAAEC,cAAc,GAAAmE,KAAA,CAAdnE,cAAc;MAC5E,IAAIV,MAAM,CAACwD,4BAA4B,CAAC,CAAC,EAAE;QAC1C;QACA;QACA;QACA,IAAM1B,kBAAkB,GAAG9B,MAAM,CAAC8B,kBAAkB,CAAC,CAAC;QACtD,IAAKA,kBAAkB,IAAIpB,cAAc,IACvC,CAACoB,kBAAkB,IAAI,CAACrB,aAAc,EAAE;UACzC,OAAO,IAAI;QACZ;MACD;IACD;EAAC;AAAA;AAAA,SAhmBmBhC,kBAAkB,IAAAqG,OAAA","ignoreList":[]}
@@ -1,57 +1,48 @@
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
-
1
+ 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."); }
2
+ 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; } }
3
+ 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; }
7
4
  // Should be the same as `DIGIT_PLACEHOLDER` in `libphonenumber-metadata-generator`.
8
5
  export var DIGIT_PLACEHOLDER = 'x'; // '\u2008' (punctuation space)
6
+ var DIGIT_PLACEHOLDER_MATCHER = new RegExp(DIGIT_PLACEHOLDER);
9
7
 
10
- var DIGIT_PLACEHOLDER_MATCHER = new RegExp(DIGIT_PLACEHOLDER); // Counts all occurences of a symbol in a string.
8
+ // Counts all occurences of a symbol in a string.
11
9
  // Unicode-unsafe (because using `.split()`).
12
-
13
10
  export function countOccurences(symbol, string) {
14
- var count = 0; // Using `.split('')` to iterate through a string here
11
+ var count = 0;
12
+ // Using `.split('')` to iterate through a string here
15
13
  // to avoid requiring `Symbol.iterator` polyfill.
16
14
  // `.split('')` is generally not safe for Unicode,
17
15
  // but in this particular case for counting brackets it is safe.
18
16
  // for (const character of string)
19
-
20
17
  for (var _iterator = _createForOfIteratorHelperLoose(string.split('')), _step; !(_step = _iterator()).done;) {
21
18
  var character = _step.value;
22
-
23
19
  if (character === symbol) {
24
20
  count++;
25
21
  }
26
22
  }
27
-
28
23
  return count;
29
- } // Repeats a string (or a symbol) N times.
30
- // http://stackoverflow.com/questions/202605/repeat-string-javascript
24
+ }
31
25
 
26
+ // Repeats a string (or a symbol) N times.
27
+ // http://stackoverflow.com/questions/202605/repeat-string-javascript
32
28
  export function repeat(string, times) {
33
29
  if (times < 1) {
34
30
  return '';
35
31
  }
36
-
37
32
  var result = '';
38
-
39
33
  while (times > 1) {
40
34
  if (times & 1) {
41
35
  result += string;
42
36
  }
43
-
44
37
  times >>= 1;
45
38
  string += string;
46
39
  }
47
-
48
40
  return result + string;
49
41
  }
50
42
  export function cutAndStripNonPairedParens(string, cutBeforeIndex) {
51
43
  if (string[cutBeforeIndex] === ')') {
52
44
  cutBeforeIndex++;
53
45
  }
54
-
55
46
  return stripNonPairedParens(string.slice(0, cutBeforeIndex));
56
47
  }
57
48
  export function closeNonPairedParens(template, cut_before) {
@@ -59,41 +50,33 @@ export function closeNonPairedParens(template, cut_before) {
59
50
  var opening_braces = countOccurences('(', retained_template);
60
51
  var closing_braces = countOccurences(')', retained_template);
61
52
  var dangling_braces = opening_braces - closing_braces;
62
-
63
53
  while (dangling_braces > 0 && cut_before < template.length) {
64
54
  if (template[cut_before] === ')') {
65
55
  dangling_braces--;
66
56
  }
67
-
68
57
  cut_before++;
69
58
  }
70
-
71
59
  return template.slice(0, cut_before);
72
60
  }
73
61
  export function stripNonPairedParens(string) {
74
62
  var dangling_braces = [];
75
63
  var i = 0;
76
-
77
64
  while (i < string.length) {
78
65
  if (string[i] === '(') {
79
66
  dangling_braces.push(i);
80
67
  } else if (string[i] === ')') {
81
68
  dangling_braces.pop();
82
69
  }
83
-
84
70
  i++;
85
71
  }
86
-
87
72
  var start = 0;
88
73
  var cleared_string = '';
89
74
  dangling_braces.push(string.length);
90
-
91
75
  for (var _i = 0, _dangling_braces = dangling_braces; _i < _dangling_braces.length; _i++) {
92
76
  var index = _dangling_braces[_i];
93
77
  cleared_string += string.slice(start, index);
94
78
  start = index + 1;
95
79
  }
96
-
97
80
  return cleared_string;
98
81
  }
99
82
  export function populateTemplateWithDigits(template, position, digits) {
@@ -104,7 +87,6 @@ export function populateTemplateWithDigits(template, position, digits) {
104
87
  // for (const digit of digits)
105
88
  for (var _iterator2 = _createForOfIteratorHelperLoose(digits.split('')), _step2; !(_step2 = _iterator2()).done;) {
106
89
  var digit = _step2.value;
107
-
108
90
  // If there is room for more digits in current `template`,
109
91
  // then set the next digit in the `template`,
110
92
  // and return the formatted digits so far.
@@ -112,11 +94,9 @@ export function populateTemplateWithDigits(template, position, digits) {
112
94
  if (template.slice(position + 1).search(DIGIT_PLACEHOLDER_MATCHER) < 0) {
113
95
  return;
114
96
  }
115
-
116
97
  position = template.search(DIGIT_PLACEHOLDER_MATCHER);
117
98
  template = template.replace(DIGIT_PLACEHOLDER_MATCHER, digit);
118
99
  }
119
-
120
100
  return [template, position];
121
101
  }
122
102
  //# sourceMappingURL=AsYouTypeFormatter.util.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AsYouTypeFormatter.util.js","names":["DIGIT_PLACEHOLDER","DIGIT_PLACEHOLDER_MATCHER","RegExp","countOccurences","symbol","string","count","split","character","repeat","times","result","cutAndStripNonPairedParens","cutBeforeIndex","stripNonPairedParens","slice","closeNonPairedParens","template","cut_before","retained_template","opening_braces","closing_braces","dangling_braces","length","i","push","pop","start","cleared_string","index","populateTemplateWithDigits","position","digits","digit","search","replace"],"sources":["../source/AsYouTypeFormatter.util.js"],"sourcesContent":["// Should be the same as `DIGIT_PLACEHOLDER` in `libphonenumber-metadata-generator`.\r\nexport const DIGIT_PLACEHOLDER = 'x' // '\\u2008' (punctuation space)\r\nconst DIGIT_PLACEHOLDER_MATCHER = new RegExp(DIGIT_PLACEHOLDER)\r\n\r\n// Counts all occurences of a symbol in a string.\r\n// Unicode-unsafe (because using `.split()`).\r\nexport function countOccurences(symbol, string) {\r\n\tlet count = 0\r\n\t// Using `.split('')` to iterate through a string here\r\n\t// to avoid requiring `Symbol.iterator` polyfill.\r\n\t// `.split('')` is generally not safe for Unicode,\r\n\t// but in this particular case for counting brackets it is safe.\r\n\t// for (const character of string)\r\n\tfor (const character of string.split('')) {\r\n\t\tif (character === symbol) {\r\n\t\t\tcount++\r\n\t\t}\r\n\t}\r\n\treturn count\r\n}\r\n\r\n// Repeats a string (or a symbol) N times.\r\n// http://stackoverflow.com/questions/202605/repeat-string-javascript\r\nexport function repeat(string, times) {\r\n\tif (times < 1) {\r\n\t\treturn ''\r\n\t}\r\n\tlet result = ''\r\n\twhile (times > 1) {\r\n\t\tif (times & 1) {\r\n\t\t\tresult += string\r\n\t\t}\r\n\t\ttimes >>= 1\r\n\t\tstring += string\r\n\t}\r\n\treturn result + string\r\n}\r\n\r\nexport function cutAndStripNonPairedParens(string, cutBeforeIndex) {\r\n\tif (string[cutBeforeIndex] === ')') {\r\n\t\tcutBeforeIndex++\r\n\t}\r\n\treturn stripNonPairedParens(string.slice(0, cutBeforeIndex))\r\n}\r\n\r\nexport function closeNonPairedParens(template, cut_before) {\r\n\tconst retained_template = template.slice(0, cut_before)\r\n\tconst opening_braces = countOccurences('(', retained_template)\r\n\tconst closing_braces = countOccurences(')', retained_template)\r\n\tlet dangling_braces = opening_braces - closing_braces\r\n\twhile (dangling_braces > 0 && cut_before < template.length) {\r\n\t\tif (template[cut_before] === ')') {\r\n\t\t\tdangling_braces--\r\n\t\t}\r\n\t\tcut_before++\r\n\t}\r\n\treturn template.slice(0, cut_before)\r\n}\r\n\r\nexport function stripNonPairedParens(string) {\r\n\tconst dangling_braces =[]\r\n\tlet i = 0\r\n\twhile (i < string.length) {\r\n\t\tif (string[i] === '(') {\r\n\t\t\tdangling_braces.push(i)\r\n\t\t}\r\n\t\telse if (string[i] === ')') {\r\n\t\t\tdangling_braces.pop()\r\n\t\t}\r\n\t\ti++\r\n\t}\r\n\tlet start = 0\r\n\tlet cleared_string = ''\r\n\tdangling_braces.push(string.length)\r\n\tfor (const index of dangling_braces) {\r\n\t\tcleared_string += string.slice(start, index)\r\n\t\tstart = index + 1\r\n\t}\r\n\treturn cleared_string\r\n}\r\n\r\nexport function populateTemplateWithDigits(template, position, digits) {\r\n\t// Using `.split('')` to iterate through a string here\r\n\t// to avoid requiring `Symbol.iterator` polyfill.\r\n\t// `.split('')` is generally not safe for Unicode,\r\n\t// but in this particular case for `digits` it is safe.\r\n\t// for (const digit of digits)\r\n\tfor (const digit of digits.split('')) {\r\n\t\t// If there is room for more digits in current `template`,\r\n\t\t// then set the next digit in the `template`,\r\n\t\t// and return the formatted digits so far.\r\n\t\t// If more digits are entered than the current format could handle.\r\n\t\tif (template.slice(position + 1).search(DIGIT_PLACEHOLDER_MATCHER) < 0) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\tposition = template.search(DIGIT_PLACEHOLDER_MATCHER)\r\n\t\ttemplate = template.replace(DIGIT_PLACEHOLDER_MATCHER, digit)\r\n\t}\r\n\treturn [template, position]\r\n}"],"mappings":";;;;;;AAAA;AACA,OAAO,IAAMA,iBAAiB,GAAG,GAA1B,C,CAA8B;;AACrC,IAAMC,yBAAyB,GAAG,IAAIC,MAAJ,CAAWF,iBAAX,CAAlC,C,CAEA;AACA;;AACA,OAAO,SAASG,eAAT,CAAyBC,MAAzB,EAAiCC,MAAjC,EAAyC;EAC/C,IAAIC,KAAK,GAAG,CAAZ,CAD+C,CAE/C;EACA;EACA;EACA;EACA;;EACA,qDAAwBD,MAAM,CAACE,KAAP,CAAa,EAAb,CAAxB,wCAA0C;IAAA,IAA/BC,SAA+B;;IACzC,IAAIA,SAAS,KAAKJ,MAAlB,EAA0B;MACzBE,KAAK;IACL;EACD;;EACD,OAAOA,KAAP;AACA,C,CAED;AACA;;AACA,OAAO,SAASG,MAAT,CAAgBJ,MAAhB,EAAwBK,KAAxB,EAA+B;EACrC,IAAIA,KAAK,GAAG,CAAZ,EAAe;IACd,OAAO,EAAP;EACA;;EACD,IAAIC,MAAM,GAAG,EAAb;;EACA,OAAOD,KAAK,GAAG,CAAf,EAAkB;IACjB,IAAIA,KAAK,GAAG,CAAZ,E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AAM,CAACmB,CAAD,CAAN,KAAc,GAAlB,EAAuB;MAC3BF,eAAe,CAACI,GAAhB;IACA;;IACDF,CAAC;EACD;;EACD,IAAIG,KAAK,GAAG,CAAZ;EACA,IAAIC,cAAc,GAAG,EAArB;EACAN,eAAe,CAACG,IAAhB,CAAqBpB,MAAM,CAACkB,MAA5B;;EACA,oCAAoBD,eAApB,sCAAqC;IAAhC,IAAMO,KAAK,uBAAX;IACJD,cAAc,IAAIvB,MAAM,CAACU,KAAP,CAAaY,KAAb,EAAoBE,KAApB,CAAlB;IACAF,KAAK,GAAGE,KAAK,GAAG,CAAhB;EACA;;EACD,OAAOD,cAAP;AACA;AAED,OAAO,SAASE,0BAAT,CAAoCb,QAApC,EAA8Cc,QAA9C,EAAwDC,MAAxD,EAAgE;EACtE;EACA;EACA;EACA;EACA;EACA,sDAAoBA,MAAM,CAACzB,KAAP,CAAa,EAAb,CAApB,2CAAsC;IAAA,IAA3B0B,KAA2B;;IACrC;IACA;IACA;IACA;IACA,IAAIhB,QAAQ,CAACF,KAAT,CAAegB,QAAQ,GAAG,CAA1B,EAA6BG,MAA7B,CAAoCjC,yBAApC,IAAiE,CAArE,EAAwE;MACvE;IACA;;IACD8B,QAAQ,GAAGd,QAAQ,CAACiB,MAAT,CAAgBjC,yBAAhB,CAAX;IACAgB,QAAQ,GAAGA,QAAQ,CAACkB,OAAT,CAAiBlC,yBAAjB,EAA4CgC,KAA5C,CAAX;EACA;;EACD,OAAO,CAAChB,QAAD,EAAWc,QAAX,CAAP;AACA"}
1
+ {"version":3,"file":"AsYouTypeFormatter.util.js","names":["DIGIT_PLACEHOLDER","DIGIT_PLACEHOLDER_MATCHER","RegExp","countOccurences","symbol","string","count","_iterator","_createForOfIteratorHelperLoose","split","_step","done","character","value","repeat","times","result","cutAndStripNonPairedParens","cutBeforeIndex","stripNonPairedParens","slice","closeNonPairedParens","template","cut_before","retained_template","opening_braces","closing_braces","dangling_braces","length","i","push","pop","start","cleared_string","_i","_dangling_braces","index","populateTemplateWithDigits","position","digits","_iterator2","_step2","digit","search","replace"],"sources":["../source/AsYouTypeFormatter.util.js"],"sourcesContent":["// Should be the same as `DIGIT_PLACEHOLDER` in `libphonenumber-metadata-generator`.\r\nexport const DIGIT_PLACEHOLDER = 'x' // '\\u2008' (punctuation space)\r\nconst DIGIT_PLACEHOLDER_MATCHER = new RegExp(DIGIT_PLACEHOLDER)\r\n\r\n// Counts all occurences of a symbol in a string.\r\n// Unicode-unsafe (because using `.split()`).\r\nexport function countOccurences(symbol, string) {\r\n\tlet count = 0\r\n\t// Using `.split('')` to iterate through a string here\r\n\t// to avoid requiring `Symbol.iterator` polyfill.\r\n\t// `.split('')` is generally not safe for Unicode,\r\n\t// but in this particular case for counting brackets it is safe.\r\n\t// for (const character of string)\r\n\tfor (const character of string.split('')) {\r\n\t\tif (character === symbol) {\r\n\t\t\tcount++\r\n\t\t}\r\n\t}\r\n\treturn count\r\n}\r\n\r\n// Repeats a string (or a symbol) N times.\r\n// http://stackoverflow.com/questions/202605/repeat-string-javascript\r\nexport function repeat(string, times) {\r\n\tif (times < 1) {\r\n\t\treturn ''\r\n\t}\r\n\tlet result = ''\r\n\twhile (times > 1) {\r\n\t\tif (times & 1) {\r\n\t\t\tresult += string\r\n\t\t}\r\n\t\ttimes >>= 1\r\n\t\tstring += string\r\n\t}\r\n\treturn result + string\r\n}\r\n\r\nexport function cutAndStripNonPairedParens(string, cutBeforeIndex) {\r\n\tif (string[cutBeforeIndex] === ')') {\r\n\t\tcutBeforeIndex++\r\n\t}\r\n\treturn stripNonPairedParens(string.slice(0, cutBeforeIndex))\r\n}\r\n\r\nexport function closeNonPairedParens(template, cut_before) {\r\n\tconst retained_template = template.slice(0, cut_before)\r\n\tconst opening_braces = countOccurences('(', retained_template)\r\n\tconst closing_braces = countOccurences(')', retained_template)\r\n\tlet dangling_braces = opening_braces - closing_braces\r\n\twhile (dangling_braces > 0 && cut_before < template.length) {\r\n\t\tif (template[cut_before] === ')') {\r\n\t\t\tdangling_braces--\r\n\t\t}\r\n\t\tcut_before++\r\n\t}\r\n\treturn template.slice(0, cut_before)\r\n}\r\n\r\nexport function stripNonPairedParens(string) {\r\n\tconst dangling_braces =[]\r\n\tlet i = 0\r\n\twhile (i < string.length) {\r\n\t\tif (string[i] === '(') {\r\n\t\t\tdangling_braces.push(i)\r\n\t\t}\r\n\t\telse if (string[i] === ')') {\r\n\t\t\tdangling_braces.pop()\r\n\t\t}\r\n\t\ti++\r\n\t}\r\n\tlet start = 0\r\n\tlet cleared_string = ''\r\n\tdangling_braces.push(string.length)\r\n\tfor (const index of dangling_braces) {\r\n\t\tcleared_string += string.slice(start, index)\r\n\t\tstart = index + 1\r\n\t}\r\n\treturn cleared_string\r\n}\r\n\r\nexport function populateTemplateWithDigits(template, position, digits) {\r\n\t// Using `.split('')` to iterate through a string here\r\n\t// to avoid requiring `Symbol.iterator` polyfill.\r\n\t// `.split('')` is generally not safe for Unicode,\r\n\t// but in this particular case for `digits` it is safe.\r\n\t// for (const digit of digits)\r\n\tfor (const digit of digits.split('')) {\r\n\t\t// If there is room for more digits in current `template`,\r\n\t\t// then set the next digit in the `template`,\r\n\t\t// and return the formatted digits so far.\r\n\t\t// If more digits are entered than the current format could handle.\r\n\t\tif (template.slice(position + 1).search(DIGIT_PLACEHOLDER_MATCHER) < 0) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\tposition = template.search(DIGIT_PLACEHOLDER_MATCHER)\r\n\t\ttemplate = template.replace(DIGIT_PLACEHOLDER_MATCHER, digit)\r\n\t}\r\n\treturn [template, position]\r\n}"],"mappings":";;;AAAA;AACA,OAAO,IAAMA,iBAAiB,GAAG,GAAG,EAAC;AACrC,IAAMC,yBAAyB,GAAG,IAAIC,MAAM,CAACF,iBAAiB,CAAC;;AAE/D;AACA;AACA,OAAO,SAASG,eAAeA,CAACC,MAAM,EAAEC,MAAM,EAAE;EAC/C,IAAIC,KAAK,GAAG,CAAC;EACb;EACA;EACA;EACA;EACA;EACA,SAAA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IAAA7B,IAAA,GAAE;IAAA,IAA3B+B,KAAK,GAAAD,MAAA,CAAA5B,KAAA;IACf;IACA;IACA;IACA;IACA,IAAIS,QAAQ,CAACF,KAAK,CAACkB,QAAQ,GAAG,CAAC,CAAC,CAACK,MAAM,CAAC1C,yBAAyB,CAAC,GAAG,CAAC,EAAE;MACvE;IACD;IACAqC,QAAQ,GAAGhB,QAAQ,CAACqB,MAAM,CAAC1C,yBAAyB,CAAC;IACrDqB,QAAQ,GAAGA,QAAQ,CAACsB,OAAO,CAAC3C,yBAAyB,EAAEyC,KAAK,CAAC;EAC9D;EACA,OAAO,CAACpB,QAAQ,EAAEgB,QAAQ,CAAC;AAC5B","ignoreList":[]}
@@ -1,20 +1,20 @@
1
1
  import { closeNonPairedParens, stripNonPairedParens, repeat } from './AsYouTypeFormatter.util.js';
2
2
  describe('closeNonPairedParens', function () {
3
3
  it('should close non-paired braces', function () {
4
- closeNonPairedParens('(000) 123-45 (9 )', 15).should.equal('(000) 123-45 (9 )');
4
+ expect(closeNonPairedParens('(000) 123-45 (9 )', 15)).to.equal('(000) 123-45 (9 )');
5
5
  });
6
6
  });
7
7
  describe('stripNonPairedParens', function () {
8
8
  it('should strip non-paired braces', function () {
9
- stripNonPairedParens('(000) 123-45 (9').should.equal('(000) 123-45 9');
10
- stripNonPairedParens('(000) 123-45 (9)').should.equal('(000) 123-45 (9)');
9
+ expect(stripNonPairedParens('(000) 123-45 (9')).to.equal('(000) 123-45 9');
10
+ expect(stripNonPairedParens('(000) 123-45 (9)')).to.equal('(000) 123-45 (9)');
11
11
  });
12
12
  });
13
13
  describe('repeat', function () {
14
14
  it('should repeat string N times', function () {
15
- repeat('a', 0).should.equal('');
16
- repeat('a', 3).should.equal('aaa');
17
- repeat('a', 4).should.equal('aaaa');
15
+ expect(repeat('a', 0)).to.equal('');
16
+ expect(repeat('a', 3)).to.equal('aaa');
17
+ expect(repeat('a', 4)).to.equal('aaaa');
18
18
  });
19
19
  });
20
20
  //# sourceMappingURL=AsYouTypeFormatter.util.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AsYouTypeFormatter.util.test.js","names":["closeNonPairedParens","stripNonPairedParens","repeat","describe","it","should","equal"],"sources":["../source/AsYouTypeFormatter.util.test.js"],"sourcesContent":["import { closeNonPairedParens, stripNonPairedParens, repeat } from './AsYouTypeFormatter.util.js'\r\n\r\ndescribe('closeNonPairedParens', () => {\r\n\tit('should close non-paired braces', () => {\r\n\t\tcloseNonPairedParens('(000) 123-45 (9 )', 15).should.equal('(000) 123-45 (9 )')\r\n\t})\r\n})\r\n\r\ndescribe('stripNonPairedParens', () => {\r\n\tit('should strip non-paired braces', () => {\r\n\t\tstripNonPairedParens('(000) 123-45 (9').should.equal('(000) 123-45 9')\r\n\t\tstripNonPairedParens('(000) 123-45 (9)').should.equal('(000) 123-45 (9)')\r\n\t})\r\n})\r\n\r\ndescribe('repeat', () => {\r\n\tit('should repeat string N times', () => {\r\n\t\trepeat('a', 0).should.equal('')\r\n\t\trepeat('a', 3).should.equal('aaa')\r\n\t\trepeat('a', 4).should.equal('aaaa')\r\n\t})\r\n})"],"mappings":"AAAA,SAASA,oBAAT,EAA+BC,oBAA/B,EAAqDC,MAArD,QAAmE,8BAAnE;AAEAC,QAAQ,CAAC,sBAAD,EAAyB,YAAM;EACtCC,EAAE,CAAC,gCAAD,EAAmC,YAAM;IAC1CJ,oBAAoB,CAAC,oBAAD,EAAuB,EAAvB,CAApB,CAA+CK,MAA/C,CAAsDC,KAAtD,CAA4D,oBAA5D;EACA,CAFC,CAAF;AAGA,CAJO,CAAR;AAMAH,QAAQ,CAAC,sBAAD,EAAyB,YAAM;EACtCC,EAAE,CAAC,gCAAD,EAAmC,YAAM;IAC1CH,oBAAoB,CAAC,iBAAD,CAApB,CAAwCI,MAAxC,CAA+CC,KAA/C,CAAqD,gBAArD;IACAL,oBAAoB,CAAC,kBAAD,CAApB,CAAyCI,MAAzC,CAAgDC,KAAhD,CAAsD,kBAAtD;EACA,CAHC,CAAF;AAIA,CALO,CAAR;AAOAH,QAAQ,CAAC,QAAD,EAAW,YAAM;EACxBC,EAAE,CAAC,8BAAD,EAAiC,YAAM;IACxCF,MAAM,CAAC,GAAD,EAAM,CAAN,CAAN,CAAeG,MAAf,CAAsBC,KAAtB,CAA4B,EAA5B;IACAJ,MAAM,CAAC,GAAD,EAAM,CAAN,CAAN,CAAeG,MAAf,CAAsBC,KAAtB,CAA4B,KAA5B;IACAJ,MAAM,CAAC,GAAD,EAAM,CAAN,CAAN,CAAeG,MAAf,CAAsBC,KAAtB,CAA4B,MAA5B;EACA,CAJC,CAAF;AAKA,CANO,CAAR"}
1
+ {"version":3,"file":"AsYouTypeFormatter.util.test.js","names":["closeNonPairedParens","stripNonPairedParens","repeat","describe","it","expect","to","equal"],"sources":["../source/AsYouTypeFormatter.util.test.js"],"sourcesContent":["import { closeNonPairedParens, stripNonPairedParens, repeat } from './AsYouTypeFormatter.util.js'\r\n\r\ndescribe('closeNonPairedParens', () => {\r\n\tit('should close non-paired braces', () => {\r\n\t\texpect(closeNonPairedParens('(000) 123-45 (9 )', 15)).to.equal('(000) 123-45 (9 )')\r\n\t})\r\n})\r\n\r\ndescribe('stripNonPairedParens', () => {\r\n\tit('should strip non-paired braces', () => {\r\n\t\texpect(stripNonPairedParens('(000) 123-45 (9')).to.equal('(000) 123-45 9')\r\n\t\texpect(stripNonPairedParens('(000) 123-45 (9)')).to.equal('(000) 123-45 (9)')\r\n\t})\r\n})\r\n\r\ndescribe('repeat', () => {\r\n\tit('should repeat string N times', () => {\r\n\t\texpect(repeat('a', 0)).to.equal('')\r\n\t\texpect(repeat('a', 3)).to.equal('aaa')\r\n\t\texpect(repeat('a', 4)).to.equal('aaaa')\r\n\t})\r\n})"],"mappings":"AAAA,SAASA,oBAAoB,EAAEC,oBAAoB,EAAEC,MAAM,QAAQ,8BAA8B;AAEjGC,QAAQ,CAAC,sBAAsB,EAAE,YAAM;EACtCC,EAAE,CAAC,gCAAgC,EAAE,YAAM;IAC1CC,MAAM,CAACL,oBAAoB,CAAC,oBAAoB,EAAE,EAAE,CAAC,CAAC,CAACM,EAAE,CAACC,KAAK,CAAC,oBAAoB,CAAC;EACtF,CAAC,CAAC;AACH,CAAC,CAAC;AAEFJ,QAAQ,CAAC,sBAAsB,EAAE,YAAM;EACtCC,EAAE,CAAC,gCAAgC,EAAE,YAAM;IAC1CC,MAAM,CAACJ,oBAAoB,CAAC,iBAAiB,CAAC,CAAC,CAACK,EAAE,CAACC,KAAK,CAAC,gBAAgB,CAAC;IAC1EF,MAAM,CAACJ,oBAAoB,CAAC,kBAAkB,CAAC,CAAC,CAACK,EAAE,CAACC,KAAK,CAAC,kBAAkB,CAAC;EAC9E,CAAC,CAAC;AACH,CAAC,CAAC;AAEFJ,QAAQ,CAAC,QAAQ,EAAE,YAAM;EACxBC,EAAE,CAAC,8BAA8B,EAAE,YAAM;IACxCC,MAAM,CAACH,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAACI,EAAE,CAACC,KAAK,CAAC,EAAE,CAAC;IACnCF,MAAM,CAACH,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAACI,EAAE,CAACC,KAAK,CAAC,KAAK,CAAC;IACtCF,MAAM,CAACH,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAACI,EAAE,CAACC,KAAK,CAAC,MAAM,CAAC;EACxC,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]}