How to use world-countries - 10 common examples

To help you get started, we’ve selected a few world-countries examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github odota / core / constants.js View on Github external
{
    var base = [key];
    if (items[key] && items[key].components)
    {
        return [].concat.apply(base, items[key].components.map(function(c)
        {
            return expandItemGroup(c);
        }));
    }
    else
    {
        return base;
    }
}
constants.countries = {};
countries.forEach(function(c){
    constants.countries[c.cca2] = c;
});
//console.log(constants.item_groups);
constants.items = items;
//abilities, already keyed by name
var abilities = constants.abilities.abilitydata;

// Add missing Shadow Fiend raze abilities by copying the shortest raze
if (!abilities.nevermore_shadowraze2) {
    abilities.nevermore_shadowraze2 = Object.assign({}, abilities.nevermore_shadowraze1);
    // Find and replace short raze range with medium raze range
    abilities.nevermore_shadowraze2.attrib = abilities.nevermore_shadowraze2.attrib.replace(/\d{3}/, 450);
}
if (!abilities.nevermore_shadowraze3) {
    abilities.nevermore_shadowraze3 = Object.assign({}, abilities.nevermore_shadowraze1);
    // Find and replace short raze range with long raze range
github CraveFood / farmblocks / packages / input-phone / updateCountryList.js View on Github external
const fs = require("fs");
// eslint-disable-next-line import/no-extraneous-dependencies
const countries = require("world-countries");
const { getCountryCallingCode } = require("libphonenumber-js");

const getNativeNames = (names, englishName) => {
  const nativeNames = Array.from(
    new Set(Object.keys(names).map(lang => names[lang].common)),
  )
    .filter(nativeName => nativeName !== englishName)
    .join("; ");

  return nativeNames;
};

const trimmedList = countries
  .map(country => {
    let callingCode;
    try {
      callingCode = getCountryCallingCode(country.cca2);
    } catch (error) {
      // Countries that don't have a calling code don't need to be on the list
      return null;
    }

    return {
      name: country.name.common,
      nativeNames: getNativeNames(country.name.native, country.name.common),
      flag: country.flag,
      code: country.cca2,
      callingCode,
      altSpellings: country.altSpellings,
github huridocs / uwazi / app / react / Forms / components / specs / IconSelector.spec.js View on Github external
it('should render a DropdownList with icons and flags, extending passed props', () => {
    render();
    const firstFlagIndex = component.find(DropdownList).props().data.length - countries.length;
    expect(component.find(DropdownList).props().data.length).toBe(iconNames.length + countries.length + 1);

    expect(component.find(DropdownList).props().data[1].type).toBe('Icons');
    expect(component.find(DropdownList).props().data[1]._id).toBe(iconNames[0]);
    expect(component.find(DropdownList).props().data[1].label).toBe(iconNames[0]);

    expect(component.find(DropdownList).props().data[firstFlagIndex].type).toBe('Flags');
    expect(component.find(DropdownList).props().data[firstFlagIndex]._id).toBe(countries[0].cca3);
    expect(component.find(DropdownList).props().data[firstFlagIndex].label).toBe(countries[0].name.common);

    expect(component.find(DropdownList).props().valueComponent).toBe(ListItem);
    expect(component.find(DropdownList).props().itemComponent).toBe(ListItem);
    expect(component.find(DropdownList).props().defaultValue).toBe(component.find(DropdownList).props().data[0]);
    expect(component.find(DropdownList).props().onChange).toBe('Function');
  });
});
github huridocs / uwazi / app / react / Forms / components / specs / IconSelector.spec.js View on Github external
it('should render a DropdownList with icons and flags, extending passed props', () => {
    render();
    const firstFlagIndex = component.find(DropdownList).props().data.length - countries.length;
    expect(component.find(DropdownList).props().data.length).toBe(iconNames.length + countries.length + 1);

    expect(component.find(DropdownList).props().data[1].type).toBe('Icons');
    expect(component.find(DropdownList).props().data[1]._id).toBe(iconNames[0]);
    expect(component.find(DropdownList).props().data[1].label).toBe(iconNames[0]);

    expect(component.find(DropdownList).props().data[firstFlagIndex].type).toBe('Flags');
    expect(component.find(DropdownList).props().data[firstFlagIndex]._id).toBe(countries[0].cca3);
    expect(component.find(DropdownList).props().data[firstFlagIndex].label).toBe(countries[0].name.common);

    expect(component.find(DropdownList).props().valueComponent).toBe(ListItem);
    expect(component.find(DropdownList).props().itemComponent).toBe(ListItem);
    expect(component.find(DropdownList).props().defaultValue).toBe(component.find(DropdownList).props().data[0]);
    expect(component.find(DropdownList).props().onChange).toBe('Function');
  });
});
github sarovin / react-native-prefix-picker / lib / picker.js View on Github external
getCountries() {
    const array = [];
    for (let i = 0; i < countries.length; i++) {
      if (countries[i].callingCode.length > 1) {
        for (let j = 0; j < countries[i].callingCode.length; j++) {
          array.push({
            cca2: `${countries[i].cca2} ( ${countries[i].callingCode[j]} )`,
            callingCode: countries[i].callingCode[j],
          });
        }
      } else {
        array.push({
          cca2: countries[i].cca2,
          callingCode: countries[i].callingCode[0],
        });
      }
    }
    return array;
  }
github huridocs / uwazi / app / react / Forms / components / IconSelector.js View on Github external
componentWillMount() {
    const listOptions = [{ _id: null, type: 'Empty' }]
    .concat(iconNames.map(icon => ({
      _id: icon,
      type: 'Icons',
      label: icon
    }))).concat(countries.map(country => ({
      _id: country.cca3,
      type: 'Flags',
      label: country.name.common
    })));

    this.setState({ listOptions });
  }
github xcarpentier / react-native-country-picker-modal / scripts / transform-world-countries.js View on Github external
const isRegion = process.argv.includes('--regions')
const isSubRegion = process.argv.includes('--subregions')

const getCountryNameAsyncs = (common, translations) =>
  Object.keys(translations)
    .filter(k => k !== 'common')
    .map(key => ({ [key]: translations[key].common }))
    .reduce(
      (prev, cur) => ({
        ...prev,
        [Object.keys(cur)[0]]: cur[Object.keys(cur)[0]]
      }),
      {}
    )

const newcountries = countries
  .map(
    ({
      cca2,
      currency,
      callingCode,
      region,
      subregion,
      name: { common },
      translations
    }) => ({
      [cca2]: {
        currency,
        callingCode,
        region,
        subregion,
        flag: isEmoji ? `flag-${cca2.toLowerCase()}` : flags[cca2],
github smucode / react-world-flags / src / country.js View on Github external
export const getAlphaTwoCode = code => {
  const uc = String(code).toUpperCase()
  const country = countries.find(
    c => c.cca2 === uc || c.ccn3 === uc || c.cca3 == uc
  )
  return (country && country.cca2) || code
}
github ava-ia / core / src / actions / action.translator.js View on Github external
terms.forEach((term, index) => {
      if (index > actionIndex) {
        if (term.tag === DEMONYM && demonymIndex === undefined) {
          const demonym = term.text.toLowerCase();
          const country = countries.find(item => item.demonym.toLowerCase() === demonym);

          if (country) {
            demonymIndex = index;
            to = country.cca2;
          }
        } else if (index > demonymIndex) {
          sentence += `${term.text} `;
        }
      }
    });
github vkurchatkin / which-country / example / main.js View on Github external
var L = require('leaflet');
var wc = require('../');
var countries = require('world-countries');

require('../node_modules/leaflet/dist/leaflet.css');
require('./style.css');

var byISO = {};

countries.forEach(function (country) {
  byISO[country.cca3] = country;
});

var map = L.map('map').setView([0, 0], 1);

L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
  attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);

map.on('click', function (e) {
  var latlng = e.latlng;
  var iso = wc([latlng.lng, latlng.lat]);

  if (!iso) return;

  var country = byISO[iso];

world-countries

List of world countries in JSON, CSV, XML and Yaml

ODbL-1.0
Latest version published 1 year ago

Package Health Score

68 / 100
Full package analysis