country-codes-library
Version:
The Country Code Library provides a collection of two-letter and three-letter country codes according to the ISO 3166-1 standard, as well as it provides USA, China and Canada Province codes (State codes / adminstrative division codes). In addition, it inc
124 lines (123 loc) • 4.22 kB
TypeScript
import { Country, SearchOptions } from './types';
/**
* Get country information by 2-letter ISO code
* @param code - ISO 3166-1 alpha-2 code (e.g., "US", "GB", "CN")
* @returns Country object or null if not found
* @example
* ```ts
* const country = getCountryByCode2("US");
* // Returns: { name: "UnitedStates", code2: "US", code3: "USA", ... }
* ```
*/
export declare function getCountryByCode2(code: string): Country | null;
/**
* Get country information by 3-letter ISO code
* @param code - ISO 3166-1 alpha-3 code (e.g., "USA", "GBR", "CHN")
* @returns Country object or null if not found
* @example
* ```ts
* const country = getCountryByCode3("USA");
* // Returns: { name: "UnitedStates", code2: "US", code3: "USA", ... }
* ```
*/
export declare function getCountryByCode3(code: string): Country | null;
/**
* Get country information by name
* @param name - Country name (e.g., "UnitedStates", "United States")
* @returns Country object or null if not found
* @example
* ```ts
* const country = getCountryByName("UnitedStates");
* // Returns: { name: "UnitedStates", code2: "US", code3: "USA", ... }
* ```
*/
export declare function getCountryByName(name: string): Country | null;
/**
* Get all countries that use a specific currency
* @param currencyCode - ISO 4217 currency code (e.g., "USD", "EUR")
* @returns Array of countries using the currency
* @example
* ```ts
* const countries = getCountriesByCurrency("EUR");
* // Returns array of European countries using Euro
* ```
*/
export declare function getCountriesByCurrency(currencyCode: string): Country[];
/**
* Get all countries with a specific calling code
* @param callingCode - International calling code (e.g., "+1", "+44")
* @returns Array of countries with the calling code
* @example
* ```ts
* const countries = getCountriesByCallingCode("+1");
* // Returns: [USA, Canada, and other +1 countries]
* ```
*/
export declare function getCountriesByCallingCode(callingCode: string): Country[];
/**
* Search countries by name (supports partial matching)
* @param query - Search query
* @param options - Search options
* @returns Array of matching countries
* @example
* ```ts
* const results = searchCountries("united");
* // Returns: [UnitedStates, UnitedKingdom, UnitedArabEmirates]
* ```
*/
export declare function searchCountries(countryName: string, options?: SearchOptions): Country[];
/**
* Convert between 2-letter and 3-letter country codes
* @param code - Country code to convert
* @param targetFormat - Target format ('code2' or 'code3')
* @returns Converted code or null if not found
* @example
* ```ts
* convertCountryCode("US", "code3"); // Returns: "USA"
* convertCountryCode("GBR", "code2"); // Returns: "GB"
* ```
*/
export declare function convertCountryCode(code: string, targetFormat: 'code2' | 'code3'): string | null;
/**
* Get calling code for a country
* @param countryIdentifier - Country name, code2, or code3
* @returns Calling code or null if not found
* @example
* ```ts
* getCallingCode("US"); // Returns: "+1"
* getCallingCode("UnitedStates"); // Returns: "+1"
* ```
*/
export declare function getCallingCode(countryIdentifier: string): string | null;
/**
* Get currency code for a country
* @param countryIdentifier - Country name, code2, or code3
* @returns Currency code or null if not found
* @example
* ```ts
* getCurrencyCode("US"); // Returns: "USD"
* getCurrencyCode("Germany"); // Returns: "EUR"
* ```
*/
export declare function getCurrencyCode(countryIdentifier: string): string | null;
/**
* Get currency symbol for a country
* @param countryIdentifier - Country name, code2, or code3
* @returns Currency symbol or null if not found
* @example
* ```ts
* getCurrencySymbol("US"); // Returns: "$"
* getCurrencySymbol("Japan"); // Returns: "¥"
* ```
*/
export declare function getCurrencySymbol(countryIdentifier: string): string | null;
/**
* Get all unique currencies used worldwide
* @returns Array of unique currency codes
*/
export declare function getAllCurrencies(): string[];
/**
* Get all unique calling codes
* @returns Array of unique calling codes
*/
export declare function getAllCallingCodes(): string[];