Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

country-list-json

DannMolina5.4kISC1.1.0TypeScript support: included

List of countries in json format that includes country dial code, country abbreviation and flag.

country listing, country in josn format, countries, geocode, country, code, dial code, country flag, flag, listing

readme

List of countries in json format that includes country dial code, country abbreviation and flag.

Get Started

  • npm install country-list-json
  • import countries

Usage

Get country name

  • countries.name

Get dial code

  • countries.dial_code

Get country code

  • countries.code

Get country flag

  • countries.flag

Data Example

[
  {
      name: "Japan",
      dial_code: "+81",
      code: "JP",
      flag: "🇯🇵"
  },
  {
      name: "Russia",
      dial_code: "+7",
      code: "RU",
      flag: "🇷🇺"
  },
]

Implementation Example(React Native)

import React from 'react';
import {
    FlatList,
    SafeAreaView,
    Text,
    View,
    StyleSheet,
    StatusBar,
} from 'react-native';

import { countries } from 'country-list-json';

const App = () => {
    const Item = ({ title }) => (
        <View style={styles.item}>
            <Text style={styles.title}>{title}</Text>
        </View>
    );

    const renderItem = ({ item }) => <Item title={item.name} />;
    return (
        <SafeAreaView style={styles.container}>
            <FlatList
                data={countries}
                keyExtractor={(item) => item.code}
                renderItem={renderItem}
            />
        </SafeAreaView>
    );
};

const styles = StyleSheet.create({
    container: {
        flex: 1,
        marginTop: StatusBar.currentHeight || 0,
    },
    item: {
        backgroundColor: 'lavender',
        padding: 20,
        marginVertical: 8,
        marginHorizontal: 16,
    },
    title: {
        fontSize: 32,
    },
});

export default App;

Importing TypeScript types

import { CountryListItemType } from 'country-list-json';