New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

country-name-code

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

country-name-code

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

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
Maintainers
0
Weekly downloads
 
Created
Source

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, getShortName } = require('country-list');

console.log(getName('GB')); // United Kingdom of Great Britain and Northern Ireland
console.log(getShortName('GB')); // United Kingdom
console.log(getCode('United Kingdom of Great Britain and Northern Ireland')); // GB
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.

getShortName(code)

Expects a two-digit country code. Returns the short name for that country or the country name if short name is not defined in the data.json. For example, the short name for United Kingdom of Great Britain and Northern Ireland is United Kingdom. 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

License

MIT

Source

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

Keywords

FAQs

Package last updated on 22 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc