libphonenumber-js 1.9.2 → 1.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (367) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +34 -9
  3. package/build/AsYouType.js +16 -21
  4. package/build/AsYouType.js.map +1 -1
  5. package/build/AsYouType.test.js +12 -3
  6. package/build/AsYouType.test.js.map +1 -1
  7. package/build/AsYouTypeFormatter.complete.js +4 -4
  8. package/build/AsYouTypeFormatter.complete.js.map +1 -1
  9. package/build/AsYouTypeFormatter.js +25 -15
  10. package/build/AsYouTypeFormatter.js.map +1 -1
  11. package/build/AsYouTypeParser.js +70 -37
  12. package/build/AsYouTypeParser.js.map +1 -1
  13. package/build/AsYouTypeState.js +1 -0
  14. package/build/AsYouTypeState.js.map +1 -1
  15. package/build/PhoneNumber.js +2 -2
  16. package/build/PhoneNumber.js.map +1 -1
  17. package/build/PhoneNumberMatcher.js +20 -16
  18. package/build/PhoneNumberMatcher.js.map +1 -1
  19. package/build/findNumbers/Leniency.js +1 -1
  20. package/build/findNumbers/Leniency.js.map +1 -1
  21. package/build/findNumbers.test.js +31 -22
  22. package/build/findNumbers.test.js.map +1 -1
  23. package/build/findPhoneNumbers_.js +21 -4
  24. package/build/findPhoneNumbers_.js.map +1 -1
  25. package/build/format.test.js +0 -6
  26. package/build/format.test.js.map +1 -1
  27. package/build/formatNumberForMobileDialing.js +3 -3
  28. package/build/formatNumberForMobileDialing.js.map +1 -1
  29. package/build/format_.js +15 -84
  30. package/build/format_.js.map +1 -1
  31. package/build/getNumberType.js +3 -3
  32. package/build/getNumberType.js.map +1 -1
  33. package/build/{RFC3966.js → helpers/RFC3966.js} +0 -0
  34. package/build/helpers/RFC3966.js.map +1 -0
  35. package/build/{RFC3966.test.js → helpers/RFC3966.test.js} +0 -0
  36. package/build/helpers/RFC3966.test.js.map +1 -0
  37. package/build/helpers/applyInternationalSeparatorStyle.js +43 -0
  38. package/build/helpers/applyInternationalSeparatorStyle.js.map +1 -0
  39. package/build/helpers/applyInternationalSeparatorStyle.test.js +13 -0
  40. package/build/helpers/applyInternationalSeparatorStyle.test.js.map +1 -0
  41. package/build/{checkNumberLength.js → helpers/checkNumberLength.js} +4 -2
  42. package/build/helpers/checkNumberLength.js.map +1 -0
  43. package/build/{checkNumberLength.test.js → helpers/checkNumberLength.test.js} +2 -2
  44. package/build/helpers/checkNumberLength.test.js.map +1 -0
  45. package/build/{extension.js → helpers/extension/createExtensionPattern.js} +3 -56
  46. package/build/helpers/extension/createExtensionPattern.js.map +1 -0
  47. package/build/helpers/extension/extractExtension.js +42 -0
  48. package/build/helpers/extension/extractExtension.js.map +1 -0
  49. package/build/helpers/extractCountryCallingCode.js +114 -0
  50. package/build/helpers/extractCountryCallingCode.js.map +1 -0
  51. package/build/helpers/extractCountryCallingCode.test.js +22 -0
  52. package/build/helpers/extractCountryCallingCode.test.js.map +1 -0
  53. package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +63 -0
  54. package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -0
  55. package/build/helpers/extractNationalNumber.js +110 -0
  56. package/build/helpers/extractNationalNumber.js.map +1 -0
  57. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +114 -0
  58. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -0
  59. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +22 -0
  60. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js.map +1 -0
  61. package/build/helpers/formatNationalNumberUsingFormat.js +46 -0
  62. package/build/helpers/formatNationalNumberUsingFormat.js.map +1 -0
  63. package/build/helpers/getCountryByCallingCode.js +73 -0
  64. package/build/helpers/getCountryByCallingCode.js.map +1 -0
  65. package/build/helpers/getIddPrefix.js +34 -0
  66. package/build/helpers/getIddPrefix.js.map +1 -0
  67. package/build/{getNumberType_.js → helpers/getNumberType.js} +12 -12
  68. package/build/helpers/getNumberType.js.map +1 -0
  69. package/build/{isViablePhoneNumber.js → helpers/isViablePhoneNumber.js} +5 -3
  70. package/build/helpers/isViablePhoneNumber.js.map +1 -0
  71. package/build/helpers/matchesEntirely.js +19 -0
  72. package/build/helpers/matchesEntirely.js.map +1 -0
  73. package/build/helpers/matchesEntirely.test.js +15 -0
  74. package/build/helpers/matchesEntirely.test.js.map +1 -0
  75. package/build/{util.js → helpers/mergeArrays.js} +3 -18
  76. package/build/helpers/mergeArrays.js.map +1 -0
  77. package/build/helpers/mergeArrays.test.js +12 -0
  78. package/build/helpers/mergeArrays.test.js.map +1 -0
  79. package/build/{parseDigits.js → helpers/parseDigits.js} +0 -0
  80. package/build/helpers/parseDigits.js.map +1 -0
  81. package/build/{parseDigits.test.js → helpers/parseDigits.test.js} +0 -0
  82. package/build/helpers/parseDigits.test.js.map +1 -0
  83. package/build/helpers/stripIddPrefix.js +46 -0
  84. package/build/helpers/stripIddPrefix.js.map +1 -0
  85. package/build/helpers/stripIddPrefix.test.js +23 -0
  86. package/build/helpers/stripIddPrefix.test.js.map +1 -0
  87. package/build/isPossibleNumber_.js +1 -1
  88. package/build/isPossibleNumber_.js.map +1 -1
  89. package/build/isValidNumberForRegion.js +1 -1
  90. package/build/isValidNumberForRegion.js.map +1 -1
  91. package/build/parse.test.js +1 -25
  92. package/build/parse.test.js.map +1 -1
  93. package/build/parseIncompletePhoneNumber.js +9 -6
  94. package/build/parseIncompletePhoneNumber.js.map +1 -1
  95. package/build/parse_.js +19 -425
  96. package/build/parse_.js.map +1 -1
  97. package/build/validate_.js +4 -4
  98. package/build/validate_.js.map +1 -1
  99. package/bundle/libphonenumber-js.min.js +1 -1
  100. package/bundle/libphonenumber-js.min.js.map +1 -1
  101. package/bundle/libphonenumber-max.js +1 -1
  102. package/bundle/libphonenumber-max.js.map +1 -1
  103. package/bundle/libphonenumber-min.js +1 -1
  104. package/bundle/libphonenumber-min.js.map +1 -1
  105. package/bundle/libphonenumber-mobile.js +1 -1
  106. package/bundle/libphonenumber-mobile.js.map +1 -1
  107. package/core/index.commonjs.js +5 -3
  108. package/core/index.d.ts +9 -1
  109. package/core/index.js +6 -2
  110. package/custom.d.ts +9 -1
  111. package/custom.js +5 -6
  112. package/es6/AsYouType.js +17 -22
  113. package/es6/AsYouType.js.map +1 -1
  114. package/es6/AsYouType.test.js +12 -3
  115. package/es6/AsYouType.test.js.map +1 -1
  116. package/es6/AsYouTypeFormatter.complete.js +3 -3
  117. package/es6/AsYouTypeFormatter.complete.js.map +1 -1
  118. package/es6/AsYouTypeFormatter.js +22 -13
  119. package/es6/AsYouTypeFormatter.js.map +1 -1
  120. package/es6/AsYouTypeParser.js +65 -32
  121. package/es6/AsYouTypeParser.js.map +1 -1
  122. package/es6/AsYouTypeState.js +1 -0
  123. package/es6/AsYouTypeState.js.map +1 -1
  124. package/es6/PhoneNumber.js +1 -1
  125. package/es6/PhoneNumber.js.map +1 -1
  126. package/es6/PhoneNumberMatcher.js +18 -15
  127. package/es6/PhoneNumberMatcher.js.map +1 -1
  128. package/es6/findNumbers/Leniency.js +1 -1
  129. package/es6/findNumbers/Leniency.js.map +1 -1
  130. package/es6/findNumbers.test.js +10 -1
  131. package/es6/findNumbers.test.js.map +1 -1
  132. package/es6/findPhoneNumbers_.js +19 -2
  133. package/es6/findPhoneNumbers_.js.map +1 -1
  134. package/es6/format.test.js +0 -5
  135. package/es6/format.test.js.map +1 -1
  136. package/es6/formatNumberForMobileDialing.js +2 -2
  137. package/es6/formatNumberForMobileDialing.js.map +1 -1
  138. package/es6/format_.js +11 -76
  139. package/es6/format_.js.map +1 -1
  140. package/es6/getNumberType.js +2 -2
  141. package/es6/getNumberType.js.map +1 -1
  142. package/es6/{RFC3966.js → helpers/RFC3966.js} +0 -0
  143. package/es6/helpers/RFC3966.js.map +1 -0
  144. package/es6/{RFC3966.test.js → helpers/RFC3966.test.js} +0 -0
  145. package/es6/helpers/RFC3966.test.js.map +1 -0
  146. package/es6/helpers/applyInternationalSeparatorStyle.js +35 -0
  147. package/es6/helpers/applyInternationalSeparatorStyle.js.map +1 -0
  148. package/es6/helpers/applyInternationalSeparatorStyle.test.js +8 -0
  149. package/es6/helpers/applyInternationalSeparatorStyle.test.js.map +1 -0
  150. package/es6/{checkNumberLength.js → helpers/checkNumberLength.js} +1 -1
  151. package/es6/helpers/checkNumberLength.js.map +1 -0
  152. package/es6/{checkNumberLength.test.js → helpers/checkNumberLength.test.js} +2 -2
  153. package/es6/helpers/checkNumberLength.test.js.map +1 -0
  154. package/es6/{extension.js → helpers/extension/createExtensionPattern.js} +3 -51
  155. package/es6/helpers/extension/createExtensionPattern.js.map +1 -0
  156. package/es6/helpers/extension/extractExtension.js +32 -0
  157. package/es6/helpers/extension/extractExtension.js.map +1 -0
  158. package/es6/helpers/extractCountryCallingCode.js +102 -0
  159. package/es6/helpers/extractCountryCallingCode.js.map +1 -0
  160. package/es6/helpers/extractCountryCallingCode.test.js +16 -0
  161. package/es6/helpers/extractCountryCallingCode.test.js.map +1 -0
  162. package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +50 -0
  163. package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -0
  164. package/es6/helpers/extractNationalNumber.js +98 -0
  165. package/es6/helpers/extractNationalNumber.js.map +1 -0
  166. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +107 -0
  167. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -0
  168. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +15 -0
  169. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js.map +1 -0
  170. package/es6/helpers/formatNationalNumberUsingFormat.js +33 -0
  171. package/es6/helpers/formatNationalNumberUsingFormat.js.map +1 -0
  172. package/es6/helpers/getCountryByCallingCode.js +61 -0
  173. package/es6/helpers/getCountryByCallingCode.js.map +1 -0
  174. package/es6/helpers/getIddPrefix.js +25 -0
  175. package/es6/helpers/getIddPrefix.js.map +1 -0
  176. package/es6/{getNumberType_.js → helpers/getNumberType.js} +9 -9
  177. package/es6/helpers/getNumberType.js.map +1 -0
  178. package/es6/{isViablePhoneNumber.js → helpers/isViablePhoneNumber.js} +2 -2
  179. package/es6/helpers/isViablePhoneNumber.js.map +1 -0
  180. package/es6/helpers/matchesEntirely.js +12 -0
  181. package/es6/helpers/matchesEntirely.js.map +1 -0
  182. package/es6/helpers/matchesEntirely.test.js +10 -0
  183. package/es6/helpers/matchesEntirely.test.js.map +1 -0
  184. package/es6/{util.js → helpers/mergeArrays.js} +3 -16
  185. package/es6/helpers/mergeArrays.js.map +1 -0
  186. package/es6/helpers/mergeArrays.test.js +7 -0
  187. package/es6/helpers/mergeArrays.test.js.map +1 -0
  188. package/es6/{parseDigits.js → helpers/parseDigits.js} +0 -0
  189. package/es6/helpers/parseDigits.js.map +1 -0
  190. package/es6/{parseDigits.test.js → helpers/parseDigits.test.js} +0 -0
  191. package/es6/helpers/parseDigits.test.js.map +1 -0
  192. package/es6/helpers/stripIddPrefix.js +34 -0
  193. package/es6/helpers/stripIddPrefix.js.map +1 -0
  194. package/es6/helpers/stripIddPrefix.test.js +17 -0
  195. package/es6/helpers/stripIddPrefix.test.js.map +1 -0
  196. package/es6/isPossibleNumber_.js +1 -1
  197. package/es6/isPossibleNumber_.js.map +1 -1
  198. package/es6/isValidNumberForRegion.js +1 -1
  199. package/es6/isValidNumberForRegion.js.map +1 -1
  200. package/es6/parse.test.js +1 -24
  201. package/es6/parse.test.js.map +1 -1
  202. package/es6/parseIncompletePhoneNumber.js +9 -6
  203. package/es6/parseIncompletePhoneNumber.js.map +1 -1
  204. package/es6/parse_.js +12 -411
  205. package/es6/parse_.js.map +1 -1
  206. package/es6/validate_.js +2 -2
  207. package/es6/validate_.js.map +1 -1
  208. package/index.common.js +71 -183
  209. package/index.d.ts +9 -5
  210. package/index.es6.exports/PhoneNumberSearch.js +11 -0
  211. package/index.es6.exports/findPhoneNumbers.js +7 -0
  212. package/index.es6.exports/format.js +7 -0
  213. package/index.es6.exports/getNumberType.js +7 -0
  214. package/index.es6.exports/isPossibleNumber.js +7 -0
  215. package/index.es6.exports/isValidNumber.js +7 -0
  216. package/index.es6.exports/isValidNumberForRegion.js +7 -0
  217. package/index.es6.exports/parse.js +7 -0
  218. package/index.es6.exports/searchPhoneNumbers.js +7 -0
  219. package/index.es6.js +46 -254
  220. package/max/exports/AsYouType.js +9 -0
  221. package/max/exports/Metadata.js +9 -0
  222. package/max/exports/PhoneNumberMatcher.js +8 -0
  223. package/max/exports/findNumbers.js +6 -0
  224. package/max/exports/findPhoneNumbersInText.js +6 -0
  225. package/max/exports/formatIncompletePhoneNumber.js +6 -0
  226. package/max/exports/getCountries.js +6 -0
  227. package/max/exports/getCountryCallingCode.js +6 -0
  228. package/max/exports/getExampleNumber.js +6 -0
  229. package/max/exports/getExtPrefix.js +6 -0
  230. package/max/exports/isSupportedCountry.js +6 -0
  231. package/max/exports/parsePhoneNumberFromString.js +6 -0
  232. package/max/exports/parsePhoneNumberWithError.js +6 -0
  233. package/max/exports/searchNumbers.js +6 -0
  234. package/max/exports/searchPhoneNumbersInText.js +6 -0
  235. package/max/index.commonjs.js +1 -0
  236. package/max/index.js +23 -103
  237. package/max/metadata.js +11 -0
  238. package/metadata.full.json +1 -1
  239. package/metadata.full.json.js +1 -1
  240. package/metadata.min.json +1 -1
  241. package/metadata.min.json.js +1 -1
  242. package/metadata.mobile.json +1 -1
  243. package/metadata.mobile.json.js +1 -1
  244. package/min/exports/AsYouType.js +9 -0
  245. package/min/exports/Metadata.js +9 -0
  246. package/min/exports/PhoneNumberMatcher.js +8 -0
  247. package/min/exports/findNumbers.js +6 -0
  248. package/min/exports/findPhoneNumbersInText.js +6 -0
  249. package/min/exports/formatIncompletePhoneNumber.js +6 -0
  250. package/min/exports/getCountries.js +6 -0
  251. package/min/exports/getCountryCallingCode.js +6 -0
  252. package/min/exports/getExampleNumber.js +6 -0
  253. package/min/exports/getExtPrefix.js +6 -0
  254. package/min/exports/isSupportedCountry.js +6 -0
  255. package/min/exports/parsePhoneNumberFromString.js +6 -0
  256. package/min/exports/parsePhoneNumberWithError.js +6 -0
  257. package/min/exports/searchNumbers.js +6 -0
  258. package/min/exports/searchPhoneNumbersInText.js +6 -0
  259. package/min/index.commonjs.js +7 -0
  260. package/min/index.d.ts +11 -1
  261. package/min/index.js +23 -103
  262. package/min/metadata.js +11 -0
  263. package/mobile/exports/AsYouType.js +9 -0
  264. package/mobile/exports/Metadata.js +9 -0
  265. package/mobile/exports/PhoneNumberMatcher.js +8 -0
  266. package/mobile/exports/findNumbers.js +6 -0
  267. package/mobile/exports/findPhoneNumbersInText.js +6 -0
  268. package/mobile/exports/formatIncompletePhoneNumber.js +6 -0
  269. package/mobile/exports/getCountries.js +6 -0
  270. package/mobile/exports/getCountryCallingCode.js +6 -0
  271. package/mobile/exports/getExampleNumber.js +6 -0
  272. package/mobile/exports/getExtPrefix.js +6 -0
  273. package/mobile/exports/isSupportedCountry.js +6 -0
  274. package/mobile/exports/parsePhoneNumberFromString.js +6 -0
  275. package/mobile/exports/parsePhoneNumberWithError.js +6 -0
  276. package/mobile/exports/searchNumbers.js +6 -0
  277. package/mobile/exports/searchPhoneNumbersInText.js +6 -0
  278. package/mobile/index.commonjs.js +1 -0
  279. package/mobile/index.js +23 -103
  280. package/mobile/metadata.js +11 -0
  281. package/package.json +3 -2
  282. package/runnable/generate-country-codes.js +13 -0
  283. package/source/AsYouType.js +13 -23
  284. package/source/AsYouType.test.js +13 -3
  285. package/source/AsYouTypeFormatter.complete.js +3 -3
  286. package/source/AsYouTypeFormatter.js +21 -28
  287. package/source/AsYouTypeParser.js +65 -48
  288. package/source/AsYouTypeState.js +1 -0
  289. package/source/PhoneNumber.js +1 -1
  290. package/source/PhoneNumberMatcher.js +28 -35
  291. package/source/findNumbers/Leniency.js +1 -1
  292. package/source/findNumbers.test.js +14 -1
  293. package/source/findPhoneNumbers_.js +19 -2
  294. package/source/format.test.js +0 -6
  295. package/source/formatNumberForMobileDialing.js +2 -2
  296. package/source/format_.js +7 -86
  297. package/source/getNumberType.js +2 -2
  298. package/source/{RFC3966.js → helpers/RFC3966.js} +7 -16
  299. package/source/{RFC3966.test.js → helpers/RFC3966.test.js} +0 -0
  300. package/source/helpers/applyInternationalSeparatorStyle.js +35 -0
  301. package/source/helpers/applyInternationalSeparatorStyle.test.js +8 -0
  302. package/source/{checkNumberLength.js → helpers/checkNumberLength.js} +1 -1
  303. package/source/{checkNumberLength.test.js → helpers/checkNumberLength.test.js} +2 -2
  304. package/source/{extension.js → helpers/extension/createExtensionPattern.js} +2 -49
  305. package/source/helpers/extension/extractExtension.js +29 -0
  306. package/source/helpers/extractCountryCallingCode.js +106 -0
  307. package/source/helpers/extractCountryCallingCode.test.js +18 -0
  308. package/source/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +63 -0
  309. package/source/helpers/extractNationalNumber.js +92 -0
  310. package/source/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +104 -0
  311. package/source/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +15 -0
  312. package/source/helpers/formatNationalNumberUsingFormat.js +46 -0
  313. package/source/helpers/getCountryByCallingCode.js +44 -0
  314. package/source/helpers/getIddPrefix.js +23 -0
  315. package/source/{getNumberType_.js → helpers/getNumberType.js} +14 -28
  316. package/source/{isViablePhoneNumber.js → helpers/isViablePhoneNumber.js} +3 -4
  317. package/source/helpers/matchesEntirely.js +11 -0
  318. package/source/helpers/matchesEntirely.test.js +11 -0
  319. package/source/helpers/mergeArrays.js +24 -0
  320. package/source/helpers/mergeArrays.test.js +7 -0
  321. package/source/{parseDigits.js → helpers/parseDigits.js} +2 -4
  322. package/source/{parseDigits.test.js → helpers/parseDigits.test.js} +0 -0
  323. package/source/helpers/stripIddPrefix.js +30 -0
  324. package/source/helpers/stripIddPrefix.test.js +21 -0
  325. package/source/isPossibleNumber_.js +1 -1
  326. package/source/isValidNumberForRegion.js +1 -1
  327. package/source/parse.test.js +1 -28
  328. package/source/parseIncompletePhoneNumber.js +9 -6
  329. package/source/parse_.js +12 -405
  330. package/source/validate_.js +2 -2
  331. package/types.d.ts +16 -1
  332. package/build/IDD.js +0 -70
  333. package/build/IDD.js.map +0 -1
  334. package/build/IDD.test.js +0 -23
  335. package/build/IDD.test.js.map +0 -1
  336. package/build/RFC3966.js.map +0 -1
  337. package/build/RFC3966.test.js.map +0 -1
  338. package/build/checkNumberLength.js.map +0 -1
  339. package/build/checkNumberLength.test.js.map +0 -1
  340. package/build/extension.js.map +0 -1
  341. package/build/getNumberType_.js.map +0 -1
  342. package/build/isViablePhoneNumber.js.map +0 -1
  343. package/build/parseDigits.js.map +0 -1
  344. package/build/parseDigits.test.js.map +0 -1
  345. package/build/util.js.map +0 -1
  346. package/build/util.test.js +0 -16
  347. package/build/util.test.js.map +0 -1
  348. package/es6/IDD.js +0 -57
  349. package/es6/IDD.js.map +0 -1
  350. package/es6/IDD.test.js +0 -17
  351. package/es6/IDD.test.js.map +0 -1
  352. package/es6/RFC3966.js.map +0 -1
  353. package/es6/RFC3966.test.js.map +0 -1
  354. package/es6/checkNumberLength.js.map +0 -1
  355. package/es6/checkNumberLength.test.js.map +0 -1
  356. package/es6/extension.js.map +0 -1
  357. package/es6/getNumberType_.js.map +0 -1
  358. package/es6/isViablePhoneNumber.js.map +0 -1
  359. package/es6/parseDigits.js.map +0 -1
  360. package/es6/parseDigits.test.js.map +0 -1
  361. package/es6/util.js.map +0 -1
  362. package/es6/util.test.js +0 -13
  363. package/es6/util.test.js.map +0 -1
  364. package/source/IDD.js +0 -52
  365. package/source/IDD.test.js +0 -21
  366. package/source/util.js +0 -37
  367. package/source/util.test.js +0 -15
@@ -0,0 +1,13 @@
1
+ import metadata from '../metadata.min.json'
2
+ import fs from 'fs'
3
+
4
+ const countryCodes = Object.keys(metadata.countries)
5
+
6
+ fs.writeFileSync(
7
+ './types.d.ts',
8
+ fs.readFileSync('./types.d.ts', 'utf-8').replace(
9
+ /export type CountryCode = .*;/,
10
+ `export type CountryCode = ${countryCodes.map(_ => `'${_}'`).join(' | ')};`
11
+ ),
12
+ 'utf-8'
13
+ )
@@ -2,8 +2,8 @@ import Metadata from './metadata'
2
2
  import PhoneNumber from './PhoneNumber'
3
3
  import AsYouTypeState from './AsYouTypeState'
4
4
  import AsYouTypeFormatter, { DIGIT_PLACEHOLDER } from './AsYouTypeFormatter'
5
- import AsYouTypeParser, { extractFormattedDigitsAndPlus, autoCorrectInternationalNumberWithoutPlus } from './AsYouTypeParser'
6
- import { findCountryCode } from './parse_'
5
+ import AsYouTypeParser, { extractFormattedDigitsAndPlus } from './AsYouTypeParser'
6
+ import getCountryByCallingCode from './helpers/getCountryByCallingCode'
7
7
 
8
8
  const USE_NON_GEOGRAPHIC_COUNTRY_CODE = false
9
9
 
@@ -72,6 +72,7 @@ export default class AsYouType {
72
72
  if (formattedNationalNumber === undefined) {
73
73
  // See if another national (significant) number could be re-extracted.
74
74
  if (this.parser.reExtractNationalSignificantNumber(this.state)) {
75
+ this.determineTheCountryIfNeeded()
75
76
  // If it could, then re-try formatting the new national (significant) number.
76
77
  const nationalDigits = this.state.getNationalDigits()
77
78
  if (nationalDigits) {
@@ -196,7 +197,7 @@ export default class AsYouType {
196
197
  // Prepends `+CountryCode ` in case of an international phone number
197
198
  getFullNumber(formattedNationalNumber) {
198
199
  if (this.isInternational()) {
199
- const prefix = (text) => this.formatter.getInternationalPrefixBeforeCountryCallingCode(this.state.IDDPrefix, {
200
+ const prefix = (text) => this.formatter.getInternationalPrefixBeforeCountryCallingCode(this.state, {
200
201
  spacing: text ? true : false
201
202
  }) + text
202
203
  const { callingCode } = this.state
@@ -251,7 +252,7 @@ export default class AsYouType {
251
252
  // entered so far based on the country phone code
252
253
  // and the national phone number.
253
254
  determineTheCountry() {
254
- this.state.setCountry(findCountryCode(
255
+ this.state.setCountry(getCountryByCallingCode(
255
256
  this.isInternational() ? this.state.callingCode : this.defaultCallingCode,
256
257
  this.state.nationalSignificantNumber,
257
258
  this.metadata
@@ -283,25 +284,6 @@ export default class AsYouType {
283
284
  }
284
285
  const countryCode = this.getCountry()
285
286
  const callingCode = this.getCountryCallingCode() || this.defaultCallingCode
286
- // Google's AsYouType formatter supports sort of an "autocorrection" feature
287
- // when it "autocorrects" numbers that have been input for a country
288
- // with that country's calling code.
289
- // Such "autocorrection" feature looks weird, but different people have been requesting it:
290
- // https://github.com/catamphetamine/libphonenumber-js/issues/376
291
- // https://github.com/catamphetamine/libphonenumber-js/issues/375
292
- // https://github.com/catamphetamine/libphonenumber-js/issues/316
293
- if (!this.isInternational() && nationalSignificantNumber === this.state.digits) {
294
- const autoCorrected = autoCorrectInternationalNumberWithoutPlus(
295
- this.state.digits,
296
- countryCode,
297
- callingCode,
298
- this.metadata
299
- )
300
- if (autoCorrected) {
301
- nationalSignificantNumber = autoCorrected.nationalNumber
302
- carrierCode = autoCorrected.carrierCode
303
- }
304
- }
305
287
  const phoneNumber = new PhoneNumber(
306
288
  countryCode || callingCode,
307
289
  nationalSignificantNumber,
@@ -349,6 +331,14 @@ export default class AsYouType {
349
331
  return this.state.nationalSignificantNumber
350
332
  }
351
333
 
334
+ /**
335
+ * Returns the phone number characters entered by the user.
336
+ * @return {string}
337
+ */
338
+ getChars() {
339
+ return (this.state.international ? '+' : '') + this.state.digits
340
+ }
341
+
352
342
  /**
353
343
  * Returns the template for the formatted phone number.
354
344
  * @return {string}
@@ -9,7 +9,7 @@ class AsYouType extends AsYouType_ {
9
9
 
10
10
  const USE_NON_GEOGRAPHIC_COUNTRY_CODE = false
11
11
 
12
- describe('as you type', () => {
12
+ describe('AsYouType', () => {
13
13
  it('should use "national_prefix_formatting_rule"', () => {
14
14
  // With national prefix (full).
15
15
  new AsYouType('RU').input('88005553535').should.equal('8 (800) 555-35-35')
@@ -884,13 +884,13 @@ describe('as you type', () => {
884
884
  it('should return PhoneNumber with autocorrected international numbers without leading +', () => {
885
885
  // https://github.com/catamphetamine/libphonenumber-js/issues/316
886
886
  const formatter = new AsYouType('FR')
887
- formatter.input('33612902554').should.equal('33612902554')
887
+ formatter.input('33612902554').should.equal('33 6 12 90 25 54')
888
888
  formatter.getNumber().country.should.equal('FR')
889
889
  formatter.getNumber().nationalNumber.should.equal('612902554')
890
890
  formatter.getNumber().number.should.equal('+33612902554')
891
891
  // Should also strip national prefix.
892
892
  formatter.reset()
893
- formatter.input('330612902554').should.equal('330612902554')
893
+ formatter.input('330612902554').should.equal('33 06 12 90 25 54')
894
894
  formatter.getNumber().country.should.equal('FR')
895
895
  formatter.getNumber().nationalNumber.should.equal('612902554')
896
896
  formatter.getNumber().number.should.equal('+33612902554')
@@ -1045,6 +1045,16 @@ describe('as you type', () => {
1045
1045
  formatter.input('1').should.equal('14880011 1 21')
1046
1046
  formatter.input('3').should.equal('14880011 1 213')
1047
1047
  })
1048
+
1049
+ it('should return the phone number characters entered by the user', () => {
1050
+ const formatter = new AsYouType('RU')
1051
+ formatter.getChars().should.equal('')
1052
+ formatter.input('+123')
1053
+ formatter.getChars().should.equal('+123')
1054
+ formatter.reset()
1055
+ formatter.input('123')
1056
+ formatter.getChars().should.equal('123')
1057
+ })
1048
1058
  })
1049
1059
 
1050
1060
  function type(something) {
@@ -1,6 +1,6 @@
1
- import checkNumberLength from './checkNumberLength'
2
- import parseDigits from './parseDigits'
3
- import { formatNationalNumberUsingFormat } from './format_'
1
+ import checkNumberLength from './helpers/checkNumberLength'
2
+ import parseDigits from './helpers/parseDigits'
3
+ import formatNationalNumberUsingFormat from './helpers/formatNationalNumberUsingFormat'
4
4
 
5
5
  export default function formatCompleteNumber(state, format, {
6
6
  metadata,
@@ -1,5 +1,3 @@
1
- import parseDigits from './parseDigits'
2
-
3
1
  import {
4
2
  DIGIT_PLACEHOLDER,
5
3
  countOccurences,
@@ -10,20 +8,15 @@ import {
10
8
  populateTemplateWithDigits
11
9
  } from './AsYouTypeFormatter.util'
12
10
 
13
- export {
14
- DIGIT_PLACEHOLDER
15
- } from './AsYouTypeFormatter.util'
16
-
17
- import formatCompleteNumber, { canFormatCompleteNumber } from './AsYouTypeFormatter.complete'
11
+ import formatCompleteNumber, {
12
+ canFormatCompleteNumber
13
+ } from './AsYouTypeFormatter.complete'
18
14
 
19
- import {
20
- FIRST_GROUP_PATTERN,
21
- applyInternationalSeparatorStyle
22
- } from './format_'
23
-
24
- import {
25
- VALID_PUNCTUATION
26
- } from './constants'
15
+ import parseDigits from './helpers/parseDigits'
16
+ export { DIGIT_PLACEHOLDER } from './AsYouTypeFormatter.util'
17
+ import { FIRST_GROUP_PATTERN } from './helpers/formatNationalNumberUsingFormat'
18
+ import { VALID_PUNCTUATION } from './constants'
19
+ import applyInternationalSeparatorStyle from './helpers/applyInternationalSeparatorStyle'
27
20
 
28
21
  // Used in phone number format template creation.
29
22
  // Could be any digit, I guess.
@@ -412,10 +405,14 @@ export default class AsYouTypeFormatter {
412
405
  return ''
413
406
  }
414
407
 
415
- getInternationalPrefixBeforeCountryCallingCode(IDDPrefix, options) {
416
- return IDDPrefix ? (
417
- options && options.spacing === false ? IDDPrefix : IDDPrefix + ' '
418
- ) : '+'
408
+ getInternationalPrefixBeforeCountryCallingCode({ IDDPrefix, missingPlus }, options) {
409
+ if (IDDPrefix) {
410
+ return options && options.spacing === false ? IDDPrefix : IDDPrefix + ' '
411
+ }
412
+ if (missingPlus) {
413
+ return ''
414
+ }
415
+ return '+'
419
416
  }
420
417
 
421
418
  getTemplate(state) {
@@ -427,7 +424,7 @@ export default class AsYouTypeFormatter {
427
424
  // so trim all non-populated digits.
428
425
  let index = -1
429
426
  let i = 0
430
- const internationalPrefix = state.international ? this.getInternationalPrefixBeforeCountryCallingCode(state.IDDPrefix, { spacing: false }) : ''
427
+ const internationalPrefix = state.international ? this.getInternationalPrefixBeforeCountryCallingCode(state, { spacing: false }) : ''
431
428
  while (i < internationalPrefix.length + state.getDigitsWithoutInternationalPrefix().length) {
432
429
  index = this.template.indexOf(DIGIT_PLACEHOLDER, index + 1)
433
430
  i++
@@ -435,11 +432,7 @@ export default class AsYouTypeFormatter {
435
432
  return cutAndStripNonPairedParens(this.template, index + 1)
436
433
  }
437
434
 
438
- setNationalNumberTemplate(template, {
439
- international,
440
- IDDPrefix,
441
- callingCode
442
- }) {
435
+ setNationalNumberTemplate(template, state) {
443
436
  this.nationalNumberTemplate = template
444
437
  this.populatedNationalNumberTemplate = template
445
438
  // With a new formatting template, the matched position
@@ -450,10 +443,10 @@ export default class AsYouTypeFormatter {
450
443
  // if the phone number being input is international:
451
444
  // 'x' for the '+' sign, 'x'es for the country phone code,
452
445
  // a spacebar and then the template for the formatted national number.
453
- if (international) {
446
+ if (state.international) {
454
447
  this.template =
455
- this.getInternationalPrefixBeforeCountryCallingCode(IDDPrefix).replace(/[\d\+]/g, DIGIT_PLACEHOLDER) +
456
- repeat(DIGIT_PLACEHOLDER, callingCode.length) +
448
+ this.getInternationalPrefixBeforeCountryCallingCode(state).replace(/[\d\+]/g, DIGIT_PLACEHOLDER) +
449
+ repeat(DIGIT_PLACEHOLDER, state.callingCode.length) +
457
450
  ' ' +
458
451
  template
459
452
  } else {
@@ -1,13 +1,8 @@
1
- import parseDigits from './parseDigits'
2
-
3
- import {
4
- extractNationalNumber,
5
- extractNationalNumberFromPossiblyIncompleteNumber,
6
- extractCountryCallingCode,
7
- extractCountryCallingCodeFromInternationalNumberWithoutPlusSign
8
- } from './parse_'
9
-
10
- import { stripIDDPrefix } from './IDD'
1
+ import extractCountryCallingCode from './helpers/extractCountryCallingCode'
2
+ import extractCountryCallingCodeFromInternationalNumberWithoutPlusSign from './helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign'
3
+ import extractNationalNumberFromPossiblyIncompleteNumber from './helpers/extractNationalNumberFromPossiblyIncompleteNumber'
4
+ import stripIddPrefix from './helpers/stripIddPrefix'
5
+ import parseDigits from './helpers/parseDigits'
11
6
 
12
7
  import {
13
8
  VALID_DIGITS,
@@ -113,7 +108,7 @@ export default class AsYouTypeParser {
113
108
  // An IDD prefix is extracted here, and then every time when
114
109
  // there's a new digit and the number couldn't be formatted.
115
110
  if (hasReceivedThreeLeadingDigits) {
116
- this.extractIDDPrefix(state)
111
+ this.extractIddPrefix(state)
117
112
  }
118
113
 
119
114
  if (this.isWaitingForCountryCallingCode(state)) {
@@ -342,12 +337,24 @@ export default class AsYouTypeParser {
342
337
  // but it's not a big deal, and in most cases there
343
338
  // will be a suitable `format` when there're 3 leading digits.
344
339
  //
345
- if (this.extractIDDPrefix(state)) {
340
+ if (this.extractIddPrefix(state)) {
341
+ this.extractCallingCodeAndNationalSignificantNumber(state)
342
+ return true
343
+ }
344
+ // Google's AsYouType formatter supports sort of an "autocorrection" feature
345
+ // when it "autocorrects" numbers that have been input for a country
346
+ // with that country's calling code.
347
+ // Such "autocorrection" feature looks weird, but different people have been requesting it:
348
+ // https://github.com/catamphetamine/libphonenumber-js/issues/376
349
+ // https://github.com/catamphetamine/libphonenumber-js/issues/375
350
+ // https://github.com/catamphetamine/libphonenumber-js/issues/316
351
+ if (this.fixMissingPlus(state)) {
352
+ this.extractCallingCodeAndNationalSignificantNumber(state)
346
353
  return true
347
354
  }
348
355
  }
349
356
 
350
- extractIDDPrefix(state) {
357
+ extractIddPrefix(state) {
351
358
  // An IDD prefix can't be present in a number written with a `+`.
352
359
  // Also, don't re-extract an IDD prefix if has already been extracted.
353
360
  const {
@@ -363,7 +370,7 @@ export default class AsYouTypeParser {
363
370
  // dialing format instead of using the leading `+`.
364
371
  // https://github.com/catamphetamine/libphonenumber-js/issues/185
365
372
  // Detect such numbers.
366
- const numberWithoutIDD = stripIDDPrefix(
373
+ const numberWithoutIDD = stripIddPrefix(
367
374
  digits,
368
375
  this.defaultCountry,
369
376
  this.defaultCallingCode,
@@ -375,16 +382,53 @@ export default class AsYouTypeParser {
375
382
  state.update({
376
383
  IDDPrefix: digits.slice(0, digits.length - numberWithoutIDD.length)
377
384
  })
378
- state.startInternationalNumber()
379
- // If a national (significant) number has been extracted before, reset it.
380
- if (nationalSignificantNumber) {
381
- state.resetNationalSignificantNumber()
382
- this.onNationalSignificantNumberChange()
383
- this.hasExtractedNationalSignificantNumber = undefined
384
- }
385
+ this.startInternationalNumber(state)
385
386
  return true
386
387
  }
387
388
  }
389
+
390
+ fixMissingPlus(state) {
391
+ if (!state.international) {
392
+ const {
393
+ countryCallingCode: newCallingCode,
394
+ number
395
+ } = extractCountryCallingCodeFromInternationalNumberWithoutPlusSign(
396
+ state.digits,
397
+ this.defaultCountry,
398
+ this.defaultCallingCode,
399
+ this.metadata.metadata
400
+ )
401
+ if (newCallingCode) {
402
+ state.update({
403
+ missingPlus: true
404
+ })
405
+ this.startInternationalNumber(state)
406
+ return true
407
+ }
408
+ }
409
+ }
410
+
411
+ startInternationalNumber(state) {
412
+ state.startInternationalNumber()
413
+ // If a national (significant) number has been extracted before, reset it.
414
+ if (state.nationalSignificantNumber) {
415
+ state.resetNationalSignificantNumber()
416
+ this.onNationalSignificantNumberChange()
417
+ this.hasExtractedNationalSignificantNumber = undefined
418
+ }
419
+ }
420
+
421
+ extractCallingCodeAndNationalSignificantNumber(state) {
422
+ if (this.extractCountryCallingCode(state)) {
423
+ // `this.extractCallingCode()` is currently called when the number
424
+ // couldn't be formatted during the standard procedure.
425
+ // Normally, the national prefix would be re-extracted
426
+ // for an international number if such number couldn't be formatted,
427
+ // but since it's already not able to be formatted,
428
+ // there won't be yet another retry, so also extract national prefix here.
429
+ this.extractNationalSignificantNumber(state.getNationalDigits(), state.update)
430
+ }
431
+ }
388
432
  }
389
433
 
390
434
  /**
@@ -444,31 +488,4 @@ export function extractFormattedDigitsAndPlus(text) {
444
488
  formattedDigits = ''
445
489
  }
446
490
  return [formattedDigits, hasPlus]
447
- }
448
-
449
- export function autoCorrectInternationalNumberWithoutPlus(
450
- digits,
451
- countryCode,
452
- callingCode,
453
- metadata
454
- ) {
455
- // Google's AsYouType formatter supports sort of an "autocorrection" feature
456
- // when it "autocorrects" numbers that have been input for a country
457
- // with that country's calling code.
458
- // Such "autocorrection" feature looks weird, but different people have been requesting it:
459
- // https://github.com/catamphetamine/libphonenumber-js/issues/376
460
- // https://github.com/catamphetamine/libphonenumber-js/issues/375
461
- // https://github.com/catamphetamine/libphonenumber-js/issues/316
462
- const {
463
- countryCallingCode: newCallingCode,
464
- number
465
- } = extractCountryCallingCodeFromInternationalNumberWithoutPlusSign(
466
- digits,
467
- countryCode,
468
- callingCode,
469
- metadata.metadata
470
- )
471
- if (newCallingCode) {
472
- return extractNationalNumber(number, metadata)
473
- }
474
491
  }
@@ -7,6 +7,7 @@ export default class AsYouTypeState {
7
7
  reset(defaultCountry, defaultCallingCode) {
8
8
  this.international = false
9
9
  this.IDDPrefix = undefined
10
+ this.missingPlus = undefined
10
11
  this.callingCode = undefined
11
12
  this.digits = ''
12
13
  this.resetNationalSignificantNumber()
@@ -2,7 +2,7 @@ import Metadata from './metadata'
2
2
  import isPossibleNumber from './isPossibleNumber_'
3
3
  import isValidNumber from './validate_'
4
4
  import isValidNumberForRegion from './isValidNumberForRegion_'
5
- import getNumberType from './getNumberType_'
5
+ import getNumberType from './helpers/getNumberType'
6
6
  import formatNumber from './format_'
7
7
 
8
8
  const USE_NON_GEOGRAPHIC_COUNTRY_CODE = false
@@ -12,7 +12,7 @@ import {
12
12
  VALID_PUNCTUATION
13
13
  } from './constants'
14
14
 
15
- import { EXTN_PATTERNS_FOR_MATCHING } from './extension'
15
+ import createExtensionPattern from './helpers/extension/createExtensionPattern'
16
16
 
17
17
  import RegExpCache from './findNumbers/RegExpCache'
18
18
 
@@ -38,6 +38,8 @@ import { isSupportedCountry } from './metadata'
38
38
 
39
39
  import parseNumber from './parse_'
40
40
 
41
+ const EXTN_PATTERNS_FOR_MATCHING = createExtensionPattern('matching')
42
+
41
43
  /**
42
44
  * Patterns used to extract phone numbers from a larger phone-number-like pattern. These are
43
45
  * ordered according to specificity. For example, white-space is last since that is frequently
@@ -209,21 +211,18 @@ export default class PhoneNumberMatcher
209
211
  * @param index the search index to start searching at
210
212
  * @return the phone number match found, null if none can be found
211
213
  */
212
- find() // (index)
213
- {
214
+ find() {
214
215
  // // Reset the regular expression.
215
216
  // this.PATTERN.lastIndex = index
216
217
 
217
218
  let matches
218
- while ((this.maxTries > 0) && (matches = this.PATTERN.exec(this.text)) !== null)
219
- {
219
+ while ((this.maxTries > 0) && (matches = this.PATTERN.exec(this.text)) !== null) {
220
220
  let candidate = matches[0]
221
221
  const offset = matches.index
222
222
 
223
223
  candidate = parsePreCandidate(candidate)
224
224
 
225
- if (isValidPreCandidate(candidate, offset, this.text))
226
- {
225
+ if (isValidPreCandidate(candidate, offset, this.text)) {
227
226
  const match =
228
227
  // Try to come up with a valid match given the entire candidate.
229
228
  this.parseAndVerify(candidate, offset, this.text)
@@ -256,28 +255,24 @@ export default class PhoneNumberMatcher
256
255
  }
257
256
 
258
257
  /**
259
- * Attempts to extract a match from `candidate`
260
- * if the whole candidate does not qualify as a match.
258
+ * Attempts to extract a match from `substring`
259
+ * if the substring itself does not qualify as a match.
261
260
  */
262
- extractInnerMatch(candidate, offset, text)
263
- {
264
- for (const innerMatchPattern of INNER_MATCHES)
265
- {
261
+ extractInnerMatch(substring, offset, text) {
262
+ for (const innerMatchPattern of INNER_MATCHES) {
266
263
  let isFirstMatch = true
267
- let matches
268
- const possibleInnerMatch = new RegExp(innerMatchPattern, 'g')
269
- while ((matches = possibleInnerMatch.exec(candidate)) !== null && this.maxTries > 0)
270
- {
271
- if (isFirstMatch)
272
- {
264
+ let candidateMatch
265
+ const innerMatchRegExp = new RegExp(innerMatchPattern, 'g')
266
+ while (this.maxTries > 0 && (candidateMatch = innerMatchRegExp.exec(substring)) !== null) {
267
+ if (isFirstMatch) {
273
268
  // We should handle any group before this one too.
274
- const group = trimAfterFirstMatch
275
- (
269
+ const candidate = trimAfterFirstMatch(
276
270
  UNWANTED_END_CHAR_PATTERN,
277
- candidate.slice(0, matches.index)
271
+ substring.slice(0, candidateMatch.index)
278
272
  )
279
273
 
280
- const match = this.parseAndVerify(group, offset, text)
274
+ const match = this.parseAndVerify(candidate, offset, text)
275
+
281
276
  if (match) {
282
277
  return match
283
278
  }
@@ -286,16 +281,16 @@ export default class PhoneNumberMatcher
286
281
  isFirstMatch = false
287
282
  }
288
283
 
289
- const group = trimAfterFirstMatch
290
- (
291
- UNWANTED_END_CHAR_PATTERN,
292
- matches[1]
293
- )
284
+ const candidate = trimAfterFirstMatch(UNWANTED_END_CHAR_PATTERN, candidateMatch[1])
294
285
 
295
286
  // Java code does `groupMatcher.start(1)` here,
296
- // but there's no way in javascript to get a group match start index,
297
- // therefore using the overall match start index `matches.index`.
298
- const match = this.parseAndVerify(group, offset + matches.index, text)
287
+ // but there's no way in javascript to get a `candidate` start index,
288
+ // therefore resort to using this kind of an approximation.
289
+ // (`groupMatcher` is called `candidateInSubstringMatch` in this javascript port)
290
+ // https://stackoverflow.com/questions/15934353/get-index-of-each-capture-in-a-javascript-regex
291
+ const candidateIndexGuess = substring.indexOf(candidate, candidateMatch.index)
292
+
293
+ const match = this.parseAndVerify(candidate, offset + candidateIndexGuess, text)
299
294
  if (match) {
300
295
  return match
301
296
  }
@@ -314,8 +309,7 @@ export default class PhoneNumberMatcher
314
309
  * @param offset the offset of {@code candidate} within {@link #text}
315
310
  * @return the parsed and validated phone number match, or null
316
311
  */
317
- parseAndVerify(candidate, offset, text)
318
- {
312
+ parseAndVerify(candidate, offset, text) {
319
313
  if (!isValidCandidate(candidate, offset, text, this.options.leniency)) {
320
314
  return
321
315
  }
@@ -333,8 +327,7 @@ export default class PhoneNumberMatcher
333
327
  return
334
328
  }
335
329
 
336
- if (this.leniency(number, candidate, this.metadata, this.regExpCache))
337
- {
330
+ if (this.leniency(number, candidate, this.metadata, this.regExpCache)) {
338
331
  // // We used parseAndKeepRawInput to create this number,
339
332
  // // but for now we don't return the extra values parsed.
340
333
  // // TODO: stop clearing all values here and switch all users over
@@ -1,5 +1,5 @@
1
1
  import isValidNumber from '../validate_'
2
- import parseDigits from '../parseDigits'
2
+ import parseDigits from '../helpers/parseDigits'
3
3
 
4
4
  import {
5
5
  startsWith,
@@ -1,5 +1,5 @@
1
1
  import findNumbers from './findNumbers'
2
- import metadata from '../metadata.min.json'
2
+ import metadata from '../metadata.full.json'
3
3
 
4
4
  describe('findNumbers', () => {
5
5
  it('should find numbers', () => {
@@ -188,4 +188,17 @@ describe('findNumbers', () => {
188
188
  // Shouldn't parse by default.
189
189
  findNumbers('The UUID is CA801c26f98cd16e231354125ad046e40b.', 'FR', metadata).should.deep.equal([])
190
190
  })
191
+
192
+ // https://gitlab.com/catamphetamine/libphonenumber-js/-/merge_requests/4
193
+ it('should return correct `startsAt` and `endsAt` when matching "inner" candidates in a could-be-a-candidate substring', () => {
194
+ findNumbers('39945926 77200596 16533084', 'ID', metadata)
195
+ .should
196
+ .deep
197
+ .equal([{
198
+ country: 'ID',
199
+ phone: '77200596',
200
+ startsAt: 9,
201
+ endsAt: 17
202
+ }])
203
+ })
191
204
  })
@@ -8,14 +8,31 @@ import {
8
8
  WHITESPACE
9
9
  } from './constants'
10
10
 
11
- import { EXTN_PATTERNS_FOR_PARSING } from './extension'
12
11
  import parse from './parse_'
13
- import { VALID_PHONE_NUMBER_WITH_EXTENSION } from './isViablePhoneNumber'
12
+ import { VALID_PHONE_NUMBER_WITH_EXTENSION } from './helpers/isViablePhoneNumber'
13
+ import createExtensionPattern from './helpers/extension/createExtensionPattern'
14
14
 
15
15
  import parsePreCandidate from './findNumbers/parsePreCandidate'
16
16
  import isValidPreCandidate from './findNumbers/isValidPreCandidate'
17
17
  import isValidCandidate from './findNumbers/isValidCandidate'
18
18
 
19
+ /**
20
+ * Regexp of all possible ways to write extensions, for use when parsing. This
21
+ * will be run as a case-insensitive regexp match. Wide character versions are
22
+ * also provided after each ASCII version. There are three regular expressions
23
+ * here. The first covers RFC 3966 format, where the extension is added using
24
+ * ';ext='. The second more generic one starts with optional white space and
25
+ * ends with an optional full stop (.), followed by zero or more spaces/tabs
26
+ * /commas and then the numbers themselves. The other one covers the special
27
+ * case of American numbers where the extension is written with a hash at the
28
+ * end, such as '- 503#'. Note that the only capturing groups should be around
29
+ * the digits that you want to capture as part of the extension, or else parsing
30
+ * will fail! We allow two options for representing the accented o - the
31
+ * character itself, and one in the unicode decomposed form with the combining
32
+ * acute accent.
33
+ */
34
+ export const EXTN_PATTERNS_FOR_PARSING = createExtensionPattern('parsing')
35
+
19
36
  const WHITESPACE_IN_THE_BEGINNING_PATTERN = new RegExp('^[' + WHITESPACE + ']+')
20
37
  const PUNCTUATION_IN_THE_END_PATTERN = new RegExp('[' + VALID_PUNCTUATION + ']+$')
21
38
 
@@ -1,5 +1,4 @@
1
1
  import metadata from '../metadata.min.json'
2
- import { applyInternationalSeparatorStyle } from './format_'
3
2
  import _formatNumber from './format'
4
3
 
5
4
  function formatNumber(...parameters) {
@@ -116,11 +115,6 @@ describe('format', () => {
116
115
  expect(() => formatNumber({ phone: '123', country: 'USA' }, 'NATIONAL')).to.throw('Unknown country')
117
116
  })
118
117
 
119
- it('should change Google\'s international format style', () => {
120
- applyInternationalSeparatorStyle('(xxx) xxx-xx-xx').should.equal('xxx xxx xx xx')
121
- applyInternationalSeparatorStyle('(xxx)xxx').should.equal('xxx xxx')
122
- })
123
-
124
118
  it('should format phone number extensions', () => {
125
119
  // National
126
120
  formatNumber({
@@ -6,8 +6,8 @@
6
6
 
7
7
  import Metadata from './metadata'
8
8
  import format from './format_'
9
- import getNumberType from './getNumberType_'
10
- import checkNumberLength from './checkNumberLength'
9
+ import getNumberType from './helpers/getNumberType'
10
+ import checkNumberLength from './helpers/checkNumberLength'
11
11
  import getCountryCallingCode from './getCountryCallingCode'
12
12
 
13
13
  const REGION_CODE_FOR_NON_GEO_ENTITY = '001'