Code Monkey home page Code Monkey logo

country-list's Introduction

country-list

Build Status Coverage Status

Maps ISO 3166-1-alpha-2 codes to English country names and vice versa.

Uses data from https://www.iso.org/iso-3166-country-codes.html

js-standard-style

Looking for Version 1

You can find version 1.* of country-list here.

Example

const { getCode, getName } = require('country-list');

console.log(getName('IS')); // Iceland
console.log(getCode('Iceland')); // IS
console.log(getCode('Nowhere-to-be-found-land')); // undefined

And how to change the name of a country

const { overwrite, getName } = require('country-list');
overwrite([{
  code: 'TW',
  name: 'Taiwan'
}])

console.log(getName('TW')); // Taiwan

Methods

Usage:

const countryList = require('country-list');

All input is case-insensitive.

overwrite(countries)

Expects an array of country objects containing code and name properties.

[{
  code: 'TW',
  name: 'Taiwan'
}]

getName(code)

Expects a two-digit country code.
Returns the name for that country.
If not found, it returns undefined.

getCode(name)

Expects the English country name.
Returns the code for that country.
If not found, it returns undefined.

getNames()

Returns an array of all country names.

getCodes()

Returns an array of all country codes.

getNameList()

Returns a key-value object of all countries using the name as key.

getCodeList()

Returns a key-value object of all countries using the code as key.

getData()

Returns an array of all country information, in the same format as it gets imported.

Install

npm install country-list

Related Projects

License

MIT

Source

ISO makes the list of alpha-2 country codes available for internal use and non-commercial purposes free of charge.

country-list's People

Contributors

fannarsh avatar camilosampedro avatar eirikurn avatar intpp avatar nharrisanalyst avatar trysound avatar gta-cool avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.