metadata.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports["default"] = void 0;
  6. exports.getCountryCallingCode = getCountryCallingCode;
  7. exports.getExtPrefix = getExtPrefix;
  8. exports.isSupportedCountry = isSupportedCountry;
  9. exports.validateMetadata = validateMetadata;
  10. var _semverCompare = _interopRequireDefault(require("./tools/semver-compare.js"));
  11. var _isObject = _interopRequireDefault(require("./helpers/isObject.js"));
  12. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  13. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  14. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  15. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  16. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  17. // Added "possibleLengths" and renamed
  18. // "country_phone_code_to_countries" to "country_calling_codes".
  19. var V2 = '1.0.18'; // Added "idd_prefix" and "default_idd_prefix".
  20. var V3 = '1.2.0'; // Moved `001` country code to "nonGeographic" section of metadata.
  21. var V4 = '1.7.35';
  22. var DEFAULT_EXT_PREFIX = ' ext. ';
  23. var CALLING_CODE_REG_EXP = /^\d+$/;
  24. /**
  25. * See: https://gitlab.com/catamphetamine/libphonenumber-js/blob/master/METADATA.md
  26. */
  27. var Metadata = /*#__PURE__*/function () {
  28. function Metadata(metadata) {
  29. _classCallCheck(this, Metadata);
  30. validateMetadata(metadata);
  31. this.metadata = metadata;
  32. setVersion.call(this, metadata);
  33. }
  34. _createClass(Metadata, [{
  35. key: "getCountries",
  36. value: function getCountries() {
  37. return Object.keys(this.metadata.countries).filter(function (_) {
  38. return _ !== '001';
  39. });
  40. }
  41. }, {
  42. key: "getCountryMetadata",
  43. value: function getCountryMetadata(countryCode) {
  44. return this.metadata.countries[countryCode];
  45. }
  46. }, {
  47. key: "nonGeographic",
  48. value: function nonGeographic() {
  49. if (this.v1 || this.v2 || this.v3) return; // `nonGeographical` was a typo.
  50. // It's present in metadata generated from `1.7.35` to `1.7.37`.
  51. // The test case could be found by searching for "nonGeographical".
  52. return this.metadata.nonGeographic || this.metadata.nonGeographical;
  53. }
  54. }, {
  55. key: "hasCountry",
  56. value: function hasCountry(country) {
  57. return this.getCountryMetadata(country) !== undefined;
  58. }
  59. }, {
  60. key: "hasCallingCode",
  61. value: function hasCallingCode(callingCode) {
  62. if (this.getCountryCodesForCallingCode(callingCode)) {
  63. return true;
  64. }
  65. if (this.nonGeographic()) {
  66. if (this.nonGeographic()[callingCode]) {
  67. return true;
  68. }
  69. } else {
  70. // A hacky workaround for old custom metadata (generated before V4).
  71. var countryCodes = this.countryCallingCodes()[callingCode];
  72. if (countryCodes && countryCodes.length === 1 && countryCodes[0] === '001') {
  73. return true;
  74. }
  75. }
  76. }
  77. }, {
  78. key: "isNonGeographicCallingCode",
  79. value: function isNonGeographicCallingCode(callingCode) {
  80. if (this.nonGeographic()) {
  81. return this.nonGeographic()[callingCode] ? true : false;
  82. } else {
  83. return this.getCountryCodesForCallingCode(callingCode) ? false : true;
  84. }
  85. } // Deprecated.
  86. }, {
  87. key: "country",
  88. value: function country(countryCode) {
  89. return this.selectNumberingPlan(countryCode);
  90. }
  91. }, {
  92. key: "selectNumberingPlan",
  93. value: function selectNumberingPlan(countryCode, callingCode) {
  94. // Supports just passing `callingCode` as the first argument.
  95. if (countryCode && CALLING_CODE_REG_EXP.test(countryCode)) {
  96. callingCode = countryCode;
  97. countryCode = null;
  98. }
  99. if (countryCode && countryCode !== '001') {
  100. if (!this.hasCountry(countryCode)) {
  101. throw new Error("Unknown country: ".concat(countryCode));
  102. }
  103. this.numberingPlan = new NumberingPlan(this.getCountryMetadata(countryCode), this);
  104. } else if (callingCode) {
  105. if (!this.hasCallingCode(callingCode)) {
  106. throw new Error("Unknown calling code: ".concat(callingCode));
  107. }
  108. this.numberingPlan = new NumberingPlan(this.getNumberingPlanMetadata(callingCode), this);
  109. } else {
  110. this.numberingPlan = undefined;
  111. }
  112. return this;
  113. }
  114. }, {
  115. key: "getCountryCodesForCallingCode",
  116. value: function getCountryCodesForCallingCode(callingCode) {
  117. var countryCodes = this.countryCallingCodes()[callingCode];
  118. if (countryCodes) {
  119. // Metadata before V4 included "non-geographic entity" calling codes
  120. // inside `country_calling_codes` (for example, `"881":["001"]`).
  121. // Now the semantics of `country_calling_codes` has changed:
  122. // it's specifically for "countries" now.
  123. // Older versions of custom metadata will simply skip parsing
  124. // "non-geographic entity" phone numbers with new versions
  125. // of this library: it's not considered a bug,
  126. // because such numbers are extremely rare,
  127. // and developers extremely rarely use custom metadata.
  128. if (countryCodes.length === 1 && countryCodes[0].length === 3) {
  129. return;
  130. }
  131. return countryCodes;
  132. }
  133. }
  134. }, {
  135. key: "getCountryCodeForCallingCode",
  136. value: function getCountryCodeForCallingCode(callingCode) {
  137. var countryCodes = this.getCountryCodesForCallingCode(callingCode);
  138. if (countryCodes) {
  139. return countryCodes[0];
  140. }
  141. }
  142. }, {
  143. key: "getNumberingPlanMetadata",
  144. value: function getNumberingPlanMetadata(callingCode) {
  145. var countryCode = this.getCountryCodeForCallingCode(callingCode);
  146. if (countryCode) {
  147. return this.getCountryMetadata(countryCode);
  148. }
  149. if (this.nonGeographic()) {
  150. var metadata = this.nonGeographic()[callingCode];
  151. if (metadata) {
  152. return metadata;
  153. }
  154. } else {
  155. // A hacky workaround for old custom metadata (generated before V4).
  156. // In that metadata, there was no concept of "non-geographic" metadata
  157. // so metadata for `001` country code was stored along with other countries.
  158. // The test case can be found by searching for:
  159. // "should work around `nonGeographic` metadata not existing".
  160. var countryCodes = this.countryCallingCodes()[callingCode];
  161. if (countryCodes && countryCodes.length === 1 && countryCodes[0] === '001') {
  162. return this.metadata.countries['001'];
  163. }
  164. }
  165. } // Deprecated.
  166. }, {
  167. key: "countryCallingCode",
  168. value: function countryCallingCode() {
  169. return this.numberingPlan.callingCode();
  170. } // Deprecated.
  171. }, {
  172. key: "IDDPrefix",
  173. value: function IDDPrefix() {
  174. return this.numberingPlan.IDDPrefix();
  175. } // Deprecated.
  176. }, {
  177. key: "defaultIDDPrefix",
  178. value: function defaultIDDPrefix() {
  179. return this.numberingPlan.defaultIDDPrefix();
  180. } // Deprecated.
  181. }, {
  182. key: "nationalNumberPattern",
  183. value: function nationalNumberPattern() {
  184. return this.numberingPlan.nationalNumberPattern();
  185. } // Deprecated.
  186. }, {
  187. key: "possibleLengths",
  188. value: function possibleLengths() {
  189. return this.numberingPlan.possibleLengths();
  190. } // Deprecated.
  191. }, {
  192. key: "formats",
  193. value: function formats() {
  194. return this.numberingPlan.formats();
  195. } // Deprecated.
  196. }, {
  197. key: "nationalPrefixForParsing",
  198. value: function nationalPrefixForParsing() {
  199. return this.numberingPlan.nationalPrefixForParsing();
  200. } // Deprecated.
  201. }, {
  202. key: "nationalPrefixTransformRule",
  203. value: function nationalPrefixTransformRule() {
  204. return this.numberingPlan.nationalPrefixTransformRule();
  205. } // Deprecated.
  206. }, {
  207. key: "leadingDigits",
  208. value: function leadingDigits() {
  209. return this.numberingPlan.leadingDigits();
  210. } // Deprecated.
  211. }, {
  212. key: "hasTypes",
  213. value: function hasTypes() {
  214. return this.numberingPlan.hasTypes();
  215. } // Deprecated.
  216. }, {
  217. key: "type",
  218. value: function type(_type) {
  219. return this.numberingPlan.type(_type);
  220. } // Deprecated.
  221. }, {
  222. key: "ext",
  223. value: function ext() {
  224. return this.numberingPlan.ext();
  225. }
  226. }, {
  227. key: "countryCallingCodes",
  228. value: function countryCallingCodes() {
  229. if (this.v1) return this.metadata.country_phone_code_to_countries;
  230. return this.metadata.country_calling_codes;
  231. } // Deprecated.
  232. }, {
  233. key: "chooseCountryByCountryCallingCode",
  234. value: function chooseCountryByCountryCallingCode(callingCode) {
  235. return this.selectNumberingPlan(callingCode);
  236. }
  237. }, {
  238. key: "hasSelectedNumberingPlan",
  239. value: function hasSelectedNumberingPlan() {
  240. return this.numberingPlan !== undefined;
  241. }
  242. }]);
  243. return Metadata;
  244. }();
  245. exports["default"] = Metadata;
  246. var NumberingPlan = /*#__PURE__*/function () {
  247. function NumberingPlan(metadata, globalMetadataObject) {
  248. _classCallCheck(this, NumberingPlan);
  249. this.globalMetadataObject = globalMetadataObject;
  250. this.metadata = metadata;
  251. setVersion.call(this, globalMetadataObject.metadata);
  252. }
  253. _createClass(NumberingPlan, [{
  254. key: "callingCode",
  255. value: function callingCode() {
  256. return this.metadata[0];
  257. } // Formatting information for regions which share
  258. // a country calling code is contained by only one region
  259. // for performance reasons. For example, for NANPA region
  260. // ("North American Numbering Plan Administration",
  261. // which includes USA, Canada, Cayman Islands, Bahamas, etc)
  262. // it will be contained in the metadata for `US`.
  263. }, {
  264. key: "getDefaultCountryMetadataForRegion",
  265. value: function getDefaultCountryMetadataForRegion() {
  266. return this.globalMetadataObject.getNumberingPlanMetadata(this.callingCode());
  267. } // Is always present.
  268. }, {
  269. key: "IDDPrefix",
  270. value: function IDDPrefix() {
  271. if (this.v1 || this.v2) return;
  272. return this.metadata[1];
  273. } // Is only present when a country supports multiple IDD prefixes.
  274. }, {
  275. key: "defaultIDDPrefix",
  276. value: function defaultIDDPrefix() {
  277. if (this.v1 || this.v2) return;
  278. return this.metadata[12];
  279. }
  280. }, {
  281. key: "nationalNumberPattern",
  282. value: function nationalNumberPattern() {
  283. if (this.v1 || this.v2) return this.metadata[1];
  284. return this.metadata[2];
  285. } // "possible length" data is always present in Google's metadata.
  286. }, {
  287. key: "possibleLengths",
  288. value: function possibleLengths() {
  289. if (this.v1) return;
  290. return this.metadata[this.v2 ? 2 : 3];
  291. }
  292. }, {
  293. key: "_getFormats",
  294. value: function _getFormats(metadata) {
  295. return metadata[this.v1 ? 2 : this.v2 ? 3 : 4];
  296. } // For countries of the same region (e.g. NANPA)
  297. // formats are all stored in the "main" country for that region.
  298. // E.g. "RU" and "KZ", "US" and "CA".
  299. }, {
  300. key: "formats",
  301. value: function formats() {
  302. var _this = this;
  303. var formats = this._getFormats(this.metadata) || this._getFormats(this.getDefaultCountryMetadataForRegion()) || [];
  304. return formats.map(function (_) {
  305. return new Format(_, _this);
  306. });
  307. }
  308. }, {
  309. key: "nationalPrefix",
  310. value: function nationalPrefix() {
  311. return this.metadata[this.v1 ? 3 : this.v2 ? 4 : 5];
  312. }
  313. }, {
  314. key: "_getNationalPrefixFormattingRule",
  315. value: function _getNationalPrefixFormattingRule(metadata) {
  316. return metadata[this.v1 ? 4 : this.v2 ? 5 : 6];
  317. } // For countries of the same region (e.g. NANPA)
  318. // national prefix formatting rule is stored in the "main" country for that region.
  319. // E.g. "RU" and "KZ", "US" and "CA".
  320. }, {
  321. key: "nationalPrefixFormattingRule",
  322. value: function nationalPrefixFormattingRule() {
  323. return this._getNationalPrefixFormattingRule(this.metadata) || this._getNationalPrefixFormattingRule(this.getDefaultCountryMetadataForRegion());
  324. }
  325. }, {
  326. key: "_nationalPrefixForParsing",
  327. value: function _nationalPrefixForParsing() {
  328. return this.metadata[this.v1 ? 5 : this.v2 ? 6 : 7];
  329. }
  330. }, {
  331. key: "nationalPrefixForParsing",
  332. value: function nationalPrefixForParsing() {
  333. // If `national_prefix_for_parsing` is not set explicitly,
  334. // then infer it from `national_prefix` (if any)
  335. return this._nationalPrefixForParsing() || this.nationalPrefix();
  336. }
  337. }, {
  338. key: "nationalPrefixTransformRule",
  339. value: function nationalPrefixTransformRule() {
  340. return this.metadata[this.v1 ? 6 : this.v2 ? 7 : 8];
  341. }
  342. }, {
  343. key: "_getNationalPrefixIsOptionalWhenFormatting",
  344. value: function _getNationalPrefixIsOptionalWhenFormatting() {
  345. return !!this.metadata[this.v1 ? 7 : this.v2 ? 8 : 9];
  346. } // For countries of the same region (e.g. NANPA)
  347. // "national prefix is optional when formatting" flag is
  348. // stored in the "main" country for that region.
  349. // E.g. "RU" and "KZ", "US" and "CA".
  350. }, {
  351. key: "nationalPrefixIsOptionalWhenFormattingInNationalFormat",
  352. value: function nationalPrefixIsOptionalWhenFormattingInNationalFormat() {
  353. return this._getNationalPrefixIsOptionalWhenFormatting(this.metadata) || this._getNationalPrefixIsOptionalWhenFormatting(this.getDefaultCountryMetadataForRegion());
  354. }
  355. }, {
  356. key: "leadingDigits",
  357. value: function leadingDigits() {
  358. return this.metadata[this.v1 ? 8 : this.v2 ? 9 : 10];
  359. }
  360. }, {
  361. key: "types",
  362. value: function types() {
  363. return this.metadata[this.v1 ? 9 : this.v2 ? 10 : 11];
  364. }
  365. }, {
  366. key: "hasTypes",
  367. value: function hasTypes() {
  368. // Versions 1.2.0 - 1.2.4: can be `[]`.
  369. /* istanbul ignore next */
  370. if (this.types() && this.types().length === 0) {
  371. return false;
  372. } // Versions <= 1.2.4: can be `undefined`.
  373. // Version >= 1.2.5: can be `0`.
  374. return !!this.types();
  375. }
  376. }, {
  377. key: "type",
  378. value: function type(_type2) {
  379. if (this.hasTypes() && getType(this.types(), _type2)) {
  380. return new Type(getType(this.types(), _type2), this);
  381. }
  382. }
  383. }, {
  384. key: "ext",
  385. value: function ext() {
  386. if (this.v1 || this.v2) return DEFAULT_EXT_PREFIX;
  387. return this.metadata[13] || DEFAULT_EXT_PREFIX;
  388. }
  389. }]);
  390. return NumberingPlan;
  391. }();
  392. var Format = /*#__PURE__*/function () {
  393. function Format(format, metadata) {
  394. _classCallCheck(this, Format);
  395. this._format = format;
  396. this.metadata = metadata;
  397. }
  398. _createClass(Format, [{
  399. key: "pattern",
  400. value: function pattern() {
  401. return this._format[0];
  402. }
  403. }, {
  404. key: "format",
  405. value: function format() {
  406. return this._format[1];
  407. }
  408. }, {
  409. key: "leadingDigitsPatterns",
  410. value: function leadingDigitsPatterns() {
  411. return this._format[2] || [];
  412. }
  413. }, {
  414. key: "nationalPrefixFormattingRule",
  415. value: function nationalPrefixFormattingRule() {
  416. return this._format[3] || this.metadata.nationalPrefixFormattingRule();
  417. }
  418. }, {
  419. key: "nationalPrefixIsOptionalWhenFormattingInNationalFormat",
  420. value: function nationalPrefixIsOptionalWhenFormattingInNationalFormat() {
  421. return !!this._format[4] || this.metadata.nationalPrefixIsOptionalWhenFormattingInNationalFormat();
  422. }
  423. }, {
  424. key: "nationalPrefixIsMandatoryWhenFormattingInNationalFormat",
  425. value: function nationalPrefixIsMandatoryWhenFormattingInNationalFormat() {
  426. // National prefix is omitted if there's no national prefix formatting rule
  427. // set for this country, or when the national prefix formatting rule
  428. // contains no national prefix itself, or when this rule is set but
  429. // national prefix is optional for this phone number format
  430. // (and it is not enforced explicitly)
  431. return this.usesNationalPrefix() && !this.nationalPrefixIsOptionalWhenFormattingInNationalFormat();
  432. } // Checks whether national prefix formatting rule contains national prefix.
  433. }, {
  434. key: "usesNationalPrefix",
  435. value: function usesNationalPrefix() {
  436. return this.nationalPrefixFormattingRule() && // Check that national prefix formatting rule is not a "dummy" one.
  437. !FIRST_GROUP_ONLY_PREFIX_PATTERN.test(this.nationalPrefixFormattingRule()) // In compressed metadata, `this.nationalPrefixFormattingRule()` is `0`
  438. // when `national_prefix_formatting_rule` is not present.
  439. // So, `true` or `false` are returned explicitly here, so that
  440. // `0` number isn't returned.
  441. ? true : false;
  442. }
  443. }, {
  444. key: "internationalFormat",
  445. value: function internationalFormat() {
  446. return this._format[5] || this.format();
  447. }
  448. }]);
  449. return Format;
  450. }();
  451. /**
  452. * A pattern that is used to determine if the national prefix formatting rule
  453. * has the first group only, i.e., does not start with the national prefix.
  454. * Note that the pattern explicitly allows for unbalanced parentheses.
  455. */
  456. var FIRST_GROUP_ONLY_PREFIX_PATTERN = /^\(?\$1\)?$/;
  457. var Type = /*#__PURE__*/function () {
  458. function Type(type, metadata) {
  459. _classCallCheck(this, Type);
  460. this.type = type;
  461. this.metadata = metadata;
  462. }
  463. _createClass(Type, [{
  464. key: "pattern",
  465. value: function pattern() {
  466. if (this.metadata.v1) return this.type;
  467. return this.type[0];
  468. }
  469. }, {
  470. key: "possibleLengths",
  471. value: function possibleLengths() {
  472. if (this.metadata.v1) return;
  473. return this.type[1] || this.metadata.possibleLengths();
  474. }
  475. }]);
  476. return Type;
  477. }();
  478. function getType(types, type) {
  479. switch (type) {
  480. case 'FIXED_LINE':
  481. return types[0];
  482. case 'MOBILE':
  483. return types[1];
  484. case 'TOLL_FREE':
  485. return types[2];
  486. case 'PREMIUM_RATE':
  487. return types[3];
  488. case 'PERSONAL_NUMBER':
  489. return types[4];
  490. case 'VOICEMAIL':
  491. return types[5];
  492. case 'UAN':
  493. return types[6];
  494. case 'PAGER':
  495. return types[7];
  496. case 'VOIP':
  497. return types[8];
  498. case 'SHARED_COST':
  499. return types[9];
  500. }
  501. }
  502. function validateMetadata(metadata) {
  503. if (!metadata) {
  504. throw new Error('[libphonenumber-js] `metadata` argument not passed. Check your arguments.');
  505. } // `country_phone_code_to_countries` was renamed to
  506. // `country_calling_codes` in `1.0.18`.
  507. if (!(0, _isObject["default"])(metadata) || !(0, _isObject["default"])(metadata.countries)) {
  508. throw new Error("[libphonenumber-js] `metadata` argument was passed but it's not a valid metadata. Must be an object having `.countries` child object property. Got ".concat((0, _isObject["default"])(metadata) ? 'an object of shape: { ' + Object.keys(metadata).join(', ') + ' }' : 'a ' + typeOf(metadata) + ': ' + metadata, "."));
  509. }
  510. } // Babel transforms `typeof` into some "branches"
  511. // so istanbul will show this as "branch not covered".
  512. /* istanbul ignore next */
  513. var typeOf = function typeOf(_) {
  514. return _typeof(_);
  515. };
  516. /**
  517. * Returns extension prefix for a country.
  518. * @param {string} country
  519. * @param {object} metadata
  520. * @return {string?}
  521. * @example
  522. * // Returns " ext. "
  523. * getExtPrefix("US")
  524. */
  525. function getExtPrefix(country, metadata) {
  526. metadata = new Metadata(metadata);
  527. if (metadata.hasCountry(country)) {
  528. return metadata.country(country).ext();
  529. }
  530. return DEFAULT_EXT_PREFIX;
  531. }
  532. /**
  533. * Returns "country calling code" for a country.
  534. * Throws an error if the country doesn't exist or isn't supported by this library.
  535. * @param {string} country
  536. * @param {object} metadata
  537. * @return {string}
  538. * @example
  539. * // Returns "44"
  540. * getCountryCallingCode("GB")
  541. */
  542. function getCountryCallingCode(country, metadata) {
  543. metadata = new Metadata(metadata);
  544. if (metadata.hasCountry(country)) {
  545. return metadata.country(country).countryCallingCode();
  546. }
  547. throw new Error("Unknown country: ".concat(country));
  548. }
  549. function isSupportedCountry(country, metadata) {
  550. // metadata = new Metadata(metadata)
  551. // return metadata.hasCountry(country)
  552. return metadata.countries.hasOwnProperty(country);
  553. }
  554. function setVersion(metadata) {
  555. var version = metadata.version;
  556. if (typeof version === 'number') {
  557. this.v1 = version === 1;
  558. this.v2 = version === 2;
  559. this.v3 = version === 3;
  560. this.v4 = version === 4;
  561. } else {
  562. if (!version) {
  563. this.v1 = true;
  564. } else if ((0, _semverCompare["default"])(version, V3) === -1) {
  565. this.v2 = true;
  566. } else if ((0, _semverCompare["default"])(version, V4) === -1) {
  567. this.v3 = true;
  568. } else {
  569. this.v4 = true;
  570. }
  571. }
  572. } // const ISO_COUNTRY_CODE = /^[A-Z]{2}$/
  573. // function isCountryCode(countryCode) {
  574. // return ISO_COUNTRY_CODE.test(countryCodeOrCountryCallingCode)
  575. // }
  576. //# sourceMappingURL=metadata.js.map