パッケージの詳細

@brixtol/country-names

brixtol1.2kMIT1.4.1

Mappings for 2 letter (Alpha 2) country codes to English country name

countries, mappings, country, 3166-1 alpha-2

readme

@brixtol/country-names

Country code (3166-1 alpha-2) to Country name (ISO 3166 mappings used by the Brixtol Textiles internal API when dealing with Localization and i18n operations.

Mappings returned in the English Language.

Minified: 4.15 KB
Gzipped: 2.25 KB

Install

pnpm

pnpm add @brixtol/country-names

npm

npm install @brixtol/country-names

Yarn

yarn add @brixtol/country-names

Usage

You can pass in a 2 letter country code that is lowercase, uppercase or a mixture of both.

import { getCountryName } from '@brixtol/country-names';

const sweden = getCountryName('SE'); // Sweden
const netherlands = getCountryName('nl'); // Netherlands
const usa = getCountryName('uS'); // United States of America
EXTRAS

The module also exposes the raw mappings and interface on the export. The mappings object is provided read only using Object.freeze. In addition to the raw mappings a ISO code union export is also exposed.

import { Countries, ICountries, CountryCodes, Country } from '@brixtol/country-names';

// Mapping Object

Countries.SE; // Sweden
Countries.NL; // Netherlands
Countries.RU; // Russian Federation

// Interface

ICountries.SE; // Sweden
ICountries.NL; // Netherlands
ICountries.RU; // Russian Federation

// Country Code Union

CountryCodes<'SE' | 'NL' | 'RU'>; // etc etc

The interface is identical to the mapping

Related

Static GeoIP utility

Country code to currency code mappings:

Currency code to currency symbol mappings:

License

Licensed under MIT


We open source!

更新履歴

CHANGELOG

1.4.1 - 01/12/2021

  • Fixed KG (Kyrgyzstan)
  • Changes Saint Barthelemy to official name Saint Barthélemy

1.2.4 - 24/11/2021

  • Added XK (Republic of Kosovo)
  • Added BN (Brunei Darussalam)

1.2.2 - 21/11/2021

  • Minor internal updates
  • Moved to esbuild minifier
  • pnpm linked dependencies
  • dropped const enum Country export
  • Updated docs

1.2.1 - 05/11/2021

Improved type support and provided error handling for when invalid or incorrect ISO codes are provided.

  • Added literal union support for argument code
  • Added type support for country name reference of return
  • Added error support when an unmatched ISO is provided
  • Appended "(DPRK)" to "North Korea" country name.
  • Added const enum Country export which uses Country Names to map ISO codes
  • Exposed ISO code Union type to export

1.2.0 - 24/10/2021

  • Added CountryCodes type export

1.1.2 - 10/09/2021

Replaced development rollup dependencies to use @brixtol/rollup-config

1.1.1 - 23/08/2021

Extend prettier config in package.json file and align readme.

1.1.0 - 23/08/2021

Mostly development space adjustments, no code was modified, aside from the eslint formats that were applied to source. In addition, the module also exposes the mapping object on the exports.

Breakdown

1.0.0 - 22/08/2021

Dropped support of default exports. This module uses named exports. The module typings now export an identical interface of countries.

Named export
import { getCountryName } from '@brixtol/country-names';

const country = getCountryName('SE'); // Sweden
Breakdown
  • No longer support default exports, project now uses named export approach.
  • Provided interface of country mappings, available on ICountries

0.1.0 - 17/08/2021

  • Initial Release