Gathering detailed insights and metrics for @apollo-tech/country-codes
Gathering detailed insights and metrics for @apollo-tech/country-codes
A simple utility for retrieving country codes and names
npm install @apollo-tech/country-codes
Typescript
Module System
Node Version
NPM Version
76.7
Supply Chain
99.1
Quality
82.7
Maintenance
100
Vulnerability
100
License
TypeScript (98.63%)
JavaScript (1.37%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
1,773
Last Day
3
Last Week
46
Last Month
598
Last Year
1,773
2 Stars
34 Commits
1 Watching
6 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
1.0.4
Package Id
@apollo-tech/country-codes@1.0.4
Unpacked Size
378.33 kB
Size
44.81 kB
File Count
9
NPM Version
10.9.0
Node Version
22.12.0
Publised On
06 Jan 2025
Cumulative downloads
Total Downloads
Last day
200%
3
Compared to previous day
Last week
-52.1%
46
Compared to previous week
Last month
82.9%
598
Compared to previous month
Last year
0%
1,773
Compared to previous year
A simple NPM package to search for country information based on various codes and names. This package provides methods to search for countries by FIPS code, ISO code, internet code, and country name.
Built on Typescript for the best developer experience.
Credit to richorama/country-code-lookup for the base country data and the original scaffold for this package. The original package was converted to Typescript and was restructured with a class-based approach to provide an alternative to the original package. Note that this original package contains types, so please choose the package that best suits your needs/development style.
Install the package using npm:
1npm install @apollo-tech/country-codes
Import the package and use the provided methods to search for country information.
1import CountryCodes from '@apollo-tech/country-codes'; 2 3const countryCodes = new CountryCodes(); 4 5// Search for a country by FIPS code 6const countryByFips = countryCodes.byFips('US'); 7console.log(countryByFips); 8 9// Search for a country by ISO code 10const countryByIso = countryCodes.byIso('USA'); 11console.log(countryByIso); 12 13// Search for a country by internet code 14const countryByInternet = countryCodes.byInternet('US'); 15console.log(countryByInternet); 16 17// Search for a country by name 18const countryByName = countryCodes.byCountry('United States'); 19console.log(countryByName);
Search for a country by FIPS code.
byFips(code: string): CountryResponse
Search for a country by ISO code. This method supports ISO2, ISO3, and ISO numeric codes. If you provide an invalid
ISO code type, the method will throw an error. You can enable safeMode
to prevent the method from throwing an error
and return null
instead.
byIso(code: string | number, safeMode: boolean = false): CountryResponse
Search for a country by internet code.
byInternet(code: string): CountryResponse
Search for a country by name. This method is case-sensitive by default. Enable ignoreCase
to perform a
case-insensitive search.
byCountry(country: string, ignoreCase: boolean = false): CountryResponse
All methods return a CountryResponse
object which is either a Country
object or null
.
For simplicity of use, below is the structure of the Country
object:
1interface Country { 2 continent: string; 3 region: string; 4 country: string; 5 capital: string; 6 fips: string; 7 iso2: string; 8 iso3: string; 9 isoNo: number; 10 internet: string; 11}
The Country
object contains the following properties:
continent
- The name of the country's continent.region
- The region of the country.country
- The name of the country.capital
- The capital of the country.fips
- The FIPS code of the country.iso2
- The ISO-3166-alpha-2 code of the country (2-char code, like US
).iso3
- The ISO-3166-alpha-3 code of the country (3-char code, like USA
).isoNo
- The ISO-3166-num-3 code of the country (3-digit numerical ccode, like 840
).internet
- The internet code of the country (2-char code, like US
).In general, if you are asked for a two-digit code, use the ISO2 code. If you are asked for a three-digit code, use the ISO3 code.
The other code types are provided, but it is likely you will know which code you need based on the context in which you are asked for it. It's unlikely you will need to use the FIPS code or internet code unless specifically asked for them.
This package is a simple utility package and is unlikely to have any major updates. If you have any suggestions or feature requests, please open an issue on GitHub. That said, time permitting, we will likely add the following features:
This package uses Semantic Versioning. For the versions available, see the Releases on this repository. Due to the nature of this package, it is unlikely to have any major updates, so the versioning will likely remain at 1.x.x.
We maintain semver by utilizing Conventional Commits via the Commit Lint package. This allows us to automatically generate the version number based on the commit messages, using the Release Please GitHub Action. Due to this, releases are automatically generated when a new commit is pushed to the main branch. The release is then published to the NPM registry. This could mean that the GitHub release and the NPM package version are not in sync for a short period of time.
If a future utility were to be added that significantly changed the nature of the package, we would likely create a new package with a different name to avoid complicating the existing package.
Contributions are welcome! If you have any suggestions, bug reports, or feature requests, please open an issue on GitHub.
For code contributions, please fork the repository and submit a pull request. Please ensure that your code is well-documented and that you have added tests for any new features or bug fixes. While this repository does not have a strict code style guide, you should aim to match the existing code style as closely as possible.
This project is licensed under the MIT License.
No vulnerabilities found.
No security vulnerabilities found.