{"version":3,"file":"bootstrap-select-country.min.js","sources":["../../node_modules/i18n-iso-countries/index.js","../../src/bootstrap-select-country.js"],"sourcesContent":["\"use strict\";\n\nvar codes = require(\"./codes.json\");\nvar registeredLocales = {};\n\n/*\n * All codes map to ISO 3166-1 alpha-2\n */\nvar alpha2 = {},\n  alpha3 = {},\n  numeric = {},\n  invertedNumeric = {};\n\ncodes.forEach(function(codeInformation) {\n  var s = codeInformation;\n  alpha2[s[0]] = s[1];\n  alpha3[s[1]] = s[0];\n  numeric[s[2]] = s[0];\n  invertedNumeric[s[0]] = s[2];\n});\n\nfunction formatNumericCode(code) {\n  return String('000'+(code ? code : '')).slice(-3);\n}\n\nfunction registerLocale(localeData) {\n  if (!localeData.locale) {\n    throw new TypeError('Missing localeData.locale');\n  }\n\n  if (!localeData.countries) {\n    throw new TypeError('Missing localeData.countries');\n  }\n\n  registeredLocales[localeData.locale] = localeData.countries;\n}\n\nexports.registerLocale = registerLocale;\n\n/*\n * @param code Alpha-3 code\n * @return Alpha-2 code or undefined\n */\nfunction alpha3ToAlpha2(code) {\n  return alpha3[code];\n}\nexports.alpha3ToAlpha2 = alpha3ToAlpha2;\n\n/*\n * @param code Alpha-2 code\n * @return Alpha-3 code or undefined\n */\nfunction alpha2ToAlpha3(code) {\n  return alpha2[code];\n}\nexports.alpha2ToAlpha3 = alpha2ToAlpha3;\n\n/*\n * @param code Alpha-3 code\n * @return Numeric code or undefined\n */\nfunction alpha3ToNumeric(code) {\n  return invertedNumeric[alpha3ToAlpha2(code)];\n}\nexports.alpha3ToNumeric = alpha3ToNumeric;\n\n/*\n * @param code Alpha-2 code\n * @return Numeric code or undefined\n */\nfunction alpha2ToNumeric(code) {\n  return invertedNumeric[code];\n}\nexports.alpha2ToNumeric = alpha2ToNumeric;\n\n/*\n * @param code Numeric code\n * @return Alpha-3 code or undefined\n */\nfunction numericToAlpha3(code) {\n  var padded = formatNumericCode(code);\n  return alpha2ToAlpha3(numeric[padded]);\n}\nexports.numericToAlpha3 = numericToAlpha3;\n\n/*\n * @param code Numeric code\n * @return Alpha-2 code or undefined\n */\nfunction numericToAlpha2(code) {\n  var padded = formatNumericCode(code);\n  return numeric[padded];\n}\nexports.numericToAlpha2 = numericToAlpha2;\n\n/*\n * @param code ISO 3166-1 alpha-2, alpha-3 or numeric code\n * @return ISO 3166-1 alpha-3\n */\nfunction toAlpha3(code) {\n  if (typeof code === \"string\") {\n    if (/^[0-9]*$/.test(code)) {\n      return numericToAlpha3(code);\n    }\n    if(code.length === 2) {\n      return alpha2ToAlpha3(code.toUpperCase());\n    }\n    if (code.length === 3) {\n      return code.toUpperCase();\n    }\n  }\n  if (typeof code === \"number\") {\n    return numericToAlpha3(code);\n  }\n  return undefined;\n}\nexports.toAlpha3 = toAlpha3;\n\n/*\n * @param code ISO 3166-1 alpha-2, alpha-3 or numeric code\n * @return ISO 3166-1 alpha-2\n */\nfunction toAlpha2(code) {\n  if (typeof code === \"string\") {\n    if (/^[0-9]*$/.test(code)) {\n      return numericToAlpha2(code);\n    }\n    if (code.length === 2) {\n      return code.toUpperCase();\n    }\n    if(code.length === 3) {\n      return alpha3ToAlpha2(code.toUpperCase());\n    }\n  }\n  if (typeof code === \"number\") {\n    return numericToAlpha2(code);\n  }\n  return undefined;\n}\nexports.toAlpha2 = toAlpha2;\n\n/*\n * @param code ISO 3166-1 alpha-2, alpha-3 or numeric code\n * @param lang language for country name\n * @return name or undefined\n */\nexports.getName = function(code, lang) {\n  try {\n    var d = registeredLocales[lang.toLowerCase()];\n    return d[toAlpha2(code)];\n  } catch (err) {\n    return undefined;\n  }\n};\n\n/*\n * @param lang language for country names\n * @return Object of country code mapped to county name\n */\nexports.getNames = function(lang) {\n  var d = registeredLocales[lang.toLowerCase()];\n  if (d === undefined) {\n    return {};\n  }\n  return d;\n};\n\n/*\n * @param name name\n * @param lang language for country name\n * @return ISO 3166-1 alpha-2 or undefined\n */\nexports.getAlpha2Code = function(name, lang) {\n  try {\n    var p, codenames = registeredLocales[lang.toLowerCase()];\n    for (p in codenames) {\n      if (codenames.hasOwnProperty(p)) {\n        if (codenames[p].toLowerCase() === name.toLowerCase()) {\n          return p;\n        }\n      }\n    }\n    return undefined;\n  } catch (err) {\n    return undefined;\n  }\n};\n\n/*\n * @return Object of alpha-2 codes mapped to alpha-3 codes\n */\nexports.getAlpha2Codes = function() {\n  return alpha2;\n};\n\n/*\n * @param name name\n * @param lang language for country name\n * @return ISO 3166-1 alpha-3 or undefined\n */\nexports.getAlpha3Code = function(name, lang) {\n  var alpha2 = this.getAlpha2Code(name, lang);\n  if (alpha2) {\n    return this.toAlpha3(alpha2);\n  } else {\n    return undefined;\n  }\n};\n\n/*\n * @return Object of alpha-3 codes mapped to alpha-2 codes\n */\nexports.getAlpha3Codes = function() {\n  return alpha3;\n};\n\n/*\n * @return Object of numeric codes mapped to alpha-2 codes\n */\nexports.getNumericCodes = function() {\n  return numeric;\n};\n\n/*\n * @return Array of supported languages\n */\nexports.langs = function() {\n  return Object.keys(registeredLocales);\n};\n\n/*\n * @param code ISO 3166-1 alpha-2, alpha-3 or numeric code\n * @return Boolean\n */\nexports.isValid = function(code) {\n  return alpha3.hasOwnProperty(code) || alpha2.hasOwnProperty(code) ||\n    numeric.hasOwnProperty(code);\n};\n","import $ from 'jquery';\n\nimport countries from \"i18n-iso-countries\";\nimport langs_en from \"i18n-iso-countries/langs/en.json\";\ncountries.registerLocale(langs_en);\nconst langCountries = countries.getNames('en');\n\nconst allCountries = Object.keys(langCountries).map((code) => {\n\treturn {\n\t\tname: langCountries[code],\n\t\tcode: code\n\t};\n});\n\nlet countrypicker = function(opts) {\n\t$(this).each(function(index, select) {\n\t\tvar $select = $(select);\n\n\t\tvar flag = $select.data('flag');\n\n\t\tvar countries = allCountries;\n\t\t\n\t\t// filter countries of an option \"data-countries\" exist\"\n\t\tvar selectedCountries = $select.data('countries');\n\t\tif (selectedCountries && selectedCountries.length) {\n\t\t\tselectedCountries = selectedCountries.toUpperCase().split(',');\n\t\t\tcountries = countries.filter(c => selectedCountries.includes(c.code));\n\t\t}\n\n\t\tvar options = [];\n\t\tif (flag) {\n\t\t\t\t/* create option for each existing country */\n\t\t\t\t$.each(countries, function (index, country) {\n\t\t\t\t\toptions.push(`<option\n\t\t\t\t\t\tdata-tokens=\"${country.code} ${country.name}\"\n\t\t\t\t\t\tdata-icon=\"inline-flag flag ${country.code.toLowerCase()}\"\n\t\t\t\t\t\tclass=\"option-with-flag\"\n\t\t\t\t\t\tvalue=\"${country.code}\">${country.name}</option>`);\n\t\t\t\t});\n\n\t\t} else {\n\t\t\t//for each build list without flag\n\t\t\t$.each(countries, function (index, country) {\n\t\t\t\toptions.push(`<option\n\t\t\t\t\tdata-countrycode=\"${country.code}\n\t\t\t\t\tdata-tokens=\"${country.code} ${country.name}\"\n\t\t\t\t\tvalue=\"${country.code}\">${country.name}</option>`);\n\t\t\t});\n\t\t}\n\n\t\t$select\n\t\t\t.addClass('f16')\n\t\t\t.html(options.join('\\n'));\n\n\t\t//check if default\n\t\tvar defaultCountryName = $select.data('default');\n\t\t//if there's a default, set it\n\t\tif (defaultCountryName) {\n\t\t\t$select.val(defaultCountryName.split(',').map((v) => v.trim()));\n\t\t}\n\t});\n};\n\n/* extend jQuery with the countrypicker function */\n$.fn.countrypicker = countrypicker;\n\n/* initialize all countrypicker by default. This is the default jQuery Behavior. */\n$('.countrypicker').countrypicker();\n\n/* return the countrypicker function for use as a module. */\nexport default countrypicker;\n"],"names":["alpha2","alpha3","numeric","invertedNumeric","formatNumericCode","code","String","slice","alpha3ToAlpha2","alpha2ToAlpha3","numericToAlpha3","padded","numericToAlpha2","toAlpha2","test","length","toUpperCase","forEach","codeInformation","s","exports","localeData","locale","TypeError","countries","lang","registeredLocales","toLowerCase","err","d","undefined","name","p","codenames","hasOwnProperty","this","getAlpha2Code","toAlpha3","Object","keys","registerLocale","langs_en","langCountries","getNames","allCountries","map","countrypicker","opts","each","index","select","$select","$","flag","data","selectedCountries","split","filter","includes","c","options","country","push","addClass","html","join","def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