libphonenumber-js 1.13.6 → 1.13.8

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