|
1 |
| -# CountryData.js  |
2 |
| - |
3 |
| - |
4 |
| -| CI Status | Code Coverage | Quality Gate Status | |
5 |
| -| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
6 |
| -| [](https://github.com/Clifftech123/CountryData.js/actions/workflows/main.yml) | [](https://codecov.io/github/Clifftech123/CountryData.js) | [](https://sonarcloud.io/summary/new_code?id=Clifftech123_CountryData.js) | |
7 |
| - |
8 |
| - |
| 1 | +# CountryData.js |
9 | 2 |
|
| 3 | +## Overview |
10 | 4 |
|
| 5 | +`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. |
11 | 6 |
|
| 7 | +## Features |
12 | 8 |
|
13 |
| -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. |
14 |
| - |
15 |
| -Make sure to compile TypeScript files to JavaScript before running the code. |
| 9 | +- 🌍 **Comprehensive Country Data**: Access detailed information, including `country names`, `short codes`, `phone codes`, `regions`, and `flags`. |
| 10 | +- ⚡ **JavaScript and TypeScript Support**: Use the package seamlessly in both JavaScript and TypeScript projects. |
| 11 | +- 🔄 **Asynchronous Operations**: All methods return promises for efficient data handling. |
| 12 | +- 📦 **Lightweight & Efficient**: Minimal dependencies to keep your project lean. |
| 13 | +- 🏗️ **Easy Integration**: Seamlessly integrates with any Node.js project using ES modules and commonJS |
16 | 14 |
|
| 15 | +## Status & Quality |
17 | 16 |
|
18 |
| -## Features |
| 17 | +| 🔄 CI Status | 📊 Code Coverage | 🏆 Quality Gate Status | |
| 18 | +| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 19 | +| [](https://github.com/Clifftech123/CountryData.js/actions/workflows/main.yml) | [](https://codecov.io/github/Clifftech123/CountryData.js) | [](https://sonarcloud.io/summary/new_code?id=Clifftech123_CountryData.js) | |
19 | 20 |
|
20 |
| -- **Comprehensive Country Data**: Access detailed information including `country names`, `short codes`, `phone codes`, `regions`, and `flags`. |
21 |
| -- **JavaScript and TypeScript Support**: Use the package in both JavaScript and TypeScript projects. |
22 |
| -- **Easy Integration**: Seamlessly integrate with any Node.js project using ES modules. |
23 |
| -- **Asynchronous Operations**: All methods return promises for efficient data handling. |
24 |
| -- **Lightweight**: Minimal dependencies to keep your project lean. |
| 21 | + |
25 | 22 |
|
26 | 23 | ## Installation
|
27 | 24 |
|
28 |
| -Install CountryData.js using npm: |
29 |
| - |
30 | 25 | ```sh
|
31 | 26 | npm install countrydata.js
|
32 | 27 | ```
|
33 | 28 |
|
34 | 29 | ## Usage
|
35 | 30 |
|
36 |
| -### JavaScript Version |
| 31 | +### JavaScript Example |
37 | 32 |
|
38 | 33 | ```javascript
|
39 |
| -import { CountryHelper } from "countrydata.js"; |
| 34 | +import { CountryHelper } from 'countrydata.js'; |
40 | 35 |
|
41 | 36 | const countryHelper = new CountryHelper();
|
42 | 37 |
|
43 | 38 | // Get all countries
|
44 |
| -(async () => { |
45 |
| - const allCountries = await countryHelper.getCountries(); |
46 |
| - console.log(JSON.stringify(allCountries, null, 2)); |
47 |
| -})(); |
| 39 | +countryHelper.getCountries().then(console.log); |
48 | 40 |
|
49 | 41 | // Get country by short code
|
50 |
| -(async () => { |
51 |
| - const country = await countryHelper.getCountryByShortCode('US'); |
52 |
| - console.log(country); |
53 |
| -})(); |
54 |
| - |
55 |
| - |
| 42 | +countryHelper.getCountryByShortCode('US').then(console.log); |
56 | 43 | ```
|
57 | 44 |
|
58 |
| -### TypeScript Version |
| 45 | +### TypeScript Example |
59 | 46 |
|
60 | 47 | ```typescript
|
61 |
| - |
62 | 48 | import { CountryHelper } from 'countrydata.js';
|
63 | 49 |
|
64 |
| -(async () => { |
65 |
| - const countryHelper = new CountryHelper(); |
66 |
| - const allCountries = await countryHelper.getCountries(); |
67 |
| - console.log(JSON.stringify(allCountries, null, 2)); |
68 |
| -})(); |
| 50 | +const countryHelper = new CountryHelper(); |
69 | 51 |
|
70 |
| -// Get country by short code |
71 |
| -(async () => { |
72 |
| - const countryHelper = new CountryHelper(); |
73 |
| - const countryData = await countryHelper.getCountryByShortCode('US'); |
74 |
| - console.log(countryData); |
75 |
| -})(); |
| 52 | +// Get all countries |
| 53 | +const allCountries = await countryHelper.getCountries(); |
| 54 | +console.log(allCountries); |
76 | 55 |
|
| 56 | +// Get country by short code |
| 57 | +const countryByCode = await countryHelper.getCountryByShortCode('US'); |
| 58 | +console.log(countryByCode); |
77 | 59 | ```
|
78 | 60 |
|
79 |
| -You can check the sample code in the [example folder](https://github.com/Clifftech123/CountryData.js/tree/main/Sample). |
80 |
| -With this sample code, you can see how to use the package in your project both in JavaScript and TypeScript. |
| 61 | +## Sample Implementation |
81 | 62 |
|
82 |
| -Make sure to check how the Sample has been implemented . |
| 63 | +If you want to see a sample implementation of this package further in both javascript and typescript , you can check out the [Sample](https://github.com/Clifftech123/CountryData.js/tree/main/Sample) folder. |
83 | 64 |
|
84 |
| -## API |
| 65 | +### Usage with Express.js |
85 | 66 |
|
86 |
| -### `CountryHelper` |
| 67 | +This package can be used in an Express.js application to create a REST API for country data. Check the [example folder](https://github.com/Clifftech123/CountryData.js/tree/main/Sample) for sample implementations in both JavaScript and TypeScript. |
87 | 68 |
|
88 |
| -The main class that provides access to country data. It works the same way in both JavaScript and TypeScript. |
| 69 | +## API Reference |
89 | 70 |
|
90 |
| -#### Methods |
| 71 | +### `CountryHelper` Methods |
91 | 72 |
|
92 |
| - |
93 |
| -| Method | Description | |
94 |
| -|--------|-------------| |
95 |
| -| `getCountries(): Promise<Country[]>` | Fetches and returns a promise that resolves to an array of all countries. | |
96 |
| -| `getCountryByShortCode(shortCode: string): Promise<Country` | null>` | Fetches and returns a promise that resolves to a country object based on the provided country short code (e.g., "US"). Returns `null` if the country is not found. | |
97 |
| -| `getRegionsByCountryShortCode(shortCode: string): Promise<Region[]>` | Fetches and returns a promise that resolves to an array of regions for the specified country short code (e.g., "US"). | |
98 |
| -| `getCountryByPhoneCode(phoneCode: string): Promise<Country` | null> | Fetches and returns a promise that resolves to a country object based on the provided phone code (e.g., "1" for the US). Returns `null` if the country is not found. | |
99 |
| -| `getCountryPhoneCodeByShortCode(shortCode: string): Promise<string` | null>` | Fetches and returns a promise that resolves to the phone code of a country based on the provided country short code (e.g., "US"). Returns `null` if the country is not found. | |
| 73 | +| Method | Description | |
| 74 | +| -------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | |
| 75 | +| **`getCountries(): Promise<Country[]>`** | Returns an array of all countries. | |
| 76 | +| **`getCountryByShortCode(shortCode: string): Promise<Country \| null>`** | Returns a country object based on the short code (e.g., "US"), or `null` if not found. | |
| 77 | +| **`getRegionsByCountryShortCode(shortCode: string): Promise<Region[]>`** | Returns an array of regions for the specified country short code (e.g., "US"). | |
| 78 | +| **`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. | |
| 79 | +| **`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. | |
100 | 80 |
|
101 | 81 | ## Contributing
|
102 | 82 |
|
103 |
| -We welcome contributions to CountryData.js! Please read our [contributing guidelines](CONTRIBUTING.md) for details on how to submit pull requests, report issues, or request features. |
| 83 | +We welcome contributions! Please read our [contributing guidelines](CONTRIBUTING.md) for details on how to submit pull requests, report issues, or request features. |
104 | 84 |
|
105 | 85 | ## License
|
106 | 86 |
|
107 | 87 | This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
108 | 88 |
|
109 | 89 | ## Support
|
110 | 90 |
|
111 |
| -If you encounter any issues or have questions about using CountryData.js, please open an issue on our GitHub repository or contact us directly through our support channels. |
112 |
| - |
| 91 | +If you encounter any issues or have questions, please open an issue on our GitHub repository or contact us directly through our support channels. |
113 | 92 |
|
| 93 | +🚀 Get started today with `CountryData.js` and simplify your country data management! |
0 commit comments