libphonenumber-js 1.13.3 → 1.13.4

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 (218) hide show
  1. package/.gitlab-ci.yml +24 -9
  2. package/README.md +27 -10
  3. package/build/AsYouType.js +100 -27
  4. package/build/AsYouType.js.map +1 -1
  5. package/build/AsYouType.test.js.map +1 -1
  6. package/build/AsYouTypeFormatter.complete.js +2 -2
  7. package/build/AsYouTypeFormatter.complete.js.map +1 -1
  8. package/build/AsYouTypeFormatter.js +1 -1
  9. package/build/AsYouTypeFormatter.js.map +1 -1
  10. package/build/AsYouTypeState.js +15 -1
  11. package/build/AsYouTypeState.js.map +1 -1
  12. package/build/PhoneNumber.js +26 -39
  13. package/build/PhoneNumber.js.map +1 -1
  14. package/build/format.js +3 -3
  15. package/build/format.js.map +1 -1
  16. package/build/formatPhoneNumberForMobileDialing.js +4 -3
  17. package/build/formatPhoneNumberForMobileDialing.js.map +1 -1
  18. package/build/helpers/checkNumberLength.js +21 -6
  19. package/build/helpers/checkNumberLength.js.map +1 -1
  20. package/build/helpers/checkNumberLength.test.js.map +1 -1
  21. package/build/helpers/extractCountryCallingCode.js +16 -11
  22. package/build/helpers/extractCountryCallingCode.js.map +1 -1
  23. package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +21 -10
  24. package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -1
  25. package/build/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.test.js.map +1 -0
  26. package/build/helpers/extractNationalNumber.js +12 -3
  27. package/build/helpers/extractNationalNumber.js.map +1 -1
  28. package/build/helpers/extractNationalNumber.test.js.map +1 -1
  29. package/build/helpers/getCountryAndCallingCodeFromOneOfThem.js +35 -0
  30. package/build/helpers/getCountryAndCallingCodeFromOneOfThem.js.map +1 -0
  31. package/build/helpers/getCountryByCallingCode.js +10 -7
  32. package/build/helpers/getCountryByCallingCode.js.map +1 -1
  33. package/build/helpers/getCountryByNationalNumber.js +13 -9
  34. package/build/helpers/getCountryByNationalNumber.js.map +1 -1
  35. package/build/helpers/getIddPrefix.js +1 -1
  36. package/build/helpers/getIddPrefix.js.map +1 -1
  37. package/build/helpers/getNumberType.js +3 -3
  38. package/build/helpers/getNumberType.js.map +1 -1
  39. package/build/helpers/getPossibleCountriesForNumber.js +4 -7
  40. package/build/helpers/getPossibleCountriesForNumber.js.map +1 -1
  41. package/build/helpers/isCallingCode.js +11 -0
  42. package/build/helpers/isCallingCode.js.map +1 -0
  43. package/build/helpers/isCallingCode.test.js.map +1 -0
  44. package/build/helpers/isCountryCode.js +11 -0
  45. package/build/helpers/isCountryCode.js.map +1 -0
  46. package/build/helpers/isCountryCode.test.js.map +1 -0
  47. package/build/helpers/stripIddPrefix.js +9 -4
  48. package/build/helpers/stripIddPrefix.js.map +1 -1
  49. package/build/isPossible.js +14 -8
  50. package/build/isPossible.js.map +1 -1
  51. package/build/isValid.js +3 -3
  52. package/build/isValid.js.map +1 -1
  53. package/build/metadata.js +80 -31
  54. package/build/metadata.js.map +1 -1
  55. package/build/metadata.test.js.map +1 -1
  56. package/build/parse.js +36 -12
  57. package/build/parse.js.map +1 -1
  58. package/build/validatePhoneNumberLength.js +3 -3
  59. package/build/validatePhoneNumberLength.js.map +1 -1
  60. package/bundle/libphonenumber-js.min.js +1 -1
  61. package/bundle/libphonenumber-js.min.js.map +1 -1
  62. package/bundle/libphonenumber-max.js +1 -1
  63. package/bundle/libphonenumber-max.js.map +1 -1
  64. package/bundle/libphonenumber-min.js +1 -1
  65. package/bundle/libphonenumber-min.js.map +1 -1
  66. package/bundle/libphonenumber-mobile.js +1 -1
  67. package/bundle/libphonenumber-mobile.js.map +1 -1
  68. package/core/index.d.cts +1 -0
  69. package/core/index.d.ts +1 -0
  70. package/custom.d.ts +3 -1
  71. package/es6/AsYouType.js +100 -27
  72. package/es6/AsYouType.js.map +1 -1
  73. package/es6/AsYouType.test.js.map +1 -1
  74. package/es6/AsYouTypeFormatter.complete.js +2 -2
  75. package/es6/AsYouTypeFormatter.complete.js.map +1 -1
  76. package/es6/AsYouTypeFormatter.js +1 -1
  77. package/es6/AsYouTypeFormatter.js.map +1 -1
  78. package/es6/AsYouTypeState.js +15 -1
  79. package/es6/AsYouTypeState.js.map +1 -1
  80. package/es6/PhoneNumber.js +26 -39
  81. package/es6/PhoneNumber.js.map +1 -1
  82. package/es6/format.js +3 -3
  83. package/es6/format.js.map +1 -1
  84. package/es6/formatPhoneNumberForMobileDialing.js +4 -3
  85. package/es6/formatPhoneNumberForMobileDialing.js.map +1 -1
  86. package/es6/helpers/checkNumberLength.js +22 -6
  87. package/es6/helpers/checkNumberLength.js.map +1 -1
  88. package/es6/helpers/checkNumberLength.test.js.map +1 -1
  89. package/es6/helpers/extractCountryCallingCode.js +16 -11
  90. package/es6/helpers/extractCountryCallingCode.js.map +1 -1
  91. package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +21 -10
  92. package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -1
  93. package/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.test.js.map +1 -0
  94. package/es6/helpers/extractNationalNumber.js +12 -3
  95. package/es6/helpers/extractNationalNumber.js.map +1 -1
  96. package/es6/helpers/extractNationalNumber.test.js.map +1 -1
  97. package/es6/helpers/getCountryAndCallingCodeFromOneOfThem.js +28 -0
  98. package/es6/helpers/getCountryAndCallingCodeFromOneOfThem.js.map +1 -0
  99. package/es6/helpers/getCountryByCallingCode.js +10 -7
  100. package/es6/helpers/getCountryByCallingCode.js.map +1 -1
  101. package/es6/helpers/getCountryByNationalNumber.js +13 -9
  102. package/es6/helpers/getCountryByNationalNumber.js.map +1 -1
  103. package/es6/helpers/getIddPrefix.js +1 -1
  104. package/es6/helpers/getIddPrefix.js.map +1 -1
  105. package/es6/helpers/getNumberType.js +3 -3
  106. package/es6/helpers/getNumberType.js.map +1 -1
  107. package/es6/helpers/getPossibleCountriesForNumber.js +4 -7
  108. package/es6/helpers/getPossibleCountriesForNumber.js.map +1 -1
  109. package/es6/helpers/isCallingCode.js +5 -0
  110. package/es6/helpers/isCallingCode.js.map +1 -0
  111. package/es6/helpers/isCallingCode.test.js.map +1 -0
  112. package/es6/helpers/isCountryCode.js +5 -0
  113. package/es6/helpers/isCountryCode.js.map +1 -0
  114. package/es6/helpers/isCountryCode.test.js.map +1 -0
  115. package/es6/helpers/stripIddPrefix.js +9 -4
  116. package/es6/helpers/stripIddPrefix.js.map +1 -1
  117. package/es6/isPossible.js +14 -8
  118. package/es6/isPossible.js.map +1 -1
  119. package/es6/isValid.js +3 -3
  120. package/es6/isValid.js.map +1 -1
  121. package/es6/metadata.js +80 -31
  122. package/es6/metadata.js.map +1 -1
  123. package/es6/metadata.test.js.map +1 -1
  124. package/es6/parse.js +36 -12
  125. package/es6/parse.js.map +1 -1
  126. package/es6/validatePhoneNumberLength.js +3 -3
  127. package/es6/validatePhoneNumberLength.js.map +1 -1
  128. package/es6-modern/AsYouType.js +100 -26
  129. package/es6-modern/AsYouType.js.map +1 -1
  130. package/es6-modern/AsYouType.test.js.map +1 -1
  131. package/es6-modern/AsYouTypeFormatter.complete.js +2 -2
  132. package/es6-modern/AsYouTypeFormatter.complete.js.map +1 -1
  133. package/es6-modern/AsYouTypeFormatter.js +1 -1
  134. package/es6-modern/AsYouTypeFormatter.js.map +1 -1
  135. package/es6-modern/AsYouTypeState.js +15 -1
  136. package/es6-modern/AsYouTypeState.js.map +1 -1
  137. package/es6-modern/PhoneNumber.js +25 -36
  138. package/es6-modern/PhoneNumber.js.map +1 -1
  139. package/es6-modern/format.js +3 -3
  140. package/es6-modern/format.js.map +1 -1
  141. package/es6-modern/formatPhoneNumberForMobileDialing.js +4 -3
  142. package/es6-modern/formatPhoneNumberForMobileDialing.js.map +1 -1
  143. package/es6-modern/helpers/checkNumberLength.js +22 -6
  144. package/es6-modern/helpers/checkNumberLength.js.map +1 -1
  145. package/es6-modern/helpers/checkNumberLength.test.js.map +1 -1
  146. package/es6-modern/helpers/extractCountryCallingCode.js +16 -11
  147. package/es6-modern/helpers/extractCountryCallingCode.js.map +1 -1
  148. package/es6-modern/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +21 -10
  149. package/es6-modern/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js.map +1 -1
  150. package/es6-modern/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.test.js.map +1 -0
  151. package/es6-modern/helpers/extractNationalNumber.js +12 -3
  152. package/es6-modern/helpers/extractNationalNumber.js.map +1 -1
  153. package/es6-modern/helpers/extractNationalNumber.test.js.map +1 -1
  154. package/es6-modern/helpers/getCountryAndCallingCodeFromOneOfThem.js +28 -0
  155. package/es6-modern/helpers/getCountryAndCallingCodeFromOneOfThem.js.map +1 -0
  156. package/es6-modern/helpers/getCountryByCallingCode.js +10 -7
  157. package/es6-modern/helpers/getCountryByCallingCode.js.map +1 -1
  158. package/es6-modern/helpers/getCountryByNationalNumber.js +13 -10
  159. package/es6-modern/helpers/getCountryByNationalNumber.js.map +1 -1
  160. package/es6-modern/helpers/getIddPrefix.js +1 -1
  161. package/es6-modern/helpers/getIddPrefix.js.map +1 -1
  162. package/es6-modern/helpers/getNumberType.js +3 -3
  163. package/es6-modern/helpers/getNumberType.js.map +1 -1
  164. package/es6-modern/helpers/getPossibleCountriesForNumber.js +4 -7
  165. package/es6-modern/helpers/getPossibleCountriesForNumber.js.map +1 -1
  166. package/es6-modern/helpers/isCallingCode.js +5 -0
  167. package/es6-modern/helpers/isCallingCode.js.map +1 -0
  168. package/es6-modern/helpers/isCallingCode.test.js.map +1 -0
  169. package/es6-modern/helpers/isCountryCode.js +5 -0
  170. package/es6-modern/helpers/isCountryCode.js.map +1 -0
  171. package/es6-modern/helpers/isCountryCode.test.js.map +1 -0
  172. package/es6-modern/helpers/stripIddPrefix.js +9 -4
  173. package/es6-modern/helpers/stripIddPrefix.js.map +1 -1
  174. package/es6-modern/isPossible.js +14 -8
  175. package/es6-modern/isPossible.js.map +1 -1
  176. package/es6-modern/isValid.js +3 -3
  177. package/es6-modern/isValid.js.map +1 -1
  178. package/es6-modern/metadata.js +78 -31
  179. package/es6-modern/metadata.js.map +1 -1
  180. package/es6-modern/metadata.test.js.map +1 -1
  181. package/es6-modern/parse.js +41 -12
  182. package/es6-modern/parse.js.map +1 -1
  183. package/es6-modern/validatePhoneNumberLength.js +3 -3
  184. package/es6-modern/validatePhoneNumberLength.js.map +1 -1
  185. package/index.d.cts +1 -0
  186. package/index.d.ts +1 -0
  187. package/max/index.d.cts +1 -0
  188. package/max/index.d.ts +1 -0
  189. package/min/index.d.cts +1 -0
  190. package/min/index.d.ts +1 -0
  191. package/mobile/index.d.cts +1 -0
  192. package/mobile/index.d.ts +1 -0
  193. package/package.json +1 -1
  194. package/source/AsYouType.js +108 -27
  195. package/source/AsYouTypeFormatter.complete.js +2 -2
  196. package/source/AsYouTypeFormatter.js +1 -1
  197. package/source/AsYouTypeState.js +15 -1
  198. package/source/PhoneNumber.js +24 -39
  199. package/source/format.js +3 -3
  200. package/source/formatPhoneNumberForMobileDialing.js +4 -3
  201. package/source/helpers/checkNumberLength.js +21 -6
  202. package/source/helpers/extractCountryCallingCode.js +16 -11
  203. package/source/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +20 -10
  204. package/source/helpers/extractNationalNumber.js +11 -3
  205. package/source/helpers/getCountryAndCallingCodeFromOneOfThem.js +31 -0
  206. package/source/helpers/getCountryByCallingCode.js +10 -7
  207. package/source/helpers/getCountryByNationalNumber.js +14 -11
  208. package/source/helpers/getIddPrefix.js +1 -1
  209. package/source/helpers/getNumberType.js +3 -3
  210. package/source/helpers/getPossibleCountriesForNumber.js +4 -7
  211. package/source/helpers/isCallingCode.js +5 -0
  212. package/source/helpers/isCountryCode.js +5 -0
  213. package/source/helpers/stripIddPrefix.js +10 -4
  214. package/source/isPossible.js +13 -7
  215. package/source/isValid.js +3 -3
  216. package/source/metadata.js +77 -33
  217. package/source/parse.js +41 -11
  218. package/source/validatePhoneNumberLength.js +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"extractNationalNumber.js","names":["extractNationalNumberFromPossiblyIncompleteNumber","matchesEntirely","checkNumberLength","getCountryByCallingCode","extractNationalNumber","number","country","metadata","_extractNationalNumbe","carrierCode","nationalNumber","shouldHaveExtractedNationalPrefix","numberingPlan","possibleLengths","callingCode","isPossibleIncompleteNationalNumber","nationalNumberBefore","nationalNumberAfter","nationalNumberPattern"],"sources":["../../source/helpers/extractNationalNumber.js"],"sourcesContent":["import extractNationalNumberFromPossiblyIncompleteNumber from './extractNationalNumberFromPossiblyIncompleteNumber.js'\r\nimport matchesEntirely from './matchesEntirely.js'\r\nimport checkNumberLength from './checkNumberLength.js'\r\nimport getCountryByCallingCode from './getCountryByCallingCode.js'\r\n\r\n/**\r\n * Strips national prefix and carrier code from a complete phone number.\r\n * The difference from the non-\"FromCompleteNumber\" function is that\r\n * it won't extract national prefix if the resultant number is too short\r\n * to be a complete number for the selected phone numbering plan.\r\n * @param {string} number — Complete phone number digits.\r\n * @param {string?} country — Country, if known.\r\n * @param {Metadata} metadata — Metadata with a phone numbering plan selected.\r\n * @return {object} `{ nationalNumber: string, carrierCode: string? }`.\r\n */\r\nexport default function extractNationalNumber(number, country, metadata) {\r\n\t// Parsing national prefixes and carrier codes\r\n\t// is only required for local phone numbers\r\n\t// but some people don't understand that\r\n\t// and sometimes write international phone numbers\r\n\t// with national prefixes (or maybe even carrier codes).\r\n\t// http://ucken.blogspot.ru/2016/03/trunk-prefixes-in-skype4b.html\r\n\t// Google's original library forgives such mistakes\r\n\t// and so does this library, because it has been requested:\r\n\t// https://github.com/catamphetamine/libphonenumber-js/issues/127\r\n\tconst {\r\n\t\tcarrierCode,\r\n\t\tnationalNumber\r\n\t} = extractNationalNumberFromPossiblyIncompleteNumber(\r\n\t\tnumber,\r\n\t\tmetadata\r\n\t)\r\n\r\n\tif (nationalNumber !== number) {\r\n\t\tif (!shouldHaveExtractedNationalPrefix(number, nationalNumber, metadata)) {\r\n\t\t\t// Don't strip the national prefix.\r\n\t\t\treturn { nationalNumber: number }\r\n\t\t}\r\n\t\t// Check the national (significant) number length after extracting national prefix and carrier code.\r\n\t\t// Legacy generated metadata (before `1.0.18`) didn't support the \"possible lengths\" feature.\r\n\t\tif (metadata.numberingPlan.possibleLengths()) {\r\n\t\t\t// If an exact `country` is not specified, attempt to detect it from the assumed national number.\r\n\t\t\tif (!country) {\r\n\t\t\t\tcountry = getCountryByCallingCode(metadata.numberingPlan.callingCode(), {\r\n\t\t\t\t\tnationalNumber,\r\n\t\t\t\t\tmetadata\r\n\t\t\t\t})\r\n\t\t\t}\r\n\r\n\t\t\t// The number remaining after stripping the national prefix and carrier code\r\n\t\t\t// should be long enough to have a possible length for the country.\r\n\t\t\t// Otherwise, don't strip the national prefix and carrier code,\r\n\t\t\t// since the original number could be a valid number.\r\n\t\t\t// This check has been copy-pasted \"as is\" from Google's original library:\r\n\t\t\t// https://github.com/google/libphonenumber/blob/876268eb1ad6cdc1b7b5bef17fc5e43052702d57/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java#L3236-L3250\r\n\t\t\t// It doesn't check for the \"possibility\" of the original `number`.\r\n\t\t\t// I guess it's fine not checking that one. It works as is anyway.\r\n\t\t\tif (!isPossibleIncompleteNationalNumber(nationalNumber, country, metadata)) {\r\n\t\t\t\t// Don't strip the national prefix.\r\n\t\t\t\treturn { nationalNumber: number }\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\treturn { nationalNumber, carrierCode }\r\n}\r\n\r\n// In some countries, the same digit could be a national prefix\r\n// or a leading digit of a valid phone number.\r\n// For example, in Russia, national prefix is `8`,\r\n// and also `800 555 35 35` is a valid number\r\n// in which `8` is not a national prefix, but the first digit\r\n// of a national (significant) number.\r\n// Same's with Belarus:\r\n// `82004910060` is a valid national (significant) number,\r\n// but `2004910060` is not.\r\n// To support such cases (to prevent the code from always stripping\r\n// national prefix), a condition is imposed: a national prefix\r\n// is not extracted when the original number is \"viable\" and the\r\n// resultant number is not, a \"viable\" national number being the one\r\n// that matches `national_number_pattern`.\r\nfunction shouldHaveExtractedNationalPrefix(nationalNumberBefore, nationalNumberAfter, metadata) {\r\n\t// The equivalent in Google's code is:\r\n\t// https://github.com/google/libphonenumber/blob/e326fa1fc4283bb05eb35cb3c15c18f98a31af33/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java#L2969-L3004\r\n\tif (matchesEntirely(nationalNumberBefore, metadata.nationalNumberPattern()) &&\r\n\t\t!matchesEntirely(nationalNumberAfter, metadata.nationalNumberPattern())) {\r\n\t\treturn false\r\n\t}\r\n\t// This \"is possible\" national number (length) check has been commented out\r\n\t// because it's superceded by the (effectively) same check done in the\r\n\t// `extractNationalNumber()` function after it calls `shouldHaveExtractedNationalPrefix()`.\r\n\t// In other words, why run the same check twice if it could only be run once.\r\n\t// // Check the national (significant) number length after extracting national prefix and carrier code.\r\n\t// // Fixes a minor \"weird behavior\" bug: https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/57\r\n\t// // (Legacy generated metadata (before `1.0.18`) didn't support the \"possible lengths\" feature).\r\n\t// if (metadata.possibleLengths()) {\r\n\t// \tif (isPossibleIncompleteNationalNumber(nationalNumberBefore, metadata) &&\r\n\t// \t\t!isPossibleIncompleteNationalNumber(nationalNumberAfter, metadata)) {\r\n\t// \t\treturn false\r\n\t// \t}\r\n\t// }\r\n\treturn true\r\n}\r\n\r\nfunction isPossibleIncompleteNationalNumber(nationalNumber, country, metadata) {\r\n\tswitch (checkNumberLength(nationalNumber, country, metadata)) {\r\n\t\tcase 'TOO_SHORT':\r\n\t\tcase 'INVALID_LENGTH':\r\n\t\t// This library ignores \"local-only\" phone numbers (for simplicity).\r\n\t\t// See the readme for more info on what are \"local-only\" phone numbers.\r\n\t\t// case 'IS_POSSIBLE_LOCAL_ONLY':\r\n\t\t\treturn false\r\n\t\tdefault:\r\n\t\t\treturn true\r\n\t}\r\n}"],"mappings":"AAAA,OAAOA,iDAAiD,MAAM,wDAAwD;AACtH,OAAOC,eAAe,MAAM,sBAAsB;AAClD,OAAOC,iBAAiB,MAAM,wBAAwB;AACtD,OAAOC,uBAAuB,MAAM,8BAA8B;;AAElE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,qBAAqBA,CAACC,MAAM,EAAEC,OAAO,EAAEC,QAAQ,EAAE;EACxE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,IAAAC,qBAAA,GAGIR,iDAAiD,CACpDK,MAAM,EACNE,QACD,CAAC;IALAE,WAAW,GAAAD,qBAAA,CAAXC,WAAW;IACXC,cAAc,GAAAF,qBAAA,CAAdE,cAAc;EAMf,IAAIA,cAAc,KAAKL,MAAM,EAAE;IAC9B,IAAI,CAACM,iCAAiC,CAACN,MAAM,EAAEK,cAAc,EAAEH,QAAQ,CAAC,EAAE;MACzE;MACA,OAAO;QAAEG,cAAc,EAAEL;MAAO,CAAC;IAClC;IACA;IACA;IACA,IAAIE,QAAQ,CAACK,aAAa,CAACC,eAAe,CAAC,CAAC,EAAE;MAC7C;MACA,IAAI,CAACP,OAAO,EAAE;QACbA,OAAO,GAAGH,uBAAuB,CAACI,QAAQ,CAACK,aAAa,CAACE,WAAW,CAAC,CAAC,EAAE;UACvEJ,cAAc,EAAdA,cAAc;UACdH,QAAQ,EAARA;QACD,CAAC,CAAC;MACH;;MAEA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA,IAAI,CAACQ,kCAAkC,CAACL,cAAc,EAAEJ,OAAO,EAAEC,QAAQ,CAAC,EAAE;QAC3E;QACA,OAAO;UAAEG,cAAc,EAAEL;QAAO,CAAC;MAClC;IACD;EACD;EAEA,OAAO;IAAEK,cAAc,EAAdA,cAAc;IAAED,WAAW,EAAXA;EAAY,CAAC;AACvC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASE,iCAAiCA,CAACK,oBAAoB,EAAEC,mBAAmB,EAAEV,QAAQ,EAAE;EAC/F;EACA;EACA,IAAIN,eAAe,CAACe,oBAAoB,EAAET,QAAQ,CAACW,qBAAqB,CAAC,CAAC,CAAC,IAC1E,CAACjB,eAAe,CAACgB,mBAAmB,EAAEV,QAAQ,CAACW,qBAAqB,CAAC,CAAC,CAAC,EAAE;IACzE,OAAO,KAAK;EACb;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,OAAO,IAAI;AACZ;AAEA,SAASH,kCAAkCA,CAACL,cAAc,EAAEJ,OAAO,EAAEC,QAAQ,EAAE;EAC9E,QAAQL,iBAAiB,CAACQ,cAAc,EAAEJ,OAAO,EAAEC,QAAQ,CAAC;IAC3D,KAAK,WAAW;IAChB,KAAK,gBAAgB;MACrB;MACA;MACA;MACC,OAAO,KAAK;IACb;MACC,OAAO,IAAI;EACb;AACD","ignoreList":[]}
1
+ {"version":3,"file":"extractNationalNumber.js","names":["extractNationalNumberFromPossiblyIncompleteNumber","matchesEntirely","checkNumberLength","getCountryByCallingCode","extractNationalNumber","number","country","metadata","_extractNationalNumbe","carrierCode","nationalNumber","shouldHaveExtractedNationalPrefix","numberingPlan","possibleLengths","callingCode","isPossibleIncompleteNationalNumber","nationalNumberBefore","nationalNumberAfter","nationalNumberPattern"],"sources":["../../source/helpers/extractNationalNumber.js"],"sourcesContent":["import extractNationalNumberFromPossiblyIncompleteNumber from './extractNationalNumberFromPossiblyIncompleteNumber.js'\r\nimport matchesEntirely from './matchesEntirely.js'\r\nimport checkNumberLength from './checkNumberLength.js'\r\nimport getCountryByCallingCode from './getCountryByCallingCode.js'\r\n\r\n/**\r\n * Strips national prefix and carrier code from a complete phone number.\r\n * The difference from the non-\"FromCompleteNumber\" function is that\r\n * it won't extract national prefix if the resultant number is too short\r\n * to be a complete number for the selected phone numbering plan.\r\n * @param {string} number — Complete phone number digits.\r\n * @param {string?} country — Specific country to use instead of the one that is pre-selected in the metadata instance.\r\n * @param {Metadata} metadata — Metadata instance with a selected numbering plan.\r\n * @return {object} `{ nationalNumber: string, carrierCode: string? }`.\r\n */\r\nexport default function extractNationalNumber(number, country, metadata) {\r\n\t// Parsing national prefixes and carrier codes\r\n\t// is only required for local phone numbers\r\n\t// but some people don't understand that\r\n\t// and sometimes write international phone numbers\r\n\t// with national prefixes (or maybe even carrier codes).\r\n\t// http://ucken.blogspot.ru/2016/03/trunk-prefixes-in-skype4b.html\r\n\t// Google's original library forgives such mistakes\r\n\t// and so does this library, because it has been requested:\r\n\t// https://github.com/catamphetamine/libphonenumber-js/issues/127\r\n\tconst {\r\n\t\tcarrierCode,\r\n\t\tnationalNumber\r\n\t} = extractNationalNumberFromPossiblyIncompleteNumber(\r\n\t\tnumber,\r\n\t\tmetadata\r\n\t)\r\n\r\n\tif (nationalNumber !== number) {\r\n\t\tif (!shouldHaveExtractedNationalPrefix(number, nationalNumber, metadata)) {\r\n\t\t\t// Don't strip the national prefix.\r\n\t\t\treturn { nationalNumber: number }\r\n\t\t}\r\n\t\t// Check the national (significant) number length after extracting national prefix and carrier code.\r\n\t\t// Legacy generated metadata (before `1.0.18`) didn't support the \"possible lengths\" feature,\r\n\t\t// so this `if` will only be executed with newer metadata.\r\n\t\tif (metadata.numberingPlan.possibleLengths()) {\r\n\t\t\t// If an exact `country` is not specified, attempt to detect it from the assumed national number.\r\n\t\t\tif (!country) {\r\n\t\t\t\tcountry = getCountryByCallingCode(metadata.numberingPlan.callingCode(), {\r\n\t\t\t\t\tnationalNumber,\r\n\t\t\t\t\tmetadata\r\n\t\t\t\t})\r\n\t\t\t}\r\n\r\n\t\t\t// The number remaining after stripping the national prefix and carrier code\r\n\t\t\t// should be long enough to have a possible length for the country.\r\n\t\t\t// Otherwise, don't strip the national prefix and carrier code,\r\n\t\t\t// since the original number could be a valid number.\r\n\t\t\t// This check has been copy-pasted \"as is\" from Google's original library:\r\n\t\t\t// https://github.com/google/libphonenumber/blob/876268eb1ad6cdc1b7b5bef17fc5e43052702d57/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java#L3236-L3250\r\n\t\t\t// It doesn't check for the \"possibility\" of the original `number`.\r\n\t\t\t// I guess it's fine not checking that one. It works as is anyway.\r\n\t\t\tif (!isPossibleIncompleteNationalNumber(nationalNumber, country, metadata)) {\r\n\t\t\t\t// Don't strip the national prefix.\r\n\t\t\t\treturn { nationalNumber: number }\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\treturn { nationalNumber, carrierCode }\r\n}\r\n\r\n// In some countries, the same digit could be a national prefix\r\n// or a leading digit of a valid phone number.\r\n// For example, in Russia, national prefix is `8`,\r\n// and also `800 555 35 35` is a valid number\r\n// in which `8` is not a national prefix, but the first digit\r\n// of a national (significant) number.\r\n// Same's with Belarus:\r\n// `82004910060` is a valid national (significant) number,\r\n// but `2004910060` is not.\r\n// To support such cases (to prevent the code from always stripping\r\n// national prefix), a condition is imposed: a national prefix\r\n// is not extracted when the original number is \"viable\" and the\r\n// resultant number is not, a \"viable\" national number being the one\r\n// that matches `national_number_pattern`.\r\nfunction shouldHaveExtractedNationalPrefix(nationalNumberBefore, nationalNumberAfter, metadata) {\r\n\t// The equivalent in Google's code is:\r\n\t// https://github.com/google/libphonenumber/blob/e326fa1fc4283bb05eb35cb3c15c18f98a31af33/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java#L2969-L3004\r\n\tif (matchesEntirely(nationalNumberBefore, metadata.nationalNumberPattern()) &&\r\n\t\t!matchesEntirely(nationalNumberAfter, metadata.nationalNumberPattern())) {\r\n\t\treturn false\r\n\t}\r\n\t// This \"is possible\" national number (length) check has been commented out\r\n\t// because it's superceded by the (effectively) same check done in the\r\n\t// `extractNationalNumber()` function after it calls `shouldHaveExtractedNationalPrefix()`.\r\n\t// In other words, why run the same check twice if it could only be run once.\r\n\t// // Check the national (significant) number length after extracting national prefix and carrier code.\r\n\t// // Fixes a minor \"weird behavior\" bug: https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/57\r\n\t// // (Legacy generated metadata (before `1.0.18`) didn't support the \"possible lengths\" feature).\r\n\t// if (metadata.possibleLengths()) {\r\n\t// \tif (isPossibleIncompleteNationalNumber(nationalNumberBefore, metadata) &&\r\n\t// \t\t!isPossibleIncompleteNationalNumber(nationalNumberAfter, metadata)) {\r\n\t// \t\treturn false\r\n\t// \t}\r\n\t// }\r\n\treturn true\r\n}\r\n\r\n/**\r\n * Tells if a given incomplete national number is possible or not.\r\n * @param {string} nationalNumber\r\n * @param {string?} country — Specific country rather than the one that is pre-selected in the metadata instance.\r\n * @param {Metadata} metadata — Metadata instance with a selected numbering plan.\r\n * @returns {boolean}\r\n */\r\nfunction isPossibleIncompleteNationalNumber(nationalNumber, country, metadata) {\r\n\tswitch (checkNumberLength(nationalNumber, country, metadata)) {\r\n\t\tcase 'TOO_SHORT':\r\n\t\tcase 'INVALID_LENGTH':\r\n\t\t// This library ignores \"local-only\" phone numbers (for simplicity).\r\n\t\t// See the readme for more info on what are \"local-only\" phone numbers.\r\n\t\t// case 'IS_POSSIBLE_LOCAL_ONLY':\r\n\t\t\treturn false\r\n\t\tdefault:\r\n\t\t\treturn true\r\n\t}\r\n}"],"mappings":"AAAA,OAAOA,iDAAiD,MAAM,wDAAwD;AACtH,OAAOC,eAAe,MAAM,sBAAsB;AAClD,OAAOC,iBAAiB,MAAM,wBAAwB;AACtD,OAAOC,uBAAuB,MAAM,8BAA8B;;AAElE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,qBAAqBA,CAACC,MAAM,EAAEC,OAAO,EAAEC,QAAQ,EAAE;EACxE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,IAAAC,qBAAA,GAGIR,iDAAiD,CACpDK,MAAM,EACNE,QACD,CAAC;IALAE,WAAW,GAAAD,qBAAA,CAAXC,WAAW;IACXC,cAAc,GAAAF,qBAAA,CAAdE,cAAc;EAMf,IAAIA,cAAc,KAAKL,MAAM,EAAE;IAC9B,IAAI,CAACM,iCAAiC,CAACN,MAAM,EAAEK,cAAc,EAAEH,QAAQ,CAAC,EAAE;MACzE;MACA,OAAO;QAAEG,cAAc,EAAEL;MAAO,CAAC;IAClC;IACA;IACA;IACA;IACA,IAAIE,QAAQ,CAACK,aAAa,CAACC,eAAe,CAAC,CAAC,EAAE;MAC7C;MACA,IAAI,CAACP,OAAO,EAAE;QACbA,OAAO,GAAGH,uBAAuB,CAACI,QAAQ,CAACK,aAAa,CAACE,WAAW,CAAC,CAAC,EAAE;UACvEJ,cAAc,EAAdA,cAAc;UACdH,QAAQ,EAARA;QACD,CAAC,CAAC;MACH;;MAEA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA,IAAI,CAACQ,kCAAkC,CAACL,cAAc,EAAEJ,OAAO,EAAEC,QAAQ,CAAC,EAAE;QAC3E;QACA,OAAO;UAAEG,cAAc,EAAEL;QAAO,CAAC;MAClC;IACD;EACD;EAEA,OAAO;IAAEK,cAAc,EAAdA,cAAc;IAAED,WAAW,EAAXA;EAAY,CAAC;AACvC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASE,iCAAiCA,CAACK,oBAAoB,EAAEC,mBAAmB,EAAEV,QAAQ,EAAE;EAC/F;EACA;EACA,IAAIN,eAAe,CAACe,oBAAoB,EAAET,QAAQ,CAACW,qBAAqB,CAAC,CAAC,CAAC,IAC1E,CAACjB,eAAe,CAACgB,mBAAmB,EAAEV,QAAQ,CAACW,qBAAqB,CAAC,CAAC,CAAC,EAAE;IACzE,OAAO,KAAK;EACb;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,OAAO,IAAI;AACZ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASH,kCAAkCA,CAACL,cAAc,EAAEJ,OAAO,EAAEC,QAAQ,EAAE;EAC9E,QAAQL,iBAAiB,CAACQ,cAAc,EAAEJ,OAAO,EAAEC,QAAQ,CAAC;IAC3D,KAAK,WAAW;IAChB,KAAK,gBAAgB;MACrB;MACA;MACA;MACC,OAAO,KAAK;IACb;MACC,OAAO,IAAI;EACb;AACD","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"extractNationalNumber.test.js","names":["describe","it","expect","extractNationalNumber","Metadata","oldMetadata","type","_oldMetadata","selectNumberingPlan","undefined","to","deep","equal","nationalNumber","carrierCode"],"sources":["../../source/helpers/extractNationalNumber.test.js"],"sourcesContent":["import { describe, it } from 'mocha'\r\nimport { expect } from 'chai'\r\n\r\nimport extractNationalNumber from './extractNationalNumber.js'\r\n\r\nimport Metadata from '../metadata.js'\r\nimport oldMetadata from '../../test/metadata/1.0.0/metadata.min.json' with { type: 'json' }\r\n\r\ndescribe('extractNationalNumber', function() {\r\n\tit('should extract a national number when using old metadata (no `country` or `defaultCountry` specified)', function() {\r\n\t\tconst _oldMetadata = new Metadata(oldMetadata)\r\n\t\t_oldMetadata.selectNumberingPlan('RU')\r\n\t\texpect(extractNationalNumber('88005553535', undefined, _oldMetadata)).to.deep.equal({\r\n\t\t\tnationalNumber: '8005553535',\r\n\t\t\tcarrierCode: undefined\r\n\t\t})\r\n\t})\r\n\r\n\tit('should extract a national number when using old metadata (`country` is specified)', function() {\r\n\t\tconst _oldMetadata = new Metadata(oldMetadata)\r\n\t\t_oldMetadata.selectNumberingPlan('RU')\r\n\t\texpect(extractNationalNumber('88005553535', 'RU', _oldMetadata)).to.deep.equal({\r\n\t\t\tnationalNumber: '8005553535',\r\n\t\t\tcarrierCode: undefined\r\n\t\t})\r\n\t})\r\n})"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,EAAE,QAAQ,OAAO;AACpC,SAASC,MAAM,QAAQ,MAAM;AAE7B,OAAOC,qBAAqB,MAAM,4BAA4B;AAE9D,OAAOC,QAAQ,MAAM,gBAAgB;AACrC,OAAOC,WAAW,MAAM,6CAA6C,QAAQC,IAAI,EAAE,MAAM;AAEzFN,QAAQ,CAAC,uBAAuB,EAAE,YAAW;EAC5CC,EAAE,CAAC,uGAAuG,EAAE,YAAW;IACtH,IAAMM,YAAY,GAAG,IAAIH,QAAQ,CAACC,WAAW,CAAC;IAC9CE,YAAY,CAACC,mBAAmB,CAAC,IAAI,CAAC;IACtCN,MAAM,CAACC,qBAAqB,CAAC,aAAa,EAAEM,SAAS,EAAEF,YAAY,CAAC,CAAC,CAACG,EAAE,CAACC,IAAI,CAACC,KAAK,CAAC;MACnFC,cAAc,EAAE,YAAY;MAC5BC,WAAW,EAAEL;IACd,CAAC,CAAC;EACH,CAAC,CAAC;EAEFR,EAAE,CAAC,mFAAmF,EAAE,YAAW;IAClG,IAAMM,YAAY,GAAG,IAAIH,QAAQ,CAACC,WAAW,CAAC;IAC9CE,YAAY,CAACC,mBAAmB,CAAC,IAAI,CAAC;IACtCN,MAAM,CAACC,qBAAqB,CAAC,aAAa,EAAE,IAAI,EAAEI,YAAY,CAAC,CAAC,CAACG,EAAE,CAACC,IAAI,CAACC,KAAK,CAAC;MAC9EC,cAAc,EAAE,YAAY;MAC5BC,WAAW,EAAEL;IACd,CAAC,CAAC;EACH,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"extractNationalNumber.test.js","names":["describe","it","expect","extractNationalNumber","Metadata","oldMetadata","type","oldMetadataInstance","selectNumberingPlan","undefined","to","deep","equal","nationalNumber","carrierCode"],"sources":["../../source/helpers/extractNationalNumber.test.js"],"sourcesContent":["import { describe, it } from 'mocha'\r\nimport { expect } from 'chai'\r\n\r\nimport extractNationalNumber from './extractNationalNumber.js'\r\n\r\nimport Metadata from '../metadata.js'\r\nimport oldMetadata from '../../test/metadata/1.0.0/metadata.min.json' with { type: 'json' }\r\n\r\ndescribe('extractNationalNumber', function() {\r\n\tit('should extract a national number when using old metadata (no `country` or `defaultCountry` specified)', function() {\r\n\t\tconst oldMetadataInstance = new Metadata(oldMetadata)\r\n\t\toldMetadataInstance.selectNumberingPlan('RU')\r\n\t\texpect(extractNationalNumber('88005553535', undefined, oldMetadataInstance)).to.deep.equal({\r\n\t\t\tnationalNumber: '8005553535',\r\n\t\t\tcarrierCode: undefined\r\n\t\t})\r\n\t})\r\n\r\n\tit('should extract a national number when using old metadata (`country` is specified)', function() {\r\n\t\tconst oldMetadataInstance = new Metadata(oldMetadata)\r\n\t\toldMetadataInstance.selectNumberingPlan('RU')\r\n\t\texpect(extractNationalNumber('88005553535', 'RU', oldMetadataInstance)).to.deep.equal({\r\n\t\t\tnationalNumber: '8005553535',\r\n\t\t\tcarrierCode: undefined\r\n\t\t})\r\n\t})\r\n})"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,EAAE,QAAQ,OAAO;AACpC,SAASC,MAAM,QAAQ,MAAM;AAE7B,OAAOC,qBAAqB,MAAM,4BAA4B;AAE9D,OAAOC,QAAQ,MAAM,gBAAgB;AACrC,OAAOC,WAAW,MAAM,6CAA6C,QAAQC,IAAI,EAAE,MAAM;AAEzFN,QAAQ,CAAC,uBAAuB,EAAE,YAAW;EAC5CC,EAAE,CAAC,uGAAuG,EAAE,YAAW;IACtH,IAAMM,mBAAmB,GAAG,IAAIH,QAAQ,CAACC,WAAW,CAAC;IACrDE,mBAAmB,CAACC,mBAAmB,CAAC,IAAI,CAAC;IAC7CN,MAAM,CAACC,qBAAqB,CAAC,aAAa,EAAEM,SAAS,EAAEF,mBAAmB,CAAC,CAAC,CAACG,EAAE,CAACC,IAAI,CAACC,KAAK,CAAC;MAC1FC,cAAc,EAAE,YAAY;MAC5BC,WAAW,EAAEL;IACd,CAAC,CAAC;EACH,CAAC,CAAC;EAEFR,EAAE,CAAC,mFAAmF,EAAE,YAAW;IAClG,IAAMM,mBAAmB,GAAG,IAAIH,QAAQ,CAACC,WAAW,CAAC;IACrDE,mBAAmB,CAACC,mBAAmB,CAAC,IAAI,CAAC;IAC7CN,MAAM,CAACC,qBAAqB,CAAC,aAAa,EAAE,IAAI,EAAEI,mBAAmB,CAAC,CAAC,CAACG,EAAE,CAACC,IAAI,CAACC,KAAK,CAAC;MACrFC,cAAc,EAAE,YAAY;MAC5BC,WAAW,EAAEL;IACd,CAAC,CAAC;EACH,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,28 @@
1
+ import Metadata from '../metadata.js';
2
+ import isCountryCode from './isCountryCode.js';
3
+ var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;
4
+ export default function getCountryAndCallingCodeFromOneOfThem(countryOrCallingCode, metadataJson) {
5
+ var country;
6
+ var callingCode;
7
+ var metadata = new Metadata(metadataJson);
8
+ // If country code is passed then derive `countryCallingCode` from it.
9
+ // Also store the country code as `.country`.
10
+ if (isCountryCode(countryOrCallingCode)) {
11
+ country = countryOrCallingCode;
12
+ metadata.selectNumberingPlan(country);
13
+ callingCode = metadata.countryCallingCode();
14
+ } else {
15
+ callingCode = countryOrCallingCode;
16
+ /* istanbul ignore if */
17
+ if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
18
+ if (metadata.isNonGeographicCallingCode(callingCode)) {
19
+ country = '001';
20
+ }
21
+ }
22
+ }
23
+ return {
24
+ country: country,
25
+ callingCode: callingCode
26
+ };
27
+ }
28
+ //# sourceMappingURL=getCountryAndCallingCodeFromOneOfThem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getCountryAndCallingCodeFromOneOfThem.js","names":["Metadata","isCountryCode","USE_NON_GEOGRAPHIC_COUNTRY_CODE","getCountryAndCallingCodeFromOneOfThem","countryOrCallingCode","metadataJson","country","callingCode","metadata","selectNumberingPlan","countryCallingCode","isNonGeographicCallingCode"],"sources":["../../source/helpers/getCountryAndCallingCodeFromOneOfThem.js"],"sourcesContent":["import Metadata from '../metadata.js'\r\nimport isCountryCode from './isCountryCode.js'\r\n\r\nconst USE_NON_GEOGRAPHIC_COUNTRY_CODE = false\r\n\r\nexport default function getCountryAndCallingCodeFromOneOfThem(countryOrCallingCode, metadataJson) {\r\n\tlet country\r\n\tlet callingCode\r\n\r\n\tconst metadata = new Metadata(metadataJson)\r\n\t// If country code is passed then derive `countryCallingCode` from it.\r\n\t// Also store the country code as `.country`.\r\n\tif (isCountryCode(countryOrCallingCode)) {\r\n\t\tcountry = countryOrCallingCode\r\n\t\tmetadata.selectNumberingPlan(country)\r\n\t\tcallingCode = metadata.countryCallingCode()\r\n\t} else {\r\n\t\tcallingCode = countryOrCallingCode\r\n\t\t/* istanbul ignore if */\r\n\t\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\t\tif (metadata.isNonGeographicCallingCode(callingCode)) {\r\n\t\t\t\tcountry = '001'\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\treturn {\r\n\t\tcountry,\r\n\t\tcallingCode\r\n\t}\r\n}"],"mappings":"AAAA,OAAOA,QAAQ,MAAM,gBAAgB;AACrC,OAAOC,aAAa,MAAM,oBAAoB;AAE9C,IAAMC,+BAA+B,GAAG,KAAK;AAE7C,eAAe,SAASC,qCAAqCA,CAACC,oBAAoB,EAAEC,YAAY,EAAE;EACjG,IAAIC,OAAO;EACX,IAAIC,WAAW;EAEf,IAAMC,QAAQ,GAAG,IAAIR,QAAQ,CAACK,YAAY,CAAC;EAC3C;EACA;EACA,IAAIJ,aAAa,CAACG,oBAAoB,CAAC,EAAE;IACxCE,OAAO,GAAGF,oBAAoB;IAC9BI,QAAQ,CAACC,mBAAmB,CAACH,OAAO,CAAC;IACrCC,WAAW,GAAGC,QAAQ,CAACE,kBAAkB,CAAC,CAAC;EAC5C,CAAC,MAAM;IACNH,WAAW,GAAGH,oBAAoB;IAClC;IACA,IAAIF,+BAA+B,EAAE;MACpC,IAAIM,QAAQ,CAACG,0BAA0B,CAACJ,WAAW,CAAC,EAAE;QACrDD,OAAO,GAAG,KAAK;MAChB;IACD;EACD;EAEA,OAAO;IACNA,OAAO,EAAPA,OAAO;IACPC,WAAW,EAAXA;EACD,CAAC;AACF","ignoreList":[]}
@@ -1,10 +1,16 @@
1
1
  import getCountryByNationalNumber from './getCountryByNationalNumber.js';
2
2
  var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;
3
3
 
4
- // Returns the exact country for the `nationalNumber`
5
- // that belongs to the specified "country calling code".
4
+ /**
5
+ * Returns the exact country that a given national (significant) number belongs to
6
+ * in case of ambiguity, i.e. when multiple countries share the same "country calling code".
7
+ * @param {string} [callingCode]
8
+ * @param {string} [options.nationalNumber] — National (significant) number.
9
+ * @param {Metadata} options.metadata — Metadata instance.
10
+ * @returns {string?} Returns the most suitable country for this calling code and national (significant) number.
11
+ */
6
12
  export default function getCountryByCallingCode(callingCode, _ref) {
7
- var nationalPhoneNumber = _ref.nationalNumber,
13
+ var nationalNumber = _ref.nationalNumber,
8
14
  metadata = _ref.metadata;
9
15
  /* istanbul ignore if */
10
16
  if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
@@ -21,9 +27,6 @@ export default function getCountryByCallingCode(callingCode, _ref) {
21
27
  if (possibleCountries.length === 1) {
22
28
  return possibleCountries[0];
23
29
  }
24
- return getCountryByNationalNumber(nationalPhoneNumber, {
25
- countries: possibleCountries,
26
- metadata: metadata.metadata
27
- });
30
+ return getCountryByNationalNumber(nationalNumber, possibleCountries, metadata.metadata);
28
31
  }
29
32
  //# sourceMappingURL=getCountryByCallingCode.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getCountryByCallingCode.js","names":["getCountryByNationalNumber","USE_NON_GEOGRAPHIC_COUNTRY_CODE","getCountryByCallingCode","callingCode","_ref","nationalPhoneNumber","nationalNumber","metadata","isNonGeographicCallingCode","possibleCountries","getCountryCodesForCallingCode","length","countries"],"sources":["../../source/helpers/getCountryByCallingCode.js"],"sourcesContent":["import getCountryByNationalNumber from './getCountryByNationalNumber.js'\r\n\r\nconst USE_NON_GEOGRAPHIC_COUNTRY_CODE = false\r\n\r\n// Returns the exact country for the `nationalNumber`\r\n// that belongs to the specified \"country calling code\".\r\nexport default function getCountryByCallingCode(callingCode, {\r\n\tnationalNumber: nationalPhoneNumber,\r\n\tmetadata\r\n}) {\r\n\t/* istanbul ignore if */\r\n\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\tif (metadata.isNonGeographicCallingCode(callingCode)) {\r\n\t\t\treturn '001'\r\n\t\t}\r\n\t}\r\n\tconst possibleCountries = metadata.getCountryCodesForCallingCode(callingCode)\r\n\tif (!possibleCountries) {\r\n\t\treturn\r\n\t}\r\n\t// If there's just one country corresponding to the country code,\r\n\t// then just return it, without further phone number digits validation.\r\n\tif (possibleCountries.length === 1) {\r\n\t\treturn possibleCountries[0]\r\n\t}\r\n\treturn getCountryByNationalNumber(nationalPhoneNumber, {\r\n\t\tcountries: possibleCountries,\r\n\t\tmetadata: metadata.metadata\r\n\t})\r\n}"],"mappings":"AAAA,OAAOA,0BAA0B,MAAM,iCAAiC;AAExE,IAAMC,+BAA+B,GAAG,KAAK;;AAE7C;AACA;AACA,eAAe,SAASC,uBAAuBA,CAACC,WAAW,EAAAC,IAAA,EAGxD;EAAA,IAFcC,mBAAmB,GAAAD,IAAA,CAAnCE,cAAc;IACdC,QAAQ,GAAAH,IAAA,CAARG,QAAQ;EAER;EACA,IAAIN,+BAA+B,EAAE;IACpC,IAAIM,QAAQ,CAACC,0BAA0B,CAACL,WAAW,CAAC,EAAE;MACrD,OAAO,KAAK;IACb;EACD;EACA,IAAMM,iBAAiB,GAAGF,QAAQ,CAACG,6BAA6B,CAACP,WAAW,CAAC;EAC7E,IAAI,CAACM,iBAAiB,EAAE;IACvB;EACD;EACA;EACA;EACA,IAAIA,iBAAiB,CAACE,MAAM,KAAK,CAAC,EAAE;IACnC,OAAOF,iBAAiB,CAAC,CAAC,CAAC;EAC5B;EACA,OAAOT,0BAA0B,CAACK,mBAAmB,EAAE;IACtDO,SAAS,EAAEH,iBAAiB;IAC5BF,QAAQ,EAAEA,QAAQ,CAACA;EACpB,CAAC,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"getCountryByCallingCode.js","names":["getCountryByNationalNumber","USE_NON_GEOGRAPHIC_COUNTRY_CODE","getCountryByCallingCode","callingCode","_ref","nationalNumber","metadata","isNonGeographicCallingCode","possibleCountries","getCountryCodesForCallingCode","length"],"sources":["../../source/helpers/getCountryByCallingCode.js"],"sourcesContent":["import getCountryByNationalNumber from './getCountryByNationalNumber.js'\r\n\r\nconst USE_NON_GEOGRAPHIC_COUNTRY_CODE = false\r\n\r\n/**\r\n * Returns the exact country that a given national (significant) number belongs to\r\n * in case of ambiguity, i.e. when multiple countries share the same \"country calling code\".\r\n * @param {string} [callingCode]\r\n * @param {string} [options.nationalNumber] — National (significant) number.\r\n * @param {Metadata} options.metadata — Metadata instance.\r\n * @returns {string?} Returns the most suitable country for this calling code and national (significant) number.\r\n */\r\nexport default function getCountryByCallingCode(callingCode, {\r\n\tnationalNumber,\r\n\tmetadata\r\n}) {\r\n\t/* istanbul ignore if */\r\n\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\tif (metadata.isNonGeographicCallingCode(callingCode)) {\r\n\t\t\treturn '001'\r\n\t\t}\r\n\t}\r\n\tconst possibleCountries = metadata.getCountryCodesForCallingCode(callingCode)\r\n\tif (!possibleCountries) {\r\n\t\treturn\r\n\t}\r\n\t// If there's just one country corresponding to the country code,\r\n\t// then just return it, without further phone number digits validation.\r\n\tif (possibleCountries.length === 1) {\r\n\t\treturn possibleCountries[0]\r\n\t}\r\n\treturn getCountryByNationalNumber(nationalNumber, possibleCountries, metadata.metadata)\r\n}"],"mappings":"AAAA,OAAOA,0BAA0B,MAAM,iCAAiC;AAExE,IAAMC,+BAA+B,GAAG,KAAK;;AAE7C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,uBAAuBA,CAACC,WAAW,EAAAC,IAAA,EAGxD;EAAA,IAFFC,cAAc,GAAAD,IAAA,CAAdC,cAAc;IACdC,QAAQ,GAAAF,IAAA,CAARE,QAAQ;EAER;EACA,IAAIL,+BAA+B,EAAE;IACpC,IAAIK,QAAQ,CAACC,0BAA0B,CAACJ,WAAW,CAAC,EAAE;MACrD,OAAO,KAAK;IACb;EACD;EACA,IAAMK,iBAAiB,GAAGF,QAAQ,CAACG,6BAA6B,CAACN,WAAW,CAAC;EAC7E,IAAI,CAACK,iBAAiB,EAAE;IACvB;EACD;EACA;EACA;EACA,IAAIA,iBAAiB,CAACE,MAAM,KAAK,CAAC,EAAE;IACnC,OAAOF,iBAAiB,CAAC,CAAC,CAAC;EAC5B;EACA,OAAOR,0BAA0B,CAACK,cAAc,EAAEG,iBAAiB,EAAEF,QAAQ,CAACA,QAAQ,CAAC;AACxF","ignoreList":[]}
@@ -4,13 +4,17 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
4
4
  import Metadata from '../metadata.js';
5
5
  import getNumberType from './getNumberType.js';
6
6
 
7
- // Returns the exact country that the `nationalPhoneNumber` belongs to
8
- // in cases of ambiguity, i.e. when multiple countries share the same "country calling code".
9
- export default function getCountryByNationalNumber(nationalPhoneNumber, _ref) {
10
- var countries = _ref.countries,
11
- metadata = _ref.metadata;
12
- // Re-create `metadata` because it will be selecting a `country`.
13
- metadata = new Metadata(metadata);
7
+ /**
8
+ * Returns the exact country that a given national (significant) number belongs to
9
+ * in case of ambiguity, i.e. when multiple countries share the same "country calling code".
10
+ * @param {string} [nationalNumber]
11
+ * @param {string[]} countries — A list of countries that share the same calling code.
12
+ * @param {object} metadata — Metadata JSON.
13
+ * @returns {string?} Returns the exact country this number belongs to, or `undefined` if the exact country couldn't be determined.
14
+ */
15
+ export default function getCountryByNationalNumber(nationalNumber, countries, metadataJson) {
16
+ // Create a new `metadata` instance because it will be selecting a `country`.
17
+ var metadata = new Metadata(metadataJson);
14
18
 
15
19
  // const matchingCountries = []
16
20
 
@@ -25,14 +29,14 @@ export default function getCountryByNationalNumber(nationalPhoneNumber, _ref) {
25
29
  // I'd suppose that "leading digits" patterns are mutually exclusive for different countries
26
30
  // because of the intended use of that feature.
27
31
  if (metadata.leadingDigits()) {
28
- if (nationalPhoneNumber && nationalPhoneNumber.search(metadata.leadingDigits()) === 0) {
32
+ if (nationalNumber && nationalNumber.search(metadata.leadingDigits()) === 0) {
29
33
  return country;
30
34
  }
31
35
  }
32
36
  // Else perform full validation with all of those
33
37
  // fixed-line/mobile/etc regular expressions.
34
38
  else if (getNumberType({
35
- phone: nationalPhoneNumber,
39
+ phone: nationalNumber,
36
40
  country: country
37
41
  }, undefined, metadata.metadata)) {
38
42
  // When multiple countries share the same "country calling code",
@@ -1 +1 @@
1
- {"version":3,"file":"getCountryByNationalNumber.js","names":["Metadata","getNumberType","getCountryByNationalNumber","nationalPhoneNumber","_ref","countries","metadata","_iterator","_createForOfIteratorHelperLoose","_step","done","country","value","selectNumberingPlan","leadingDigits","search","phone","undefined"],"sources":["../../source/helpers/getCountryByNationalNumber.js"],"sourcesContent":["import Metadata from '../metadata.js'\r\nimport getNumberType from './getNumberType.js'\r\n\r\n// Returns the exact country that the `nationalPhoneNumber` belongs to\r\n// in cases of ambiguity, i.e. when multiple countries share the same \"country calling code\".\r\nexport default function getCountryByNationalNumber(nationalPhoneNumber, {\r\n\tcountries,\r\n\tmetadata\r\n}) {\r\n\t// Re-create `metadata` because it will be selecting a `country`.\r\n\tmetadata = new Metadata(metadata)\r\n\r\n\t// const matchingCountries = []\r\n\r\n\tfor (const country of countries) {\r\n\t\tmetadata.selectNumberingPlan(country)\r\n\t\t// \"Leading digits\" patterns are only defined for about 20% of all countries.\r\n\t\t// By definition, matching \"leading digits\" is a sufficient but not a necessary\r\n\t\t// condition for a phone number to belong to a country.\r\n\t\t// The point of \"leading digits\" check is that it's the fastest one to get a match.\r\n\t\t// https://gitlab.com/catamphetamine/libphonenumber-js/blob/master/METADATA.md#leading_digits\r\n\t\t// I'd suppose that \"leading digits\" patterns are mutually exclusive for different countries\r\n\t\t// because of the intended use of that feature.\r\n\t\tif (metadata.leadingDigits()) {\r\n\t\t\tif (nationalPhoneNumber &&\r\n\t\t\t\tnationalPhoneNumber.search(metadata.leadingDigits()) === 0) {\r\n\t\t\t\treturn country\r\n\t\t\t}\r\n\t\t}\r\n\t\t// Else perform full validation with all of those\r\n\t\t// fixed-line/mobile/etc regular expressions.\r\n\t\telse if (getNumberType({ phone: nationalPhoneNumber, country }, undefined, metadata.metadata)) {\r\n\t\t\t// When multiple countries share the same \"country calling code\",\r\n\t\t\t// type patterns aren't guaranteed to be unique among them.\r\n\t\t\t// For example, both `US` and `CA` have the same pattern for `toll_free` numbers.\r\n\t\t\t// https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/103#note_1417147572\r\n\t\t\t//\r\n\t\t\t// That means that this `if` condition could be `true` for multiple countries from the list.\r\n\t\t\t// Currently, it just returns the first one, which is also the \"main\" country for the \"country calling code\".\r\n\t\t\t// In an example with `toll_free` numbers above, `\"US\"` would be returned even though\r\n\t\t\t// it could as well be `\"CA\"`.\r\n\t\t\t//\r\n\t\t\t// There was also a time when this attempted to be overly smart\r\n\t\t\t// and kept track of all such multiple matching countries\r\n\t\t\t// and then picked the one that matched the `defaultCountry`, if provided.\r\n\t\t\t// For example, with `toll_free` numbers above, and with `defaultCountry: \"CA\"`,\r\n\t\t\t// it would've returned `\"CA\"` instead of `\"US\"`.\r\n\t\t\t// Later it turned out that such \"overly smart\" behavior turned out to be just confusing,\r\n\t\t\t// so this \"overly smart\" country detection was reverted to returning the \"main\" country\r\n\t\t\t// for the \"country calling code\".\r\n\t\t\t// https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/154\r\n\t\t\t//\r\n\t\t\treturn country\r\n\t\t\t//\r\n\t\t\t// The \"overly smart\" behavior code:\r\n\t\t\t//\r\n\t\t\t// if (defaultCountry) {\r\n\t\t\t// \tif (country === defaultCountry) {\r\n\t\t\t// \t\treturn country\r\n\t\t\t// \t} else {\r\n\t\t\t// \t\tmatchingCountries.push(country)\r\n\t\t\t// \t}\r\n\t\t\t// } else {\r\n\t\t\t// \treturn country\r\n\t\t\t// }\r\n\t\t}\r\n\t}\r\n\r\n\t// // Return the first (\"main\") one of the `matchingCountries`.\r\n\t// if (matchingCountries.length > 0) {\r\n\t// \treturn matchingCountries[0]\r\n\t// }\r\n}"],"mappings":";;;AAAA,OAAOA,QAAQ,MAAM,gBAAgB;AACrC,OAAOC,aAAa,MAAM,oBAAoB;;AAE9C;AACA;AACA,eAAe,SAASC,0BAA0BA,CAACC,mBAAmB,EAAAC,IAAA,EAGnE;EAAA,IAFFC,SAAS,GAAAD,IAAA,CAATC,SAAS;IACTC,QAAQ,GAAAF,IAAA,CAARE,QAAQ;EAER;EACAA,QAAQ,GAAG,IAAIN,QAAQ,CAACM,QAAQ,CAAC;;EAEjC;;EAEA,SAAAC,SAAA,GAAAC,+BAAA,CAAsBH,SAAS,GAAAI,KAAA,IAAAA,KAAA,GAAAF,SAAA,IAAAG,IAAA,GAAE;IAAA,IAAtBC,OAAO,GAAAF,KAAA,CAAAG,KAAA;IACjBN,QAAQ,CAACO,mBAAmB,CAACF,OAAO,CAAC;IACrC;IACA;IACA;IACA;IACA;IACA;IACA;IACA,IAAIL,QAAQ,CAACQ,aAAa,CAAC,CAAC,EAAE;MAC7B,IAAIX,mBAAmB,IACtBA,mBAAmB,CAACY,MAAM,CAACT,QAAQ,CAACQ,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE;QAC5D,OAAOH,OAAO;MACf;IACD;IACA;IACA;IAAA,KACK,IAAIV,aAAa,CAAC;MAAEe,KAAK,EAAEb,mBAAmB;MAAEQ,OAAO,EAAPA;IAAQ,CAAC,EAAEM,SAAS,EAAEX,QAAQ,CAACA,QAAQ,CAAC,EAAE;MAC9F;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA,OAAOK,OAAO;MACd;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;IACD;EACD;;EAEA;EACA;EACA;EACA;AACD","ignoreList":[]}
1
+ {"version":3,"file":"getCountryByNationalNumber.js","names":["Metadata","getNumberType","getCountryByNationalNumber","nationalNumber","countries","metadataJson","metadata","_iterator","_createForOfIteratorHelperLoose","_step","done","country","value","selectNumberingPlan","leadingDigits","search","phone","undefined"],"sources":["../../source/helpers/getCountryByNationalNumber.js"],"sourcesContent":["import Metadata from '../metadata.js'\r\nimport getNumberType from './getNumberType.js'\r\n\r\n/**\r\n * Returns the exact country that a given national (significant) number belongs to\r\n * in case of ambiguity, i.e. when multiple countries share the same \"country calling code\".\r\n * @param {string} [nationalNumber]\r\n * @param {string[]} countries — A list of countries that share the same calling code.\r\n * @param {object} metadata — Metadata JSON.\r\n * @returns {string?} Returns the exact country this number belongs to, or `undefined` if the exact country couldn't be determined.\r\n */\r\nexport default function getCountryByNationalNumber(nationalNumber, countries, metadataJson) {\r\n\t// Create a new `metadata` instance because it will be selecting a `country`.\r\n\tconst metadata = new Metadata(metadataJson)\r\n\r\n\t// const matchingCountries = []\r\n\r\n\tfor (const country of countries) {\r\n\t\tmetadata.selectNumberingPlan(country)\r\n\t\t// \"Leading digits\" patterns are only defined for about 20% of all countries.\r\n\t\t// By definition, matching \"leading digits\" is a sufficient but not a necessary\r\n\t\t// condition for a phone number to belong to a country.\r\n\t\t// The point of \"leading digits\" check is that it's the fastest one to get a match.\r\n\t\t// https://gitlab.com/catamphetamine/libphonenumber-js/blob/master/METADATA.md#leading_digits\r\n\t\t// I'd suppose that \"leading digits\" patterns are mutually exclusive for different countries\r\n\t\t// because of the intended use of that feature.\r\n\t\tif (metadata.leadingDigits()) {\r\n\t\t\tif (nationalNumber &&\r\n\t\t\t\tnationalNumber.search(metadata.leadingDigits()) === 0) {\r\n\t\t\t\treturn country\r\n\t\t\t}\r\n\t\t}\r\n\t\t// Else perform full validation with all of those\r\n\t\t// fixed-line/mobile/etc regular expressions.\r\n\t\telse if (getNumberType({ phone: nationalNumber, country }, undefined, metadata.metadata)) {\r\n\t\t\t// When multiple countries share the same \"country calling code\",\r\n\t\t\t// type patterns aren't guaranteed to be unique among them.\r\n\t\t\t// For example, both `US` and `CA` have the same pattern for `toll_free` numbers.\r\n\t\t\t// https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/103#note_1417147572\r\n\t\t\t//\r\n\t\t\t// That means that this `if` condition could be `true` for multiple countries from the list.\r\n\t\t\t// Currently, it just returns the first one, which is also the \"main\" country for the \"country calling code\".\r\n\t\t\t// In an example with `toll_free` numbers above, `\"US\"` would be returned even though\r\n\t\t\t// it could as well be `\"CA\"`.\r\n\t\t\t//\r\n\t\t\t// There was also a time when this attempted to be overly smart\r\n\t\t\t// and kept track of all such multiple matching countries\r\n\t\t\t// and then picked the one that matched the `defaultCountry`, if provided.\r\n\t\t\t// For example, with `toll_free` numbers above, and with `defaultCountry: \"CA\"`,\r\n\t\t\t// it would've returned `\"CA\"` instead of `\"US\"`.\r\n\t\t\t// Later it turned out that such \"overly smart\" behavior turned out to be just confusing,\r\n\t\t\t// so this \"overly smart\" country detection was reverted to returning the \"main\" country\r\n\t\t\t// for the \"country calling code\".\r\n\t\t\t// https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/154\r\n\t\t\t//\r\n\t\t\treturn country\r\n\t\t\t//\r\n\t\t\t// The \"overly smart\" behavior code:\r\n\t\t\t//\r\n\t\t\t// if (defaultCountry) {\r\n\t\t\t// \tif (country === defaultCountry) {\r\n\t\t\t// \t\treturn country\r\n\t\t\t// \t} else {\r\n\t\t\t// \t\tmatchingCountries.push(country)\r\n\t\t\t// \t}\r\n\t\t\t// } else {\r\n\t\t\t// \treturn country\r\n\t\t\t// }\r\n\t\t}\r\n\t}\r\n\r\n\t// // Return the first (\"main\") one of the `matchingCountries`.\r\n\t// if (matchingCountries.length > 0) {\r\n\t// \treturn matchingCountries[0]\r\n\t// }\r\n}"],"mappings":";;;AAAA,OAAOA,QAAQ,MAAM,gBAAgB;AACrC,OAAOC,aAAa,MAAM,oBAAoB;;AAE9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,0BAA0BA,CAACC,cAAc,EAAEC,SAAS,EAAEC,YAAY,EAAE;EAC3F;EACA,IAAMC,QAAQ,GAAG,IAAIN,QAAQ,CAACK,YAAY,CAAC;;EAE3C;;EAEA,SAAAE,SAAA,GAAAC,+BAAA,CAAsBJ,SAAS,GAAAK,KAAA,IAAAA,KAAA,GAAAF,SAAA,IAAAG,IAAA,GAAE;IAAA,IAAtBC,OAAO,GAAAF,KAAA,CAAAG,KAAA;IACjBN,QAAQ,CAACO,mBAAmB,CAACF,OAAO,CAAC;IACrC;IACA;IACA;IACA;IACA;IACA;IACA;IACA,IAAIL,QAAQ,CAACQ,aAAa,CAAC,CAAC,EAAE;MAC7B,IAAIX,cAAc,IACjBA,cAAc,CAACY,MAAM,CAACT,QAAQ,CAACQ,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE;QACvD,OAAOH,OAAO;MACf;IACD;IACA;IACA;IAAA,KACK,IAAIV,aAAa,CAAC;MAAEe,KAAK,EAAEb,cAAc;MAAEQ,OAAO,EAAPA;IAAQ,CAAC,EAAEM,SAAS,EAAEX,QAAQ,CAACA,QAAQ,CAAC,EAAE;MACzF;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA,OAAOK,OAAO;MACd;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;IACD;EACD;;EAEA;EACA;EACA;EACA;AACD","ignoreList":[]}
@@ -15,7 +15,7 @@ var SINGLE_IDD_PREFIX_REG_EXP = /^[\d]+(?:[~\u2053\u223C\uFF5E][\d]+)?$/;
15
15
  // If the `country` doesn't support IDD calling, it returns `undefined`.
16
16
  export default function getIddPrefix(country, callingCode, metadata) {
17
17
  var countryMetadata = new Metadata(metadata);
18
- countryMetadata.selectNumberingPlan(country, callingCode);
18
+ countryMetadata.selectNumberingPlan(country || callingCode);
19
19
  if (countryMetadata.defaultIDDPrefix()) {
20
20
  return countryMetadata.defaultIDDPrefix();
21
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"getIddPrefix.js","names":["Metadata","SINGLE_IDD_PREFIX_REG_EXP","getIddPrefix","country","callingCode","metadata","countryMetadata","selectNumberingPlan","defaultIDDPrefix","test","IDDPrefix"],"sources":["../../source/helpers/getIddPrefix.js"],"sourcesContent":["import Metadata from '../metadata.js'\r\n\r\n/**\r\n * Pattern that makes it easy to distinguish whether a region has a single\r\n * international dialing prefix or not. If a region has a single international\r\n * prefix (e.g. 011 in USA), it will be represented as a string that contains\r\n * a sequence of ASCII digits, and possibly a tilde, which signals waiting for\r\n * the tone. If there are multiple available international prefixes in a\r\n * region, they will be represented as a regex string that always contains one\r\n * or more characters that are not ASCII digits or a tilde.\r\n */\r\nconst SINGLE_IDD_PREFIX_REG_EXP = /^[\\d]+(?:[~\\u2053\\u223C\\uFF5E][\\d]+)?$/\r\n\r\n// If the `country` supports IDD calling, it returns a preferred IDD prefix.\r\n// If the `country` doesn't support IDD calling, it returns `undefined`.\r\nexport default function getIddPrefix(country, callingCode, metadata) {\r\n\tconst countryMetadata = new Metadata(metadata)\r\n\tcountryMetadata.selectNumberingPlan(country, callingCode)\r\n\tif (countryMetadata.defaultIDDPrefix()) {\r\n\t\treturn countryMetadata.defaultIDDPrefix()\r\n\t}\r\n\tif (SINGLE_IDD_PREFIX_REG_EXP.test(countryMetadata.IDDPrefix())) {\r\n\t\treturn countryMetadata.IDDPrefix()\r\n\t}\r\n}\r\n"],"mappings":"AAAA,OAAOA,QAAQ,MAAM,gBAAgB;;AAErC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMC,yBAAyB,GAAG,wCAAwC;;AAE1E;AACA;AACA,eAAe,SAASC,YAAYA,CAACC,OAAO,EAAEC,WAAW,EAAEC,QAAQ,EAAE;EACpE,IAAMC,eAAe,GAAG,IAAIN,QAAQ,CAACK,QAAQ,CAAC;EAC9CC,eAAe,CAACC,mBAAmB,CAACJ,OAAO,EAAEC,WAAW,CAAC;EACzD,IAAIE,eAAe,CAACE,gBAAgB,CAAC,CAAC,EAAE;IACvC,OAAOF,eAAe,CAACE,gBAAgB,CAAC,CAAC;EAC1C;EACA,IAAIP,yBAAyB,CAACQ,IAAI,CAACH,eAAe,CAACI,SAAS,CAAC,CAAC,CAAC,EAAE;IAChE,OAAOJ,eAAe,CAACI,SAAS,CAAC,CAAC;EACnC;AACD","ignoreList":[]}
1
+ {"version":3,"file":"getIddPrefix.js","names":["Metadata","SINGLE_IDD_PREFIX_REG_EXP","getIddPrefix","country","callingCode","metadata","countryMetadata","selectNumberingPlan","defaultIDDPrefix","test","IDDPrefix"],"sources":["../../source/helpers/getIddPrefix.js"],"sourcesContent":["import Metadata from '../metadata.js'\r\n\r\n/**\r\n * Pattern that makes it easy to distinguish whether a region has a single\r\n * international dialing prefix or not. If a region has a single international\r\n * prefix (e.g. 011 in USA), it will be represented as a string that contains\r\n * a sequence of ASCII digits, and possibly a tilde, which signals waiting for\r\n * the tone. If there are multiple available international prefixes in a\r\n * region, they will be represented as a regex string that always contains one\r\n * or more characters that are not ASCII digits or a tilde.\r\n */\r\nconst SINGLE_IDD_PREFIX_REG_EXP = /^[\\d]+(?:[~\\u2053\\u223C\\uFF5E][\\d]+)?$/\r\n\r\n// If the `country` supports IDD calling, it returns a preferred IDD prefix.\r\n// If the `country` doesn't support IDD calling, it returns `undefined`.\r\nexport default function getIddPrefix(country, callingCode, metadata) {\r\n\tconst countryMetadata = new Metadata(metadata)\r\n\tcountryMetadata.selectNumberingPlan(country || callingCode)\r\n\tif (countryMetadata.defaultIDDPrefix()) {\r\n\t\treturn countryMetadata.defaultIDDPrefix()\r\n\t}\r\n\tif (SINGLE_IDD_PREFIX_REG_EXP.test(countryMetadata.IDDPrefix())) {\r\n\t\treturn countryMetadata.IDDPrefix()\r\n\t}\r\n}\r\n"],"mappings":"AAAA,OAAOA,QAAQ,MAAM,gBAAgB;;AAErC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMC,yBAAyB,GAAG,wCAAwC;;AAE1E;AACA;AACA,eAAe,SAASC,YAAYA,CAACC,OAAO,EAAEC,WAAW,EAAEC,QAAQ,EAAE;EACpE,IAAMC,eAAe,GAAG,IAAIN,QAAQ,CAACK,QAAQ,CAAC;EAC9CC,eAAe,CAACC,mBAAmB,CAACJ,OAAO,IAAIC,WAAW,CAAC;EAC3D,IAAIE,eAAe,CAACE,gBAAgB,CAAC,CAAC,EAAE;IACvC,OAAOF,eAAe,CAACE,gBAAgB,CAAC,CAAC;EAC1C;EACA,IAAIP,yBAAyB,CAACQ,IAAI,CAACH,eAAe,CAACI,SAAS,CAAC,CAAC,CAAC,EAAE;IAChE,OAAOJ,eAAe,CAACI,SAAS,CAAC,CAAC;EACnC;AACD","ignoreList":[]}
@@ -6,7 +6,7 @@ import matchesEntirely from './matchesEntirely.js';
6
6
  var NON_FIXED_LINE_PHONE_TYPES = ['MOBILE', 'PREMIUM_RATE', 'TOLL_FREE', 'SHARED_COST', 'VOIP', 'PERSONAL_NUMBER', 'PAGER', 'UAN', 'VOICEMAIL'];
7
7
 
8
8
  // Finds out national phone number type (fixed line, mobile, etc)
9
- export default function getNumberType(input, options, metadata) {
9
+ export default function getNumberType(input, options, metadataJson) {
10
10
  // If assigning the `{}` default value is moved to the arguments above,
11
11
  // code coverage would decrease for some weird reason.
12
12
  options = options || {};
@@ -17,8 +17,8 @@ export default function getNumberType(input, options, metadata) {
17
17
  if (!input.country && !input.countryCallingCode) {
18
18
  return;
19
19
  }
20
- metadata = new Metadata(metadata);
21
- metadata.selectNumberingPlan(input.country, input.countryCallingCode);
20
+ var metadata = new Metadata(metadataJson);
21
+ metadata.selectNumberingPlan(input.country || input.countryCallingCode);
22
22
  var nationalNumber = options.v2 ? input.nationalNumber : input.phone;
23
23
 
24
24
  // The following is copy-pasted from the original function:
@@ -1 +1 @@
1
- {"version":3,"file":"getNumberType.js","names":["Metadata","matchesEntirely","NON_FIXED_LINE_PHONE_TYPES","getNumberType","input","options","metadata","country","countryCallingCode","selectNumberingPlan","nationalNumber","v2","phone","nationalNumberPattern","isNumberTypeEqualTo","type","pattern","_iterator","_createForOfIteratorHelperLoose","_step","done","value","typeDefinition","possibleLengths","indexOf","length"],"sources":["../../source/helpers/getNumberType.js"],"sourcesContent":["import Metadata from '../metadata.js'\r\nimport matchesEntirely from './matchesEntirely.js'\r\n\r\nconst NON_FIXED_LINE_PHONE_TYPES = [\r\n\t'MOBILE',\r\n\t'PREMIUM_RATE',\r\n\t'TOLL_FREE',\r\n\t'SHARED_COST',\r\n\t'VOIP',\r\n\t'PERSONAL_NUMBER',\r\n\t'PAGER',\r\n\t'UAN',\r\n\t'VOICEMAIL'\r\n]\r\n\r\n// Finds out national phone number type (fixed line, mobile, etc)\r\nexport default function getNumberType(input, options, metadata)\r\n{\r\n\t// If assigning the `{}` default value is moved to the arguments above,\r\n\t// code coverage would decrease for some weird reason.\r\n\toptions = options || {}\r\n\r\n\t// When `parse()` returns an empty object — `{}` —\r\n\t// that means that the phone number is malformed,\r\n\t// so it can't possibly be valid.\r\n\tif (!input.country && !input.countryCallingCode) {\r\n\t\treturn\r\n\t}\r\n\r\n\tmetadata = new Metadata(metadata)\r\n\r\n\tmetadata.selectNumberingPlan(input.country, input.countryCallingCode)\r\n\r\n\tconst nationalNumber = options.v2 ? input.nationalNumber : input.phone\r\n\r\n\t// The following is copy-pasted from the original function:\r\n\t// https://github.com/googlei18n/libphonenumber/blob/3ea547d4fbaa2d0b67588904dfa5d3f2557c27ff/javascript/i18n/phonenumbers/phonenumberutil.js#L2835\r\n\r\n\t// Is this national number even valid for this country\r\n\tif (!matchesEntirely(nationalNumber, metadata.nationalNumberPattern())) {\r\n\t\treturn\r\n\t}\r\n\r\n\t// Is it fixed line number\r\n\tif (isNumberTypeEqualTo(nationalNumber, 'FIXED_LINE', metadata)) {\r\n\t\t// Because duplicate regular expressions are removed\r\n\t\t// to reduce metadata size, if \"mobile\" pattern is \"\"\r\n\t\t// then it means it was removed due to being a duplicate of the fixed-line pattern.\r\n\t\t//\r\n\t\tif (metadata.type('MOBILE') && metadata.type('MOBILE').pattern() === '') {\r\n\t\t\treturn 'FIXED_LINE_OR_MOBILE'\r\n\t\t}\r\n\r\n\t\t// `MOBILE` type pattern isn't included if it matched `FIXED_LINE` one.\r\n\t\t// For example, for \"US\" country.\r\n\t\t// Old metadata (< `1.0.18`) had a specific \"types\" data structure\r\n\t\t// that happened to be `undefined` for `MOBILE` in that case.\r\n\t\t// Newer metadata (>= `1.0.18`) has another data structure that is\r\n\t\t// not `undefined` for `MOBILE` in that case (it's just an empty array).\r\n\t\t// So this `if` is just for backwards compatibility with old metadata.\r\n\t\tif (!metadata.type('MOBILE')) {\r\n\t\t\treturn 'FIXED_LINE_OR_MOBILE'\r\n\t\t}\r\n\r\n\t\t// Check if the number happens to qualify as both fixed line and mobile.\r\n\t\t// (no such country in the minimal metadata set)\r\n\t\t/* istanbul ignore if */\r\n\t\tif (isNumberTypeEqualTo(nationalNumber, 'MOBILE', metadata)) {\r\n\t\t\treturn 'FIXED_LINE_OR_MOBILE'\r\n\t\t}\r\n\r\n\t\treturn 'FIXED_LINE'\r\n\t}\r\n\r\n\tfor (const type of NON_FIXED_LINE_PHONE_TYPES) {\r\n\t\tif (isNumberTypeEqualTo(nationalNumber, type, metadata)) {\r\n\t\t\treturn type\r\n\t\t}\r\n\t}\r\n}\r\n\r\nexport function isNumberTypeEqualTo(nationalNumber, type, metadata) {\r\n\tconst typeDefinition = metadata.type(type)\r\n\tif (!typeDefinition || !typeDefinition.pattern()) {\r\n\t\treturn false\r\n\t}\r\n\r\n\t// Check if any possible number lengths are present;\r\n\t// if so, we use them to avoid checking\r\n\t// the validation pattern if they don't match.\r\n\t// If they are absent, this means they match\r\n\t// the general description, which we have\r\n\t// already checked before a specific number type.\r\n\tif (\r\n\t\ttypeDefinition.possibleLengths() &&\r\n\t\ttypeDefinition.possibleLengths().indexOf(nationalNumber.length) < 0\r\n\t) {\r\n\t\treturn false\r\n\t}\r\n\r\n\treturn matchesEntirely(nationalNumber, typeDefinition.pattern())\r\n}"],"mappings":";;;AAAA,OAAOA,QAAQ,MAAM,gBAAgB;AACrC,OAAOC,eAAe,MAAM,sBAAsB;AAElD,IAAMC,0BAA0B,GAAG,CAClC,QAAQ,EACR,cAAc,EACd,WAAW,EACX,aAAa,EACb,MAAM,EACN,iBAAiB,EACjB,OAAO,EACP,KAAK,EACL,WAAW,CACX;;AAED;AACA,eAAe,SAASC,aAAaA,CAACC,KAAK,EAAEC,OAAO,EAAEC,QAAQ,EAC9D;EACC;EACA;EACAD,OAAO,GAAGA,OAAO,IAAI,CAAC,CAAC;;EAEvB;EACA;EACA;EACA,IAAI,CAACD,KAAK,CAACG,OAAO,IAAI,CAACH,KAAK,CAACI,kBAAkB,EAAE;IAChD;EACD;EAEAF,QAAQ,GAAG,IAAIN,QAAQ,CAACM,QAAQ,CAAC;EAEjCA,QAAQ,CAACG,mBAAmB,CAACL,KAAK,CAACG,OAAO,EAAEH,KAAK,CAACI,kBAAkB,CAAC;EAErE,IAAME,cAAc,GAAGL,OAAO,CAACM,EAAE,GAAGP,KAAK,CAACM,cAAc,GAAGN,KAAK,CAACQ,KAAK;;EAEtE;EACA;;EAEA;EACA,IAAI,CAACX,eAAe,CAACS,cAAc,EAAEJ,QAAQ,CAACO,qBAAqB,CAAC,CAAC,CAAC,EAAE;IACvE;EACD;;EAEA;EACA,IAAIC,mBAAmB,CAACJ,cAAc,EAAE,YAAY,EAAEJ,QAAQ,CAAC,EAAE;IAChE;IACA;IACA;IACA;IACA,IAAIA,QAAQ,CAACS,IAAI,CAAC,QAAQ,CAAC,IAAIT,QAAQ,CAACS,IAAI,CAAC,QAAQ,CAAC,CAACC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;MACxE,OAAO,sBAAsB;IAC9B;;IAEA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,IAAI,CAACV,QAAQ,CAACS,IAAI,CAAC,QAAQ,CAAC,EAAE;MAC7B,OAAO,sBAAsB;IAC9B;;IAEA;IACA;IACA;IACA,IAAID,mBAAmB,CAACJ,cAAc,EAAE,QAAQ,EAAEJ,QAAQ,CAAC,EAAE;MAC5D,OAAO,sBAAsB;IAC9B;IAEA,OAAO,YAAY;EACpB;EAEA,SAAAW,SAAA,GAAAC,+BAAA,CAAmBhB,0BAA0B,GAAAiB,KAAA,IAAAA,KAAA,GAAAF,SAAA,IAAAG,IAAA,GAAE;IAAA,IAApCL,IAAI,GAAAI,KAAA,CAAAE,KAAA;IACd,IAAIP,mBAAmB,CAACJ,cAAc,EAAEK,IAAI,EAAET,QAAQ,CAAC,EAAE;MACxD,OAAOS,IAAI;IACZ;EACD;AACD;AAEA,OAAO,SAASD,mBAAmBA,CAACJ,cAAc,EAAEK,IAAI,EAAET,QAAQ,EAAE;EACnE,IAAMgB,cAAc,GAAGhB,QAAQ,CAACS,IAAI,CAACA,IAAI,CAAC;EAC1C,IAAI,CAACO,cAAc,IAAI,CAACA,cAAc,CAACN,OAAO,CAAC,CAAC,EAAE;IACjD,OAAO,KAAK;EACb;;EAEA;EACA;EACA;EACA;EACA;EACA;EACA,IACCM,cAAc,CAACC,eAAe,CAAC,CAAC,IAChCD,cAAc,CAACC,eAAe,CAAC,CAAC,CAACC,OAAO,CAACd,cAAc,CAACe,MAAM,CAAC,GAAG,CAAC,EAClE;IACD,OAAO,KAAK;EACb;EAEA,OAAOxB,eAAe,CAACS,cAAc,EAAEY,cAAc,CAACN,OAAO,CAAC,CAAC,CAAC;AACjE","ignoreList":[]}
1
+ {"version":3,"file":"getNumberType.js","names":["Metadata","matchesEntirely","NON_FIXED_LINE_PHONE_TYPES","getNumberType","input","options","metadataJson","country","countryCallingCode","metadata","selectNumberingPlan","nationalNumber","v2","phone","nationalNumberPattern","isNumberTypeEqualTo","type","pattern","_iterator","_createForOfIteratorHelperLoose","_step","done","value","typeDefinition","possibleLengths","indexOf","length"],"sources":["../../source/helpers/getNumberType.js"],"sourcesContent":["import Metadata from '../metadata.js'\r\nimport matchesEntirely from './matchesEntirely.js'\r\n\r\nconst NON_FIXED_LINE_PHONE_TYPES = [\r\n\t'MOBILE',\r\n\t'PREMIUM_RATE',\r\n\t'TOLL_FREE',\r\n\t'SHARED_COST',\r\n\t'VOIP',\r\n\t'PERSONAL_NUMBER',\r\n\t'PAGER',\r\n\t'UAN',\r\n\t'VOICEMAIL'\r\n]\r\n\r\n// Finds out national phone number type (fixed line, mobile, etc)\r\nexport default function getNumberType(input, options, metadataJson)\r\n{\r\n\t// If assigning the `{}` default value is moved to the arguments above,\r\n\t// code coverage would decrease for some weird reason.\r\n\toptions = options || {}\r\n\r\n\t// When `parse()` returns an empty object — `{}` —\r\n\t// that means that the phone number is malformed,\r\n\t// so it can't possibly be valid.\r\n\tif (!input.country && !input.countryCallingCode) {\r\n\t\treturn\r\n\t}\r\n\r\n\tconst metadata = new Metadata(metadataJson)\r\n\r\n\tmetadata.selectNumberingPlan(input.country || input.countryCallingCode)\r\n\r\n\tconst nationalNumber = options.v2 ? input.nationalNumber : input.phone\r\n\r\n\t// The following is copy-pasted from the original function:\r\n\t// https://github.com/googlei18n/libphonenumber/blob/3ea547d4fbaa2d0b67588904dfa5d3f2557c27ff/javascript/i18n/phonenumbers/phonenumberutil.js#L2835\r\n\r\n\t// Is this national number even valid for this country\r\n\tif (!matchesEntirely(nationalNumber, metadata.nationalNumberPattern())) {\r\n\t\treturn\r\n\t}\r\n\r\n\t// Is it fixed line number\r\n\tif (isNumberTypeEqualTo(nationalNumber, 'FIXED_LINE', metadata)) {\r\n\t\t// Because duplicate regular expressions are removed\r\n\t\t// to reduce metadata size, if \"mobile\" pattern is \"\"\r\n\t\t// then it means it was removed due to being a duplicate of the fixed-line pattern.\r\n\t\t//\r\n\t\tif (metadata.type('MOBILE') && metadata.type('MOBILE').pattern() === '') {\r\n\t\t\treturn 'FIXED_LINE_OR_MOBILE'\r\n\t\t}\r\n\r\n\t\t// `MOBILE` type pattern isn't included if it matched `FIXED_LINE` one.\r\n\t\t// For example, for \"US\" country.\r\n\t\t// Old metadata (< `1.0.18`) had a specific \"types\" data structure\r\n\t\t// that happened to be `undefined` for `MOBILE` in that case.\r\n\t\t// Newer metadata (>= `1.0.18`) has another data structure that is\r\n\t\t// not `undefined` for `MOBILE` in that case (it's just an empty array).\r\n\t\t// So this `if` is just for backwards compatibility with old metadata.\r\n\t\tif (!metadata.type('MOBILE')) {\r\n\t\t\treturn 'FIXED_LINE_OR_MOBILE'\r\n\t\t}\r\n\r\n\t\t// Check if the number happens to qualify as both fixed line and mobile.\r\n\t\t// (no such country in the minimal metadata set)\r\n\t\t/* istanbul ignore if */\r\n\t\tif (isNumberTypeEqualTo(nationalNumber, 'MOBILE', metadata)) {\r\n\t\t\treturn 'FIXED_LINE_OR_MOBILE'\r\n\t\t}\r\n\r\n\t\treturn 'FIXED_LINE'\r\n\t}\r\n\r\n\tfor (const type of NON_FIXED_LINE_PHONE_TYPES) {\r\n\t\tif (isNumberTypeEqualTo(nationalNumber, type, metadata)) {\r\n\t\t\treturn type\r\n\t\t}\r\n\t}\r\n}\r\n\r\nexport function isNumberTypeEqualTo(nationalNumber, type, metadata) {\r\n\tconst typeDefinition = metadata.type(type)\r\n\tif (!typeDefinition || !typeDefinition.pattern()) {\r\n\t\treturn false\r\n\t}\r\n\r\n\t// Check if any possible number lengths are present;\r\n\t// if so, we use them to avoid checking\r\n\t// the validation pattern if they don't match.\r\n\t// If they are absent, this means they match\r\n\t// the general description, which we have\r\n\t// already checked before a specific number type.\r\n\tif (\r\n\t\ttypeDefinition.possibleLengths() &&\r\n\t\ttypeDefinition.possibleLengths().indexOf(nationalNumber.length) < 0\r\n\t) {\r\n\t\treturn false\r\n\t}\r\n\r\n\treturn matchesEntirely(nationalNumber, typeDefinition.pattern())\r\n}"],"mappings":";;;AAAA,OAAOA,QAAQ,MAAM,gBAAgB;AACrC,OAAOC,eAAe,MAAM,sBAAsB;AAElD,IAAMC,0BAA0B,GAAG,CAClC,QAAQ,EACR,cAAc,EACd,WAAW,EACX,aAAa,EACb,MAAM,EACN,iBAAiB,EACjB,OAAO,EACP,KAAK,EACL,WAAW,CACX;;AAED;AACA,eAAe,SAASC,aAAaA,CAACC,KAAK,EAAEC,OAAO,EAAEC,YAAY,EAClE;EACC;EACA;EACAD,OAAO,GAAGA,OAAO,IAAI,CAAC,CAAC;;EAEvB;EACA;EACA;EACA,IAAI,CAACD,KAAK,CAACG,OAAO,IAAI,CAACH,KAAK,CAACI,kBAAkB,EAAE;IAChD;EACD;EAEA,IAAMC,QAAQ,GAAG,IAAIT,QAAQ,CAACM,YAAY,CAAC;EAE3CG,QAAQ,CAACC,mBAAmB,CAACN,KAAK,CAACG,OAAO,IAAIH,KAAK,CAACI,kBAAkB,CAAC;EAEvE,IAAMG,cAAc,GAAGN,OAAO,CAACO,EAAE,GAAGR,KAAK,CAACO,cAAc,GAAGP,KAAK,CAACS,KAAK;;EAEtE;EACA;;EAEA;EACA,IAAI,CAACZ,eAAe,CAACU,cAAc,EAAEF,QAAQ,CAACK,qBAAqB,CAAC,CAAC,CAAC,EAAE;IACvE;EACD;;EAEA;EACA,IAAIC,mBAAmB,CAACJ,cAAc,EAAE,YAAY,EAAEF,QAAQ,CAAC,EAAE;IAChE;IACA;IACA;IACA;IACA,IAAIA,QAAQ,CAACO,IAAI,CAAC,QAAQ,CAAC,IAAIP,QAAQ,CAACO,IAAI,CAAC,QAAQ,CAAC,CAACC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;MACxE,OAAO,sBAAsB;IAC9B;;IAEA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,IAAI,CAACR,QAAQ,CAACO,IAAI,CAAC,QAAQ,CAAC,EAAE;MAC7B,OAAO,sBAAsB;IAC9B;;IAEA;IACA;IACA;IACA,IAAID,mBAAmB,CAACJ,cAAc,EAAE,QAAQ,EAAEF,QAAQ,CAAC,EAAE;MAC5D,OAAO,sBAAsB;IAC9B;IAEA,OAAO,YAAY;EACpB;EAEA,SAAAS,SAAA,GAAAC,+BAAA,CAAmBjB,0BAA0B,GAAAkB,KAAA,IAAAA,KAAA,GAAAF,SAAA,IAAAG,IAAA,GAAE;IAAA,IAApCL,IAAI,GAAAI,KAAA,CAAAE,KAAA;IACd,IAAIP,mBAAmB,CAACJ,cAAc,EAAEK,IAAI,EAAEP,QAAQ,CAAC,EAAE;MACxD,OAAOO,IAAI;IACZ;EACD;AACD;AAEA,OAAO,SAASD,mBAAmBA,CAACJ,cAAc,EAAEK,IAAI,EAAEP,QAAQ,EAAE;EACnE,IAAMc,cAAc,GAAGd,QAAQ,CAACO,IAAI,CAACA,IAAI,CAAC;EAC1C,IAAI,CAACO,cAAc,IAAI,CAACA,cAAc,CAACN,OAAO,CAAC,CAAC,EAAE;IACjD,OAAO,KAAK;EACb;;EAEA;EACA;EACA;EACA;EACA;EACA;EACA,IACCM,cAAc,CAACC,eAAe,CAAC,CAAC,IAChCD,cAAc,CAACC,eAAe,CAAC,CAAC,CAACC,OAAO,CAACd,cAAc,CAACe,MAAM,CAAC,GAAG,CAAC,EAClE;IACD,OAAO,KAAK;EACb;EAEA,OAAOzB,eAAe,CAACU,cAAc,EAAEY,cAAc,CAACN,OAAO,CAAC,CAAC,CAAC;AACjE","ignoreList":[]}
@@ -17,12 +17,9 @@ export default function getPossibleCountriesForNumber(callingCode, nationalNumbe
17
17
  return couldNationalNumberBelongToCountry(nationalNumber, country, metadata);
18
18
  });
19
19
  }
20
- function couldNationalNumberBelongToCountry(nationalNumber, country, metadata) {
21
- var _metadata = new Metadata(metadata);
22
- _metadata.selectNumberingPlan(country);
23
- if (_metadata.numberingPlan.possibleLengths().indexOf(nationalNumber.length) >= 0) {
24
- return true;
25
- }
26
- return false;
20
+ function couldNationalNumberBelongToCountry(nationalNumber, country, metadataJson) {
21
+ var metadata = new Metadata(metadataJson);
22
+ metadata.selectNumberingPlan(country);
23
+ return metadata.numberingPlan.possibleLengths().indexOf(nationalNumber.length) >= 0;
27
24
  }
28
25
  //# sourceMappingURL=getPossibleCountriesForNumber.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getPossibleCountriesForNumber.js","names":["Metadata","getPossibleCountriesForNumber","callingCode","nationalNumber","metadata","_metadata","possibleCountries","getCountryCodesForCallingCode","filter","country","couldNationalNumberBelongToCountry","selectNumberingPlan","numberingPlan","possibleLengths","indexOf","length"],"sources":["../../source/helpers/getPossibleCountriesForNumber.js"],"sourcesContent":["import Metadata from '../metadata.js'\r\n\r\n/**\r\n * Returns a list of countries that the phone number could potentially belong to.\r\n * @param {string} callingCode — Calling code.\r\n * @param {string} nationalNumber — National (significant) number.\r\n * @param {object} metadata — Metadata.\r\n * @return {string[]} A list of possible countries.\r\n */\r\nexport default function getPossibleCountriesForNumber(callingCode, nationalNumber, metadata) {\r\n\tconst _metadata = new Metadata(metadata)\r\n\tlet possibleCountries = _metadata.getCountryCodesForCallingCode(callingCode)\r\n\tif (!possibleCountries) {\r\n\t\treturn []\r\n\t}\r\n\treturn possibleCountries.filter((country) => {\r\n\t\treturn couldNationalNumberBelongToCountry(nationalNumber, country, metadata)\r\n\t})\r\n}\r\n\r\nfunction couldNationalNumberBelongToCountry(nationalNumber, country, metadata) {\r\n\tconst _metadata = new Metadata(metadata)\r\n\t_metadata.selectNumberingPlan(country)\r\n\tif (_metadata.numberingPlan.possibleLengths().indexOf(nationalNumber.length) >= 0) {\r\n\t\treturn true\r\n\t}\r\n\treturn false\r\n}"],"mappings":"AAAA,OAAOA,QAAQ,MAAM,gBAAgB;;AAErC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,6BAA6BA,CAACC,WAAW,EAAEC,cAAc,EAAEC,QAAQ,EAAE;EAC5F,IAAMC,SAAS,GAAG,IAAIL,QAAQ,CAACI,QAAQ,CAAC;EACxC,IAAIE,iBAAiB,GAAGD,SAAS,CAACE,6BAA6B,CAACL,WAAW,CAAC;EAC5E,IAAI,CAACI,iBAAiB,EAAE;IACvB,OAAO,EAAE;EACV;EACA,OAAOA,iBAAiB,CAACE,MAAM,CAAC,UAACC,OAAO,EAAK;IAC5C,OAAOC,kCAAkC,CAACP,cAAc,EAAEM,OAAO,EAAEL,QAAQ,CAAC;EAC7E,CAAC,CAAC;AACH;AAEA,SAASM,kCAAkCA,CAACP,cAAc,EAAEM,OAAO,EAAEL,QAAQ,EAAE;EAC9E,IAAMC,SAAS,GAAG,IAAIL,QAAQ,CAACI,QAAQ,CAAC;EACxCC,SAAS,CAACM,mBAAmB,CAACF,OAAO,CAAC;EACtC,IAAIJ,SAAS,CAACO,aAAa,CAACC,eAAe,CAAC,CAAC,CAACC,OAAO,CAACX,cAAc,CAACY,MAAM,CAAC,IAAI,CAAC,EAAE;IAClF,OAAO,IAAI;EACZ;EACA,OAAO,KAAK;AACb","ignoreList":[]}
1
+ {"version":3,"file":"getPossibleCountriesForNumber.js","names":["Metadata","getPossibleCountriesForNumber","callingCode","nationalNumber","metadata","_metadata","possibleCountries","getCountryCodesForCallingCode","filter","country","couldNationalNumberBelongToCountry","metadataJson","selectNumberingPlan","numberingPlan","possibleLengths","indexOf","length"],"sources":["../../source/helpers/getPossibleCountriesForNumber.js"],"sourcesContent":["import Metadata from '../metadata.js'\r\n\r\n/**\r\n * Returns a list of countries that the phone number could potentially belong to.\r\n * @param {string} callingCode — Calling code.\r\n * @param {string} nationalNumber — National (significant) number.\r\n * @param {object} metadata — Metadata.\r\n * @return {string[]} A list of possible countries.\r\n */\r\nexport default function getPossibleCountriesForNumber(callingCode, nationalNumber, metadata) {\r\n\tconst _metadata = new Metadata(metadata)\r\n\tlet possibleCountries = _metadata.getCountryCodesForCallingCode(callingCode)\r\n\tif (!possibleCountries) {\r\n\t\treturn []\r\n\t}\r\n\treturn possibleCountries.filter((country) => {\r\n\t\treturn couldNationalNumberBelongToCountry(nationalNumber, country, metadata)\r\n\t})\r\n}\r\n\r\nfunction couldNationalNumberBelongToCountry(nationalNumber, country, metadataJson) {\r\n\tconst metadata = new Metadata(metadataJson)\r\n\tmetadata.selectNumberingPlan(country)\r\n\treturn metadata.numberingPlan.possibleLengths().indexOf(nationalNumber.length) >= 0\r\n}"],"mappings":"AAAA,OAAOA,QAAQ,MAAM,gBAAgB;;AAErC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,6BAA6BA,CAACC,WAAW,EAAEC,cAAc,EAAEC,QAAQ,EAAE;EAC5F,IAAMC,SAAS,GAAG,IAAIL,QAAQ,CAACI,QAAQ,CAAC;EACxC,IAAIE,iBAAiB,GAAGD,SAAS,CAACE,6BAA6B,CAACL,WAAW,CAAC;EAC5E,IAAI,CAACI,iBAAiB,EAAE;IACvB,OAAO,EAAE;EACV;EACA,OAAOA,iBAAiB,CAACE,MAAM,CAAC,UAACC,OAAO,EAAK;IAC5C,OAAOC,kCAAkC,CAACP,cAAc,EAAEM,OAAO,EAAEL,QAAQ,CAAC;EAC7E,CAAC,CAAC;AACH;AAEA,SAASM,kCAAkCA,CAACP,cAAc,EAAEM,OAAO,EAAEE,YAAY,EAAE;EAClF,IAAMP,QAAQ,GAAG,IAAIJ,QAAQ,CAACW,YAAY,CAAC;EAC3CP,QAAQ,CAACQ,mBAAmB,CAACH,OAAO,CAAC;EACrC,OAAOL,QAAQ,CAACS,aAAa,CAACC,eAAe,CAAC,CAAC,CAACC,OAAO,CAACZ,cAAc,CAACa,MAAM,CAAC,IAAI,CAAC;AACpF","ignoreList":[]}
@@ -0,0 +1,5 @@
1
+ var CALLING_CODE_REG_EXP = /^\d+$/;
2
+ export default function isCallingCode(string) {
3
+ return CALLING_CODE_REG_EXP.test(string);
4
+ }
5
+ //# sourceMappingURL=isCallingCode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isCallingCode.js","names":["CALLING_CODE_REG_EXP","isCallingCode","string","test"],"sources":["../../source/helpers/isCallingCode.js"],"sourcesContent":["const CALLING_CODE_REG_EXP = /^\\d+$/\r\n\r\nexport default function isCallingCode(string) {\r\n\treturn CALLING_CODE_REG_EXP.test(string)\r\n}\r\n"],"mappings":"AAAA,IAAMA,oBAAoB,GAAG,OAAO;AAEpC,eAAe,SAASC,aAAaA,CAACC,MAAM,EAAE;EAC7C,OAAOF,oBAAoB,CAACG,IAAI,CAACD,MAAM,CAAC;AACzC","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isCallingCode.test.js","names":["describe","it","expect","isCallingCode","to","equal"],"sources":["../../source/helpers/isCallingCode.test.js"],"sourcesContent":["import { describe, it } from 'mocha'\r\nimport { expect } from 'chai'\r\n\r\nimport isCallingCode from './isCallingCode.js'\r\n\r\ndescribe('helpers/isCallingCode', () => {\r\n\tit('should determine if a string is a calling code', () => {\r\n\t\texpect(isCallingCode('')).to.equal(false)\r\n\t\texpect(isCallingCode('US')).to.equal(false)\r\n\t\texpect(isCallingCode('7')).to.equal(true)\r\n\t\texpect(isCallingCode('77')).to.equal(true)\r\n\t\texpect(isCallingCode('777')).to.equal(true)\r\n\t\texpect(isCallingCode('7777')).to.equal(true)\r\n\t})\r\n})"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,EAAE,QAAQ,OAAO;AACpC,SAASC,MAAM,QAAQ,MAAM;AAE7B,OAAOC,aAAa,MAAM,oBAAoB;AAE9CH,QAAQ,CAAC,uBAAuB,EAAE,YAAM;EACvCC,EAAE,CAAC,gDAAgD,EAAE,YAAM;IAC1DC,MAAM,CAACC,aAAa,CAAC,EAAE,CAAC,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,KAAK,CAAC;IACzCH,MAAM,CAACC,aAAa,CAAC,IAAI,CAAC,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,KAAK,CAAC;IAC3CH,MAAM,CAACC,aAAa,CAAC,GAAG,CAAC,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IACzCH,MAAM,CAACC,aAAa,CAAC,IAAI,CAAC,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IAC1CH,MAAM,CAACC,aAAa,CAAC,KAAK,CAAC,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IAC3CH,MAAM,CAACC,aAAa,CAAC,MAAM,CAAC,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;EAC7C,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,5 @@
1
+ var COUNTRY_CODE_REG_EXP = /^[A-Z]{2}$/;
2
+ export default function isCountryCode(string) {
3
+ return COUNTRY_CODE_REG_EXP.test(string);
4
+ }
5
+ //# sourceMappingURL=isCountryCode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isCountryCode.js","names":["COUNTRY_CODE_REG_EXP","isCountryCode","string","test"],"sources":["../../source/helpers/isCountryCode.js"],"sourcesContent":["const COUNTRY_CODE_REG_EXP = /^[A-Z]{2}$/\r\n\r\nexport default function isCountryCode(string) {\r\n\treturn COUNTRY_CODE_REG_EXP.test(string)\r\n}\r\n"],"mappings":"AAAA,IAAMA,oBAAoB,GAAG,YAAY;AAEzC,eAAe,SAASC,aAAaA,CAACC,MAAM,EAAE;EAC7C,OAAOF,oBAAoB,CAACG,IAAI,CAACD,MAAM,CAAC;AACzC","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isCountryCode.test.js","names":["describe","it","expect","isCountryCode","to","equal"],"sources":["../../source/helpers/isCountryCode.test.js"],"sourcesContent":["import { describe, it } from 'mocha'\r\nimport { expect } from 'chai'\r\n\r\nimport isCountryCode from './isCountryCode.js'\r\n\r\ndescribe('helpers/isCountryCode', () => {\r\n\tit('should determine if a string is a country code', () => {\r\n\t\texpect(isCountryCode('')).to.equal(false)\r\n\t\texpect(isCountryCode('U')).to.equal(false)\r\n\t\texpect(isCountryCode('US')).to.equal(true)\r\n\t\texpect(isCountryCode('USA')).to.equal(false)\r\n\t\texpect(isCountryCode('1')).to.equal(false)\r\n\t})\r\n})"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,EAAE,QAAQ,OAAO;AACpC,SAASC,MAAM,QAAQ,MAAM;AAE7B,OAAOC,aAAa,MAAM,oBAAoB;AAE9CH,QAAQ,CAAC,uBAAuB,EAAE,YAAM;EACvCC,EAAE,CAAC,gDAAgD,EAAE,YAAM;IAC1DC,MAAM,CAACC,aAAa,CAAC,EAAE,CAAC,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,KAAK,CAAC;IACzCH,MAAM,CAACC,aAAa,CAAC,GAAG,CAAC,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,KAAK,CAAC;IAC1CH,MAAM,CAACC,aAAa,CAAC,IAAI,CAAC,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IAC1CH,MAAM,CAACC,aAAa,CAAC,KAAK,CAAC,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,KAAK,CAAC;IAC5CH,MAAM,CAACC,aAAa,CAAC,GAAG,CAAC,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,KAAK,CAAC;EAC3C,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
@@ -1,19 +1,24 @@
1
1
  import Metadata from '../metadata.js';
2
2
  import { VALID_DIGITS } from '../constants.js';
3
3
  var CAPTURING_DIGIT_PATTERN = new RegExp('([' + VALID_DIGITS + '])');
4
- export default function stripIddPrefix(number, country, callingCode, metadata) {
4
+ export default function stripIddPrefix(number, country, callingCode, metadataJson) {
5
5
  if (!country) {
6
6
  return;
7
7
  }
8
+
9
+ // Get the IDD prefix pattern.
10
+ var metadata = new Metadata(metadataJson);
11
+ metadata.selectNumberingPlan(country || callingCode);
12
+ var IDDPrefixPattern = new RegExp(metadata.IDDPrefix());
13
+
8
14
  // Check if the number is IDD-prefixed.
9
- var countryMetadata = new Metadata(metadata);
10
- countryMetadata.selectNumberingPlan(country, callingCode);
11
- var IDDPrefixPattern = new RegExp(countryMetadata.IDDPrefix());
12
15
  if (number.search(IDDPrefixPattern) !== 0) {
13
16
  return;
14
17
  }
18
+
15
19
  // Strip IDD prefix.
16
20
  number = number.slice(number.match(IDDPrefixPattern)[0].length);
21
+
17
22
  // If there're any digits after an IDD prefix,
18
23
  // then those digits are a country calling code.
19
24
  // Since no country code starts with a `0`,
@@ -1 +1 @@
1
- {"version":3,"file":"stripIddPrefix.js","names":["Metadata","VALID_DIGITS","CAPTURING_DIGIT_PATTERN","RegExp","stripIddPrefix","number","country","callingCode","metadata","countryMetadata","selectNumberingPlan","IDDPrefixPattern","IDDPrefix","search","slice","match","length","matchedGroups"],"sources":["../../source/helpers/stripIddPrefix.js"],"sourcesContent":["import Metadata from '../metadata.js'\r\nimport { VALID_DIGITS } from '../constants.js'\r\n\r\nconst CAPTURING_DIGIT_PATTERN = new RegExp('([' + VALID_DIGITS + '])')\r\n\r\nexport default function stripIddPrefix(number, country, callingCode, metadata) {\r\n\tif (!country) {\r\n\t\treturn\r\n\t}\r\n\t// Check if the number is IDD-prefixed.\r\n\tconst countryMetadata = new Metadata(metadata)\r\n\tcountryMetadata.selectNumberingPlan(country, callingCode)\r\n\tconst IDDPrefixPattern = new RegExp(countryMetadata.IDDPrefix())\r\n\tif (number.search(IDDPrefixPattern) !== 0) {\r\n\t\treturn\r\n\t}\r\n\t// Strip IDD prefix.\r\n\tnumber = number.slice(number.match(IDDPrefixPattern)[0].length)\r\n\t// If there're any digits after an IDD prefix,\r\n\t// then those digits are a country calling code.\r\n\t// Since no country code starts with a `0`,\r\n\t// the code below validates that the next digit (if present) is not `0`.\r\n\tconst matchedGroups = number.match(CAPTURING_DIGIT_PATTERN)\r\n\tif (matchedGroups && matchedGroups[1] != null && matchedGroups[1].length > 0) {\r\n\t\tif (matchedGroups[1] === '0') {\r\n\t\t\treturn\r\n\t\t}\r\n\t}\r\n\treturn number\r\n}"],"mappings":"AAAA,OAAOA,QAAQ,MAAM,gBAAgB;AACrC,SAASC,YAAY,QAAQ,iBAAiB;AAE9C,IAAMC,uBAAuB,GAAG,IAAIC,MAAM,CAAC,IAAI,GAAGF,YAAY,GAAG,IAAI,CAAC;AAEtE,eAAe,SAASG,cAAcA,CAACC,MAAM,EAAEC,OAAO,EAAEC,WAAW,EAAEC,QAAQ,EAAE;EAC9E,IAAI,CAACF,OAAO,EAAE;IACb;EACD;EACA;EACA,IAAMG,eAAe,GAAG,IAAIT,QAAQ,CAACQ,QAAQ,CAAC;EAC9CC,eAAe,CAACC,mBAAmB,CAACJ,OAAO,EAAEC,WAAW,CAAC;EACzD,IAAMI,gBAAgB,GAAG,IAAIR,MAAM,CAACM,eAAe,CAACG,SAAS,CAAC,CAAC,CAAC;EAChE,IAAIP,MAAM,CAACQ,MAAM,CAACF,gBAAgB,CAAC,KAAK,CAAC,EAAE;IAC1C;EACD;EACA;EACAN,MAAM,GAAGA,MAAM,CAACS,KAAK,CAACT,MAAM,CAACU,KAAK,CAACJ,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAACK,MAAM,CAAC;EAC/D;EACA;EACA;EACA;EACA,IAAMC,aAAa,GAAGZ,MAAM,CAACU,KAAK,CAACb,uBAAuB,CAAC;EAC3D,IAAIe,aAAa,IAAIA,aAAa,CAAC,CAAC,CAAC,IAAI,IAAI,IAAIA,aAAa,CAAC,CAAC,CAAC,CAACD,MAAM,GAAG,CAAC,EAAE;IAC7E,IAAIC,aAAa,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;MAC7B;IACD;EACD;EACA,OAAOZ,MAAM;AACd","ignoreList":[]}
1
+ {"version":3,"file":"stripIddPrefix.js","names":["Metadata","VALID_DIGITS","CAPTURING_DIGIT_PATTERN","RegExp","stripIddPrefix","number","country","callingCode","metadataJson","metadata","selectNumberingPlan","IDDPrefixPattern","IDDPrefix","search","slice","match","length","matchedGroups"],"sources":["../../source/helpers/stripIddPrefix.js"],"sourcesContent":["import Metadata from '../metadata.js'\r\nimport { VALID_DIGITS } from '../constants.js'\r\n\r\nconst CAPTURING_DIGIT_PATTERN = new RegExp('([' + VALID_DIGITS + '])')\r\n\r\nexport default function stripIddPrefix(number, country, callingCode, metadataJson) {\r\n\tif (!country) {\r\n\t\treturn\r\n\t}\r\n\r\n\t// Get the IDD prefix pattern.\r\n\tconst metadata = new Metadata(metadataJson)\r\n\tmetadata.selectNumberingPlan(country || callingCode)\r\n\tconst IDDPrefixPattern = new RegExp(metadata.IDDPrefix())\r\n\r\n\t// Check if the number is IDD-prefixed.\r\n\tif (number.search(IDDPrefixPattern) !== 0) {\r\n\t\treturn\r\n\t}\r\n\r\n\t// Strip IDD prefix.\r\n\tnumber = number.slice(number.match(IDDPrefixPattern)[0].length)\r\n\r\n\t// If there're any digits after an IDD prefix,\r\n\t// then those digits are a country calling code.\r\n\t// Since no country code starts with a `0`,\r\n\t// the code below validates that the next digit (if present) is not `0`.\r\n\tconst matchedGroups = number.match(CAPTURING_DIGIT_PATTERN)\r\n\tif (matchedGroups && matchedGroups[1] != null && matchedGroups[1].length > 0) {\r\n\t\tif (matchedGroups[1] === '0') {\r\n\t\t\treturn\r\n\t\t}\r\n\t}\r\n\r\n\treturn number\r\n}"],"mappings":"AAAA,OAAOA,QAAQ,MAAM,gBAAgB;AACrC,SAASC,YAAY,QAAQ,iBAAiB;AAE9C,IAAMC,uBAAuB,GAAG,IAAIC,MAAM,CAAC,IAAI,GAAGF,YAAY,GAAG,IAAI,CAAC;AAEtE,eAAe,SAASG,cAAcA,CAACC,MAAM,EAAEC,OAAO,EAAEC,WAAW,EAAEC,YAAY,EAAE;EAClF,IAAI,CAACF,OAAO,EAAE;IACb;EACD;;EAEA;EACA,IAAMG,QAAQ,GAAG,IAAIT,QAAQ,CAACQ,YAAY,CAAC;EAC3CC,QAAQ,CAACC,mBAAmB,CAACJ,OAAO,IAAIC,WAAW,CAAC;EACpD,IAAMI,gBAAgB,GAAG,IAAIR,MAAM,CAACM,QAAQ,CAACG,SAAS,CAAC,CAAC,CAAC;;EAEzD;EACA,IAAIP,MAAM,CAACQ,MAAM,CAACF,gBAAgB,CAAC,KAAK,CAAC,EAAE;IAC1C;EACD;;EAEA;EACAN,MAAM,GAAGA,MAAM,CAACS,KAAK,CAACT,MAAM,CAACU,KAAK,CAACJ,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAACK,MAAM,CAAC;;EAE/D;EACA;EACA;EACA;EACA,IAAMC,aAAa,GAAGZ,MAAM,CAACU,KAAK,CAACb,uBAAuB,CAAC;EAC3D,IAAIe,aAAa,IAAIA,aAAa,CAAC,CAAC,CAAC,IAAI,IAAI,IAAIA,aAAa,CAAC,CAAC,CAAC,CAACD,MAAM,GAAG,CAAC,EAAE;IAC7E,IAAIC,aAAa,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;MAC7B;IACD;EACD;EAEA,OAAOZ,MAAM;AACd","ignoreList":[]}
package/es6/isPossible.js CHANGED
@@ -11,20 +11,20 @@ import checkNumberLength from './helpers/checkNumberLength.js';
11
11
  *
12
12
  * @param {object|PhoneNumber} input — If `options.v2: true` flag is passed, the `input` should be a `PhoneNumber` instance. Otherwise, it should be an object of shape `{ phone: '...', country: '...' }`.
13
13
  * @param {object} [options]
14
- * @param {object} metadata
14
+ * @param {object} metadataJson
15
15
  * @return {string}
16
16
  */
17
- export default function isPossiblePhoneNumber(input, options, metadata) {
17
+ export default function isPossiblePhoneNumber(input, options, metadataJson) {
18
18
  /* istanbul ignore if */
19
19
  if (options === undefined) {
20
20
  options = {};
21
21
  }
22
- metadata = new Metadata(metadata);
22
+ var metadata = new Metadata(metadataJson);
23
23
  if (options.v2) {
24
24
  if (!input.countryCallingCode) {
25
25
  throw new Error('Invalid phone number object passed');
26
26
  }
27
- metadata.selectNumberingPlan(input.countryCallingCode);
27
+ metadata.selectNumberingPlan(input.country || input.countryCallingCode);
28
28
  } else {
29
29
  if (!input.phone) {
30
30
  return false;
@@ -45,7 +45,7 @@ export default function isPossiblePhoneNumber(input, options, metadata) {
45
45
  // Old (legacy) metadata (< 1.0.18) had no "possible length" data.
46
46
  // So `isPossibleNumber()` function is supported only for non-legacy metadata.
47
47
  if (metadata.possibleLengths()) {
48
- return isPossibleNumber(input.phone || input.nationalNumber, input.country, metadata);
48
+ return isPossibleNumber(input.phone || input.nationalNumber, metadata);
49
49
  }
50
50
 
51
51
  // There was a bug in versions from `1.7.35` to `1.7.37` of `libphonenumber-js`
@@ -62,9 +62,15 @@ export default function isPossiblePhoneNumber(input, options, metadata) {
62
62
  // `isPossibleNumber()` function is not supported.
63
63
  throw new Error('Missing "possibleLengths" in metadata. Perhaps the metadata has been generated before v1.0.18.');
64
64
  }
65
- export function isPossibleNumber(nationalNumber, country, metadata) {
66
- //, isInternational) {
67
- switch (checkNumberLength(nationalNumber, country, metadata)) {
65
+
66
+ /**
67
+ * Tells if a given national (significant) number is possible
68
+ * @param {string} nationalNumber
69
+ * @param {Metadata} metadata = Metadata instance with a pre-selected telephone numbering plan.
70
+ * @returns {boolean}
71
+ */
72
+ export function isPossibleNumber(nationalNumber, metadata) {
73
+ switch (checkNumberLength(nationalNumber, undefined, metadata)) {
68
74
  case 'IS_POSSIBLE':
69
75
  return true;
70
76
  // This library ignores "local-only" phone numbers (for simplicity).
@@ -1 +1 @@
1
- {"version":3,"file":"isPossible.js","names":["Metadata","checkNumberLength","isPossiblePhoneNumber","input","options","metadata","undefined","v2","countryCallingCode","Error","selectNumberingPlan","phone","country","hasCountry","concat","possibleLengths","isPossibleNumber","nationalNumber","isNonGeographicCallingCode"],"sources":["../source/isPossible.js"],"sourcesContent":["import Metadata from './metadata.js'\r\nimport checkNumberLength from './helpers/checkNumberLength.js'\r\n\r\n/**\r\n * Checks if a phone number is \"possible\" (basically just checks its length).\r\n *\r\n * isPossible(phoneNumberInstance, { ..., v2: true }, metadata)\r\n *\r\n * isPossible({ phone: '8005553535', country: 'RU' }, { ... }, metadata)\r\n * isPossible({ phone: '8005553535', country: 'RU' }, undefined, metadata)\r\n *\r\n * @param {object|PhoneNumber} input — If `options.v2: true` flag is passed, the `input` should be a `PhoneNumber` instance. Otherwise, it should be an object of shape `{ phone: '...', country: '...' }`.\r\n * @param {object} [options]\r\n * @param {object} metadata\r\n * @return {string}\r\n */\r\nexport default function isPossiblePhoneNumber(input, options, metadata) {\r\n\t/* istanbul ignore if */\r\n\tif (options === undefined) {\r\n\t\toptions = {}\r\n\t}\r\n\r\n\tmetadata = new Metadata(metadata)\r\n\r\n\tif (options.v2) {\r\n\t\tif (!input.countryCallingCode) {\r\n\t\t\tthrow new Error('Invalid phone number object passed')\r\n\t\t}\r\n\t\tmetadata.selectNumberingPlan(input.countryCallingCode)\r\n\t} else {\r\n\t\tif (!input.phone) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\tif (input.country) {\r\n\t\t\tif (!metadata.hasCountry(input.country)) {\r\n\t\t\t\tthrow new Error(`Unknown country: ${input.country}`)\r\n\t\t\t}\r\n\t\t\tmetadata.selectNumberingPlan(input.country)\r\n\t\t} else {\r\n\t\t\tif (!input.countryCallingCode) {\r\n\t\t\t\tthrow new Error('Invalid phone number object passed')\r\n\t\t\t}\r\n\t\t\tmetadata.selectNumberingPlan(input.countryCallingCode)\r\n\t\t}\r\n\t}\r\n\r\n\t// Old (legacy) metadata (< 1.0.18) had no \"possible length\" data.\r\n\t// So `isPossibleNumber()` function is supported only for non-legacy metadata.\r\n\tif (metadata.possibleLengths()) {\r\n\t\treturn isPossibleNumber(input.phone || input.nationalNumber, input.country, metadata)\r\n\t}\r\n\r\n\t// There was a bug in versions from `1.7.35` to `1.7.37` of `libphonenumber-js`\r\n\t// where \"possible_lengths\" property was missing from \"non-geographical\" numbering plans' metadata.\r\n\t// After that, the bug was noticed and fixed.\r\n\t// So for versions from `1.7.35` to `1.7.37`, just assume that all \"non=geotraphical\" numbers are possible.\r\n\t// The reason is that the bug was noticed relatively quickly (within a day or so)\r\n\t// and it's unlikely that anyone generated their custom metadata in that short time span.\r\n\t// And if they didn't generate any custom metadata then a follow-up package update would've silently fixed the bug.\r\n\tif (input.countryCallingCode && metadata.isNonGeographicCallingCode(input.countryCallingCode)) {\r\n\t\treturn true\r\n\t}\r\n\r\n\t// `isPossibleNumber()` function is not supported.\r\n\tthrow new Error('Missing \"possibleLengths\" in metadata. Perhaps the metadata has been generated before v1.0.18.');\r\n}\r\n\r\nexport function isPossibleNumber(nationalNumber, country, metadata) { //, isInternational) {\r\n\tswitch (checkNumberLength(nationalNumber, country, metadata)) {\r\n\t\tcase 'IS_POSSIBLE':\r\n\t\t\treturn true\r\n\t\t// This library ignores \"local-only\" phone numbers (for simplicity).\r\n\t\t// See the readme for more info on what are \"local-only\" phone numbers.\r\n\t\t// case 'IS_POSSIBLE_LOCAL_ONLY':\r\n\t\t// \treturn !isInternational\r\n\t\tdefault:\r\n\t\t\treturn false\r\n\t}\r\n}"],"mappings":"AAAA,OAAOA,QAAQ,MAAM,eAAe;AACpC,OAAOC,iBAAiB,MAAM,gCAAgC;;AAE9D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,qBAAqBA,CAACC,KAAK,EAAEC,OAAO,EAAEC,QAAQ,EAAE;EACvE;EACA,IAAID,OAAO,KAAKE,SAAS,EAAE;IAC1BF,OAAO,GAAG,CAAC,CAAC;EACb;EAEAC,QAAQ,GAAG,IAAIL,QAAQ,CAACK,QAAQ,CAAC;EAEjC,IAAID,OAAO,CAACG,EAAE,EAAE;IACf,IAAI,CAACJ,KAAK,CAACK,kBAAkB,EAAE;MAC9B,MAAM,IAAIC,KAAK,CAAC,oCAAoC,CAAC;IACtD;IACAJ,QAAQ,CAACK,mBAAmB,CAACP,KAAK,CAACK,kBAAkB,CAAC;EACvD,CAAC,MAAM;IACN,IAAI,CAACL,KAAK,CAACQ,KAAK,EAAE;MACjB,OAAO,KAAK;IACb;IACA,IAAIR,KAAK,CAACS,OAAO,EAAE;MAClB,IAAI,CAACP,QAAQ,CAACQ,UAAU,CAACV,KAAK,CAACS,OAAO,CAAC,EAAE;QACxC,MAAM,IAAIH,KAAK,qBAAAK,MAAA,CAAqBX,KAAK,CAACS,OAAO,CAAE,CAAC;MACrD;MACAP,QAAQ,CAACK,mBAAmB,CAACP,KAAK,CAACS,OAAO,CAAC;IAC5C,CAAC,MAAM;MACN,IAAI,CAACT,KAAK,CAACK,kBAAkB,EAAE;QAC9B,MAAM,IAAIC,KAAK,CAAC,oCAAoC,CAAC;MACtD;MACAJ,QAAQ,CAACK,mBAAmB,CAACP,KAAK,CAACK,kBAAkB,CAAC;IACvD;EACD;;EAEA;EACA;EACA,IAAIH,QAAQ,CAACU,eAAe,CAAC,CAAC,EAAE;IAC/B,OAAOC,gBAAgB,CAACb,KAAK,CAACQ,KAAK,IAAIR,KAAK,CAACc,cAAc,EAAEd,KAAK,CAACS,OAAO,EAAEP,QAAQ,CAAC;EACtF;;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,IAAIF,KAAK,CAACK,kBAAkB,IAAIH,QAAQ,CAACa,0BAA0B,CAACf,KAAK,CAACK,kBAAkB,CAAC,EAAE;IAC9F,OAAO,IAAI;EACZ;;EAEA;EACA,MAAM,IAAIC,KAAK,CAAC,gGAAgG,CAAC;AAClH;AAEA,OAAO,SAASO,gBAAgBA,CAACC,cAAc,EAAEL,OAAO,EAAEP,QAAQ,EAAE;EAAE;EACrE,QAAQJ,iBAAiB,CAACgB,cAAc,EAAEL,OAAO,EAAEP,QAAQ,CAAC;IAC3D,KAAK,aAAa;MACjB,OAAO,IAAI;IACZ;IACA;IACA;IACA;IACA;MACC,OAAO,KAAK;EACd;AACD","ignoreList":[]}
1
+ {"version":3,"file":"isPossible.js","names":["Metadata","checkNumberLength","isPossiblePhoneNumber","input","options","metadataJson","undefined","metadata","v2","countryCallingCode","Error","selectNumberingPlan","country","phone","hasCountry","concat","possibleLengths","isPossibleNumber","nationalNumber","isNonGeographicCallingCode"],"sources":["../source/isPossible.js"],"sourcesContent":["import Metadata from './metadata.js'\r\nimport checkNumberLength from './helpers/checkNumberLength.js'\r\n\r\n/**\r\n * Checks if a phone number is \"possible\" (basically just checks its length).\r\n *\r\n * isPossible(phoneNumberInstance, { ..., v2: true }, metadata)\r\n *\r\n * isPossible({ phone: '8005553535', country: 'RU' }, { ... }, metadata)\r\n * isPossible({ phone: '8005553535', country: 'RU' }, undefined, metadata)\r\n *\r\n * @param {object|PhoneNumber} input — If `options.v2: true` flag is passed, the `input` should be a `PhoneNumber` instance. Otherwise, it should be an object of shape `{ phone: '...', country: '...' }`.\r\n * @param {object} [options]\r\n * @param {object} metadataJson\r\n * @return {string}\r\n */\r\nexport default function isPossiblePhoneNumber(input, options, metadataJson) {\r\n\t/* istanbul ignore if */\r\n\tif (options === undefined) {\r\n\t\toptions = {}\r\n\t}\r\n\r\n\tconst metadata = new Metadata(metadataJson)\r\n\r\n\tif (options.v2) {\r\n\t\tif (!input.countryCallingCode) {\r\n\t\t\tthrow new Error('Invalid phone number object passed')\r\n\t\t}\r\n\t\tmetadata.selectNumberingPlan(input.country || input.countryCallingCode)\r\n\t} else {\r\n\t\tif (!input.phone) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\tif (input.country) {\r\n\t\t\tif (!metadata.hasCountry(input.country)) {\r\n\t\t\t\tthrow new Error(`Unknown country: ${input.country}`)\r\n\t\t\t}\r\n\t\t\tmetadata.selectNumberingPlan(input.country)\r\n\t\t} else {\r\n\t\t\tif (!input.countryCallingCode) {\r\n\t\t\t\tthrow new Error('Invalid phone number object passed')\r\n\t\t\t}\r\n\t\t\tmetadata.selectNumberingPlan(input.countryCallingCode)\r\n\t\t}\r\n\t}\r\n\r\n\t// Old (legacy) metadata (< 1.0.18) had no \"possible length\" data.\r\n\t// So `isPossibleNumber()` function is supported only for non-legacy metadata.\r\n\tif (metadata.possibleLengths()) {\r\n\t\treturn isPossibleNumber(input.phone || input.nationalNumber, metadata)\r\n\t}\r\n\r\n\t// There was a bug in versions from `1.7.35` to `1.7.37` of `libphonenumber-js`\r\n\t// where \"possible_lengths\" property was missing from \"non-geographical\" numbering plans' metadata.\r\n\t// After that, the bug was noticed and fixed.\r\n\t// So for versions from `1.7.35` to `1.7.37`, just assume that all \"non=geotraphical\" numbers are possible.\r\n\t// The reason is that the bug was noticed relatively quickly (within a day or so)\r\n\t// and it's unlikely that anyone generated their custom metadata in that short time span.\r\n\t// And if they didn't generate any custom metadata then a follow-up package update would've silently fixed the bug.\r\n\tif (input.countryCallingCode && metadata.isNonGeographicCallingCode(input.countryCallingCode)) {\r\n\t\treturn true\r\n\t}\r\n\r\n\t// `isPossibleNumber()` function is not supported.\r\n\tthrow new Error('Missing \"possibleLengths\" in metadata. Perhaps the metadata has been generated before v1.0.18.');\r\n}\r\n\r\n/**\r\n * Tells if a given national (significant) number is possible\r\n * @param {string} nationalNumber\r\n * @param {Metadata} metadata = Metadata instance with a pre-selected telephone numbering plan.\r\n * @returns {boolean}\r\n */\r\nexport function isPossibleNumber(nationalNumber, metadata) {\r\n\tswitch (checkNumberLength(nationalNumber, undefined, metadata)) {\r\n\t\tcase 'IS_POSSIBLE':\r\n\t\t\treturn true\r\n\t\t// This library ignores \"local-only\" phone numbers (for simplicity).\r\n\t\t// See the readme for more info on what are \"local-only\" phone numbers.\r\n\t\t// case 'IS_POSSIBLE_LOCAL_ONLY':\r\n\t\t// \treturn !isInternational\r\n\t\tdefault:\r\n\t\t\treturn false\r\n\t}\r\n}"],"mappings":"AAAA,OAAOA,QAAQ,MAAM,eAAe;AACpC,OAAOC,iBAAiB,MAAM,gCAAgC;;AAE9D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,qBAAqBA,CAACC,KAAK,EAAEC,OAAO,EAAEC,YAAY,EAAE;EAC3E;EACA,IAAID,OAAO,KAAKE,SAAS,EAAE;IAC1BF,OAAO,GAAG,CAAC,CAAC;EACb;EAEA,IAAMG,QAAQ,GAAG,IAAIP,QAAQ,CAACK,YAAY,CAAC;EAE3C,IAAID,OAAO,CAACI,EAAE,EAAE;IACf,IAAI,CAACL,KAAK,CAACM,kBAAkB,EAAE;MAC9B,MAAM,IAAIC,KAAK,CAAC,oCAAoC,CAAC;IACtD;IACAH,QAAQ,CAACI,mBAAmB,CAACR,KAAK,CAACS,OAAO,IAAIT,KAAK,CAACM,kBAAkB,CAAC;EACxE,CAAC,MAAM;IACN,IAAI,CAACN,KAAK,CAACU,KAAK,EAAE;MACjB,OAAO,KAAK;IACb;IACA,IAAIV,KAAK,CAACS,OAAO,EAAE;MAClB,IAAI,CAACL,QAAQ,CAACO,UAAU,CAACX,KAAK,CAACS,OAAO,CAAC,EAAE;QACxC,MAAM,IAAIF,KAAK,qBAAAK,MAAA,CAAqBZ,KAAK,CAACS,OAAO,CAAE,CAAC;MACrD;MACAL,QAAQ,CAACI,mBAAmB,CAACR,KAAK,CAACS,OAAO,CAAC;IAC5C,CAAC,MAAM;MACN,IAAI,CAACT,KAAK,CAACM,kBAAkB,EAAE;QAC9B,MAAM,IAAIC,KAAK,CAAC,oCAAoC,CAAC;MACtD;MACAH,QAAQ,CAACI,mBAAmB,CAACR,KAAK,CAACM,kBAAkB,CAAC;IACvD;EACD;;EAEA;EACA;EACA,IAAIF,QAAQ,CAACS,eAAe,CAAC,CAAC,EAAE;IAC/B,OAAOC,gBAAgB,CAACd,KAAK,CAACU,KAAK,IAAIV,KAAK,CAACe,cAAc,EAAEX,QAAQ,CAAC;EACvE;;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,IAAIJ,KAAK,CAACM,kBAAkB,IAAIF,QAAQ,CAACY,0BAA0B,CAAChB,KAAK,CAACM,kBAAkB,CAAC,EAAE;IAC9F,OAAO,IAAI;EACZ;;EAEA;EACA,MAAM,IAAIC,KAAK,CAAC,gGAAgG,CAAC;AAClH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASO,gBAAgBA,CAACC,cAAc,EAAEX,QAAQ,EAAE;EAC1D,QAAQN,iBAAiB,CAACiB,cAAc,EAAEZ,SAAS,EAAEC,QAAQ,CAAC;IAC7D,KAAK,aAAa;MACjB,OAAO,IAAI;IACZ;IACA;IACA;IACA;IACA;MACC,OAAO,KAAK;EACd;AACD","ignoreList":[]}
package/es6/isValid.js CHANGED
@@ -36,12 +36,12 @@ import getNumberType from './helpers/getNumberType.js';
36
36
  * isValidNumber({ phone: '8005553535', country: 'RU' }, metadata)
37
37
  * ```
38
38
  */
39
- export default function isValidNumber(input, options, metadata) {
39
+ export default function isValidNumber(input, options, metadataJson) {
40
40
  // If assigning the `{}` default value is moved to the arguments above,
41
41
  // code coverage would decrease for some weird reason.
42
42
  options = options || {};
43
- metadata = new Metadata(metadata);
44
- metadata.selectNumberingPlan(input.country, input.countryCallingCode);
43
+ var metadata = new Metadata(metadataJson);
44
+ metadata.selectNumberingPlan(input.country || input.countryCallingCode);
45
45
 
46
46
  // By default, countries only have type regexps when it's required for
47
47
  // distinguishing different countries having the same `countryCallingCode`.
@@ -1 +1 @@
1
- {"version":3,"file":"isValid.js","names":["Metadata","matchesEntirely","getNumberType","isValidNumber","input","options","metadata","selectNumberingPlan","country","countryCallingCode","hasTypes","undefined","nationalNumber","v2","phone","nationalNumberPattern"],"sources":["../source/isValid.js"],"sourcesContent":["import Metadata from './metadata.js'\r\nimport matchesEntirely from './helpers/matchesEntirely.js'\r\nimport getNumberType from './helpers/getNumberType.js'\r\n\r\n/**\r\n * Checks if a given phone number is valid.\r\n *\r\n * isValid(phoneNumberInstance, { ..., v2: true }, metadata)\r\n *\r\n * isPossible({ phone: '8005553535', country: 'RU' }, { ... }, metadata)\r\n * isPossible({ phone: '8005553535', country: 'RU' }, undefined, metadata)\r\n *\r\n * If the `number` is a string, it will be parsed to an object,\r\n * but only if it contains only valid phone number characters (including punctuation).\r\n * If the `number` is an object, it is used as is.\r\n *\r\n * The optional `defaultCountry` argument is the default country.\r\n * I.e. it does not restrict to just that country,\r\n * e.g. in those cases where several countries share\r\n * the same phone numbering rules (NANPA, Britain, etc).\r\n * For example, even though the number `07624 369230`\r\n * belongs to the Isle of Man (\"IM\" country code)\r\n * calling `isValidNumber('07624369230', 'GB', metadata)`\r\n * still returns `true` because the country is not restricted to `GB`,\r\n * it's just that `GB` is the default one for the phone numbering rules.\r\n * For restricting the country see `isValidNumberForRegion()`\r\n * though restricting a country might not be a good idea.\r\n * https://github.com/googlei18n/libphonenumber/blob/master/FAQ.md#when-should-i-use-isvalidnumberforregion\r\n *\r\n * Examples:\r\n *\r\n * ```js\r\n * isValidNumber('+78005553535', metadata)\r\n * isValidNumber('8005553535', 'RU', metadata)\r\n * isValidNumber('88005553535', 'RU', metadata)\r\n * isValidNumber({ phone: '8005553535', country: 'RU' }, metadata)\r\n * ```\r\n */\r\nexport default function isValidNumber(input, options, metadata)\r\n{\r\n\t// If assigning the `{}` default value is moved to the arguments above,\r\n\t// code coverage would decrease for some weird reason.\r\n\toptions = options || {}\r\n\r\n\tmetadata = new Metadata(metadata)\r\n\r\n\tmetadata.selectNumberingPlan(input.country, input.countryCallingCode)\r\n\r\n\t// By default, countries only have type regexps when it's required for\r\n\t// distinguishing different countries having the same `countryCallingCode`.\r\n\tif (metadata.hasTypes()) {\r\n\t\treturn getNumberType(input, options, metadata.metadata) !== undefined\r\n\t}\r\n\r\n\t// If there are no type regexps for this country in metadata then use\r\n\t// `nationalNumberPattern` as a \"better than nothing\" replacement.\r\n\tconst nationalNumber = options.v2 ? input.nationalNumber : input.phone\r\n\treturn matchesEntirely(nationalNumber, metadata.nationalNumberPattern())\r\n}"],"mappings":"AAAA,OAAOA,QAAQ,MAAM,eAAe;AACpC,OAAOC,eAAe,MAAM,8BAA8B;AAC1D,OAAOC,aAAa,MAAM,4BAA4B;;AAEtD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,aAAaA,CAACC,KAAK,EAAEC,OAAO,EAAEC,QAAQ,EAC9D;EACC;EACA;EACAD,OAAO,GAAGA,OAAO,IAAI,CAAC,CAAC;EAEvBC,QAAQ,GAAG,IAAIN,QAAQ,CAACM,QAAQ,CAAC;EAEjCA,QAAQ,CAACC,mBAAmB,CAACH,KAAK,CAACI,OAAO,EAAEJ,KAAK,CAACK,kBAAkB,CAAC;;EAErE;EACA;EACA,IAAIH,QAAQ,CAACI,QAAQ,CAAC,CAAC,EAAE;IACxB,OAAOR,aAAa,CAACE,KAAK,EAAEC,OAAO,EAAEC,QAAQ,CAACA,QAAQ,CAAC,KAAKK,SAAS;EACtE;;EAEA;EACA;EACA,IAAMC,cAAc,GAAGP,OAAO,CAACQ,EAAE,GAAGT,KAAK,CAACQ,cAAc,GAAGR,KAAK,CAACU,KAAK;EACtE,OAAOb,eAAe,CAACW,cAAc,EAAEN,QAAQ,CAACS,qBAAqB,CAAC,CAAC,CAAC;AACzE","ignoreList":[]}
1
+ {"version":3,"file":"isValid.js","names":["Metadata","matchesEntirely","getNumberType","isValidNumber","input","options","metadataJson","metadata","selectNumberingPlan","country","countryCallingCode","hasTypes","undefined","nationalNumber","v2","phone","nationalNumberPattern"],"sources":["../source/isValid.js"],"sourcesContent":["import Metadata from './metadata.js'\r\nimport matchesEntirely from './helpers/matchesEntirely.js'\r\nimport getNumberType from './helpers/getNumberType.js'\r\n\r\n/**\r\n * Checks if a given phone number is valid.\r\n *\r\n * isValid(phoneNumberInstance, { ..., v2: true }, metadata)\r\n *\r\n * isPossible({ phone: '8005553535', country: 'RU' }, { ... }, metadata)\r\n * isPossible({ phone: '8005553535', country: 'RU' }, undefined, metadata)\r\n *\r\n * If the `number` is a string, it will be parsed to an object,\r\n * but only if it contains only valid phone number characters (including punctuation).\r\n * If the `number` is an object, it is used as is.\r\n *\r\n * The optional `defaultCountry` argument is the default country.\r\n * I.e. it does not restrict to just that country,\r\n * e.g. in those cases where several countries share\r\n * the same phone numbering rules (NANPA, Britain, etc).\r\n * For example, even though the number `07624 369230`\r\n * belongs to the Isle of Man (\"IM\" country code)\r\n * calling `isValidNumber('07624369230', 'GB', metadata)`\r\n * still returns `true` because the country is not restricted to `GB`,\r\n * it's just that `GB` is the default one for the phone numbering rules.\r\n * For restricting the country see `isValidNumberForRegion()`\r\n * though restricting a country might not be a good idea.\r\n * https://github.com/googlei18n/libphonenumber/blob/master/FAQ.md#when-should-i-use-isvalidnumberforregion\r\n *\r\n * Examples:\r\n *\r\n * ```js\r\n * isValidNumber('+78005553535', metadata)\r\n * isValidNumber('8005553535', 'RU', metadata)\r\n * isValidNumber('88005553535', 'RU', metadata)\r\n * isValidNumber({ phone: '8005553535', country: 'RU' }, metadata)\r\n * ```\r\n */\r\nexport default function isValidNumber(input, options, metadataJson)\r\n{\r\n\t// If assigning the `{}` default value is moved to the arguments above,\r\n\t// code coverage would decrease for some weird reason.\r\n\toptions = options || {}\r\n\r\n\tconst metadata = new Metadata(metadataJson)\r\n\r\n\tmetadata.selectNumberingPlan(input.country || input.countryCallingCode)\r\n\r\n\t// By default, countries only have type regexps when it's required for\r\n\t// distinguishing different countries having the same `countryCallingCode`.\r\n\tif (metadata.hasTypes()) {\r\n\t\treturn getNumberType(input, options, metadata.metadata) !== undefined\r\n\t}\r\n\r\n\t// If there are no type regexps for this country in metadata then use\r\n\t// `nationalNumberPattern` as a \"better than nothing\" replacement.\r\n\tconst nationalNumber = options.v2 ? input.nationalNumber : input.phone\r\n\treturn matchesEntirely(nationalNumber, metadata.nationalNumberPattern())\r\n}"],"mappings":"AAAA,OAAOA,QAAQ,MAAM,eAAe;AACpC,OAAOC,eAAe,MAAM,8BAA8B;AAC1D,OAAOC,aAAa,MAAM,4BAA4B;;AAEtD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,aAAaA,CAACC,KAAK,EAAEC,OAAO,EAAEC,YAAY,EAClE;EACC;EACA;EACAD,OAAO,GAAGA,OAAO,IAAI,CAAC,CAAC;EAEvB,IAAME,QAAQ,GAAG,IAAIP,QAAQ,CAACM,YAAY,CAAC;EAE3CC,QAAQ,CAACC,mBAAmB,CAACJ,KAAK,CAACK,OAAO,IAAIL,KAAK,CAACM,kBAAkB,CAAC;;EAEvE;EACA;EACA,IAAIH,QAAQ,CAACI,QAAQ,CAAC,CAAC,EAAE;IACxB,OAAOT,aAAa,CAACE,KAAK,EAAEC,OAAO,EAAEE,QAAQ,CAACA,QAAQ,CAAC,KAAKK,SAAS;EACtE;;EAEA;EACA;EACA,IAAMC,cAAc,GAAGR,OAAO,CAACS,EAAE,GAAGV,KAAK,CAACS,cAAc,GAAGT,KAAK,CAACW,KAAK;EACtE,OAAOd,eAAe,CAACY,cAAc,EAAEN,QAAQ,CAACS,qBAAqB,CAAC,CAAC,CAAC;AACzE","ignoreList":[]}