Global-pocket
This is an npm package that provides utility functions for fetching and managing country data from the REST Countries API. The package supports fetching all countries, fetching a country by its ISO 3166-1 alpha-2 code, and fetching a country by its name. It is designed to be secure, efficient, and professional.
Features
- Fetch all countries with caching to reduce redundant API calls.
- Fetch a specific country by its ISO 3166-1 alpha-2 code.
- Fetch a specific country by its name.
- Structured error logging for debugging.
- Validates and normalizes API responses to handle inconsistencies.
- Utilizes environment variables for better configuration and security.
Installation
npm install global-pocket
Function Reference
Get all countries
const countries = await getAllCountries();
Get Country
const countryByCode = await getCountryByCode("IN");
Parameter | Type | Description |
---|
code | string | Required. code of country to fetch |
Get Country
const countryByName = await getCountryByName("INDIA");
Parameter | Type | Description |
---|
name | string | Required. name of country to fetch |
Authors
