simple-country-codes

Retrieve country names by giving country codes

Usage no npm install needed!

<script type="module">
  import simpleCountryCodes from 'https://cdn.skypack.dev/simple-country-codes';
</script>

README

Simple country codes

GitHub | NPM | @jelmerdemaat

Retrieve country names by giving country codes.

All this is:

  • A JSON object of all country codes and their country names
  • A function to safely retrieve items from that object

Features:

  • ES6 ready
  • Case insensitive ('gb' and 'GB' both work)
  • Function getCountry checks existance of property with object.hasOwnProperty
  • Returns false if your query does not exist

Usage

Add to your local dependencies using npm:

npm install --save simple-country-codes

Import and use in your own JavaScript:

import { getCountry } from 'simple-country-codes';

getCountry('gb'); // Returns "United Kingdom"
getCountry('nl'); // Returns "Netherlands"
getCountry('poop'); // Returns false