libphonenumber-js 1.12.43 → 1.13.0

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 (310) hide show
  1. package/CHANGELOG.md +131 -104
  2. package/README.md +36 -6
  3. package/core/es6/index.d.cts +2 -0
  4. package/core/es6/index.d.ts +2 -0
  5. package/core/es6/index.js +39 -0
  6. package/core/es6/package.json +12 -0
  7. package/core/index.cjs +5 -0
  8. package/core/index.cjs.js +5 -0
  9. package/core/index.d.cts +3 -1
  10. package/core/index.d.ts +3 -1
  11. package/core/index.js +5 -0
  12. package/custom.d.ts +6 -4
  13. package/custom.js +5 -5
  14. package/es6-modern/AsYouType.js +445 -0
  15. package/es6-modern/AsYouType.js.map +1 -0
  16. package/es6-modern/AsYouType.test.js.map +1 -0
  17. package/es6-modern/AsYouTypeFormatter.PatternMatcher.js +195 -0
  18. package/es6-modern/AsYouTypeFormatter.PatternMatcher.js.map +1 -0
  19. package/es6-modern/AsYouTypeFormatter.PatternMatcher.test.js.map +1 -0
  20. package/es6-modern/AsYouTypeFormatter.PatternParser.js +184 -0
  21. package/es6-modern/AsYouTypeFormatter.PatternParser.js.map +1 -0
  22. package/es6-modern/AsYouTypeFormatter.PatternParser.test.js.map +1 -0
  23. package/es6-modern/AsYouTypeFormatter.complete.js +120 -0
  24. package/es6-modern/AsYouTypeFormatter.complete.js.map +1 -0
  25. package/es6-modern/AsYouTypeFormatter.js +659 -0
  26. package/es6-modern/AsYouTypeFormatter.js.map +1 -0
  27. package/es6-modern/AsYouTypeFormatter.util.js +96 -0
  28. package/es6-modern/AsYouTypeFormatter.util.js.map +1 -0
  29. package/es6-modern/AsYouTypeFormatter.util.test.js.map +1 -0
  30. package/es6-modern/AsYouTypeParser.js +435 -0
  31. package/es6-modern/AsYouTypeParser.js.map +1 -0
  32. package/es6-modern/AsYouTypeState.js +104 -0
  33. package/es6-modern/AsYouTypeState.js.map +1 -0
  34. package/es6-modern/ParseError.js +15 -0
  35. package/es6-modern/ParseError.js.map +1 -0
  36. package/es6-modern/PhoneNumber.js +166 -0
  37. package/es6-modern/PhoneNumber.js.map +1 -0
  38. package/es6-modern/PhoneNumber.test.js.map +1 -0
  39. package/es6-modern/PhoneNumberMatcher.js +330 -0
  40. package/es6-modern/PhoneNumberMatcher.js.map +1 -0
  41. package/es6-modern/PhoneNumberMatcher.test.js.map +1 -0
  42. package/es6-modern/constants.js +31 -0
  43. package/es6-modern/constants.js.map +1 -0
  44. package/es6-modern/findNumbers/LRUCache.js +98 -0
  45. package/es6-modern/findNumbers/LRUCache.js.map +1 -0
  46. package/es6-modern/findNumbers/Leniency.js +311 -0
  47. package/es6-modern/findNumbers/Leniency.js.map +1 -0
  48. package/es6-modern/findNumbers/RegExpCache.js +20 -0
  49. package/es6-modern/findNumbers/RegExpCache.js.map +1 -0
  50. package/es6-modern/findNumbers/isValidCandidate.js +66 -0
  51. package/es6-modern/findNumbers/isValidCandidate.js.map +1 -0
  52. package/es6-modern/findNumbers/isValidPreCandidate.js +26 -0
  53. package/es6-modern/findNumbers/isValidPreCandidate.js.map +1 -0
  54. package/es6-modern/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js +63 -0
  55. package/es6-modern/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js.map +1 -0
  56. package/es6-modern/findNumbers/parsePreCandidate.js +18 -0
  57. package/es6-modern/findNumbers/parsePreCandidate.js.map +1 -0
  58. package/es6-modern/findNumbers/utf-8.js +63 -0
  59. package/es6-modern/findNumbers/utf-8.js.map +1 -0
  60. package/es6-modern/findNumbers/util.js +26 -0
  61. package/es6-modern/findNumbers/util.js.map +1 -0
  62. package/es6-modern/findNumbers/util.test.js.map +1 -0
  63. package/es6-modern/findPhoneNumbersInText.js +19 -0
  64. package/es6-modern/findPhoneNumbersInText.js.map +1 -0
  65. package/es6-modern/findPhoneNumbersInText.test.js.map +1 -0
  66. package/es6-modern/format.js +204 -0
  67. package/es6-modern/format.js.map +1 -0
  68. package/es6-modern/format.test.js.map +1 -0
  69. package/es6-modern/formatIncompletePhoneNumber.js +18 -0
  70. package/es6-modern/formatIncompletePhoneNumber.js.map +1 -0
  71. package/es6-modern/formatIncompletePhoneNumber.test.js.map +1 -0
  72. package/es6-modern/formatPhoneNumberForMobileDialing.js +190 -0
  73. package/es6-modern/formatPhoneNumberForMobileDialing.js.map +1 -0
  74. package/es6-modern/getCountries.js +5 -0
  75. package/es6-modern/getCountries.js.map +1 -0
  76. package/es6-modern/getCountries.test.js.map +1 -0
  77. package/es6-modern/getCountryCallingCode.js +3 -0
  78. package/es6-modern/getCountryCallingCode.js.map +1 -0
  79. package/es6-modern/getCountryCallingCode.test.js.map +1 -0
  80. package/es6-modern/getExampleNumber.js +7 -0
  81. package/es6-modern/getExampleNumber.js.map +1 -0
  82. package/es6-modern/getExampleNumber.test.js.map +1 -0
  83. package/es6-modern/helpers/RFC3966.js +63 -0
  84. package/es6-modern/helpers/RFC3966.js.map +1 -0
  85. package/es6-modern/helpers/RFC3966.test.js.map +1 -0
  86. package/es6-modern/helpers/applyInternationalSeparatorStyle.js +36 -0
  87. package/es6-modern/helpers/applyInternationalSeparatorStyle.js.map +1 -0
  88. package/es6-modern/helpers/applyInternationalSeparatorStyle.test.js.map +1 -0
  89. package/es6-modern/helpers/checkNumberLength.js +112 -0
  90. package/es6-modern/helpers/checkNumberLength.js.map +1 -0
  91. package/es6-modern/helpers/checkNumberLength.test.js.map +1 -0
  92. package/es6-modern/helpers/extension/createExtensionPattern.js +93 -0
  93. package/es6-modern/helpers/extension/createExtensionPattern.js.map +1 -0
  94. package/es6-modern/helpers/extension/extractExtension.js +30 -0
  95. package/es6-modern/helpers/extension/extractExtension.js.map +1 -0
  96. package/es6-modern/helpers/extractCountryCallingCode.js +142 -0
  97. package/es6-modern/helpers/extractCountryCallingCode.js.map +1 -0
  98. package/es6-modern/helpers/extractCountryCallingCode.test.js.map +1 -0
  99. package/es6-modern/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +49 -0
  100. package/es6-modern/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -0
  101. package/es6-modern/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js +66 -0
  102. package/es6-modern/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js.map +1 -0
  103. package/es6-modern/helpers/extractNationalNumber.js +117 -0
  104. package/es6-modern/helpers/extractNationalNumber.js.map +1 -0
  105. package/es6-modern/helpers/extractNationalNumber.test.js.map +1 -0
  106. package/es6-modern/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +102 -0
  107. package/es6-modern/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -0
  108. package/es6-modern/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js.map +1 -0
  109. package/es6-modern/helpers/extractPhoneContext.js +82 -0
  110. package/es6-modern/helpers/extractPhoneContext.js.map +1 -0
  111. package/es6-modern/helpers/extractPhoneContext.test.js.map +1 -0
  112. package/es6-modern/helpers/formatNationalNumberUsingFormat.js +34 -0
  113. package/es6-modern/helpers/formatNationalNumberUsingFormat.js.map +1 -0
  114. package/es6-modern/helpers/getCountryByCallingCode.js +30 -0
  115. package/es6-modern/helpers/getCountryByCallingCode.js.map +1 -0
  116. package/es6-modern/helpers/getCountryByNationalNumber.js +76 -0
  117. package/es6-modern/helpers/getCountryByNationalNumber.js.map +1 -0
  118. package/es6-modern/helpers/getIddPrefix.js +26 -0
  119. package/es6-modern/helpers/getIddPrefix.js.map +1 -0
  120. package/es6-modern/helpers/getNumberType.js +81 -0
  121. package/es6-modern/helpers/getNumberType.js.map +1 -0
  122. package/es6-modern/helpers/getNumberType.test.js.map +1 -0
  123. package/es6-modern/helpers/getPossibleCountriesForNumber.js +28 -0
  124. package/es6-modern/helpers/getPossibleCountriesForNumber.js.map +1 -0
  125. package/es6-modern/helpers/isObject.js +5 -0
  126. package/es6-modern/helpers/isObject.js.map +1 -0
  127. package/es6-modern/helpers/isViablePhoneNumber.js +77 -0
  128. package/es6-modern/helpers/isViablePhoneNumber.js.map +1 -0
  129. package/es6-modern/helpers/matchesEntirely.js +12 -0
  130. package/es6-modern/helpers/matchesEntirely.js.map +1 -0
  131. package/es6-modern/helpers/matchesEntirely.test.js.map +1 -0
  132. package/es6-modern/helpers/mergeArrays.js +23 -0
  133. package/es6-modern/helpers/mergeArrays.js.map +1 -0
  134. package/es6-modern/helpers/mergeArrays.test.js.map +1 -0
  135. package/es6-modern/helpers/parseDigits.js +111 -0
  136. package/es6-modern/helpers/parseDigits.js.map +1 -0
  137. package/es6-modern/helpers/parseDigits.test.js.map +1 -0
  138. package/es6-modern/helpers/stripIddPrefix.js +29 -0
  139. package/es6-modern/helpers/stripIddPrefix.js.map +1 -0
  140. package/es6-modern/helpers/stripIddPrefix.test.js.map +1 -0
  141. package/es6-modern/isPossible.js +77 -0
  142. package/es6-modern/isPossible.js.map +1 -0
  143. package/es6-modern/isPossible.test.js.map +1 -0
  144. package/es6-modern/isPossiblePhoneNumber.js +16 -0
  145. package/es6-modern/isPossiblePhoneNumber.js.map +1 -0
  146. package/es6-modern/isPossiblePhoneNumber.test.js.map +1 -0
  147. package/es6-modern/isValid.js +57 -0
  148. package/es6-modern/isValid.js.map +1 -0
  149. package/es6-modern/isValid.test.js.map +1 -0
  150. package/es6-modern/isValidPhoneNumber.js +16 -0
  151. package/es6-modern/isValidPhoneNumber.js.map +1 -0
  152. package/es6-modern/isValidPhoneNumber.test.js.map +1 -0
  153. package/es6-modern/legacy/PhoneNumberSearch.js +109 -0
  154. package/es6-modern/legacy/PhoneNumberSearch.js.map +1 -0
  155. package/es6-modern/legacy/findNumbers.js +16 -0
  156. package/es6-modern/legacy/findNumbers.js.map +1 -0
  157. package/es6-modern/legacy/findNumbers.test.js.map +1 -0
  158. package/es6-modern/legacy/findPhoneNumbers.js +26 -0
  159. package/es6-modern/legacy/findPhoneNumbers.js.map +1 -0
  160. package/es6-modern/legacy/findPhoneNumbers.test.js.map +1 -0
  161. package/es6-modern/legacy/findPhoneNumbersInitialImplementation.js +79 -0
  162. package/es6-modern/legacy/findPhoneNumbersInitialImplementation.js.map +1 -0
  163. package/es6-modern/legacy/format.js +97 -0
  164. package/es6-modern/legacy/format.js.map +1 -0
  165. package/es6-modern/legacy/format.test.js.map +1 -0
  166. package/es6-modern/legacy/getNumberType.js +104 -0
  167. package/es6-modern/legacy/getNumberType.js.map +1 -0
  168. package/es6-modern/legacy/getNumberType.test.js.map +1 -0
  169. package/es6-modern/legacy/isPossibleNumber.js +30 -0
  170. package/es6-modern/legacy/isPossibleNumber.js.map +1 -0
  171. package/es6-modern/legacy/isPossibleNumber.test.js.map +1 -0
  172. package/es6-modern/legacy/isValidNumber.js +17 -0
  173. package/es6-modern/legacy/isValidNumber.js.map +1 -0
  174. package/es6-modern/legacy/isValidNumber.test.js.map +1 -0
  175. package/es6-modern/legacy/isValidNumberForRegion.js +65 -0
  176. package/es6-modern/legacy/isValidNumberForRegion.js.map +1 -0
  177. package/es6-modern/legacy/isValidNumberForRegion.test.js.map +1 -0
  178. package/es6-modern/legacy/isValidNumberForRegion_.js +14 -0
  179. package/es6-modern/legacy/isValidNumberForRegion_.js.map +1 -0
  180. package/es6-modern/legacy/parse.js +11 -0
  181. package/es6-modern/legacy/parse.js.map +1 -0
  182. package/es6-modern/legacy/parse.test.js.map +1 -0
  183. package/es6-modern/legacy/searchNumbers.js +32 -0
  184. package/es6-modern/legacy/searchNumbers.js.map +1 -0
  185. package/es6-modern/legacy/searchNumbers.test.js.map +1 -0
  186. package/es6-modern/metadata.js +494 -0
  187. package/es6-modern/metadata.js.map +1 -0
  188. package/es6-modern/metadata.test.js.map +1 -0
  189. package/es6-modern/normalizeArguments.js +52 -0
  190. package/es6-modern/normalizeArguments.js.map +1 -0
  191. package/es6-modern/parse.js +341 -0
  192. package/es6-modern/parse.js.map +1 -0
  193. package/es6-modern/parse.test.js.map +1 -0
  194. package/es6-modern/parseIncompletePhoneNumber.js +70 -0
  195. package/es6-modern/parseIncompletePhoneNumber.js.map +1 -0
  196. package/es6-modern/parseIncompletePhoneNumber.test.js.map +1 -0
  197. package/es6-modern/parsePhoneNumber.js +11 -0
  198. package/es6-modern/parsePhoneNumber.js.map +1 -0
  199. package/es6-modern/parsePhoneNumber.test.js.map +1 -0
  200. package/es6-modern/parsePhoneNumberWithError.js +11 -0
  201. package/es6-modern/parsePhoneNumberWithError.js.map +1 -0
  202. package/es6-modern/parsePhoneNumberWithError.test.js.map +1 -0
  203. package/es6-modern/parsePhoneNumberWithError_.js +8 -0
  204. package/es6-modern/parsePhoneNumberWithError_.js.map +1 -0
  205. package/es6-modern/parsePhoneNumber_.js +24 -0
  206. package/es6-modern/parsePhoneNumber_.js.map +1 -0
  207. package/es6-modern/searchPhoneNumbersInText.js +31 -0
  208. package/es6-modern/searchPhoneNumbersInText.js.map +1 -0
  209. package/es6-modern/searchPhoneNumbersInText.test.js.map +1 -0
  210. package/es6-modern/tools/semver-compare.js +27 -0
  211. package/es6-modern/tools/semver-compare.js.map +1 -0
  212. package/es6-modern/tools/semver-compare.test.js.map +1 -0
  213. package/es6-modern/validatePhoneNumberLength.js +35 -0
  214. package/es6-modern/validatePhoneNumberLength.js.map +1 -0
  215. package/es6-modern/validatePhoneNumberLength.test.js.map +1 -0
  216. package/index.cjs +4 -0
  217. package/index.cjs.js +4 -0
  218. package/index.d.cts +5 -3
  219. package/index.d.ts +5 -3
  220. package/index.js +5 -0
  221. package/max/es6/exports/AsYouType.js +11 -0
  222. package/max/es6/exports/Metadata.js +11 -0
  223. package/max/es6/exports/PhoneNumber.js +11 -0
  224. package/max/es6/exports/PhoneNumberMatcher.js +11 -0
  225. package/max/es6/exports/findNumbers.js +6 -0
  226. package/max/es6/exports/findPhoneNumbersInText.js +6 -0
  227. package/max/es6/exports/formatIncompletePhoneNumber.js +6 -0
  228. package/max/es6/exports/getCountries.js +6 -0
  229. package/max/es6/exports/getCountryCallingCode.js +6 -0
  230. package/max/es6/exports/getExampleNumber.js +6 -0
  231. package/max/es6/exports/getExtPrefix.js +6 -0
  232. package/max/es6/exports/isPossiblePhoneNumber.js +6 -0
  233. package/max/es6/exports/isSupportedCountry.js +6 -0
  234. package/max/es6/exports/isValidPhoneNumber.js +6 -0
  235. package/max/es6/exports/parsePhoneNumber.js +7 -0
  236. package/max/es6/exports/parsePhoneNumberWithError.js +7 -0
  237. package/max/es6/exports/searchNumbers.js +6 -0
  238. package/max/es6/exports/searchPhoneNumbersInText.js +6 -0
  239. package/max/es6/exports/validatePhoneNumberLength.js +6 -0
  240. package/max/es6/exports/withMetadataArgument.js +13 -0
  241. package/max/es6/index.d.cts +2 -0
  242. package/max/es6/index.d.ts +2 -0
  243. package/max/es6/index.js +44 -0
  244. package/max/es6/package.json +12 -0
  245. package/max/index.cjs +5 -0
  246. package/max/index.cjs.js +5 -0
  247. package/max/index.d.cts +3 -1
  248. package/max/index.d.ts +3 -1
  249. package/max/index.js +4 -0
  250. package/min/es6/exports/AsYouType.js +11 -0
  251. package/min/es6/exports/Metadata.js +11 -0
  252. package/min/es6/exports/PhoneNumber.js +11 -0
  253. package/min/es6/exports/PhoneNumberMatcher.js +11 -0
  254. package/min/es6/exports/findNumbers.js +6 -0
  255. package/min/es6/exports/findPhoneNumbersInText.js +6 -0
  256. package/min/es6/exports/formatIncompletePhoneNumber.js +6 -0
  257. package/min/es6/exports/getCountries.js +6 -0
  258. package/min/es6/exports/getCountryCallingCode.js +6 -0
  259. package/min/es6/exports/getExampleNumber.js +6 -0
  260. package/min/es6/exports/getExtPrefix.js +6 -0
  261. package/min/es6/exports/isPossiblePhoneNumber.js +6 -0
  262. package/min/es6/exports/isSupportedCountry.js +6 -0
  263. package/min/es6/exports/isValidPhoneNumber.js +6 -0
  264. package/min/es6/exports/parsePhoneNumber.js +7 -0
  265. package/min/es6/exports/parsePhoneNumberWithError.js +7 -0
  266. package/min/es6/exports/searchNumbers.js +6 -0
  267. package/min/es6/exports/searchPhoneNumbersInText.js +6 -0
  268. package/min/es6/exports/validatePhoneNumberLength.js +6 -0
  269. package/min/es6/exports/withMetadataArgument.js +13 -0
  270. package/min/es6/index.d.cts +2 -0
  271. package/min/es6/index.d.ts +2 -0
  272. package/min/es6/index.js +44 -0
  273. package/min/es6/package.json +12 -0
  274. package/min/index.cjs +5 -0
  275. package/min/index.cjs.js +5 -0
  276. package/min/index.d.cts +3 -1
  277. package/min/index.d.ts +3 -1
  278. package/min/index.js +3 -0
  279. package/mobile/es6/exports/AsYouType.js +11 -0
  280. package/mobile/es6/exports/Metadata.js +11 -0
  281. package/mobile/es6/exports/PhoneNumber.js +11 -0
  282. package/mobile/es6/exports/PhoneNumberMatcher.js +11 -0
  283. package/mobile/es6/exports/findNumbers.js +6 -0
  284. package/mobile/es6/exports/findPhoneNumbersInText.js +6 -0
  285. package/mobile/es6/exports/formatIncompletePhoneNumber.js +6 -0
  286. package/mobile/es6/exports/getCountries.js +6 -0
  287. package/mobile/es6/exports/getCountryCallingCode.js +6 -0
  288. package/mobile/es6/exports/getExampleNumber.js +6 -0
  289. package/mobile/es6/exports/getExtPrefix.js +6 -0
  290. package/mobile/es6/exports/isPossiblePhoneNumber.js +6 -0
  291. package/mobile/es6/exports/isSupportedCountry.js +6 -0
  292. package/mobile/es6/exports/isValidPhoneNumber.js +6 -0
  293. package/mobile/es6/exports/parsePhoneNumber.js +7 -0
  294. package/mobile/es6/exports/parsePhoneNumberWithError.js +7 -0
  295. package/mobile/es6/exports/searchNumbers.js +6 -0
  296. package/mobile/es6/exports/searchPhoneNumbersInText.js +6 -0
  297. package/mobile/es6/exports/validatePhoneNumberLength.js +6 -0
  298. package/mobile/es6/exports/withMetadataArgument.js +13 -0
  299. package/mobile/es6/index.d.cts +2 -0
  300. package/mobile/es6/index.d.ts +2 -0
  301. package/mobile/es6/index.js +44 -0
  302. package/mobile/es6/package.json +12 -0
  303. package/mobile/index.cjs +5 -0
  304. package/mobile/index.cjs.js +5 -0
  305. package/mobile/index.d.cts +3 -1
  306. package/mobile/index.d.ts +3 -1
  307. package/mobile/index.js +4 -0
  308. package/package.json +28 -9
  309. package/types.d.cts +54 -21
  310. package/types.d.ts +54 -21
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PhoneNumberMatcher.test.js","names":["describe","it","expect","PhoneNumberMatcher","metadata","type","test","text","defaultCountry","expectedNumbers","nationalNumber","matcher","v2","hasNext","number","next","phoneNumber","shift","startsAt","undefined","to","equal","endsAt","country","length","leniency","throw","maxTries","number1","number2"],"sources":["../source/PhoneNumberMatcher.test.js"],"sourcesContent":["import { describe, it } from 'mocha'\r\nimport { expect } from 'chai'\r\n\r\nimport PhoneNumberMatcher from './PhoneNumberMatcher.js'\r\nimport metadata from '../metadata.min.json' with { type: 'json' }\r\n\r\nfunction test(text, defaultCountry, expectedNumbers) {\r\n\tif (typeof expectedNumbers === 'string') {\r\n\t\texpectedNumbers = [{\r\n\t\t\tnationalNumber: expectedNumbers\r\n\t\t}]\r\n\t}\r\n\tconst matcher = new PhoneNumberMatcher(text, { defaultCountry, v2: true }, metadata)\r\n\twhile (matcher.hasNext()) {\r\n\t\tconst number = matcher.next()\r\n\t\tconst phoneNumber = expectedNumbers.shift()\r\n\t\tif (phoneNumber.startsAt !== undefined) {\r\n\t\t\texpect(number.startsAt).to.equal(phoneNumber.startsAt)\r\n\t\t}\r\n\t\tif (phoneNumber.endsAt !== undefined) {\r\n\t\t\texpect(number.endsAt).to.equal(phoneNumber.endsAt)\r\n\t\t}\r\n\t\texpect(number.number.country).to.equal(phoneNumber.country || defaultCountry)\r\n\t\texpect(number.number.nationalNumber).to.equal(phoneNumber.nationalNumber)\r\n\t}\r\n\texpect(expectedNumbers.length).to.equal(0)\r\n}\r\n\r\ndescribe('PhoneNumberMatcher', () => {\r\n\tit('should find phone numbers', () => {\r\n\t\ttest(\r\n\t\t\t'The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.',\r\n\t\t\t'US',\r\n\t\t\t[{\r\n\t\t\t\tcountry: 'RU',\r\n\t\t\t\tnationalNumber: '8005553535',\r\n\t\t\t\tstartsAt: 14,\r\n\t\t\t\tendsAt: 32\r\n\t\t\t}, {\r\n\t\t\t\tcountry: 'US',\r\n\t\t\t\tnationalNumber: '2133734253',\r\n\t\t\t\tstartsAt: 41,\r\n\t\t\t\tendsAt: 55\r\n\t\t\t}]\r\n\t\t)\r\n\t})\r\n\r\n\tit('should find phone numbers from Mexico', () => {\r\n\t\t// Test parsing fixed-line numbers of Mexico.\r\n\t\ttest('+52 (449)978-0001', 'MX', '4499780001')\r\n\t\ttest('01 (449)978-0001', 'MX', '4499780001')\r\n\t\ttest('(449)978-0001', 'MX', '4499780001')\r\n\r\n\t\t// \"Dialling tokens 01, 02, 044, 045 and 1 are removed as they are\r\n\t\t// no longer valid since August 2019.\"\r\n\t\t// // Test parsing mobile numbers of Mexico.\r\n\t\t// test('+52 1 33 1234-5678', 'MX', '3312345678')\r\n\t\t// test('044 (33) 1234-5678', 'MX', '3312345678')\r\n\t\t// test('045 33 1234-5678', 'MX', '3312345678')\r\n\t})\r\n\r\n\tit('should find phone numbers from Argentina', () => {\r\n\t\t// Test parsing mobile numbers of Argentina.\r\n\t\ttest('+54 9 343 555 1212', 'AR', '93435551212')\r\n\t\ttest('0343 15-555-1212', 'AR', '93435551212')\r\n\r\n\t\ttest('+54 9 3715 65 4320', 'AR', '93715654320')\r\n\t\ttest('03715 15 65 4320', 'AR', '93715654320')\r\n\r\n\t\t// Test parsing fixed-line numbers of Argentina.\r\n\t\ttest('+54 11 3797 0000', 'AR', '1137970000')\r\n\t\ttest('011 3797 0000', 'AR', '1137970000')\r\n\r\n\t\ttest('+54 3715 65 4321', 'AR', '3715654321')\r\n\t\ttest('03715 65 4321', 'AR', '3715654321')\r\n\r\n\t\ttest('+54 23 1234 0000', 'AR', '2312340000')\r\n\t\ttest('023 1234 0000', 'AR', '2312340000')\r\n\t})\r\n\r\n\tit('should only support the supported leniency values', function() {\r\n\t\texpect(() => new PhoneNumberMatcher('+54 23 1234 0000', { leniency: 'STRICT_GROUPING', v2: true }, metadata)).to.throw('Supported values: \"POSSIBLE\", \"VALID\".')\r\n\t})\r\n\r\n\tit('should validate input parameters', function() {\r\n\t\t// expect(() => new PhoneNumberMatcher('+54 23 1234 0000', { v2: true }, metadata)).to.throw('`leniency` is required')\r\n\t\texpect(() => new PhoneNumberMatcher('+54 23 1234 0000', { leniency: '???', v2: true }, metadata)).to.throw('Unknown leniency: \"???\"')\r\n\t\texpect(() => new PhoneNumberMatcher('+54 23 1234 0000', { maxTries: -1, v2: true }, metadata)).to.throw('`maxTries` must be `>= 0`')\r\n\t})\r\n\r\n\tit('should throw when calling `.next()` and there\\'s no next match', function() {\r\n\t\tconst matcher = new PhoneNumberMatcher('+54 23 1234 0000', { v2: true }, metadata)\r\n\t\tmatcher.next()\r\n\t\texpect(() => matcher.next()).to.throw('No next element')\r\n\t})\r\n\r\n\tit('should find phone numbers that are separated by a slash', function() {\r\n\t\tconst matcher = new PhoneNumberMatcher('651-234-2345/332-445-1234', { defaultCountry: 'US', v2: true }, metadata)\r\n\r\n\t\texpect(matcher.hasNext()).to.equal(true)\r\n\t\tconst number1 = matcher.next()\r\n\t\texpect(number1.startsAt).to.equal(0)\r\n\t\texpect(number1.number.number).to.equal('+16512342345')\r\n\r\n\t\texpect(matcher.hasNext()).to.equal(true)\r\n\t\tconst number2 = matcher.next()\r\n\t\texpect(number2.startsAt).to.equal(13)\r\n\t\texpect(number2.number.number).to.equal('+13324451234')\r\n\r\n\t\texpect(matcher.hasNext()).to.equal(false)\r\n\t})\r\n})"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,EAAE,QAAQ,OAAO;AACpC,SAASC,MAAM,QAAQ,MAAM;AAE7B,OAAOC,kBAAkB,MAAM,yBAAyB;AACxD,OAAOC,QAAQ,MAAM,sBAAsB,QAAQC,IAAI,EAAE,MAAM;AAE/D,SAASC,IAAIA,CAACC,IAAI,EAAEC,cAAc,EAAEC,eAAe,EAAE;EACpD,IAAI,OAAOA,eAAe,KAA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CAACV,QAAQ,CAAC,CAACE,EAAE,CAACC,KAAK,CAAC,CAAC,CAAC;IACpCnB,MAAM,CAAC0B,OAAO,CAACd,MAAM,CAACA,MAAM,CAAC,CAACM,EAAE,CAACC,KAAK,CAAC,cAAc,CAAC;IAEtDnB,MAAM,CAACS,OAAO,CAACE,OAAO,CAAC,CAAC,CAAC,CAACO,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IACxC,MAAMQ,OAAO,GAAGlB,OAAO,CAACI,IAAI,CAAC,CAAC;IAC9Bb,MAAM,CAAC2B,OAAO,CAACX,QAAQ,CAAC,CAACE,EAAE,CAACC,KAAK,CAAC,EAAE,CAAC;IACrCnB,MAAM,CAAC2B,OAAO,CAACf,MAAM,CAACA,MAAM,CAAC,CAACM,EAAE,CAACC,KAAK,CAAC,cAAc,CAAC;IAEtDnB,MAAM,CAACS,OAAO,CAACE,OAAO,CAAC,CAAC,CAAC,CAACO,EAAE,CAACC,KAAK,CAAC,KAAK,CAAC;EAC1C,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,31 @@
1
+ // The minimum length of the national significant number.
2
+ export const MIN_LENGTH_FOR_NSN = 2;
3
+
4
+ // The ITU says the maximum length should be 15,
5
+ // but one can find longer numbers in Germany.
6
+ export const MAX_LENGTH_FOR_NSN = 17;
7
+
8
+ // The maximum length of the country calling code.
9
+ export const MAX_LENGTH_COUNTRY_CODE = 3;
10
+
11
+ // Digits accepted in phone numbers
12
+ // (ascii, fullwidth, arabic-indic, and eastern arabic digits).
13
+ export const VALID_DIGITS = '0-9\uFF10-\uFF19\u0660-\u0669\u06F0-\u06F9';
14
+
15
+ // `DASHES` will be right after the opening square bracket of the "character class"
16
+ const DASHES = '-\u2010-\u2015\u2212\u30FC\uFF0D';
17
+ const SLASHES = '\uFF0F/';
18
+ const DOTS = '\uFF0E.';
19
+ export const WHITESPACE = ' \u00A0\u00AD\u200B\u2060\u3000';
20
+ const BRACKETS = '()\uFF08\uFF09\uFF3B\uFF3D\\[\\]';
21
+ // export const OPENING_BRACKETS = '(\uFF08\uFF3B\\\['
22
+ const TILDES = '~\u2053\u223C\uFF5E';
23
+
24
+ // Regular expression of acceptable punctuation found in phone numbers. This
25
+ // excludes punctuation found as a leading character only. This consists of dash
26
+ // characters, white space characters, full stops, slashes, square brackets,
27
+ // parentheses and tildes. Full-width variants are also present.
28
+ export const VALID_PUNCTUATION = `${DASHES}${SLASHES}${DOTS}${WHITESPACE}${BRACKETS}${TILDES}`;
29
+ export const PLUS_CHARS = '+\uFF0B';
30
+ // const LEADING_PLUS_CHARS_PATTERN = new RegExp('^[' + PLUS_CHARS + ']+')
31
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","names":["MIN_LENGTH_FOR_NSN","MAX_LENGTH_FOR_NSN","MAX_LENGTH_COUNTRY_CODE","VALID_DIGITS","DASHES","SLASHES","DOTS","WHITESPACE","BRACKETS","TILDES","VALID_PUNCTUATION","PLUS_CHARS"],"sources":["../source/constants.js"],"sourcesContent":["// The minimum length of the national significant number.\r\nexport const MIN_LENGTH_FOR_NSN = 2\r\n\r\n// The ITU says the maximum length should be 15,\r\n// but one can find longer numbers in Germany.\r\nexport const MAX_LENGTH_FOR_NSN = 17\r\n\r\n// The maximum length of the country calling code.\r\nexport const MAX_LENGTH_COUNTRY_CODE = 3\r\n\r\n// Digits accepted in phone numbers\r\n// (ascii, fullwidth, arabic-indic, and eastern arabic digits).\r\nexport const VALID_DIGITS = '0-9\\uFF10-\\uFF19\\u0660-\\u0669\\u06F0-\\u06F9'\r\n\r\n// `DASHES` will be right after the opening square bracket of the \"character class\"\r\nconst DASHES = '-\\u2010-\\u2015\\u2212\\u30FC\\uFF0D'\r\nconst SLASHES = '\\uFF0F/'\r\nconst DOTS = '\\uFF0E.'\r\nexport const WHITESPACE = ' \\u00A0\\u00AD\\u200B\\u2060\\u3000'\r\nconst BRACKETS = '()\\uFF08\\uFF09\\uFF3B\\uFF3D\\\\[\\\\]'\r\n// export const OPENING_BRACKETS = '(\\uFF08\\uFF3B\\\\\\['\r\nconst TILDES = '~\\u2053\\u223C\\uFF5E'\r\n\r\n// Regular expression of acceptable punctuation found in phone numbers. This\r\n// excludes punctuation found as a leading character only. This consists of dash\r\n// characters, white space characters, full stops, slashes, square brackets,\r\n// parentheses and tildes. Full-width variants are also present.\r\nexport const VALID_PUNCTUATION = `${DASHES}${SLASHES}${DOTS}${WHITESPACE}${BRACKETS}${TILDES}`\r\n\r\nexport const PLUS_CHARS = '+\\uFF0B'\r\n// const LEADING_PLUS_CHARS_PATTERN = new RegExp('^[' + PLUS_CHARS + ']+')"],"mappings":"AAAA;AACA,OAAO,MAAMA,kBAAkB,GAAG,CAAC;;AAEnC;AACA;AACA,OAAO,MAAMC,kBAAkB,GAAG,EAAE;;AAEpC;AACA,OAAO,MAAMC,uBAAuB,GAAG,CAAC;;AAExC;AACA;AACA,OAAO,MAAMC,YAAY,GAAG,4CAA4C;;AAExE;AACA,MAAMC,MAAM,GAAG,kCAAkC;AACjD,MAAMC,OAAO,GAAG,SAAS;AACzB,MAAMC,IAAI,GAAG,SAAS;AACtB,OAAO,MAAMC,UAAU,GAAG,iCAAiC;AAC3D,MAAMC,QAAQ,GAAG,kCAAkC;AACnD;AACA,MAAMC,MAAM,GAAG,qBAAqB;;AAEpC;AACA;AACA;AACA;AACA,OAAO,MAAMC,iBAAiB,GAAG,GAAGN,MAAM,GAAGC,OAAO,GAAGC,IAAI,GAAGC,UAAU,GAAGC,QAAQ,GAAGC,MAAM,EAAE;AAE9F,OAAO,MAAME,UAAU,GAAG,SAAS;AACnC","ignoreList":[]}
@@ -0,0 +1,98 @@
1
+ // https://medium.com/dsinjs/implementing-lru-cache-in-javascript-94ba6755cda9
2
+
3
+ class Node {
4
+ constructor(key, value, next = null, prev = null) {
5
+ this.key = key;
6
+ this.value = value;
7
+ this.next = next;
8
+ this.prev = prev;
9
+ }
10
+ }
11
+ export default class LRUCache {
12
+ //set default limit of 10 if limit is not passed.
13
+ constructor(limit = 10) {
14
+ this.size = 0;
15
+ this.limit = limit;
16
+ this.head = null;
17
+ this.tail = null;
18
+ this.cache = {};
19
+ }
20
+
21
+ // Write Node to head of LinkedList
22
+ // update cache with Node key and Node reference
23
+ put(key, value) {
24
+ this.ensureLimit();
25
+ if (!this.head) {
26
+ this.head = this.tail = new Node(key, value);
27
+ } else {
28
+ const node = new Node(key, value, this.head);
29
+ this.head.prev = node;
30
+ this.head = node;
31
+ }
32
+
33
+ //Update the cache map
34
+ this.cache[key] = this.head;
35
+ this.size++;
36
+ }
37
+
38
+ // Read from cache map and make that node as new Head of LinkedList
39
+ get(key) {
40
+ if (this.cache[key]) {
41
+ const value = this.cache[key].value;
42
+
43
+ // node removed from it's position and cache
44
+ this.remove(key);
45
+ // write node again to the head of LinkedList to make it most recently used
46
+ this.put(key, value);
47
+ return value;
48
+ }
49
+ console.log(`Item not available in cache for key ${key}`);
50
+ }
51
+ ensureLimit() {
52
+ if (this.size === this.limit) {
53
+ this.remove(this.tail.key);
54
+ }
55
+ }
56
+ remove(key) {
57
+ const node = this.cache[key];
58
+ if (node.prev !== null) {
59
+ node.prev.next = node.next;
60
+ } else {
61
+ this.head = node.next;
62
+ }
63
+ if (node.next !== null) {
64
+ node.next.prev = node.prev;
65
+ } else {
66
+ this.tail = node.prev;
67
+ }
68
+ delete this.cache[key];
69
+ this.size--;
70
+ }
71
+ clear() {
72
+ this.head = null;
73
+ this.tail = null;
74
+ this.size = 0;
75
+ this.cache = {};
76
+ }
77
+
78
+ // // Invokes the callback function with every node of the chain and the index of the node.
79
+ // forEach(fn) {
80
+ // let node = this.head;
81
+ // let counter = 0;
82
+ // while (node) {
83
+ // fn(node, counter);
84
+ // node = node.next;
85
+ // counter++;
86
+ // }
87
+ // }
88
+
89
+ // // To iterate over LRU with a 'for...of' loop
90
+ // *[Symbol.iterator]() {
91
+ // let node = this.head;
92
+ // while (node) {
93
+ // yield node;
94
+ // node = node.next;
95
+ // }
96
+ // }
97
+ }
98
+ //# sourceMappingURL=LRUCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LRUCache.js","names":["Node","constructor","key","value","next","prev","LRUCache","limit","size","head","tail","cache","put","ensureLimit","node","get","remove","console","log","clear"],"sources":["../../source/findNumbers/LRUCache.js"],"sourcesContent":["// https://medium.com/dsinjs/implementing-lru-cache-in-javascript-94ba6755cda9\r\n\r\nclass Node {\r\n constructor(key, value, next = null, prev = null) {\r\n this.key = key;\r\n this.value = value;\r\n this.next = next;\r\n this.prev = prev;\r\n }\r\n}\r\n\r\nexport default class LRUCache {\r\n //set default limit of 10 if limit is not passed.\r\n constructor(limit = 10) {\r\n this.size = 0;\r\n this.limit = limit;\r\n this.head = null;\r\n this.tail = null;\r\n this.cache = {};\r\n }\r\n\r\n // Write Node to head of LinkedList\r\n // update cache with Node key and Node reference\r\n put(key, value){\r\n this.ensureLimit();\r\n\r\n if(!this.head){\r\n this.head = this.tail = new Node(key, value);\r\n }else{\r\n const node = new Node(key, value, this.head);\r\n this.head.prev = node;\r\n this.head = node;\r\n }\r\n\r\n //Update the cache map\r\n this.cache[key] = this.head;\r\n this.size++;\r\n }\r\n\r\n // Read from cache map and make that node as new Head of LinkedList\r\n get(key){\r\n if(this.cache[key]){\r\n const value = this.cache[key].value;\r\n\r\n // node removed from it's position and cache\r\n this.remove(key)\r\n // write node again to the head of LinkedList to make it most recently used\r\n this.put(key, value);\r\n\r\n return value;\r\n }\r\n\r\n console.log(`Item not available in cache for key ${key}`);\r\n }\r\n\r\n ensureLimit(){\r\n if(this.size === this.limit){\r\n this.remove(this.tail.key)\r\n }\r\n }\r\n\r\n remove(key){\r\n const node = this.cache[key];\r\n\r\n if(node.prev !== null){\r\n node.prev.next = node.next;\r\n }else{\r\n this.head = node.next;\r\n }\r\n\r\n if(node.next !== null){\r\n node.next.prev = node.prev;\r\n }else{\r\n this.tail = node.prev\r\n }\r\n\r\n delete this.cache[key];\r\n this.size--;\r\n }\r\n\r\n clear() {\r\n this.head = null;\r\n this.tail = null;\r\n this.size = 0;\r\n this.cache = {};\r\n }\r\n\r\n // // Invokes the callback function with every node of the chain and the index of the node.\r\n // forEach(fn) {\r\n // let node = this.head;\r\n // let counter = 0;\r\n // while (node) {\r\n // fn(node, counter);\r\n // node = node.next;\r\n // counter++;\r\n // }\r\n // }\r\n\r\n // // To iterate over LRU with a 'for...of' loop\r\n // *[Symbol.iterator]() {\r\n // let node = this.head;\r\n // while (node) {\r\n // yield node;\r\n // node = node.next;\r\n // }\r\n // }\r\n}"],"mappings":"AAAA;;AAEA,MAAMA,IAAI,CAAC;EACTC,WAAWA,CAACC,GAAG,EAAEC,KAAK,EAAEC,IAAI,GAAG,IAAI,EAAEC,IAAI,GAAG,IAAI,EAAE;IAChD,IAAI,CAACH,GAAG,GAAGA,GAAG;IACd,IAAI,CAACC,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACC,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,IAAI,GAAGA,IAAI;EAClB;AACF;AAEA,eAAe,MAAMC,QAAQ,CAAC;EAC5B;EACAL,WAAWA,CAACM,KAAK,GAAG,EAAE,EAAE;IACtB,IAAI,CAACC,IAAI,GAAG,CAAC;IACb,IAAI,CAACD,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACE,IAAI,GAAG,IAAI;IAChB,IAAI,CAACC,IAAI,GAAG,IAAI;IAChB,IAAI,CAACC,KAAK,GAAG,CAAC,CAAC;EACjB;;EAEA;EACA;EACAC,GAAGA,CAACV,GAAG,EAAEC,KAAK,EAAC;IACb,IAAI,CAACU,WAAW,CAAC,CAAC;IAElB,IAAG,CAAC,IAAI,CAACJ,IAAI,EAAC;MACZ,IAAI,CAACA,IAAI,GAAG,IAAI,CAACC,IAAI,GAAG,IAAIV,IAAI,CAACE,GAAG,EAAEC,KAAK,CAAC;IAC9C,CAAC,MAAI;MACH,MAAMW,IAAI,GAAG,IAAId,IAAI,CAACE,GAAG,EAAEC,KAAK,EA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,OAAO,IAAI,CAACM,KAAK,CAACT,GAAG,CAAC;IACtB,IAAI,CAACM,IAAI,EAAE;EACb;EAEAW,KAAKA,CAAA,EAAG;IACN,IAAI,CAACV,IAAI,GAAG,IAAI;IAChB,IAAI,CAACC,IAAI,GAAG,IAAI;IAChB,IAAI,CAACF,IAAI,GAAG,CAAC;IACb,IAAI,CAACG,KAAK,GAAG,CAAC,CAAC;EACjB;;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;AACF","ignoreList":[]}
@@ -0,0 +1,311 @@
1
+ import parseDigits from '../helpers/parseDigits.js';
2
+ import matchPhoneNumberStringAgainstPhoneNumber from './matchPhoneNumberStringAgainstPhoneNumber.js';
3
+ import Metadata from '../metadata.js';
4
+ import getCountryByCallingCode from '../helpers/getCountryByCallingCode.js';
5
+ import { chooseFormatForNumber } from '../format.js';
6
+ import { startsWith, endsWith } from './util.js';
7
+
8
+ /**
9
+ * Leniency when finding potential phone numbers in text segments
10
+ * The levels here are ordered in increasing strictness.
11
+ */
12
+ export default {
13
+ /**
14
+ * Phone numbers accepted are "possible", but not necessarily "valid".
15
+ */
16
+ POSSIBLE(phoneNumber, {
17
+ candidate,
18
+ metadata
19
+ }) {
20
+ return true;
21
+ },
22
+ /**
23
+ * Phone numbers accepted are "possible" and "valid".
24
+ * Numbers written in national format must have their national-prefix
25
+ * present if it is usually written for a number of this type.
26
+ */
27
+ VALID(phoneNumber, {
28
+ candidate,
29
+ defaultCountry,
30
+ metadata
31
+ }) {
32
+ if (!phoneNumber.isValid() || !containsOnlyValidXChars(phoneNumber, candidate, metadata)) {
33
+ return false;
34
+ }
35
+
36
+ // Skipped for simplicity.
37
+ // return isNationalPrefixPresentIfRequired(phoneNumber, { defaultCountry, metadata })
38
+ return true;
39
+ },
40
+ /**
41
+ * Phone numbers accepted are "valid" and
42
+ * are grouped in a possible way for this locale. For example, a US number written as
43
+ * "65 02 53 00 00" and "650253 0000" are not accepted at this leniency level, whereas
44
+ * "650 253 0000", "650 2530000" or "6502530000" are.
45
+ * Numbers with more than one '/' symbol in the national significant number
46
+ * are also dropped at this level.
47
+ *
48
+ * Warning: This level might result in lower coverage especially for regions outside of
49
+ * country code "+1". If you are not sure about which level to use,
50
+ * email the discussion group libphonenumber-discuss@googlegroups.com.
51
+ */
52
+ STRICT_GROUPING(phoneNumber, {
53
+ candidate,
54
+ defaultCountry,
55
+ metadata,
56
+ regExpCache
57
+ }) {
58
+ if (!phoneNumber.isValid() || !containsOnlyValidXChars(phoneNumber, candidate, metadata) || containsMoreThanOneSlashInNationalNumber(phoneNumber, candidate) || !isNationalPrefixPresentIfRequired(phoneNumber, {
59
+ defaultCountry,
60
+ metadata
61
+ })) {
62
+ return false;
63
+ }
64
+ return checkNumberGroupingIsValid(phoneNumber, candidate, metadata, allNumberGroupsRemainGrouped, regExpCache);
65
+ },
66
+ /**
67
+ * Phone numbers accepted are "valid" and are grouped in the same way
68
+ * that we would have formatted it, or as a single block.
69
+ * For example, a US number written as "650 2530000" is not accepted
70
+ * at this leniency level, whereas "650 253 0000" or "6502530000" are.
71
+ * Numbers with more than one '/' symbol are also dropped at this level.
72
+ *
73
+ * Warning: This level might result in lower coverage especially for regions outside of
74
+ * country code "+1". If you are not sure about which level to use, email the discussion group
75
+ * libphonenumber-discuss@googlegroups.com.
76
+ */
77
+ EXACT_GROUPING(phoneNumber, {
78
+ candidate,
79
+ defaultCountry,
80
+ metadata,
81
+ regExpCache
82
+ }) {
83
+ if (!phoneNumber.isValid() || !containsOnlyValidXChars(phoneNumber, candidate, metadata) || containsMoreThanOneSlashInNationalNumber(phoneNumber, candidate) || !isNationalPrefixPresentIfRequired(phoneNumber, {
84
+ defaultCountry,
85
+ metadata
86
+ })) {
87
+ return false;
88
+ }
89
+ return checkNumberGroupingIsValid(phoneNumber, candidate, metadata, allNumberGroupsAreExactlyPresent, regExpCache);
90
+ }
91
+ };
92
+ function containsOnlyValidXChars(phoneNumber, candidate, metadata) {
93
+ // The characters 'x' and 'X' can be (1) a carrier code, in which case they always precede the
94
+ // national significant number or (2) an extension sign, in which case they always precede the
95
+ // extension number. We assume a carrier code is more than 1 digit, so the first case has to
96
+ // have more than 1 consecutive 'x' or 'X', whereas the second case can only have exactly 1 'x'
97
+ // or 'X'. We ignore the character if it appears as the last character of the string.
98
+ for (let index = 0; index < candidate.length - 1; index++) {
99
+ const charAtIndex = candidate.charAt(index);
100
+ if (charAtIndex === 'x' || charAtIndex === 'X') {
101
+ const charAtNextIndex = candidate.charAt(index + 1);
102
+ if (charAtNextIndex === 'x' || charAtNextIndex === 'X') {
103
+ // This is the carrier code case, in which the 'X's always precede the national
104
+ // significant number.
105
+ index++;
106
+ if (matchPhoneNumberStringAgainstPhoneNumber(candidate.substring(index), phoneNumber, metadata) !== 'NSN_MATCH') {
107
+ return false;
108
+ }
109
+ // This is the extension sign case, in which the 'x' or 'X' should always precede the
110
+ // extension number.
111
+ } else {
112
+ const ext = parseDigits(candidate.substring(index));
113
+ if (ext) {
114
+ if (phoneNumber.ext !== ext) {
115
+ return false;
116
+ }
117
+ } else {
118
+ if (phoneNumber.ext) {
119
+ return false;
120
+ }
121
+ }
122
+ }
123
+ }
124
+ }
125
+ return true;
126
+ }
127
+ function isNationalPrefixPresentIfRequired(phoneNumber, {
128
+ defaultCountry,
129
+ metadata: _metadata
130
+ }) {
131
+ // First, check how we deduced the country code. If it was written in international format, then
132
+ // the national prefix is not required.
133
+ if (phoneNumber.__countryCallingCodeSource !== 'FROM_DEFAULT_COUNTRY') {
134
+ return true;
135
+ }
136
+ const metadata = new Metadata(_metadata);
137
+ metadata.selectNumberingPlan(phoneNumber.countryCallingCode);
138
+ const phoneNumberRegion = phoneNumber.country || getCountryByCallingCode(phoneNumber.countryCallingCode, {
139
+ nationalNumber: phoneNumber.nationalNumber,
140
+ metadata
141
+ });
142
+
143
+ // Check if a national prefix should be present when formatting this number.
144
+ const nationalNumber = phoneNumber.nationalNumber;
145
+ const format = chooseFormatForNumber(metadata.numberingPlan.formats(), nationalNumber);
146
+
147
+ // To do this, we check that a national prefix formatting rule was present
148
+ // and that it wasn't just the first-group symbol ($1) with punctuation.
149
+ if (format.nationalPrefixFormattingRule()) {
150
+ if (metadata.numberingPlan.nationalPrefixIsOptionalWhenFormattingInNationalFormat()) {
151
+ // The national-prefix is optional in these cases, so we don't need to check if it was present.
152
+ return true;
153
+ }
154
+ if (!format.usesNationalPrefix()) {
155
+ // National Prefix not needed for this number.
156
+ return true;
157
+ }
158
+ return Boolean(phoneNumber.nationalPrefix);
159
+ }
160
+ return true;
161
+ }
162
+ export function containsMoreThanOneSlashInNationalNumber(phoneNumber, candidate) {
163
+ const firstSlashInBodyIndex = candidate.indexOf('/');
164
+ if (firstSlashInBodyIndex < 0) {
165
+ // No slashes, this is okay.
166
+ return false;
167
+ }
168
+
169
+ // Now look for a second one.
170
+ const secondSlashInBodyIndex = candidate.indexOf('/', firstSlashInBodyIndex + 1);
171
+ if (secondSlashInBodyIndex < 0) {
172
+ // Only one slash, this is okay.
173
+ return false;
174
+ }
175
+
176
+ // If the first slash is after the country calling code, this is permitted.
177
+ const candidateHasCountryCode = phoneNumber.__countryCallingCodeSource === 'FROM_NUMBER_WITH_PLUS_SIGN' || phoneNumber.__countryCallingCodeSource === 'FROM_NUMBER_WITHOUT_PLUS_SIGN';
178
+ if (candidateHasCountryCode && parseDigits(candidate.substring(0, firstSlashInBodyIndex)) === phoneNumber.countryCallingCode) {
179
+ // Any more slashes and this is illegal.
180
+ return candidate.slice(secondSlashInBodyIndex + 1).indexOf('/') >= 0;
181
+ }
182
+ return true;
183
+ }
184
+ function checkNumberGroupingIsValid(number, candidate, metadata, checkGroups, regExpCache) {
185
+ throw new Error('This part of code hasn\'t been ported');
186
+ const normalizedCandidate = normalizeDigits(candidate, true /* keep non-digits */);
187
+ let formattedNumberGroups = getNationalNumberGroups(metadata, number, null);
188
+ if (checkGroups(metadata, number, normalizedCandidate, formattedNumberGroups)) {
189
+ return true;
190
+ }
191
+
192
+ // If this didn't pass, see if there are any alternate formats that match, and try them instead.
193
+ const alternateFormats = MetadataManager.getAlternateFormatsForCountry(number.getCountryCode());
194
+ const nationalSignificantNumber = util.getNationalSignificantNumber(number);
195
+ if (alternateFormats) {
196
+ for (const alternateFormat of alternateFormats.numberFormats()) {
197
+ if (alternateFormat.leadingDigitsPatterns().length > 0) {
198
+ // There is only one leading digits pattern for alternate formats.
199
+ const leadingDigitsRegExp = regExpCache.getPatternForRegExp('^' + alternateFormat.leadingDigitsPatterns()[0]);
200
+ if (!leadingDigitsRegExp.test(nationalSignificantNumber)) {
201
+ // Leading digits don't match; try another one.
202
+ continue;
203
+ }
204
+ }
205
+ formattedNumberGroups = getNationalNumberGroups(metadata, number, alternateFormat);
206
+ if (checkGroups(metadata, number, normalizedCandidate, formattedNumberGroups)) {
207
+ return true;
208
+ }
209
+ }
210
+ }
211
+ return false;
212
+ }
213
+
214
+ /**
215
+ * Helper method to get the national-number part of a number, formatted without any national
216
+ * prefix, and return it as a set of digit blocks that would be formatted together following
217
+ * standard formatting rules.
218
+ */
219
+ function getNationalNumberGroups(metadata, number, formattingPattern) {
220
+ throw new Error('This part of code hasn\'t been ported');
221
+ if (formattingPattern) {
222
+ // We format the NSN only, and split that according to the separator.
223
+ const nationalSignificantNumber = util.getNationalSignificantNumber(number);
224
+ return util.formatNsnUsingPattern(nationalSignificantNumber, formattingPattern, 'RFC3966', metadata).split('-');
225
+ }
226
+
227
+ // This will be in the format +CC-DG1-DG2-DGX;ext=EXT where DG1..DGX represents groups of digits.
228
+ const rfc3966Format = formatNumber(number, 'RFC3966', metadata);
229
+
230
+ // We remove the extension part from the formatted string before splitting it into different
231
+ // groups.
232
+ let endIndex = rfc3966Format.indexOf(';');
233
+ if (endIndex < 0) {
234
+ endIndex = rfc3966Format.length;
235
+ }
236
+
237
+ // The country-code will have a '-' following it.
238
+ const startIndex = rfc3966Format.indexOf('-') + 1;
239
+ return rfc3966Format.slice(startIndex, endIndex).split('-');
240
+ }
241
+ function allNumberGroupsAreExactlyPresent(metadata, number, normalizedCandidate, formattedNumberGroups) {
242
+ throw new Error('This part of code hasn\'t been ported');
243
+ const candidateGroups = normalizedCandidate.split(NON_DIGITS_PATTERN);
244
+
245
+ // Set this to the last group, skipping it if the number has an extension.
246
+ let candidateNumberGroupIndex = number.hasExtension() ? candidateGroups.length - 2 : candidateGroups.length - 1;
247
+
248
+ // First we check if the national significant number is formatted as a block.
249
+ // We use contains and not equals, since the national significant number may be present with
250
+ // a prefix such as a national number prefix, or the country code itself.
251
+ if (candidateGroups.length == 1 || candidateGroups[candidateNumberGroupIndex].contains(util.getNationalSignificantNumber(number))) {
252
+ return true;
253
+ }
254
+
255
+ // Starting from the end, go through in reverse, excluding the first group, and check the
256
+ // candidate and number groups are the same.
257
+ let formattedNumberGroupIndex = formattedNumberGroups.length - 1;
258
+ while (formattedNumberGroupIndex > 0 && candidateNumberGroupIndex >= 0) {
259
+ if (candidateGroups[candidateNumberGroupIndex] !== formattedNumberGroups[formattedNumberGroupIndex]) {
260
+ return false;
261
+ }
262
+ formattedNumberGroupIndex--;
263
+ candidateNumberGroupIndex--;
264
+ }
265
+
266
+ // Now check the first group. There may be a national prefix at the start, so we only check
267
+ // that the candidate group ends with the formatted number group.
268
+ return candidateNumberGroupIndex >= 0 && endsWith(candidateGroups[candidateNumberGroupIndex], formattedNumberGroups[0]);
269
+ }
270
+ function allNumberGroupsRemainGrouped(metadata, number, normalizedCandidate, formattedNumberGroups) {
271
+ throw new Error('This part of code hasn\'t been ported');
272
+ let fromIndex = 0;
273
+ if (number.getCountryCodeSource() !== CountryCodeSource.FROM_DEFAULT_COUNTRY) {
274
+ // First skip the country code if the normalized candidate contained it.
275
+ const countryCode = String(number.getCountryCode());
276
+ fromIndex = normalizedCandidate.indexOf(countryCode) + countryCode.length();
277
+ }
278
+
279
+ // Check each group of consecutive digits are not broken into separate groupings in the
280
+ // {@code normalizedCandidate} string.
281
+ for (let i = 0; i < formattedNumberGroups.length; i++) {
282
+ // Fails if the substring of {@code normalizedCandidate} starting from {@code fromIndex}
283
+ // doesn't contain the consecutive digits in formattedNumberGroups[i].
284
+ fromIndex = normalizedCandidate.indexOf(formattedNumberGroups[i], fromIndex);
285
+ if (fromIndex < 0) {
286
+ return false;
287
+ }
288
+ // Moves {@code fromIndex} forward.
289
+ fromIndex += formattedNumberGroups[i].length();
290
+ if (i == 0 && fromIndex < normalizedCandidate.length()) {
291
+ // We are at the position right after the NDC. We get the region used for formatting
292
+ // information based on the country code in the phone number, rather than the number itself,
293
+ // as we do not need to distinguish between different countries with the same country
294
+ // calling code and this is faster.
295
+ const region = util.getRegionCodeForCountryCode(number.getCountryCode());
296
+ if (util.getNddPrefixForRegion(region, true) != null && Character.isDigit(normalizedCandidate.charAt(fromIndex))) {
297
+ // This means there is no formatting symbol after the NDC. In this case, we only
298
+ // accept the number if there is no formatting symbol at all in the number, except
299
+ // for extensions. This is only important for countries with national prefixes.
300
+ const nationalSignificantNumber = util.getNationalSignificantNumber(number);
301
+ return startsWith(normalizedCandidate.slice(fromIndex - formattedNumberGroups[i].length), nationalSignificantNumber);
302
+ }
303
+ }
304
+ }
305
+
306
+ // The check here makes sure that we haven't mistakenly already used the extension to
307
+ // match the last group of the subscriber number. Note the extension cannot have
308
+ // formatting in-between digits.
309
+ return normalizedCandidate.slice(fromIndex).contains(number.getExtension());
310
+ }
311
+ //# sourceMappingURL=Leniency.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Leniency.js","names":["parseDigits","matchPhoneNumberStringAgainstPhoneNumber","Metadata","getCountryByCallingCode","chooseFormatForNumber","startsWith","endsWith","POSSIBLE","phoneNumber","candidate","metadata","VALID","defaultCountry","isValid","containsOnlyValidXChars","STRICT_GROUPING","regExpCache","containsMoreThanOneSlashInNationalNumber","isNationalPrefixPresentIfRequired","checkNumberGroupingIsValid","allNumberGroupsRemainGrouped","EXACT_GROUPING","allNumberGroupsAreExactlyPresent","index","length","charAtIndex","charAt","charAtNextIndex","substring","ext","_metadata","__countryCallingCodeSource","selectNumberingPlan","countryCallingCode","phoneNumberRegion","country","nationalNumber","format","numberingPlan","formats","nationalPrefixFormattingRule","nationalPrefixIsOptionalWhenFormattingInNationalFormat","usesNationalPrefix","Boolean","nationalPrefix","firstSlashInBodyIndex","indexOf","secondSlashInBodyIndex","candidateHasCountryCode","slice","number","checkGroups","Error","normalizedCandidate","normalizeDigits","formattedNumberGroups","getNationalNumberGroups","alternateFormats","MetadataManager","getAlternateFormatsForCountry","getCountryCode","nationalSignificantNumber","util","getNationalSignificantNumber","alternateFormat","numberFormats","leadingDigitsPatterns","leadingDigitsRegExp","getPatternForRegExp","test","formattingPattern","formatNsnUsingPattern","split","rfc3966Format","formatNumber","endIndex","startIndex","candidateGroups","NON_DIGITS_PATTERN","candidateNumberGroupIndex","hasExtension","contains","formattedNumberGroupIndex","fromIndex","getCountryCodeSource","CountryCodeSource","FROM_DEFAULT_COUNTRY","countryCode","String","i","region","getRegionCodeForCountryCode","getNddPrefixForRegion","Character","isDigit","getExtension"],"sources":["../../source/findNumbers/Leniency.js"],"sourcesContent":["import parseDigits from '../helpers/parseDigits.js'\r\nimport matchPhoneNumberStringAgainstPhoneNumber from './matchPhoneNumberStringAgainstPhoneNumber.js'\r\nimport Metadata from '../metadata.js'\r\nimport getCountryByCallingCode from '../helpers/getCountryByCallingCode.js'\r\nimport { chooseFormatForNumber } from '../format.js'\r\n\r\nimport {\r\n\tstartsWith,\r\n\tendsWith\r\n} from './util.js'\r\n\r\n/**\r\n * Leniency when finding potential phone numbers in text segments\r\n * The levels here are ordered in increasing strictness.\r\n */\r\nexport default\r\n{\r\n\t/**\r\n\t * Phone numbers accepted are \"possible\", but not necessarily \"valid\".\r\n\t */\r\n\tPOSSIBLE(phoneNumber, { candidate, metadata })\r\n\t{\r\n\t\treturn true\r\n\t},\r\n\r\n\t/**\r\n\t * Phone numbers accepted are \"possible\" and \"valid\".\r\n\t * Numbers written in national format must have their national-prefix\r\n\t * present if it is usually written for a number of this type.\r\n\t */\r\n\tVALID(phoneNumber, { candidate, defaultCountry, metadata })\r\n\t{\r\n\t\tif (\r\n\t\t\t!phoneNumber.isValid() ||\r\n\t\t\t!containsOnlyValidXChars(phoneNumber, candidate, metadata)\r\n\t\t)\r\n\t\t{\r\n\t\t\treturn false\r\n\t\t}\r\n\r\n\t\t// Skipped for simplicity.\r\n\t\t// return isNationalPrefixPresentIfRequired(phoneNumber, { defaultCountry, metadata })\r\n\t\treturn true\r\n\t},\r\n\r\n\t/**\r\n\t * Phone numbers accepted are \"valid\" and\r\n\t * are grouped in a possible way for this locale. For example, a US number written as\r\n\t * \"65 02 53 00 00\" and \"650253 0000\" are not accepted at this leniency level, whereas\r\n\t * \"650 253 0000\", \"650 2530000\" or \"6502530000\" are.\r\n\t * Numbers with more than one '/' symbol in the national significant number\r\n\t * are also dropped at this level.\r\n\t *\r\n\t * Warning: This level might result in lower coverage especially for regions outside of\r\n\t * country code \"+1\". If you are not sure about which level to use,\r\n\t * email the discussion group libphonenumber-discuss@googlegroups.com.\r\n\t */\r\n\tSTRICT_GROUPING(phoneNumber, { candidate, defaultCountry, metadata, regExpCache })\r\n\t{\r\n\t\tif (\r\n\t\t\t!phoneNumber.isValid() ||\r\n\t\t\t!containsOnlyValidXChars(phoneNumber, candidate, metadata) ||\r\n\t\t\tcontainsMoreThanOneSlashInNationalNumber(phoneNumber, candidate) ||\r\n\t\t\t!isNationalPrefixPresentIfRequired(phoneNumber, { defaultCountry, metadata })\r\n\t\t)\r\n\t\t{\r\n\t\t\treturn false\r\n\t\t}\r\n\r\n\t\treturn checkNumberGroupingIsValid\r\n\t\t(\r\n\t\t\tphoneNumber,\r\n\t\t\tcandidate,\r\n\t\t\tmetadata,\r\n\t\t\tallNumberGroupsRemainGrouped,\r\n\t\t\tregExpCache\r\n\t\t)\r\n\t},\r\n\r\n\t/**\r\n\t * Phone numbers accepted are \"valid\" and are grouped in the same way\r\n\t * that we would have formatted it, or as a single block.\r\n\t * For example, a US number written as \"650 2530000\" is not accepted\r\n\t * at this leniency level, whereas \"650 253 0000\" or \"6502530000\" are.\r\n\t * Numbers with more than one '/' symbol are also dropped at this level.\r\n\t *\r\n\t * Warning: This level might result in lower coverage especially for regions outside of\r\n\t * country code \"+1\". If you are not sure about which level to use, email the discussion group\r\n\t * libphonenumber-discuss@googlegroups.com.\r\n\t */\r\n\tEXACT_GROUPING(phoneNumber, { candidate, defaultCountry, metadata, regExpCache })\r\n\t{\r\n\t\tif (\r\n\t\t\t!phoneNumber.isValid() ||\r\n\t\t\t!containsOnlyValidXChars(phoneNumber, candidate, metadata) ||\r\n\t\t\tcontainsMoreThanOneSlashInNationalNumber(phoneNumber, candidate) ||\r\n\t\t\t!isNationalPrefixPresentIfRequired(phoneNumber, { defaultCountry, metadata })\r\n\t\t)\r\n\t\t{\r\n\t\t\treturn false\r\n\t\t}\r\n\r\n\t\treturn checkNumberGroupingIsValid\r\n\t\t(\r\n\t\t\tphoneNumber,\r\n\t\t\tcandidate,\r\n\t\t\tmetadata,\r\n\t\t\tallNumberGroupsAreExactlyPresent,\r\n\t\t\tregExpCache\r\n\t\t)\r\n\t}\r\n}\r\n\r\nfunction containsOnlyValidXChars(phoneNumber, candidate, metadata)\r\n{\r\n\t// The characters 'x' and 'X' can be (1) a carrier code, in which case they always precede the\r\n\t// national significant number or (2) an extension sign, in which case they always precede the\r\n\t// extension number. We assume a carrier code is more than 1 digit, so the first case has to\r\n\t// have more than 1 consecutive 'x' or 'X', whereas the second case can only have exactly 1 'x'\r\n\t// or 'X'. We ignore the character if it appears as the last character of the string.\r\n\tfor (let index = 0; index < candidate.length - 1; index++)\r\n\t{\r\n\t\tconst charAtIndex = candidate.charAt(index)\r\n\r\n\t\tif (charAtIndex === 'x' || charAtIndex === 'X')\r\n\t\t{\r\n\t\t\tconst charAtNextIndex = candidate.charAt(index + 1)\r\n\r\n\t\t\tif (charAtNextIndex === 'x' || charAtNextIndex === 'X')\r\n\t\t\t{\r\n\t\t\t\t// This is the carrier code case, in which the 'X's always precede the national\r\n\t\t\t\t// significant number.\r\n\t\t\t\tindex++\r\n\t\t\t\tif (matchPhoneNumberStringAgainstPhoneNumber(candidate.substring(index), phoneNumber, metadata) !== 'NSN_MATCH')\r\n\t\t\t\t{\r\n\t\t\t\t\treturn false\r\n\t\t\t\t}\r\n\t\t\t\t// This is the extension sign case, in which the 'x' or 'X' should always precede the\r\n\t\t\t\t// extension number.\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tconst ext = parseDigits(candidate.substring(index))\r\n\t\t\t\tif (ext) {\r\n\t\t\t\t\tif (phoneNumber.ext !== ext) {\r\n\t\t\t\t\t\treturn false\r\n\t\t\t\t\t}\r\n\t\t\t\t} else {\r\n\t\t\t\t\tif (phoneNumber.ext) {\r\n\t\t\t\t\t\treturn false\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\treturn true\r\n}\r\n\r\nfunction isNationalPrefixPresentIfRequired(phoneNumber, { defaultCountry, metadata: _metadata })\r\n{\r\n\t// First, check how we deduced the country code. If it was written in international format, then\r\n\t// the national prefix is not required.\r\n\tif (phoneNumber.__countryCallingCodeSource !== 'FROM_DEFAULT_COUNTRY')\r\n\t{\r\n\t\treturn true\r\n\t}\r\n\r\n\tconst metadata = new Metadata(_metadata)\r\n\tmetadata.selectNumberingPlan(phoneNumber.countryCallingCode)\r\n\r\n\tconst phoneNumberRegion = phoneNumber.country || getCountryByCallingCode(phoneNumber.countryCallingCode, {\r\n\t\tnationalNumber: phoneNumber.nationalNumber,\r\n\t\tmetadata\r\n\t})\r\n\r\n\t// Check if a national prefix should be present when formatting this number.\r\n\tconst nationalNumber = phoneNumber.nationalNumber\r\n\tconst format = chooseFormatForNumber(metadata.numberingPlan.formats(), nationalNumber)\r\n\r\n\t// To do this, we check that a national prefix formatting rule was present\r\n\t// and that it wasn't just the first-group symbol ($1) with punctuation.\r\n\tif (format.nationalPrefixFormattingRule())\r\n\t{\r\n\t\tif (metadata.numberingPlan.nationalPrefixIsOptionalWhenFormattingInNationalFormat())\r\n\t\t{\r\n\t\t\t// The national-prefix is optional in these cases, so we don't need to check if it was present.\r\n\t\t\treturn true\r\n\t\t}\r\n\r\n\t\tif (!format.usesNationalPrefix())\r\n\t\t{\r\n\t\t\t// National Prefix not needed for this number.\r\n\t\t\treturn true\r\n\t\t}\r\n\r\n\t\treturn Boolean(phoneNumber.nationalPrefix)\r\n\t}\r\n\r\n\treturn true\r\n}\r\n\r\nexport function containsMoreThanOneSlashInNationalNumber(phoneNumber, candidate)\r\n{\r\n\tconst firstSlashInBodyIndex = candidate.indexOf('/')\r\n\tif (firstSlashInBodyIndex < 0)\r\n\t{\r\n\t\t// No slashes, this is okay.\r\n\t\treturn false\r\n\t}\r\n\r\n\t// Now look for a second one.\r\n\tconst secondSlashInBodyIndex = candidate.indexOf('/', firstSlashInBodyIndex + 1)\r\n\tif (secondSlashInBodyIndex < 0)\r\n\t{\r\n\t\t// Only one slash, this is okay.\r\n\t\treturn false\r\n\t}\r\n\r\n\t// If the first slash is after the country calling code, this is permitted.\r\n\tconst candidateHasCountryCode =\r\n\t\t\tphoneNumber.__countryCallingCodeSource === 'FROM_NUMBER_WITH_PLUS_SIGN' ||\r\n\t\t\tphoneNumber.__countryCallingCodeSource === 'FROM_NUMBER_WITHOUT_PLUS_SIGN'\r\n\r\n\tif (candidateHasCountryCode && parseDigits(candidate.substring(0, firstSlashInBodyIndex)) === phoneNumber.countryCallingCode)\r\n\t{\r\n\t\t// Any more slashes and this is illegal.\r\n\t\treturn candidate.slice(secondSlashInBodyIndex + 1).indexOf('/') >= 0\r\n\t}\r\n\r\n\treturn true\r\n}\r\n\r\nfunction checkNumberGroupingIsValid(\r\n\tnumber,\r\n\tcandidate,\r\n\tmetadata,\r\n\tcheckGroups,\r\n\tregExpCache\r\n) {\r\n\tthrow new Error('This part of code hasn\\'t been ported')\r\n\r\n\tconst normalizedCandidate = normalizeDigits(candidate, true /* keep non-digits */)\r\n\tlet formattedNumberGroups = getNationalNumberGroups(metadata, number, null)\r\n\tif (checkGroups(metadata, number, normalizedCandidate, formattedNumberGroups)) {\r\n\t\treturn true\r\n\t}\r\n\r\n\t// If this didn't pass, see if there are any alternate formats that match, and try them instead.\r\n\tconst alternateFormats = MetadataManager.getAlternateFormatsForCountry(number.getCountryCode())\r\n\tconst nationalSignificantNumber = util.getNationalSignificantNumber(number)\r\n\r\n\tif (alternateFormats) {\r\n\t\tfor (const alternateFormat of alternateFormats.numberFormats()) {\r\n\t\t\tif (alternateFormat.leadingDigitsPatterns().length > 0) {\r\n\t\t\t\t// There is only one leading digits pattern for alternate formats.\r\n\t\t\t\tconst leadingDigitsRegExp = regExpCache.getPatternForRegExp('^' + alternateFormat.leadingDigitsPatterns()[0])\r\n\t\t\t\tif (!leadingDigitsRegExp.test(nationalSignificantNumber)) {\r\n\t\t\t\t\t// Leading digits don't match; try another one.\r\n\t\t\t\t\tcontinue\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tformattedNumberGroups = getNationalNumberGroups(metadata, number, alternateFormat)\r\n\t\t\tif (checkGroups(metadata, number, normalizedCandidate, formattedNumberGroups)) {\r\n\t\t\t\treturn true\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\treturn false\r\n}\r\n\r\n/**\r\n * Helper method to get the national-number part of a number, formatted without any national\r\n * prefix, and return it as a set of digit blocks that would be formatted together following\r\n * standard formatting rules.\r\n */\r\nfunction getNationalNumberGroups(\r\n\tmetadata,\r\n\tnumber,\r\n\tformattingPattern\r\n) {\r\n\tthrow new Error('This part of code hasn\\'t been ported')\r\n\r\n\tif (formattingPattern) {\r\n\t\t// We format the NSN only, and split that according to the separator.\r\n\t\tconst nationalSignificantNumber = util.getNationalSignificantNumber(number)\r\n\t\treturn util.formatNsnUsingPattern(nationalSignificantNumber,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tformattingPattern, 'RFC3966', metadata).split('-')\r\n\t}\r\n\r\n\t// This will be in the format +CC-DG1-DG2-DGX;ext=EXT where DG1..DGX represents groups of digits.\r\n\tconst rfc3966Format = formatNumber(number, 'RFC3966', metadata)\r\n\r\n\t// We remove the extension part from the formatted string before splitting it into different\r\n\t// groups.\r\n\tlet endIndex = rfc3966Format.indexOf(';')\r\n\tif (endIndex < 0) {\r\n\t\tendIndex = rfc3966Format.length\r\n\t}\r\n\r\n\t// The country-code will have a '-' following it.\r\n\tconst startIndex = rfc3966Format.indexOf('-') + 1\r\n\treturn rfc3966Format.slice(startIndex, endIndex).split('-')\r\n}\r\n\r\nfunction allNumberGroupsAreExactlyPresent\r\n(\r\n\tmetadata,\r\n\tnumber,\r\n\tnormalizedCandidate,\r\n\tformattedNumberGroups\r\n)\r\n{\r\n\tthrow new Error('This part of code hasn\\'t been ported')\r\n\r\n\tconst candidateGroups = normalizedCandidate.split(NON_DIGITS_PATTERN)\r\n\r\n\t// Set this to the last group, skipping it if the number has an extension.\r\n\tlet candidateNumberGroupIndex =\r\n\t\t\tnumber.hasExtension() ? candidateGroups.length - 2 : candidateGroups.length - 1\r\n\r\n\t// First we check if the national significant number is formatted as a block.\r\n\t// We use contains and not equals, since the national significant number may be present with\r\n\t// a prefix such as a national number prefix, or the country code itself.\r\n\tif (candidateGroups.length == 1\r\n\t\t\t|| candidateGroups[candidateNumberGroupIndex].contains(\r\n\t\t\t\t\tutil.getNationalSignificantNumber(number)))\r\n\t{\r\n\t\treturn true\r\n\t}\r\n\r\n\t// Starting from the end, go through in reverse, excluding the first group, and check the\r\n\t// candidate and number groups are the same.\r\n\tlet formattedNumberGroupIndex = (formattedNumberGroups.length - 1)\r\n\twhile (formattedNumberGroupIndex > 0 && candidateNumberGroupIndex >= 0)\r\n\t{\r\n\t\tif (candidateGroups[candidateNumberGroupIndex] !== formattedNumberGroups[formattedNumberGroupIndex])\r\n\t\t{\r\n\t\t\treturn false\r\n\t\t}\r\n\t\tformattedNumberGroupIndex--\r\n\t\tcandidateNumberGroupIndex--\r\n\t}\r\n\r\n\t// Now check the first group. There may be a national prefix at the start, so we only check\r\n\t// that the candidate group ends with the formatted number group.\r\n\treturn (candidateNumberGroupIndex >= 0\r\n\t\t\t&& endsWith(candidateGroups[candidateNumberGroupIndex], formattedNumberGroups[0]))\r\n}\r\n\r\n\r\nfunction allNumberGroupsRemainGrouped\r\n(\r\n\tmetadata,\r\n\tnumber,\r\n\tnormalizedCandidate,\r\n\tformattedNumberGroups\r\n)\r\n{\r\n\tthrow new Error('This part of code hasn\\'t been ported')\r\n\r\n\tlet fromIndex = 0\r\n\tif (number.getCountryCodeSource() !== CountryCodeSource.FROM_DEFAULT_COUNTRY)\r\n\t{\r\n\t\t// First skip the country code if the normalized candidate contained it.\r\n\t\tconst countryCode = String(number.getCountryCode())\r\n\t\tfromIndex = normalizedCandidate.indexOf(countryCode) + countryCode.length()\r\n\t}\r\n\r\n\t// Check each group of consecutive digits are not broken into separate groupings in the\r\n\t// {@code normalizedCandidate} string.\r\n\tfor (let i = 0; i < formattedNumberGroups.length; i++)\r\n\t{\r\n\t\t// Fails if the substring of {@code normalizedCandidate} starting from {@code fromIndex}\r\n\t\t// doesn't contain the consecutive digits in formattedNumberGroups[i].\r\n\t\tfromIndex = normalizedCandidate.indexOf(formattedNumberGroups[i], fromIndex)\r\n\t\tif (fromIndex < 0) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\t// Moves {@code fromIndex} forward.\r\n\t\tfromIndex += formattedNumberGroups[i].length()\r\n\t\tif (i == 0 && fromIndex < normalizedCandidate.length())\r\n\t\t{\r\n\t\t\t// We are at the position right after the NDC. We get the region used for formatting\r\n\t\t\t// information based on the country code in the phone number, rather than the number itself,\r\n\t\t\t// as we do not need to distinguish between different countries with the same country\r\n\t\t\t// calling code and this is faster.\r\n\t\t\tconst region = util.getRegionCodeForCountryCode(number.getCountryCode())\r\n\t\t\tif (util.getNddPrefixForRegion(region, true) != null\r\n\t\t\t\t\t&& Character.isDigit(normalizedCandidate.charAt(fromIndex))) {\r\n\t\t\t\t// This means there is no formatting symbol after the NDC. In this case, we only\r\n\t\t\t\t// accept the number if there is no formatting symbol at all in the number, except\r\n\t\t\t\t// for extensions. This is only important for countries with national prefixes.\r\n\t\t\t\tconst nationalSignificantNumber = util.getNationalSignificantNumber(number)\r\n\t\t\t\treturn startsWith\r\n\t\t\t\t(\r\n\t\t\t\t\tnormalizedCandidate.slice(fromIndex - formattedNumberGroups[i].length),\r\n\t\t\t\t\t nationalSignificantNumber\r\n\t\t\t\t)\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// The check here makes sure that we haven't mistakenly already used the extension to\r\n\t// match the last group of the subscriber number. Note the extension cannot have\r\n\t// formatting in-between digits.\r\n\treturn normalizedCandidate.slice(fromIndex).contains(number.getExtension())\r\n}"],"mappings":"AAAA,OAAOA,WAAW,MAAM,2BAA2B;AACnD,OAAOC,wCAAwC,MAAM,+CAA+C;AACpG,OAAOC,QAAQ,MAAM,gBAAgB;AACrC,OAAOC,uBAAuB,MAAM,uCAAuC;AAC3E,SAASC,qBAAqB,QAAQ,cAAc;AAEpD,SACCC,UAAU,EACVC,QAAQ,QACF,WAAW;;AAElB;AACA;AACA;AACA;AACA,eACA;EACC;AACD;AACA;EACCC,QAAQA,CAACC,WAAW,EAAE;IAAEC,SAAS;IAAEC;EAAS,CAAC,EAC7C;IACC,OAAO,IAAI;EACZ,CAAC;EAED;AACD;AACA;AACA;AACA;EACCC,KAAKA,CAACH,WAAW,EAAE;IAAEC,SAAS;IAAEG,cAAc;IAAEF;EAAS,CAAC,EAC1D;IACC,IACC,CAACF,WAAW,CAACK,OAAO,CAAC,CAAC,IACtB,CAACC,uBAAuB,CAACN,WAAW,EAAEC,SAAS,EAAEC,QAAQ,CAAC,EAE3D;MACC,OAAO,KAAK;IACb;;IAEA;IACA;IACA,OAAO,IAAI;EACZ,CAAC;EAED;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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,SAAS,CAAC;IAC5E,IAAIA,SAAS,GAAG,CAAC,EAAE;MAClB,OAAO,KAAK;IACb;IACA;IACAA,SAAS,IAAI5B,qBAAqB,CAACkC,CAAC,CAAC,CAACjE,MAAM,CAAC,CAAC;IAC9C,IAAIiE,CAAC,IAAI,CAAC,IAAIN,SAAS,GAAG9B,mBAAmB,CAAC7B,MAAM,CAAC,CAAC,EACtD;MACC;MACA;MACA;MACA;MACA,MAAMkE,MAAM,GAAG5B,IAAI,CAAC6B,2BAA2B,CAACzC,MAAM,CAACU,cAAc,CAAC,CAAC,CAAC;MACxE,IAAIE,IAAI,CAAC8B,qBAAqB,CAACF,MAAM,EAAE,IAAI,CAAC,IAAI,IAAI,IAC/CG,SAAS,CAACC,OAAO,CAACzC,mBAAmB,CAAC3B,MAAM,CAACyD,SAAS,CAAC,CAAC,EAAE;QAC9D;QACA;QACA;QACA,MAAMtB,yBAAyB,GAAGC,IAAI,CAACC,4BAA4B,CAACb,MAAM,CAAC;QAC3E,OAAO7C,UAAU,CAEhBgD,mBAAmB,CAACJ,KAAK,CAACkC,SAAS,GAAG5B,qBAAqB,CAACkC,CAAC,CAAC,CAACjE,MAAM,CAAC,EACrEqC,yBACF,CAAC;MACF;IACD;EACD;;EAEA;EACA;EACA;EACA,OAAOR,mBAAmB,CAACJ,KAAK,CAACkC,SAAS,CAAC,CAACF,QAAQ,CAAC/B,MAAM,CAAC6C,YAAY,CAAC,CAAC,CAAC;AAC5E","ignoreList":[]}
@@ -0,0 +1,20 @@
1
+ import LRUCache from './LRUCache.js';
2
+
3
+ // A cache for frequently used country-specific regular expressions. Set to 32 to cover ~2-3
4
+ // countries being used for the same doc with ~10 patterns for each country. Some pages will have
5
+ // a lot more countries in use, but typically fewer numbers for each so expanding the cache for
6
+ // that use-case won't have a lot of benefit.
7
+ export default class RegExpCache {
8
+ constructor(size) {
9
+ this.cache = new LRUCache(size);
10
+ }
11
+ getPatternForRegExp(pattern) {
12
+ let regExp = this.cache.get(pattern);
13
+ if (!regExp) {
14
+ regExp = new RegExp('^' + pattern);
15
+ this.cache.put(pattern, regExp);
16
+ }
17
+ return regExp;
18
+ }
19
+ }
20
+ //# sourceMappingURL=RegExpCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RegExpCache.js","names":["LRUCache","RegExpCache","constructor","size","cache","getPatternForRegExp","pattern","regExp","get","RegExp","put"],"sources":["../../source/findNumbers/RegExpCache.js"],"sourcesContent":["import LRUCache from './LRUCache.js'\r\n\r\n// A cache for frequently used country-specific regular expressions. Set to 32 to cover ~2-3\r\n// countries being used for the same doc with ~10 patterns for each country. Some pages will have\r\n// a lot more countries in use, but typically fewer numbers for each so expanding the cache for\r\n// that use-case won't have a lot of benefit.\r\nexport default class RegExpCache {\r\n\tconstructor(size) {\r\n\t\tthis.cache = new LRUCache(size)\r\n\t}\r\n\r\n\tgetPatternForRegExp(pattern) {\r\n\t\tlet regExp = this.cache.get(pattern)\r\n\t\tif (!regExp) {\r\n\t\t\tregExp = new RegExp('^' + pattern)\r\n\t\t\tthis.cache.put(pattern, regExp)\r\n\t\t}\r\n\t\treturn regExp\r\n\t}\r\n}"],"mappings":"AAAA,OAAOA,QAAQ,MAAM,eAAe;;AAEpC;AACA;AACA;AACA;AACA,eAAe,MAAMC,WAAW,CAAC;EAChCC,WAAWA,CAACC,IAAI,EAAE;IACjB,IAAI,CAACC,KAAK,GAAG,IAAIJ,QAAQ,CAACG,IAAI,CAAC;EAChC;EAEAE,mBAAmBA,CAACC,OAAO,EAAE;IAC5B,IAAIC,MAAM,GAAG,IAAI,CAACH,KAAK,CAACI,GAAG,CAACF,OAAO,CAAC;IACpC,IAAI,CAACC,MAAM,EAAE;MACZA,MAAM,GAAG,IAAIE,MAAM,CAAC,GAAG,GAAGH,OAAO,CAAC;MAClC,IAAI,CAACF,KAAK,CAACM,GAAG,CAACJ,OAAO,EAAEC,MAAM,CAAC;IAChC;IACA,OAAOA,MAAM;EACd;AACD","ignoreList":[]}
@@ -0,0 +1,66 @@
1
+ // Copy-pasted from `PhoneNumberMatcher.js`.
2
+
3
+ import { PLUS_CHARS } from '../constants.js';
4
+ import { limit } from './util.js';
5
+ import { isLatinLetter, isInvalidPunctuationSymbol } from './utf-8.js';
6
+ const OPENING_PARENS = '(\\[\uFF08\uFF3B';
7
+ const CLOSING_PARENS = ')\\]\uFF09\uFF3D';
8
+ const NON_PARENS = `[^${OPENING_PARENS}${CLOSING_PARENS}]`;
9
+ export const LEAD_CLASS = `[${OPENING_PARENS}${PLUS_CHARS}]`;
10
+
11
+ // Punctuation that may be at the start of a phone number - brackets and plus signs.
12
+ const LEAD_CLASS_LEADING = new RegExp('^' + LEAD_CLASS);
13
+
14
+ // Limit on the number of pairs of brackets in a phone number.
15
+ const BRACKET_PAIR_LIMIT = limit(0, 3);
16
+
17
+ /**
18
+ * Pattern to check that brackets match. Opening brackets should be closed within a phone number.
19
+ * This also checks that there is something inside the brackets. Having no brackets at all is also
20
+ * fine.
21
+ *
22
+ * An opening bracket at the beginning may not be closed, but subsequent ones should be. It's
23
+ * also possible that the leading bracket was dropped, so we shouldn't be surprised if we see a
24
+ * closing bracket first. We limit the sets of brackets in a phone number to four.
25
+ */
26
+ const MATCHING_BRACKETS_ENTIRE = new RegExp('^' + "(?:[" + OPENING_PARENS + "])?" + "(?:" + NON_PARENS + "+" + "[" + CLOSING_PARENS + "])?" + NON_PARENS + "+" + "(?:[" + OPENING_PARENS + "]" + NON_PARENS + "+[" + CLOSING_PARENS + "])" + BRACKET_PAIR_LIMIT + NON_PARENS + "*" + '$');
27
+
28
+ /**
29
+ * Matches strings that look like publication pages. Example:
30
+ * <pre>Computing Complete Answers to Queries in the Presence of Limited Access Patterns.
31
+ * Chen Li. VLDB J. 12(3): 211-227 (2003).</pre>
32
+ *
33
+ * The string "211-227 (2003)" is not a telephone number.
34
+ */
35
+ const PUB_PAGES = /\d{1,5}-+\d{1,5}\s{0,4}\(\d{1,4}/;
36
+ export default function isValidCandidate(candidate, offset, text, leniency) {
37
+ // Check the candidate doesn't contain any formatting
38
+ // which would indicate that it really isn't a phone number.
39
+ if (!MATCHING_BRACKETS_ENTIRE.test(candidate) || PUB_PAGES.test(candidate)) {
40
+ return;
41
+ }
42
+
43
+ // If leniency is set to VALID or stricter, we also want to skip numbers that are surrounded
44
+ // by Latin alphabetic characters, to skip cases like abc8005001234 or 8005001234def.
45
+ if (leniency !== 'POSSIBLE') {
46
+ // If the candidate is not at the start of the text,
47
+ // and does not start with phone-number punctuation,
48
+ // check the previous character.
49
+ if (offset > 0 && !LEAD_CLASS_LEADING.test(candidate)) {
50
+ const previousChar = text[offset - 1];
51
+ // We return null if it is a latin letter or an invalid punctuation symbol.
52
+ if (isInvalidPunctuationSymbol(previousChar) || isLatinLetter(previousChar)) {
53
+ return false;
54
+ }
55
+ }
56
+ const lastCharIndex = offset + candidate.length;
57
+ if (lastCharIndex < text.length) {
58
+ const nextChar = text[lastCharIndex];
59
+ if (isInvalidPunctuationSymbol(nextChar) || isLatinLetter(nextChar)) {
60
+ return false;
61
+ }
62
+ }
63
+ }
64
+ return true;
65
+ }
66
+ //# sourceMappingURL=isValidCandidate.js.map