Skip to content

A simple library for converting country codes between ISO, name and numeric formats.

License

Notifications You must be signed in to change notification settings

Marius-Adam/country-codes-converter

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn


Country Codes Converter

A simple library for converting country codes between ISO, name and numeric formats.

View Demo · Report Bug · Request Feature


Table of contents
  1. Installation
  2. Usage
  3. API
  4. Contributing
  5. License
  6. Contact

Installation

You can install the package using npm or yarn:

npm install country-codes-converter

yarn add country-codes-converter

Usage

country-codes-converter is fully TypeScript-supported, ensuring type safety and improved development experience. Additionally, it boasts 100% code test coverage, which guarantees the reliability and stability of the library.

import { iso3ToIso2, nameToIso3 } from "country-codes-converter";

// Convert ISO3 to ISO2
iso3ToIso2("USA").then((iso2) => {
  console.log(`ISO2 Code: ${iso2}`);
});

// Convert country name to ISO3
nameToIso3("Canada").then((iso3) => {
  console.log(`ISO3 Code: ${iso3}`);
});

API

Functions

The library exposes the following functions:

  1. iso3ToIso2(iso3: string): Promise<string | null>

    • Converts an ISO3 code to an ISO2 code.
  2. iso2ToIso3(iso2: string): Promise<string | null>

    • Converts an ISO2 code to an ISO3 code.
  3. iso3ToNumeric(iso3: string): Promise<string | null>

    • Converts an ISO3 code to its numeric representation.
  4. numericToIso3(numeric: string): Promise<string | null>

    • Converts a numeric code to an ISO3 code.
  5. iso3ToName(iso3: string): Promise<string | null>

    • Converts an ISO3 code to the country's name.
  6. nameToIso3(name: string): Promise<string | null>

    • Converts a country name to its ISO3 code.
  7. iso2ToNumeric(iso2: string): Promise<string | null>

    • Converts an ISO2 code to its numeric representation.
  8. numericToIso2(numeric: string): Promise<string | null>

    • Converts a numeric code to an ISO2 code.
  9. nameToIso2(name: string): Promise<string | null>

    • Converts a country name to its ISO2 code.
  10. iso2ToName(iso2: string): Promise<string | null>

    • Converts an ISO2 code to the country's name.
  11. numericToName(numeric: string): Promise<string | null>

    • Converts a numeric code to the country's name.
  12. nameToNumeric(name: string): Promise<string | null>

    • Converts a country name to its numeric representation.

Notes

  • All functions return a promise that resolves to the corresponding code or name, or null if the provided input is invalid or not found in the data.
  • The data is cached after the first fetch, making subsequent calls faster.

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue. Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch: git checkout -b feature/AmazingFeature
  3. Commit your Changes: git commit -m 'Add some AmazingFeature'
  4. Push to the Branch: git push origin feature/AmazingFeature
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE.txt for more information.


Contact

Marius Adam - @Marius Adam LinkedIn

Project Link: https://github.com/Marius-Adam/country-codes-converter

About

A simple library for converting country codes between ISO, name and numeric formats.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published