Gathering detailed insights and metrics for countries-data-kit
Gathering detailed insights and metrics for countries-data-kit
Gathering detailed insights and metrics for countries-data-kit
Gathering detailed insights and metrics for countries-data-kit
Country data with advanced filters: ISO codes, capitals, continents, currencies, dialing codes, flags, emergency numbers, and phone masking. Tiny package, compatible with backend and frontend JS frameworks
npm install countries-data-kit
Typescript
Module System
Node Version
NPM Version
75.6
Supply Chain
99
Quality
81.9
Maintenance
100
Vulnerability
100
License
TypeScript (53.14%)
JavaScript (46.86%)
Love this project? Help keep it running β sponsor us today! π
Total Downloads
734
Last Day
1
Last Week
5
Last Month
41
Last Year
734
1 Stars
25 Commits
1 Watching
2 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
1.1.13
Package Id
countries-data-kit@1.1.13
Unpacked Size
301.77 kB
Size
71.04 kB
File Count
8
NPM Version
10.2.4
Node Version
21.6.0
Publised On
29 Aug 2024
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
-37.5%
5
Compared to previous week
Last month
173.3%
41
Compared to previous month
Last year
0%
734
Compared to previous year
7
countries-data-kit
is a powerful, minimal-sized JavaScript package offering over 15 types of detailed country information with advanced filtering options. It adhers to ISO 3166 for countries, ISO 4217 for currencies, and ISO 639 for languages.
π§ Wide Compatibility: Runs seamlessly in Node.js, React, React Native, and browser environments.
π Comprehensive Data: Fetch Currency Details, Get Dialing Codes, Display Flag Emojis, Provide Language Info, Access Emergency Numbers, Driving Side Info, Get Phone Number Masks
π ISO Standards Compliance: Adheres to ISO 3166 for countries, ISO 4217 for currencies, and ISO 639 for languages.
π Flexible Filtering: Filter data by over 10 different criteria to get precisely the information you need.
You can install the package via npm or yarn:
1npm install countries-data-kit
or
1yarn add countries-data-kit
The main function, getCountries({ fields:[], filters:{}|[] })
, retrieves country details based on two parameters:
fields: Specify which country data you want, such as mobile number mask, capital, or dialing code. Use the CFields
enum or pass a string array.
filters: Define criteria to filter countries, like continent, alpha-2/alpha-3 code, name, or dialing number.
This setup gives you control over the data you receive and how countries are selected.
1const { getCountries, SFields, CFields } = require('countries-data-kit'); 2
1import { getCountries, CFields, SFields } from 'countries-data-kit';
for filters it could be passed as object or array both syntaxes are correct and the details of how to pass them are shown below
To get data for all 249 countries, simply call the getCountries
function:
1const countries = getCountries(); 2or 3const countries = getCountries({});
If you only need certain fields, such as phone number details, you can specify them using the fields
parameter:
1const countriesPhoneNumberDetails = getCountries({ 2 fields: [ 3 CFields.dialingCode, 4 CFields.phoneNumberMask 5 ] 6});
Alternatively, you can pass them as strings:
1const countriesPhoneNumberDetails = getCountries({ 2 fields: [ 3 "dialingCode", 4 "phoneNumberMask" 5 ] 6});
To filter countries by certain criteria, such as continent or country code, use the filters
parameter.
Get all Asian and European countries:
1const asianCountries = getCountries({ 2 filters: [ 3 SFields.continentNames.Asia 4 ] 5});
or
1const asianCountries = getCountries({ 2 filters: { 3 continentName:"Asia" 4 } 5});
or
1const asianCountries = getCountries({ 2 filters: { 3 continentName:["Asia"] 4 } 5}); 6
You can also filter by specific country codes:
1let countries = getCountries({ 2 filters: { 3 alpha2Code: ["US", "CA", "EG", "JP"] 4 } 5});
You can combine fields
and filters
to retrieve specific data. For example, to get the capital city of Germany:
1let countries = getCountries({ 2 fields: [CFields.capitalCity], 3 filters: [SFields.countryNames.Germany] 4});
or
1let countries = getCountries({ 2 fields: [ 3 CFields.capitalCity 4 ], 5 filters: { 6 countryName: "Germany" 7 } 8});
Retrieve in which continents specific countries exist based on their alpha3 codes:
1let countries = getCountries({ 2 fields: [ 3 CFields.continentName 4 ], 5 filters: { 6 alpha3Code: ["DZA", "AUT"] 7 } 8});
You can apply multiple filters to retrieve data that meets several criteria. For example, to get all countries with Cairo as the capital, a specific flag, and those that use the Euro:
1let countries = getCountries({ 2 fields: [CFields.continentName], 3 filters: [ 4 SFields.capitalCities.Cairo, 5 SFields.flagEmojis["πΊπΈ"], 6 SFields.currencyCodes.EUR 7 ] 8});
or
1let countries = getCountries({ 2 fields:[CFields.continentName], 3 filters:{ 4 capitalCity:"Cairo", 5 flagEmoji:"πΊπΈ", 6 currencyCode:"EUR" 7 } 8}) 9
the above call will return all countries that use Euro + Egypt + USA
Retrieve the dialing codes and flag emojis for all countries:
1const countries = getCountries({ 2 fields: [CFields.dialingCode, CFields.flagEmoji] 3});
Retrieve the dialing code and phone mask for a specific country or multiple countries:
1const countryDetails = getCountries({ 2 fields: [CFields.dialingCode, CFields.phoneNumberMask], 3 filters: [ 4 SFields.countryNames['United Arab Emirates'], 5 SFields.countryNames['United States of America'] 6 ] 7});
Retrieve the emergency numbers for the United States:
1const emergencyNumbersUS = getCountries({ 2 fields: [CFields.emergencyNumbers], 3 filters: { 4 alpha2Code: "US" 5 //alpha3Code: "USA" 6 //countryName: "United States of America" 7 //capitalCity:"Washington, D.C." 8 } 9});
Find out the driving side in France:
1const drivingSideFrance = getCountries({ 2 fields: [CFields.drivingSide], 3 filters: { 4 countryName: "France" 5 } 6}); 7 8or 9 10const drivingSideFrance = getCountries({ 11 fields: [CFields.drivingSide], 12 filters: [SFields.countryNames.France] 13}); 14
Retrieve the names of all countries that use USD as their currency:
1 2const usdCountries = getCountries({ 3 fields: [CFields.countryName], 4 filters: [SFields.currencyCodes.USD] 5}); 6or 7const usdCountries = getCountries({ 8 fields: [CFields.countryName], 9 filters: { 10 currencyCode: "USD" 11 } 12});
The package provides the following data fields: CFields
Field | Description | Example | How to Access |
---|---|---|---|
alpha2Code | ISO 3166-1 alpha-2 code | "US" | CFields.alpha2Code |
alpha3Code | ISO 3166-1 alpha-3 code | "USA" | CFields.alpha3Code |
capitalCity | Capital city | "Washington, D.C." | CFields.capitalCity |
continentName | Continent name | "North America" | CFields.continentName |
countryName | Official country name | "United States of America" | CFields.countryName |
currency | Official currency name | "United States dollar" | CFields.currency |
currencyCode | ISO 4217 currency code | "USD" | CFields.currencyCode |
currencySymbol | Currency symbol | "$" | CFields.currencySymbol |
dialingCode | International dialing code | "+1" | CFields.dialingCode |
drivingSide | Driving side ("left" or "right") | "right" | CFields.drivingSide |
emergencyNumbers | List of emergency numbers | {"police": "911", "fire": "911", "ambulance": "911"} | CFields.emergencyNumbers |
flagEmoji | Flag emoji | "πΊπΈ" | CFields.flagEmoji |
flagSVGUrl | URL to SVG image of the flag | "https://example.com/flag.svg" | CFields.flagSVGUrl |
numericCountryCode | Numeric country code | "840" | CFields.numericCountryCode |
phoneNumberMask | Phone number format mask | "+1 (###) ###-####" | CFields.phoneNumberMask |
primaryLanguage | Primary language | "English" | CFields.primaryLanguage |
SFields
Values:This method allows you to filter countries by providing an array of values from the SFields
mappings.
Example:
1const filteredCountries = getCountries({ 2 filters: [SFields.alpha2Codes.US, SFields.continentNames.Africa] 3});
SFields Table:
Field | How to Access |
---|---|
alpha2Codes | SFields.alpha2Codes |
alpha3Codes | SFields.alpha3Codes |
capitalCities | SFields.capitalCities |
continentNames | SFields.continentNames |
countryNames | SFields.countryNames |
currencies | SFields.currencies |
currencyCodes | SFields.currencyCodes |
dialingCodes | SFields.dialingCodes |
drivingSides | SFields.drivingSides |
flagEmojis | SFields.flagEmojis |
numericCountryCodes | SFields.numericCountryCodes |
phoneNumberMasks | SFields.phoneNumberMasks |
primaryLanguages | SFields.primaryLanguages |
This method provides more control by allowing you to specify filters as key-value pairs, where the keys correspond to the filter object keys and the values are the criteria you want to filter by.
Example:
1const filteredCountries = getCountries({ 2 filters: { 3 continentName: ["Europe", "Asia"], 4 alpha2Code: "EG" 5 } 6});
Filter Object Key Table:
Filter Object Key | Example |
---|---|
alpha2Code | "EG" |
alpha3Code | "USA" |
capitalCity | "Cairo" |
continentName | ["Europe", "Asia"] |
countryName | "United States of America" |
currency | "Egyptian pound" |
currencyCode | "USD" |
dialingCode | ["+20", "+1"] |
drivingSide | "right" |
flagEmoji | "πͺπ¬" |
numericCountryCode | "840" |
phoneNumberMask | "(###) ###-####" |
primaryLanguage | ["English", "Arabic"] |
Contributions are welcome! Please check the contribution guidelines for more details.
This project is licensed under the MIT License. See the LICENSE file for details.
For questions or support, please open an issue on GitHub or contact us via email at mm7modmgdy@gmail.com.
Happy coding! π
No vulnerabilities found.
No security vulnerabilities found.