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
95 lines (94 loc) • 3.16 kB
TypeScript
import { PhoneValidationResult } from './types';
/**
* Validate if a string is a valid ISO 3166-1 alpha-2 country code
* @param code - The code to validate
* @returns true if valid, false otherwise
* @example
* ```ts
* isValidCountryCode2("US"); // true
* isValidCountryCode2("XX"); // false
* ```
*/
export declare function isValidCountryCode2(code: string): boolean;
/**
* Validate if a string is a valid ISO 3166-1 alpha-3 country code
* @param code - The code to validate
* @returns true if valid, false otherwise
* @example
* ```ts
* isValidCountryCode3("USA"); // true
* isValidCountryCode3("XXX"); // false
* ```
*/
export declare function isValidCountryCode3(code: string): boolean;
/**
* Validate if a string is a valid country code (2-letter or 3-letter)
* @param code - The code to validate
* @returns true if valid, false otherwise
* @example
* ```ts
* isValidCountryCode("US"); // true
* isValidCountryCode("USA"); // true
* isValidCountryCode("INVALID"); // false
* ```
*/
export declare function isValidCountryCode(code: string): boolean;
/**
* Validate if a string is a valid country name
* @param name - The country name to validate
* @returns true if valid, false otherwise
* @example
* ```ts
* isValidCountryName("UnitedStates"); // true
* isValidCountryName("United States"); // true (case-insensitive)
* isValidCountryName("Atlantis"); // false
* ```
*/
export declare function isValidCountryName(name: string): boolean;
/**
* Validate if a currency code is valid (ISO 4217)
* @param currencyCode - The currency code to validate
* @returns true if valid, false otherwise
* @example
* ```ts
* isValidCurrencyCode("USD"); // true
* isValidCurrencyCode("EUR"); // true
* isValidCurrencyCode("XXX"); // false (not used by any country)
* ```
*/
export declare function isValidCurrencyCode(currencyCode: string): boolean;
/**
* Validate if a calling code is valid
* @param callingCode - The calling code to validate (with or without +)
* @returns true if valid, false otherwise
* @example
* ```ts
* isValidCallingCode("+1"); // true
* isValidCallingCode("44"); // true
* isValidCallingCode("+999"); // false
* ```
*/
export declare function isValidCallingCode(callingCode: string): boolean;
/**
* Basic phone number validation for a specific country
* @param phoneNumber - The phone number to validate
* @param countryIdentifier - Country name, code2, or code3
* @returns Validation result object
* @example
* ```ts
* validatePhoneNumber("2025551234", "US");
* // Returns: { isValid: true, formatted: "+1-202-555-1234", countryCode: "+1" }
* ```
*/
export declare function validatePhoneNumber(phoneNumber: string, countryIdentifier: string): PhoneValidationResult;
/**
* Parse a phone number and detect the country
* @param phoneNumber - The phone number to parse (with calling code)
* @returns Validation result with detected country
* @example
* ```ts
* parsePhoneNumber("+1-202-555-1234");
* // Returns: { isValid: true, formatted: "+1-2025551234", countryCode: "+1" }
* ```
*/
export declare function parsePhoneNumber(phoneNumber: string): PhoneValidationResult;