CountryData.js
is a comprehensive Node.js package designed to provide easy access to detailed country information. It supports both JavaScript and TypeScript, making it versatile for various project needs. Whether you're building a web application, API, or any other project that requires country data, this package offers a simple and efficient solution.
- 🌍 Comprehensive Country Data: Access detailed information, including
country names
,short codes
,phone codes
,regions
, andflags
. - ⚡ JavaScript and TypeScript Support: Use the package seamlessly in both JavaScript and TypeScript projects.
- 🔄 Asynchronous Operations: All methods return promises for efficient data handling.
- 📦 Lightweight & Efficient: Minimal dependencies to keep your project lean.
- 🏗️ Easy Integration: Seamlessly integrates with any Node.js project using ES modules and commonJS
🔄 CI Status | 📊 Code Coverage | 🏆 Quality Gate Status |
---|---|---|
npm install countrydata.js
import { CountryHelper } from 'countrydata.js';
const countryHelper = new CountryHelper();
// Get all countries
countryHelper.getCountries().then(console.log);
// Get country by short code
countryHelper.getCountryByShortCode('US').then(console.log);
import { CountryHelper } from 'countrydata.js';
const countryHelper = new CountryHelper();
// Get all countries
const allCountries = await countryHelper.getCountries();
console.log(allCountries);
// Get country by short code
const countryByCode = await countryHelper.getCountryByShortCode('US');
console.log(countryByCode);
If you want to see a sample implementation of this package further in both javascript and typescript , you can check out the Sample folder.
This package can be used in an Express.js application to create a REST API for country data. Check the example folder for sample implementations in both JavaScript and TypeScript.
Method | Description |
---|---|
getCountries(): Promise<Country[]> |
Returns an array of all countries. |
getCountryByShortCode(shortCode: string): Promise<Country | null> |
Returns a country object based on the short code (e.g., "US"), or null if not found. |
getRegionsByCountryShortCode(shortCode: string): Promise<Region[]> |
Returns an array of regions for the specified country short code (e.g., "US"). |
getCountryByPhoneCode(phoneCode: string): Promise<Country | null> |
Returns a country object based on the phone code (e.g., "1" for the US), or null if not found. |
getCountryPhoneCodeByShortCode(shortCode: string): Promise<string | null> |
Returns the phone code of a country based on the short code (e.g., "US"), or null if not found. |
We welcome contributions! Please read our contributing guidelines for details on how to submit pull requests, report issues, or request features.
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or have questions, please open an issue on our GitHub repository or contact us directly through our support channels.
🚀 Get started today with CountryData.js
and simplify your country data management!