libphonenumber-js 1.12.9 → 1.12.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (569) hide show
  1. package/CODE_OF_CONDUCT.md +78 -78
  2. package/README.md +2 -3
  3. package/build/AsYouType.js +69 -131
  4. package/build/AsYouType.js.map +1 -1
  5. package/build/AsYouType.test.js +610 -553
  6. package/build/AsYouType.test.js.map +1 -1
  7. package/build/AsYouTypeFormatter.PatternMatcher.js +29 -77
  8. package/build/AsYouTypeFormatter.PatternMatcher.js.map +1 -1
  9. package/build/AsYouTypeFormatter.PatternMatcher.test.js +107 -109
  10. package/build/AsYouTypeFormatter.PatternMatcher.test.js.map +1 -1
  11. package/build/AsYouTypeFormatter.PatternParser.js +34 -67
  12. package/build/AsYouTypeFormatter.PatternParser.js.map +1 -1
  13. package/build/AsYouTypeFormatter.PatternParser.test.js +7 -9
  14. package/build/AsYouTypeFormatter.PatternParser.test.js.map +1 -1
  15. package/build/AsYouTypeFormatter.complete.js +18 -28
  16. package/build/AsYouTypeFormatter.complete.js.map +1 -1
  17. package/build/AsYouTypeFormatter.js +193 -233
  18. package/build/AsYouTypeFormatter.js.map +1 -1
  19. package/build/AsYouTypeFormatter.util.js +11 -38
  20. package/build/AsYouTypeFormatter.util.js.map +1 -1
  21. package/build/AsYouTypeFormatter.util.test.js +6 -7
  22. package/build/AsYouTypeFormatter.util.test.js.map +1 -1
  23. package/build/AsYouTypeParser.js +89 -143
  24. package/build/AsYouTypeParser.js.map +1 -1
  25. package/build/AsYouTypeState.js +13 -23
  26. package/build/AsYouTypeState.js.map +1 -1
  27. package/build/ParseError.js +22 -43
  28. package/build/ParseError.js.map +1 -1
  29. package/build/PhoneNumber.js +46 -85
  30. package/build/PhoneNumber.js.map +1 -1
  31. package/build/PhoneNumber.test.js +41 -33
  32. package/build/PhoneNumber.test.js.map +1 -1
  33. package/build/PhoneNumberMatcher.js +67 -101
  34. package/build/PhoneNumberMatcher.js.map +1 -1
  35. package/build/PhoneNumberMatcher.test.js +35 -18
  36. package/build/PhoneNumberMatcher.test.js.map +1 -1
  37. package/build/constants.js +17 -19
  38. package/build/constants.js.map +1 -1
  39. package/build/findNumbers/LRUCache.js +23 -34
  40. package/build/findNumbers/LRUCache.js.map +1 -1
  41. package/build/findNumbers/Leniency.js +58 -114
  42. package/build/findNumbers/Leniency.js.map +1 -1
  43. package/build/findNumbers/RegExpCache.js +9 -20
  44. package/build/findNumbers/RegExpCache.js.map +1 -1
  45. package/build/findNumbers/isValidCandidate.js +12 -19
  46. package/build/findNumbers/isValidCandidate.js.map +1 -1
  47. package/build/findNumbers/isValidPreCandidate.js +5 -7
  48. package/build/findNumbers/isValidPreCandidate.js.map +1 -1
  49. package/build/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js +9 -15
  50. package/build/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js.map +1 -1
  51. package/build/findNumbers/parsePreCandidate.js +0 -3
  52. package/build/findNumbers/parsePreCandidate.js.map +1 -1
  53. package/build/findNumbers/utf-8.js +9 -13
  54. package/build/findNumbers/utf-8.js.map +1 -1
  55. package/build/findNumbers/util.js +1 -8
  56. package/build/findNumbers/util.js.map +1 -1
  57. package/build/findNumbers/util.test.js +9 -15
  58. package/build/findNumbers/util.test.js.map +1 -1
  59. package/build/findPhoneNumbersInText.js +10 -17
  60. package/build/findPhoneNumbersInText.js.map +1 -1
  61. package/build/findPhoneNumbersInText.test.js +100 -93
  62. package/build/findPhoneNumbersInText.test.js.map +1 -1
  63. package/build/format.js +31 -64
  64. package/build/format.js.map +1 -1
  65. package/build/format.test.js +133 -119
  66. package/build/format.test.js.map +1 -1
  67. package/build/formatIncompletePhoneNumber.js +1 -5
  68. package/build/formatIncompletePhoneNumber.js.map +1 -1
  69. package/build/formatIncompletePhoneNumber.test.js +14 -13
  70. package/build/formatIncompletePhoneNumber.test.js.map +1 -1
  71. package/build/formatPhoneNumberForMobileDialing.js +32 -32
  72. package/build/formatPhoneNumberForMobileDialing.js.map +1 -1
  73. package/build/getCountries.js +1 -4
  74. package/build/getCountries.js.map +1 -1
  75. package/build/getCountries.test.js +2 -5
  76. package/build/getCountries.test.js.map +1 -1
  77. package/build/getCountryCallingCode.js +0 -1
  78. package/build/getCountryCallingCode.js.map +1 -1
  79. package/build/getCountryCallingCode.test.js +2 -5
  80. package/build/getCountryCallingCode.test.js.map +1 -1
  81. package/build/getExampleNumber.js +1 -4
  82. package/build/getExampleNumber.js.map +1 -1
  83. package/build/getExampleNumber.test.js +5 -9
  84. package/build/getExampleNumber.test.js.map +1 -1
  85. package/build/helpers/RFC3966.js +16 -38
  86. package/build/helpers/RFC3966.js.map +1 -1
  87. package/build/helpers/RFC3966.test.js +16 -14
  88. package/build/helpers/RFC3966.test.js.map +1 -1
  89. package/build/helpers/applyInternationalSeparatorStyle.js +0 -2
  90. package/build/helpers/applyInternationalSeparatorStyle.js.map +1 -1
  91. package/build/helpers/applyInternationalSeparatorStyle.test.js +3 -5
  92. package/build/helpers/applyInternationalSeparatorStyle.test.js.map +1 -1
  93. package/build/helpers/checkNumberLength.js +18 -22
  94. package/build/helpers/checkNumberLength.js.map +1 -1
  95. package/build/helpers/checkNumberLength.test.js +19 -27
  96. package/build/helpers/checkNumberLength.test.js.map +1 -1
  97. package/build/helpers/extension/createExtensionPattern.js +19 -35
  98. package/build/helpers/extension/createExtensionPattern.js.map +1 -1
  99. package/build/helpers/extension/extractExtension.js +6 -12
  100. package/build/helpers/extension/extractExtension.js.map +1 -1
  101. package/build/helpers/extractCountryCallingCode.js +14 -24
  102. package/build/helpers/extractCountryCallingCode.js.map +1 -1
  103. package/build/helpers/extractCountryCallingCode.test.js +4 -7
  104. package/build/helpers/extractCountryCallingCode.test.js.map +1 -1
  105. package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +4 -16
  106. package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -1
  107. package/build/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js +16 -29
  108. package/build/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js.map +1 -1
  109. package/build/helpers/extractNationalNumber.js +10 -21
  110. package/build/helpers/extractNationalNumber.js.map +1 -1
  111. package/build/helpers/extractNationalNumber.test.js +2 -8
  112. package/build/helpers/extractNationalNumber.test.js.map +1 -1
  113. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +12 -18
  114. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -1
  115. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +2 -6
  116. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js.map +1 -1
  117. package/build/helpers/extractPhoneContext.js +19 -28
  118. package/build/helpers/extractPhoneContext.js.map +1 -1
  119. package/build/helpers/extractPhoneContext.test.js +12 -15
  120. package/build/helpers/extractPhoneContext.test.js.map +1 -1
  121. package/build/helpers/formatNationalNumberUsingFormat.js +7 -13
  122. package/build/helpers/formatNationalNumberUsingFormat.js.map +1 -1
  123. package/build/helpers/getCountryByCallingCode.js +5 -14
  124. package/build/helpers/getCountryByCallingCode.js.map +1 -1
  125. package/build/helpers/getCountryByNationalNumber.js +18 -20
  126. package/build/helpers/getCountryByNationalNumber.js.map +1 -1
  127. package/build/helpers/getIddPrefix.js +4 -8
  128. package/build/helpers/getIddPrefix.js.map +1 -1
  129. package/build/helpers/getNumberType.js +23 -35
  130. package/build/helpers/getNumberType.js.map +1 -1
  131. package/build/helpers/getNumberType.test.js +4 -8
  132. package/build/helpers/getNumberType.test.js.map +1 -1
  133. package/build/helpers/getPossibleCountriesForNumber.js +1 -11
  134. package/build/helpers/getPossibleCountriesForNumber.js.map +1 -1
  135. package/build/helpers/isObject.js +0 -1
  136. package/build/helpers/isObject.js.map +1 -1
  137. package/build/helpers/isViablePhoneNumber.js +19 -19
  138. package/build/helpers/isViablePhoneNumber.js.map +1 -1
  139. package/build/helpers/matchesEntirely.js +0 -1
  140. package/build/helpers/matchesEntirely.js.map +1 -1
  141. package/build/helpers/matchesEntirely.test.js +4 -5
  142. package/build/helpers/matchesEntirely.test.js.map +1 -1
  143. package/build/helpers/mergeArrays.js +6 -11
  144. package/build/helpers/mergeArrays.js.map +1 -1
  145. package/build/helpers/mergeArrays.test.js +2 -4
  146. package/build/helpers/mergeArrays.test.js.map +1 -1
  147. package/build/helpers/parseDigits.js +7 -17
  148. package/build/helpers/parseDigits.js.map +1 -1
  149. package/build/helpers/parseDigits.test.js +2 -4
  150. package/build/helpers/parseDigits.test.js.map +1 -1
  151. package/build/helpers/stripIddPrefix.js +7 -17
  152. package/build/helpers/stripIddPrefix.js.map +1 -1
  153. package/build/helpers/stripIddPrefix.test.js +4 -7
  154. package/build/helpers/stripIddPrefix.test.js.map +1 -1
  155. package/build/isPossible.js +3 -15
  156. package/build/isPossible.js.map +1 -1
  157. package/build/isPossible.test.js +34 -41
  158. package/build/isPossible.test.js.map +1 -1
  159. package/build/isPossiblePhoneNumber.js +10 -15
  160. package/build/isPossiblePhoneNumber.js.map +1 -1
  161. package/build/isPossiblePhoneNumber.test.js +11 -17
  162. package/build/isPossiblePhoneNumber.test.js.map +1 -1
  163. package/build/isValid.js +7 -11
  164. package/build/isValid.js.map +1 -1
  165. package/build/isValid.test.js +59 -58
  166. package/build/isValid.test.js.map +1 -1
  167. package/build/isValidPhoneNumber.js +10 -15
  168. package/build/isValidPhoneNumber.js.map +1 -1
  169. package/build/isValidPhoneNumber.test.js +10 -15
  170. package/build/isValidPhoneNumber.test.js.map +1 -1
  171. package/build/legacy/findNumbers.js +4 -11
  172. package/build/legacy/findNumbers.js.map +1 -1
  173. package/build/legacy/findNumbers.test.js +77 -63
  174. package/build/legacy/findNumbers.test.js.map +1 -1
  175. package/build/legacy/findPhoneNumbers.js +11 -21
  176. package/build/legacy/findPhoneNumbers.js.map +1 -1
  177. package/build/legacy/findPhoneNumbers.test.js +75 -72
  178. package/build/legacy/findPhoneNumbers.test.js.map +1 -1
  179. package/build/legacy/findPhoneNumbersInitialImplementation.js +34 -62
  180. package/build/legacy/findPhoneNumbersInitialImplementation.js.map +1 -1
  181. package/build/legacy/format.js +28 -44
  182. package/build/legacy/format.js.map +1 -1
  183. package/build/legacy/format.test.js +119 -103
  184. package/build/legacy/format.test.js.map +1 -1
  185. package/build/legacy/getNumberType.js +30 -44
  186. package/build/legacy/getNumberType.js.map +1 -1
  187. package/build/legacy/getNumberType.test.js +31 -34
  188. package/build/legacy/getNumberType.test.js.map +1 -1
  189. package/build/legacy/isPossibleNumber.js +5 -11
  190. package/build/legacy/isPossibleNumber.js.map +1 -1
  191. package/build/legacy/isPossibleNumber.test.js +22 -25
  192. package/build/legacy/isPossibleNumber.test.js.map +1 -1
  193. package/build/legacy/isValidNumber.js +5 -11
  194. package/build/legacy/isValidNumber.js.map +1 -1
  195. package/build/legacy/isValidNumber.test.js +41 -39
  196. package/build/legacy/isValidNumber.test.js.map +1 -1
  197. package/build/legacy/isValidNumberForRegion.js +4 -12
  198. package/build/legacy/isValidNumberForRegion.js.map +1 -1
  199. package/build/legacy/isValidNumberForRegion.test.js +6 -11
  200. package/build/legacy/isValidNumberForRegion.test.js.map +1 -1
  201. package/build/legacy/isValidNumberForRegion_.js +1 -4
  202. package/build/legacy/isValidNumberForRegion_.js.map +1 -1
  203. package/build/legacy/parse.js +4 -9
  204. package/build/legacy/parse.js.map +1 -1
  205. package/build/legacy/parse.test.js +233 -194
  206. package/build/legacy/parse.test.js.map +1 -1
  207. package/build/legacy/searchNumbers.js +8 -12
  208. package/build/legacy/searchNumbers.js.map +1 -1
  209. package/build/legacy/searchNumbers.test.js +6 -14
  210. package/build/legacy/searchNumbers.test.js.map +1 -1
  211. package/build/metadata.js +85 -122
  212. package/build/metadata.js.map +1 -1
  213. package/build/metadata.test.js +54 -80
  214. package/build/metadata.test.js.map +1 -1
  215. package/build/normalizeArguments.js +25 -35
  216. package/build/normalizeArguments.js.map +1 -1
  217. package/build/parse.js +66 -116
  218. package/build/parse.js.map +1 -1
  219. package/build/parse.test.js +244 -206
  220. package/build/parse.test.js.map +1 -1
  221. package/build/parseIncompletePhoneNumber.js +8 -18
  222. package/build/parseIncompletePhoneNumber.js.map +1 -1
  223. package/build/parseIncompletePhoneNumber.test.js +24 -25
  224. package/build/parseIncompletePhoneNumber.test.js.map +1 -1
  225. package/build/parsePhoneNumber.js +4 -9
  226. package/build/parsePhoneNumber.js.map +1 -1
  227. package/build/parsePhoneNumber.test.js +14 -25
  228. package/build/parsePhoneNumber.test.js.map +1 -1
  229. package/build/parsePhoneNumberWithError.js +4 -9
  230. package/build/parsePhoneNumberWithError.js.map +1 -1
  231. package/build/parsePhoneNumberWithError.test.js +31 -35
  232. package/build/parsePhoneNumberWithError.test.js.map +1 -1
  233. package/build/parsePhoneNumberWithError_.js +7 -10
  234. package/build/parsePhoneNumberWithError_.js.map +1 -1
  235. package/build/parsePhoneNumber_.js +11 -16
  236. package/build/parsePhoneNumber_.js.map +1 -1
  237. package/build/searchPhoneNumbersInText.js +10 -16
  238. package/build/searchPhoneNumbersInText.js.map +1 -1
  239. package/build/searchPhoneNumbersInText.test.js +11 -21
  240. package/build/searchPhoneNumbersInText.test.js.map +1 -1
  241. package/build/tools/semver-compare.js +0 -4
  242. package/build/tools/semver-compare.js.map +1 -1
  243. package/build/tools/semver-compare.test.js +2 -4
  244. package/build/tools/semver-compare.test.js.map +1 -1
  245. package/build/validatePhoneNumberLength.js +12 -20
  246. package/build/validatePhoneNumberLength.js.map +1 -1
  247. package/build/validatePhoneNumberLength.test.js +14 -16
  248. package/build/validatePhoneNumberLength.test.js.map +1 -1
  249. package/bundle/libphonenumber-js.min.js +1 -1
  250. package/bundle/libphonenumber-js.min.js.map +1 -1
  251. package/bundle/libphonenumber-max.js +1 -1
  252. package/bundle/libphonenumber-max.js.map +1 -1
  253. package/bundle/libphonenumber-min.js +1 -1
  254. package/bundle/libphonenumber-min.js.map +1 -1
  255. package/bundle/libphonenumber-mobile.js +1 -1
  256. package/bundle/libphonenumber-mobile.js.map +1 -1
  257. package/es6/AsYouType.js +66 -112
  258. package/es6/AsYouType.js.map +1 -1
  259. package/es6/AsYouType.test.js +610 -551
  260. package/es6/AsYouType.test.js.map +1 -1
  261. package/es6/AsYouTypeFormatter.PatternMatcher.js +27 -72
  262. package/es6/AsYouTypeFormatter.PatternMatcher.js.map +1 -1
  263. package/es6/AsYouTypeFormatter.PatternMatcher.test.js +106 -106
  264. package/es6/AsYouTypeFormatter.PatternMatcher.test.js.map +1 -1
  265. package/es6/AsYouTypeFormatter.PatternParser.js +33 -64
  266. package/es6/AsYouTypeFormatter.PatternParser.js.map +1 -1
  267. package/es6/AsYouTypeFormatter.PatternParser.test.js +6 -6
  268. package/es6/AsYouTypeFormatter.PatternParser.test.js.map +1 -1
  269. package/es6/AsYouTypeFormatter.complete.js +17 -21
  270. package/es6/AsYouTypeFormatter.complete.js.map +1 -1
  271. package/es6/AsYouTypeFormatter.js +193 -217
  272. package/es6/AsYouTypeFormatter.js.map +1 -1
  273. package/es6/AsYouTypeFormatter.util.js +10 -30
  274. package/es6/AsYouTypeFormatter.util.js.map +1 -1
  275. package/es6/AsYouTypeFormatter.util.test.js +6 -6
  276. package/es6/AsYouTypeFormatter.util.test.js.map +1 -1
  277. package/es6/AsYouTypeParser.js +87 -132
  278. package/es6/AsYouTypeParser.js.map +1 -1
  279. package/es6/AsYouTypeState.js +12 -20
  280. package/es6/AsYouTypeState.js.map +1 -1
  281. package/es6/ParseError.js +21 -40
  282. package/es6/ParseError.js.map +1 -1
  283. package/es6/PhoneNumber.js +45 -68
  284. package/es6/PhoneNumber.js.map +1 -1
  285. package/es6/PhoneNumber.test.js +41 -30
  286. package/es6/PhoneNumber.test.js.map +1 -1
  287. package/es6/PhoneNumberMatcher.js +61 -78
  288. package/es6/PhoneNumberMatcher.js.map +1 -1
  289. package/es6/PhoneNumberMatcher.test.js +35 -16
  290. package/es6/PhoneNumberMatcher.test.js.map +1 -1
  291. package/es6/constants.js +15 -9
  292. package/es6/constants.js.map +1 -1
  293. package/es6/findNumbers/LRUCache.js +22 -31
  294. package/es6/findNumbers/LRUCache.js.map +1 -1
  295. package/es6/findNumbers/Leniency.js +57 -103
  296. package/es6/findNumbers/Leniency.js.map +1 -1
  297. package/es6/findNumbers/RegExpCache.js +10 -16
  298. package/es6/findNumbers/RegExpCache.js.map +1 -1
  299. package/es6/findNumbers/isValidCandidate.js +12 -13
  300. package/es6/findNumbers/isValidCandidate.js.map +1 -1
  301. package/es6/findNumbers/isValidPreCandidate.js +5 -6
  302. package/es6/findNumbers/isValidPreCandidate.js.map +1 -1
  303. package/es6/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js +9 -12
  304. package/es6/findNumbers/matchPhoneNumberStringAgainstPhoneNumber.js.map +1 -1
  305. package/es6/findNumbers/parsePreCandidate.js +3 -2
  306. package/es6/findNumbers/parsePreCandidate.js.map +1 -1
  307. package/es6/findNumbers/utf-8.js +5 -3
  308. package/es6/findNumbers/utf-8.js.map +1 -1
  309. package/es6/findNumbers/util.js +1 -4
  310. package/es6/findNumbers/util.js.map +1 -1
  311. package/es6/findNumbers/util.test.js +9 -14
  312. package/es6/findNumbers/util.test.js.map +1 -1
  313. package/es6/findPhoneNumbersInText.js +9 -12
  314. package/es6/findPhoneNumbersInText.js.map +1 -1
  315. package/es6/findPhoneNumbersInText.test.js +101 -91
  316. package/es6/findPhoneNumbersInText.test.js.map +1 -1
  317. package/es6/format.js +27 -50
  318. package/es6/format.js.map +1 -1
  319. package/es6/format.test.js +133 -116
  320. package/es6/format.test.js.map +1 -1
  321. package/es6/formatIncompletePhoneNumber.js +1 -2
  322. package/es6/formatIncompletePhoneNumber.js.map +1 -1
  323. package/es6/formatIncompletePhoneNumber.test.js +14 -10
  324. package/es6/formatIncompletePhoneNumber.test.js.map +1 -1
  325. package/es6/formatPhoneNumberForMobileDialing.js +31 -24
  326. package/es6/formatPhoneNumberForMobileDialing.js.map +1 -1
  327. package/es6/getCountries.js.map +1 -1
  328. package/es6/getCountries.test.js +2 -2
  329. package/es6/getCountries.test.js.map +1 -1
  330. package/es6/getCountryCallingCode.js.map +1 -1
  331. package/es6/getCountryCallingCode.test.js +2 -2
  332. package/es6/getCountryCallingCode.test.js.map +1 -1
  333. package/es6/getExampleNumber.js.map +1 -1
  334. package/es6/getExampleNumber.test.js +6 -6
  335. package/es6/getExampleNumber.test.js.map +1 -1
  336. package/es6/helpers/RFC3966.js +17 -34
  337. package/es6/helpers/RFC3966.js.map +1 -1
  338. package/es6/helpers/RFC3966.test.js +16 -13
  339. package/es6/helpers/RFC3966.test.js.map +1 -1
  340. package/es6/helpers/applyInternationalSeparatorStyle.js +3 -2
  341. package/es6/helpers/applyInternationalSeparatorStyle.js.map +1 -1
  342. package/es6/helpers/applyInternationalSeparatorStyle.test.js +2 -2
  343. package/es6/helpers/applyInternationalSeparatorStyle.test.js.map +1 -1
  344. package/es6/helpers/checkNumberLength.js +17 -17
  345. package/es6/helpers/checkNumberLength.js.map +1 -1
  346. package/es6/helpers/checkNumberLength.test.js +20 -23
  347. package/es6/helpers/checkNumberLength.test.js.map +1 -1
  348. package/es6/helpers/extension/createExtensionPattern.js +21 -34
  349. package/es6/helpers/extension/createExtensionPattern.js.map +1 -1
  350. package/es6/helpers/extension/extractExtension.js +7 -9
  351. package/es6/helpers/extension/extractExtension.js.map +1 -1
  352. package/es6/helpers/extractCountryCallingCode.js +14 -18
  353. package/es6/helpers/extractCountryCallingCode.js.map +1 -1
  354. package/es6/helpers/extractCountryCallingCode.test.js +4 -4
  355. package/es6/helpers/extractCountryCallingCode.test.js.map +1 -1
  356. package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +4 -9
  357. package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -1
  358. package/es6/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js +14 -19
  359. package/es6/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js.map +1 -1
  360. package/es6/helpers/extractNationalNumber.js +10 -15
  361. package/es6/helpers/extractNationalNumber.js.map +1 -1
  362. package/es6/helpers/extractNationalNumber.test.js +2 -4
  363. package/es6/helpers/extractNationalNumber.test.js.map +1 -1
  364. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +12 -17
  365. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -1
  366. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +2 -2
  367. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js.map +1 -1
  368. package/es6/helpers/extractPhoneContext.js +17 -17
  369. package/es6/helpers/extractPhoneContext.js.map +1 -1
  370. package/es6/helpers/extractPhoneContext.test.js +12 -12
  371. package/es6/helpers/extractPhoneContext.test.js.map +1 -1
  372. package/es6/helpers/formatNationalNumberUsingFormat.js +8 -8
  373. package/es6/helpers/formatNationalNumberUsingFormat.js.map +1 -1
  374. package/es6/helpers/getCountryByCallingCode.js +4 -9
  375. package/es6/helpers/getCountryByCallingCode.js.map +1 -1
  376. package/es6/helpers/getCountryByNationalNumber.js +17 -15
  377. package/es6/helpers/getCountryByNationalNumber.js.map +1 -1
  378. package/es6/helpers/getIddPrefix.js +3 -4
  379. package/es6/helpers/getIddPrefix.js.map +1 -1
  380. package/es6/helpers/getNumberType.js +22 -29
  381. package/es6/helpers/getNumberType.js.map +1 -1
  382. package/es6/helpers/getNumberType.test.js +4 -4
  383. package/es6/helpers/getNumberType.test.js.map +1 -1
  384. package/es6/helpers/getPossibleCountriesForNumber.js +1 -8
  385. package/es6/helpers/getPossibleCountriesForNumber.js.map +1 -1
  386. package/es6/helpers/isObject.js.map +1 -1
  387. package/es6/helpers/isViablePhoneNumber.js +21 -13
  388. package/es6/helpers/isViablePhoneNumber.js.map +1 -1
  389. package/es6/helpers/matchesEntirely.js.map +1 -1
  390. package/es6/helpers/matchesEntirely.test.js +3 -2
  391. package/es6/helpers/matchesEntirely.test.js.map +1 -1
  392. package/es6/helpers/mergeArrays.js +6 -10
  393. package/es6/helpers/mergeArrays.js.map +1 -1
  394. package/es6/helpers/mergeArrays.test.js +1 -1
  395. package/es6/helpers/mergeArrays.test.js.map +1 -1
  396. package/es6/helpers/parseDigits.js +6 -12
  397. package/es6/helpers/parseDigits.js.map +1 -1
  398. package/es6/helpers/parseDigits.test.js +1 -1
  399. package/es6/helpers/parseDigits.test.js.map +1 -1
  400. package/es6/helpers/stripIddPrefix.js +6 -11
  401. package/es6/helpers/stripIddPrefix.js.map +1 -1
  402. package/es6/helpers/stripIddPrefix.test.js +4 -4
  403. package/es6/helpers/stripIddPrefix.test.js.map +1 -1
  404. package/es6/isPossible.js +3 -10
  405. package/es6/isPossible.js.map +1 -1
  406. package/es6/isPossible.test.js +34 -38
  407. package/es6/isPossible.test.js.map +1 -1
  408. package/es6/isPossiblePhoneNumber.js +9 -10
  409. package/es6/isPossiblePhoneNumber.js.map +1 -1
  410. package/es6/isPossiblePhoneNumber.test.js +12 -16
  411. package/es6/isPossiblePhoneNumber.test.js.map +1 -1
  412. package/es6/isValid.js +7 -6
  413. package/es6/isValid.js.map +1 -1
  414. package/es6/isValid.test.js +59 -55
  415. package/es6/isValid.test.js.map +1 -1
  416. package/es6/isValidPhoneNumber.js +9 -10
  417. package/es6/isValidPhoneNumber.js.map +1 -1
  418. package/es6/isValidPhoneNumber.test.js +10 -13
  419. package/es6/isValidPhoneNumber.test.js.map +1 -1
  420. package/es6/legacy/findNumbers.js +3 -6
  421. package/es6/legacy/findNumbers.js.map +1 -1
  422. package/es6/legacy/findNumbers.test.js +77 -60
  423. package/es6/legacy/findNumbers.test.js.map +1 -1
  424. package/es6/legacy/findPhoneNumbers.js +8 -9
  425. package/es6/legacy/findPhoneNumbers.js.map +1 -1
  426. package/es6/legacy/findPhoneNumbers.test.js +73 -62
  427. package/es6/legacy/findPhoneNumbers.test.js.map +1 -1
  428. package/es6/legacy/findPhoneNumbersInitialImplementation.js +32 -45
  429. package/es6/legacy/findPhoneNumbersInitialImplementation.js.map +1 -1
  430. package/es6/legacy/format.js +27 -37
  431. package/es6/legacy/format.js.map +1 -1
  432. package/es6/legacy/format.test.js +119 -101
  433. package/es6/legacy/format.test.js.map +1 -1
  434. package/es6/legacy/getNumberType.js +31 -37
  435. package/es6/legacy/getNumberType.js.map +1 -1
  436. package/es6/legacy/getNumberType.test.js +31 -31
  437. package/es6/legacy/getNumberType.test.js.map +1 -1
  438. package/es6/legacy/isPossibleNumber.js +5 -7
  439. package/es6/legacy/isPossibleNumber.js.map +1 -1
  440. package/es6/legacy/isPossibleNumber.test.js +22 -23
  441. package/es6/legacy/isPossibleNumber.test.js.map +1 -1
  442. package/es6/legacy/isValidNumber.js +6 -7
  443. package/es6/legacy/isValidNumber.js.map +1 -1
  444. package/es6/legacy/isValidNumber.test.js +41 -37
  445. package/es6/legacy/isValidNumber.test.js.map +1 -1
  446. package/es6/legacy/isValidNumberForRegion.js +5 -7
  447. package/es6/legacy/isValidNumberForRegion.js.map +1 -1
  448. package/es6/legacy/isValidNumberForRegion.test.js +6 -8
  449. package/es6/legacy/isValidNumberForRegion.test.js.map +1 -1
  450. package/es6/legacy/isValidNumberForRegion_.js +1 -1
  451. package/es6/legacy/isValidNumberForRegion_.js.map +1 -1
  452. package/es6/legacy/parse.js +3 -4
  453. package/es6/legacy/parse.js.map +1 -1
  454. package/es6/legacy/parse.test.js +233 -191
  455. package/es6/legacy/parse.test.js.map +1 -1
  456. package/es6/legacy/searchNumbers.js +8 -8
  457. package/es6/legacy/searchNumbers.js.map +1 -1
  458. package/es6/legacy/searchNumbers.test.js +6 -11
  459. package/es6/legacy/searchNumbers.test.js.map +1 -1
  460. package/es6/metadata.js +86 -114
  461. package/es6/metadata.js.map +1 -1
  462. package/es6/metadata.test.js +57 -73
  463. package/es6/metadata.test.js.map +1 -1
  464. package/es6/normalizeArguments.js +26 -32
  465. package/es6/normalizeArguments.js.map +1 -1
  466. package/es6/parse.js +66 -94
  467. package/es6/parse.js.map +1 -1
  468. package/es6/parse.test.js +244 -203
  469. package/es6/parse.test.js.map +1 -1
  470. package/es6/parseIncompletePhoneNumber.js +9 -16
  471. package/es6/parseIncompletePhoneNumber.js.map +1 -1
  472. package/es6/parseIncompletePhoneNumber.test.js +22 -18
  473. package/es6/parseIncompletePhoneNumber.test.js.map +1 -1
  474. package/es6/parsePhoneNumber.js +3 -4
  475. package/es6/parsePhoneNumber.js.map +1 -1
  476. package/es6/parsePhoneNumber.test.js +14 -23
  477. package/es6/parsePhoneNumber.test.js.map +1 -1
  478. package/es6/parsePhoneNumberWithError.js +3 -4
  479. package/es6/parsePhoneNumberWithError.js.map +1 -1
  480. package/es6/parsePhoneNumberWithError.test.js +32 -33
  481. package/es6/parsePhoneNumberWithError.test.js.map +1 -1
  482. package/es6/parsePhoneNumberWithError_.js +6 -6
  483. package/es6/parsePhoneNumberWithError_.js.map +1 -1
  484. package/es6/parsePhoneNumber_.js +10 -10
  485. package/es6/parsePhoneNumber_.js.map +1 -1
  486. package/es6/searchPhoneNumbersInText.js +9 -11
  487. package/es6/searchPhoneNumbersInText.js.map +1 -1
  488. package/es6/searchPhoneNumbersInText.test.js +11 -18
  489. package/es6/searchPhoneNumbersInText.test.js.map +1 -1
  490. package/es6/tools/semver-compare.js +0 -3
  491. package/es6/tools/semver-compare.js.map +1 -1
  492. package/es6/tools/semver-compare.test.js +1 -1
  493. package/es6/tools/semver-compare.test.js.map +1 -1
  494. package/es6/validatePhoneNumberLength.js +11 -12
  495. package/es6/validatePhoneNumberLength.js.map +1 -1
  496. package/es6/validatePhoneNumberLength.test.js +14 -14
  497. package/es6/validatePhoneNumberLength.test.js.map +1 -1
  498. package/jest.config.json +26 -0
  499. package/metadata.full.json +1 -1
  500. package/metadata.full.json.js +1 -1
  501. package/metadata.max.json +1 -1
  502. package/metadata.max.json.js +1 -1
  503. package/metadata.min.json +1 -1
  504. package/metadata.min.json.js +1 -1
  505. package/metadata.mobile.json +1 -1
  506. package/metadata.mobile.json.js +1 -1
  507. package/package.json +36 -26
  508. package/rollup.config.mjs +2 -2
  509. package/runnable/generate-country-codes.js +1 -1
  510. package/source/AsYouType.test.js +414 -414
  511. package/source/AsYouTypeFormatter.PatternMatcher.test.js +91 -91
  512. package/source/AsYouTypeFormatter.PatternParser.test.js +6 -6
  513. package/source/AsYouTypeFormatter.util.test.js +6 -6
  514. package/source/PhoneNumber.js +13 -15
  515. package/source/PhoneNumber.test.js +36 -29
  516. package/source/PhoneNumberMatcher.js +8 -9
  517. package/source/PhoneNumberMatcher.test.js +18 -6
  518. package/source/findNumbers/Leniency.js +0 -1
  519. package/source/findNumbers/util.test.js +14 -19
  520. package/source/findPhoneNumbersInText.test.js +98 -53
  521. package/source/format.test.js +70 -65
  522. package/source/formatIncompletePhoneNumber.test.js +11 -7
  523. package/source/formatPhoneNumberForMobileDialing.js +16 -1
  524. package/source/getCountries.test.js +2 -2
  525. package/source/getCountryCallingCode.test.js +2 -2
  526. package/source/getExampleNumber.test.js +6 -6
  527. package/source/helpers/RFC3966.test.js +8 -8
  528. package/source/helpers/applyInternationalSeparatorStyle.test.js +2 -2
  529. package/source/helpers/checkNumberLength.test.js +11 -11
  530. package/source/helpers/extractCountryCallingCode.test.js +4 -4
  531. package/source/helpers/extractNationalNumber.test.js +2 -2
  532. package/source/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +2 -2
  533. package/source/helpers/extractPhoneContext.test.js +1 -1
  534. package/source/helpers/getNumberType.test.js +4 -4
  535. package/source/helpers/matchesEntirely.test.js +2 -2
  536. package/source/helpers/mergeArrays.test.js +1 -1
  537. package/source/helpers/parseDigits.test.js +1 -1
  538. package/source/helpers/stripIddPrefix.test.js +4 -4
  539. package/source/isPossible.test.js +16 -10
  540. package/source/isPossiblePhoneNumber.test.js +12 -13
  541. package/source/isValid.test.js +20 -20
  542. package/source/isValidPhoneNumber.test.js +9 -9
  543. package/source/legacy/findNumbers.test.js +57 -44
  544. package/source/legacy/findPhoneNumbers.test.js +51 -35
  545. package/source/legacy/format.test.js +74 -71
  546. package/source/legacy/getNumberType.test.js +20 -18
  547. package/source/legacy/isPossibleNumber.test.js +16 -10
  548. package/source/legacy/isValidNumber.test.js +25 -23
  549. package/source/legacy/isValidNumberForRegion.test.js +5 -5
  550. package/source/legacy/parse.test.js +114 -117
  551. package/source/legacy/searchNumbers.test.js +3 -3
  552. package/source/metadata.test.js +61 -49
  553. package/source/parse.test.js +116 -119
  554. package/source/parseIncompletePhoneNumber.test.js +13 -13
  555. package/source/parsePhoneNumber.test.js +14 -14
  556. package/source/parsePhoneNumberWithError.test.js +26 -26
  557. package/source/searchPhoneNumbersInText.test.js +8 -8
  558. package/source/tools/semver-compare.test.js +1 -1
  559. package/source/validatePhoneNumberLength.test.js +10 -10
  560. package/build/findNumbers/Leniency.test.js +0 -37
  561. package/build/findNumbers/Leniency.test.js.map +0 -1
  562. package/build/formatPhoneNumberForMobileDialing.test.js +0 -15
  563. package/build/formatPhoneNumberForMobileDialing.test.js.map +0 -1
  564. package/es6/findNumbers/Leniency.test.js +0 -36
  565. package/es6/findNumbers/Leniency.test.js.map +0 -1
  566. package/es6/formatPhoneNumberForMobileDialing.test.js +0 -14
  567. package/es6/formatPhoneNumberForMobileDialing.test.js.map +0 -1
  568. package/source/findNumbers/Leniency.test.js +0 -35
  569. package/source/formatPhoneNumberForMobileDialing.test.js +0 -16
package/es6/constants.js CHANGED
@@ -1,25 +1,31 @@
1
1
  // The minimum length of the national significant number.
2
- export var MIN_LENGTH_FOR_NSN = 2; // The ITU says the maximum length should be 15,
2
+ export var MIN_LENGTH_FOR_NSN = 2;
3
+
4
+ // The ITU says the maximum length should be 15,
3
5
  // but one can find longer numbers in Germany.
6
+ export var MAX_LENGTH_FOR_NSN = 17;
4
7
 
5
- export var MAX_LENGTH_FOR_NSN = 17; // The maximum length of the country calling code.
8
+ // The maximum length of the country calling code.
9
+ export var MAX_LENGTH_COUNTRY_CODE = 3;
6
10
 
7
- export var MAX_LENGTH_COUNTRY_CODE = 3; // Digits accepted in phone numbers
11
+ // Digits accepted in phone numbers
8
12
  // (ascii, fullwidth, arabic-indic, and eastern arabic digits).
13
+ export var VALID_DIGITS = "0-9\uFF10-\uFF19\u0660-\u0669\u06F0-\u06F9";
9
14
 
10
- export var VALID_DIGITS = "0-9\uFF10-\uFF19\u0660-\u0669\u06F0-\u06F9"; // `DASHES` will be right after the opening square bracket of the "character class"
11
-
15
+ // `DASHES` will be right after the opening square bracket of the "character class"
12
16
  var DASHES = "-\u2010-\u2015\u2212\u30FC\uFF0D";
13
17
  var SLASHES = "\uFF0F/";
14
18
  var DOTS = "\uFF0E.";
15
19
  export var WHITESPACE = " \xA0\xAD\u200B\u2060\u3000";
16
- var BRACKETS = "()\uFF08\uFF09\uFF3B\uFF3D\\[\\]"; // export const OPENING_BRACKETS = '(\uFF08\uFF3B\\\['
20
+ var BRACKETS = "()\uFF08\uFF09\uFF3B\uFF3D\\[\\]";
21
+ // export const OPENING_BRACKETS = '(\uFF08\uFF3B\\\['
22
+ var TILDES = "~\u2053\u223C\uFF5E";
17
23
 
18
- var TILDES = "~\u2053\u223C\uFF5E"; // Regular expression of acceptable punctuation found in phone numbers. This
24
+ // Regular expression of acceptable punctuation found in phone numbers. This
19
25
  // excludes punctuation found as a leading character only. This consists of dash
20
26
  // characters, white space characters, full stops, slashes, square brackets,
21
27
  // parentheses and tildes. Full-width variants are also present.
22
-
23
28
  export var VALID_PUNCTUATION = "".concat(DASHES).concat(SLASHES).concat(DOTS).concat(WHITESPACE).concat(BRACKETS).concat(TILDES);
24
- export var PLUS_CHARS = "+\uFF0B"; // const LEADING_PLUS_CHARS_PATTERN = new RegExp('^[' + PLUS_CHARS + ']+')
29
+ export var PLUS_CHARS = "+\uFF0B";
30
+ // const LEADING_PLUS_CHARS_PATTERN = new RegExp('^[' + PLUS_CHARS + ']+')
25
31
  //# sourceMappingURL=constants.js.map
@@ -1 +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,IAAMA,kBAAkB,GAAG,CAA3B,C,CAEP;AACA;;AACA,OAAO,IAAMC,kBAAkB,GAAG,EAA3B,C,CAEP;;AACA,OAAO,IAAMC,uBAAuB,GAAG,CAAhC,C,CAEP;AACA;;AACA,OAAO,IAAMC,YAAY,GAAG,4CAArB,C,CAEP;;AACA,IAAMC,MAAM,GAAG,kCAAf;AACA,IAAMC,OAAO,GAAG,SAAhB;AACA,IAAMC,IAAI,GAAG,SAAb;AACA,OAAO,IAAMC,UAAU,GAAG,6BAAnB;AACP,IAAMC,QAAQ,GAAG,kCAAjB,C,CACA;;AACA,IAAMC,MAAM,GAAG,qBAAf,C,CAEA;AACA;AACA;AACA;;AACA,OAAO,IAAMC,iBAAiB,aAAMN,MAAN,SAAeC,OAAf,SAAyBC,IAAzB,SAAgCC,UAAhC,SAA6CC,QAA7C,SAAwDC,MAAxD,CAAvB;AAEP,OAAO,IAAME,UAAU,GAAG,SAAnB,C,CACP"}
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","concat","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,IAAMA,kBAAkB,GAAG,CAAC;;AAEnC;AACA;AACA,OAAO,IAAMC,kBAAkB,GAAG,EAAE;;AAEpC;AACA,OAAO,IAAMC,uBAAuB,GAAG,CAAC;;AAExC;AACA;AACA,OAAO,IAAMC,YAAY,GAAG,4CAA4C;;AAExE;AACA,IAAMC,MAAM,GAAG,kCAAkC;AACjD,IAAMC,OAAO,GAAG,SAAS;AACzB,IAAMC,IAAI,GAAG,SAAS;AACtB,OAAO,IAAMC,UAAU,GAAG,6BAAiC;AAC3D,IAAMC,QAAQ,GAAG,kCAAkC;AACnD;AACA,IAAMC,MAAM,GAAG,qBAAqB;;AAEpC;AACA;AACA;AACA;AACA,OAAO,IAAMC,iBAAiB,MAAAC,MAAA,CAAMP,MAAM,EAAAO,MAAA,CAAGN,OAAO,EAAAM,MAAA,CAAGL,IAAI,EAAAK,MAAA,CAAGJ,UAAU,EAAAI,MAAA,CAAGH,QAAQ,EAAAG,MAAA,CAAGF,MAAM,CAAE;AAE9F,OAAO,IAAMG,UAAU,GAAG,SAAS;AACnC","ignoreList":[]}
@@ -1,68 +1,63 @@
1
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
2
-
3
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
4
-
5
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
-
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
3
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
4
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
5
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
6
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
7
7
  // https://medium.com/dsinjs/implementing-lru-cache-in-javascript-94ba6755cda9
8
8
  var Node = /*#__PURE__*/_createClass(function Node(key, value) {
9
9
  var next = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
10
10
  var prev = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
11
-
12
11
  _classCallCheck(this, Node);
13
-
14
12
  this.key = key;
15
13
  this.value = value;
16
14
  this.next = next;
17
15
  this.prev = prev;
18
16
  });
19
-
20
17
  var LRUCache = /*#__PURE__*/function () {
21
18
  //set default limit of 10 if limit is not passed.
22
19
  function LRUCache() {
23
20
  var limit = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
24
-
25
21
  _classCallCheck(this, LRUCache);
26
-
27
22
  this.size = 0;
28
23
  this.limit = limit;
29
24
  this.head = null;
30
25
  this.tail = null;
31
26
  this.cache = {};
32
- } // Write Node to head of LinkedList
33
- // update cache with Node key and Node reference
34
-
27
+ }
35
28
 
36
- _createClass(LRUCache, [{
29
+ // Write Node to head of LinkedList
30
+ // update cache with Node key and Node reference
31
+ return _createClass(LRUCache, [{
37
32
  key: "put",
38
33
  value: function put(key, value) {
39
34
  this.ensureLimit();
40
-
41
35
  if (!this.head) {
42
36
  this.head = this.tail = new Node(key, value);
43
37
  } else {
44
38
  var node = new Node(key, value, this.head);
45
39
  this.head.prev = node;
46
40
  this.head = node;
47
- } //Update the cache map
48
-
41
+ }
49
42
 
43
+ //Update the cache map
50
44
  this.cache[key] = this.head;
51
45
  this.size++;
52
- } // Read from cache map and make that node as new Head of LinkedList
46
+ }
53
47
 
48
+ // Read from cache map and make that node as new Head of LinkedList
54
49
  }, {
55
50
  key: "get",
56
51
  value: function get(key) {
57
52
  if (this.cache[key]) {
58
- var value = this.cache[key].value; // node removed from it's position and cache
59
-
60
- this.remove(key); // write node again to the head of LinkedList to make it most recently used
53
+ var value = this.cache[key].value;
61
54
 
55
+ // node removed from it's position and cache
56
+ this.remove(key);
57
+ // write node again to the head of LinkedList to make it most recently used
62
58
  this.put(key, value);
63
59
  return value;
64
60
  }
65
-
66
61
  console.log("Item not available in cache for key ".concat(key));
67
62
  }
68
63
  }, {
@@ -76,19 +71,16 @@ var LRUCache = /*#__PURE__*/function () {
76
71
  key: "remove",
77
72
  value: function remove(key) {
78
73
  var node = this.cache[key];
79
-
80
74
  if (node.prev !== null) {
81
75
  node.prev.next = node.next;
82
76
  } else {
83
77
  this.head = node.next;
84
78
  }
85
-
86
79
  if (node.next !== null) {
87
80
  node.next.prev = node.prev;
88
81
  } else {
89
82
  this.tail = node.prev;
90
83
  }
91
-
92
84
  delete this.cache[key];
93
85
  this.size--;
94
86
  }
@@ -99,7 +91,9 @@ var LRUCache = /*#__PURE__*/function () {
99
91
  this.tail = null;
100
92
  this.size = 0;
101
93
  this.cache = {};
102
- } // // Invokes the callback function with every node of the chain and the index of the node.
94
+ }
95
+
96
+ // // Invokes the callback function with every node of the chain and the index of the node.
103
97
  // forEach(fn) {
104
98
  // let node = this.head;
105
99
  // let counter = 0;
@@ -109,6 +103,7 @@ var LRUCache = /*#__PURE__*/function () {
109
103
  // counter++;
110
104
  // }
111
105
  // }
106
+
112
107
  // // To iterate over LRU with a 'for...of' loop
113
108
  // *[Symbol.iterator]() {
114
109
  // let node = this.head;
@@ -117,11 +112,7 @@ var LRUCache = /*#__PURE__*/function () {
117
112
  // node = node.next;
118
113
  // }
119
114
  // }
120
-
121
115
  }]);
122
-
123
- return LRUCache;
124
116
  }();
125
-
126
117
  export { LRUCache as default };
127
118
  //# sourceMappingURL=LRUCache.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"LRUCache.js","names":["Node","key","value","next","prev","LRUCache","limit","size","head","tail","cache","ensureLimit","node","remove","put","console","log"],"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;IAEMA,I,6BACJ,cAAYC,GAAZ,EAAiBC,KAAjB,EAAkD;EAAA,IAA1BC,IAA0B,uEAAnB,IAAmB;EAAA,IAAbC,IAAa,uEAAN,IAAM;;EAAA;;EAChD,KAAKH,GAAL,GAAWA,GAAX;EACA,KAAKC,KAAL,GAAaA,KAAb;EACA,KAAKC,IAAL,GAAYA,IAAZ;EACA,KAAKC,IAAL,GAAYA,IAAZ;AACD,C;;IAGkBC,Q;EACnB;EACA,oBAAwB;IAAA,IAAZC,KAAY,uEAAJ,EAAI;;IAAA;;IACtB,KAAKC,IAAL,GAAY,CAAZ;IACA,KAAKD,KAAL,GAAaA,KAAb;IACA,KAAKE,IAAL,GAAY,IAAZ;IACA,KAAKC,IAAL,GAAY,IAAZ;IACA,KAAKC,KAAL,GAAa,EAAb;EACD,C,CAED;EACA;;;;;WACA,aAAIT,GAAJ,EAASC,KAAT,EAAe;MACb,KAAKS,WAAL;;MAEA,IAAG,CAAC,KAAKH,IAAT,EAAc;QACZ,KAAKA,IAAL,GAAY,KAAKC,IAAL,GAAY,IAAIT,IAAJ,CAASC,GAAT,EAAcC,KAAd,CAAxB;MACD,CAFD,MAEK;QACH,IAAMU,IAAI,GAAG,IAAIZ,IAAJ,CAASC,GAAT,EAAcC,KAAd,EAAqB,KAAKM,IAA1B,CAAb;QACA,KAAKA,IAAL,CAAUJ,IAAV,GAAiBQ,IAAjB;QACA,KAAKJ,IAAL,GAAYI,IAAZ;MACD,CATY,CAWb;;;MACA,KAAKF,KAAL,CAAWT,GAAX,IAAkB,KAAKO,IAAvB;MACA,KAAKD,IAAL;IACD,C,CAED;;;;WACA,aAAIN,GAAJ,EAAQ;MACN,IAAG,KAAKS,KAAL,CAAWT,GAAX,CAAH,EAAmB;QACjB,IAAMC,KAAK,GAAG,KAAKQ,KAAL,CAAWT,GAAX,EAAgBC,KAA9B,CADiB,CAGjB;;QACA,KAAKW,MAAL,CAAYZ,GAAZ,EAJiB,CAKjB;;QACA,KAAKa,GAAL,CAASb,GAAT,EAAcC,KAAd;QAEA,OAAOA,KAAP;MACD;;MAEDa,OAAO,CAACC,GAAR,+CAAmDf,GAAnD;IACD;;;WAED,uBAAa;MACX,IAAG,KAAKM,IAAL,KAAc,KAAKD,KAAtB,EAA4B;QAC1B,KAAKO,MAAL,CAAY,KAAKJ,IAAL,CAAUR,GAAtB;MACD;IACF;;;WAED,gBAAOA,GAAP,EAAW;MACT,IAAMW,IAAI,GAAG,KAAKF,KAAL,CAAWT,GAAX,CAAb;;MAEA,IAAGW,IAAI,CAACR,IAAL,KAAc,IAAjB,EAAsB;QACpBQ,IAAI,CAACR,IAAL,CAAUD,IAAV,GAAiBS,IAAI,CAACT,IAAtB;MACD,CAFD,MAEK;QACH,KAAKK,IAAL,GAAYI,IAAI,CAACT,IAAjB;MACD;;MAED,IAAGS,IAAI,CAACT,IAAL,KAAc,IAAjB,EAAsB;QACpBS,IAAI,CAACT,IAAL,CAAUC,IAAV,GAAiBQ,IAAI,CAACR,IAAtB;MACD,CAFD,MAEK;QACH,KAAKK,IAAL,GAAYG,IAAI,CAACR,IAAjB;MACD;;MAED,OAAO,KAAKM,KAAL,CAAWT,GAAX,CAAP;MACA,KAAKM,IAAL;IACD;;;WAED,iBAAQ;MACN,KAAKC,IAAL,GAAY,IAAZ;MACA,KAAKC,IAAL,GAAY,IAAZ;MACA,KAAKF,IAAL,GAAY,CAAZ;MACA,KAAKG,KAAL,GAAa,EAAb;IACD,C,CAED;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAEA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;;;;;;SA9FmBL,Q"}
1
+ {"version":3,"file":"LRUCache.js","names":["Node","_createClass","key","value","next","arguments","length","undefined","prev","_classCallCheck","LRUCache","limit","size","head","tail","cache","put","ensureLimit","node","get","remove","console","log","concat","clear","default"],"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;AAAA,IAEMA,IAAI,gBAAAC,YAAA,CACR,SAAAD,KAAYE,GAAG,EAAEC,KAAK,EAA4B;EAAA,IAA1BC,IAAI,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,IAAI;EAAA,IAAEG,IAAI,GAAAH,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,IAAI;EAAAI,eAAA,OAAAT,IAAA;EAC9C,IAAI,CAACE,GAAG,GAAGA,GAAG;EACd,IAAI,CAACC,KAAK,GAAGA,KAAK;EAClB,IAAI,CAACC,IAAI,GAAGA,IAAI;EAChB,IAAI,CAACI,IAAI,GAAGA,IAAI;AAClB,CAAC;AAAA,IAGkBE,QAAQ;EAC3B;EACA,SAAAA,SAAA,EAAwB;IAAA,IAAZC,KAAK,GAAAN,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,EAAE;IAAAI,eAAA,OAAAC,QAAA;IACpB,IAAI,CAACE,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;EAAA,OAAAd,YAAA,CAAAS,QAAA;IAAAR,GAAA;IAAAC,KAAA,EACA,SAAAa,GAAGA,CAACd,GAAG,EAAEC,KAAK,EAAC;MACb,IAAI,CAACc,WAAW,CAAC,CAAC;MAElB,IAAG,CAAC,IAAI,CAACJ,IAAI,EAAC;QACZ,IAAI,CAACA,IAAI,GAAG,IAAI,CAACC,IAAI,GAAG,IAAId,IAAI,CAACE,GAAG,EAAEC,KAAK,CAAC;MAC9C,CAAC,MAAI;QACH,IAAMe,IAAI,GAAG,IAAIlB,IAAI,CAACE,GAAG,EAAEC,KAAK,EAAE,IAAI,CAACU,IAAI,CAAC;QAC5C,IAAI,CAACA,IAAI,CAACL,IAAI,GAAGU,IAAI;QACrB,IAAI,CAACL,IAAI,GAAGK,IAAI;MAClB;;MAEA;MACA,IAAI,CAACH,KAAK,CAACb,GAAG,CAAC,GAAG,IAAI,CAACW,IAAI;MAC3B,IAAI,CAACD,IAAI,EAAE;IACb;;IAEA;EAAA;IAAAV,GAAA;IAAAC,KAAA,EACA,SAAAgB,GAAGA,CAACjB,GAAG,EAAC;MACN,IAAG,IAAI,CAACa,KAAK,CAACb,GAAG,CAAC,EAAC;QACjB,IAAMC,KAAK,GAAG,IAAI,CAACY,KAAK,CAACb,GAAG,CAAC,CAACC,KAAK;;QAEnC;QACA,IAAI,CAACiB,MAAM,CAAClB,GAAG,CAAC;QAChB;QACA,IAAI,CAACc,GAAG,CAACd,GAAG,EAAEC,KAAK,CAAC;QAEpB,OAAOA,KAAK;MACd;MAEAkB,OAAO,CAACC,GAAG,wCAAAC,MAAA,CAAwCrB,GAAG,CAAE,CAAC;IAC3D;EAAC;IAAAA,GAAA;IAAAC,KAAA,EAED,SAAAc,WAAWA,CAAA,EAAE;MACX,IAAG,IAAI,CAACL,IAAI,KAAK,IAAI,CAACD,KAAK,EAAC;QAC1B,IAAI,CAACS,MAAM,CAAC,IAAI,CAACN,IAAI,CAACZ,GAAG,CAAC;MAC5B;IACF;EAAC;IAAAA,GAAA;IAAAC,KAAA,EAED,SAAAiB,MAAMA,CAAClB,GAAG,EAAC;MACT,IAAMgB,IAAI,GAAG,IAAI,CAACH,KAAK,CAACb,GAAG,CAAC;MAE5B,IAAGgB,IAAI,CAACV,IAAI,KAAK,IAAI,EAAC;QACpBU,IAAI,CAACV,IAAI,CAACJ,IAAI,GAAGc,IAAI,CAACd,IAAI;MAC5B,CAAC,MAAI;QACH,IAAI,CAACS,IAAI,GAAGK,IAAI,CAACd,IAAI;MACvB;MAEA,IAAGc,IAAI,CAACd,IAAI,KAAK,IAAI,EAAC;QACpBc,IAAI,CAACd,IAAI,CAACI,IAAI,GAAGU,IAAI,CAACV,IAAI;MAC5B,CAAC,MAAI;QACH,IAAI,CAACM,IAAI,GAAGI,IAAI,CAACV,IAAI;MACvB;MAEA,OAAO,IAAI,CAACO,KAAK,CAACb,GAAG,CAAC;MACtB,IAAI,CAACU,IAAI,EAAE;IACb;EAAC;IAAAV,GAAA;IAAAC,KAAA,EAED,SAAAqB,KAAKA,CAAA,EAAG;MACN,IAAI,CAACX,IAAI,GAAG,IAAI;MAChB,IAAI,CAACC,IAAI,GAAG,IAAI;MAChB,IAAI,CAACF,IAAI,GAAG,CAAC;MACb,IAAI,CAACG,KAAK,GAAG,CAAC,CAAC;IACjB;;IAEA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;IAEA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;EAAA;AAAA;AAAA,SA9FmBL,QAAQ,IAAAe,OAAA","ignoreList":[]}
@@ -1,31 +1,26 @@
1
- function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
2
-
3
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
-
5
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
6
-
7
- import isValidNumber from '../isValid.js';
1
+ function _createForOfIteratorHelperLoose(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (t) return (t = t.call(r)).next.bind(t); if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var o = 0; return function () { return o >= r.length ? { done: !0 } : { done: !1, value: r[o++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
2
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
3
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
8
4
  import parseDigits from '../helpers/parseDigits.js';
9
5
  import matchPhoneNumberStringAgainstPhoneNumber from './matchPhoneNumberStringAgainstPhoneNumber.js';
10
6
  import Metadata from '../metadata.js';
11
7
  import getCountryByCallingCode from '../helpers/getCountryByCallingCode.js';
12
8
  import { chooseFormatForNumber } from '../format.js';
13
9
  import { startsWith, endsWith } from './util.js';
10
+
14
11
  /**
15
12
  * Leniency when finding potential phone numbers in text segments
16
13
  * The levels here are ordered in increasing strictness.
17
14
  */
18
-
19
15
  export default {
20
16
  /**
21
17
  * Phone numbers accepted are "possible", but not necessarily "valid".
22
18
  */
23
19
  POSSIBLE: function POSSIBLE(phoneNumber, _ref) {
24
20
  var candidate = _ref.candidate,
25
- metadata = _ref.metadata;
21
+ metadata = _ref.metadata;
26
22
  return true;
27
23
  },
28
-
29
24
  /**
30
25
  * Phone numbers accepted are "possible" and "valid".
31
26
  * Numbers written in national format must have their national-prefix
@@ -33,18 +28,16 @@ export default {
33
28
  */
34
29
  VALID: function VALID(phoneNumber, _ref2) {
35
30
  var candidate = _ref2.candidate,
36
- defaultCountry = _ref2.defaultCountry,
37
- metadata = _ref2.metadata;
38
-
31
+ defaultCountry = _ref2.defaultCountry,
32
+ metadata = _ref2.metadata;
39
33
  if (!phoneNumber.isValid() || !containsOnlyValidXChars(phoneNumber, candidate, metadata)) {
40
34
  return false;
41
- } // Skipped for simplicity.
42
- // return isNationalPrefixPresentIfRequired(phoneNumber, { defaultCountry, metadata })
43
-
35
+ }
44
36
 
37
+ // Skipped for simplicity.
38
+ // return isNationalPrefixPresentIfRequired(phoneNumber, { defaultCountry, metadata })
45
39
  return true;
46
40
  },
47
-
48
41
  /**
49
42
  * Phone numbers accepted are "valid" and
50
43
  * are grouped in a possible way for this locale. For example, a US number written as
@@ -59,20 +52,17 @@ export default {
59
52
  */
60
53
  STRICT_GROUPING: function STRICT_GROUPING(phoneNumber, _ref3) {
61
54
  var candidate = _ref3.candidate,
62
- defaultCountry = _ref3.defaultCountry,
63
- metadata = _ref3.metadata,
64
- regExpCache = _ref3.regExpCache;
65
-
55
+ defaultCountry = _ref3.defaultCountry,
56
+ metadata = _ref3.metadata,
57
+ regExpCache = _ref3.regExpCache;
66
58
  if (!phoneNumber.isValid() || !containsOnlyValidXChars(phoneNumber, candidate, metadata) || containsMoreThanOneSlashInNationalNumber(phoneNumber, candidate) || !isNationalPrefixPresentIfRequired(phoneNumber, {
67
59
  defaultCountry: defaultCountry,
68
60
  metadata: metadata
69
61
  })) {
70
62
  return false;
71
63
  }
72
-
73
64
  return checkNumberGroupingIsValid(phoneNumber, candidate, metadata, allNumberGroupsRemainGrouped, regExpCache);
74
65
  },
75
-
76
66
  /**
77
67
  * Phone numbers accepted are "valid" and are grouped in the same way
78
68
  * that we would have formatted it, or as a single block.
@@ -86,21 +76,18 @@ export default {
86
76
  */
87
77
  EXACT_GROUPING: function EXACT_GROUPING(phoneNumber, _ref4) {
88
78
  var candidate = _ref4.candidate,
89
- defaultCountry = _ref4.defaultCountry,
90
- metadata = _ref4.metadata,
91
- regExpCache = _ref4.regExpCache;
92
-
79
+ defaultCountry = _ref4.defaultCountry,
80
+ metadata = _ref4.metadata,
81
+ regExpCache = _ref4.regExpCache;
93
82
  if (!phoneNumber.isValid() || !containsOnlyValidXChars(phoneNumber, candidate, metadata) || containsMoreThanOneSlashInNationalNumber(phoneNumber, candidate) || !isNationalPrefixPresentIfRequired(phoneNumber, {
94
83
  defaultCountry: defaultCountry,
95
84
  metadata: metadata
96
85
  })) {
97
86
  return false;
98
87
  }
99
-
100
88
  return checkNumberGroupingIsValid(phoneNumber, candidate, metadata, allNumberGroupsAreExactlyPresent, regExpCache);
101
89
  }
102
90
  };
103
-
104
91
  function containsOnlyValidXChars(phoneNumber, candidate, metadata) {
105
92
  // The characters 'x' and 'X' can be (1) a carrier code, in which case they always precede the
106
93
  // national significant number or (2) an extension sign, in which case they always precede the
@@ -109,23 +96,19 @@ function containsOnlyValidXChars(phoneNumber, candidate, metadata) {
109
96
  // or 'X'. We ignore the character if it appears as the last character of the string.
110
97
  for (var index = 0; index < candidate.length - 1; index++) {
111
98
  var charAtIndex = candidate.charAt(index);
112
-
113
99
  if (charAtIndex === 'x' || charAtIndex === 'X') {
114
100
  var charAtNextIndex = candidate.charAt(index + 1);
115
-
116
101
  if (charAtNextIndex === 'x' || charAtNextIndex === 'X') {
117
102
  // This is the carrier code case, in which the 'X's always precede the national
118
103
  // significant number.
119
104
  index++;
120
-
121
105
  if (matchPhoneNumberStringAgainstPhoneNumber(candidate.substring(index), phoneNumber, metadata) !== 'NSN_MATCH') {
122
106
  return false;
123
- } // This is the extension sign case, in which the 'x' or 'X' should always precede the
107
+ }
108
+ // This is the extension sign case, in which the 'x' or 'X' should always precede the
124
109
  // extension number.
125
-
126
110
  } else {
127
111
  var ext = parseDigits(candidate.substring(index));
128
-
129
112
  if (ext) {
130
113
  if (phoneNumber.ext !== ext) {
131
114
  return false;
@@ -138,207 +121,178 @@ function containsOnlyValidXChars(phoneNumber, candidate, metadata) {
138
121
  }
139
122
  }
140
123
  }
141
-
142
124
  return true;
143
125
  }
144
-
145
126
  function isNationalPrefixPresentIfRequired(phoneNumber, _ref5) {
146
127
  var defaultCountry = _ref5.defaultCountry,
147
- _metadata = _ref5.metadata;
148
-
128
+ _metadata = _ref5.metadata;
149
129
  // First, check how we deduced the country code. If it was written in international format, then
150
130
  // the national prefix is not required.
151
131
  if (phoneNumber.__countryCallingCodeSource !== 'FROM_DEFAULT_COUNTRY') {
152
132
  return true;
153
133
  }
154
-
155
134
  var metadata = new Metadata(_metadata);
156
135
  metadata.selectNumberingPlan(phoneNumber.countryCallingCode);
157
136
  var phoneNumberRegion = phoneNumber.country || getCountryByCallingCode(phoneNumber.countryCallingCode, {
158
137
  nationalNumber: phoneNumber.nationalNumber,
159
138
  defaultCountry: defaultCountry,
160
139
  metadata: metadata
161
- }); // Check if a national prefix should be present when formatting this number.
140
+ });
162
141
 
142
+ // Check if a national prefix should be present when formatting this number.
163
143
  var nationalNumber = phoneNumber.nationalNumber;
164
- var format = chooseFormatForNumber(metadata.numberingPlan.formats(), nationalNumber); // To do this, we check that a national prefix formatting rule was present
165
- // and that it wasn't just the first-group symbol ($1) with punctuation.
144
+ var format = chooseFormatForNumber(metadata.numberingPlan.formats(), nationalNumber);
166
145
 
146
+ // To do this, we check that a national prefix formatting rule was present
147
+ // and that it wasn't just the first-group symbol ($1) with punctuation.
167
148
  if (format.nationalPrefixFormattingRule()) {
168
149
  if (metadata.numberingPlan.nationalPrefixIsOptionalWhenFormattingInNationalFormat()) {
169
150
  // The national-prefix is optional in these cases, so we don't need to check if it was present.
170
151
  return true;
171
152
  }
172
-
173
153
  if (!format.usesNationalPrefix()) {
174
154
  // National Prefix not needed for this number.
175
155
  return true;
176
156
  }
177
-
178
157
  return Boolean(phoneNumber.nationalPrefix);
179
158
  }
180
-
181
159
  return true;
182
160
  }
183
-
184
161
  export function containsMoreThanOneSlashInNationalNumber(phoneNumber, candidate) {
185
162
  var firstSlashInBodyIndex = candidate.indexOf('/');
186
-
187
163
  if (firstSlashInBodyIndex < 0) {
188
164
  // No slashes, this is okay.
189
165
  return false;
190
- } // Now look for a second one.
191
-
166
+ }
192
167
 
168
+ // Now look for a second one.
193
169
  var secondSlashInBodyIndex = candidate.indexOf('/', firstSlashInBodyIndex + 1);
194
-
195
170
  if (secondSlashInBodyIndex < 0) {
196
171
  // Only one slash, this is okay.
197
172
  return false;
198
- } // If the first slash is after the country calling code, this is permitted.
199
-
173
+ }
200
174
 
175
+ // If the first slash is after the country calling code, this is permitted.
201
176
  var candidateHasCountryCode = phoneNumber.__countryCallingCodeSource === 'FROM_NUMBER_WITH_PLUS_SIGN' || phoneNumber.__countryCallingCodeSource === 'FROM_NUMBER_WITHOUT_PLUS_SIGN';
202
-
203
177
  if (candidateHasCountryCode && parseDigits(candidate.substring(0, firstSlashInBodyIndex)) === phoneNumber.countryCallingCode) {
204
178
  // Any more slashes and this is illegal.
205
179
  return candidate.slice(secondSlashInBodyIndex + 1).indexOf('/') >= 0;
206
180
  }
207
-
208
181
  return true;
209
182
  }
210
-
211
183
  function checkNumberGroupingIsValid(number, candidate, metadata, checkGroups, regExpCache) {
212
184
  throw new Error('This part of code hasn\'t been ported');
213
- var normalizedCandidate = normalizeDigits(candidate, true
214
- /* keep non-digits */
215
- );
185
+ var normalizedCandidate = normalizeDigits(candidate, true /* keep non-digits */);
216
186
  var formattedNumberGroups = getNationalNumberGroups(metadata, number, null);
217
-
218
187
  if (checkGroups(metadata, number, normalizedCandidate, formattedNumberGroups)) {
219
188
  return true;
220
- } // If this didn't pass, see if there are any alternate formats that match, and try them instead.
221
-
189
+ }
222
190
 
191
+ // If this didn't pass, see if there are any alternate formats that match, and try them instead.
223
192
  var alternateFormats = MetadataManager.getAlternateFormatsForCountry(number.getCountryCode());
224
193
  var nationalSignificantNumber = util.getNationalSignificantNumber(number);
225
-
226
194
  if (alternateFormats) {
227
195
  for (var _iterator = _createForOfIteratorHelperLoose(alternateFormats.numberFormats()), _step; !(_step = _iterator()).done;) {
228
196
  var alternateFormat = _step.value;
229
-
230
197
  if (alternateFormat.leadingDigitsPatterns().length > 0) {
231
198
  // There is only one leading digits pattern for alternate formats.
232
199
  var leadingDigitsRegExp = regExpCache.getPatternForRegExp('^' + alternateFormat.leadingDigitsPatterns()[0]);
233
-
234
200
  if (!leadingDigitsRegExp.test(nationalSignificantNumber)) {
235
201
  // Leading digits don't match; try another one.
236
202
  continue;
237
203
  }
238
204
  }
239
-
240
205
  formattedNumberGroups = getNationalNumberGroups(metadata, number, alternateFormat);
241
-
242
206
  if (checkGroups(metadata, number, normalizedCandidate, formattedNumberGroups)) {
243
207
  return true;
244
208
  }
245
209
  }
246
210
  }
247
-
248
211
  return false;
249
212
  }
213
+
250
214
  /**
251
215
  * Helper method to get the national-number part of a number, formatted without any national
252
216
  * prefix, and return it as a set of digit blocks that would be formatted together following
253
217
  * standard formatting rules.
254
218
  */
255
-
256
-
257
219
  function getNationalNumberGroups(metadata, number, formattingPattern) {
258
220
  throw new Error('This part of code hasn\'t been ported');
259
-
260
221
  if (formattingPattern) {
261
222
  // We format the NSN only, and split that according to the separator.
262
223
  var nationalSignificantNumber = util.getNationalSignificantNumber(number);
263
224
  return util.formatNsnUsingPattern(nationalSignificantNumber, formattingPattern, 'RFC3966', metadata).split('-');
264
- } // This will be in the format +CC-DG1-DG2-DGX;ext=EXT where DG1..DGX represents groups of digits.
225
+ }
265
226
 
227
+ // This will be in the format +CC-DG1-DG2-DGX;ext=EXT where DG1..DGX represents groups of digits.
228
+ var rfc3966Format = formatNumber(number, 'RFC3966', metadata);
266
229
 
267
- var rfc3966Format = formatNumber(number, 'RFC3966', metadata); // We remove the extension part from the formatted string before splitting it into different
230
+ // We remove the extension part from the formatted string before splitting it into different
268
231
  // groups.
269
-
270
232
  var endIndex = rfc3966Format.indexOf(';');
271
-
272
233
  if (endIndex < 0) {
273
234
  endIndex = rfc3966Format.length;
274
- } // The country-code will have a '-' following it.
275
-
235
+ }
276
236
 
237
+ // The country-code will have a '-' following it.
277
238
  var startIndex = rfc3966Format.indexOf('-') + 1;
278
239
  return rfc3966Format.slice(startIndex, endIndex).split('-');
279
240
  }
280
-
281
241
  function allNumberGroupsAreExactlyPresent(metadata, number, normalizedCandidate, formattedNumberGroups) {
282
242
  throw new Error('This part of code hasn\'t been ported');
283
- var candidateGroups = normalizedCandidate.split(NON_DIGITS_PATTERN); // Set this to the last group, skipping it if the number has an extension.
243
+ var candidateGroups = normalizedCandidate.split(NON_DIGITS_PATTERN);
244
+
245
+ // Set this to the last group, skipping it if the number has an extension.
246
+ var candidateNumberGroupIndex = number.hasExtension() ? candidateGroups.length - 2 : candidateGroups.length - 1;
284
247
 
285
- var candidateNumberGroupIndex = number.hasExtension() ? candidateGroups.length - 2 : candidateGroups.length - 1; // First we check if the national significant number is formatted as a block.
248
+ // First we check if the national significant number is formatted as a block.
286
249
  // We use contains and not equals, since the national significant number may be present with
287
250
  // a prefix such as a national number prefix, or the country code itself.
288
-
289
251
  if (candidateGroups.length == 1 || candidateGroups[candidateNumberGroupIndex].contains(util.getNationalSignificantNumber(number))) {
290
252
  return true;
291
- } // Starting from the end, go through in reverse, excluding the first group, and check the
292
- // candidate and number groups are the same.
293
-
253
+ }
294
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.
295
257
  var formattedNumberGroupIndex = formattedNumberGroups.length - 1;
296
-
297
258
  while (formattedNumberGroupIndex > 0 && candidateNumberGroupIndex >= 0) {
298
259
  if (candidateGroups[candidateNumberGroupIndex] !== formattedNumberGroups[formattedNumberGroupIndex]) {
299
260
  return false;
300
261
  }
301
-
302
262
  formattedNumberGroupIndex--;
303
263
  candidateNumberGroupIndex--;
304
- } // Now check the first group. There may be a national prefix at the start, so we only check
305
- // that the candidate group ends with the formatted number group.
306
-
264
+ }
307
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.
308
268
  return candidateNumberGroupIndex >= 0 && endsWith(candidateGroups[candidateNumberGroupIndex], formattedNumberGroups[0]);
309
269
  }
310
-
311
270
  function allNumberGroupsRemainGrouped(metadata, number, normalizedCandidate, formattedNumberGroups) {
312
271
  throw new Error('This part of code hasn\'t been ported');
313
272
  var fromIndex = 0;
314
-
315
273
  if (number.getCountryCodeSource() !== CountryCodeSource.FROM_DEFAULT_COUNTRY) {
316
274
  // First skip the country code if the normalized candidate contained it.
317
275
  var countryCode = String(number.getCountryCode());
318
276
  fromIndex = normalizedCandidate.indexOf(countryCode) + countryCode.length();
319
- } // Check each group of consecutive digits are not broken into separate groupings in the
320
- // {@code normalizedCandidate} string.
321
-
277
+ }
322
278
 
279
+ // Check each group of consecutive digits are not broken into separate groupings in the
280
+ // {@code normalizedCandidate} string.
323
281
  for (var i = 0; i < formattedNumberGroups.length; i++) {
324
282
  // Fails if the substring of {@code normalizedCandidate} starting from {@code fromIndex}
325
283
  // doesn't contain the consecutive digits in formattedNumberGroups[i].
326
284
  fromIndex = normalizedCandidate.indexOf(formattedNumberGroups[i], fromIndex);
327
-
328
285
  if (fromIndex < 0) {
329
286
  return false;
330
- } // Moves {@code fromIndex} forward.
331
-
332
-
287
+ }
288
+ // Moves {@code fromIndex} forward.
333
289
  fromIndex += formattedNumberGroups[i].length();
334
-
335
290
  if (i == 0 && fromIndex < normalizedCandidate.length()) {
336
291
  // We are at the position right after the NDC. We get the region used for formatting
337
292
  // information based on the country code in the phone number, rather than the number itself,
338
293
  // as we do not need to distinguish between different countries with the same country
339
294
  // calling code and this is faster.
340
295
  var region = util.getRegionCodeForCountryCode(number.getCountryCode());
341
-
342
296
  if (util.getNddPrefixForRegion(region, true) != null && Character.isDigit(normalizedCandidate.charAt(fromIndex))) {
343
297
  // This means there is no formatting symbol after the NDC. In this case, we only
344
298
  // accept the number if there is no formatting symbol at all in the number, except
@@ -347,11 +301,11 @@ function allNumberGroupsRemainGrouped(metadata, number, normalizedCandidate, for
347
301
  return startsWith(normalizedCandidate.slice(fromIndex - formattedNumberGroups[i].length), nationalSignificantNumber);
348
302
  }
349
303
  }
350
- } // The check here makes sure that we haven't mistakenly already used the extension to
304
+ }
305
+
306
+ // The check here makes sure that we haven't mistakenly already used the extension to
351
307
  // match the last group of the subscriber number. Note the extension cannot have
352
308
  // formatting in-between digits.
353
-
354
-
355
309
  return normalizedCandidate.slice(fromIndex).contains(number.getExtension());
356
310
  }
357
311
  //# sourceMappingURL=Leniency.js.map